@imricci/zaker 0.1.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/dist/commands/align.d.ts +3 -0
- package/dist/commands/align.js +28 -0
- package/dist/commands/align.js.map +1 -0
- package/dist/commands/audit.d.ts +3 -0
- package/dist/commands/audit.js +59 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/confirm.d.ts +3 -0
- package/dist/commands/confirm.js +22 -0
- package/dist/commands/confirm.js.map +1 -0
- package/dist/commands/dialog.d.ts +9 -0
- package/dist/commands/dialog.js +396 -0
- package/dist/commands/dialog.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.js +31 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/models.d.ts +9 -0
- package/dist/commands/models.js +65 -0
- package/dist/commands/models.js.map +1 -0
- package/dist/commands/plan.d.ts +3 -0
- package/dist/commands/plan.js +69 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/run.d.ts +40 -0
- package/dist/commands/run.js +310 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.js +39 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/tui.d.ts +14 -0
- package/dist/commands/tui.js +394 -0
- package/dist/commands/tui.js.map +1 -0
- package/dist/core/auditor.d.ts +13 -0
- package/dist/core/auditor.js +122 -0
- package/dist/core/auditor.js.map +1 -0
- package/dist/core/c3fi.d.ts +10 -0
- package/dist/core/c3fi.js +305 -0
- package/dist/core/c3fi.js.map +1 -0
- package/dist/core/challenge.d.ts +8 -0
- package/dist/core/challenge.js +29 -0
- package/dist/core/challenge.js.map +1 -0
- package/dist/core/checkpoint.d.ts +20 -0
- package/dist/core/checkpoint.js +192 -0
- package/dist/core/checkpoint.js.map +1 -0
- package/dist/core/execution-provider.d.ts +2 -0
- package/dist/core/execution-provider.js +125 -0
- package/dist/core/execution-provider.js.map +1 -0
- package/dist/core/executor.d.ts +16 -0
- package/dist/core/executor.js +68 -0
- package/dist/core/executor.js.map +1 -0
- package/dist/core/memory.d.ts +11 -0
- package/dist/core/memory.js +105 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/planner.d.ts +146 -0
- package/dist/core/planner.js +152 -0
- package/dist/core/planner.js.map +1 -0
- package/dist/core/preflight.d.ts +6 -0
- package/dist/core/preflight.js +140 -0
- package/dist/core/preflight.js.map +1 -0
- package/dist/core/provider-onboarding.d.ts +12 -0
- package/dist/core/provider-onboarding.js +32 -0
- package/dist/core/provider-onboarding.js.map +1 -0
- package/dist/core/run-loop.d.ts +32 -0
- package/dist/core/run-loop.js +205 -0
- package/dist/core/run-loop.js.map +1 -0
- package/dist/core/scope.d.ts +3 -0
- package/dist/core/scope.js +75 -0
- package/dist/core/scope.js.map +1 -0
- package/dist/core/types.d.ts +288 -0
- package/dist/core/types.js +11 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/verdict-panel.d.ts +29 -0
- package/dist/core/verdict-panel.js +120 -0
- package/dist/core/verdict-panel.js.map +1 -0
- package/dist/core/verifier.d.ts +2 -0
- package/dist/core/verifier.js +47 -0
- package/dist/core/verifier.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/infra/config.d.ts +36 -0
- package/dist/infra/config.js +397 -0
- package/dist/infra/config.js.map +1 -0
- package/dist/infra/git.d.ts +6 -0
- package/dist/infra/git.js +35 -0
- package/dist/infra/git.js.map +1 -0
- package/dist/infra/hashing.d.ts +1 -0
- package/dist/infra/hashing.js +8 -0
- package/dist/infra/hashing.js.map +1 -0
- package/dist/infra/intent.d.ts +30 -0
- package/dist/infra/intent.js +357 -0
- package/dist/infra/intent.js.map +1 -0
- package/dist/infra/memory.d.ts +10 -0
- package/dist/infra/memory.js +94 -0
- package/dist/infra/memory.js.map +1 -0
- package/dist/infra/model-catalog.d.ts +27 -0
- package/dist/infra/model-catalog.js +273 -0
- package/dist/infra/model-catalog.js.map +1 -0
- package/dist/infra/process.d.ts +12 -0
- package/dist/infra/process.js +32 -0
- package/dist/infra/process.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runPreflight = runPreflight;
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const git_1 = require("../infra/git");
|
|
8
|
+
const hashing_1 = require("../infra/hashing");
|
|
9
|
+
const process_1 = require("../infra/process");
|
|
10
|
+
const LOCKFILE_CANDIDATES = [
|
|
11
|
+
"package-lock.json",
|
|
12
|
+
"pnpm-lock.yaml",
|
|
13
|
+
"yarn.lock",
|
|
14
|
+
"npm-shrinkwrap.json"
|
|
15
|
+
];
|
|
16
|
+
const ALLOWED_DIRTY_PATHS = new Set([
|
|
17
|
+
"sop.json",
|
|
18
|
+
"checkpoint.json",
|
|
19
|
+
".molo/memory.json",
|
|
20
|
+
".molo/intent.card.json",
|
|
21
|
+
".molo/intent.confirmed.json",
|
|
22
|
+
".molo/session.json",
|
|
23
|
+
".molo/tui_session.json"
|
|
24
|
+
]);
|
|
25
|
+
async function fileExists(filePath) {
|
|
26
|
+
try {
|
|
27
|
+
await (0, promises_1.access)(filePath, node_fs_1.constants.F_OK);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function parseCommandBinary(command) {
|
|
35
|
+
const trimmed = command.trim();
|
|
36
|
+
if (!trimmed) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
return trimmed.split(/\s+/)[0] || "";
|
|
40
|
+
}
|
|
41
|
+
async function resolveLockfile(cwd) {
|
|
42
|
+
for (const candidate of LOCKFILE_CANDIDATES) {
|
|
43
|
+
const absolutePath = (0, node_path_1.resolve)(cwd, candidate);
|
|
44
|
+
if (await fileExists(absolutePath)) {
|
|
45
|
+
const content = await (0, promises_1.readFile)(absolutePath, "utf8");
|
|
46
|
+
return {
|
|
47
|
+
path: candidate,
|
|
48
|
+
sha256: (0, hashing_1.sha256)(content)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error("Preflight failed: lockfile not found. Expected package-lock.json/pnpm-lock.yaml/yarn.lock.");
|
|
53
|
+
}
|
|
54
|
+
async function assertGitClean(cwd) {
|
|
55
|
+
const git = (0, git_1.createGitClient)(cwd);
|
|
56
|
+
const rawStatus = (await git.raw(["status", "--porcelain"])).trim();
|
|
57
|
+
if (rawStatus.length === 0) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const lines = rawStatus.split(/\r?\n/).map((line) => line.trimEnd());
|
|
61
|
+
const disallowed = lines.filter((line) => {
|
|
62
|
+
const match = line.match(/^(.{1,2})\s+(.*)$/);
|
|
63
|
+
if (!match) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
const payload = match[2].trim();
|
|
67
|
+
const normalized = payload.includes(" -> ")
|
|
68
|
+
? payload.split(" -> ").pop()?.trim() || payload
|
|
69
|
+
: payload;
|
|
70
|
+
return !ALLOWED_DIRTY_PATHS.has(normalized);
|
|
71
|
+
});
|
|
72
|
+
if (disallowed.length > 0) {
|
|
73
|
+
throw new Error(`Preflight failed: git workspace is not clean. disallowed=${disallowed.join(" | ")}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function buildCommandSignatures(commands) {
|
|
77
|
+
const signatures = [];
|
|
78
|
+
for (const commandSpec of commands) {
|
|
79
|
+
if (!commandSpec.required) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const binary = parseCommandBinary(commandSpec.command);
|
|
83
|
+
if (!binary) {
|
|
84
|
+
throw new Error(`Preflight failed: invalid verification command (${commandSpec.id}).`);
|
|
85
|
+
}
|
|
86
|
+
const lookup = await (0, process_1.runCommand)("which", [binary]);
|
|
87
|
+
if (lookup.exitCode !== 0) {
|
|
88
|
+
throw new Error(`Preflight failed: verification binary not found: ${binary}`);
|
|
89
|
+
}
|
|
90
|
+
signatures.push({
|
|
91
|
+
id: commandSpec.id,
|
|
92
|
+
command: commandSpec.command,
|
|
93
|
+
command_sha256: (0, hashing_1.sha256)(commandSpec.command)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (signatures.length === 0) {
|
|
97
|
+
throw new Error("Preflight failed: no required verification commands configured.");
|
|
98
|
+
}
|
|
99
|
+
return signatures;
|
|
100
|
+
}
|
|
101
|
+
async function resolveRiskPathInfo(config, cwd) {
|
|
102
|
+
const riskPath = config.risk.risk_paths_file;
|
|
103
|
+
const absoluteRiskPath = (0, node_path_1.resolve)(cwd, riskPath);
|
|
104
|
+
if (!(await fileExists(absoluteRiskPath))) {
|
|
105
|
+
throw new Error(`Preflight failed: risk paths file not found: ${riskPath}`);
|
|
106
|
+
}
|
|
107
|
+
const stats = await (0, promises_1.stat)(absoluteRiskPath);
|
|
108
|
+
if ((stats.mode & 0o222) !== 0) {
|
|
109
|
+
throw new Error(`Preflight failed: risk paths file must be read-only: ${riskPath} (chmod 444 ${riskPath})`);
|
|
110
|
+
}
|
|
111
|
+
const riskContent = await (0, promises_1.readFile)(absoluteRiskPath, "utf8");
|
|
112
|
+
return {
|
|
113
|
+
riskPath,
|
|
114
|
+
riskSha256: (0, hashing_1.sha256)(riskContent)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function runPreflight(sop, config, cwd = process.cwd()) {
|
|
118
|
+
await assertGitClean(cwd);
|
|
119
|
+
const lockfile = await resolveLockfile(cwd);
|
|
120
|
+
const verificationCommands = await buildCommandSignatures(sop.verification.commands);
|
|
121
|
+
const risk = await resolveRiskPathInfo(config, cwd);
|
|
122
|
+
return {
|
|
123
|
+
metadata: {
|
|
124
|
+
preflight_checked_at: new Date().toISOString(),
|
|
125
|
+
lockfile_path: lockfile.path,
|
|
126
|
+
lockfile_sha256: lockfile.sha256,
|
|
127
|
+
verification_commands: verificationCommands,
|
|
128
|
+
risk_paths_file: risk.riskPath,
|
|
129
|
+
risk_paths_sha256: risk.riskSha256,
|
|
130
|
+
execution: {
|
|
131
|
+
provider: config.execution.provider,
|
|
132
|
+
model: config.execution.model,
|
|
133
|
+
ollama_host: config.execution.provider === "ollama" ? config.execution.ollama_host : undefined,
|
|
134
|
+
max_attempts: config.execution.max_attempts,
|
|
135
|
+
attempts_used: 0
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=preflight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../src/core/preflight.ts"],"names":[],"mappings":";;AA6IA,oCA4BC;AAzKD,+CAA0D;AAC1D,qCAAoC;AACpC,yCAAoC;AACpC,sCAA+C;AAC/C,8CAA0C;AAC1C,8CAA8C;AAI9C,MAAM,mBAAmB,GAAG;IAC1B,mBAAmB;IACnB,gBAAgB;IAChB,WAAW;IACX,qBAAqB;CACtB,CAAC;AACF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAClC,UAAU;IACV,iBAAiB;IACjB,mBAAmB;IACnB,wBAAwB;IACxB,6BAA6B;IAC7B,oBAAoB;IACpB,wBAAwB;CACzB,CAAC,CAAC;AAEH,KAAK,UAAU,UAAU,CAAC,QAAgB;IACxC,IAAI,CAAC;QACH,MAAM,IAAA,iBAAM,EAAC,QAAQ,EAAE,mBAAS,CAAC,IAAI,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAe;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAA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M,QAAQ,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,oBAAoB,GAAG,MAAM,sBAAsB,CAAC,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACrF,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEpD,OAAO;QACL,QAAQ,EAAE;YACR,oBAAoB,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YAC9C,aAAa,EAAE,QAAQ,CAAC,IAAI;YAC5B,eAAe,EAAE,QAAQ,CAAC,MAAM;YAChC,qBAAqB,EAAE,oBAAoB;YAC3C,eAAe,EAAE,IAAI,CAAC,QAAQ;YAC9B,iBAAiB,EAAE,IAAI,CAAC,UAAU;YAClC,SAAS,EAAE;gBACT,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ;gBACnC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK;gBAC7B,WAAW,EACT,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;gBACnF,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC,YAAY;gBAC3C,aAAa,EAAE,CAAC;aACjB;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MoloConfig } from "../infra/config";
|
|
2
|
+
export interface ProviderOnboardingState {
|
|
3
|
+
required: boolean;
|
|
4
|
+
provider: string;
|
|
5
|
+
catalog_size: number;
|
|
6
|
+
selected: {
|
|
7
|
+
planner: string;
|
|
8
|
+
auditor: string;
|
|
9
|
+
execution: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function ensureProviderOnboarding(config: MoloConfig): Promise<ProviderOnboardingState>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureProviderOnboarding = ensureProviderOnboarding;
|
|
4
|
+
const model_catalog_1 = require("../infra/model-catalog");
|
|
5
|
+
async function ensureProviderOnboarding(config) {
|
|
6
|
+
const required = (0, model_catalog_1.isCloudOnboardingRequired)(config);
|
|
7
|
+
const selections = (0, model_catalog_1.resolveModelSelections)(config);
|
|
8
|
+
if (!required) {
|
|
9
|
+
return {
|
|
10
|
+
required: false,
|
|
11
|
+
provider: config.model.provider,
|
|
12
|
+
catalog_size: 0,
|
|
13
|
+
selected: selections
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const catalog = await (0, model_catalog_1.fetchModelCatalog)(config);
|
|
17
|
+
(0, model_catalog_1.validateModelSelection)("planner", selections.planner, catalog.role_models.planner);
|
|
18
|
+
(0, model_catalog_1.validateModelSelection)("auditor", selections.auditor, catalog.role_models.auditor);
|
|
19
|
+
if (config.execution.provider === "cheap_cloud") {
|
|
20
|
+
(0, model_catalog_1.validateModelSelection)("execution", selections.execution, catalog.role_models.execution);
|
|
21
|
+
}
|
|
22
|
+
if (config.execution.provider === "ollama") {
|
|
23
|
+
(0, model_catalog_1.validateModelSelection)("execution", selections.execution, catalog.role_models.execution);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
required: true,
|
|
27
|
+
provider: catalog.provider,
|
|
28
|
+
catalog_size: catalog.models.length,
|
|
29
|
+
selected: selections
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=provider-onboarding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-onboarding.js","sourceRoot":"","sources":["../../src/core/provider-onboarding.ts"],"names":[],"mappings":";;AAmBA,4DA+BC;AAjDD,0DAKgC;AAazB,KAAK,UAAU,wBAAwB,CAC5C,MAAkB;IAElB,MAAM,QAAQ,GAAG,IAAA,yCAAyB,EAAC,MAAM,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,IAAA,sCAAsB,EAAC,MAAM,CAAC,CAAC;IAElD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ;YAC/B,YAAY,EAAE,CAAC;YACf,QAAQ,EAAE,UAAU;SACrB,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,iCAAiB,EAAC,MAAM,CAAC,CAAC;IAChD,IAAA,sCAAsB,EAAC,SAAS,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnF,IAAA,sCAAsB,EAAC,SAAS,EAAE,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnF,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;QAChD,IAAA,sCAAsB,EAAC,WAAW,EAAE,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC3F,CAAC;IACD,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC3C,IAAA,sCAAsB,EAAC,WAAW,EAAE,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM;QACnC,QAAQ,EAAE,UAAU;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InterpretedAudit } from "./auditor";
|
|
2
|
+
import { AuditResult, Checkpoint, C3FIReport, ChallengeHistoryEntry, IntentBinding, LLMProvider, MemorySummary, RunnerCommandSignature, RunnerMetadata, VerificationReport } from "./types";
|
|
3
|
+
export interface RunAuditLoopOptions {
|
|
4
|
+
provider: LLMProvider;
|
|
5
|
+
baseCommit: string;
|
|
6
|
+
sopId: string;
|
|
7
|
+
allowedPaths: string[];
|
|
8
|
+
verificationCommands: RunnerCommandSignature[];
|
|
9
|
+
initialVerification: VerificationReport;
|
|
10
|
+
runnerMetadata: RunnerMetadata;
|
|
11
|
+
c3fiReport: C3FIReport;
|
|
12
|
+
memorySummary: MemorySummary;
|
|
13
|
+
intentBinding: IntentBinding;
|
|
14
|
+
maxChallenges: number;
|
|
15
|
+
cloudPlanCalls?: number;
|
|
16
|
+
checkpointOutputPath?: string;
|
|
17
|
+
cwd?: string;
|
|
18
|
+
onChallenge?: (interpretation: InterpretedAudit) => void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface RunAuditLoopResult {
|
|
21
|
+
interpretation: InterpretedAudit;
|
|
22
|
+
verification: VerificationReport;
|
|
23
|
+
checkpoint: Checkpoint;
|
|
24
|
+
finalAuditResult: AuditResult;
|
|
25
|
+
challengeHistory: ChallengeHistoryEntry[];
|
|
26
|
+
budget: {
|
|
27
|
+
cloud_plan_calls: number;
|
|
28
|
+
cloud_audit_calls: number;
|
|
29
|
+
challenge_used: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare function runBoundedAuditLoop(options: RunAuditLoopOptions): Promise<RunAuditLoopResult>;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runBoundedAuditLoop = runBoundedAuditLoop;
|
|
4
|
+
const auditor_1 = require("./auditor");
|
|
5
|
+
const challenge_1 = require("./challenge");
|
|
6
|
+
const checkpoint_1 = require("./checkpoint");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
const CHALLENGE_ROUND_HARD_LIMIT = 2;
|
|
9
|
+
async function runBoundedAuditLoop(options) {
|
|
10
|
+
const cwd = options.cwd ?? process.cwd();
|
|
11
|
+
const checkpointOutputPath = options.checkpointOutputPath ?? "checkpoint.json";
|
|
12
|
+
const challengeLimit = Math.min(CHALLENGE_ROUND_HARD_LIMIT, Math.max(0, options.maxChallenges));
|
|
13
|
+
const seenFingerprints = new Set();
|
|
14
|
+
const challengeHistory = [];
|
|
15
|
+
const budget = {
|
|
16
|
+
cloud_plan_calls: options.cloudPlanCalls ?? 1,
|
|
17
|
+
cloud_audit_calls: 0,
|
|
18
|
+
challenge_used: 0
|
|
19
|
+
};
|
|
20
|
+
let verification = options.initialVerification;
|
|
21
|
+
let lastCheckpoint = null;
|
|
22
|
+
async function persistCheckpoint() {
|
|
23
|
+
const checkpoint = await (0, checkpoint_1.buildCheckpoint)({
|
|
24
|
+
cwd,
|
|
25
|
+
baseCommit: options.baseCommit,
|
|
26
|
+
sopId: options.sopId,
|
|
27
|
+
intentBinding: options.intentBinding,
|
|
28
|
+
verification,
|
|
29
|
+
c3fiReport: options.c3fiReport,
|
|
30
|
+
memorySummary: options.memorySummary,
|
|
31
|
+
budget,
|
|
32
|
+
challengeHistory,
|
|
33
|
+
runnerMetadata: options.runnerMetadata
|
|
34
|
+
});
|
|
35
|
+
await (0, checkpoint_1.writeCheckpoint)(checkpoint, checkpointOutputPath, cwd);
|
|
36
|
+
lastCheckpoint = checkpoint;
|
|
37
|
+
return checkpoint;
|
|
38
|
+
}
|
|
39
|
+
while (true) {
|
|
40
|
+
if (options.c3fiReport.required && options.c3fiReport.status === "FAILED") {
|
|
41
|
+
const checkpoint = await persistCheckpoint();
|
|
42
|
+
const finalAuditResult = {
|
|
43
|
+
schema_version: types_1.AUDIT_SCHEMA_VERSION,
|
|
44
|
+
verdict: "FAIL",
|
|
45
|
+
reason_code: "C3_FI_GUARD_FAILED",
|
|
46
|
+
message: options.c3fiReport.message
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
interpretation: {
|
|
50
|
+
verdict: "FAIL",
|
|
51
|
+
lines: ["FAIL", options.c3fiReport.message],
|
|
52
|
+
exitCode: 1
|
|
53
|
+
},
|
|
54
|
+
verification,
|
|
55
|
+
checkpoint,
|
|
56
|
+
finalAuditResult,
|
|
57
|
+
challengeHistory,
|
|
58
|
+
budget
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const checkpointBeforeAudit = await persistCheckpoint();
|
|
62
|
+
const preconditionResult = (0, auditor_1.guardCheckpointForAudit)(checkpointBeforeAudit);
|
|
63
|
+
if (preconditionResult) {
|
|
64
|
+
const finalAuditResult = {
|
|
65
|
+
schema_version: types_1.AUDIT_SCHEMA_VERSION,
|
|
66
|
+
verdict: "FAIL",
|
|
67
|
+
reason_code: "PRECONDITION_FAILED",
|
|
68
|
+
message: preconditionResult.lines.slice(1).join(" | ")
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
interpretation: preconditionResult,
|
|
72
|
+
verification,
|
|
73
|
+
checkpoint: checkpointBeforeAudit,
|
|
74
|
+
finalAuditResult,
|
|
75
|
+
challengeHistory,
|
|
76
|
+
budget
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
budget.cloud_audit_calls += 1;
|
|
80
|
+
const checkpoint = await persistCheckpoint();
|
|
81
|
+
const normalizedAudit = (0, auditor_1.normalizeAuditResult)(await options.provider.audit(checkpoint));
|
|
82
|
+
const interpreted = (0, auditor_1.interpretAuditResult)(normalizedAudit, { allowChallenge: true });
|
|
83
|
+
if (interpreted.verdict !== "CHALLENGE") {
|
|
84
|
+
return {
|
|
85
|
+
interpretation: interpreted,
|
|
86
|
+
verification,
|
|
87
|
+
checkpoint,
|
|
88
|
+
finalAuditResult: normalizedAudit,
|
|
89
|
+
challengeHistory,
|
|
90
|
+
budget
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
await options.onChallenge?.(interpreted);
|
|
94
|
+
const challenge = normalizedAudit.challenge;
|
|
95
|
+
if (!challenge) {
|
|
96
|
+
const interpretation = (0, auditor_1.humanInterventionResult)("Invalid challenge payload: missing challenge data.");
|
|
97
|
+
const finalAuditResult = {
|
|
98
|
+
schema_version: types_1.AUDIT_SCHEMA_VERSION,
|
|
99
|
+
verdict: "FAIL",
|
|
100
|
+
reason_code: "INVALID_CHALLENGE",
|
|
101
|
+
message: "Invalid challenge payload: missing challenge data."
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
interpretation,
|
|
105
|
+
verification,
|
|
106
|
+
checkpoint,
|
|
107
|
+
finalAuditResult,
|
|
108
|
+
challengeHistory,
|
|
109
|
+
budget
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const challengeRound = budget.challenge_used + 1;
|
|
113
|
+
const duplicateFingerprint = seenFingerprints.has(challenge.fingerprint);
|
|
114
|
+
const exceedsLimit = challengeRound > challengeLimit;
|
|
115
|
+
if (duplicateFingerprint || exceedsLimit) {
|
|
116
|
+
challengeHistory.push({
|
|
117
|
+
round: challengeRound,
|
|
118
|
+
challenge_id: challenge.challenge_id,
|
|
119
|
+
type: challenge.type,
|
|
120
|
+
fingerprint: challenge.fingerprint,
|
|
121
|
+
instruction: challenge.instruction,
|
|
122
|
+
audit_call: budget.cloud_audit_calls,
|
|
123
|
+
status: "REJECTED",
|
|
124
|
+
applied_patches: 0,
|
|
125
|
+
verification_all_passed: verification.all_passed,
|
|
126
|
+
reason: duplicateFingerprint
|
|
127
|
+
? `Duplicate challenge fingerprint: ${challenge.fingerprint}`
|
|
128
|
+
: `Challenge limit exceeded: max ${challengeLimit}`,
|
|
129
|
+
recorded_at: new Date().toISOString()
|
|
130
|
+
});
|
|
131
|
+
await persistCheckpoint();
|
|
132
|
+
const interpretation = (0, auditor_1.humanInterventionResult)(duplicateFingerprint
|
|
133
|
+
? `Duplicate challenge fingerprint detected: ${challenge.fingerprint}`
|
|
134
|
+
: `Challenge limit exceeded (${challengeLimit}).`);
|
|
135
|
+
const checkpointWithHistory = lastCheckpoint ?? checkpoint;
|
|
136
|
+
const finalAuditResult = {
|
|
137
|
+
schema_version: types_1.AUDIT_SCHEMA_VERSION,
|
|
138
|
+
verdict: "FAIL",
|
|
139
|
+
reason_code: duplicateFingerprint
|
|
140
|
+
? "DUPLICATE_CHALLENGE_FINGERPRINT"
|
|
141
|
+
: "CHALLENGE_LIMIT_EXCEEDED",
|
|
142
|
+
message: interpretation.lines.slice(1).join(" | ")
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
interpretation,
|
|
146
|
+
verification,
|
|
147
|
+
checkpoint: checkpointWithHistory,
|
|
148
|
+
finalAuditResult,
|
|
149
|
+
challengeHistory,
|
|
150
|
+
budget
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
seenFingerprints.add(challenge.fingerprint);
|
|
154
|
+
try {
|
|
155
|
+
const resolution = await (0, challenge_1.handleChallenge)(normalizedAudit, options.allowedPaths, options.verificationCommands, cwd);
|
|
156
|
+
const appliedPatches = resolution.execution?.applied_patches ?? 0;
|
|
157
|
+
verification = resolution.verification ?? verification;
|
|
158
|
+
budget.challenge_used = challengeRound;
|
|
159
|
+
challengeHistory.push({
|
|
160
|
+
round: challengeRound,
|
|
161
|
+
challenge_id: challenge.challenge_id,
|
|
162
|
+
type: challenge.type,
|
|
163
|
+
fingerprint: challenge.fingerprint,
|
|
164
|
+
instruction: challenge.instruction,
|
|
165
|
+
audit_call: budget.cloud_audit_calls,
|
|
166
|
+
status: appliedPatches > 0 ? "APPLIED" : "SKIPPED",
|
|
167
|
+
applied_patches: appliedPatches,
|
|
168
|
+
verification_all_passed: verification.all_passed,
|
|
169
|
+
recorded_at: new Date().toISOString()
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
174
|
+
budget.challenge_used = challengeRound;
|
|
175
|
+
challengeHistory.push({
|
|
176
|
+
round: challengeRound,
|
|
177
|
+
challenge_id: challenge.challenge_id,
|
|
178
|
+
type: challenge.type,
|
|
179
|
+
fingerprint: challenge.fingerprint,
|
|
180
|
+
instruction: challenge.instruction,
|
|
181
|
+
audit_call: budget.cloud_audit_calls,
|
|
182
|
+
status: "REJECTED",
|
|
183
|
+
applied_patches: 0,
|
|
184
|
+
verification_all_passed: verification.all_passed,
|
|
185
|
+
reason: message,
|
|
186
|
+
recorded_at: new Date().toISOString()
|
|
187
|
+
});
|
|
188
|
+
await persistCheckpoint();
|
|
189
|
+
return {
|
|
190
|
+
interpretation: (0, auditor_1.humanInterventionResult)(`Challenge execution failed: ${message}`),
|
|
191
|
+
verification,
|
|
192
|
+
checkpoint: lastCheckpoint ?? checkpoint,
|
|
193
|
+
finalAuditResult: {
|
|
194
|
+
schema_version: types_1.AUDIT_SCHEMA_VERSION,
|
|
195
|
+
verdict: "FAIL",
|
|
196
|
+
reason_code: "CHALLENGE_EXECUTION_FAILED",
|
|
197
|
+
message
|
|
198
|
+
},
|
|
199
|
+
challengeHistory,
|
|
200
|
+
budget
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=run-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-loop.js","sourceRoot":"","sources":["../../src/core/run-loop.ts"],"names":[],"mappings":";;AAwDA,kDA0NC;AAlRD,uCAMmB;AACnB,2CAA8C;AAC9C,6CAAgE;AAChE,mCAYiB;AAEjB,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAiC9B,KAAK,UAAU,mBAAmB,CAAC,OAA4B;IACpE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,IAAI,iBAAiB,CAAC;IAC/E,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAC7B,0BAA0B,EAC1B,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CACnC,CAAC;IACF,MAAM,gBAAgB,GAAG,IAAI,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0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractPatchedPaths = extractPatchedPaths;
|
|
7
|
+
exports.resolveAllowedPaths = resolveAllowedPaths;
|
|
8
|
+
exports.validatePatch = validatePatch;
|
|
9
|
+
const micromatch_1 = __importDefault(require("micromatch"));
|
|
10
|
+
const SRC_SCOPE = "src/**";
|
|
11
|
+
const DIFF_GIT_REGEX = /^diff --git a\/(.+?) b\/(.+)$/;
|
|
12
|
+
function normalizePath(filePath) {
|
|
13
|
+
return filePath
|
|
14
|
+
.trim()
|
|
15
|
+
.replace(/^"+|"+$/g, "")
|
|
16
|
+
.replace(/^\.\/+/, "")
|
|
17
|
+
.replace(/\\/g, "/");
|
|
18
|
+
}
|
|
19
|
+
function parseDiffPathToken(token) {
|
|
20
|
+
const normalizedToken = token.trim().split(/\s+/)[0];
|
|
21
|
+
if (!normalizedToken || normalizedToken === "/dev/null") {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
let filePath = normalizedToken;
|
|
25
|
+
if (filePath.startsWith("a/") || filePath.startsWith("b/")) {
|
|
26
|
+
filePath = filePath.slice(2);
|
|
27
|
+
}
|
|
28
|
+
const parsed = normalizePath(filePath);
|
|
29
|
+
return parsed.length > 0 ? parsed : null;
|
|
30
|
+
}
|
|
31
|
+
function extractPatchedPaths(patch) {
|
|
32
|
+
const files = new Set();
|
|
33
|
+
const lines = patch.split(/\r?\n/);
|
|
34
|
+
for (const line of lines) {
|
|
35
|
+
const diffMatch = DIFF_GIT_REGEX.exec(line);
|
|
36
|
+
if (diffMatch) {
|
|
37
|
+
const leftPath = normalizePath(diffMatch[1]);
|
|
38
|
+
const rightPath = normalizePath(diffMatch[2]);
|
|
39
|
+
if (leftPath.length > 0) {
|
|
40
|
+
files.add(leftPath);
|
|
41
|
+
}
|
|
42
|
+
if (rightPath.length > 0) {
|
|
43
|
+
files.add(rightPath);
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (line.startsWith("+++ ") || line.startsWith("--- ")) {
|
|
48
|
+
const token = line.slice(4);
|
|
49
|
+
const parsed = parseDiffPathToken(token);
|
|
50
|
+
if (parsed) {
|
|
51
|
+
files.add(parsed);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Array.from(files);
|
|
56
|
+
}
|
|
57
|
+
function resolveAllowedPaths(...pathSources) {
|
|
58
|
+
const merged = pathSources
|
|
59
|
+
.flatMap((paths) => paths ?? [])
|
|
60
|
+
.map((path) => path.trim())
|
|
61
|
+
.filter((path) => path.length > 0);
|
|
62
|
+
if (merged.length === 0) {
|
|
63
|
+
return [SRC_SCOPE];
|
|
64
|
+
}
|
|
65
|
+
return Array.from(new Set(merged));
|
|
66
|
+
}
|
|
67
|
+
function validatePatch(patch, allowedPaths) {
|
|
68
|
+
const effectiveGlobs = resolveAllowedPaths(allowedPaths);
|
|
69
|
+
const patchedPaths = extractPatchedPaths(patch);
|
|
70
|
+
if (patchedPaths.length === 0) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return patchedPaths.every((filePath) => micromatch_1.default.isMatch(filePath, SRC_SCOPE) && micromatch_1.default.isMatch(filePath, effectiveGlobs));
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/core/scope.ts"],"names":[],"mappings":";;;;;AA4BA,kDA4BC;AAED,kDAWC;AAED,sCAYC;AAnFD,4DAAoC;AAEpC,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAEvD,SAAS,aAAa,CAAC,QAAgB;IACrC,O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