Changing code

Six built-in skills change code: build-feature builds a feature, reproduce-bug and fix-bug turn a bug report into a failing test and then a fix, port-sdk carries a change from one implementation of an SDK to another, and write-tests and docs-sync add the tests and the documentation a pull request is missing. Their change is published as the repository’s merge policy allows: a draft pull request by default. “The package registries” in the kits are the ten hosts listed under What the kits have in common. How to change one of these skills for a repository is under Overriding a built-in skill.

build-feature

Builds a feature end to end from an issue or a request: understand, plan, implement with tests and docs, verify.

Tier strong
Tools get_issue, read_file, list_files, search, write_file, edit_file, exec, git_diff, memory_search, memory_save, set_output
Outputs TEST_CMD, ACCEPTANCE
Steps per attempt 120

What it does. The instructions are nine steps, in order:

  1. Understand. Read the request and every comment, write the acceptance criteria as observable behaviours, and record them as ACCEPTANCE. Where the request leaves a choice open, take the one that matches how the repository already does similar things and say so. If it cannot be built without an answer only a maintainer has, stop and ask.
  2. Learn the codebase. Read AGENTS.md, search team memory, and read the closest existing feature completely, including how it is wired in.
  3. Find the commands. Work out how the repository builds, tests and lints, run the tests of the area once, and record TEST_CMD. When the repository has them, also record BUILD_CMD and LINT_CMD.
  4. Plan. List the files to add or change, the smallest set that satisfies the criteria.
  5. Implement. In the style of the surrounding code, with input validation at the boundary, a migration when stored data changes and a config default when a setting is added.
  6. Test. Add tests for every acceptance criterion, including at least one failure case.
  7. Document. Update what describes the feature to a user.
  8. Verify. Run the build, the linter and the tests, then read its own diff and remove what is not part of the feature.
  9. Report. The criteria and how each is met, the choices made, what was left out, what to look at twice. Save one line to team memory when it learned an unwritten convention.

Its limits: one feature, one change; no changes to CI configuration, deployment manifests or .factory/; no weakening of existing tests.

Goals.

max_attempts: 3
checks:
  - name: builds
    run: ${BUILD_CMD}
    skip_if_unset: true
    timeout: 20m
  - name: tests pass
    run: ${TEST_CMD}
    timeout: 30m
  - name: lint
    run: ${LINT_CMD}
    skip_if_unset: true
    timeout: 15m
constraints:
  max_changed_lines: 1500
  # A feature without a test is not done.
  required_paths: ["**/*test*", "**/*spec*", "**/tests/**", "**/test/**", "**/__tests__/**"]
  forbidden_paths: [".github/**", ".gitlab-ci.yml", ".forgejo/**", "bitbucket-pipelines.yml", ".factory/**"]
judge:
  rubric: |
    - Every acceptance criterion recorded in ACCEPTANCE is implemented, and the report says where.
    - Each criterion has a test that would fail without the implementation, and at least one failure case is tested.
    - The feature is wired in end to end (reachable through the route, command, config or API it is meant for), not only implemented as an unused function.
    - User-facing docs describe the new behaviour.
    - No unrelated refactors, renames or formatting changes; no existing test was weakened.
    - The code follows the repository's conventions (see AGENTS.md).

The build and lint checks run only when the subagent recorded their commands. The change must touch at least one test file.

Kit. 4 CPUs, 8Gi memory, 40Gi disk. needs_docker: true. Egress: the package registries.

Outputs. TEST_CMD and ACCEPTANCE are required; BUILD_CMD and LINT_CMD are recorded when they exist. The feature is in the workspace.

Override. Copy to .factory/skills/build-feature/. If your repository always has a build and a lint command, add them to outputs in SKILL.md and drop skip_if_unset from their checks, so a run that skips them is rejected. Raise or lower max_changed_lines to the size of feature you want delivered in one change.

reproduce-bug

Turns a bug report into a failing automated test, without fixing the bug.

Tier strong
Tools get_issue, read_file, list_files, search, write_file, edit_file, exec, git_diff, memory_search, set_output
Outputs REPRO_TEST, REPRO_CMD
Steps per attempt 40 (default)

