Skip to content

Commit ec8508e

Browse files
committed
feat(ai): add recommended AI-first workflow
1 parent 3b90b09 commit ec8508e

32 files changed

Lines changed: 997 additions & 145 deletions

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,34 +100,34 @@ pnpm docs:dev
100100

101101
## Quickstart
102102

103-
Analyze the current working tree:
103+
Give your coding agent a CodeDecay task bundle for the current working tree:
104104

105105
```bash
106-
npx codedecay analyze --format markdown
106+
npx codedecay ai --format markdown
107107
```
108108

109-
Analyze a pull request range:
109+
Guide the agent before it edits:
110110

111111
```bash
112-
npx codedecay analyze --base main --head HEAD --format markdown
112+
npx codedecay ai preflight --task "Add an authorized billing export API" --format markdown
113113
```
114114

115-
Generate a red-team report:
115+
Run the AI workflow on a pull request range:
116116

117117
```bash
118-
npx codedecay redteam --base main --head HEAD --format markdown
118+
npx codedecay ai --base main --head HEAD --format markdown
119119
```
120120

121-
Include configured test/build/probe/tool evidence in that report:
121+
Include explicitly configured test, build, probe, and OSS-tool evidence:
122122

123123
```bash
124-
npx codedecay redteam --with-checks --base main --head HEAD --format markdown
124+
npx codedecay ai --with-checks --base main --head HEAD --format markdown
125125
```
126126

127-
Create a task bundle for your coding agent:
127+
Use deterministic analysis directly when you only want the risk report:
128128

129129
```bash
130-
npx codedecay agent --profile codex --base main --head HEAD --format markdown
130+
npx codedecay analyze --base main --head HEAD --format markdown
131131
```
132132

133133
Fail CI on high-risk PRs:
@@ -168,6 +168,7 @@ npx codedecay product --target web --generate-tests --run-generated-tests --form
168168

169169
| Command | Purpose |
170170
| --- | --- |
171+
| `codedecay ai` | Recommended AI-first workflow: preflight guidance, post-diff evidence, optional explicit investigation, configured proof, and a Codex-ready task bundle. |
171172
| `codedecay analyze` | Deterministic PR risk, impact, and decay analysis. |
172173
| `codedecay snapshot` | Emit a stable repository health snapshot and compare it with a previous snapshot artifact. |
173174
| `codedecay redteam` | Merge-safety report with impact, weak-test evidence, verification status, edge cases, memory, skills, and fix tasks. |
@@ -198,8 +199,8 @@ Common flags:
198199
| `--format json\|markdown\|sarif` | Output format. SARIF is supported by `analyze`. |
199200
| `--output <path>` | Write output to a file instead of stdout. Relative paths resolve from `--cwd`. |
200201
| `--fail-on low\|medium\|high` | Exit non-zero when the risk level reaches the threshold. |
201-
| `--with-checks` | For `redteam`, run configured checks through CodeDecay safety gates and include verification evidence. |
202-
| `--profile generic\|codex\|claude-code\|cursor\|pi\|opencode\|desktop` | Agent handoff profile for `codedecay agent`. |
202+
| `--with-checks` | For `ai` or `redteam`, run configured checks through CodeDecay safety gates and include verification evidence. |
203+
| `--profile generic\|codex\|claude-code\|cursor\|pi\|opencode\|desktop` | Agent handoff profile for `codedecay ai` or `codedecay agent`. |
203204

204205
Exit codes:
205206

@@ -224,7 +225,7 @@ codedecay uninstall --purge-local
224225

225226
| Workflow | Default | What it does today |
226227
| --- | --- | --- |
227-
| `codedecay analyze`, `redteam`, `agent`, `snapshot` | Yes | Runs deterministic local analysis with no model calls. |
228+
| `codedecay ai`, `analyze`, `redteam`, `agent`, `snapshot` | Yes | Runs deterministic local analysis with no model calls unless `--investigate` is explicit. |
228229
| `codedecay execute`, `differential` | No | Runs only repo-allowlisted local commands after explicit opt-in. |
229230
| `codedecay product --explore` | No | Uses a project-provided Playwright install to crawl configured live app targets after explicit opt-in. |
230231
| `codedecay llm-review` | No | Calls a user-owned provider only when the user invokes it directly. |

