Repository navigation
feat(opencode): oc kit CLI (list, validate) on Phase 1 domain model - #9
Merged
Merged
Conversation
…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.
|
The following comment was made by an LLM, it may be inaccurate: |
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #8
Type of change
What does this PR do?
Adds the
oc kitCLI on top of the Phase 1 OC Kit domain model (merged in PR #2):oc kit listenumerates every registered kit, skill, agent, workflow, and hookfrom the registry.
oc kit validateruns the schema + cross-reference validator and exits nonzerowhen it finds duplicate ids or dangling references (e.g. a skill pointing at a
missing agent).
Why this works:
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.
packages/opencode/src/ockit/cli.tsand covered by unit tests. The validatortests 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 validateexit-nonzero path is exercised by a test fixture with adeliberate dangling reference.
Screenshots / recordings
Not a UI change.
Checklist