Reference repositories

A session works on its own repository. A request can name others for the skills to read next to it: reference repositories. kōjō clones each one into a fixed directory of the workspace, and nothing in that directory ever becomes part of the session’s change. The built-in port-sdk skill uses one to port a change from another implementation of an SDK; a skill of your own can use them for anything that needs a second repository to read: a client checked against its server’s API, docs checked against the code they describe.

Reference repositories are read-only and belong to one request: the request names them, the skills read them, and nothing of them is published. To change several repositories of one product in one session, link them instead: a linked repository is configured once for a repository in the repos object, is cloned into every session on it at .kojo/linked/<name>, may be changed when the requester may change it, and gets a pull request of its own when it changed.

Naming one

A reference repository is the request input reference.<name>. The name is the directory it gets: lowercase letters, digits and dashes. The value says which repository, and optionally which part of it the work is about:

Value What is checked out What comes with it
github/acme/sdk-python The default branch Nothing
github/acme/sdk-python@v1.5.0 That branch, tag or commit Nothing
github/acme/sdk-python#412 The head of pull request 412 (GitLab: !412 works too) The pull request’s diff and its description
github/acme/sdk-python@v1.4.0..v1.5.0 The end of the commit range The diff of the range

A session takes at most four. A request gets them in one of these ways:

  • kojo run --reference github/acme/sdk-python#412 names the reference source; --reference upstream=github/acme/api@v2 gives it another name. The flag can be repeated.
  • An API request carries "inputs": {"reference.source": "github/acme/sdk-python#412"}.
  • A mention on a forge can name one repository the way forges write a reference to another repository: acme/sdk-python#412 or acme/sdk-python@v1.5.0, with or without the forge in front. The first one that is an enabled repository on the same forge, and that the mention may have, becomes the reference source. Any other is ordinary text.
  • A follow-up of a merged pull request (on_merge of the repos object) attaches that pull request as source. See port-sdk for a configuration. A follow-up on the repository the pull request was merged in attaches no reference: it works on the default branch, which holds the merge, and reads the pull request with get_pr_diff. It runs only for a merge into the default branch.

Where it is in the workspace

/workspace/                the session's repository
└── .kojo/refs/
    ├── source/            the checkout, a git repository of its own
    ├── source.diff        the change: a pull request's diff, or a commit range's
    └── source.md          a pull request's title, author, state, link and description
  • The clone is 50 commits deep and its HEAD is detached at what the request named.
  • A pull request’s diff and description are read by the core through the forge’s API and written next to the checkout. The diff is cut at 2 MiB. A commit range’s diff is made by git in the sandbox.
  • git in the workspace ignores .kojo/refs/ (an entry in .git/info/exclude), and the core leaves the directory out of every diff it takes, whatever is staged. So nothing under it shows in git_diff, counts for a constraint, is seen by the judge, or is pushed. A file a subagent copies out of it into the repository is part of the change like any other file.
  • Each subagent is told in its system prompt which reference repositories exist, where they are, and what they are about. What people wrote about the change, a pull request’s title and description, stays in the .md file and reaches the model as a file it reads.
  • read_file reads paths under .kojo/refs/. list_files and search cover the session’s repository only, so a skill that explores a reference needs exec: git -C .kojo/refs/source ls-files, git -C .kojo/refs/source grep -n pattern.
  • When a session uses a second sandbox image, the reference repositories are copied over with the workspace.
  • A pull request the session opens has a “References” section in its description: the name, the repository, the pull request or commits, the commit that was read, and the link.
  • A repository that tracks files of its own under .kojo/refs/, or has a symbolic link at .kojo, cannot be worked on with reference repositories: the session fails when it prepares the workspace.

How it is cloned

The sandbox holds no credential, and the kit of the skill does not need the reference’s host. The core clones a reference repository itself, before the first skill runs, with a clone credential that the forge adapter issues for that repository, the same way it issues the session’s own.

sequenceDiagram
    participant C as Core
    participant F as Forge adapter
    participant P as Proxy
    participant S as Sandbox
    C->>S: clone the session's repository, with its own clone credential
    C->>F: clone credential for the reference repository
    C->>P: policy of the sandbox, now the reference's git host and that credential only
    C->>S: git fetch into .kojo/refs/source
    C->>P: policy of the sandbox, the skill's again
    Note over S: the skill starts, the reference is a directory

While a skill runs, the forge’s credential in the proxy is the one of the session’s own repository. A skill that should fetch more of a reference than the clone holds cannot; name the ref or the range it needs in the request.

Who may name one

A reference repository is read with kōjō’s access, not the requester’s. Four rules decide. The first two are checked when the request is accepted, again when the session starts, and again each time a clone credential is resolved:

  • The request is trusted. It comes from an operator (the CLI, the API, the dashboard), from a mention by someone with the repository’s trigger_permission, or from an on_merge follow-up an operator configured. Any other request that names one is rejected.
  • The repository is enabled in the repos object, on a configured forge, and is not the session’s own. kōjō does not read a repository it was not enabled on. A repository that is disabled while a session runs is no longer cloned.
  • In a mention, the author can read it. The author needs at least read access to the repository they name, unless it is not private.
  • A private repository is not read for a public one. A session that can publish on a repository that is not private does not get a private reference repository. A dry run is exempt: it publishes nothing.

A request that names a reference repository it may not have is rejected, and a session whose reference stops being allowed fails. A mention is the exception, because people cite other repositories for many reasons: there the repository is left out, the mention is handled as if it had not named one, and the refusal is in the audit log as reference.refuse.

In a skill of your own

A skill does not declare reference repositories; the request brings them, under the names the skill’s instructions expect. Say the name in the instructions, and make a missing one a failed check instead of a guess:

---
name: check-client
description: Check this API client against the server's routes in the reference repository `server` and report every call that no longer matches.
model_tier: strong
tools: [read_file, list_files, search, exec]
---

The server this client talks to is the reference repository `server`, checked
out at `.kojo/refs/server`. List its routes, then find every call in this
repository that does not match one. Change nothing.
# goals.yaml
max_attempts: 2
checks:
  - name: server is attached
    run: test -d .kojo/refs/server
constraints:
  no_changes: true
judge:
  rubric: |
    - Every reported mismatch names the call in this repository and the route in the server.
kojo run --repo github/acme/client --skill check-client --reference server=github/acme/api@v2

In an eval fixture

An eval case has no forge to clone from. A case brings its reference repositories as files: a references/ directory next to repo/, with one directory per reference and, optionally, <name>.diff and <name>.md beside it. The engine places them under .kojo/refs/ where a clone would be and makes each directory a git repository with one commit.

evals/fixtures/port-sdk/truncate/
├── case.yaml
├── repo/                  the target, as the workspace
└── references/
    ├── source/            the source after its change
    ├── source.diff
    └── source.md
Scroll to move. + - zoom, 0 fit, Esc close.100%