auditor-lambda 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +6 -1
  2. package/audit-code-wrapper-lib.mjs +78 -5
  3. package/dist/cli.js +205 -67
  4. package/dist/extractors/graph.d.ts +5 -1
  5. package/dist/extractors/graph.js +223 -3
  6. package/dist/extractors/pathPatterns.d.ts +3 -2
  7. package/dist/extractors/pathPatterns.js +97 -24
  8. package/dist/io/artifacts.d.ts +5 -0
  9. package/dist/io/artifacts.js +2 -0
  10. package/dist/io/json.js +3 -3
  11. package/dist/io/runArtifacts.js +4 -0
  12. package/dist/mcp/server.js +24 -11
  13. package/dist/orchestrator/advance.js +1 -1
  14. package/dist/orchestrator/dependencyMap.js +18 -0
  15. package/dist/orchestrator/internalExecutors.d.ts +1 -1
  16. package/dist/orchestrator/internalExecutors.js +120 -33
  17. package/dist/orchestrator/reviewPackets.d.ts +14 -0
  18. package/dist/orchestrator/reviewPackets.js +300 -0
  19. package/dist/orchestrator/selectiveDeepening.d.ts +14 -0
  20. package/dist/orchestrator/selectiveDeepening.js +392 -0
  21. package/dist/orchestrator/state.js +6 -1
  22. package/dist/orchestrator/taskBuilder.d.ts +16 -0
  23. package/dist/orchestrator/taskBuilder.js +68 -11
  24. package/dist/orchestrator.js +53 -2
  25. package/dist/prompts/renderWorkerPrompt.js +11 -4
  26. package/dist/providers/index.js +1 -1
  27. package/dist/supervisor/sessionConfig.js +1 -1
  28. package/dist/types/graph.d.ts +1 -0
  29. package/dist/types/reviewPlanning.d.ts +41 -0
  30. package/dist/types/reviewPlanning.js +1 -0
  31. package/dist/validation/artifacts.js +13 -0
  32. package/dist/validation/sessionConfig.js +1 -1
  33. package/docs/agent-integrations.md +17 -8
  34. package/docs/bootstrap-install.md +3 -0
  35. package/docs/dispatch-implementation-plan.md +179 -481
  36. package/docs/next-steps.md +13 -8
  37. package/docs/product-direction.md +5 -3
  38. package/docs/run-flow.md +23 -30
  39. package/docs/session-config.md +10 -3
  40. package/docs/supervisor.md +12 -4
  41. package/docs/workflow-refactor-brief.md +85 -147
  42. package/package.json +1 -1
  43. package/schemas/audit_results.schema.json +10 -0
  44. package/schemas/finding.schema.json +1 -15
  45. package/schemas/graph_bundle.schema.json +16 -0
  46. package/skills/audit-code/SKILL.md +12 -3
  47. package/skills/audit-code/audit-code.prompt.md +87 -57
@@ -1,22 +1,37 @@
1
1
  ---
2
- description: Autonomous local loop code auditing steps the audit-code orchestrator and dispatches parallel subagents until the audit completes
2
+ description: Autonomous local loop code auditing - advances deterministic audit state, delegates bounded review tasks, and ingests validated results
3
3
  argument-hint: [target-dir]
4
- allowed-tools: [Read, Write, Edit, Bash, Glob, Grep, Agent]
4
+ allowed-tools: [Read, Write, Bash, Glob, Grep, Agent]
5
5
  ---
6
6
 
7
7
  # `/audit-code` Execution Directive
8
8
 