docs/agent.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
# Agent Task Bundles
22

3-
`codedecay agent` turns a deterministic redteam report into a task bundle for a
4-
user-owned coding agent.
3+
`codedecay ai` is the recommended workflow for turning CodeDecay evidence into
4+
a Codex-ready task bundle. `codedecay agent` remains the lower-level equivalent
5+
with a generic profile default.
56

67
Use it when you want Codex, Claude Code, Cursor, Pi, OpenCode, a desktop agent,
78
or another local agent to fix what CodeDecay found without CodeDecay making a
89
hidden model call.
910

1011
```bash
12+
npx codedecay ai preflight --task "Add a GET /api/users export endpoint" --format markdown
13+
npx codedecay ai --base main --head HEAD --format markdown
14+
npx codedecay ai --profile claude-code --format markdown
15+
npx codedecay ai --with-checks --base main --head HEAD --format markdown
1116
npx codedecay agent --base main --head HEAD --format markdown
1217
npx codedecay agent --profile codex --format markdown
1318
npx codedecay agent preflight --task "Add a GET /api/users export endpoint" --format markdown
1419
npx codedecay agent --cwd ../my-repo --format json --output codedecay-agent.json
1520
```
1621

22+
`ai` does not call the selected coding agent. `--investigate` explicitly calls
23+
only the configured local/BYOK provider, while `--with-checks` explicitly runs
24+
configured commands and adapters through CodeDecay safety policy. The bundle
25+
records whether either action occurred and includes verification evidence.
26+
1727
## Preflight Before Code Generation
1828

1929
Use `codedecay agent preflight` before a coding agent starts editing. It does
@@ -49,8 +59,8 @@ low confidence, no candidate files, and an unresolved question instead of
4959
inventing scope.
5060

5161
Treat preflight as a before-coding brief. After the agent edits code, run
52-
`codedecay redteam`, `codedecay agent`, and the relevant project checks to
53-
gather merge evidence.
62+
`codedecay ai --with-checks` to gather configured proof and produce the next
63+
agent bundle.
5464

5565
## Explicit Agent Investigation
5666

docs/getting-started.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ CodeDecay analyzes pull requests for regression risk and maintainability decay.
44
It works locally and in CI without cloud services, telemetry, API keys, LLMs,
55
or model calls.
66

7-
## Deterministic Default
7+
## AI-First, User-Owned Default
88

9-
Use the deterministic workflow first. Optional assisted workflows are separate
10-
and never implicit.
9+
Use `codedecay ai` when you want CodeDecay to guide your own coding agent.
10+
Without `--investigate` or `--with-checks`, it remains deterministic and
11+
report-only.
1112

