Skip to content

Add source-checkout CLI task adapter - #31

Merged
krishna916 merged 4 commits into
mainfrom
feature/issue-22-cli-task-adapter
Jul 27, 2026
Merged

Add source-checkout CLI task adapter#31
krishna916 merged 4 commits into
mainfrom
feature/issue-22-cli-task-adapter

Conversation

@krishna916

@krishna916 krishna916 commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • add the source-checkout relay CLI entry point and JSON envelope runner
  • wire CLI build/bin configuration and document source-checkout invocation
  • add an implementation plan and initial CLI unit coverage

Validation

  • pnpm typecheck
  • pnpm test -- tests/unit/interfaces/cli/run-cli.test.ts

Follow-up

This draft intentionally records remaining issue #22 acceptance work identified by review: strict per-command option validation, edit clear/value validation, built-process and MCP/CLI parity integration coverage, and CLI asset validation.

Summary by CodeRabbit

  • New Features

    • Added the relay source-checkout CLI for task and session workflows (capture, list/get, find similar, edit, triage, start/complete/archive, session captures).
    • Standardized CLI output to a single JSON envelope per run (with diagnostics on stderr) plus stable exit codes and clear success/warning/error structures.
    • CLI storage is selectable via RELAY_DB_PATH and works from any working directory.
  • Documentation

    • Updated CLI usage, JSON protocol, command/option contract, exit-code behavior, and architecture boundaries guidance.
  • Tests

    • Added unit and integration coverage for CLI parsing, execution, error mapping, storage behavior, and parity with MCP tool results.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: af169d03-3d1b-4dc8-b1fb-58d6dd4e13fb

📥 Commits

Reviewing files that changed from the base of the PR and between beb9aa9 and 2b41100.

📒 Files selected for processing (6)
  • README.md
  • docs/superpowers/plans/2026-07-27-issue-22-cli-task-adapter.md
  • src/interfaces/cli/cli-command.ts
  • src/interfaces/cli/main.ts
  • src/interfaces/cli/parse-cli.ts
  • tests/integration/mcp-cli-parity.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/interfaces/cli/main.ts
  • src/interfaces/cli/cli-command.ts
  • docs/superpowers/plans/2026-07-27-issue-22-cli-task-adapter.md
  • README.md
  • tests/integration/mcp-cli-parity.test.ts
  • src/interfaces/cli/parse-cli.ts

📝 Walkthrough

Walkthrough

Adds a JSON-only source-checkout CLI for ten task/session commands, with strict parsing, stable error envelopes and exit codes, shared DTO mappings, MCP parity, built-process integration, asset validation, and expanded documentation.

Changes

Source-checkout CLI adapter

