A plain `run` rejects an ask it cannot answer and lets the model continue; the run now ends non-zero with the diagnostic instead of reporting success. `--auto` runs are unchanged: an approved ask is not counted, and a rejected sandbox escalation stays an expected autonomous outcome.
Upstream sync tooling (Kilo v2 line)
Scripts to sync Kilo's v2 branch with upstream OpenCode, release by release, and to keep Kilo's patches in shared upstream files small and visible.
- Integration branch:
origin/v2. Upstream source:upstream/dev(upstream's v2 line since 2026-10-10). Never mergeupstream/v2: it is frozen at4617210822b. - Each sync merges one release commit: the parent of a
v2.x.ytag. Upstream tags a version-bump commit next todev, so the tag itself is not on the branch. - Sync each release in order, at least weekly. One PR per release, from a branch off
origin/v2. - The merge commit message is
chore(upstream): sync v2.x.y (<sha11>). The checks use it to find the pinned upstream release. - Merge the PR with "Create a merge commit". Never squash or rebase: that drops the upstream ancestry, and the next sync conflicts again.
- Upstream package names (
@opencode/*) stay until decision D-1. The package-name transform and the branding codemods are in the code but off inutils/config.ts.
v1 (main) keeps its own copy of this tooling. This copy is for the v2 line only.
Quick start
git remote add upstream https://github.com/anomalyco/opencode.git # once
bun install --cwd script/upstream # once, for the codemods (ts-morph)
bun script/upstream/list-versions.ts # releases, which ones v2 has, next target, lag
bun script/upstream/list-versions.ts --json # the same as one JSON object, for scripts
bun script/upstream/analyze.ts # dry run of the next sync: conflicts, new workflows, shared files and mirrors touched
bun script/upstream/merge.ts # merge the next release into a new branch sync-v2-x-y from origin/v2
bun script/upstream/merge.ts --version v2.0.27 # a given release
In an Agent Manager worktree that is already on a fresh branch from origin/v2, merge in place: bun script/upstream/merge.ts --base-branch HEAD.
What merge.ts does
- Checks the
upstreamremote and a clean working tree. mergiraf is optional (brew install mergiraf). - Fetches
upstream/devwith tags, andorigin/v2. - Picks the target: the next release that the base does not have, or
--version. It refuses a target that skips an older release (--allow-skipoverrides) and a commit that is not onupstream/dev. - Analyzes the merge with
git merge-treeand prints the report: conflicts with a recommendation, new upstream workflows, shared files that Kilo patched and upstream changed, commits added to history, harness change size, and the lag before and after (releases and days). - Creates
sync-v2-x-yfromorigin/v2(or uses the current branch with--base-branch HEAD), enables rerere and trains it from earlier sync merges. - Runs
git merge --no-ff --no-commitwith the sync message, then resolves what it can. The merge and the analysis turn off directory rename detection (merge.directoryRenames=false). Otherwise a removed upstream folder looks renamed into a Kilo copy (packages/session-uiintopackages/kilo-ui-base), and git moves new upstream files into the copy, whereskipFilesdoes not remove them.bun script/check-workflows.ts --fix: removes workflows that Kilo dropped. This also resolves their modify/delete conflicts.skipFiles: removes upstream changes and additions under the product areas Kilo removed (desktop, web app, hosted platform, seeutils/config.ts). This also resolves their modify/delete conflicts.keepOursand Kilo-owned paths (utils/owned.ts): keep Kilo's version.- mergiraf: syntax-aware resolution, staged only when no marker is left.
- package.json:
transforms/transform-package-json.ts(take upstream, re-apply Kilo's listed fields). - Branding transforms: only when
transforms.brandingis on. - Lock files: keep ours, then regenerate with
bun install(only with the Bun version frompackageManager).
- Runs
bun script/check-workflows.tsand lists unexpected workflows. - If conflicts or unexpected workflows are left, it stops with the merge in progress and writes the report. Otherwise it commits the merge, runs
script/check-opencode-annotations.ts,script/check-shared-patches.tsandscript/check-mirrors.ts --drift, and writes the report. A mirror behind the pinned release stops the sync before any push.
Reports go to $(git rev-parse --absolute-git-dir)/upstream-sync/report-<tag>.md, so they are never committed.
Options
| Option | Use |
|---|---|
--version <tag> |
Release to sync, for example v2.0.27 |
--commit <sha> |
Pin a commit on upstream/dev. Only for an unreleased fix that Kilo needs |
--base-branch <name> |
Base branch (default v2, read from origin/v2). HEAD merges into the current branch in place |
--branch <name> |
Sync branch name (default sync-v2-x-y) |
--dry-run, --report-only |
Analysis and report only |
--allow-skip |
Allow a target that skips older releases |
--no-fetch |
Do not fetch |
--no-worktrees |
No read-only reference worktrees |
--no-install |
Do not regenerate lock files |
--push |
Push the sync branch after the merge commit (off by default) |
--output <path> |
Report path |
Reference worktrees (.worktrees/upstream-sync/): upstream (pristine release commit), kilo-base (the base before the merge) and auto-merge (the automated merge with its conflicts). They are read-only evidence.
Resolving what is left
-
Keep Kilo's
kilocode_changelines and take upstream's other changes. Never drop upstream code without a reason in the PR. -
When a conflict hits a Kilo patch, check the plugin-first order (
migration-tracking/principles.md, section 2) before you re-apply it, and record the result in the sync PR:- Kilo plugin on the public plugin API (
@opencode/plugin). - Kilo host (
packages/kilo-cli):SdkPlugins.register, Effect layer overrides such asGlobal.layerWith, environment translation at the entry. - Small, generic seam patch in a shared file, marked
kilocode_change, in a file that changes rarely. - Feature patch in a shared file, marked, last resort, with the reason in the PR.
- Branding and product strings: automated renaming in Kilo-owned code (the interim adapter from #15417, mapping reviewed at every sync), never hand edits.
Move the code in a follow-up PR: the sync PR contains only the merge and the conflict resolutions.
- Kilo plugin on the public plugin API (
-
New upstream workflow: review it, add it to
activeorremovedinscript/check-workflows.ts, thenbun script/check-workflows.ts --fix. -
Mirror listed under "Mirrors touched": upstream changed a file that Kilo copies into a Kilo-owned path, so the merge took the upstream change and left the copy behind. Re-merge the change into the copy, keep the
whyandinvariantsinscript/upstream/mirrors.jsontrue, and record the new upstream SHA there. The sync stops untilbun script/check-mirrors.ts --driftpasses. -
Conclude with
git commit --no-editto keep the sync message. -
.kilo/agent/upstream-merge.mdhas the detailed resolution workflow.
Verify a sync
bun install
bun script/check-workflows.ts
bun run check # or bun typecheck in packages/core, cli, server, tui, plugin
bun script/check-opencode-annotations.ts
bun script/check-shared-patches.ts
bun script/check-mirrors.ts --drift
bun script/upstream/progress.ts # validates the map inputs; do not commit the generated files
Then run focused tests in packages/core, cli and server with the test isolation from .kilo/skills/v2-migration/SKILL.md, run the same tests on origin/v2, and classify each failure as new or already failing. Self-test the CLI as the skill describes (VERIFICATION_TEST.md).
The sync PR body gives: release and SHA, lag before and after, each conflict and its resolution, shared files touched, mirrors touched with the re-merged change and recorded SHA, tooling gaps, the test comparison, self-test evidence, and in bold: Merge with 'Create a merge commit'. Do not squash or rebase.
Shared-patch checks
Both checks compare the tree with the pinned upstream release commit: the second parent of the newest chore(upstream): sync merge in the history, or the initial base of v2 (5e73d5cb1f7, release commit of v2.0.26) before the first sync. They need no network, only a full history.
bun script/check-opencode-annotations.ts [--worktree] [--pin <ref>]: fails on a Kilo line in a shared upstream file without akilocode_changemarker. A file that cannot carry markers (JSON) needs anunmarkedreason inshared-patches.json.bun script/check-shared-patches.ts [--worktree] [--json] [--pin <ref>]: prints each shared file that Kilo adds or changes, its marked and unmarked lines, and the shared files Kilo deleted. It fails when a shared file has no entry inshared-patches.json(rung and missing seam), or when a count grows above its limit. A PR that adds a shared patch adds the entry and raises the limit in the same diff. Deleted workflows are not counted:script/check-workflows.tsgoverns them. Paths inskipFilesare not shared files and are not counted. Generated files (bun.lock, listed inutils/owned.ts) are listed but not counted: they follow from thepackage.jsonfiles, so a new Kilo-owned package does not trip the checks.
CI runs both in .github/workflows/kilo-v2.yml (job shared upstream patches), and the tests of this directory (job upstream sync tooling tests).
Mirror checks
A mirror is a Kilo-owned copy of an upstream file (the host entry, a replaced tool). Upstream never edits Kilo-owned paths, so a change to a copied upstream file merges cleanly at its own path and the copy drifts with no conflict and no report line. script/upstream/mirrors.json lists every mirror: the upstream path, the Kilo copy, the upstream blob SHA last verified against the pinned release, why Kilo copies the file instead of using an upstream extension point, and the invariants a re-merge must keep. Each copy starts with // kilo_mirror: <upstream path>.
The entry describes decisions, not an inventory: the upstream diff shows which lines differ, so an invariant earns its place by saying what must stay true after upstream reshapes the file (an import scheme, an ordering, a deliberate omission). A drifted mirror prints its why and invariants, and the sync rewrites them when the divergence set changes.
bun script/check-mirrors.ts [--json] [--registry <file>] checks the registry structure and needs no pin: a registered copy is missing, its kilo_mirror marker is missing or names another path, or a copy declares a marker with no registry entry. CI runs it in the shared upstream patches job, because a PR that adds a copy can fix all of that.
bun script/check-mirrors.ts --drift [--pin <ref>] adds the pin comparison and fails when the pinned upstream file changed or disappeared since the recorded SHA. --pin implies --drift. Only a sync can act on that result, so the sync runs it and does not finish while a copy is behind: merge.ts stops after the merge commit, writes the report and exits non-zero before any push. It passes the commit it merged with --pin, because a --commit sync's merge is not a release and pinned() would resolve the previous release. The fix is to re-merge the upstream change into the copy (git diff <recorded sha> <pin>:<upstream path>), keep what the entry requires, then record the new SHA. The sync report lists the same files under "Mirrors touched".
Progress map
bun script/upstream/progress.ts generates migration-tracking/progress/README.md, progress.json, progress.svg (treemap: one box per feature, green done, grey open, yellow dropped) and history.svg (one point per day, read from the committed progress.json files on the first-parent history): Kilo's v1 feature delta as cells per feature (modules, API operations, feature-attributed patches, tests), each checked against the v2 working tree. Unattributed shared-file hunks are not counted in the progress total (existing unattributed: proofs and dispositions remain valid, and --list unattributed:<area> still lists them for inspection). A patch cell closes with a done-proof that carries its ID: kilocode_change(<feature>:<id>) in a shared upstream file or kilo_port(<feature>:<id>) in a Kilo-owned file; the map records the rung where it landed (plugin, host, seam, patch). The summary also carries two ratchets: the core-internal upstream modules that Kilo packages and adapters import (the run fails when a packages/kilo-*-core logic package imports @opencode/*), and the shared patches by rung in shared-patches.json. Inputs are migration-tracking/progress/features.json (pins, feature split, exclusions), dispositions.json (decisions per cell) and shared-patches.json (rungs). CI job migration progress map validates the inputs on PRs and fails when a PR other than the map bot PR commits the generated files. On pushes to v2, CI regenerates the map and opens or updates the bot PR when the generated files change; the map on v2 updates when that PR is reviewed and merged. --root <dir> runs against another checkout or worktree; the value resolves from the current directory (CI passes ../base). --check fails when the committed output is stale, which is the expected state on a feature branch while a bot PR is pending; it is the check the map bot PR runs against its own regenerated commit. In this directory, bun run progress:check-bot runs that check for the bot branch; do not use it as an author check while a bot PR is pending. --outputs prints the generated file paths; --list <feature> prints the open cells of one feature; --compare <base.json> <head.json> [<pr.diff>] prints the markdown delta that the CI job migration progress comment posts on every same-repository feature pull request (one comment, updated per push, from maps generated for the base and the PR). With the PR diff it adds the placement line: new marked lines in shared files by rung, new kilo_port annotations and new core-internal imports. When the PR adds lines in Kilo-owned package files and closes no cell, it replaces "No change to the progress map." with a sentence that names the added lines and asks for a done-proof or a disposition, so a silent port is visible in review. badge.svg and the two charts are embedded in the root README.md inside a marked block. The pins name the v1 target (a main commit) and the upstream commit it was synced to. Move them together when the v1 reference moves, in a PR of their own, and expect patch IDs of changed hunks to change with them; dispositions.json entries and done-proofs that no longer resolve fail the run and must be updated in the same PR. .kilo/skills/v2-migration/SKILL.md describes how a port closes cells. After a local run, restore the generated files with git checkout HEAD -- $(bun script/upstream/progress.ts --outputs). Do not restore them from origin/v2: that stages a newer map onto an older branch and produces the diff the guard rejects.
Feature placement
bun script/upstream/placement.ts <path-or-module> answers, for one module, the questions of .kilo/skills/v2-feature-placement/SKILL.md steps 2 to 6, with no model and no network. The input is a repository path or a module specifier (@opencode/core/session/compaction). It prints: whether the file is Kilo-owned; the plugin domains whose name or hook names match the module (hooks, editor methods, domain members, from packages/plugin/src/effect/); the upstream plugins that are the file, call transform on its service, or import it, with their ctx uses, services and editor calls; for a builtin tool, the ToolEditor.update and remove plus add calls; the service nodes with their kind and the host call (Global.node.replace(Global.layerWith(...))) for packages/kilo-cli/src/host.ts, and the OPENCODE_* variables it reads; the shared-patches.json entries and kilocode_change markers for the file; and the lowest rung to start on. --json prints the same data. --pin <ref> sets the upstream commit for the Kilo-owned check; without a pin in the history (a shallow clone) the check uses the path patterns of utils/owned.ts only.
bun script/upstream/placement.ts --imports [--json] checks the import rule of .kilo/skills/v2-feature-placement/SKILL.md (step 6): it fails when a logic package (packages/kilo-*-core/src) imports @opencode/*, and it prints the distinct core-internal modules (under packages/core/src, not Kilo-owned) that each adapter (packages/kilo-*/src, packages/*/src/kilocode) imports, and their total.
Per-file tools
| Command | Use |
|---|---|
bun script/upstream/fix-kilocode-markers.ts <file> [--dry-run] |
Rebuild the markers of one shared file from its diff with the pinned upstream release. It refuses a file where Kilo deleted upstream lines (the standalone marker that explains a deletion would be lost) unless --force |
bun script/upstream/reset-to-upstream.ts <file> [--dry-run] |
Reset one file to the pinned upstream release (with the enabled transforms). It refuses a file listed in shared-patches.json unless --force |
bun script/upstream/find-reset-candidates.ts [path] [--dry-run] |
Find shared files whose diff with upstream is only kilocode_change markers, and reset them. Whitespace-only and small real diffs are listed for review, never reset, and files in shared-patches.json are skipped |
script/upstream/find-conflict-markers.sh <file> |
Print the conflict markers of a file |
Transforms and codemods
| Tool | v2 state |
|---|---|
transforms/keep-ours.ts |
On. Kilo-owned paths and keepOurs (empty on v2) |
transforms/skip-files.ts |
On. skipFiles lists the upstream product areas Kilo removed. Workflows go through script/check-workflows.ts |
transforms/lock-files.ts |
On. Keep ours, regenerate with the pinned Bun |
transforms/transform-package-json.ts |
On for conflicted package.json files. Re-applies Kilo's root dev and lint scripts |
transforms/package-names.ts |
Off until decision D-1 (transforms.packageNames). Package renames apply to Kilo-owned code too (for example packages/kilo-plugin imports @opencode/plugin), so Kilo imports follow the rename |
transforms/preserve-versions.ts |
Off: v2 follows upstream version numbers (transforms.versions) |
transforms/transform-i18n.ts, transform-take-theirs.ts, transform-scripts.ts, transform-extensions.ts, transform-web.ts |
Off until rebranding (transforms.branding) |
codemods/transform-strings.ts, codemods/transform-imports.ts |
Off until rebranding. Default is a dry-run report of each change; --apply writes |
Brand-text tools never touch Kilo-owned paths (utils/owned.ts); package-name tools (package-names.ts, transform-imports.ts) do, so Kilo imports follow a rename. Each branding CLI prints a dry-run report by default (bun script/upstream/codemods/transform-strings.ts). --apply writes, and refuses while the switch is off unless --force is given.
Not ported from v1 (yet)
| v1 tool | Reason |
|---|---|
opencode-changesets.ts, script/kilocode/changeset-version.ts |
Postponed. The v2 line has no changesets yet. Port them (as in v1: one changeset per sync with the upstream release notes) with the first v2 channel release |
transforms/remove-kilo-web.ts |
Its target (WebCommand in packages/opencode/src/index.ts) does not exist on v2 |
Pre-merge compatibility branch (refactor: kilo compat for) and .opencode-version |
It pre-applied the renames to upstream so they did not conflict. With renames off it only adds a commit. The pin comes from the sync merge message instead. Bring it back when the rename transforms turn on (D-1, rebranding) |
| Version resync after a merge | v2 follows upstream version numbers |