auditor-lambda 0.3.20 → 0.3.22

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.
@@ -0,0 +1,77 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "audit-code-dispatch-quota/v1alpha1",
4
+ "title": "DispatchQuota",
5
+ "description": "Quota schedule for a prepare-dispatch run. Written beside dispatch-plan.json. Hosts must launch at most wave_size packets per wave, then re-read this file before the next wave to pick up any updated limits.",
6
+ "type": "object",
7
+ "required": [
8
+ "contract_version",
9
+ "run_id",
10
+ "model",
11
+ "resolved_limits",
12
+ "confidence",
13
+ "source",
14
+ "wave_size",
15
+ "estimated_wave_tokens",
16
+ "cooldown_until"
17
+ ],
18
+ "additionalProperties": false,
19
+ "properties": {
20
+ "contract_version": {
21
+ "type": "string",
22
+ "const": "audit-code-dispatch-quota/v1alpha1"
23
+ },
24
+ "run_id": {
25
+ "type": "string",
26
+ "description": "The dispatch run this quota schedule applies to."
27
+ },
28
+ "model": {
29
+ "type": ["string", "null"],
30
+ "description": "The host model this schedule was computed for, or null if unknown."
31
+ },
32
+ "resolved_limits": {
33
+ "type": "object",
34
+ "description": "The rate and context limits used to compute the wave size.",
35
+ "required": [
36
+ "context_tokens",
37
+ "output_tokens",
38
+ "requests_per_minute",
39
+ "input_tokens_per_minute",
40
+ "output_tokens_per_minute"
41
+ ],
42
+ "additionalProperties": false,
43
+ "properties": {
44
+ "context_tokens": { "type": "integer", "minimum": 1 },
45
+ "output_tokens": { "type": "integer", "minimum": 1 },
46
+ "requests_per_minute": { "type": ["integer", "null"], "minimum": 1 },
47
+ "input_tokens_per_minute": { "type": ["integer", "null"], "minimum": 1 },
48
+ "output_tokens_per_minute": { "type": ["integer", "null"], "minimum": 1 }
49
+ }
50
+ },
51
+ "confidence": {
52
+ "type": "string",
53
+ "enum": ["high", "medium", "low"],
54
+ "description": "How confident the scheduler is in the resolved limits."
55
+ },
56
+ "source": {
57
+ "type": "string",
58
+ "enum": ["explicit_config", "cli_flags", "known_metadata", "learned", "default"],
59
+ "description": "Where the resolved limits came from."
60
+ },
61
+ "wave_size": {
62
+ "type": "integer",
63
+ "minimum": 1,
64
+ "description": "Maximum number of packets to dispatch in a single wave."
65
+ },
66
+ "estimated_wave_tokens": {
67
+ "type": "integer",
68
+ "minimum": 0,
69
+ "description": "Estimated total input tokens for one wave at the recommended wave_size."
70
+ },
71
+ "cooldown_until": {
72
+ "type": ["string", "null"],
73
+ "format": "date-time",
74
+ "description": "If non-null, the host should wait until this timestamp before launching the next wave."
75
+ }
76
+ }
77
+ }
@@ -56,6 +56,11 @@ const OPENCODE_AUDIT_BASH_PERMISSION = {
56
56
  'audit-code cleanup*': 'deny',
57
57
  'audit-code requeue*': 'deny',
58
58
  'audit-code ingest-results*': 'deny',
59
+ '*dist*index.js* run-to-completion*': 'deny',
60
+ '*dist*index.js* synthesize*': 'deny',
61
+ '*dist*index.js* cleanup*': 'deny',
62
+ '*dist*index.js* requeue*': 'deny',
63
+ '*dist*index.js* ingest-results*': 'deny',
59
64
  '*audit-code.mjs* run-to-completion*': 'deny',
60
65
  '*audit-code.mjs* synthesize*': 'deny',
61
66
  '*audit-code.mjs* cleanup*': 'deny',
@@ -63,25 +68,44 @@ const OPENCODE_AUDIT_BASH_PERMISSION = {
63
68
  '*audit-code.mjs* ingest-results*': 'deny',
64
69
  'audit-code': 'allow',
65
70
  'audit-code ensure*': 'allow',
71
+ 'audit-code next-step*': 'allow',
66
72
  'audit-code prepare-dispatch*': 'allow',
67
73
  'audit-code submit-packet*': 'allow',
68
74
  'audit-code merge-and-ingest*': 'allow',
69
75
  'audit-code validate*': 'allow',
70
76
  '*audit-code.mjs': 'allow',
71
77
  '*audit-code.mjs* ensure*': 'allow',
78
+ '*audit-code.mjs* next-step*': 'allow',
72
79
  '*audit-code.mjs* prepare-dispatch*': 'allow',
73
80
  '*audit-code.mjs* submit-packet*': 'allow',
74
81
  '*audit-code.mjs* merge-and-ingest*': 'allow',
75
82
  '*audit-code.mjs* worker-run*': 'allow',
76
83
  '*audit-code.mjs* validate*': 'allow',
84
+ '*node* *auditor-lambda*dist*index.js* worker-run*': 'allow',
77
85
  'node* .audit-code/install/run-mcp-server.mjs*': 'allow',
78
86
  'node* ./.audit-code/install/run-mcp-server.mjs*': 'allow',
79
87
  'git status*': 'allow',
80
88
  'git diff*': 'allow',
81
89
  'grep *': 'allow',
90
+ 'Select-String *': 'allow',
82
91
  'rm *': 'deny',
83
92
  };
84
93
 
94
+ function replaceBackslashes(value) {
95
+ return value.replace(/\\/g, '/');
96
+ }
97
+
98
+ function externalDirectoryPattern(path) {
99
+ return `${replaceBackslashes(path).replace(/\/+$/u, '')}/**`;
100
+ }
101
+
102
+ function renderOpenCodeExternalDirectoryPermission() {
103
+ return {
104
+ [externalDirectoryPattern(pkgRoot)]: 'allow',
105
+ [externalDirectoryPattern(dirname(process.execPath))]: 'allow',
106
+ };
107
+ }
108
+
85
109
  function objectValue(value) {
86
110
  return value && typeof value === 'object' && !Array.isArray(value)
87
111
  ? value
@@ -127,6 +151,14 @@ function mergeOpenCodePermissionConfig(existingPermission, generatedPermission)
127
151
  return {
128
152
  ...generatedPermission,
129
153
  ...existingPermission,
154
+ read: generatedPermission.read,
155
+ glob: generatedPermission.glob,
156
+ grep: generatedPermission.grep,
157
+ external_directory: mergeOpenCodePermissionRule(
158
+ existingPermission.external_directory,
159
+ generatedPermission.external_directory,
160
+ generatedPermission.external_directory,
161
+ ),
130
162
  edit: mergeOpenCodePermissionRule(
131
163
  existingPermission.edit,
132
164
  generatedPermission.edit,
@@ -145,6 +177,7 @@ function renderOpenCodePermissionConfig() {
145
177
  read: 'allow',
146
178
  glob: 'allow',
147
179
  grep: 'allow',
180
+ external_directory: renderOpenCodeExternalDirectoryPermission(),
148
181
  edit: { ...OPENCODE_AUDIT_EDIT_PERMISSION },
149
182
  bash: { ...OPENCODE_AUDIT_BASH_PERMISSION },
150
183
  };
@@ -1,55 +1,17 @@
1
1
  ---
2
- description: Autonomous local loop code auditing - advances deterministic audit state, delegates bounded review tasks, and ingests validated results
2
+ description: Autonomous local loop code auditing - loads one backend-rendered audit step at a time
3
3
  argument-hint: [target-dir]
4
4
  allowed-tools: [Read, Bash, Glob, Grep, Agent]
5
5
  ---
6
6
 
7
- # `/audit-code` Execution Directive
7
+ # `/audit-code` Loader
8
8
 
9
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.
10
+ surface is `/audit-code`, but the backend owns every audit workflow branch.
12
11
 
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.
12
+ ## Loader
16
13
 
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
- - Do not inspect the backend command catalog or try alternate subcommands to
29
- bypass a blocked semantic-review handoff. In particular, do not run
30
- `run-to-completion`, `synthesize`, `cleanup`, `requeue`, or direct
31
- `ingest-results` while following this directive.
32
- - A report under `.audit-artifacts/` is not a completion signal while
33
- `audit_state.status` is `"blocked"`. Present a report only after Step 5.
34
- - CRITICAL: Do not use your `Read` tool to read `entry.prompt_path` or JSON schemas into your own context window. The subagent will read them. Pass the path literally.
35
- - Prefer subagent dispatch for semantic review whenever the host exposes an
36
- Agent/subagent tool.
37
- - Treat the user's `/audit-code` request as explicit authorization to launch
38
- review subagents in parallel. Do not ask for a separate delegation request
39
- before using available Agent/subagent tools.
40
- - Decide subagent support from the active toolset, not from shell commands or
41
- backend provider names. A shell command named `agent`, an MCP prompt, or a
42
- `local-subprocess` provider is not a host subagent facility.
43
- - Do not use `browser_subagent` for semantic review of source code unless the
44
- task explicitly requires browser-based validation.
45
- - If the host cannot dispatch subagents, complete exactly one assigned review
46
- task, run the provided ingestion command, then stop. The user can run
47
- `/audit-code` again to continue from fresh context.
48
-
49
- ## Step 1 - Advance Deterministic State
50
-
51
- First, make sure the repository has the minimal local assets required by the
52
- current host:
14
+ First, make sure the repository has current local audit assets:
53
15
 
54
16
  ```bash
55
17
  audit-code ensure --quiet
@@ -61,141 +23,24 @@ Inside the `auditor-lambda` repository itself, use:
61
23
  node audit-code.mjs ensure --quiet
62
24
  ```
63
25
 
64
- Then run:
26
+ Then ask the backend for exactly one next step:
65
27
 
66
28
  ```bash
67
- audit-code
29
+ audit-code next-step
68
30
  ```
69
31
 
70
32
  Inside the `auditor-lambda` repository itself, use:
71
33
 
72
34
  ```bash
73
- node audit-code.mjs
35
+ node audit-code.mjs next-step
74
36
  ```
75
37
 
76
- Parse only the command JSON envelope needed for routing:
77
-
78
- - `audit_state.status`
79
- - `handoff.active_review_run.run_id`
80
- - `handoff.artifacts_dir`
81
- - `handoff.active_review_run.task_path`
82
- - `handoff.active_review_run.prompt_path`
83
- - `handoff.active_review_run.pending_audit_tasks_path`
84
- - `handoff.active_review_run.audit_results_path`
85
- - `handoff.active_review_run.worker_command`
86
-
87
- If status is `"active"`, deterministic progress was made. Run Step 1 again.
88
-
89
- If status is `"complete"`, skip to Step 5.
90
-
91
- If status is `"blocked"` and the blocker is not semantic review, report the
92
- blocker verbatim and stop.
93
-
94
- If status is `"blocked"` for semantic review, continue to Step 2.
95
-
96
- ## Step 2 - Dispatch Review Work
97
-
98
- Use this step only when the active toolset exposes a callable host subagent
99
- facility such as `Agent`, `Task`, or an equivalent built-in delegation tool.
100
- Do not try to discover subagent support by running shell commands.
101
-
102
- When that callable subagent facility exists, prepare a dispatch plan by default:
103
-
104
- ```bash
105
- audit-code prepare-dispatch --run-id <run_id> --artifacts-dir <artifacts_dir>
106
- ```
107
-
108
- Read only `<artifacts_dir>/runs/<run_id>/dispatch-plan.json`.
109
-
110
- In a single message, launch one Agent/subagent call per dispatch-plan entry:
111
-
112
- ```text
113
- Agent({ description: entry.description, prompt: "Read and follow the audit instructions in: " + entry.prompt_path })
114
- ```
115
-
116
- Do NOT use your `Read` tool to load `entry.prompt_path` into your context window. The subagent has its own context window and will read the file.
117
-
118
- If the host supports per-subagent model selection, use `entry.model_hint.tier`
119
- as a provider-neutral routing hint (`small`, `standard`, or `deep`). Map it to
120
- available host models without asking the user to choose model names. If model
121
- selection is unavailable, ignore the hint and dispatch normally.
122
-
123
- If the host supports per-subagent tool restrictions, give review subagents no
124
- Write tool and allow shell access only for the `audit-code submit-packet`
125
- command printed in their prompt.
126
-
127
- All subagent calls should be launched together. Wait for them to finish.
128
-
129
- Subagents own bounded semantic review. They must read only their prompt and
130
- assigned files, produce the requested `AuditResult[]`, pipe it to the
131
- `submit-packet` command in their prompt, retry up to 3 times if submission
132
- fails, and stop. The backend command validates and writes the packet-owned
133
- result artifacts. They must not use direct file writes, edit source files,
134
- remediate findings, create extra task results, run unrelated audits, or write
135
- the worker `result.json` control envelope.
136
-
137
- Then run:
138
-
139
- ```bash
140
- audit-code merge-and-ingest --run-id <run_id> --artifacts-dir <artifacts_dir>
141
- ```
142
-
143
- If `merge-and-ingest` exits non-zero, stop immediately and report the exact
144
- error. Do not improvise manual merging or state edits.
145
-
146
- Loop back to Step 1.
147
-
148
- If no callable host subagent facility exists, or a delegation attempt fails
149
- because the host does not provide such a tool, go directly to Step 3. Do not run
150
- `prepare-dispatch`, do not inspect generated packet prompts, and do not try
151
- alternate backend commands.
152
-
153
- ## Step 3 - Single-Task Fallback
154
-
155
- Use this path only when the host cannot dispatch subagents.
156
-
157
- Allowed backend command in this step: the exact `worker_command` from the task
158
- file, after you have written the single-task result. Do not run `audit-code`,
159
- `run-to-completion`, `prepare-dispatch`, `merge-and-ingest`, `synthesize`,
160
- `validate`, or any other backend command as a substitute for the fallback.
161
-
162
- Read the generated single-task fallback prompt at
163
- `handoff.file_map.single_task_prompt` when present, otherwise
164
- `.audit-artifacts/dispatch/current-single-task-prompt.md`. That file is
165
- deterministically narrowed to the first pending task. If it is unavailable, read
166
- the current review prompt named by `handoff.active_review_run.prompt_path` or
167
- `.audit-artifacts/dispatch/current-prompt.md`, plus the matching task file
168
- needed to find `audit_results_path` and `worker_command`.
169
-
170
- Complete exactly one assigned review task. If a batch file lists multiple tasks,
171
- choose the first pending task by array order only; do not substitute a smaller
172
- or easier task. If that first task covers a large file, use targeted reads and
173
- searches within its assigned files instead of abandoning it. Read only that
174
- task's assigned files. Write one valid `AuditResult` object, wrapped in a JSON
175
- array, to `audit_results_path`.
176
-
177
- If the current review prompt says to produce results for every listed task, the
178
- single-task fallback overrides that wording for the top-level orchestrator:
179
- produce exactly one result for the first pending task only.
180
-
181
- Run the exact `worker_command` from the task file. Then stop and summarize that
182
- one bounded step. Do not loop into another semantic review task in the same
183
- conversation turn. Do not re-check audit state or read an audit report after the
184
- worker command.
185
-
186
- ## Step 4 - Backend Failure Handling
187
-
188
- If `prepare-dispatch`, `merge-and-ingest`, or `worker_command` fails:
189
-
190
- - stop immediately
191
- - report the exact command and error output
192
- - do not manually create prompts, split tasks, merge results, edit state, or
193
- remediate application code
194
-
195
- Invalid or missing subagent output is a blocker. It should not be silently
196
- merged or treated as automatic progress.
38
+ Read the returned JSON only far enough to find `prompt_path`, then read and
39
+ follow only that prompt. Do not read packet prompts, schemas, command catalogs,
40
+ or handoff files unless the current step prompt explicitly instructs you to do
41
+ so.
197
42
 
198
- ## Step 5 - Present Results
43
+ When a step prompt tells you to continue, run `audit-code next-step` again and
44
+ follow only the newly returned `prompt_path`.
199
45
 
200
- When `audit_state.status` is `"complete"`, do not run the orchestrator again.
201
- Read `audit-report.md` and present the completed audit with work blocks first.
46
+ Stop when the current step prompt tells you to stop.