Manage with git

A repository can carry its own part of the runtime config in a .factory/ directory, so a change to how kōjō works on that repository is a commit: reviewed, merged and reverted like code.

What kōjō reads from a repository

File Becomes Details
.factory/skills/<name>/ with SKILL.md, goals.yaml, kit.yaml The repository’s own skills. They shadow the org’s and the built-in ones of the same name. Skills
.factory/schedules.yaml The schedules object in the repository’s scope Schedules
.factory/factory.yaml The repository’s settings/merge_policy factory.yaml

Everything else in the runtime config is org-wide and is not read from a repository: models and budgets, egress limits, the activation policy, which repositories are enabled, and access. Change those in the dashboard, with kojo config apply or through the HTTP API.

When it is read

sequenceDiagram
    participant Dev as Developer
    participant Forge
    participant Kojo as kōjō
    participant PG as Postgres
    Dev->>Forge: merge a change to .factory/ on the default branch
    Forge->>Kojo: push webhook
    Kojo->>Forge: read .factory/ at the default branch
    Kojo->>PG: new revisions in the repository's scope
    Note over Kojo: the same read happens when a session starts

kōjō reads .factory/ at the repository’s default branch on a push webhook to that branch, and again when a session starts. A change on another branch has no effect until it is merged.

What a repository cannot decide

.factory/ is written by whoever can change the default branch, which is a wider group than kōjō’s admins. So some things are not taken from it:

  • trigger_permission in factory.yaml is ignored. Who may trigger work is set by an admin.
  • mode: auto_merge in factory.yaml only works on a repository an admin has opted in with allow_auto_merge.
  • A skill whose kit.yaml asks for hosts or credentials beyond the scope’s settings/egress is dropped when skills are resolved and reported as a problem.

A broken file changes nothing

A factory.yaml or schedules.yaml that does not parse or validate is reported and ignored: the last good version stays in force. Removing schedules.yaml stops the schedules that came from it. Removing factory.yaml, or its merge_policy key, takes back an override that came from git, and the org’s policy applies again.

Check skill files before they are pushed:

kojo skills validate .factory/skills

Dashboard or git

settings/skills_source chooses one source of truth per scope.

Scope dashboard git
Org (org, default dashboard) Org skills are skill/<name> revisions in Postgres Org skills are read from .factory/skills/ of skills_repo, at its default branch
Repository (repo, default git) The repository’s .factory/skills/ are ignored; its skills are skill/<name> revisions in its scope The repository’s skills are read from its .factory/skills/, at its default branch

Resolution order for a session is the repository’s skills, then the org’s, then the built-in ones. A skill records which layers it shadows, and the skills listing shows them.

In either mode, a skill kept in the dashboard for a scope shadows the git skill of the same name in that scope, until the dashboard copy is deleted.

With git, hand edits arrive with the next push: kōjō reads .factory/ again on a push webhook to the default branch and when a session starts. With dashboard, kojo config export is the way to keep a copy in a repository: the export contains every skill/<name> object with its files. To move a scope to git for good, export it as files (next section).

The file formats are described in Skills.

Editing a setting that lives in git

Once the default branch holds a repository’s merge policy (a factory.yaml with a merge_policy key) or its schedules (a schedules.yaml), that setting is git-managed: the next read of .factory/ would put the file back over an edit saved in kōjō alone. So an edit made in kōjō becomes a pull request on the repository instead of a revision, wherever it is made: the dashboard’s forms and rollback, PUT /api/v1/config/object, MCP kojo_config_put and kojo_rollback, and kojo config apply.

