Repository navigation
Conversation
Record the fork's relationship to upstream anomalyco/opencode (1.18.18 line, no re-pin) and the phase 0+1 plan covering the OC Kit domain model, branch strategy, and CI-first verification. Upstream: https://github.com/anomalyco/opencode
Introduce the OC Kit workflow/agent engineering layer in packages/opencode/src/ockit. Phase 1 delivers the typed domain model only; the workflow engine, hook dispatcher, artifact manager, CLI, and installer land in later phases. Schemas (types.ts): Kit, KitSkill, KitAgent, Workflow/WorkflowStep, KitHook, Mode, WorkflowState, WorkflowRun, Artifact, Checkpoint, OwnershipEntry/Manifest, OCKitConfig as Effect Schemas. Manifest (manifest.ts): loadManifest reads kit.json (prefers) or kit.yaml via Bun.YAML, validates against the Kit schema, and reports ManifestError. Parse/schema failures are effectful errors, never synchronous throws. Registry (registry.ts): OCKitRegistry service scans global <config>/kits and per-project config-dir kits/ lazily via InstanceState; all/get/require/dirs with NotFoundError and invalid-manifest skips. Resolver (resolver.ts): indexKit builds name-indexed maps; resolveFromKit throws ResolveError; resolveAcross searches kits in order. Ownership (ownership.ts): load/save/claim/detectUserEdits/planUpdate implement the ownership manifest with sha256 conflict detection and replace/preserve planning. Checkpoint (checkpoint.ts): create/list/read checkpoint snapshots under .oc/state/checkpoints recording per-file sha256. Config (config.ts): defaults, read, enabled, validate for the oc_kit section. Config schema (core): add optional oc_kit section to ConfigV1.Info. Tests: unit suites under packages/opencode/test/ockit for manifest, registry, resolver, ownership, checkpoint, config.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
There was a problem hiding this comment.
Pull request overview
Implements Phase 1 of OC Kit for packages/opencode: introduces the typed OC Kit domain model plus manifest loading/validation, kit discovery/registry, name-based resolution, ownership tracking, checkpoints, and oc_kit config plumbing (kept optional/backward-compatible in core config).
Changes:
- Added
packages/opencode/src/ockit/modules for OC Kit schemas/types and core domain services (manifest/registry/resolver/ownership/checkpoint/config) with an export surface. - Extended
packages/coreConfigV1 schema with an optionaloc_kitsection. - Added
packages/opencode/test/ockit/unit tests covering the new OC Kit modules.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| UPSTREAM.md | Documents fork/upstream relationship and divergence policy. |
| plans/260814-1636-oc-kit-phase0-1/plan.md | Captures Phase 0/1 implementation plan and scope boundaries. |
| packages/opencode/src/ockit/types.ts | Defines OC Kit domain schemas/types (Kit/Skill/Agent/Workflow/etc). |
| packages/opencode/src/ockit/manifest.ts | Implements manifest loading/parsing/validation for kit.json/kit.yaml. |
| packages/opencode/src/ockit/registry.ts | Adds registry service to discover/index kits from global + project config dirs. |
| packages/opencode/src/ockit/resolver.ts | Adds in-memory resolver for kit declarations (per-kit and across kits). |
| packages/opencode/src/ockit/ownership.ts | Adds ownership manifest load/save + conflict/edit detection + update planning. |
| packages/opencode/src/ockit/checkpoint.ts | Adds checkpoint creation/list/read for managed-file snapshotting. |
| packages/opencode/src/ockit/config.ts | Adds typed accessors/defaults/validation for oc_kit config section. |
| packages/opencode/src/ockit/index.ts | Exposes the public OC Kit module surface. |
| packages/core/src/v1/config/config.ts | Adds optional oc_kit section to ConfigV1.Info schema (backward compatible). |
| packages/opencode/test/ockit/manifest.test.ts | Tests manifest load/validation and json/yaml preference. |
| packages/opencode/test/ockit/registry.test.ts | Tests kit discovery/indexing and error/skip behavior. |
| packages/opencode/test/ockit/resolver.test.ts | Tests indexing + resolver behavior and missing-id error path. |
| packages/opencode/test/ockit/ownership.test.ts | Tests ownership claim/conflict detection/edit detection/update planning and persistence. |
| packages/opencode/test/ockit/checkpoint.test.ts | Tests checkpoint create/list/read and missing checkpoint failure. |
| packages/opencode/test/ockit/config.test.ts | Tests defaults and config validation/decoding. |
Suppressed comments (2)
packages/opencode/src/ockit/checkpoint.ts:58
- Checkpoint ids are documented as "newest first", but list() currently just reverses the directory entry order. Directory iteration order is not guaranteed, so this can return checkpoints in an arbitrary order. Sort ids first (they include Date.now(), so lexicographic sort matches creation time) before reversing.
const entries = yield* fs.readDirectoryEntries(dir)
const files = entries.filter((entry) => entry.type === "file" && entry.name.endsWith(".json"))
const ids = files.map((entry) => entry.name.replace(/\.json$/, ""))
return kit ? ids.filter((id) => id.includes(`-${kit}-`)).toReversed() : ids.toReversed()
})
packages/opencode/src/ockit/checkpoint.ts:68
- read() calls JSON.parse(raw) directly; invalid JSON will throw synchronously instead of failing with a typed CheckpointError. Wrap parsing in Effect.try and map parse failures to CheckpointError.
const raw = yield* fs.readFileStringSafe(path)
if (raw === undefined) return yield* new CheckpointError({ path, message: `No checkpoint "${id}"` })
const decoded = yield* Schema.decodeUnknown(Checkpoint)(JSON.parse(raw)).pipe(
Effect.mapError((err) => new CheckpointError({ path, message: Schema.TreeFormatter.formatIssueSync(err.issue) })),
)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /** Resolve a kit's own declarations by name; throws ResolveError when absent. */ | ||
| export function resolveFromKit(index: KitIndex, kind: KitIndexKeys, id: string) { | ||
| const found = index[kind].get(id) | ||
| if (found) return found | ||
| throw new ResolveError({ kind, id, kit: index.kit.id }) | ||
| } | ||
|
|
||
| type KitIndexKeys = "skills" | "agents" | "workflows" | "hooks" | ||
|
|
| const raw = yield* Effect.try({ | ||
| try: () => (hasJson ? JSON.parse(source) : Bun.YAML.parse(source)), | ||
| catch: (cause) => new ManifestError({ path, message: `Invalid ${KIT_MANIFEST_JSON} syntax: ${String(cause)}` }), | ||
| }) |
| const raw = yield* fs.readFileStringSafe(path) | ||
| if (raw === undefined) return { files: {} } | ||
| const decoded = yield* Schema.decodeUnknown(OwnershipManifest)(JSON.parse(raw)).pipe( | ||
| Effect.mapError((err) => new OwnershipError({ path, message: Schema.TreeFormatter.formatIssueSync(err.issue) })), | ||
| ) | ||
| return decoded |
| const fs = yield* FSUtil.Service | ||
| const id = `${Date.now()}-${input.kit}-${input.operation}` | ||
| const checkpoint: Checkpoint = { |
| /** | ||
| * A workflow step references one capability (a skill) plus optional per-step | ||
| * overrides. `run` names the skill; `as` is an optional local alias used when | ||
| * the same skill is referenced more than once in a workflow. | ||
| */ |
| export class NotFoundError extends Schema.TaggedErrorClass<NotFoundError>()("OCKit.NotFoundError", { | ||
| id: Schema.String, | ||
| available: Schema.Array(Schema.String), | ||
| }) {} |
| async function writeGlobalKit(home: string, kitId: string, manifest: unknown) { | ||
| const dir = path.join(home, ".config", "opencode", "kits", kitId) | ||
| await fs.mkdir(dir, { recursive: true }) | ||
| await Bun.write(path.join(dir, "kit.json"), JSON.stringify(manifest)) | ||
| } |
Summary
Implements Phase 1 of the OC Kit integration plan for the
vibecoder880/opencodefork: the OC Kit domain model — typed schemas, manifest loading/validation, kit discovery, resolution, ownership tracking, checkpoints, and config access. The workflow engine, hook dispatcher, artifact manager, CLI, and installer are explicitly out of scope (later phases).Changes
packages/opencode/src/ockit/(new)types.ts— Effect Schemas forKit,KitSkill,KitAgent,Workflow/WorkflowStep,KitHook,Mode,WorkflowState,WorkflowRun,Artifact,Checkpoint,OwnershipEntry/OwnershipManifest,OCKitConfig.manifest.ts—loadManifestreadskit.json(preferred) orkit.yaml(viaBun.YAML), validates against theKitschema, errors asManifestError(parse/schema failures are effectful, never sync throws).registry.ts—OCKitRegistryservice scans global<config>/kitsand per-project config-dirkits/lazily viaInstanceState;all/get/require/dirs,NotFoundError, invalid manifests skipped.resolver.ts—indexKitname-indexes declarations;resolveFromKitthrowsResolveError;resolveAcrosssearches kits in order.ownership.ts—loadOwnership/saveOwnership/claim/detectUserEdits/planUpdateimplement the ownership manifest with sha256 conflict detection and replace/preserve planning.checkpoint.ts—create/list/readsnapshots under.oc/state/checkpointsrecording per-file sha256.config.ts—defaults/read/enabled/validatefor theoc_kitsection.index.ts— export surface.packages/core/src/v1/config/config.tsoc_kitsection toConfigV1.Info(strictly backward-compatible).packages/opencode/test/ockit/(new)testEffect(layer)pattern.Verification
bun turbo test(test.yml) andbun typecheck(typecheck.yml) run on this PR.