@brandontroberts/sync-fork
Automatically sync forked Kody community packages with upstream in Kody Cloud using Graft's repo-mode fork mechanism.
Files
@brandontroberts/sync-fork
Kody package for keeping forked Kody community packages in sync with upstream using Graft — natively in Kody Cloud (workerd) by default, with optional Execution Context delegation when you configure host shell commands (testCommand or agentCommand).
Intent
Keep local customizations on forked Kody community packages working across upstream republishes without hand-porting diffs, running a local daemon, or losing track of why each fork diverged. When an upstream listing republishes, this package runs Graft's deterministic repo-mode fork sync directly in Kody Cloud over Git Smart HTTP (kody.packageGetGitRemote), adopts clean merges with full upstream two-parent git ancestry, and pushes conflict-marked -agent branches with a scoped upstream diff and .grafts/ Invariants when an agent is needed.
Quick start — hand it to your coding agent
Paste this once into Claude Code, Codex, Cursor, or any coding agent connected to Kody MCP (no Execution Context required):
Set up Sync Fork (/@brandontroberts/sync-fork) in my Kody account so my forked
Kody community packages stay in sync with upstream automatically in Kody Cloud.
1. Fork `/@brandontroberts/sync-fork` into my org (`communityFork`), publish it,
and enable its `community.fork.upstream_updated` subscription (`enablementEnable`).
No Execution Context is needed unless I later configure `testCommand` or `agentCommand`.
2. List my forked community packages (`packageList`), diff each against its
upstream listing, and ask me which ones to keep in sync and how (`branch`,
`push`, or `publish`, plus optional `allowZeroConflictPackageJson`, or
optional Execution Context `testCommand` / `agentCommand`).
3. For each fork I pick:
- check any `leftover_origin_references` from `communityFork`, run the fork's
tests first, and fix any remaining origin-scope references before baselining it,
- scaffold `.grafts/upstream-sync/graft.md` via `graft add --mechanism fork --in-place`
at its `origin_commit` (using `npx -y @graftsync/cli@latest` if `graft` is not installed),
- fill in Why, Invariants, Where to look, and Anchors (never write `kody:` +
another user's `@scope/` in `graft.md`),
- verify `graft sync` and the fork's tests pass, commit, push, publish, and save
its policy via `setPolicy`.
4. Smoke-test one onboarded fork via `packageSubscriptionDispatch` and confirm
`getRun()` shows `outcome: "green"`, `warnings: []`, and a populated `reportMd`,
running directly in Kody Cloud.
5. Summarize what was set up and how conflicts will be handled.How it works
- Each forked Kody package you want managed commits
.grafts/upstream-sync/graft.md(with Why, Invariants, Where to look, Anchors, History) and.grafts/upstream-sync/variants/fork.json({ "ref": "@worktree", "base": "@verified" }). Forks without.grafts/are safely skipped (skipped-no-graft). - When an upstream listing republishes, Kody delivers
community.fork.upstream_updatedto./src/on-upstream-updated.tsin Kody Cloud by default (no local machine required). - Cloud path (default):
- Resolves your fork's scoped name via
packageGetand mints a short-lived scoped write remote viapackageGetGitRemote. - Fetches both your fork and the upstream public listing (
https://kody.codes/@<origin>/<leaf>.git) in memory over Git Smart HTTP v1. - Evaluates Graft's repo-mode
forkrules natively inworkerd(fuzz-0 hunk anchors, boundary-line checks, binary/executable-mode changes, likely-upstreamed detection, and comment-preservingGraftDocumentEditorupdates). - Green: creates a two-parent merge commit (keeping upstream's
pinned_commitin git history, using your Kodygit_author), pushes according to policy (branchby default, orpush/publish), storesreportMdinpackageStorage(), and dispatches@brandontroberts/sync-fork.completeddirectly. - Conflicts (
needs-agent): performs a 3-way merge with conflict markers, updatesgraft.mdtostatus: conflicted, pushesgraft/agent-<short-sha>, savesconflicts+ scoped diff (reportMd) inpackageStorage(), and emits@brandontroberts/sync-fork.completed. - Tooling errors: fails loudly, records
outcome: "error"inpackageStorage(), and never pushes or publishes.
- Resolves your fork's scoped name via
- Optional Execution Context path (
testCommand,agentCommand, orexecution: "context"):- When a fork's policy configures host shell commands (
testCommandoragentCommand) or setsexecution: "context",./on-upstream-updatedautomatically schedules./sync-on-contextviaworkflows.create(usingexecutionContextif named, elserequires: ["fs"]withwhenOffline: "queue",queueMinutes: 1440). - On the Execution Context,
./sync-on-contextrunsgraft sync --json(falling back tonpx -y @graftsync/cli@latest), optionalagentCommand(always re-verified withgraft sync), and optionaltestCommand, then schedules./emit-sync-completedon Kody Cloud to dispatch@brandontroberts/sync-fork.completed. - Host commands are never silently skipped: if scheduling
./sync-on-contextfails, the run recordsoutcome: "error"loudly.
- When a fork's policy configures host shell commands (
Optional Execution Context setup (only for testCommand / agentCommand)
Skip this unless you configure testCommand, agentCommand, or execution: "context" on a fork policy:
kody login
kody auth setup-git
kody connect --name my-dev-box
kody context commands onImportant: Never write
kody:followed by another user's@scope/insidegraft.md— Kody's publish cross-scope scan checks docs too. Use plain@origin/<leaf>andhttps://kody.codes/@origin/<leaf>.git.
Policies (setPolicy)
| Field | Default | Meaning |
|---|---|---|
mode | 'branch' | 'branch' pushes graft/sync-<sha>; 'push' pushes to the default branch; 'publish' pushes and calls packagePublishExternalPush (respecting locked_at approval URLs) |
execution | 'cloud' | 'cloud' runs natively in Kody Cloud (workerd); 'context' delegates to an Execution Context via ./sync-on-context. Automatically 'context' when testCommand or agentCommand is set |
executionContext | unset | Optional named Execution Context for ./sync-on-context delegation (defaults to requires: ["fs"]) |
testCommand | unset | Optional host shell command run on an Execution Context before pushing a green merge (e.g. node --test test/*.test.ts); failures abort the push and mark needs-agent |
agentCommand | unset | Optional local coding-agent command run on an Execution Context on needs-agent (use full binary path + headless edit flags, e.g. /path/to/claude -p "$(cat "$GRAFT_PROMPT_FILE")" --permission-mode acceptEdits). Always re-verified with graft sync + testCommand |
graftCommand | auto (graft, else npx -y @graftsync/cli@latest) | Override how Graft is invoked on an Execution Context |
workspaceRoot | ~/.cache/kody-graft | Directory on an Execution Context where full fork clones are cached |
pushAgentBranch | true | Push graft/agent-<sha> with conflict markers on needs-agent |
allowZeroConflictPackageJson | false | Opt-in: when the only missed anchor is package.json (e.g. upstream bumped "version" inside -U3 context of communityFork's "name" rewrite) and 3-way merge has zero conflicts, adopt the merge cleanly |
When a conflict needs your agent
Hand any needs-agent run to your coding agent:
Check `listRuns` on `@<you>/sync-fork` and resolve the `needs-agent` sync for
`@<you>/<leaf>` following the `sync-fork` skill. Preserve every Invariant in
`graft.md`, verify with `graft sync` and the package's tests, and summarize what
changed before publishing.Exports
setPolicy/getPolicy/listPolicies/deletePolicy— manage per-fork sync policies inpackageStorage()listRuns/getRun— inspect recent sync runs, conflicts,agentRan,approvalUrl, and.grafts/.report/sync.md(reportMd)syncFork— trigger a manual sync for a fork against a specific upstream commit SHA (runs in Kody Cloud by default)./on-upstream-updated— Kody Cloud subscription handler forcommunity.fork.upstream_updated./sync-on-context— Execution Context workflow export scheduled automatically when a fork configurestestCommand,agentCommand, orexecution: "context"./emit-sync-completed— Kody Cloud workflow export scheduled by Execution Context runs to dispatch@brandontroberts/sync-fork.completed
Emitted events
@brandontroberts/sync-fork.completed— subscribe from any email/Discord/notifier package in your org to get alerts on green syncs,needs-agentconflicts, approval URLs, or errors. Dispatched directly in Kody Cloud (or via./emit-sync-completedafter Execution Context runs).
Publishing from this repository
Trigger the manual Release Kody package workflow (.github/workflows/release-kody.yml) from the Actions tab (or gh workflow run release-kody.yml). It runs packages/kody tests and kody dev check --offline, mints an Artifacts git remote via packageGetGitRemote, pushes the packages/kody subtree, and runs kody package publish.
Required repository secret: KODY_API_TOKEN (a user-owned kody_at_… token with package:read, package:write, and package:create scopes).
License
MIT