What it does. It reads the report and finds the code involved, then finds out how the repository runs tests (AGENTS.md, the Makefile, CI config, package manifests) and runs the existing tests of the affected package once. It writes the smallest test that exercises the reported behaviour and asserts the expected behaviour, next to the existing tests and in their style. It runs the test, which must fail on the assertion about the reported behaviour, not on a compile error or a typo. It records REPRO_TEST, the path of the test file, and REPRO_CMD, one command that runs only that test. It must not change non-test code or fix the bug. If the report cannot be reproduced, it says what it tried instead of writing a test that fails for another reason.

Goals.

max_attempts: 3
checks:
  - name: reproduction fails before the fix
    run: ${REPRO_CMD}
    expect_failure: true
    timeout: 15m
constraints:
  max_changed_lines: 200
  required_paths: ["**/*test*", "**/*spec*", "**/tests/**", "**/test/**"]
  forbidden_paths: [".github/**", ".gitlab-ci.yml", ".forgejo/**", "bitbucket-pipelines.yml", ".factory/**"]
judge:
  rubric: |
    - The new test targets the behaviour described in the bug report.
    - The test output shows an assertion failing for the reported reason, not a build or setup error.
    - Only test code changed.
    - REPRO_CMD runs just the new test.

The check runs the recorded command and passes only when it exits non-zero within 15 minutes.

Kit. 4 CPUs, 8Gi memory, 40Gi disk. needs_docker: true, because a reproduction may need to build images or start services. Egress: the package registries.

Outputs. REPRO_TEST and REPRO_CMD, which fix-bug uses later in the same session, and the new test in the workspace.

Override. Copy to .factory/skills/reproduce-bug/. Adjust required_paths if your tests live in paths the four globs do not match. Keep the two output names: the built-in fix-bug reads them.

fix-bug

Writes a minimal, tested fix for a bug, ideally one that already has a failing reproduction test.

Tier strong
Tools get_issue, read_file, list_files, search, write_file, edit_file, exec, git_diff, memory_search, set_output
Outputs TEST_CMD
Steps per attempt 40 (default)

What it does. It receives a bug report and, when one exists, a failing reproduction test (REPRO_TEST, run with REPRO_CMD). It finds the root cause until it can state it in one sentence, makes the smallest change that makes the reproduction pass, and does not modify the reproduction test; if it believes the test is wrong, it stops and says why. It runs the full test suite of the affected package and the linter if there is one, records TEST_CMD, and finishes with the root cause, what changed and why there, and what a reviewer should look at twice. No unrelated refactors, renames or formatting changes. Without a reproduction test, it adds a regression test for the fix.

Goals.

max_attempts: 3
checks:
  - name: reproduction passes
    run: ${REPRO_CMD}
    skip_if_unset: true
    timeout: 15m
  - name: package tests pass
    run: ${TEST_CMD}
    timeout: 30m
constraints:
  max_changed_lines: 300
  forbidden_paths: ["${REPRO_TEST}", ".github/**", ".gitlab-ci.yml", ".forgejo/**", "bitbucket-pipelines.yml", ".factory/**"]
judge:
  rubric: |
    - The fix addresses the root cause described in the analysis, not a symptom.
    - No unrelated refactors.
    - The reproduction test was not weakened, skipped or deleted.
    - The code follows the repository's conventions (see AGENTS.md).

The first check is skipped when no reproduction was recorded in the session. The second always runs.

Kit. 4 CPUs, 8Gi memory, 40Gi disk. needs_docker: true. Egress: the package registries.

Outputs. TEST_CMD, and the fix in the workspace.

Override. Copy to .factory/skills/fix-bug/. Common changes are a stricter max_changed_lines, more forbidden_paths, and a fixed lint check in goals.yaml when your repository has one command for it. The three files are shown and explained in the worked example.

port-sdk

Ports a change from another implementation of the same SDK to this repository: the same public API and behaviour, written the way this repository’s language and conventions do it, with tests and docs.