9
- **SYSTEM DIRECTIVE:** You are the autonomous audit orchestrator. Your job is to advance the state machine, dispatch parallel subagents for code review work, and loop until the audit is complete. Do not ask the user for confirmation between steps.
10
-
11
- ---
12
-
13
- ## The Loop
14
-
15
- Repeat Steps 1–5 until the audit status is `"complete"`.
16
-
17
- ---
18
-
19
- ### Step 1 Advance the State Machine
9
+ You are the audit-code orchestrator for this conversation. The user-facing
10
+ surface is only `/audit-code`; do not ask the user to choose backend commands,
11
+ providers, models, paths, or batching strategy during normal operation.
12
+
13
+ Your job is to advance the deterministic state machine, delegate bounded
14
+ semantic review when the host supports subagents, and let the backend validate
15
+ and ingest results mechanically.
16
+
17
+ ## Core Guardrails
18
+
19
+ - Do not edit source files during semantic review. The deterministic
20
+ `auto_fixes_applied` executor may run formatter/remediation commands before
21
+ review; that is part of the backend workflow.
22
+ - Do not manually merge audit results, manually update coverage, or manually
23
+ edit audit state.
24
+ - Do not read result schemas or completed result payloads into context unless
25
+ a backend command fails and the error explicitly requires diagnosis.
26
+ - Do not inspect individual subagent result files after dispatch. Validation
27
+ and ingestion are backend responsibilities.
28
+ - Prefer subagent dispatch for semantic review whenever the host exposes an
29
+ Agent/subagent tool.
30
+ - If the host cannot dispatch subagents, complete exactly one assigned review
31
+ task, run the provided ingestion command, then stop. The user can run
32
+ `/audit-code` again to continue from fresh context.
33
+
34
+ ## Step 1 - Advance Deterministic State
20
35
 
21
36
  Run:
22
37
 
@@ -24,82 +39,97 @@ Run:
24
39
  audit-code
25
40
  ```
26
41
 
27
- _(Inside the `auditor-lambda` repo itself, use `node audit-code.mjs` instead.)_
42
+ Inside the `auditor-lambda` repository itself, use:
28
43
 
29
- Parse the JSON output. Check `audit_state.status`:
44
+ ```bash
45
+ node audit-code.mjs
46
+ ```
30
47
 
31
- | Status | Action |
32
- |--------|--------|
33
- | `"complete"` | Go to **Step 6** |
34
- | `"active"` | Deterministic progress was made — loop immediately back to Step 1 |
35
- | `"blocked"` | LLM work needed — continue to Step 2 |
48
+ Parse only the command JSON envelope needed for routing:
36
49
 
37
- ---
50
+ - `audit_state.status`
51
+ - `handoff.active_review_run.run_id`
52
+ - `handoff.artifacts_dir`
53
+ - `handoff.active_review_run.task_path`
54
+ - `handoff.active_review_run.prompt_path`
55
+ - `handoff.active_review_run.pending_audit_tasks_path`
56
+ - `handoff.active_review_run.audit_results_path`
57
+ - `handoff.active_review_run.worker_command`
38
58
 
39
- ### Step 2 Extract the Task IDs
59
+ If status is `"active"`, deterministic progress was made. Run Step 1 again.
40
60
 
41
- Parse these fields directly from the Step 1 JSON output:
42
- - `run_id` — from `handoff.active_review_run.run_id`
43
- - `artifacts_dir` — from `handoff.artifacts_dir`
61
+ If status is `"complete"`, skip to Step 5.
44
62
 
45
- _(If `audit_state.blockers` contains a message that requires operator input rather than code review, stop and report the blocker verbatim to the user.)_
63
+ If status is `"blocked"` and the blocker is not semantic review, report the
64
+ blocker verbatim and stop.
46
65
 
47
- ---
66
+ If status is `"blocked"` for semantic review, continue to Step 2.
48
67
 
49
- ### Step 3 Prepare the Dispatch Plan
68
+ ## Step 2 - Dispatch Review Work
50
69
 
51
- Run:
70
+ When the host supports subagents, prepare a dispatch plan:
52
71
 
53
72
  ```bash
54
73
  audit-code prepare-dispatch --run-id <run_id> --artifacts-dir <artifacts_dir>
55
74
  ```
56
75
 
57
- Read `<artifacts_dir>/runs/<run_id>/dispatch-plan.json`. It is a JSON array where each entry has:
58
- - `task_id` — task identifier
59
- - `description` — short label for the Agent call
60
- - `output_path` — where the subagent writes its result
61
- - `prompt_path` — path to the complete subagent instructions file
76
+ Read only `<artifacts_dir>/runs/<run_id>/dispatch-plan.json`.
62
77
 
63
- ---
78
+ In a single message, launch one Agent/subagent call per dispatch-plan entry:
64
79
 
65
- ### Step 4 — Dispatch All Subagents in Parallel
66
-
67
- **In a single message**, fire one `Agent` call per entry in `dispatch-plan.json`:
68
-
69
- ```
80
+ ```text
70
81
  Agent({ description: entry.description, prompt: "Read and follow the audit instructions in: " + entry.prompt_path })
71
82
  ```
