auditor-lambda 0.10.3 → 0.10.7

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 (183) hide show
  1. package/audit-code-wrapper-build.mjs +198 -0
  2. package/audit-code-wrapper-install-hosts.mjs +1140 -0
  3. package/audit-code-wrapper-io.mjs +155 -0
  4. package/audit-code-wrapper-legacy.mjs +125 -0
  5. package/audit-code-wrapper-lib.mjs +17 -1801
  6. package/audit-code-wrapper-opencode.mjs +256 -0
  7. package/dispatch/merge-results.mjs +5 -3
  8. package/dispatch/validate-result.mjs +2 -2
  9. package/dist/adapters/coverageSummary.js +6 -2
  10. package/dist/adapters/normalizeExternal.js +16 -1
  11. package/dist/adapters/npmAudit.js +20 -9
  12. package/dist/adapters/semgrep.js +26 -1
  13. package/dist/cli/advanceAuditCommand.d.ts +1 -0
  14. package/dist/cli/advanceAuditCommand.js +95 -0
  15. package/dist/cli/args.js +1 -2
  16. package/dist/cli/auditStep.js +2 -2
  17. package/dist/cli/cleanup.d.ts +11 -1
  18. package/dist/cli/cleanup.js +25 -5
  19. package/dist/cli/cleanupCommand.d.ts +1 -0
  20. package/dist/cli/cleanupCommand.js +24 -0
  21. package/dist/cli/dispatch.d.ts +55 -31
  22. package/dist/cli/dispatch.js +298 -241
  23. package/dist/cli/dispatchStatusCommand.d.ts +1 -0
  24. package/dist/cli/dispatchStatusCommand.js +68 -0
  25. package/dist/cli/explainTaskCommand.d.ts +1 -0
  26. package/dist/cli/explainTaskCommand.js +33 -0
  27. package/dist/cli/importExternalAnalyzerCommand.d.ts +1 -0
  28. package/dist/cli/importExternalAnalyzerCommand.js +20 -0
  29. package/dist/cli/ingestResultsCommand.d.ts +1 -0
  30. package/dist/cli/ingestResultsCommand.js +34 -0
  31. package/dist/cli/intakeCommand.d.ts +1 -0
  32. package/dist/cli/intakeCommand.js +17 -0
  33. package/dist/cli/lineIndex.js +19 -12
  34. package/dist/cli/nextStepCommand.d.ts +139 -0
  35. package/dist/cli/nextStepCommand.js +281 -232
  36. package/dist/cli/planCommand.d.ts +1 -0
  37. package/dist/cli/planCommand.js +16 -0
  38. package/dist/cli/prepareDispatchCommand.d.ts +1 -0
  39. package/dist/cli/prepareDispatchCommand.js +25 -0
  40. package/dist/cli/quotaCommand.d.ts +1 -0
  41. package/dist/cli/quotaCommand.js +56 -0
  42. package/dist/cli/requeueCommand.d.ts +1 -0
  43. package/dist/cli/requeueCommand.js +10 -0
  44. package/dist/cli/runToCompletion.js +451 -412
  45. package/dist/cli/sampleRunCommand.d.ts +1 -0
  46. package/dist/cli/sampleRunCommand.js +93 -0
  47. package/dist/cli/statusCommand.js +1 -1
  48. package/dist/cli/steps.js +4 -1
  49. package/dist/cli/submitPacketCommand.js +16 -15
  50. package/dist/cli/synthesizeCommand.d.ts +1 -0
  51. package/dist/cli/synthesizeCommand.js +15 -0
  52. package/dist/cli/updateRuntimeValidationCommand.d.ts +1 -0
  53. package/dist/cli/updateRuntimeValidationCommand.js +16 -0
  54. package/dist/cli/validateCommand.d.ts +1 -0
  55. package/dist/cli/validateCommand.js +41 -0
  56. package/dist/cli/validateResultCommand.d.ts +1 -0
  57. package/dist/cli/validateResultCommand.js +63 -0
  58. package/dist/cli/validateResultsCommand.d.ts +1 -0
  59. package/dist/cli/validateResultsCommand.js +31 -0
  60. package/dist/cli/workerRunCommand.d.ts +15 -1
  61. package/dist/cli/workerRunCommand.js +40 -4
  62. package/dist/cli.d.ts +3 -2
  63. package/dist/cli.js +21 -628
  64. package/dist/coverage.js +7 -3
  65. package/dist/extractors/analyzers/css.js +2 -2
  66. package/dist/extractors/analyzers/html.js +2 -2
  67. package/dist/extractors/analyzers/python.js +2 -2
  68. package/dist/extractors/analyzers/registry.js +17 -36
  69. package/dist/extractors/analyzers/treeSitter.d.ts +10 -1
  70. package/dist/extractors/analyzers/treeSitter.js +28 -6
  71. package/dist/extractors/analyzers/typescript.js +104 -85
  72. package/dist/extractors/browserExtension.js +4 -1
  73. package/dist/extractors/designAssessment.js +21 -21
  74. package/dist/extractors/fsIntake.js +34 -10
  75. package/dist/extractors/graph.js +17 -7
  76. package/dist/extractors/graphManifestEdges/cargo.d.ts +4 -0
  77. package/dist/extractors/graphManifestEdges/cargo.js +107 -0
  78. package/dist/extractors/graphManifestEdges/go.d.ts +5 -0
  79. package/dist/extractors/graphManifestEdges/go.js +151 -0
  80. package/dist/extractors/graphManifestEdges/index.d.ts +8 -0
  81. package/dist/extractors/graphManifestEdges/index.js +11 -0
  82. package/dist/extractors/graphManifestEdges/jsonc.d.ts +3 -0
  83. package/dist/extractors/graphManifestEdges/jsonc.js +97 -0
  84. package/dist/extractors/graphManifestEdges/maven.d.ts +3 -0
  85. package/dist/extractors/graphManifestEdges/maven.js +73 -0
  86. package/dist/extractors/graphManifestEdges/packageJson.d.ts +19 -0
  87. package/dist/extractors/graphManifestEdges/packageJson.js +204 -0
  88. package/dist/extractors/graphManifestEdges/pnpm.d.ts +2 -0
  89. package/dist/extractors/graphManifestEdges/pnpm.js +42 -0
  90. package/dist/extractors/graphManifestEdges/pyproject.d.ts +3 -0
  91. package/dist/extractors/graphManifestEdges/pyproject.js +83 -0
  92. package/dist/extractors/graphManifestEdges/toml.d.ts +4 -0
  93. package/dist/extractors/graphManifestEdges/toml.js +68 -0
  94. package/dist/extractors/graphManifestEdges/typescript.d.ts +3 -0
  95. package/dist/extractors/graphManifestEdges/typescript.js +56 -0
  96. package/dist/extractors/graphManifestEdges/workspace.d.ts +10 -0
  97. package/dist/extractors/graphManifestEdges/workspace.js +72 -0
  98. package/dist/extractors/graphManifestEdges/yaml.d.ts +3 -0
  99. package/dist/extractors/graphManifestEdges/yaml.js +59 -0
  100. package/dist/extractors/graphManifestEdges/yamlPaths.d.ts +4 -0
  101. package/dist/extractors/graphManifestEdges/yamlPaths.js +89 -0
  102. package/dist/extractors/graphPythonImports.js +4 -20
  103. package/dist/extractors/pathPatterns.js +3 -13
  104. package/dist/io/artifacts.d.ts +1 -1
  105. package/dist/io/artifacts.js +4 -1
  106. package/dist/io/runArtifacts.d.ts +8 -2
  107. package/dist/io/runArtifacts.js +103 -69
  108. package/dist/io/toolingManifest.js +2 -1
  109. package/dist/orchestrator/advance.js +36 -0
  110. package/dist/orchestrator/artifactFreshness.d.ts +1 -1
  111. package/dist/orchestrator/artifactFreshness.js +1 -1
  112. package/dist/orchestrator/artifactMetadata.js +5 -5
  113. package/dist/orchestrator/auditTaskUtils.d.ts +4 -0
  114. package/dist/orchestrator/auditTaskUtils.js +8 -12
  115. package/dist/orchestrator/autoFixExecutor.js +40 -26
  116. package/dist/orchestrator/dependencyMap.js +1 -1
  117. package/dist/orchestrator/executorResult.d.ts +33 -0
  118. package/dist/orchestrator/executors.d.ts +7 -0
  119. package/dist/orchestrator/executors.js +24 -0
  120. package/dist/orchestrator/fileAnchors.js +42 -29
  121. package/dist/orchestrator/fileIntegrity.js +6 -1
  122. package/dist/orchestrator/flowCoverage.js +1 -2
  123. package/dist/orchestrator/flowPlanning.js +8 -4
  124. package/dist/orchestrator/graphEnrichmentExecutor.js +67 -45
  125. package/dist/orchestrator/ingestionExecutors.js +9 -1
  126. package/dist/orchestrator/intakeExecutors.d.ts +0 -4
  127. package/dist/orchestrator/intakeExecutors.js +24 -14
  128. package/dist/orchestrator/localCommands.d.ts +1 -0
  129. package/dist/orchestrator/localCommands.js +10 -17
  130. package/dist/orchestrator/nextStep.js +3 -1
  131. package/dist/orchestrator/requeueCommand.js +4 -0
  132. package/dist/orchestrator/reviewPacketGraph.js +50 -18
  133. package/dist/orchestrator/reviewPackets.js +10 -8
  134. package/dist/orchestrator/runtimeCommand.js +35 -7
  135. package/dist/orchestrator/runtimeValidationUpdate.js +6 -0
  136. package/dist/orchestrator/selectiveDeepening/highRiskClean.js +3 -2
  137. package/dist/orchestrator/selectiveDeepening/lensVerification.js +44 -18
  138. package/dist/orchestrator/staleness.js +3 -3
  139. package/dist/orchestrator/state.js +1 -1
  140. package/dist/orchestrator/syntaxResolutionExecutor.js +17 -24
  141. package/dist/orchestrator/synthesisExecutors.js +1 -0
  142. package/dist/orchestrator/taskBuilder.js +5 -4
  143. package/dist/providers/claudeCodeProvider.js +4 -1
  144. package/dist/providers/opencodeProvider.js +4 -1
  145. package/dist/quota/discoveredLimits.js +3 -3
  146. package/dist/quota/headerExtraction.js +5 -2
  147. package/dist/quota/headerExtractors/claudeCodeHeaderExtractor.js +3 -0
  148. package/dist/quota/headerExtractors/index.js +3 -3
  149. package/dist/quota/index.d.ts +3 -1
  150. package/dist/quota/index.js +3 -0
  151. package/dist/reporting/findingRanks.d.ts +3 -0
  152. package/dist/reporting/findingRanks.js +24 -0
  153. package/dist/reporting/mergeFindings.js +1 -24
  154. package/dist/reporting/synthesis.d.ts +3 -1
  155. package/dist/reporting/synthesis.js +30 -6
  156. package/dist/reporting/synthesisNarrativePrompt.js +3 -0
  157. package/dist/reporting/workBlocks.js +1 -14
  158. package/dist/supervisor/operatorHandoff.js +2 -6
  159. package/dist/supervisor/runLedger.js +30 -41
  160. package/dist/types/activeDispatch.d.ts +31 -0
  161. package/dist/types/activeDispatch.js +2 -0
  162. package/dist/types.d.ts +21 -4
  163. package/dist/types.js +24 -16
  164. package/dist/validation/artifacts.js +3 -0
  165. package/dist/validation/auditResults.js +8 -2
  166. package/package.json +2 -2
  167. package/schemas/audit_findings.schema.json +5 -1
  168. package/schemas/audit_plan_metrics.schema.json +1 -1
  169. package/schemas/audit_result.schema.json +5 -6
  170. package/schemas/audit_task.schema.json +1 -4
  171. package/schemas/blind_spot_register.schema.json +1 -1
  172. package/schemas/coverage_matrix.schema.json +2 -8
  173. package/schemas/finding.schema.json +1 -16
  174. package/schemas/flow_coverage.schema.json +2 -8
  175. package/schemas/graph_bundle.schema.json +31 -0
  176. package/schemas/lens.schema.json +7 -0
  177. package/schemas/review_packets.schema.json +6 -17
  178. package/schemas/step_contract.schema.json +8 -2
  179. package/schemas/unit_manifest.schema.json +1 -4
  180. package/scripts/postinstall.mjs +3 -1
  181. package/skills/audit-code/audit-code.prompt.md +2 -3
  182. package/dist/extractors/graphManifestEdges.d.ts +0 -12
  183. package/dist/extractors/graphManifestEdges.js +0 -1135