sequenceDiagram
    participant P as Person
    participant K as kōjō
    participant F as Forge
    P->>K: change a repository's merge policy or schedules (dashboard, API, MCP, kojo config apply)
    K->>F: read .factory/ at the default branch
    alt the file holds the setting
        K->>F: commit to the open kojo/config-… pull request, or open one
        K-->>P: 202 and the pull request
        F->>F: people review and merge
        F->>K: push webhook to the default branch
        K->>K: SyncRepo writes the new revision
    else it does not
        K->>K: new revision, as before
        K-->>P: 200 and the revision
    end
  • What the pull request changes. kōjō edits the file, not the object: the keys you changed and nothing else. Comments and formatting stay, and a key you did not change stays as the file has it, including one the file leaves to its default. A schedule you did not change keeps its lines. The branch is kojo/config-merge-policy-<id> or kojo/config-schedules-<id>, started at the default branch’s head. The pull request is titled “Update the merge policy” or “Update the schedules”, is opened ready for review, closes no issue, and its description names who asked, their message and the whole change as a diff.
  • A second edit while kōjō’s pull request on that file is open adds a commit to it, with a comment showing that step, and rewrites the change in the description. Forms start from the pull request’s version of the setting, so adding schedule B after schedule A keeps A. When someone pushed to the branch in the meantime, kōjō builds on their commit; when it moves again during that second try, the edit is refused.
  • After the pull request is closed without merging, the next edit opens a new one from the default branch. The closed one’s branch is left alone.
  • Taking the policy back to the org’s. Saving the merge policy with inherit: true (or rolling back to such a revision) removes the merge_policy key; once merged, the repository takes the org’s policy.
  • trigger_permission is not written: the file cannot set it. A change of trigger_permission alone is refused; with other changes it is dropped and the answer says so. A repository whose own trigger_permission, set in kōjō, differs from the org’s cannot get its merge policy proposed: after the merge it would quietly take the org’s. Set it at the org, or remove the repository’s override, first.
  • Nothing changes until the merge. The merge’s push webhook makes kōjō read the file, and the new revision is authored git:<commit>.

A factory.yaml without a merge_policy key, or no file at all, keeps the setting in kōjō: an edit writes a revision, as before.

Answer When
202 with pull_request (number, url), updated and notes A pull request was opened (updated false), or kōjō’s open one got a commit (updated true). No revision is written.
200 with changed: false and git_managed: true The file, or kōjō’s open pull request, already holds this.
200 with the new revision The repository does not keep this setting in .factory/.
400 The content is not a valid object.
409 Refused, with the reason: a trigger_permission override, a change of trigger_permission alone, kōjō’s open pull request has lost the file or takes the policy back to the org’s (merge or close it first), or its branch moved twice.
422 The file on the default branch, or on kōjō’s open pull request, does not parse. Fix it in git first.
503 The forge did not answer, or refused the write. Nothing changed; try again.
500 kōjō’s edit of the file did not make the setting it was asked for. Nothing is pushed, and the server logs both.

GET /api/v1/config/object says which it is: git_managed, file (the object the default branch’s file makes), and pending (number, url and the content the pull request’s file makes) while kōjō’s pull request is open. A repository that keeps the setting in git before its first sync has no revision yet: the answer is then 200 without revision. The dashboard shows a banner above the form, starts the form from the pull request, else the revision, else the file, and its button reads Open pull request.

The merge policy page for github/acme/api: a banner saying pull request #1 is open and changes this setting, the form showing 45m as the time to answer in chat, the trigger permission select disabled, and an Open pull request button.
The merge policy of a repository that keeps it in .factory/factory.yaml, while kōjō's pull request on the file is open.

Moving a scope to git

A team that started in the dashboard can move a scope’s skills, and a repository’s merge policy and schedules, into .factory/ files, so later changes are reviewed in git. kojo config export --factory writes them (admin role), or kōjō opens the pull request itself (Moving from the dashboard):

kojo config export --factory ./api/.factory --scope repo:github/acme/api
kojo config export --factory ./skills-repo/.factory --scope org
Scope Files written
repo:<forge/owner/name> skills/<name>/… for each dashboard skill of the repository that is not deleted, factory.yaml with its merge_policy (unless it is inherit), schedules.yaml with its schedules
org skills/<name>/… only. The org’s skills repository is read for skills and nothing else, so the org’s merge policy and schedules stay in the dashboard.

What the command does:

  • It reads the same document as kojo config export and writes only the objects of the scope you name.
  • trigger_permission is left out of factory.yaml, because a repository cannot set it. When kōjō reads the file, the repository takes the org’s trigger_permission; the command says so when the repository had another one.
  • A file whose content starts with #! is written executable (0755), every other 0644.
  • Every path is checked, and the files are written inside the directory only. A path that would land outside it stops the command before anything is written.
  • A file that already exists with other content stops the command before anything is written, and the command names it. --force replaces such files. A file that exists with the same content is reported unchanged. Files the export does not name are left alone.
  • It prints each file as written, unchanged or replaced, then the objects of the scope that stay in the dashboard (egress limits, plan and the like), then the next steps.

