auditor-lambda 0.3.40 → 0.3.41

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 (148) hide show
  1. package/audit-code-wrapper-lib.mjs +20 -2
  2. package/dist/cli/args.d.ts +59 -0
  3. package/dist/cli/args.js +244 -0
  4. package/dist/cli/dispatch.d.ts +80 -0
  5. package/dist/cli/dispatch.js +528 -0
  6. package/dist/cli/prompts.d.ts +18 -0
  7. package/dist/cli/prompts.js +130 -0
  8. package/dist/cli/steps.d.ts +29 -0
  9. package/dist/cli/steps.js +30 -0
  10. package/dist/cli/waveManifest.d.ts +40 -0
  11. package/dist/cli/waveManifest.js +41 -0
  12. package/dist/cli/workerResult.d.ts +18 -0
  13. package/dist/cli/workerResult.js +42 -0
  14. package/dist/cli.d.ts +2 -22
  15. package/dist/cli.js +160 -973
  16. package/dist/extractors/browserExtension.d.ts +1 -3
  17. package/dist/extractors/browserExtension.js +2 -2
  18. package/dist/extractors/designAssessment.d.ts +1 -3
  19. package/dist/extractors/disposition.d.ts +2 -1
  20. package/dist/extractors/disposition.js +3 -0
  21. package/dist/extractors/flows.d.ts +1 -3
  22. package/dist/extractors/flows.js +2 -2
  23. package/dist/extractors/graph.d.ts +1 -2
  24. package/dist/extractors/graph.js +4 -326
  25. package/dist/extractors/graphManifestEdges.d.ts +1 -1
  26. package/dist/extractors/graphPathUtils.d.ts +1 -1
  27. package/dist/extractors/graphPythonImports.d.ts +3 -0
  28. package/dist/extractors/graphPythonImports.js +326 -0
  29. package/dist/extractors/risk.d.ts +1 -2
  30. package/dist/extractors/surfaces.d.ts +1 -3
  31. package/dist/extractors/surfaces.js +2 -2
  32. package/dist/io/artifacts.d.ts +1 -5
  33. package/dist/io/artifacts.js +1 -1
  34. package/dist/io/runArtifacts.js +1 -1
  35. package/dist/mcp/server.js +1 -1
  36. package/dist/orchestrator/advance.d.ts +1 -0
  37. package/dist/orchestrator/advance.js +8 -5
  38. package/dist/orchestrator/auditTaskUtils.d.ts +4 -0
  39. package/dist/orchestrator/auditTaskUtils.js +27 -0
  40. package/dist/orchestrator/fileAnchors.d.ts +1 -1
  41. package/dist/orchestrator/fileIntegrity.d.ts +7 -0
  42. package/dist/orchestrator/fileIntegrity.js +41 -0
  43. package/dist/orchestrator/flowCoverage.d.ts +1 -1
  44. package/dist/orchestrator/flowPlanning.d.ts +1 -1
  45. package/dist/orchestrator/flowRequeue.d.ts +1 -1
  46. package/dist/orchestrator/internalExecutors.d.ts +3 -1
  47. package/dist/orchestrator/internalExecutors.js +23 -5
  48. package/dist/orchestrator/nextStep.d.ts +2 -1
  49. package/dist/orchestrator/nextStep.js +1 -1
  50. package/dist/orchestrator/planning.d.ts +1 -1
  51. package/dist/orchestrator/requeueCommand.d.ts +1 -1
  52. package/dist/orchestrator/reviewPackets.d.ts +1 -1
  53. package/dist/orchestrator/reviewPackets.js +21 -113
  54. package/dist/orchestrator/runtimeValidation.d.ts +1 -1
  55. package/dist/orchestrator/taskBuilder.d.ts +1 -1
  56. package/dist/orchestrator/taskBuilder.js +1 -12
  57. package/dist/orchestrator/unionFind.d.ts +7 -0
  58. package/dist/orchestrator/unionFind.js +32 -0
  59. package/dist/orchestrator/unitBuilder.d.ts +2 -2
  60. package/dist/orchestrator/unitBuilder.js +4 -18
  61. package/dist/prompts/renderWorkerPrompt.js +18 -1
  62. package/dist/providers/claudeCodeProvider.d.ts +4 -4
  63. package/dist/providers/claudeCodeProvider.js +9 -3
  64. package/dist/providers/constants.d.ts +1 -1
  65. package/dist/providers/constants.js +1 -1
  66. package/dist/providers/index.d.ts +1 -2
  67. package/dist/providers/index.js +5 -4
  68. package/dist/providers/localSubprocessProvider.d.ts +2 -2
  69. package/dist/providers/localSubprocessProvider.js +1 -1
  70. package/dist/providers/opencodeProvider.d.ts +4 -4
  71. package/dist/providers/opencodeProvider.js +7 -2
  72. package/dist/providers/spawnLoggedCommand.d.ts +3 -1
  73. package/dist/providers/spawnLoggedCommand.js +21 -0
  74. package/dist/providers/subprocessTemplateProvider.d.ts +4 -4
  75. package/dist/providers/subprocessTemplateProvider.js +8 -3
  76. package/dist/providers/vscodeTaskProvider.d.ts +3 -4
  77. package/dist/providers/vscodeTaskProvider.js +2 -2
  78. package/dist/quota/discoveredLimits.js +1 -1
  79. package/dist/quota/hostLimits.d.ts +1 -2
  80. package/dist/quota/hostLimits.js +4 -46
  81. package/dist/quota/index.d.ts +18 -15
  82. package/dist/quota/index.js +4 -9
  83. package/dist/quota/scheduler.d.ts +1 -3
  84. package/dist/quota/scheduler.js +1 -2
  85. package/dist/reporting/synthesis.d.ts +1 -2
  86. package/dist/reporting/synthesis.js +2 -0
  87. package/dist/reporting/workBlocks.d.ts +1 -2
  88. package/dist/supervisor/operatorHandoff.js +1 -1
  89. package/dist/supervisor/runLedger.d.ts +1 -1
  90. package/dist/supervisor/runLedger.js +2 -2
  91. package/dist/supervisor/sessionConfig.d.ts +1 -1
  92. package/dist/supervisor/sessionConfig.js +1 -3
  93. package/dist/types/reviewPlanning.d.ts +1 -1
  94. package/dist/types/workerSession.d.ts +6 -0
  95. package/dist/validation/artifacts.d.ts +1 -1
  96. package/dist/validation/artifacts.js +1 -1
  97. package/dist/validation/auditResults.d.ts +1 -1
  98. package/dist/validation/auditResults.js +1 -1
  99. package/dist/validation/sessionConfig.d.ts +2 -3
  100. package/dist/validation/sessionConfig.js +2 -3
  101. package/package.json +4 -2
  102. package/scripts/postinstall.mjs +0 -1
  103. package/dist/io/json.d.ts +0 -10
  104. package/dist/io/json.js +0 -142
  105. package/dist/providers/types.d.ts +0 -33
  106. package/dist/providers/types.js +0 -1
  107. package/dist/quota/compositeQuotaSource.d.ts +0 -7
  108. package/dist/quota/compositeQuotaSource.js +0 -20
  109. package/dist/quota/errorParsers/claudeCodeErrorParser.d.ts +0 -6
  110. package/dist/quota/errorParsers/claudeCodeErrorParser.js +0 -39
  111. package/dist/quota/errorParsers/genericErrorParser.d.ts +0 -9
  112. package/dist/quota/errorParsers/genericErrorParser.js +0 -7
  113. package/dist/quota/errorParsers/index.d.ts +0 -5
  114. package/dist/quota/errorParsers/index.js +0 -12
  115. package/dist/quota/errorParsing.d.ts +0 -7
  116. package/dist/quota/errorParsing.js +0 -69
  117. package/dist/quota/fileLock.d.ts +0 -6
  118. package/dist/quota/fileLock.js +0 -64
  119. package/dist/quota/learnedQuotaSource.d.ts +0 -7
  120. package/dist/quota/learnedQuotaSource.js +0 -25
  121. package/dist/quota/limits.d.ts +0 -16
  122. package/dist/quota/limits.js +0 -77
  123. package/dist/quota/quotaSource.d.ts +0 -12
  124. package/dist/quota/quotaSource.js +0 -1
  125. package/dist/quota/slidingWindow.d.ts +0 -4
  126. package/dist/quota/slidingWindow.js +0 -28
  127. package/dist/quota/state.d.ts +0 -15
  128. package/dist/quota/state.js +0 -148
  129. package/dist/quota/types.d.ts +0 -67
  130. package/dist/quota/types.js +0 -1
  131. package/dist/reporting/rootCause.d.ts +0 -10
  132. package/dist/reporting/rootCause.js +0 -146
  133. package/dist/types/disposition.d.ts +0 -9
  134. package/dist/types/disposition.js +0 -1
  135. package/dist/types/flows.d.ts +0 -17
  136. package/dist/types/flows.js +0 -1
  137. package/dist/types/graph.d.ts +0 -22
  138. package/dist/types/graph.js +0 -1
  139. package/dist/types/risk.d.ts +0 -9
  140. package/dist/types/risk.js +0 -1
  141. package/dist/types/runLedger.d.ts +0 -17
  142. package/dist/types/runLedger.js +0 -6
  143. package/dist/types/sessionConfig.d.ts +0 -79
  144. package/dist/types/sessionConfig.js +0 -15
  145. package/dist/types/surfaces.d.ts +0 -15
  146. package/dist/types/surfaces.js +0 -1
  147. package/dist/validation/basic.d.ts +0 -13
  148. package/dist/validation/basic.js +0 -46
