feat(cli): make agent workflows project-scoped and scriptable - #141
feat(cli): make agent workflows project-scoped and scriptable#141Waishnav wants to merge 6 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughThe PR adds workspace-aware CLI behavior and structured JSON output for local agents and workflows. It adds workspace-scoped workflow listing, JSON argument parsing, output serializers, ownership checks, tests, and explicit ChangesWorkspace-scoped CLI JSON output
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant WorkspaceContext
participant WorkflowStore
participant OutputSerializer
CLI->>WorkspaceContext: resolve current workspace
CLI->>WorkflowStore: list runs for workspace scope
WorkflowStore-->>CLI: filtered workflow records
CLI->>OutputSerializer: serialize workflow records
OutputSerializer-->>CLI: structured JSON output
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThe PR adds project-scoped agent and workflow CLI operations with sanitized JSON output, plus scoped workflow-store queries and supporting tests.
Confidence Score: 4/5The prompt-corruption defect in The new output-option handling removes every standalone Files Needing Attention: src/cli.ts
|
| Filename | Overview |
|---|---|
| src/cli.ts | Adds scoped agent commands and JSON output, but globally filtering --json corrupts prompts containing that literal token. |
| src/workflow-cli.ts | Adds project ownership checks and JSON representations across workflow CLI operations. |
| src/cli-workspace.ts | Introduces injected-ID, marker, and Git-based workspace resolution with ID-first record matching. |
| src/cli-output.ts | Defines sanitized JSON projections for agents, workflow runs, and workflow calls. |
| src/workflow-store.ts | Adds workspace-ID-aware run listing and explicit result error propagation. |
| src/workflow-launch.ts | Preserves launch error types while explicitly adapting result errors. |
| src/workflow-schema.ts | Explicitly propagates schema compilation and provider execution errors. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
CLI[CLI arguments] --> Scope[Resolve workspace context]
Scope --> Store[Load scoped agent or workflow records]
CLI --> Parse[Parse command and JSON option]
Store --> ProjectCheck[Validate project ownership]
Parse --> Execute[Run, inspect, list, or cancel]
ProjectCheck --> Execute
Execute --> Output{JSON requested?}
Output -->|Yes| JSON[Sanitized JSON projection]
Output -->|No| Text[Human-readable output]
Reviews (1): Last reviewed commit: "fix(workflow): preserve result types acr..." | Re-trigger Greptile
4535c4a to
cb3d51e
Compare
cb3d51e to
36da490
Compare
[gpt-5.6 high] RESPONDING ON BEHALF OF WAISHNAVFixed in |
|
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/workflow-cli.ts (1)
207-222: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winReject unsupported status arguments.
Line 216 selects the first positional token but does not validate the remaining tokens.
devspace workflow status <runId> --json=1returns text output.devspace workflow status <runId> --unknownalso runs instead of returning usage.Parse only
--followand--json. Require exactly one non-option run ID. Update the usage error to include both supported options.Proposed fix
- const runId = args.find((a) => !a.startsWith("-")); - if (!runId) { + const positionals = args.filter( + (arg) => arg !== "--follow" && arg !== "--json", + ); + if ( + positionals.length !== 1 || + positionals[0]!.startsWith("-") + ) { throw new InvalidWorkflowInputError({ code: "invalid_argument", - message: "Usage: devspace workflow status <runId> [--follow]", + message: "Usage: devspace workflow status <runId> [--follow] [--json]", }); } + const runId = positionals[0]!;As per coding guidelines, verify the actual user-consumption path, including packaged npm/npx usage.
🤖 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/workflow-cli.ts` around lines 207 - 222, Update runWorkflowStatus to validate every argument: accept only --follow and --json options, reject unknown or malformed options such as --json=1, and require exactly one non-option run ID. Preserve the existing follow/json mutual-exclusion check, and update the usage error to advertise both supported options; verify this validation is used by the packaged npm/npx command path.Source: Coding guidelines
🤖 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 `@src/local-agent-targets.ts`:
- Around line 25-26: Update the USAGE text associated with the CLI parser to end
with "<prompt>" [--json], documenting the trailing option handled by the json
and target parsing logic. If USAGE is covered by CLI parse-error contract tests,
add or update an assertion verifying this exact usage text.
In `@src/workflow-store.ts`:
- Line 316: Update the no-ID branch in the workflow-store run listing to query
only legacy records with workspace_id null and the normalized workspace root,
rather than calling listRunsForWorkspace. Preserve the existing workspaceId
branch, which includes the identified workspace and legacy rows, and add
coverage for the no-ID scope behavior.
---
Outside diff comments:
In `@src/workflow-cli.ts`:
- Around line 207-222: Update runWorkflowStatus to validate every argument:
accept only --follow and --json options, reject unknown or malformed options
such as --json=1, and require exactly one non-option run ID. Preserve the
existing follow/json mutual-exclusion check, and update the usage error to
advertise both supported options; verify this validation is used by the packaged
npm/npx command path.
🪄 Autofix
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: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 252539bb-7969-4fe8-a2b8-1085ae3316e9
📒 Files selected for processing (14)
package.jsonsrc/cli-output.test.tssrc/cli-output.tssrc/cli-workspace.test.tssrc/cli-workspace.tssrc/cli.test.tssrc/cli.tssrc/local-agent-targets.test.tssrc/local-agent-targets.tssrc/workflow-cli.tssrc/workflow-launch.tssrc/workflow-schema.tssrc/workflow-store.test.tssrc/workflow-store.ts
| const json = args.at(-1) === "--json"; | ||
| const [target, ...rest] = json ? args.slice(0, -1) : args; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Document the trailing --json option in USAGE.
The parser supports a trailing --json option, but the usage text omits it. Update the usage text to end with "<prompt>" [--json]. Add a parse-error assertion if this text is part of the CLI contract.
As per coding guidelines, “Prefer explicit lifecycle and state over hidden autonomy; make tasks, inputs, outputs, failures, and ownership inspectable.”
🤖 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/local-agent-targets.ts` around lines 25 - 26, Update the USAGE text
associated with the CLI parser to end with "<prompt>" [--json], documenting the
trailing option handled by the json and target parsing logic. If USAGE is
covered by CLI parse-error contract tests, add or update an assertion verifying
this exact usage text.
Source: Coding guidelines
| limit?: number; | ||
| } = {}, | ||
| ): WorkflowRunRecord[] { | ||
| if (!scope.workspaceId) return this.listRunsForWorkspace(scope.workspaceRoot, options); |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Do not use workspaceRoot to scope runs when workspaceId is unavailable.
listRunsForWorkspace filters only by workspace_root. The test setup shows that this includes runs from another workspace ID at the same root. A scope without an ID can therefore expose records owned by another workspace.
When scope.workspaceId is absent, query only legacy rows where workspace_id is null and workspace_root matches the normalized root. Keep the existing ID branch for the identified workspace plus legacy rows. Add coverage for this no-ID scope path.
As per coding guidelines, “Treat every operation as workspace-scoped and use workspaceId as the opaque handle returned by open_workspace. Do not conflate workspaces, allowed roots, checkouts, or worktrees.”
🤖 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/workflow-store.ts` at line 316, Update the no-ID branch in the
workflow-store run listing to query only legacy records with workspace_id null
and the normalized workspace root, rather than calling listRunsForWorkspace.
Preserve the existing workspaceId branch, which includes the identified
workspace and legacy rows, and add coverage for the no-ID scope behavior.
Source: Coding guidelines
Agent and workflow CLI commands need a stable project scope when invoked from Codex, Pi, OpenCode, Cursor, or an MCP shell. This layer resolves the injected DevSpace workspace first, then the Git root, a project marker, and the current directory; list, lookup, continuation, status, and cancellation all use that scope.
It also adds
--jsonoutput for target discovery, agent lifecycle commands, and workflow lifecycle commands so harnesses can launch once, retain an ID, and poll without holding a long tool call open. Workflow error paths preserve their original errors while returning the correct result type.Verified with
npm run typecheckand the full test suite.Summary by CodeRabbit
New Features
--jsonsupport for local-agent runs.Bug Fixes
Tests