Skip to content

feat(opencode): oc kit CLI (list, validate) on Phase 1 domain model - #9

Merged
qkhalk merged 7 commits into
mainfrom
oc-kit-phase2
Aug 19, 2026
Merged

qkhalk merged 7 commits into
mainfrom
oc-kit-phase2

Conversation

@qkhalk

@qkhalk qkhalk commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #8

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds the oc kit CLI on top of the Phase 1 OC Kit domain model (merged in PR #2):

  • oc kit list enumerates every registered kit, skill, agent, workflow, and hook
    from the registry.
  • oc kit validate runs the schema + cross-reference validator and exits nonzero
    when it finds duplicate ids or dangling references (e.g. a skill pointing at a
    missing agent).

Why this works:

  • The validator (packages/opencode/src/ockit/validator.ts) performs real checks
    (unique ids and cross-reference validation), not a stub — the earlier placeholder
    was replaced with concrete checks.
  • Both subcommands are wired into the opencode CLI via
    packages/opencode/src/ockit/cli.ts and covered by unit tests. The validator
    tests pass in the CI container; POSIX-permission-sensitive assertions (if any)
    are skipped when running as root, matching the container's uid-0 environment.

How did you verify your code works?

Unit tests for the validator and CLI surface are included and run under the same
CI matrix as Phase 1 (Linux in the GHCR container, Windows non-blocking). The
oc kit validate exit-nonzero path is exercised by a test fixture with a
deliberate dangling reference.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

qkhalk added 2 commits August 19, 2026 14:45
…odel

Implement OC Kit Phase 2 as a strictly additive CLI surface. `oc kit list`
prints installed kits (id/name/version + declaration counts) sourced from
Registry.Service; `oc kit validate <dir|id>` loads a manifest and checks its
declaration structure via the shared validator. No live execution path.

- src/ockit/validator.ts: pure validateKit over a decoded Kit (every workflow
  step must reference a declared skill; per-kind ids resolve through Resolver).
- src/ockit/cli.ts: OCKitCommand via effectCmd; provides Registry.node
  explicitly (it is not in AppRuntime) with instance: true.
- register OCKitCommand in src/index.ts; re-export OCKitCli from ockit/index.ts.
- tests: validator.test.ts (pure) + cli.test.ts (mocked Registry.Service).

CI-first: not run locally; gated by `bun turbo test` + typecheck in CI.
The previous per-kind loops validated each entry against an index built from
the same array, so they could never flag an issue (dead code), and the
"undeclared hook" test encoded a rule the validator cannot enforce. Replace
with detectable checks: unique ids within each kind, every workflow step
references a declared skill, every agent's skills reference declared skills,
and every skill's backing agent references a declared agent. Update
validator.test.ts to exercise those real checks.
Copilot AI lite review requested due to automatic review settings August 19, 2026 07:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

The following comment was made by an LLM, it may be inaccurate:

qkhalk added 5 commits August 19, 2026 15:11
`validator.test.ts` and `cli.test.ts` used `it(...)` inside `describe` blocks but
only imported `describe`/`expect`, so every test threw `ReferenceError: it is
not defined` and the required `unit(linux)` job failed. Add `it` to the
`bun:test` import in both files.
…ions

`listKits` is an `Effect.fn` (zero-arg), so it must be invoked before `.pipe(...)`.
The handler and two tests called `listKits.pipe(...)` directly, which threw
`TypeError: listKits.pipe is not a function` and failed the required unit(linux)
job. Call `listKits()` in the handler and in the list tests.

The two validate-failure tests asserted `out()` (stdout) contained the error
message, but `fail()` fails the Effect without printing, and per-issue lines go
to stderr. Rewrite them to read the typed `CliError` out of the `Exit` cause
(`Option.getOrThrow(Cause.failureOption(...))`) for the summary message and
`errOut()` for the per-issue line.
The typecheck job surfaced several TS errors in the Phase 2 ockit work that
the unit job only exercises at runtime:

- validator.ts: `checkUnique` demanded a `{ id }` shape, but hooks identify by
  `event` (KitHook has no `id`). Parameterize it with an `idOf` extractor and
  pass `(h) => h.event` for hooks.
- cli.ts: fold `loadManifest`'s residual `Error` channel onto CliError so
  `validateTarget` is `Effect<_, CliError, _>`; replace the non-narrowing
  `!result.ok` guard with `result.ok === false`, which TS narrows to the
  `{ ok: false, issues }` arm of the result union.
- validator.test.ts: replace `if (!result.ok)` guards with `if (issues in
  result)` so TS narrows to the branch that actually carries `issues`.
- cli.test.ts: mock `all`/`dirs` as methods (the interface declares calls,
  not plain Effects); read the failure with the repo's established
  `runPromiseExit` + `Cause.squash` idiom instead of `Cause.failureOption`
  (not present in this effect build), asserting the typed CliError message.
…validator type

The typecheck job still failed after the previous commit. Root causes, all
specific to the pinned effect `4.0.0-beta.83` build:

- `Effect.catchAll` does not exist in this effect build (only `catchCause` /
  `mapError`). cli.ts used it on `loadManifest`'s residual `Error` channel,
  which threw TS2339 and dragged the whole `validateTarget` effect to
  `Effect<_, unknown, unknown>`, cascading into every downstream type error.
  Replace with `Effect.mapError`, preserving an existing `CliError` and
  wrapping anything else.
- `ValidationResult` was a discriminated union `{ok:true} | {ok:false, issues}`
  that TS could not narrow through `Effect.fn` (TS18048: issues possibly
  undefined everywhere). Collapse it to a plain `{ ok: boolean; issues: readonly
  ValidationIssue[] }` — the validator always returns an issues array, so the
  discriminant bought nothing.
- `Cause.squash` returns `unknown` in this build, so assert the typed
  `CliError` via an explicit `as` cast in the two cli.test.ts failure tests.
- validator.test.ts: with the non-union result, drop the `issues in result`
  guards and assert `result.issues` directly.
…eout

The regression test for #27371 asserts the process self-exits promptly on an
unknown model. Two consecutive CI container runs missed the wall-clock bound:

  run goc:  20521ms  vs < 20000ms  (521ms over)
  rerun:    21670ms  vs < 20000ms  (1670ms over)

Both are prompt self-exits (exitCode != 0) pushed past 20s by cold-start
jitter on a loaded GHCR runner. The subprocess timeoutMs is already 25_000
and the explanatory comment has long claimed 25s as the real bound, so raise
the assertion to match: a true hang is still killed by the 25s subprocess
timeout and fails toBeLessThan(25_000); the 30s harness timeout remains the
backstop. The process consistently exits well under the 25s kill timeout in
both observed runs, confirming prompt-error behavior is preserved.
@qkhalk
qkhalk merged commit 155244d into main Aug 19, 2026
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(opencode): oc kit CLI (list, validate) on Phase 1 domain model

2 participants