auditor-lambda 0.3.40 → 0.5.0
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.
- package/audit-code-wrapper-lib.mjs +20 -2
- package/dist/cli/args.d.ts +59 -0
- package/dist/cli/args.js +244 -0
- package/dist/cli/dispatch.d.ts +80 -0
- package/dist/cli/dispatch.js +532 -0
- package/dist/cli/prompts.d.ts +37 -0
- package/dist/cli/prompts.js +225 -0
- package/dist/cli/steps.d.ts +29 -0
- package/dist/cli/steps.js +30 -0
- package/dist/cli/waveManifest.d.ts +40 -0
- package/dist/cli/waveManifest.js +41 -0
- package/dist/cli/workerResult.d.ts +18 -0
- package/dist/cli/workerResult.js +42 -0
- package/dist/cli.d.ts +2 -22
- package/dist/cli.js +442 -975
- package/dist/extractors/analyzers/css.d.ts +2 -0
- package/dist/extractors/analyzers/css.js +101 -0
- package/dist/extractors/analyzers/html.d.ts +2 -0
- package/dist/extractors/analyzers/html.js +92 -0
- package/dist/extractors/analyzers/merge.d.ts +14 -0
- package/dist/extractors/analyzers/merge.js +85 -0
- package/dist/extractors/analyzers/python.d.ts +2 -0
- package/dist/extractors/analyzers/python.js +104 -0
- package/dist/extractors/analyzers/registry.d.ts +33 -0
- package/dist/extractors/analyzers/registry.js +100 -0
- package/dist/extractors/analyzers/resourceUrl.d.ts +7 -0
- package/dist/extractors/analyzers/resourceUrl.js +25 -0
- package/dist/extractors/analyzers/sql.d.ts +2 -0
- package/dist/extractors/analyzers/sql.js +19 -0
- package/dist/extractors/analyzers/treeSitter.d.ts +34 -0
- package/dist/extractors/analyzers/treeSitter.js +111 -0
- package/dist/extractors/analyzers/types.d.ts +53 -0
- package/dist/extractors/analyzers/typescript.d.ts +2 -0
- package/dist/extractors/analyzers/typescript.js +257 -0
- package/dist/extractors/browserExtension.d.ts +1 -3
- package/dist/extractors/browserExtension.js +2 -2
- package/dist/extractors/designAssessment.d.ts +1 -3
- package/dist/extractors/disposition.d.ts +2 -1
- package/dist/extractors/disposition.js +11 -1
- package/dist/extractors/flows.d.ts +1 -3
- package/dist/extractors/flows.js +2 -2
- package/dist/extractors/graph.d.ts +2 -2
- package/dist/extractors/graph.js +171 -327
- package/dist/extractors/graphManifestEdges.d.ts +1 -1
- package/dist/extractors/graphPathUtils.d.ts +1 -1
- package/dist/extractors/graphPythonImports.d.ts +18 -0
- package/dist/extractors/graphPythonImports.js +362 -0
- package/dist/extractors/pathPatterns.d.ts +6 -0
- package/dist/extractors/pathPatterns.js +8 -0
- package/dist/extractors/risk.d.ts +1 -2
- package/dist/extractors/surfaces.d.ts +1 -3
- package/dist/extractors/surfaces.js +2 -2
- package/dist/io/artifacts.d.ts +12 -5
- package/dist/io/artifacts.js +13 -1
- package/dist/io/runArtifacts.js +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/orchestrator/advance.d.ts +21 -0
- package/dist/orchestrator/advance.js +69 -7
- package/dist/orchestrator/auditTaskUtils.d.ts +4 -0
- package/dist/orchestrator/auditTaskUtils.js +27 -0
- package/dist/orchestrator/dependencyMap.js +27 -0
- package/dist/orchestrator/edgeReasoning.d.ts +39 -0
- package/dist/orchestrator/edgeReasoning.js +125 -0
- package/dist/orchestrator/executors.js +11 -1
- package/dist/orchestrator/fileAnchors.d.ts +1 -1
- package/dist/orchestrator/fileIntegrity.d.ts +7 -0
- package/dist/orchestrator/fileIntegrity.js +41 -0
- package/dist/orchestrator/flowCoverage.d.ts +1 -1
- package/dist/orchestrator/flowPlanning.d.ts +1 -1
- package/dist/orchestrator/flowRequeue.d.ts +1 -1
- package/dist/orchestrator/graphEnrichmentExecutor.d.ts +29 -0
- package/dist/orchestrator/graphEnrichmentExecutor.js +196 -0
- package/dist/orchestrator/internalExecutors.d.ts +13 -2
- package/dist/orchestrator/internalExecutors.js +112 -16
- package/dist/orchestrator/localCommands.js +6 -25
- package/dist/orchestrator/nextStep.d.ts +2 -1
- package/dist/orchestrator/nextStep.js +3 -1
- package/dist/orchestrator/planning.d.ts +1 -1
- package/dist/orchestrator/requeueCommand.d.ts +1 -1
- package/dist/orchestrator/reviewPackets.d.ts +37 -4
- package/dist/orchestrator/reviewPackets.js +113 -158
- package/dist/orchestrator/runtimeValidation.d.ts +1 -1
- package/dist/orchestrator/runtimeValidation.js +4 -31
- package/dist/orchestrator/scope.d.ts +62 -0
- package/dist/orchestrator/scope.js +227 -0
- package/dist/orchestrator/state.js +2 -0
- package/dist/orchestrator/taskBuilder.d.ts +1 -1
- package/dist/orchestrator/taskBuilder.js +1 -12
- package/dist/orchestrator/unionFind.d.ts +7 -0
- package/dist/orchestrator/unionFind.js +32 -0
- package/dist/orchestrator/unitBuilder.d.ts +2 -2
- package/dist/orchestrator/unitBuilder.js +4 -18
- package/dist/prompts/renderWorkerPrompt.js +18 -1
- package/dist/providers/claudeCodeProvider.d.ts +4 -4
- package/dist/providers/claudeCodeProvider.js +9 -3
- package/dist/providers/constants.d.ts +1 -1
- package/dist/providers/constants.js +1 -1
- package/dist/providers/index.d.ts +1 -2
- package/dist/providers/index.js +5 -4
- package/dist/providers/localSubprocessProvider.d.ts +2 -2
- package/dist/providers/localSubprocessProvider.js +1 -1
- package/dist/providers/opencodeProvider.d.ts +4 -4
- package/dist/providers/opencodeProvider.js +7 -2
- package/dist/providers/spawnLoggedCommand.d.ts +3 -1
- package/dist/providers/spawnLoggedCommand.js +21 -0
- package/dist/providers/subprocessTemplateProvider.d.ts +4 -4
- package/dist/providers/subprocessTemplateProvider.js +8 -3
- package/dist/providers/vscodeTaskProvider.d.ts +3 -4
- package/dist/providers/vscodeTaskProvider.js +2 -2
- package/dist/quota/discoveredLimits.js +1 -1
- package/dist/quota/hostLimits.d.ts +1 -2
- package/dist/quota/hostLimits.js +4 -46
- package/dist/quota/index.d.ts +18 -15
- package/dist/quota/index.js +4 -9
- package/dist/quota/scheduler.d.ts +1 -3
- package/dist/quota/scheduler.js +1 -2
- package/dist/reporting/synthesis.d.ts +37 -3
- package/dist/reporting/synthesis.js +97 -16
- package/dist/reporting/synthesisNarrativePrompt.d.ts +7 -0
- package/dist/reporting/synthesisNarrativePrompt.js +60 -0
- package/dist/reporting/workBlocks.d.ts +2 -11
- package/dist/supervisor/operatorHandoff.js +1 -1
- package/dist/supervisor/runLedger.d.ts +1 -1
- package/dist/supervisor/runLedger.js +2 -2
- package/dist/supervisor/sessionConfig.d.ts +8 -1
- package/dist/supervisor/sessionConfig.js +22 -3
- package/dist/types/analyzerCapability.d.ts +16 -0
- package/dist/types/auditScope.d.ts +43 -0
- package/dist/types/auditScope.js +14 -0
- package/dist/types/reviewPlanning.d.ts +1 -1
- package/dist/types/synthesisNarrative.d.ts +7 -0
- package/dist/types/synthesisNarrative.js +5 -0
- package/dist/types/workerSession.d.ts +6 -0
- package/dist/types.d.ts +2 -19
- package/dist/validation/artifacts.d.ts +1 -1
- package/dist/validation/artifacts.js +10 -1
- package/dist/validation/auditResults.d.ts +1 -1
- package/dist/validation/auditResults.js +1 -1
- package/dist/validation/sessionConfig.d.ts +2 -3
- package/dist/validation/sessionConfig.js +25 -3
- package/package.json +7 -3
- package/schemas/analyzer_capability.schema.json +47 -0
- package/schemas/audit_findings.schema.json +141 -0
- package/schemas/finding.schema.json +2 -1
- package/schemas/graph_bundle.schema.json +5 -0
- package/schemas/scope.schema.json +46 -0
- package/scripts/postinstall.mjs +0 -1
- package/dist/io/json.d.ts +0 -10
- package/dist/io/json.js +0 -142
- package/dist/providers/types.d.ts +0 -33
- package/dist/quota/compositeQuotaSource.d.ts +0 -7
- package/dist/quota/compositeQuotaSource.js +0 -20
- package/dist/quota/errorParsers/claudeCodeErrorParser.d.ts +0 -6
- package/dist/quota/errorParsers/claudeCodeErrorParser.js +0 -39
- package/dist/quota/errorParsers/genericErrorParser.d.ts +0 -9
- package/dist/quota/errorParsers/genericErrorParser.js +0 -7
- package/dist/quota/errorParsers/index.d.ts +0 -5
- package/dist/quota/errorParsers/index.js +0 -12
- package/dist/quota/errorParsing.d.ts +0 -7
- package/dist/quota/errorParsing.js +0 -69
- package/dist/quota/fileLock.d.ts +0 -6
- package/dist/quota/fileLock.js +0 -64
- package/dist/quota/learnedQuotaSource.d.ts +0 -7
- package/dist/quota/learnedQuotaSource.js +0 -25
- package/dist/quota/limits.d.ts +0 -16
- package/dist/quota/limits.js +0 -77
- package/dist/quota/quotaSource.d.ts +0 -12
- package/dist/quota/slidingWindow.d.ts +0 -4
- package/dist/quota/slidingWindow.js +0 -28
- package/dist/quota/state.d.ts +0 -15
- package/dist/quota/state.js +0 -148
- package/dist/quota/types.d.ts +0 -67
- package/dist/quota/types.js +0 -1
- package/dist/reporting/rootCause.d.ts +0 -10
- package/dist/reporting/rootCause.js +0 -146
- package/dist/types/disposition.d.ts +0 -9
- package/dist/types/disposition.js +0 -1
- package/dist/types/flows.d.ts +0 -17
- package/dist/types/flows.js +0 -1
- package/dist/types/graph.d.ts +0 -22
- package/dist/types/graph.js +0 -1
- package/dist/types/risk.d.ts +0 -9
- package/dist/types/risk.js +0 -1
- package/dist/types/runLedger.d.ts +0 -17
- package/dist/types/runLedger.js +0 -6
- package/dist/types/sessionConfig.d.ts +0 -79
- package/dist/types/sessionConfig.js +0 -15
- package/dist/types/surfaces.d.ts +0 -15
- package/dist/types/surfaces.js +0 -1
- package/dist/validation/basic.d.ts +0 -13
- package/dist/validation/basic.js +0 -46
- /package/dist/{providers → extractors/analyzers}/types.js +0 -0
- /package/dist/{quota/quotaSource.js → types/analyzerCapability.js} +0 -0
package/dist/io/json.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile, appendFile } from "node:fs/promises";
|
|
2
|
-
import { dirname } from "node:path";
|
|
3
|
-
function errorMessage(error) {
|
|
4
|
-
return error instanceof Error ? error.message : String(error);
|
|
5
|
-
}
|
|
6
|
-
function ioError(action, path, error) {
|
|
7
|
-
return new Error(`Failed to ${action} ${path}: ${errorMessage(error)}`);
|
|
8
|
-
}
|
|
9
|
-
async function ensureParentDirectory(path) {
|
|
10
|
-
try {
|
|
11
|
-
await mkdir(dirname(path), { recursive: true });
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
throw ioError("prepare parent directory", path, error);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export function isFileMissingError(error) {
|
|
18
|
-
return (typeof error === "object" &&
|
|
19
|
-
error !== null &&
|
|
20
|
-
"code" in error &&
|
|
21
|
-
error.code === "ENOENT");
|
|
22
|
-
}
|
|
23
|
-
export async function readJsonFile(path) {
|
|
24
|
-
let content;
|
|
25
|
-
try {
|
|
26
|
-
content = await readFile(path, "utf8");
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
if (isFileMissingError(error)) {
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
throw ioError("read", path, error);
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
return JSON.parse(content);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
throw new Error(`Invalid JSON in ${path}: ${errorMessage(error)}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export async function writeJsonFile(path, value) {
|
|
42
|
-
await ensureParentDirectory(path);
|
|
43
|
-
try {
|
|
44
|
-
await writeFile(path, JSON.stringify(value, null, 2) + "\n", "utf8");
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
throw ioError("write", path, error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export async function appendNdjsonFile(path, value) {
|
|
51
|
-
await ensureParentDirectory(path);
|
|
52
|
-
try {
|
|
53
|
-
await appendFile(path, JSON.stringify(value) + "\n", "utf8");
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
throw ioError("append", path, error);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export async function readNdjsonFile(path) {
|
|
60
|
-
try {
|
|
61
|
-
const content = await readFile(path, "utf8");
|
|
62
|
-
const values = [];
|
|
63
|
-
let sawContent = false;
|
|
64
|
-
for (const [index, line] of content.split(/\r?\n/).entries()) {
|
|
65
|
-
if (line.trim().length === 0) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
sawContent = true;
|
|
69
|
-
try {
|
|
70
|
-
values.push(JSON.parse(line));
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
throw new Error(`Invalid NDJSON in ${path} at line ${index + 1}: ${errorMessage(error)}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return sawContent ? values : [];
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
if (isFileMissingError(error)) {
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
if (error instanceof Error && error.message.includes(path)) {
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
throw ioError("read", path, error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export async function readOptionalJsonFile(path) {
|
|
89
|
-
try {
|
|
90
|
-
return await readJsonFile(path);
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
if (isFileMissingError(error)) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export async function readOptionalNdjsonFile(path) {
|
|
100
|
-
try {
|
|
101
|
-
return await readNdjsonFile(path);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
if (isFileMissingError(error)) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
export async function writeNdjsonFile(path, values) {
|
|
111
|
-
await ensureParentDirectory(path);
|
|
112
|
-
try {
|
|
113
|
-
if (values.length === 0) {
|
|
114
|
-
await writeFile(path, "", "utf8");
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
await writeFile(path, values.map((v) => JSON.stringify(v)).join("\n") + "\n", "utf8");
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
throw ioError("write", path, error);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
export async function readOptionalTextFile(path) {
|
|
124
|
-
try {
|
|
125
|
-
return await readFile(path, "utf8");
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
if (isFileMissingError(error)) {
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
throw ioError("read", path, error);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
export async function writeTextFile(path, value) {
|
|
135
|
-
await ensureParentDirectory(path);
|
|
136
|
-
try {
|
|
137
|
-
await writeFile(path, value, "utf8");
|
|
138
|
-
}
|
|
139
|
-
catch (error) {
|
|
140
|
-
throw ioError("write", path, error);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export interface LaunchFreshSessionInput {
|
|
2
|
-
repoRoot: string;
|
|
3
|
-
runId: string;
|
|
4
|
-
obligationId: string | null;
|
|
5
|
-
promptPath: string;
|
|
6
|
-
taskPath: string;
|
|
7
|
-
resultPath: string;
|
|
8
|
-
stdoutPath: string;
|
|
9
|
-
stderrPath: string;
|
|
10
|
-
uiMode: "visible" | "headless";
|
|
11
|
-
timeoutMs: number;
|
|
12
|
-
}
|
|
13
|
-
export interface LaunchFreshSessionResult {
|
|
14
|
-
accepted: boolean;
|
|
15
|
-
processId?: number;
|
|
16
|
-
exitCode?: number | null;
|
|
17
|
-
signal?: string | null;
|
|
18
|
-
command?: string;
|
|
19
|
-
args?: string[];
|
|
20
|
-
stdoutPath?: string;
|
|
21
|
-
stderrPath?: string;
|
|
22
|
-
error?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface ProviderRateLimits {
|
|
25
|
-
requests_per_minute?: number | null;
|
|
26
|
-
input_tokens_per_minute?: number | null;
|
|
27
|
-
output_tokens_per_minute?: number | null;
|
|
28
|
-
}
|
|
29
|
-
export interface FreshSessionProvider {
|
|
30
|
-
name: string;
|
|
31
|
-
launch(input: LaunchFreshSessionInput): Promise<LaunchFreshSessionResult>;
|
|
32
|
-
queryLimits?(model: string | null): Promise<ProviderRateLimits | null>;
|
|
33
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { QuotaSource, QuotaUsageSnapshot } from "./quotaSource.js";
|
|
2
|
-
export declare class CompositeQuotaSource implements QuotaSource {
|
|
3
|
-
readonly name = "composite";
|
|
4
|
-
private sources;
|
|
5
|
-
constructor(sources: QuotaSource[]);
|
|
6
|
-
queryCurrentUsage(providerModelKey: string): Promise<QuotaUsageSnapshot | null>;
|
|
7
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export class CompositeQuotaSource {
|
|
2
|
-
name = "composite";
|
|
3
|
-
sources;
|
|
4
|
-
constructor(sources) {
|
|
5
|
-
this.sources = sources;
|
|
6
|
-
}
|
|
7
|
-
async queryCurrentUsage(providerModelKey) {
|
|
8
|
-
for (const source of this.sources) {
|
|
9
|
-
try {
|
|
10
|
-
const snapshot = await source.queryCurrentUsage(providerModelKey);
|
|
11
|
-
if (snapshot)
|
|
12
|
-
return snapshot;
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
// Skip failing sources, try next
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { RateLimitDetectionResult } from "../errorParsing.js";
|
|
2
|
-
import type { ErrorParser } from "./genericErrorParser.js";
|
|
3
|
-
export declare class ClaudeCodeErrorParser implements ErrorParser {
|
|
4
|
-
readonly name = "claude-code";
|
|
5
|
-
parse(text: string): RateLimitDetectionResult;
|
|
6
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export class ClaudeCodeErrorParser {
|
|
2
|
-
name = "claude-code";
|
|
3
|
-
parse(text) {
|
|
4
|
-
for (const line of text.split("\n")) {
|
|
5
|
-
const trimmed = line.trim();
|
|
6
|
-
if (!trimmed.startsWith("{"))
|
|
7
|
-
continue;
|
|
8
|
-
try {
|
|
9
|
-
const obj = JSON.parse(trimmed);
|
|
10
|
-
const level = obj["level"];
|
|
11
|
-
const type = obj["type"];
|
|
12
|
-
const message = obj["message"] ?? "";
|
|
13
|
-
const statusCode = obj["status_code"];
|
|
14
|
-
if (statusCode === 429 ||
|
|
15
|
-
type === "rate_limit_error" ||
|
|
16
|
-
(level === "error" && /\brate.?limit/i.test(message))) {
|
|
17
|
-
const retryAfter = obj["retry_after"];
|
|
18
|
-
const retryAfterMs = obj["retry_after_ms"];
|
|
19
|
-
let extractedMs = null;
|
|
20
|
-
if (retryAfterMs != null && retryAfterMs > 0) {
|
|
21
|
-
extractedMs = retryAfterMs;
|
|
22
|
-
}
|
|
23
|
-
else if (retryAfter != null && retryAfter > 0) {
|
|
24
|
-
extractedMs = retryAfter < 600 ? retryAfter * 1000 : retryAfter;
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
isRateLimited: true,
|
|
28
|
-
retryAfterMs: extractedMs,
|
|
29
|
-
rawMatch: `claude-code-stderr:${statusCode ?? type ?? "rate_limit"}`,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
// Not valid JSON, skip
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return { isRateLimited: false, retryAfterMs: null, rawMatch: null };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { RateLimitDetectionResult } from "../errorParsing.js";
|
|
2
|
-
export interface ErrorParser {
|
|
3
|
-
readonly name: string;
|
|
4
|
-
parse(text: string): RateLimitDetectionResult;
|
|
5
|
-
}
|
|
6
|
-
export declare class GenericErrorParser implements ErrorParser {
|
|
7
|
-
readonly name = "generic";
|
|
8
|
-
parse(text: string): RateLimitDetectionResult;
|
|
9
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type { ErrorParser } from "./genericErrorParser.js";
|
|
2
|
-
export { GenericErrorParser } from "./genericErrorParser.js";
|
|
3
|
-
export { ClaudeCodeErrorParser } from "./claudeCodeErrorParser.js";
|
|
4
|
-
import type { ErrorParser } from "./genericErrorParser.js";
|
|
5
|
-
export declare function getErrorParserForProvider(providerName: string): ErrorParser;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { GenericErrorParser } from "./genericErrorParser.js";
|
|
2
|
-
export { ClaudeCodeErrorParser } from "./claudeCodeErrorParser.js";
|
|
3
|
-
import { GenericErrorParser } from "./genericErrorParser.js";
|
|
4
|
-
import { ClaudeCodeErrorParser } from "./claudeCodeErrorParser.js";
|
|
5
|
-
const PROVIDER_PARSERS = {
|
|
6
|
-
"claude-code": () => new ClaudeCodeErrorParser(),
|
|
7
|
-
};
|
|
8
|
-
const genericParser = new GenericErrorParser();
|
|
9
|
-
export function getErrorParserForProvider(providerName) {
|
|
10
|
-
const factory = PROVIDER_PARSERS[providerName];
|
|
11
|
-
return factory ? factory() : genericParser;
|
|
12
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface RateLimitDetectionResult {
|
|
2
|
-
isRateLimited: boolean;
|
|
3
|
-
retryAfterMs: number | null;
|
|
4
|
-
rawMatch: string | null;
|
|
5
|
-
}
|
|
6
|
-
export declare function detectRateLimitError(text: string): RateLimitDetectionResult;
|
|
7
|
-
export declare function computeCooldownUntil(retryAfterMs: number | null, defaultMs?: number): string;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const RATE_LIMIT_PATTERNS = [
|
|
2
|
-
/\b429\b/i,
|
|
3
|
-
/\btoo many requests\b/i,
|
|
4
|
-
/\brate.?limit/i,
|
|
5
|
-
/\boverloaded\b/i,
|
|
6
|
-
/\bresource.?exhausted\b/i,
|
|
7
|
-
/\bquota.?exceeded\b/i,
|
|
8
|
-
];
|
|
9
|
-
function tryParseJson(text) {
|
|
10
|
-
const jsonStart = text.indexOf("{");
|
|
11
|
-
if (jsonStart === -1)
|
|
12
|
-
return null;
|
|
13
|
-
try {
|
|
14
|
-
return JSON.parse(text.slice(jsonStart));
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function extractRetryAfterMs(obj) {
|
|
21
|
-
const headers = obj["headers"];
|
|
22
|
-
const retryAfter = headers?.["retry-after"] ??
|
|
23
|
-
headers?.["Retry-After"] ??
|
|
24
|
-
obj["retry_after"] ??
|
|
25
|
-
obj["retry_after_ms"];
|
|
26
|
-
if (retryAfter == null)
|
|
27
|
-
return null;
|
|
28
|
-
const val = typeof retryAfter === "string" ? Number(retryAfter) : retryAfter;
|
|
29
|
-
if (!Number.isFinite(val) || val <= 0)
|
|
30
|
-
return null;
|
|
31
|
-
// If the value looks like seconds (< 600), convert to ms
|
|
32
|
-
return val < 600 ? val * 1000 : val;
|
|
33
|
-
}
|
|
34
|
-
function detectFromJson(text) {
|
|
35
|
-
const obj = tryParseJson(text);
|
|
36
|
-
if (!obj)
|
|
37
|
-
return null;
|
|
38
|
-
const status = obj["status"];
|
|
39
|
-
const type = obj["type"];
|
|
40
|
-
const errorObj = obj["error"];
|
|
41
|
-
const errorType = errorObj?.["type"];
|
|
42
|
-
const isRateLimited = status === 429 ||
|
|
43
|
-
type === "rate_limit_error" ||
|
|
44
|
-
errorType === "rate_limit_error";
|
|
45
|
-
if (!isRateLimited)
|
|
46
|
-
return null;
|
|
47
|
-
return {
|
|
48
|
-
isRateLimited: true,
|
|
49
|
-
retryAfterMs: extractRetryAfterMs(obj),
|
|
50
|
-
rawMatch: `json:${status === 429 ? "status=429" : `type=${type ?? errorType}`}`,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export function detectRateLimitError(text) {
|
|
54
|
-
const jsonResult = detectFromJson(text);
|
|
55
|
-
if (jsonResult)
|
|
56
|
-
return jsonResult;
|
|
57
|
-
for (const pattern of RATE_LIMIT_PATTERNS) {
|
|
58
|
-
const match = pattern.exec(text);
|
|
59
|
-
if (match) {
|
|
60
|
-
return { isRateLimited: true, retryAfterMs: null, rawMatch: match[0] };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return { isRateLimited: false, retryAfterMs: null, rawMatch: null };
|
|
64
|
-
}
|
|
65
|
-
const DEFAULT_COOLDOWN_MS = 60_000;
|
|
66
|
-
export function computeCooldownUntil(retryAfterMs, defaultMs = DEFAULT_COOLDOWN_MS) {
|
|
67
|
-
const ms = retryAfterMs != null && retryAfterMs > 0 ? retryAfterMs : defaultMs;
|
|
68
|
-
return new Date(Date.now() + ms).toISOString();
|
|
69
|
-
}
|
package/dist/quota/fileLock.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare class FileLockTimeoutError extends Error {
|
|
2
|
-
constructor(lockPath: string);
|
|
3
|
-
}
|
|
4
|
-
export declare function acquireLock(lockPath: string, timeoutMs?: number): Promise<void>;
|
|
5
|
-
export declare function releaseLock(lockPath: string): Promise<void>;
|
|
6
|
-
export declare function withFileLock<T>(lockPath: string, fn: () => Promise<T>, timeoutMs?: number): Promise<T>;
|
package/dist/quota/fileLock.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { open, unlink, stat } from "node:fs/promises";
|
|
2
|
-
const STALE_LOCK_MS = 30_000;
|
|
3
|
-
const RETRY_INTERVAL_MS = 50;
|
|
4
|
-
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
5
|
-
export class FileLockTimeoutError extends Error {
|
|
6
|
-
constructor(lockPath) {
|
|
7
|
-
super(`Timed out acquiring lock: ${lockPath}`);
|
|
8
|
-
this.name = "FileLockTimeoutError";
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
async function isLockStale(lockPath) {
|
|
12
|
-
try {
|
|
13
|
-
const info = await stat(lockPath);
|
|
14
|
-
return Date.now() - info.mtimeMs > STALE_LOCK_MS;
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export async function acquireLock(lockPath, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
21
|
-
const deadline = Date.now() + timeoutMs;
|
|
22
|
-
while (true) {
|
|
23
|
-
try {
|
|
24
|
-
const fd = await open(lockPath, "wx");
|
|
25
|
-
await fd.close();
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
if (err.code !== "EEXIST")
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
if (await isLockStale(lockPath)) {
|
|
33
|
-
try {
|
|
34
|
-
await unlink(lockPath);
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
// Another process may have already cleaned it up
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (Date.now() >= deadline) {
|
|
42
|
-
throw new FileLockTimeoutError(lockPath);
|
|
43
|
-
}
|
|
44
|
-
await new Promise((r) => setTimeout(r, RETRY_INTERVAL_MS));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export async function releaseLock(lockPath) {
|
|
48
|
-
try {
|
|
49
|
-
await unlink(lockPath);
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
if (err.code !== "ENOENT")
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export async function withFileLock(lockPath, fn, timeoutMs) {
|
|
57
|
-
await acquireLock(lockPath, timeoutMs);
|
|
58
|
-
try {
|
|
59
|
-
return await fn();
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
await releaseLock(lockPath);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { QuotaSource, QuotaUsageSnapshot } from "./quotaSource.js";
|
|
2
|
-
export declare class LearnedQuotaSource implements QuotaSource {
|
|
3
|
-
readonly name = "learned";
|
|
4
|
-
private halfLifeHours;
|
|
5
|
-
constructor(halfLifeHours?: number);
|
|
6
|
-
queryCurrentUsage(providerModelKey: string): Promise<QuotaUsageSnapshot | null>;
|
|
7
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { readQuotaState, computeMaxSafeConcurrency } from "./state.js";
|
|
2
|
-
export class LearnedQuotaSource {
|
|
3
|
-
name = "learned";
|
|
4
|
-
halfLifeHours;
|
|
5
|
-
constructor(halfLifeHours = 24) {
|
|
6
|
-
this.halfLifeHours = halfLifeHours;
|
|
7
|
-
}
|
|
8
|
-
async queryCurrentUsage(providerModelKey) {
|
|
9
|
-
const state = await readQuotaState();
|
|
10
|
-
const entry = state.entries[providerModelKey];
|
|
11
|
-
if (!entry)
|
|
12
|
-
return null;
|
|
13
|
-
const maxSafe = computeMaxSafeConcurrency(entry, this.halfLifeHours);
|
|
14
|
-
const isInCooldown = entry.cooldown_until != null &&
|
|
15
|
-
new Date(entry.cooldown_until).getTime() > Date.now();
|
|
16
|
-
return {
|
|
17
|
-
remaining_pct: isInCooldown ? 0 : null,
|
|
18
|
-
reset_at: isInCooldown ? entry.cooldown_until : null,
|
|
19
|
-
requests_remaining: maxSafe,
|
|
20
|
-
tokens_remaining: null,
|
|
21
|
-
captured_at: entry.updated_at,
|
|
22
|
-
source: "learned",
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
package/dist/quota/limits.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ResolvedProviderName, SessionConfig } from "../types/sessionConfig.js";
|
|
2
|
-
import type { LimitConfidence, LimitSource, ResolvedLimits } from "./types.js";
|
|
3
|
-
export type ProviderType = "hosted" | "local" | "unknown";
|
|
4
|
-
export declare function classifyProvider(providerName: ResolvedProviderName): ProviderType;
|
|
5
|
-
export declare function lookupKnownModel(modelKey: string): Pick<ResolvedLimits, "context_tokens" | "output_tokens"> | undefined;
|
|
6
|
-
export interface LimitResolutionResult {
|
|
7
|
-
limits: ResolvedLimits;
|
|
8
|
-
source: LimitSource;
|
|
9
|
-
confidence: LimitConfidence;
|
|
10
|
-
}
|
|
11
|
-
export interface ResolveLimitsOptions {
|
|
12
|
-
providerName: ResolvedProviderName;
|
|
13
|
-
sessionConfig: SessionConfig;
|
|
14
|
-
hostModel?: string | null;
|
|
15
|
-
}
|
|
16
|
-
export declare function resolveLimits(options: ResolveLimitsOptions): LimitResolutionResult;
|
package/dist/quota/limits.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// RPM/TPM are omitted here — they are tier-dependent and must come from learning.
|
|
2
|
-
const KNOWN_MODEL_LIMITS = {
|
|
3
|
-
"anthropic/claude-opus-4-7": { context_tokens: 200_000, output_tokens: 32_000 },
|
|
4
|
-
"anthropic/claude-sonnet-4-6": { context_tokens: 200_000, output_tokens: 8_192 },
|
|
5
|
-
"anthropic/claude-haiku-4-5": { context_tokens: 200_000, output_tokens: 8_192 },
|
|
6
|
-
"anthropic/claude-opus-4-5": { context_tokens: 200_000, output_tokens: 8_192 },
|
|
7
|
-
"anthropic/claude-sonnet-4-5": { context_tokens: 200_000, output_tokens: 8_192 },
|
|
8
|
-
"openai/gpt-4o": { context_tokens: 128_000, output_tokens: 16_384 },
|
|
9
|
-
"openai/gpt-4o-mini": { context_tokens: 128_000, output_tokens: 16_384 },
|
|
10
|
-
"google/gemini-2.0-flash": { context_tokens: 1_048_576, output_tokens: 8_192 },
|
|
11
|
-
"google/gemini-1.5-pro": { context_tokens: 2_097_152, output_tokens: 8_192 },
|
|
12
|
-
};
|
|
13
|
-
export function classifyProvider(providerName) {
|
|
14
|
-
switch (providerName) {
|
|
15
|
-
case "claude-code":
|
|
16
|
-
return "hosted";
|
|
17
|
-
case "opencode":
|
|
18
|
-
case "local-subprocess":
|
|
19
|
-
return "local";
|
|
20
|
-
case "subprocess-template":
|
|
21
|
-
case "vscode-task":
|
|
22
|
-
default:
|
|
23
|
-
return "unknown";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export function lookupKnownModel(modelKey) {
|
|
27
|
-
return KNOWN_MODEL_LIMITS[modelKey.toLowerCase().trim()];
|
|
28
|
-
}
|
|
29
|
-
function defaultLimits(sessionConfig) {
|
|
30
|
-
const quota = sessionConfig.quota ?? {};
|
|
31
|
-
return {
|
|
32
|
-
context_tokens: quota.default_context_tokens ?? 32_000,
|
|
33
|
-
output_tokens: quota.reserved_output_tokens ?? 4_096,
|
|
34
|
-
requests_per_minute: null,
|
|
35
|
-
input_tokens_per_minute: null,
|
|
36
|
-
output_tokens_per_minute: null,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export function resolveLimits(options) {
|
|
40
|
-
const { providerName: _providerName, sessionConfig, hostModel } = options;
|
|
41
|
-
const quota = sessionConfig.quota ?? {};
|
|
42
|
-
const defaults = defaultLimits(sessionConfig);
|
|
43
|
-
// 1. Explicit per-model config overrides
|
|
44
|
-
if (hostModel && quota.models?.[hostModel]) {
|
|
45
|
-
const override = quota.models[hostModel];
|
|
46
|
-
return {
|
|
47
|
-
limits: {
|
|
48
|
-
context_tokens: override.context_tokens ?? defaults.context_tokens,
|
|
49
|
-
output_tokens: override.output_tokens ?? defaults.output_tokens,
|
|
50
|
-
requests_per_minute: override.requests_per_minute ?? null,
|
|
51
|
-
input_tokens_per_minute: override.input_tokens_per_minute ?? null,
|
|
52
|
-
output_tokens_per_minute: override.output_tokens_per_minute ?? null,
|
|
53
|
-
},
|
|
54
|
-
source: "explicit_config",
|
|
55
|
-
confidence: "high",
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// 2. Static known-model database (context/output only; RPM/TPM from learning)
|
|
59
|
-
if (hostModel) {
|
|
60
|
-
const known = lookupKnownModel(hostModel);
|
|
61
|
-
if (known) {
|
|
62
|
-
return {
|
|
63
|
-
limits: {
|
|
64
|
-
context_tokens: known.context_tokens,
|
|
65
|
-
output_tokens: known.output_tokens,
|
|
66
|
-
requests_per_minute: null,
|
|
67
|
-
input_tokens_per_minute: null,
|
|
68
|
-
output_tokens_per_minute: null,
|
|
69
|
-
},
|
|
70
|
-
source: "known_metadata",
|
|
71
|
-
confidence: "medium",
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// 3. Conservative defaults for all provider types
|
|
76
|
-
return { limits: defaults, source: "default", confidence: "low" };
|
|
77
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface QuotaUsageSnapshot {
|
|
2
|
-
remaining_pct: number | null;
|
|
3
|
-
reset_at: string | null;
|
|
4
|
-
requests_remaining: number | null;
|
|
5
|
-
tokens_remaining: number | null;
|
|
6
|
-
captured_at: string;
|
|
7
|
-
source: string;
|
|
8
|
-
}
|
|
9
|
-
export interface QuotaSource {
|
|
10
|
-
readonly name: string;
|
|
11
|
-
queryCurrentUsage(providerModelKey: string): Promise<QuotaUsageSnapshot | null>;
|
|
12
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export interface SlidingWindowResult<T> {
|
|
2
|
-
results: PromiseSettledResult<T>[];
|
|
3
|
-
}
|
|
4
|
-
export declare function runSlidingWindow<T>(tasks: Array<() => Promise<T>>, concurrency: number, onComplete?: (index: number, result: PromiseSettledResult<T>) => void): Promise<SlidingWindowResult<T>>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export async function runSlidingWindow(tasks, concurrency, onComplete) {
|
|
2
|
-
const results = new Array(tasks.length);
|
|
3
|
-
let nextIndex = 0;
|
|
4
|
-
async function runOne(index) {
|
|
5
|
-
let result;
|
|
6
|
-
try {
|
|
7
|
-
const value = await tasks[index]();
|
|
8
|
-
result = { status: "fulfilled", value };
|
|
9
|
-
}
|
|
10
|
-
catch (reason) {
|
|
11
|
-
result = { status: "rejected", reason };
|
|
12
|
-
}
|
|
13
|
-
results[index] = result;
|
|
14
|
-
onComplete?.(index, result);
|
|
15
|
-
if (nextIndex < tasks.length) {
|
|
16
|
-
const next = nextIndex++;
|
|
17
|
-
await runOne(next);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const initialBatch = Math.min(concurrency, tasks.length);
|
|
21
|
-
const runners = [];
|
|
22
|
-
for (let i = 0; i < initialBatch; i++) {
|
|
23
|
-
const idx = nextIndex++;
|
|
24
|
-
runners.push(runOne(idx));
|
|
25
|
-
}
|
|
26
|
-
await Promise.all(runners);
|
|
27
|
-
return { results };
|
|
28
|
-
}
|
package/dist/quota/state.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ObservedWaveOutcome, QuotaState, QuotaStateEntry } from "./types.js";
|
|
2
|
-
export declare function getQuotaStatePath(): string;
|
|
3
|
-
export declare function decayWeight(weight: number, elapsedHours: number, halfLifeHours: number): number;
|
|
4
|
-
export declare function applyDecayToEntry(entry: QuotaStateEntry, halfLifeHours: number): QuotaStateEntry;
|
|
5
|
-
export declare function readQuotaState(): Promise<QuotaState>;
|
|
6
|
-
export declare function writeQuotaState(state: QuotaState): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Returns the highest concurrency level for which decayed success evidence
|
|
9
|
-
* exceeds failure evidence, with a minimum of 1.
|
|
10
|
-
*/
|
|
11
|
-
export declare function computeMaxSafeConcurrency(entry: QuotaStateEntry, halfLifeHours: number, maxToCheck?: number): number;
|
|
12
|
-
export declare function computeRampUpConcurrency(entry: QuotaStateEntry, halfLifeHours: number, maxToCheck?: number): number;
|
|
13
|
-
export declare function computeBackoffCooldownMs(consecutive429Count: number): number;
|
|
14
|
-
export declare function computeBackoffFailureWeight(consecutive429Count: number): number;
|
|
15
|
-
export declare function recordWaveOutcome(providerModelKey: string, outcome: ObservedWaveOutcome, halfLifeHours: number): Promise<void>;
|