Skip to content

feat(cli): make agent workflows project-scoped and scriptable - #141

Open
Waishnav wants to merge 6 commits into
pr/dw-agent-call-budgetfrom
codex/dw-cli-contract
Open

feat(cli): make agent workflows project-scoped and scriptable#141
Waishnav wants to merge 6 commits into
pr/dw-agent-call-budgetfrom
codex/dw-cli-contract

Conversation

@Waishnav

@Waishnav Waishnav commented Aug 8, 2026

Copy link
Copy Markdown
Owner

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 --json output 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 typecheck and the full test suite.

Summary by CodeRabbit

  • New Features

    • Added JSON output options for agent and workflow CLI commands.
    • Added workspace-aware filtering to keep agent and workflow records scoped to the active project.
    • Added structured output for agent targets, workflow runs, and workflow calls, including statuses, timestamps, errors, and summaries.
    • Added trailing --json support for local-agent runs.
  • Bug Fixes

    • Improved validation and error reporting for invalid command options and inaccessible records.
  • Tests

    • Expanded coverage for JSON output, workspace isolation, and CLI workspace detection.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 Result.err propagation.

Changes

Workspace-scoped CLI JSON output

Layer / File(s) Summary
Workspace resolution and scoped workflow storage
src/cli-workspace.ts, src/workflow-store.ts, src/cli-workspace.test.ts, src/workflow-store.test.ts
Workspace context resolves from environment variables, DevSpace markers, Git roots, or the current directory. Workflow runs can be filtered by workspace ID, root, status, and limit.
CLI output serializers and argument parsing
src/cli-output.ts, src/cli-output.test.ts, src/local-agent-targets.ts, src/local-agent-targets.test.ts, package.json
Local-agent and workflow records receive normalized serializers. A trailing --json flag is parsed separately from the prompt.
Workspace-aware agent commands
src/cli.ts, src/cli.test.ts
Agent commands validate workspace ownership, persist workspace IDs, and support structured JSON output.
Workflow CLI JSON flow and Result propagation
src/workflow-cli.ts, src/workflow-launch.ts, src/workflow-schema.ts, src/cli.test.ts
Workflow commands support validated JSON output and workspace checks. Launch, schema, and store error paths explicitly return Result.err values.

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
Loading

Possibly related PRs

Poem

A rabbit hops through workspace ground,
Finds JSON fields neatly bound.
Agents and workflows show their face,
While stray records stay out of place.
Errors return with care—
Clean output everywhere!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.45% 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 summarizes the main changes: project-scoped agent workflows and scriptable CLI behavior.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/dw-cli-contract

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.

@Waishnav Waishnav changed the title codex/dw cli contract feat(cli): make agent workflows project-scoped and scriptable Aug 8, 2026
@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds project-scoped agent and workflow CLI operations with sanitized JSON output, plus scoped workflow-store queries and supporting tests.

  • Adds --json output to agent and workflow run, list, status, cancel, and detail commands.
  • Resolves CLI project context using injected workspace metadata, .devspace markers, or Git roots.
  • Filters workflow and agent records to the current workspace and validates record ownership before ID-based operations.
  • Makes result error propagation explicit in workflow launch, schema, and store paths.

Confidence Score: 4/5

The prompt-corruption defect in agents run should be fixed before merging because valid instructions containing --json are silently altered.

The new output-option handling removes every standalone --json token before prompt parsing rather than distinguishing the CLI option from literal prompt content.

Files Needing Attention: src/cli.ts

Important Files Changed

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]
Loading

Reviews (1): Last reviewed commit: "fix(workflow): preserve result types acr..." | Re-trigger Greptile

Comment thread src/cli.ts Outdated
@Waishnav
Waishnav force-pushed the codex/dw-cli-contract branch from 4535c4a to cb3d51e Compare August 8, 2026 00:59
@Waishnav
Waishnav force-pushed the codex/dw-cli-contract branch from cb3d51e to 36da490 Compare August 8, 2026 01:02
@Waishnav

Waishnav commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

[gpt-5.6 high] RESPONDING ON BEHALF OF WAISHNAV

Fixed in 1f6c021. agents run now recognizes --json only as the documented trailing output option, so a standalone --json token inside the prompt is preserved. Added parser coverage for both literal prompt content and the trailing option; typecheck and the full test suite pass.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

@Waishnav, I will perform a complete review of PR #141.

⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 57 minutes.

@Waishnav

Waishnav commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@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: 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 win

Reject unsupported status arguments.

Line 216 selects the first positional token but does not validate the remaining tokens. devspace workflow status <runId> --json=1 returns text output. devspace workflow status <runId> --unknown also runs instead of returning usage.

Parse only --follow and --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

📥 Commits

Reviewing files that changed from the base of the PR and between 9860cbd and 801feb5.

📒 Files selected for processing (14)
  • package.json
  • src/cli-output.test.ts
  • src/cli-output.ts
  • src/cli-workspace.test.ts
  • src/cli-workspace.ts
  • src/cli.test.ts
  • src/cli.ts
  • src/local-agent-targets.test.ts
  • src/local-agent-targets.ts
  • src/workflow-cli.ts
  • src/workflow-launch.ts
  • src/workflow-schema.ts
  • src/workflow-store.test.ts
  • src/workflow-store.ts

Comment on lines +25 to +26
const json = args.at(-1) === "--json";
const [target, ...rest] = json ? args.slice(0, -1) : args;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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

Comment thread src/workflow-store.ts
limit?: number;
} = {},
): WorkflowRunRecord[] {
if (!scope.workspaceId) return this.listRunsForWorkspace(scope.workspaceRoot, options);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 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

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.

1 participant