Tier strong
Tools get_issue, read_file, list_files, search, write_file, edit_file, exec, git_diff, memory_search, memory_save, set_output
Outputs TEST_CMD, SOURCE_CHANGE, DIFFERENCES
Steps per attempt 120

Inputs. The skill needs the other repository as the reference repository named source. The request names it, with the part of it the port is about:

reference.source What is ported
github/acme/sdk-python#412 Pull request 412. The checkout is its head, and its diff and description are next to it.
github/acme/sdk-python@v1.4.0..v1.5.0 A commit range. The checkout is its end, and its diff is next to it.
github/acme/sdk-python@v1.5.0 or github/acme/sdk-python A feature the request names in words, found in the checkout of that ref or of the default branch.

kōjō clones the source into .kojo/refs/source of the workspace before the skill starts. Nothing under .kojo/refs/ is ever part of the change.

What it does. The instructions are ten steps, in order:

  1. Read the source change. The diff, then the files it touches in the checkout: code, tests, docs, changelog.
  2. Map it. Write down what the change means to a user of the SDK: public API, behaviour, defaults, errors, what crosses a process boundary (wire names, config keys, environment variables), and its test cases. What is internal to the source implementation is left out. Record the map as SOURCE_CHANGE. When nothing in the change can be observed by a user, or this repository already has it, there is nothing to port: the skill changes nothing and reports why.
  3. Learn how this repository says the same things. Read AGENTS.md, search team memory, and read the closest existing feature here next to its counterpart in the source. That pair shows how names, optional arguments, errors and documentation were carried over before.
  4. Find the commands. Run the tests of the area once and record TEST_CMD. When the repository has them, also record BUILD_CMD and LINT_CMD.
  5. Port. Implement every item of the map. The behaviour is ported, not the text: this language’s error type instead of an exception, an options value instead of keyword arguments. What users of both SDKs see as the same thing stays the same: wire names, config keys, error codes, documented defaults.
  6. Port the tests. Every test case of the source change gets a test here with the same inputs and results, plus the cases this language makes possible.
  7. Docs and changelog. In this repository’s wording and format.
  8. Verify. Run the build, the linter and the tests, then read its own diff and remove what is not part of the port.
  9. Differences. List every place where the port deliberately differs from the source, and everything that could not be ported one to one, each with the reason. Record the list as DIFFERENCES, or none.
  10. Report. The source change, where each item of the map is in this repository, the differences, and what to look at twice. Save one line to team memory when it settled a mapping that later ports should repeat.

Its limits: this change and nothing else; nothing under .kojo/refs/ is edited; no changes to CI configuration, deployment manifests or .factory/; no weakening of existing tests.

Goals.

max_attempts: 3
checks:
  # The port is made from the reference repository, never from memory.
  - name: source is attached
    run: test -d .kojo/refs/source
  - name: builds
    run: ${BUILD_CMD}
    skip_if_unset: true
    timeout: 20m
  - name: tests pass
    run: ${TEST_CMD}
    timeout: 30m
  - name: lint
    run: ${LINT_CMD}
    skip_if_unset: true
    timeout: 15m
  # A port without a test is not done. A run that found nothing to port
  # changes nothing and passes.
  - name: a change comes with tests
    run: |
      changed=$(git -c safe.directory='*' status --porcelain)
      [ -z "$changed" ] || printf '%s\n' "$changed" | grep -Eiq 'test|spec'
constraints:
  max_changed_lines: 1500
  forbidden_paths: [".github/**", ".gitlab-ci.yml", ".forgejo/**", "bitbucket-pipelines.yml", ".factory/**"]
judge:
  rubric: |
    - Every item of SOURCE_CHANGE (public API, behaviour, defaults, errors) is implemented in the diff, or is listed in DIFFERENCES with a reason. If SOURCE_CHANGE says there is nothing to port, the diff is empty and the report says why.
    - The port is idiomatic: names, optional arguments, errors and documentation follow this repository's language and its existing API, not the source language's. It is not a line-by-line translation.
    - What users of both SDKs see as the same thing is the same: defaults, error conditions, wire names, config keys.
    - Each ported behaviour has a test that would fail without the implementation, and at least one failure case is tested.
    - User-facing docs describe the new behaviour, and the changelog has an entry when the repository keeps one by hand.
    - The report names the source change it ports and lists every deliberate difference; it agrees with DIFFERENCES.
    - No unrelated refactors, renames or formatting changes; no existing test was weakened.