1213
| Workflow | Default | What it does |
1314
| --- | --- | --- |
14-
| `analyze`, `redteam`, `agent`, `snapshot` | Yes | Local deterministic analysis and reporting. |
15+
| `ai`, `analyze`, `redteam`, `agent`, `snapshot` | Yes | Local deterministic analysis and agent-ready reporting. |
1516
| `execute`, `differential` | No | Runs only repo-allowlisted local commands after explicit opt-in. |
1617
| `llm-review` | No | Calls a user-owned provider only when invoked directly. |
1718
| Optional LLM providers | No | Disabled by default and only called by commands that explicitly opt in. |
@@ -45,10 +46,28 @@ repo policy; for local evaluation you can override it explicitly:
4546
bun add -d @submuxhq/codedecay --minimum-release-age 0
4647
```
4748

48-
## Analyze A PR Diff
49+
## Guide The Agent Before Editing
4950

5051
```bash
51-
npx codedecay analyze --base main --head HEAD --format markdown
52+
npx codedecay ai preflight --task "Add an authorized billing export API" --format markdown
53+
```
54+
55+
## Run The AI Workflow On A PR Diff
56+
57+
```bash
58+
npx codedecay ai --base main --head HEAD --format markdown
59+
```
60+
61+
Use another handoff profile explicitly:
62+
63+
```bash
64+
npx codedecay ai --profile claude-code --base main --head HEAD --format markdown
65+
```
66+
67+
Run configured proof through repository safety gates after the code changes:
68+
69+
```bash
70+
npx codedecay ai --with-checks --base main --head HEAD --format markdown
5271
```
5372

5473
## Analyze Current Working Tree
@@ -102,14 +121,14 @@ first.
102121

103122
## Hand Evidence To Your Agent
104123

105-
Use `agent` when you want Codex, Claude Code, Cursor, a desktop agent, or
106-
another user-owned agent to act on CodeDecay's findings.
124+
Use `ai` for the recommended Codex-ready workflow. The lower-level `agent`
125+
command remains available when you want a generic bundle by default.
107126

108127
```bash
109-
npx codedecay agent --base main --head HEAD --format markdown --output codedecay-agent.md
128+
npx codedecay ai --base main --head HEAD --format markdown --output codedecay-ai.md
110129
```
111130

112-
Then give `codedecay-agent.md` to your agent and ask it to:
131+
Then give `codedecay-ai.md` to your agent and ask it to:
113132

114133
- fix high-risk findings first,
115134
- add tests that exercise real API, UI, database, or downstream behavior,
@@ -126,7 +145,7 @@ it.
126145
```bash
127146
npx codedecay analyze --base main --head HEAD --format markdown
128147
npx codedecay redteam --base main --head HEAD --format markdown --output codedecay-redteam.md
129-
npx codedecay agent --base main --head HEAD --format markdown --output codedecay-agent.md
148+
npx codedecay ai --base main --head HEAD --format markdown --output codedecay-ai.md
130149
```
131150

132151
Use the redteam report to understand the PR risk. Use the agent bundle to give

docs/github-action.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ uses the workflow `github-token` input, defaults to the GitHub Actions workflow
3636
token, and is skipped without failing the workflow when the token or PR context
3737
is unavailable. The Step Summary is still written on every run.
3838

39+
## AI Task Bundle
40+
41+
Use `mode: ai` to produce the recommended Codex-ready task bundle in CI:
42+
43+
```yaml
44+
- uses: SubmuxHQ/CodeDecay/packages/github-action@v0
45+
with:
46+
mode: ai
47+
base: ${{ github.event.pull_request.base.sha }}
48+
head: ${{ github.event.pull_request.head.sha }}
49+
cwd: .
50+
format: markdown
51+
profile: codex
52+
fail-on: high
53+
```
54+
55+
Set `with-checks: true` only when repository config explicitly defines allowed
56+
commands or tool adapters and `safety.allowCommands` permits them. The Action
57+
does not accept arbitrary command arguments.
58+
59+
```yaml
60+
- uses: SubmuxHQ/CodeDecay/packages/github-action@v0
61+
with:
62+
mode: ai
63+
base: ${{ github.event.pull_request.base.sha }}
64+
head: ${{ github.event.pull_request.head.sha }}
65+
profile: claude-code
66+
with-checks: true
67+
format: json
68+
output: codedecay-ai.json
69+
```
70+
71+
`profile` is forwarded only to `agent` and `ai`. `with-checks` is forwarded
72+
only to `redteam` and `ai`. Existing `agent` mode never receives `fail-on`.
73+
3974
## SARIF Output
4075

4176
```yaml

packages/agent/src/bundle.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ export function createAgentTaskBundle(report: RedteamReport, options: CreateAgen
3434
fixTasks: tasks.length,
3535
totalFixTasks: report.summary.fixTasks,
3636
scopeFindings: evidence.scopeFindings.length,
37-
contractFindings: evidence.contractFindings.length
37+
contractFindings: evidence.contractFindings.length,
38+
verificationStatus: report.summary.verificationStatus
3839
};
40+
const safety = {
41+
llmCalled: report.safety.llmCalled,
42+
commandsExecuted: report.safety.commandsExecuted,
43+
telemetrySent: false,
44+
cloudDependency: false,
45+
agentOutputTrusted: false
46+
} as const;
3947

