Knowledge Base Sync
How CodeLantern keeps its copy of your repository's knowledge base current on GitHub and Azure Repos, and how to check that it's working.
Your knowledge base lives in your repository, and that copy is the source of truth. Knowledge base sync keeps a copy of it on the CodeLantern platform, so the portal's Knowledge analytics can show how your knowledge is growing across repositories.
Sync is one-way, from your repository to CodeLantern. It never writes to your repository, and editing the knowledge base always means changing the files in your repository and merging the change.
Sync is on by default and needs nothing in your repository. It starts when the repository is added in the portal and stays on while the repository is configured. To stop it, remove the repository from the portal.
Sync doesn't change what your skills read. Skills read the knowledge-base files in your working copy, so a session has the knowledge it needs whether or not sync is set up.
What's synced
- Synced: every markdown file under
.codelantern/knowledge-base/, includingadr/, as it is on your default branch. The knowledge base can have up to 2,000 files, and each file can be up to 1 MB. - Not synced:
.codelantern/work-items/, the plans, session logs, and decisions for each issue. They stay in your repository.
Each sync reflects the whole knowledge base on the default branch, so an entry you delete from the repository is also removed from CodeLantern's copy.
A sync applies the whole knowledge base or nothing. If one file can't be read as knowledge, for example because two of its headings are identical or it's larger than 1 MB, CodeLantern keeps its previous copy of the entire knowledge base until you fix the file and push again. Your files are never partly synced.
GitHub repositories
On GitHub, CodeLantern reads the knowledge base itself through the CodeLantern GitHub App. Nothing is added to your repository, and no tokens or secrets are needed.
Set it up
- Install the CodeLantern GitHub App on the repository and register the repository in the portal.
- Run
/cl-dev:cl-initto create the knowledge base, then commit it and merge it into your default branch.
When it runs
- After every push to the default branch. Merging a pull request that updates the knowledge base, such as one from
/cl-dev:consolidate, counts. A push that doesn't change the knowledge base is checked and leaves CodeLantern's copy as it is. - Once a day, as a safety net. If a repository was used with CodeLantern that day but hasn't synced, CodeLantern syncs it without waiting for another push. This covers a push notification that never arrived.
The App reads the repository with read-only access to that repository's contents. It can't write to your repository or read any other repository.
Check that it worked
A few minutes after a push to the default branch, open Repositories in the portal. The repository's row shows Knowledge Base: Synced and when it last synced. If it shows Retrying or Sync stopped instead, the row says why and what fixes it; see When a sync stops.
If the row still shows an older sync time:
- Check that the push was to the default branch and that the repository shows as Active in the portal.
- Check that the CodeLantern GitHub App is still installed on the repository and can access it.
- Select Sync now on the row to sync it straight away.
- If it still hasn't synced the next day, contact CodeLantern support.
Repositories set up before this change
Earlier versions of cl-init added a .github/workflows/cl-kb-sync.yml workflow. It's no longer used, and its runs now fail. Sync doesn't depend on it, so delete the file from your repository when convenient.
Azure Repos repositories
On Azure Repos, sync is automatic and needs no workflow or pipeline in your Azure DevOps organization. When an admin adds an Azure Repos repository in the portal, CodeLantern registers a Service Hook (Azure DevOps's webhook subscription) on that Azure DevOps project. After that, every push to the repository's default branch tells CodeLantern to read the knowledge base at the tip of that branch. Nothing is installed in your Azure DevOps organization.
What the admin needs
When adding the repository, the admin needs:
- An active personal connection to Azure DevOps.
- Permission to manage Service Hooks on the project, which Azure DevOps grants to Project Administrators.
If either is missing, the repository is still added, and the portal shows a warning that Knowledge Base sync couldn't be enabled, with the reason. Fix the cause, then remove the repository and add it again, which sets up sync. Removing a repository clears its settings in the portal, so if you'd rather keep them, contact CodeLantern support instead. Sync is also set up again when a repository that needs reconfiguration is reconfigured in the portal.
To read the repository, sync uses the Azure DevOps connection of a member of your organization: the person who pushed, or another member with an active connection. Keep at least one member's Azure DevOps connection active, or sync stops.
Check that it worked
Azure sync doesn't produce a run log in your organization. A few minutes after a push to the default branch, open Repositories in the portal. The repository's row shows Knowledge Base: Synced and when it last synced. If it shows Retrying or Sync stopped, the row says why and what fixes it; see When a sync stops.
If the row still shows an older sync time, check that the push was to the default branch, that the repository shows as Active in the portal, and that at least one member has an active Azure DevOps connection. Then select Sync now on the row, and contact CodeLantern support if it still doesn't sync.
When a sync stops
Every member of your organization can see each repository's sync state on the Repositories page:
- Synced: the latest sync succeeded. The row shows when.
- Retrying: the latest sync failed for a reason outside your files, such as a brief outage, and CodeLantern is trying again on its own. You don't need to do anything, though the row still shows the cause in case it's one you can fix.
- Sync stopped: the latest sync failed and CodeLantern won't try again until something changes. The row shows the cause and the fix, when the repository last synced, when it started failing, and how many attempts have failed.
When files are rejected, the row lists each one with the reason and how to fix it. For a duplicate heading, it names the heading that appears twice. Fix the files in your repository and push to the default branch; the next sync picks up the fix. /cl-dev:doctor finds the same problems locally before you push.
When a cause lies outside CodeLantern, the row names where to fix it, for example restoring the CodeLantern GitHub App's access in GitHub, or reconnecting Azure DevOps in Personal settings.
While any repository's sync has stopped, the dashboard shows a banner naming it, for every member. The banner goes away on its own once the repository syncs again.
Sync now
Select Sync now on a repository's row to sync it straight away, for example after fixing a file or restoring access. Any member can use it. The row shows Syncing… until you reload the page, and then the result.
- Sync now isn't available while a sync is already queued or running, or while CodeLantern is retrying.
- Each repository can be synced on request once every 5 minutes, whoever asks, because every sync reads the repository through your provider. If you try again sooner, the row tells you when you can.
- A repository that is inactive or needs reconfiguration doesn't show its sync state or Sync now. Reconfigure or reactivate it first.