The first check fails a run that was started without a source. The last one lets a run with nothing to port pass with an empty diff, and requires a test file in any other change. The judge sees this repository’s diff and the recorded SOURCE_CHANGE, not the source’s code: that is why the map is a required output.

Kit. 4 CPUs, 8Gi memory, 40Gi disk. No Docker. Egress: the package registries. The source repository’s host is not in the kit: the core clones it.

Outputs. TEST_CMD, SOURCE_CHANGE and DIFFERENCES are required; BUILD_CMD and LINT_CMD are recorded when they exist. The port is in the workspace, and becomes a pull request as the repository’s merge policy allows: a draft by default. Its description has a “References” section with the source repository, the pull request or commits, the commit that was read and the link.

Starting a port. There are four ways, and in each the request must be allowed to name the source: it is trusted, and the source is an enabled repository.

  • From the CLI, with --reference:

    kojo run --repo github/acme/sdk-go --skill port-sdk --reference github/acme/sdk-python#412
    kojo run --repo github/acme/sdk-go --skill port-sdk --reference github/acme/sdk-python@v1.5.0 "port the retry budget option"
  • Through the API, as an input of the session:

    curl -X POST "$KOJO_SERVER/api/v1/sessions" \
      -H "Authorization: Bearer $KOJO_TOKEN" -H "Content-Type: application/json" \
      -d '{"repo": "github/acme/sdk-go", "skill": "port-sdk", "inputs": {"reference.source": "github/acme/sdk-python#412"}}'
  • With a mention on an issue or pull request of the target repository, by writing the source the way forges write a reference to another repository:

    @kojo port acme/sdk-python#412

    The orchestrator picks port-sdk from the request. The author needs the trigger permission on this repository and must be able to read the source. kojo stands for your bot’s name.

  • As a follow-up: when a pull request is merged in the source repository, kōjō starts a port on every repository listed under its on_merge. The merged pull request is the source of each session.

This configuration ports every pull request merged in the Python SDK to the TypeScript and Go SDKs. Apply it with kojo config apply, or edit the repos object:

version: 1
objects:
  - scope: org
    object: repos
    content:
      repos:
        github/acme/sdk-python:
          enabled: true
          on_merge:
            - skill: port-sdk
              repos: [github/acme/sdk-typescript, github/acme/sdk-go]
        github/acme/sdk-typescript:
          enabled: true
        github/acme/sdk-go:
          enabled: true
sequenceDiagram
    participant F as Forge
    participant C as Core
    participant S as Sandbox of sdk-go
    F->>C: webhook, pull request 412 merged in sdk-python
    Note over C: on_merge of sdk-python lists port-sdk on sdk-go
    C->>S: clone sdk-go into the workspace
    C->>S: clone sdk-python at the pull request into .kojo/refs/source
    C->>S: write source.diff and source.md, read from the forge API
    Note over S: port-sdk maps the change, ports it and tests it
    C->>S: goal critic runs the checks
    C->>F: draft pull request on sdk-go that names pull request 412 of sdk-python

A follow-up session may change code, as a session an operator started would: an operator wrote the follow-up, and the merge was made by someone the source repository allows to merge. A target that is not enabled is skipped and the refusal is audited. A merge is followed once, however often the forge reports it. A pull request that a follow-up opened starts no follow-up when it merges, and a port is not followed back to the repository it was made from, so two repositories that list each other do not port back and forth. A merged pull request with nothing a user of the SDK can observe ends as a session with a report and no pull request.

Override. Copy to .factory/skills/port-sdk/ in the target repository. Put the mapping between the two SDKs that your team has settled (naming, error types, what is never ported) into the target’s AGENTS.md or .factory/memory/ rather than into the skill, so every skill sees it. If your SDKs share generated code, add its paths to forbidden_paths. Tighten the last check to your test layout if test|spec is too loose for it.