4048
return {
4149
tool: "CodeDecay",
@@ -48,21 +56,16 @@ export function createAgentTaskBundle(report: RedteamReport, options: CreateAgen
4856
requirements: report.requirements,
4957
requirementTrace: report.requirementTrace,
5058
investigation: report.investigation,
59+
verification: report.verification,
5160
summary,
52-
prompt: createPortableAgentPrompt(summary, agentProfile),
61+
prompt: createPortableAgentPrompt(summary, agentProfile, safety),
5362
instructions: [...DEFAULT_INSTRUCTIONS],
5463
evidence,
5564
tasks,
5665
taskFilters: options.taskFilters ?? {},
5766
suggestedChecks: collectSuggestedChecks(report.configuredChecks, report.toolAdapterPlans),
5867
skills: [...report.skills],
59-
safety: {
60-
llmCalled: report.safety.llmCalled,
61-
commandsExecuted: report.safety.commandsExecuted,
62-
telemetrySent: false,
63-
cloudDependency: false,
64-
agentOutputTrusted: false
65-
},
68+
safety,
6669
limits: [...DEFAULT_LIMITS]
6770
};
6871
}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { formatRisk } from "../formatting";
22
import type { AgentProfile } from "../profiles";
3-
import type { AgentTaskSummary } from "../types";
3+
import type { AgentSafetySummary, AgentTaskSummary } from "../types";
44