The files take effect once they are on the default branch and kōjō has read them:

flowchart TD
    D["Dashboard objects of one scope"] -- "kojo config export --factory" --> F[".factory/ files: skills/, factory.yaml, schedules.yaml"]
    F -- "pull request, merged to the default branch" --> B["Default branch"]
    B -- "push webhook, or a session starts" --> R["kōjō reads .factory/"]
    R -- "factory.yaml, schedules.yaml" --> P["The repository's merge policy and schedules are replaced"]
    R -- "skills/" --> S{"settings/skills_source reads git for this scope?"}
    S -- no --> DB["The files are ignored"]
    S -- yes --> C{"A dashboard copy of the skill in this scope?"}
    C -- "yes, not deleted" --> DC["The dashboard copy runs"]
    C -- "no, or deleted" --> GS["The git skill runs"]
    DC -.->|"delete the copy"| GS
  1. Commit the files as .factory/ in the repository (for org, in the org’s skills repository) and merge them to the default branch.
  2. factory.yaml and schedules.yaml then replace the repository’s settings/merge_policy and schedules: there is nothing to delete for them. From then on an edit of them made in kōjō opens a pull request that changes the file (Editing a setting that lives in git).
  3. Skills are read from git only when settings/skills_source says so: repo: git (the default) for repositories, org: git with skills_repo naming the skills repository for the org. The command prints the current values.
  4. A dashboard copy shadows the git skill of the same name in its scope until it is deleted, and deleting it hands the name to the git skill. Once kōjō has read the files, delete the copies in the dashboard, or apply the document the command prints, which marks each exported skill deleted:
kojo config apply -i - <<'EOF'
version: 1
objects:
  - scope: repo:github/acme/api
    object: skill/fix-bug
    content:
      deleted: true
EOF

Deleting a copy before the files are read leaves the name to the org’s or the built-in skill until then.

Moving from the dashboard

A repository’s merge policy and schedules can move without a checkout. On Settings → Repositories an admin sees Move to the repository on a configured repository that has neither file, or a factory.yaml without a merge_policy key. It opens one pull request, on a branch kojo/config-move-to-repository-<id>, that writes the files kojo config export --factory would:

  • .factory/factory.yaml from the repository’s merge policy, unless it has none of its own or it is inherit. A factory.yaml without the key gains it, and its comments stay.
  • .factory/schedules.yaml from the repository’s schedules, when it has any.
  • A file that exists otherwise is left alone, and the answer names it. Skills are not moved: use kojo config export --factory for them.

The same through the API, the CLI and MCP (kojo_repo_factory):

curl -X POST -H "Authorization: Bearer $KOJO_TOKEN" \
  "$KOJO_SERVER/api/v1/repos/github/acme/api/factory"
kojo config export --scope repo:github/acme/api --pr

The answer is 202 with pull_request (number, url), created and left_alone. It is refused with 409 when there is nothing to move (no merge policy of its own and no schedules, or the files already hold them), when the repository’s trigger_permission differs from the org’s, or while an earlier move’s pull request is open; with 422 when one of the files there does not parse; with 400 for a repository kōjō cannot read through its forge. While it is open, an edit in kōjō of a setting it writes is refused with 409, because the merge would replace it; close the pull request to edit in kōjō again. Once it is merged, edits of these settings in kōjō open pull requests. A setting the file repeats exactly gets no new revision, so it keeps its revision’s author: removing the file later does not take it back, as for a setting written in kōjō.

The Repositories settings page: github/acme/api tagged merge policy in .factory, and github/acme/web with a Move to the repository button.
Settings → Repositories. Move to the repository is offered on github/acme/web, which keeps its merge policy in kōjō.

Keeping the rest in git too

The org-wide objects have no file in a repository, but the whole runtime config can be exported to one and applied from CI. See Config as code.

Scroll to move. + - zoom, 0 fit, Esc close.100%