write-tests

Writes tests for the lines a pull request changed, in the repository’s own framework, that fail without the change when it changes behaviour.

Tier strong
Tools get_pr, get_pr_diff, get_issue, read_file, list_files, search, write_file, edit_file, exec, git_diff, memory_search, set_output
Outputs TEST_CMD (required); NEW_TESTS_CMD when the pull request changes behaviour
Steps per attempt 40 (default)

What it does. It reads the pull request’s diff and finds the changed lines that are not tests. It writes tests in the repository’s own framework and style, next to the existing tests, and never edits a file that is not a test. It records TEST_CMD, a command that runs the affected tests. When the pull request changes behaviour (a feature or a fix), it also records NEW_TESTS_CMD, a command that runs only the new tests. When it does not (a refactor), it leaves NEW_TESTS_CMD unset and says in the report why behaviour is unchanged. Without a pull request, it writes tests for what the task names.

Starting it. Mention kōjō on the pull request and ask for tests; list it under auto.pr_opened of the repository to run it on every new pull request (see automatic triggers); or run kojo run --repo github/acme/api --pr 412 --skill write-tests "write tests for this change". The tests come as a pull request of their own, stacked on the person’s: its base is the pull request’s branch.

Goals.

max_attempts: 3
checks:
  - name: tests pass
    run: ${TEST_CMD}
    timeout: 30m
  - name: new tests pass
    run: ${NEW_TESTS_CMD}
    skip_if_unset: true
    timeout: 30m
  - name: new tests see the change
    run: ${NEW_TESTS_CMD}
    on_base: true
    expect_failure: true
    skip_if_unset: true
    timeout: 30m
constraints:
  allowed_paths: ["@tests"]
  forbidden_paths: [".github/**", ".gitlab-ci.yml", ".forgejo/**", "bitbucket-pipelines.yml", ".factory/**"]
  max_changed_lines: 600
judge:
  rubric: |
    - The tests exercise the lines the pull request changed.
    - The assertions are specific: no tautologies, no snapshot of everything.
    - The tests follow the repository's existing framework and style.
    - No existing test was weakened or skipped.
    - When NEW_TESTS_CMD is unset, the report explains why the change keeps behaviour, and the diff agrees.

The first check runs the affected tests on the pull request’s head, the new ones included. The second runs only the new tests there. The third runs them on the code from before the pull request, with the session’s new test files on top, and must fail: tests that pass without the change do not test it. The second check is what stops a NEW_TESTS_CMD of false from passing the third. For a refactor both are skipped. allowed_paths: ["@tests"] fails any change outside test files, and the judge reads the pull request’s diff next to the tests.

How the core finds the code from before the pull request, and what happens when it cannot, is under checks against the code from before the pull request. When it cannot, the third check is unverified and the pull request stays a draft.

sequenceDiagram
    participant PR as Pull request
    participant S as write-tests
    participant C as Goal critic
    PR->>S: get_pr_diff: the changed lines
    S->>S: tests next to the existing ones, TEST_CMD, NEW_TESTS_CMD when behaviour changes
    S->>C: report
    C->>C: only test files changed (allowed_paths @tests)
    C->>C: TEST_CMD and NEW_TESTS_CMD pass on the head
    C->>C: NEW_TESTS_CMD fails on the code from before the pull request (on_base)
    C->>C: judge reads the tests and the pull request's diff
The replay of a write-tests session: its goal critic open, with the checks tests pass, new tests pass, and new tests see the change marked on the base, exit 1, passed.
The session page of a write-tests run: the third check ran on the code from before the pull request and failed there, as it must.

Kit. The same as fix-bug: 4 CPUs, 8Gi memory, 40Gi disk. needs_docker: true. Egress: the package registries.

Outputs. TEST_CMD, NEW_TESTS_CMD when the pull request changes behaviour, and the tests in the workspace. Only TEST_CMD is required, because a refactor has no NEW_TESTS_CMD.