@@ -1,6 +1,7 @@
1
1
  import { access, cp, mkdir, open, readFile, readdir, stat, unlink, writeFile } from 'node:fs/promises';
2
2
  import { constants } from 'node:fs';
3
3
  import { spawn } from 'node:child_process';
4
+ import { createRequire } from 'node:module';
4
5
  import { dirname, join, relative, resolve } from 'node:path';
5
6
  import { fileURLToPath } from 'node:url';
6
7
 
@@ -681,7 +682,6 @@ const OPENCODE_AUDIT_BASH_PERMISSION = {
681
682
  'git status*': 'allow',
682
683
  'git diff*': 'allow',
683
684
  'grep *': 'allow',
684
- 'Select-String *': 'allow',
685
685
  'rm *': 'deny',
686
686
  };
687
687
 
@@ -849,7 +849,6 @@ function assertOpenCodeAuditPermissionConfig(permissionConfig, label) {
849
849
  '*audit-code.mjs* worker-run*',
850
850
  '*node* *auditor-lambda*dist*index.js* worker-run*',
851
851
  'node* .audit-code/install/run-mcp-server.mjs*',
852
- 'Select-String *',
853
852
  ]) {
854
853
  if (bash[pattern] !== 'allow') {
855
854
  throw new Error(`OpenCode ${label}.bash must allow ${pattern}. Run "audit-code install --host opencode".`);
@@ -1217,6 +1216,21 @@ async function buildClaudeDesktopBundle(root, results) {
1217
1216
  await writeFile(join(bundleRoot, 'audit-code-wrapper-lib.mjs'), await readFile(join(repoRoot, 'audit-code-wrapper-lib.mjs')));
1218
1217
  await writeFile(join(bundleRoot, 'package.json'), await readFile(join(repoRoot, 'package.json')));
1219
1218
 
1219
+ try {
1220
+ const req = createRequire(join(repoRoot, 'package.json'));
1221
+ const sharedEntry = req.resolve('@audit-tools/shared');
1222
+ let sharedRoot = dirname(sharedEntry);
1223
+ while (sharedRoot !== dirname(sharedRoot) && !(await fileExists(join(sharedRoot, 'package.json')))) {
1224
+ sharedRoot = dirname(sharedRoot);
1225
+ }
1226
+ const bundleSharedRoot = join(bundleRoot, 'node_modules', '@audit-tools', 'shared');
1227
+ await mkdir(bundleSharedRoot, { recursive: true });
1228
+ await cp(join(sharedRoot, 'dist'), join(bundleSharedRoot, 'dist'), { recursive: true, force: true });
1229
+ await writeFile(join(bundleSharedRoot, 'package.json'), await readFile(join(sharedRoot, 'package.json')));
1230
+ } catch {
1231
+ // @audit-tools/shared not resolvable — bundle will use runtime resolution
1232
+ }
1233
+
1220
1234
  results.push({ path: bundleRoot, mode: bundleExisted ? 'updated' : 'created' });
1221
1235
 
1222
1236
  const serverEntry = [
@@ -1895,6 +1909,10 @@ function createInstallMcpClient(command, args, options = {}) {
1895
1909
  child.stdin.end();
1896
1910
  }
1897
1911
 
1912
+ if (child.exitCode !== null || child.signalCode !== null) {
1913
+ return;
1914
+ }
1915
+
1898
1916
  await new Promise((resolvePromise) => {
1899
1917
  child.on('exit', () => resolvePromise());
1900
1918
  });
@@ -0,0 +1,59 @@
1
+ import type { SessionConfig } from "@audit-tools/shared";
2
+ export type UiMode = "visible" | "headless";
3
+ export declare const DIRECT_CLI_DEFAULTS: {
4
+ rootDir: string;
5
+ artifactsDir: string;
6
+ maxRuns: number;
7
+ agentBatchSize: number;
8
+ parallelWorkers: number;
9
+ timeoutMs: number;
10
+ uiMode: UiMode;
11
+ };
12
+ export declare function getFlag(argv: string[], name: string, fallback?: string): string | undefined;
13
+ export declare function hasFlag(argv: string[], name: string): boolean;
14
+ export declare function getOptionalBooleanFlag(argv: string[], name: string): boolean | undefined;
15
+ export declare function optionalBooleanEnv(value: string | undefined): boolean | undefined;
16
+ export declare function resolveHostDispatchCapability(options: {
17
+ explicit?: boolean;
18
+ sessionConfig: SessionConfig;
19
+ env?: NodeJS.ProcessEnv;
20
+ }): boolean;
21
+ export declare function toBase64Url(value: string): string;
22
+ export declare function fromBase64Url(value: string): string;
23
+ export declare function digestId(value: string): string;
24
+ export declare function safeArtifactStem(value: string): string;
25
+ export declare function artifactNameForId(value: string, extension: string): string;
26
+ export declare function quoteCommandArg(value: string): string;
27
+ export declare function renderCommand(argv: string[]): string;
28
+ export declare function summarizeLaunchExit(result: {
29
+ accepted?: boolean;
30
+ exitCode?: number | null;
31
+ signal?: string | null;
32
+ command?: string;
33
+ stdoutPath?: string;
34
+ stderrPath?: string;
35
+ error?: string;
36
+ }): string | null;
37
+ export declare function taskResultPath(taskResultsDir: string, taskId: string): string;
38
+ export declare function packetPromptPath(taskResultsDir: string, packetId: string): string;
39
+ export declare function readStdinText(): Promise<string>;
40
+ export declare function normalizePositiveInteger(value: unknown): number | undefined;
41
+ export declare function parsePositiveIntegerFlag(argv: string[], name: string): number | undefined;
42
+ export declare function getArtifactsDir(argv: string[]): string;
43
+ export declare function getRootDir(argv: string[]): string;
44
+ export declare function warnIfNotGitRepo(root: string): void;
45
+ export declare function getBatchResultsDir(argv: string[]): string | undefined;
46
+ export declare function getMaxRuns(argv: string[]): number;
47
+ export declare function getAgentBatchSize(argv: string[], sessionConfig: SessionConfig): number;
48
+ export declare function getParallelWorkers(argv: string[], sessionConfig: SessionConfig): number;
49
+ export declare function getTimeoutMs(argv: string[], sessionConfig: SessionConfig): number;
50
+ export declare function getExplicitProvider(argv: string[]): string | undefined;
51
+ export declare function getHostModel(argv: string[]): string | null;
52
+ export declare function getHostMaxActiveSubagents(argv: string[]): number | null;
53
+ export declare function getQuotaProbeMode(argv: string[], sessionConfig: SessionConfig): "auto" | "never" | "force";
54
+ export declare function resolveRunProviderName(argv: string[], sessionConfig: SessionConfig): string;
55
+ export declare function chunkArray<T>(arr: T[], size: number): T[][];
56
+ export declare function getUiMode(argv: string[], fallback?: UiMode): UiMode;
57
+ export declare function looksLikeCliFlag(value: string | undefined): boolean;
58
+ export declare function countLines(path: string): Promise<number>;
59
+ export declare function listBatchResultFiles(batchDir: string): Promise<string[]>;
@@ -0,0 +1,244 @@
1
+ import { existsSync } from "node:fs";
2
+ import { createReadStream } from "node:fs";
3
+ import { readdir } from "node:fs/promises";
4
+ import { Buffer } from "node:buffer";
5
+ import { createHash } from "node:crypto";
6
+ import { join, resolve } from "node:path";
7
+ import { resolveFreshSessionProviderName } from "../providers/index.js";
8
+ export const DIRECT_CLI_DEFAULTS = {
9
+ rootDir: ".",
10
+ artifactsDir: ".artifacts",
11
+ maxRuns: 1000,
12
+ agentBatchSize: 6,
13
+ parallelWorkers: 1,
14
+ timeoutMs: 30 * 60 * 1000, // 30 minutes
15
+ uiMode: "headless",
16
+ };
17
+ function isLongFlagToken(value) {
18
+ return typeof value === "string" && value.startsWith("--");
19
+ }
20
+ export function getFlag(argv, name, fallback) {
21
+ const index = argv.indexOf(name);
22
+ if (index < 0)
23
+ return fallback;
24
+ const candidate = argv[index + 1];
25
+ if (!candidate || isLongFlagToken(candidate))
26
+ return fallback;
27
+ return candidate;
28
+ }
29
+ export function hasFlag(argv, name) {
30
+ return argv.includes(name);
31
+ }
32
+ export function getOptionalBooleanFlag(argv, name) {
33
+ const raw = getFlag(argv, name);
34
+ if (raw === undefined) {
35
+ return undefined;
36
+ }
37
+ if (raw === "true") {
38
+ return true;
39
+ }
40
+ if (raw === "false") {
41
+ return false;
42
+ }
43
+ throw new Error(`${name} must be either true or false.`);
44
+ }
45
+ export function optionalBooleanEnv(value) {
46
+ if (value === "true")
47
+ return true;
48
+ if (value === "false")
49
+ return false;
50
+ return undefined;
51
+ }
52
+ export function resolveHostDispatchCapability(options) {
53
+ if (options.explicit !== undefined) {
54
+ return options.explicit;
55
+ }
56
+ if (options.sessionConfig.host_can_dispatch_subagents !== undefined) {
57
+ return options.sessionConfig.host_can_dispatch_subagents;
58
+ }
59
+ return optionalBooleanEnv((options.env ?? process.env).AUDIT_CODE_HOST_CAN_DISPATCH) ?? true;
60
+ }
61
+ export function toBase64Url(value) {
62
+ return Buffer.from(value, "utf8").toString("base64url");
63
+ }
64
+ export function fromBase64Url(value) {
65
+ return Buffer.from(value, "base64url").toString("utf8");
66
+ }
67
+ export function digestId(value) {
68
+ return createHash("sha256").update(value).digest("hex").slice(0, 12);
69
+ }
70
+ export function safeArtifactStem(value) {
71
+ const sanitized = value
72
+ .replace(/[^a-zA-Z0-9_-]+/g, "_")
73
+ .replace(/^_+|_+$/g, "")
74
+ .slice(0, 80);
75
+ return sanitized.length > 0 ? sanitized : "artifact";
76
+ }
77
+ export function artifactNameForId(value, extension) {
78
+ return `${safeArtifactStem(value)}_${digestId(value)}.${extension}`;
79
+ }
80
+ export function quoteCommandArg(value) {
81
+ return /[\s"]/u.test(value) ? `"${value.replace(/"/g, '\\"')}"` : value;
82
+ }
83
+ export function renderCommand(argv) {
84
+ return argv.map((item) => quoteCommandArg(item)).join(" ");
85
+ }
86
+ export function summarizeLaunchExit(result) {
87
+ if (result.accepted !== false && !result.error) {
88
+ return null;
89
+ }
90
+ const parts = [
91
+ result.signal
92
+ ? `signal ${result.signal}`
93
+ : `exit code ${result.exitCode ?? "unknown"}`,
94
+ result.command ? `command: ${result.command}` : null,
95
+ result.stdoutPath ? `stdout: ${result.stdoutPath}` : null,
96
+ result.stderrPath ? `stderr: ${result.stderrPath}` : null,
97
+ result.error ?? null,
98
+ ].filter((part) => Boolean(part));
99
+ return parts.join("; ");
100
+ }
101
+ export function taskResultPath(taskResultsDir, taskId) {
102
+ return join(taskResultsDir, artifactNameForId(taskId, "json"));
103
+ }
104
+ export function packetPromptPath(taskResultsDir, packetId) {
105
+ return join(taskResultsDir, artifactNameForId(packetId, "prompt.md"));
106
+ }
107
+ export async function readStdinText() {
108
+ if (process.stdin.isTTY) {
109
+ return "";
110
+ }
111
+ return await new Promise((resolveInput, reject) => {
112
+ let input = "";
113
+ process.stdin.setEncoding("utf8");
114
+ process.stdin.on("data", (chunk) => {
115
+ input += chunk;
116
+ });
117
+ process.stdin.on("end", () => resolveInput(input));
118
+ process.stdin.on("error", reject);
119
+ });
120
+ }
121
+ function resolveFlagPath(argv, name, fallback) {
122
+ return resolve(getFlag(argv, name, fallback));
123
+ }
124
+ export function normalizePositiveInteger(value) {
125
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
126
+ return undefined;
127
+ }
128
+ return Math.floor(value);
129
+ }
130
+ export function parsePositiveIntegerFlag(argv, name) {
131
+ const raw = getFlag(argv, name);
132
+ if (raw === undefined) {
133
+ return undefined;
134
+ }
135
+ return normalizePositiveInteger(Number(raw));
136
+ }
137
+ export function getArtifactsDir(argv) {
138
+ return resolveFlagPath(argv, "--artifacts-dir", DIRECT_CLI_DEFAULTS.artifactsDir);
139
+ }
140
+ export function getRootDir(argv) {
141
+ return resolveFlagPath(argv, "--root", DIRECT_CLI_DEFAULTS.rootDir);
142
+ }
143
+ export function warnIfNotGitRepo(root) {
144
+ const gitEntry = join(root, ".git");
145
+ if (!existsSync(gitEntry)) {
146
+ console.warn(`Warning: target directory '${root}' does not appear to be a git repository. Diff-based signals will be unavailable.`);
147
+ }
148
+ }
149
+ export function getBatchResultsDir(argv) {
150
+ const value = getFlag(argv, "--batch-results");
151
+ return value ? resolve(value) : undefined;
152
+ }
153
+ export function getMaxRuns(argv) {
154
+ return parsePositiveIntegerFlag(argv, "--max-runs") ?? DIRECT_CLI_DEFAULTS.maxRuns;
155
+ }
156
+ export function getAgentBatchSize(argv, sessionConfig) {
157
+ return (parsePositiveIntegerFlag(argv, "--agent-batch-size") ??
158
+ normalizePositiveInteger(sessionConfig.agent_task_batch_size) ??
159
+ DIRECT_CLI_DEFAULTS.agentBatchSize);
160
+ }
161
+ export function getParallelWorkers(argv, sessionConfig) {
162
+ return (parsePositiveIntegerFlag(argv, "--parallel") ??
163
+ normalizePositiveInteger(sessionConfig.parallel_workers) ??
164
+ DIRECT_CLI_DEFAULTS.parallelWorkers);
165
+ }
166
+ export function getTimeoutMs(argv, sessionConfig) {
167
+ return (parsePositiveIntegerFlag(argv, "--timeout") ??
168
+ normalizePositiveInteger(sessionConfig.timeout_ms) ??
169
+ DIRECT_CLI_DEFAULTS.timeoutMs);
170
+ }
171
+ export function getExplicitProvider(argv) {
172
+ return getFlag(argv, "--provider");
173
+ }
174
+ export function getHostModel(argv) {
175
+ return getFlag(argv, "--host-model") ?? null;
176
+ }
177
+ export function getHostMaxActiveSubagents(argv) {
178
+ return parsePositiveIntegerFlag(argv, "--host-max-active-subagents") ?? null;
179
+ }
180
+ export function getQuotaProbeMode(argv, sessionConfig) {
181
+ const raw = getFlag(argv, "--quota-probe") ?? sessionConfig.quota?.probe ?? "auto";
182
+ if (raw === "auto" || raw === "never" || raw === "force")
183
+ return raw;
184
+ return "auto";
185
+ }
186
+ export function resolveRunProviderName(argv, sessionConfig) {
187
+ return resolveFreshSessionProviderName(getExplicitProvider(argv), sessionConfig);
188
+ }
189
+ export function chunkArray(arr, size) {
190
+ const chunkSize = normalizePositiveInteger(size);
191
+ if (chunkSize === undefined) {
192
+ throw new Error("chunkArray size must be a positive integer.");
193
+ }
194
+ const chunks = [];
195
+ for (let i = 0; i < arr.length; i += chunkSize) {
196
+ chunks.push(arr.slice(i, i + chunkSize));
197
+ }
198
+ return chunks;
199
+ }
200
+ export function getUiMode(argv, fallback = DIRECT_CLI_DEFAULTS.uiMode) {
201
+ const raw = getFlag(argv, "--ui");
202
+ if (raw === "visible")
203
+ return "visible";
204
+ if (raw === "headless")
205
+ return "headless";
206
+ return fallback;
207
+ }
208
+ export function looksLikeCliFlag(value) {
209
+ return isLongFlagToken(value);
210
+ }
211
+ export async function countLines(path) {
212
+ return new Promise((resolve, reject) => {
213
+ let lines = 0;
214
+ let byteCount = 0;
215
+ let lastByte = -1;
216
+ const stream = createReadStream(path);
217
+ stream.on("data", (chunk) => {
218
+ const buffer = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
219
+ byteCount += buffer.length;
220
+ for (let i = 0; i < buffer.length; ++i) {
221
+ if (buffer[i] === 10)
222
+ lines++;
223
+ lastByte = buffer[i];
224
+ }
225
+ });
226
+ stream.on("end", () => {
227
+ if (byteCount === 0)
228
+ return resolve(0);
229
+ resolve(lastByte !== 10 ? lines + 1 : lines);
230
+ });
231
+ stream.on("error", reject);
232
+ });
233
+ }
234
+ export async function listBatchResultFiles(batchDir) {
235
+ const entries = await readdir(batchDir, { withFileTypes: true });
236
+ const files = entries
237
+ .filter((entry) => entry.isFile() && entry.name.toLowerCase().endsWith(".json"))
238
+ .map((entry) => join(batchDir, entry.name))
239
+ .sort((a, b) => a.localeCompare(b));
240
+ if (files.length === 0) {
241
+ throw new Error(`No JSON audit result files found in ${batchDir}.`);
242
+ }
243
+ return files;
244
+ }
@@ -0,0 +1,80 @@
1
+ import type { SessionConfig, DispatchModelHint } from "@audit-tools/shared";
2
+ import type { ArtifactBundle } from "../io/artifacts.js";
3
+ import type { AuditTask } from "../types.js";
4
+ export declare const LARGE_FILE_PACKET_TARGET_LINES = 2500;
5
+ export declare const SMALL_MODEL_HINT_MAX_LINES = 500;
6
+ export declare const SMALL_MODEL_HINT_MAX_ESTIMATED_TOKENS = 3000;
7
+ export declare const DEEP_MODEL_HINT_MIN_ESTIMATED_TOKENS = 9000;
8
+ export interface DispatchComplexity {
9
+ priority: NonNullable<AuditTask["priority"]>;
10
+ task_count: number;
11
+ file_count: number;
12
+ total_lines: number;
13
+ estimated_tokens: number;
14
+ lenses: AuditTask["lens"][];
15
+ tags: string[];
16
+ large_file_mode: boolean;
17
+ }
18
+ export declare const DISPATCH_RESULT_MAP_FILENAME = "dispatch-result-map.json";
19
+ export declare const ACTIVE_DISPATCH_FILENAME = "active-dispatch.json";
20
+ export interface ActiveDispatchState {
21
+ run_id: string;
22
+ created_at: string;
23
+ packet_count: number;
24
+ task_count: number;
25
+ status: "active" | "merged";
26
+ }
27
+ export interface DispatchResultMapEntry {
28
+ packet_id: string;
29
+ task_id: string;
30
+ result_path: string;
31
+ }
32
+ export interface DispatchResultMap {
33
+ contract_version: "audit-code-dispatch-results/v1alpha1";
34
+ run_id: string;
35
+ entries: DispatchResultMapEntry[];
36
+ }
37
+ export interface PrepareDispatchResult {
38
+ run_id: string;
39
+ dispatch_plan_path: string;
40
+ dispatch_quota_path: string | null;
41
+ packet_count: number;
42
+ task_count: number;
43
+ skipped_task_count: number;
44
+ largest_packet: {
45
+ packet_id: string;
46
+ total_lines: number;
47
+ estimated_tokens: number;
48
+ } | null;
49
+ warning_count: number;
50
+ dispatch_warnings_path: string | null;
51
+ }
52
+ export declare function dispatchResultMapPath(runDir: string): string;
53
+ export declare function resolveRunScopedArg(argv: string[], rawFlag: string, b64Flag: string): string | undefined;
54
+ export declare function loadDispatchResultMap(runDir: string): Promise<DispatchResultMap | null>;
55
+ export declare function entriesByTaskId(entries: DispatchResultMapEntry[]): Map<string, DispatchResultMapEntry>;
56
+ export declare function isIsolatedLargeFilePacket(packet: {
57
+ file_paths: string[];
58
+ total_lines: number;
59
+ }): boolean;
60
+ export declare function buildDispatchComplexity(packet: {
61
+ task_ids: string[];
62
+ file_paths: string[];
63
+ total_lines: number;
64
+ estimated_tokens: number;
65
+ priority: NonNullable<AuditTask["priority"]>;
66
+ lenses: AuditTask["lens"][];
67
+ tags?: string[];
68
+ }, largeFileMode: boolean): DispatchComplexity;
69
+ export declare function buildDispatchModelHint(complexity: DispatchComplexity): DispatchModelHint;
70
+ export declare function withinRoot(root: string, path: string): string;
71
+ export declare function buildPendingAuditTasks(bundle: ArtifactBundle): AuditTask[];
72
+ export declare function prepareDispatchArtifacts(params: {
73
+ packageRoot: string;
74
+ runId: string;
75
+ artifactsDir: string;
76
+ root?: string;
77
+ sessionConfig?: SessionConfig;
78
+ hostModel?: string | null;
79
+ hostActiveSubagentLimit?: number | null;
80
+ }): Promise<PrepareDispatchResult>;