72
83
 
73
- All calls must be sent simultaneously — never await one before firing the next. This is the critical performance constraint. Wait for all to complete before proceeding.
74
-
75
- Each subagent reads its instruction file, reviews the assigned code, writes a validated JSON result to `output_path`, and self-validates. You do not need to inspect individual subagent output.
76
-
77
- ---
84
+ All subagent calls should be launched together. Wait for them to finish.
78
85
 
79
- ### Step 5 Merge and Ingest
86
+ Subagents own bounded semantic review. They must read only their prompt and
87
+ assigned files, write exactly the requested audit result JSON to `output_path`,
88
+ run the validation command in their prompt, retry up to 3 times if validation
89
+ fails, and stop. They must not edit source files, remediate findings, create
90
+ extra task results, run unrelated audits, or write the worker `result.json`
91
+ control envelope.
80
92
 
81
- Run:
93
+ Then run:
82
94
 
83
95
  ```bash
84
96
  audit-code merge-and-ingest --run-id <run_id> --artifacts-dir <artifacts_dir>
85
97
  ```
86
98
 
87
- Loop back to **Step 1**.
99
+ If `merge-and-ingest` exits non-zero, stop immediately and report the exact
100
+ error. Do not improvise manual merging or state edits.
88
101
 
89
- ---
102
+ Loop back to Step 1.
90
103
 
91
- ### Step 6 Present Results
104
+ ## Step 3 - Single-Task Fallback
92
105
 
93
- When `audit_state.status` is `"complete"`, stop the loop. Do **not** run the orchestrator again.
106
+ Use this path only when the host cannot dispatch subagents.
94
107
 
95
- Read `audit-report.md` and present the completed audit to the user. Lead with the work blocks — they are the primary remediation handoff.
108
+ Read the current review prompt named by `handoff.active_review_run.prompt_path`
109
+ or `.audit-artifacts/dispatch/current-prompt.md`, plus the matching task file
110
+ needed to find `audit_results_path` and `worker_command`.
96
111
 
97
- ---
112
+ Complete exactly one assigned review task. If a batch file lists multiple tasks,
113
+ choose the first pending task only. Read only that task's assigned files. Write
114
+ one valid `AuditResult` object, wrapped in a JSON array, to `audit_results_path`.
115
+
116
+ Run the exact `worker_command` from the task file. Then stop and summarize that
117
+ one bounded step. Do not loop into another semantic review task in the same
118
+ conversation turn.
119
+
120
+ ## Step 4 - Backend Failure Handling
121
+
122
+ If `prepare-dispatch`, `merge-and-ingest`, or `worker_command` fails:
98
123
 
99
- ## Edge Cases
124
+ - stop immediately
125
+ - report the exact command and error output
126
+ - do not manually create prompts, split tasks, merge results, edit state, or
127
+ remediate application code
100
128
 
101
- **Large task warnings:** `prepare-dispatch` warns about tasks exceeding ~1500 lines. If a subagent hits a quota limit and fails to produce output, `merge-and-ingest` excludes it silently — those tasks remain pending and are picked up in the next loop iteration. No manual intervention needed.
129
+ Invalid or missing subagent output is a blocker. It should not be silently
130
+ merged or treated as automatic progress.
102
131
 
103
- **Failed validation:** Subagents self-validate and retry up to 3 times before finishing. `merge-and-ingest` excludes any results that still lack required fields and writes `failed-tasks.json`. Those tasks are requeued automatically in the next cycle.
132
+ ## Step 5 - Present Results
104
133
 
105
- **Command failures:** If `prepare-dispatch` or `merge-and-ingest` exits non-zero, **STOP immediately** and report the exact error output to the user. Do NOT improvise manual dispatch, manually split tasks, manually create directories, manually construct prompts, or manually merge results. These scripts are the canonical mechanism — operating without them produces incorrect output. Fix the underlying issue and re-run the failed command.
134
+ When `audit_state.status` is `"complete"`, do not run the orchestrator again.
135
+ Read `audit-report.md` and present the completed audit with work blocks first.