Override. Copy to .factory/skills/write-tests/. Common changes are naming your test command in the instructions, narrowing allowed_paths to your test directories (for example ["tests/**", "**/*_test.go"]), and a smaller max_changed_lines.

docs-sync

Updates the documentation a pull request made untrue, and only that; reports what was checked when nothing needs changing.

Tier fast
Tools get_pr, get_pr_diff, read_file, list_files, search, write_file, edit_file, exec, git_diff, memory_search
Outputs none
Steps per attempt 40 (default)

What it does. It reads the pull request’s diff and lists every command, flag, config key, environment variable, path and behaviour the diff adds, renames or removes. It searches the documentation for each (the README, docs/, and every Markdown, MDX, reStructuredText and AsciiDoc file), and edits only what the change made untrue or left out, spelling each name as the diff does. It never writes a changelog entry and leaves unrelated documentation alone. When nothing needs updating, it changes nothing and says in the report what it searched for: that is a success, not a failure.

Starting it. A mention on the pull request; auto.pr_opened of the repository; kojo run --repo github/acme/api --pr 412 --skill docs-sync "bring the docs up to date"; or after a merge, through on_merge naming the repository itself:

repos:
  github/acme/api:
    enabled: true
    on_merge:
      - skill: docs-sync
        repos: [github/acme/api]

Only a merge into the default branch starts it; a merge into another branch, such as a stacked pull request merged into the branch it stacks on, does not. The session clones the default branch, which holds the merged change, reads the pull request with get_pr_diff, and opens a pull request of its own against the default branch, whose description says Follows #<n>. A pull request it opened starts no on_merge session when it merges. On an open pull request, its edits come as a pull request stacked on the person’s. Each run opens one, so a skill under auto.pr_updated, which runs on every push, would open one per push.

Goals.

max_attempts: 2
checks:
  - name: docs check
    run: ${DOCS_CHECK_CMD}
    skip_if_unset: true
    timeout: 15m
constraints:
  allowed_paths: ["**/*.md", "**/*.mdx", "**/*.rst", "**/*.adoc", "docs/**"]
  forbidden_paths: ["CHANGELOG*", "**/CHANGELOG*", ".factory/**", ".github/**", ".gitlab/**", ".forgejo/**"]
judge:
  rubric: |
    - Each edit follows from a change in the pull request's code.
    - Every command, flag, config key and path the edits add or rename is spelled as the pull request's diff spells it.
    - Docs unrelated to the change are untouched.
    - When nothing needed updating, the report says what was checked.

The docs check runs only when DOCS_CHECK_CMD has a value: a site build, a link checker, a script that compares the documented flags with the code. The value comes from the request (kojo run --input DOCS_CHECK_CMD="make docs-check", or inputs in the API) or from a repository’s override that writes the command into goals.yaml. The skill has no set_output, so the model cannot choose the command its own work is checked with. The judge reads the pull request’s diff next to the edits.

flowchart TD
    A["A pull request: a mention, auto, kojo run --pr"] --> R["Read the pull request's diff"]
    M["A merge: on_merge naming the repository itself, on the default branch"] --> R
    R --> E{"Did the change make any docs untrue?"}
    E -->|yes| W[Edit those docs only]
    E -->|no| N["Change nothing, say what was searched"]
    W --> K{"DOCS_CHECK_CMD given?"}
    N --> K
    K -->|yes| C[Run the docs check]
    K -->|no| J["Judge, with the pull request's diff"]
    C --> J
    J --> P["A pull request against the person's branch, or the default branch after a merge"]
    J --> Q["A report when nothing changed"]

Kit. 2 CPUs, 4Gi memory, 20Gi disk. No Docker. Egress: the package registries, because a docs check may install its tool.

Outputs. None; the edits in the workspace, or a report.

Override. Copy to .factory/skills/docs-sync/. Common changes are a fixed docs check in goals.yaml (run: make docs-check instead of ${DOCS_CHECK_CMD}), allowed_paths narrowed to where your documentation lives, and more forbidden_paths for generated reference pages.

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