Layer / File(s) Summary
CLI contract, parsing, and runtime lifecycle
src/interfaces/cli/cli-command.ts, src/interfaces/cli/parse-cli.ts, src/interfaces/cli/output/*, src/interfaces/cli/run-cli.ts, tests/unit/interfaces/cli/*
Defines typed commands, strict option validation, JSON success/failure envelopes, standardized error mapping, runtime cleanup, and unit coverage.
Task handlers and shared adapter DTOs
src/interfaces/cli/commands/*, src/interfaces/cli/execute-cli-command.ts, src/interfaces/contracts/*, src/interfaces/http/task-dto.ts, src/interfaces/mcp/tools/*, tests/unit/interfaces/cli/command-handlers.test.ts, tests/integration/mcp-cli-parity.test.ts
Routes task and session commands through TaskApplication, serializes results with shared DTOs, preserves duplicate warnings and change metadata, and verifies MCP/CLI payload parity.
Executable packaging and process integration
package.json, tsup.config.ts, src/interfaces/cli/main.ts, scripts/validate-repository-assets.ts, tests/integration/cli.test.ts, tests/unit/scripts/validate-repository-assets.test.ts
Builds and exposes dist/cli/main.js, validates CLI assets and configuration, and tests persistence, lifecycle transitions, validation errors, and storage failures across processes.
CLI contract and implementation records
README.md, docs/cli-reference.md, docs/superpowers/plans/*, docs/superpowers/tasks/*
Documents invocation, JSON protocol, commands, exit codes, architecture boundaries, implementation tasks, review tasks, and verification results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • krishna916/relay#2 — Covers the source-checkout CLI adapter, commands, shared contracts, MCP parity, and documentation.
  • krishna916/relay#22 — Specifies the parser, handlers, JSON/error contracts, runtime lifecycle, build entrypoint, and parity tests implemented here.

Possibly related PRs

  • krishna916/relay#3 — Provides repository asset validation extended here for the CLI executable.
  • krishna916/relay#28 — Provides session metadata used by capture and session-listing behavior.
  • krishna916/relay#30 — Adds MCP mutation handlers whose DTO mapping is switched to the shared contract mapper here.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a source-checkout CLI task adapter.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/issue-22-cli-task-adapter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@krishna916 krishna916 linked an issue Jul 27, 2026 that may be closed by this pull request

@krishna916 krishna916 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review against #22

Verdict: not ready to merge. This draft establishes a useful skeleton, but it does not yet satisfy the issue acceptance gate.

High — runtime validation starts too early

parse() only validates the generic token shape and --output json. Required command options, allowed options, status/priority values, edit clear/value conflicts, and triage targets are validated later inside execute(), after createRuntime() has already opened the database. Issue #22 requires syntax to be sufficiently validated before runtime creation. For example, task capture --agent codex --session s --output json currently creates a runtime before discovering the missing --title.

Please introduce a command-specific parsed union/schema and complete validation before createRuntime().

High — unknown options are silently accepted

Because options are collected generically and handlers read only the keys they know, commands such as task get id --bogus value --output json succeed. The authoritative spec requires unknown options to be usage errors. This needs strict per-command allowlists/schema validation, with tests for every command.

High — acceptance coverage is still absent

The PR currently has only three unit tests. Issue #22 explicitly requires built-process arbitrary-CWD tests, isolated RELAY_DB_PATH, stable exit-code categories, all ten command families, stdout/stderr separation, runtime close behavior, edit/no-op/clear semantics, and MCP/CLI parity. The PR description acknowledges these gaps; they remain merge blockers rather than optional follow-up work.

Medium — CLI depends on MCP adapter internals

run-cli.ts imports DTO and change-metadata mappers from interfaces/mcp/mapping. The issue asks the CLI and MCP adapters to reuse adapter-neutral contracts. Move these pure serializers/mappers to a shared contracts/mapping location so neither adapter depends on the other adapter’s namespace.

The core direction is sound, but the PR should remain draft until these items and the full pnpm verify gate pass.

} finally {
runtime.close();
}
} catch (error) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

runtime.close() can throw after a success or failure envelope has already been written. The outer catch then writes another failure envelope, so stdout contains two JSON documents and violates the “exactly one JSON document” contract. Capture execution and close failures before writing output, then emit exactly one final envelope. Add tests for close failure after both successful execution and command failure.

Copy link
Copy Markdown
Owner Author

Luna remediation plan for PR #31

Use this as the implementation checklist for addressing the review against issue #22. Do not redesign the CLI contract. Preserve the command surface, exit codes, envelopes, application semantics, and scope already defined in issue #22 and its authoritative implementation comment.

Working rules

  • Keep the PR in draft until every task below is complete.
  • Use TDD for each task: add or tighten the failing test first, then implement the minimum change.
  • Do not add HTTP calls, MCP process spawning, direct SQLite access, npm publication, installers, setup/doctor/update commands, shell completion, TUI work, or vendor-specific assets.
  • Do not change task lifecycle semantics. CLI must call TaskApplication methods directly.
  • Do not weaken tests merely to match the current implementation.
  • Prefer small focused commits so each review concern can be inspected independently.

Task 1 — Introduce a fully validated parsed-command model

Goal

Complete all syntax and option validation before createRuntime() is called.

Required changes

  1. Extract parsing from run-cli.ts into a focused module such as:
    • src/interfaces/cli/parse-cli.ts
    • optionally src/interfaces/cli/cli-command.ts
  2. Replace the current generic { group, action, id, options } result with a discriminated union containing one validated type per supported command:
    • task capture
    • task list
    • task get
    • task find-similar
    • task edit
    • task triage
    • task start
    • task complete
    • task archive
    • session captures
  3. Each parsed command must already contain typed and normalized values required by execution. execute() must not perform usage validation.
  4. Validate before runtime creation:
    • command/group exists and is supported
    • required positional task ID
    • required options
    • unknown options
    • missing option values
    • duplicate singular options
    • allowed repeated options such as --status
    • allowed enum values
    • bounded integer limits
    • edit field/clear conflicts
    • at least one edit operation
    • --output json
  5. runCli() must call parseCli(argv) first and only invoke createRuntime() after parsing succeeds.

Command-specific option allowlists

Implement explicit allowlists rather than collecting arbitrary options.

  • task capture
    • required: --title, --agent, --session, --output json
    • optional: --description, --priority, --workspace, --source-context
  • task list
    • optional: repeated --status, --workspace, --limit
    • required: --output json
  • task get <id>
    • only --output json
  • task find-similar
    • required: --title, --output json
    • optional: --workspace, --limit
  • task edit <id>
    • optional editable values: --title, --description, --priority, --workspace, --source-context
    • optional clears: --clear-description, --clear-priority, --clear-workspace, --clear-source-context
    • required: --output json
  • task triage <id>
    • required: --to, --output json
  • task start|complete|archive <id>
    • only --output json
  • session captures
    • required: --session, --output json
    • optional: --limit

Validation rules

  • Unknown commands and options return exit code 2.
  • Unknown positional arguments return exit code 2.
  • Singular options supplied more than once return exit code 2.
  • --status may repeat, but every status must be valid.
  • task triage --to accepts only INBOX, ACTIVE, or BACKLOG.
  • Priority must be validated against the canonical domain/contract values; do not cast arbitrary strings to TaskPriority.
  • List and session limits must use the issue-defined upper bound of 100.
  • Similarity limits must use the issue-defined upper bound of 5.
  • An edit value and its matching clear flag are mutually exclusive, for example:
    • --description x with --clear-description
    • --priority HIGH with --clear-priority
    • --workspace relay with --clear-workspace
    • --source-context x with --clear-source-context
  • task edit with no actual edit operation is a usage error.

Tests

Add parser-focused tests covering every command:

  • valid minimum invocation
  • valid invocation with all supported options
  • every missing required option
  • every unknown option
  • duplicate singular options
  • missing option value
  • unexpected positional argument
  • invalid enum values
  • invalid limits: non-number, decimal, zero, negative, above maximum
  • repeated valid and invalid statuses
  • edit clear/value conflicts
  • edit with no fields

For every parser failure assert:

  • exit code is 2
  • exactly one failure envelope is written
  • createRuntime is not called
  • stderr receives one diagnostic

Acceptance check

execute() receives only validated typed commands and contains no CLI usage checks.


Task 2 — Refactor execution into focused command handlers

Goal

Make command behavior easy to review and prevent parser/application concerns from being mixed in one large function.

Required changes

  1. Split command execution into focused modules under src/interfaces/cli/commands/, preferably:
    • task-capture.ts
    • task-list.ts
    • task-get.ts
    • task-find-similar.ts
    • task-edit.ts
    • task-triage.ts
    • task-start.ts
    • task-complete.ts
    • task-archive.ts
    • session-captures.ts
  2. Add one exhaustive dispatcher over the discriminated parsed-command union.
  3. Each handler must:
    • call only the relevant TaskApplication method or methods
    • avoid persistence/runtime knowledge
    • return the normalized success payload and warnings
    • contain no stdout/stderr writing
  4. Ensure one application call for simple reads and focused lifecycle mutations.
  5. Preserve capture behavior:
    • run advisory duplicate lookup first
    • create an AGENT task
    • preserve agent, session, workspace, and source context
    • duplicate matches only create warnings and do not change exit code
  6. Preserve exact mutation metadata from issue Implement user-directed lifecycle capabilities through MCP #21.

Tests

Add unit tests for every command handler asserting exact application calls and exact returned payload shape.

Important cases:

  • capture with and without duplicate candidates
  • list with explicit/default statuses
  • find-similar candidate reason mapping
  • exact session capture query
  • edit of each field
  • clearing each nullable field
  • edit no-op metadata returned by the application/mappers
  • triage to each permitted target
  • start, complete, and archive success

Task 3 — Remove CLI dependency on MCP adapter internals

Goal

MCP and CLI must be sibling adapters sharing neutral contracts/mappers. CLI must not import from interfaces/mcp.

Required changes

  1. Move pure shared mapping functions currently used by both adapters out of:
    • src/interfaces/mcp/mapping/task-mcp-dto.ts
    • src/interfaces/mcp/mapping/change-metadata.ts
  2. Place them in an adapter-neutral location, for example:
    • src/interfaces/contracts/task-dto.ts
    • src/interfaces/contracts/change-metadata.ts
    • or src/application/tasks/mapping/ if that better matches the repository conventions
  3. Rename MCP-specific symbols where necessary. For example, toTaskMcpDto should become an adapter-neutral name such as toTaskDto.
  4. Update both MCP and CLI imports to use the shared neutral modules.
  5. Do not duplicate mapper implementations.
  6. Do not move transport-specific MCP schemas or server behavior into the shared layer.

Tests

  • Existing MCP tests must remain unchanged in behavior.
  • CLI and MCP parity tests must consume the same shared DTO/change expectations.
  • Add an architectural/import assertion if the repository already has asset or boundary validation; otherwise add a focused test ensuring no file under src/interfaces/cli/ imports from src/interfaces/mcp/.

Acceptance check

A repository search for imports from interfaces/mcp under src/interfaces/cli returns no results.


Task 4 — Guarantee exactly one JSON envelope even when cleanup fails

Goal

No execution path may write two JSON documents to stdout.

Current defect

runtime.close() can throw after a success or failure envelope has already been written. The outer catch then writes a second failure envelope.

Required design

  1. Separate these phases:
    • parse
    • runtime creation
    • command execution
    • runtime cleanup
    • final output emission
  2. Do not write the success or command-failure envelope until cleanup has completed.
  3. Capture command execution failure and cleanup failure as values before deciding the final result.
  4. Call runtime.close() exactly once whenever runtime creation succeeded.
  5. Emit exactly one final envelope and one newline.
  6. Recommended precedence:
    • if command execution fails, preserve that primary error even if cleanup also fails; record cleanup only through a diagnostic if needed, without emitting a second envelope
    • if command execution succeeds but cleanup fails, return a mapped internal/storage failure rather than success
  7. Do not expose stack traces or low-level SQLite details in the JSON contract.
  8. Ensure stderr remains diagnostic-only and stdout remains protocol-only.

Required tests

Add explicit tests for:

  • successful execution + successful close
  • command failure + successful close
  • successful execution + close failure
  • command failure + close failure
  • runtime creation failure
  • parser failure

For every case assert:

  • stdout is written exactly once
  • stdout contains exactly one valid JSON document plus newline
  • runtime close is called exactly once when runtime exists
  • parser failures do not create/close runtime
  • returned exit code matches the chosen primary error

Also test a writer spy that would expose accidental second writes.


Task 5 — Complete stable error and exit-code coverage

Goal

Prove all issue #22 exit categories and output separation rules.

Required mapping

  • 0 success
  • 1 internal/unexpected
  • 2 usage or validation
  • 3 task not found
  • 4 conflict or archived-task operation
  • 5 storage/persistence failure

Required changes

  1. Review toCliError() against the canonical application/domain error hierarchy.
  2. Avoid broad mappings that could incorrectly classify an unexpected programming error as validation.
  3. Keep public error codes/messages deterministic.
  4. Ensure warnings never change exit code from 0.
  5. Ensure failures write:
    • exactly one JSON failure envelope to stdout
    • human-readable diagnostic to stderr
  6. Ensure success writes no stderr output.

Tests

Add one explicit unit test for every exit category and representative error subtype:

  • invalid CLI usage
  • invalid application request
  • not found
  • archived task
  • invalid transition/conflict
  • persistence/storage failure
  • unexpected error
  • duplicate warning success

Assert exact public error code, exit code, stdout shape, stderr behavior, and runtime cleanup.


Task 6 — Complete MCP/CLI parity tests

Goal

Equivalent MCP and CLI operations must produce equivalent task DTOs, warnings, and change metadata.

Required changes

Create tests/integration/mcp-cli-parity.test.ts or the repository-equivalent location.

Use shared fixtures and the same isolated database/runtime where practical. Cover at minimum:

  1. Capture without duplicates
  2. Capture with duplicate warning
  3. List with status/workspace filters
  4. Get
  5. Find similar
  6. Session captures
  7. Edit field
  8. Clear nullable field
  9. Edit no-op
  10. Triage to inbox/active/backlog
  11. Start
  12. Complete
  13. Archive
  14. Not-found and conflict/error envelope equivalence where contracts require it

Compare semantic payloads, not transport wrappers that are intentionally different. The task DTO and change metadata must match exactly.

Do not implement separate CLI semantics to make the tests pass.


Task 7 — Add built-process CLI integration tests

Goal

Prove the actual built CLI works from source checkout, outside the repository CWD, against an isolated database.

Required changes

Create tests/integration/cli.test.ts or the repository-equivalent location.

  1. Build the Node CLI entry before invoking it, using the existing test/build setup.
  2. Spawn the built file using process.execPath and an absolute path to dist/cli/main.js.
  3. Launch from a temporary directory that is not the repository root.
  4. Set RELAY_DB_PATH to a unique temporary database path for each test.
  5. Verify commands share that database across separate short-lived CLI processes.
  6. Verify the CLI does not require an HTTP or MCP process.
  7. Verify stdout is parseable as one JSON document and stderr is empty on success.
  8. Verify failures return the documented process exit code.
  9. Clean up temporary directories/databases deterministically.

Required scenarios

  • first invocation initializes/opens isolated storage successfully
  • capture then get/list in a separate process
  • session capture query sees the created task
  • lifecycle mutation persists across processes
  • invocation from arbitrary CWD
  • invalid command exits 2 without creating the database if parser validation occurs before runtime creation
  • storage failure exits 5 where it can be reproduced safely

Acceptance check

Tests invoke only the built artifact, not TypeScript source through tsx.


Task 8 — Complete repository asset/build validation

Goal

Ensure the new relay executable is part of the verified source-checkout build.

Required changes

  1. Confirm package.json contains the intended source-checkout bin mapping:
    • relay -> ./dist/cli/main.js
  2. Confirm tsup.config.ts produces dist/cli/main.js.
  3. Update repository asset validation so it checks:
    • CLI source entry exists
    • build entry exists
    • package bin target matches the built path
    • documentation references a valid invocation
  4. Add/update README.md with a concise source-checkout example.
  5. Keep npm publication and installer behavior out of scope.
  6. Ensure build output remains independent of current working directory.

Tests

Update tests/unit/scripts/validate-repository-assets.test.ts and any associated script tests.


Task 9 — Finish CLI documentation

Goal

Document the implemented contract, not planned or unsupported behavior.

Required documentation

Update docs/cli-reference.md and README.md to include:

  • source-checkout build command
  • absolute-path invocation from any CWD
  • RELAY_DB_PATH behavior
  • all ten supported commands
  • every supported option and whether required/repeatable
  • JSON-only authoritative mode
  • success/failure envelope examples
  • stable exit-code table
  • stdout/stderr rules
  • duplicate warning behavior
  • direct TaskApplication architecture statement
  • explicit out-of-scope items where useful

Do not document flags or human-readable output that are not implemented.


Task 10 — Run the full verification gate and update the PR

Required commands

Run all of the following from a clean working tree:

pnpm test -- tests/unit/interfaces/cli
pnpm test -- tests/integration/cli.test.ts
pnpm test -- tests/integration/mcp-cli-parity.test.ts
pnpm format:check
pnpm lint
pnpm typecheck
pnpm test:coverage
pnpm build
pnpm validate:assets
pnpm verify

If the repository test runner requires slightly different paths, use the equivalent commands but preserve the same coverage.

Final Luna self-review

Before marking the work complete, verify manually:

  • All ten commands are implemented.
  • Every command rejects unknown options.
  • All usage validation finishes before runtime creation.
  • CLI has no imports from interfaces/mcp.
  • Runtime is closed exactly once.
  • Cleanup failure cannot produce a second JSON document.
  • stdout contains only one JSON envelope and newline.
  • stderr contains no success output.
  • All six exit-code categories are tested.
  • Built CLI works from a non-repository CWD.
  • Separate CLI processes use the same RELAY_DB_PATH database.
  • MCP/CLI parity tests pass.
  • Asset validation covers the new executable.
  • pnpm verify passes.
  • No forbidden scope was added.

PR update required from Luna

After implementation:

  1. Update the PR description so it no longer describes required acceptance work as follow-up.
  2. Add a concise completion comment containing:
    • commits or major change groups
    • verification commands run
    • confirmation that arbitrary-CWD and MCP/CLI parity tests pass
    • any intentional deviation from this plan, with justification
  3. Keep the PR draft until the complete gate passes.
  4. Do not resolve the review thread until the close-failure regression test is present and passing.

@krishna916 krishna916 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Re-review against issue #22

The previously reported blockers are addressed:

  • parsing is now command-specific and completes before runtime creation
  • unknown and duplicate options are rejected
  • edit clear/value conflicts and enum/limit validation are enforced before opening storage
  • CLI/MCP mapping logic is adapter-neutral
  • runtime execution and cleanup are collected before emitting one final JSON envelope
  • built-process arbitrary-CWD, isolated RELAY_DB_PATH, command-family, exit-code, architecture, and MCP/CLI parity coverage has been added
  • the latest CI run passes

I did not find a new merge-blocking code issue in this pass.

Administrative cleanup before merge: resolve the now-addressed inline cleanup thread, update the stale PR description/validation section, and mark the PR ready for review. Since this is the author's own PR, GitHub does not permit a formal approval from this account.

@krishna916
krishna916 marked this pull request as ready for review July 27, 2026 17:01

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🧹 Nitpick comments (3)
tests/integration/mcp-cli-parity.test.ts (1)

57-95: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Exercise the claimed duplicate-warning parity.

Both applications are empty here, so capture cannot produce a duplicate warning; callCli also discards warnings. Seed an equivalent candidate in both fixtures and compare the warning envelopes, not just data.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/mcp-cli-parity.test.ts` around lines 57 - 95, Update the
“matches capture payloads and duplicate warnings” test to seed equivalent
existing candidate tasks in both application fixtures before capture, ensuring
the new capture triggers a duplicate warning. Extend callCli to return the
parsed envelope warnings, then compare CLI and MCP warnings alongside data while
preserving the existing payload assertions.
src/interfaces/cli/parse-cli.ts (1)

283-289: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Simplify redundant branch in readId.

The outer condition already establishes value === undefined || value.startsWith('--'); re-testing value?.startsWith('--') inside the block is redundant.

♻️ Suggested simplification
 function readId(value: string | undefined, label: string): string | undefined {
-  if (value === undefined || value.startsWith('--')) {
-    if (value?.startsWith('--')) throw new CliUsageError(`A ${label} is required.`);
-    return undefined;
-  }
-  return boundedText(value, label, MAX_ID_LENGTH);
+  if (value === undefined) return undefined;
+  if (value.startsWith('--')) throw new CliUsageError(`A ${label} is required.`);
+  return boundedText(value, label, MAX_ID_LENGTH);
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/interfaces/cli/parse-cli.ts` around lines 283 - 289, In readId, simplify
the outer guard by handling undefined and option-prefixed values without
rechecking value?.startsWith('--') inside the block. Preserve returning
undefined for missing values and throwing CliUsageError with the existing
label-specific message when a value starts with '--'; keep boundedText
validation unchanged.
src/interfaces/cli/cli-command.ts (1)

47-51: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Split TaskLifecycleCommand into a true discriminated union.

kind: 'task.start' | 'task.complete' | 'task.archive' and action: 'start' | 'complete' | 'archive' are typed independently, so nothing prevents constructing { kind: 'task.start', action: 'archive' }. parseTaskLifecycle in parse-cli.ts always keeps them in sync today, but this shape works against PR objective #1's "discriminated, fully validated parsed-command model" and leaves a foot-gun for any downstream code that switches on action instead of kind (or vice versa).

♻️ Suggested tightening
-export interface TaskLifecycleCommand {
-  readonly kind: 'task.start' | 'task.complete' | 'task.archive';
-  readonly id: string;
-  readonly action: 'start' | 'complete' | 'archive';
-}
+export interface TaskStartCommand {
+  readonly kind: 'task.start';
+  readonly id: string;
+}
+export interface TaskCompleteCommand {
+  readonly kind: 'task.complete';
+  readonly id: string;
+}
+export interface TaskArchiveCommand {
+  readonly kind: 'task.archive';
+  readonly id: string;
+}
+export type TaskLifecycleCommand = TaskStartCommand | TaskCompleteCommand | TaskArchiveCommand;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/interfaces/cli/cli-command.ts` around lines 47 - 51, Replace the
independently unioned fields in TaskLifecycleCommand with a discriminated union
of three object variants, pairing each kind with its corresponding action:
task.start/start, task.complete/complete, and task.archive/archive. Preserve the
readonly properties and update any dependent types or usage sites as needed so
parseTaskLifecycle and downstream command handling retain the validated pairing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/superpowers/plans/2026-07-27-issue-22-cli-task-adapter.md`:
- Around line 152-153: Update the Task 3 file list to replace task-start.ts,
task-complete.ts, and task-archive.ts with
src/interfaces/cli/commands/task-lifecycle.ts, while preserving the existing
task-edit.ts and task-triage.ts entries and other listed modifications.
- Around line 61-73: Update the runCli example so it matches the required
phase-separated flow: handle parse failures and runtime-creation failures
through the single JSON error-envelope path, and ensure runtime.close() failures
are also converted into that envelope without replacing an already-emitted
response. Alternatively, clearly mark this snippet as historical pseudocode
rather than presenting it as the implementation.

In `@README.md`:
- Around line 46-53: Clarify the README instructions before the source-checkout
CLI example to state that pnpm build:node must run from the repository checkout
root, or show the equivalent pnpm --dir invocation for an arbitrary working
directory. Keep the existing CLI invocation and behavior description unchanged.

In `@src/interfaces/cli/main.ts`:
- Line 1: Add the Node shebang as the first line of the CLI entrypoint
containing createTaskRuntime, before all imports, so the generated relay binary
is directly executable. Preserve the existing import and runtime behavior.

---

Nitpick comments:
In `@src/interfaces/cli/cli-command.ts`:
- Around line 47-51: Replace the independently unioned fields in
TaskLifecycleCommand with a discriminated union of three object variants,
pairing each kind with its corresponding action: task.start/start,
task.complete/complete, and task.archive/archive. Preserve the readonly
properties and update any dependent types or usage sites as needed so
parseTaskLifecycle and downstream command handling retain the validated pairing.

In `@src/interfaces/cli/parse-cli.ts`:
- Around line 283-289: In readId, simplify the outer guard by handling undefined
and option-prefixed values without rechecking value?.startsWith('--') inside the
block. Preserve returning undefined for missing values and throwing
CliUsageError with the existing label-specific message when a value starts with
'--'; keep boundedText validation unchanged.

In `@tests/integration/mcp-cli-parity.test.ts`:
- Around line 57-95: Update the “matches capture payloads and duplicate
warnings” test to seed equivalent existing candidate tasks in both application
fixtures before capture, ensuring the new capture triggers a duplicate warning.
Extend callCli to return the parsed envelope warnings, then compare CLI and MCP
warnings alongside data while preserving the existing payload assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8143cc2e-a70c-48fd-954b-773877138190

📥 Commits

Reviewing files that changed from the base of the PR and between d39af71 and beb9aa9.

📒 Files selected for processing (42)
  • README.md
  • docs/cli-reference.md
  • docs/superpowers/plans/2026-07-27-issue-22-cli-task-adapter.md
  • docs/superpowers/tasks/2026-07-27-pr-31-review-tracker.md
  • package.json
  • scripts/validate-repository-assets.ts
  • src/interfaces/cli/cli-command.ts
  • src/interfaces/cli/commands/command-result.ts
  • src/interfaces/cli/commands/session-captures.ts
  • src/interfaces/cli/commands/task-capture.ts
  • src/interfaces/cli/commands/task-edit.ts
  • src/interfaces/cli/commands/task-find-similar.ts
  • src/interfaces/cli/commands/task-get.ts
  • src/interfaces/cli/commands/task-lifecycle.ts
  • src/interfaces/cli/commands/task-list.ts
  • src/interfaces/cli/commands/task-triage.ts
  • src/interfaces/cli/execute-cli-command.ts
  • src/interfaces/cli/main.ts
  • src/interfaces/cli/output/cli-errors.ts
  • src/interfaces/cli/output/cli-result.ts
  • src/interfaces/cli/parse-cli.ts
  • src/interfaces/cli/run-cli.ts
  • src/interfaces/contracts/change-metadata.ts
  • src/interfaces/contracts/task-dto.ts
  • src/interfaces/http/task-dto.ts
  • src/interfaces/mcp/mapping/task-mcp-dto.ts
  • src/interfaces/mcp/tools/register-read-tools.ts
  • src/interfaces/mcp/tools/task-archive.ts
  • src/interfaces/mcp/tools/task-capture.ts
  • src/interfaces/mcp/tools/task-complete.ts
  • src/interfaces/mcp/tools/task-edit.ts
  • src/interfaces/mcp/tools/task-start.ts
  • src/interfaces/mcp/tools/task-triage.ts
  • tests/integration/cli.test.ts
  • tests/integration/mcp-cli-parity.test.ts
  • tests/unit/interfaces/cli/architecture.test.ts
  • tests/unit/interfaces/cli/cli-errors.test.ts
  • tests/unit/interfaces/cli/command-handlers.test.ts
  • tests/unit/interfaces/cli/parse-cli.test.ts
  • tests/unit/interfaces/cli/run-cli.test.ts
  • tests/unit/scripts/validate-repository-assets.test.ts
  • tsup.config.ts
💤 Files with no reviewable changes (1)
  • src/interfaces/mcp/mapping/task-mcp-dto.ts

Comment thread docs/superpowers/plans/2026-07-27-issue-22-cli-task-adapter.md
Comment thread docs/superpowers/plans/2026-07-27-issue-22-cli-task-adapter.md Outdated
Comment thread README.md Outdated
Comment thread src/interfaces/cli/main.ts
@krishna916
krishna916 merged commit 49a1418 into main Jul 27, 2026
2 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.

Implement the source-checkout CLI task adapter

1 participant