@@ -0,0 +1,198 @@
1
+ import { open, stat, unlink } from 'node:fs/promises';
2
+ import { spawn } from 'node:child_process';
3
+ import { createRequire } from 'node:module';
4
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { fileExists, newestMtimeMs } from './audit-code-wrapper-io.mjs';
7
+
8
+ const repoRoot = dirname(fileURLToPath(import.meta.url));
9
+ const distEntry = join(repoRoot, 'dist', 'index.js');
10
+ const tsconfigPath = join(repoRoot, 'tsconfig.json');
11
+ const sourceRoot = join(repoRoot, 'src');
12
+ const buildLockPath = join(repoRoot, '.audit-code-build.lock');
13
+ const BUILD_LOCK_MAX_AGE_MS = 5 * 60 * 1000;
14
+ const BUILD_LOCK_WAIT_TIMEOUT_MS = 2 * 60 * 1000;
15
+ const BUILD_LOCK_WAIT_INTERVAL_MS = 200;
16
+
17
+ function npmExecutable() {
18
+ return process.platform === 'win32' ? 'npm.cmd' : 'npm';
19
+ }
20
+
21
+ function resolveSpawn(command, args) {
22
+ if (!(process.platform === 'win32' && /\.(cmd|bat)$/i.test(command))) {
23
+ return { command, args };
24
+ }
25
+ return {
26
+ command: process.env.ComSpec ?? 'cmd.exe',
27
+ args: ['/d', '/s', '/c', [command, ...args].map((arg) => {
28
+ if (arg.length === 0) return '""';
29
+ if (!/[\s"]/u.test(arg)) return arg;
30
+ return `"${arg.replace(/"/g, '""')}"`;
31
+ }).join(' ')],
32
+ };
33
+ }
34
+
35
+ function runBuild(command, args) {
36
+ return new Promise((resolvePromise, rejectPromise) => {
37
+ const resolved = resolveSpawn(command, args);
38
+ const child = spawn(resolved.command, resolved.args, {
39
+ cwd: repoRoot,
40
+ // Auto-rebuild output is diagnostic — route both child streams to the
41
+ // parent's stderr (fd 2) so npm's `> auditor-lambda@… build` banner can
42
+ // never pollute the wrapper's stdout JSON channel when a caller captures it.
43
+ stdio: ['ignore', 2, 2],
44
+ env: process.env,
45
+ });
46
+ child.on('error', rejectPromise);
47
+ child.on('exit', (code) => {
48
+ if (code === 0) {
49
+ resolvePromise();
50
+ return;
51
+ }
52
+ rejectPromise(new Error(`Command failed with exit code ${code}.`));
53
+ });
54
+ });
55
+ }
56
+
57
+ export async function shouldBuildDistForPaths({
58
+ distEntryPath,
59
+ sourceRootPath,
60
+ tsconfigPath: tsconfigPathValue,
61
+ }) {
62
+ if (!(await fileExists(distEntryPath))) {
63
+ if (!(await fileExists(sourceRootPath)) || !(await fileExists(tsconfigPathValue))) {
64
+ throw new Error(
65
+ 'Bundled dist is missing and source files are unavailable for rebuild.',
66
+ );
67
+ }
68
+ return true;
69
+ }
70
+
71
+ if (!(await fileExists(sourceRootPath)) || !(await fileExists(tsconfigPathValue))) {
72
+ return false;
73
+ }
74
+
75
+ const distMtime = (await stat(distEntryPath)).mtimeMs;
76
+ const sourceMtime = await newestMtimeMs(sourceRootPath);
77
+ const tsconfigMtime = (await stat(tsconfigPathValue)).mtimeMs;
78
+ const newestInput = Math.max(sourceMtime, tsconfigMtime);
79
+ return distMtime < newestInput;
80
+ }
81
+
82
+ async function shouldBuildDist() {
83
+ return await shouldBuildDistForPaths({
84
+ distEntryPath: distEntry,
85
+ sourceRootPath: sourceRoot,
86
+ tsconfigPath,
87
+ });
88
+ }
89
+
90
+ async function releaseBuildLock(handle) {
91
+ try {
92
+ await handle?.close();
93
+ } finally {
94
+ await unlink(buildLockPath).catch(() => {});
95
+ }
96
+ }
97
+
98
+ async function waitForPeerBuild() {
99
+ const start = Date.now();
100
+
101
+ while (true) {
102
+ if (!(await fileExists(buildLockPath))) {
103
+ return;
104
+ }
105
+
106
+ if (Date.now() - start > BUILD_LOCK_WAIT_TIMEOUT_MS) {
107
+ throw new Error(`Timed out waiting for build lock ${buildLockPath}.`);
108
+ }
109
+
110
+ await new Promise((r) => setTimeout(r, BUILD_LOCK_WAIT_INTERVAL_MS));
111
+ }
112
+ }
113
+
114
+ async function acquireBuildLock() {
115
+ while (true) {
116
+ try {
117
+ const handle = await open(buildLockPath, 'wx');
118
+ await handle.writeFile(JSON.stringify({ pid: process.pid, acquired_at: new Date().toISOString() }));
119
+ return handle;
120
+ } catch (error) {
121
+ if (error && error.code === 'EEXIST') {
122
+ try {
123
+ const lockStats = await stat(buildLockPath);
124
+ if (Date.now() - lockStats.mtimeMs > BUILD_LOCK_MAX_AGE_MS) {
125
+ await unlink(buildLockPath).catch(() => {});
126
+ continue;
127
+ }
128
+ } catch {
129
+ continue;
130
+ }
131
+
132
+ await waitForPeerBuild();
133
+ if (!(await shouldBuildDist())) {
134
+ return null;
135
+ }
136
+ continue;
137
+ }
138
+ throw error;
139
+ }
140
+ }
141
+ }
142
+
143
+ export function assertWorkspaceInstalled({ checkoutRoot, sharedManifestPath }) {
144
+ if (!sharedManifestPath) {
145
+ throw new Error(
146
+ 'Dependencies are not installed for this checkout. Run `npm install` from ' +
147
+ 'the repository root, then retry — building from source needs node_modules ' +
148
+ '(including the @audit-tools/shared workspace link).',
149
+ );
150
+ }
151
+
152
+ const relToCheckout = relative(checkoutRoot, sharedManifestPath);
153
+ if (relToCheckout.startsWith('..') || isAbsolute(relToCheckout)) {
154
+ throw new Error(
155
+ `@audit-tools/shared resolved to ${sharedManifestPath}, outside this ` +
156
+ `checkout (${checkoutRoot}). node_modules was never installed here — ` +
157
+ 'common in a fresh git worktree — so building would typecheck against ' +
158
+ "another checkout's stale dist and report phantom \"missing export\" " +
159
+ "errors. Run `npm install` from this checkout's root.",
160
+ );
161
+ }
162
+ }
163
+
164
+ async function preflightWorkspace() {
165
+ const requireFromHere = createRequire(import.meta.url);
166
+ let sharedManifestPath = null;
167
+ try {
168
+ sharedManifestPath = requireFromHere.resolve('@audit-tools/shared/package.json');
169
+ } catch {
170
+ sharedManifestPath = null;
171
+ }
172
+ assertWorkspaceInstalled({
173
+ checkoutRoot: resolve(repoRoot, '..', '..'),
174
+ sharedManifestPath,
175
+ });
176
+ }
177
+
178
+ export async function ensureBuilt() {
179
+ if (!(await shouldBuildDist())) {
180
+ return;
181
+ }
182
+
183
+ await preflightWorkspace();
184
+
185
+ const lockHandle = await acquireBuildLock();
186
+ if (!lockHandle) {
187
+ return;
188
+ }
189
+
190
+ try {
191
+ if (!(await shouldBuildDist())) {
192
+ return;
193
+ }
194
+ await runBuild(npmExecutable(), ['run', 'build']);
195
+ } finally {
196
+ await releaseBuildLock(lockHandle);
197
+ }
198
+ }