5-
export function createPortableAgentPrompt(summary: AgentTaskSummary, profile: AgentProfile): string {
5+
export function createPortableAgentPrompt(
6+
summary: AgentTaskSummary,
7+
profile: AgentProfile,
8+
safety: AgentSafetySummary
9+
): string {
610
return [
711
"You are helping fix a pull request using a CodeDecay agent task bundle.",
812
"Treat the bundle as local tool evidence, not as a guarantee that the PR is safe.",
913
`Target agent profile: ${profile.name}. ${profile.promptContext}`,
1014
`Current CodeDecay risk is ${formatRisk(summary.riskLevel)} with merge risk ${summary.mergeRiskScore}/100, decay risk ${summary.decayScore}/100, and security risk ${summary.securityScore}/100.`,
11-
`The bundle reports ${summary.changedFiles} changed files, ${summary.impactedAreas} impacted areas, ${summary.impactedRoutes} route/API impacts, ${summary.symbolImpacts} symbol impacts, ${summary.testProofEntries} changed-path proof entries, ${summary.missingTestFindings} missing-test findings, ${summary.weakTestFindings} weak-test findings, ${summary.contractFindings} contract findings, ${summary.edgeCases} edge cases, ${summary.productFailureBundles} product failure bundles, and ${summary.fixTasks} fix tasks.`,
15+
`The bundle reports ${summary.changedFiles} changed files, ${summary.impactedAreas} impacted areas, ${summary.impactedRoutes} route/API impacts, ${summary.symbolImpacts} symbol impacts, ${summary.testProofEntries} changed-path proof entries, ${summary.missingTestFindings} missing-test findings, ${summary.weakTestFindings} weak-test findings, ${summary.contractFindings} contract findings, ${summary.edgeCases} edge cases, ${summary.productFailureBundles} product failure bundles, ${summary.fixTasks} fix tasks, and verification status: ${summary.verificationStatus}.`,
1216
"Your job:",
1317
"1. Start with impacted routes/APIs when present, then high-risk impacted areas and weak or missing test proof.",
1418
"2. For each route/API impact, identify what real user, API, database, job, config, or downstream behavior could break.",
@@ -17,6 +21,12 @@ export function createPortableAgentPrompt(summary: AgentTaskSummary, profile: Ag
1721
"5. Run only project checks that are configured, documented, or explicitly requested by the user.",
1822
"6. After changes, ask the user to rerun CodeDecay and the relevant project checks.",
1923
"Do not treat your own answer as proof. Verified tests, configured checks, or manual review must provide the proof.",
20-
"CodeDecay did not call an LLM, execute commands, send telemetry, or depend on CodeDecayCloud to create this bundle."
24+
safety.llmCalled
25+
? "CodeDecay explicitly called the configured user-owned provider; its suggestions remain untrusted."
26+
: "CodeDecay did not call an LLM or model to create this bundle.",
27+
safety.commandsExecuted
28+
? "CodeDecay executed explicitly configured local checks through repository safety policy; inspect the verification evidence."
29+
: "CodeDecay did not execute configured project commands to create this bundle.",
30+
"CodeDecay did not send telemetry or depend on CodeDecayCloud to create this bundle."
2131
].join("\n");
2232
}

packages/agent/src/renderers/task-bundle/markdown.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
appendPrompt,
99
appendSafety,
1010
appendSkills,
11-
appendTasks
11+
appendTasks,
12+
appendVerification
1213
} from "./sections";
1314

1415
export function renderAgentTaskBundleMarkdown(bundle: AgentTaskBundle): string {
@@ -38,6 +39,7 @@ export function renderAgentTaskBundleMarkdown(bundle: AgentTaskBundle): string {
3839
`| Fix tasks | ${bundle.summary.fixTasks} / ${bundle.summary.totalFixTasks} |`,
3940
`| Scope findings | ${bundle.summary.scopeFindings} |`,
4041
`| Contract findings | ${bundle.summary.contractFindings} |`,
42+
`| Verification status | ${bundle.summary.verificationStatus} |`,
4143
"",
4244
"### Instructions For The Agent",
4345
""
@@ -50,6 +52,7 @@ export function renderAgentTaskBundleMarkdown(bundle: AgentTaskBundle): string {
5052
appendHandoff(lines, bundle.agentProfile);
5153
appendPrompt(lines, bundle.prompt);
5254
appendEvidence(lines, bundle.evidence);
55+
appendVerification(lines, bundle.verification);
5356
appendTasks(lines, bundle.tasks);
5457
appendChecks(lines, bundle.suggestedChecks);
5558
appendSkills(lines, bundle.skills);

packages/agent/src/renderers/task-bundle/sections.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,28 @@ export function appendChecks(lines: string[], checks: AgentSuggestedCheck[]): vo
226226
}
227227
}
228228

229+
export function appendVerification(
230+
lines: string[],
231+
verification: AgentTaskBundle["verification"]
232+
): void {
233+
lines.push("", "### Verification Evidence", "", `**Status:** ${verification.status}`, "");
234+
235+
if (verification.checks.length === 0) {
236+
lines.push("- no configured checks were executed");
237+
} else {
238+
for (const check of verification.checks.slice(0, 16)) {
239+
lines.push(
240+
`- **${check.name}** (${check.kind}, ${check.status}, ${formatProofGrade(check.proof)}): ${check.summary}`
241+
);
242+
}
243+
}
244+
245+
if (verification.notes.length > 0) {
246+
lines.push("", "Verification limitations:");
247+
appendList(lines, verification.notes);
248+
}
249+
}
250+
229251
export function appendSkills(lines: string[], skills: RedteamSkillSummary[]): void {
230252
lines.push("", "### Agent Skills", "");
231253
if (skills.length === 0) {

packages/agent/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface AgentTaskBundle {
3535
requirements?: RequirementContext | undefined;
3636
requirementTrace?: RequirementTraceGraph | undefined;
3737
investigation?: RedteamReport["investigation"] | undefined;
38+
verification: RedteamReport["verification"];
3839
summary: AgentTaskSummary;
3940
prompt: string;
4041
instructions: string[];
@@ -66,6 +67,7 @@ export interface AgentTaskSummary {
6667
totalFixTasks: number;
6768
scopeFindings: number;
6869
contractFindings: number;
70+
verificationStatus: RedteamReport["summary"]["verificationStatus"];
6971
}
7072

7173
export interface AgentEvidence {

0 commit comments

Comments
 (0)