@mousedev/harness-core 0.1.1
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/LICENSE +21 -0
- package/README.md +36 -0
- package/dist/detect.d.ts +45 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +170 -0
- package/dist/detect.js.map +1 -0
- package/dist/engine.d.ts +33 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +2 -0
- package/dist/engine.js.map +1 -0
- package/dist/events.d.ts +13 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/exec.d.ts +9 -0
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +54 -0
- package/dist/exec.js.map +1 -0
- package/dist/failures.d.ts +10 -0
- package/dist/failures.d.ts.map +1 -0
- package/dist/failures.js +52 -0
- package/dist/failures.js.map +1 -0
- package/dist/git.d.ts +14 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +47 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/loop.d.ts +119 -0
- package/dist/loop.d.ts.map +1 -0
- package/dist/loop.js +190 -0
- package/dist/loop.js.map +1 -0
- package/dist/mea.d.ts +80 -0
- package/dist/mea.d.ts.map +1 -0
- package/dist/mea.js +156 -0
- package/dist/mea.js.map +1 -0
- package/dist/paths.d.ts +7 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +27 -0
- package/dist/paths.js.map +1 -0
- package/dist/policy.d.ts +74 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +179 -0
- package/dist/policy.js.map +1 -0
- package/dist/probe.d.ts +21 -0
- package/dist/probe.d.ts.map +1 -0
- package/dist/probe.js +55 -0
- package/dist/probe.js.map +1 -0
- package/dist/prompt.d.ts +33 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +48 -0
- package/dist/prompt.js.map +1 -0
- package/dist/trace.d.ts +57 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +35 -0
- package/dist/trace.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace.d.ts +26 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +8 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +39 -0
package/dist/loop.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Completion loop: the harness keeps going after the model says "done".
|
|
3
|
+
*
|
|
4
|
+
* Every DeepSWE pass on FrontierHarness took 73-358 turns and ended with the
|
|
5
|
+
* repo's suite green; an engine's own loop ends the moment the model's finish
|
|
6
|
+
* reason is not `tool-calls`, and that single fact costs it every long task.
|
|
7
|
+
* After each turn this loop probes the workspace deterministically (did
|
|
8
|
+
* anything change, do the checks pass, was anything tampered with), then
|
|
9
|
+
* either stops with evidence or continues in the same session with the
|
|
10
|
+
* failing output and an audit request.
|
|
11
|
+
*
|
|
12
|
+
* Spend follows evidence of progress, never a fixed round count: the loop
|
|
13
|
+
* stops on a satisfied audit, on the wall clock, on a step ceiling far above
|
|
14
|
+
* the field's maximum, or when consecutive rounds change nothing.
|
|
15
|
+
*
|
|
16
|
+
* Pure: it needs a probe (four functions over the workspace), an engine that
|
|
17
|
+
* can take a prompt, and callbacks. No filesystem, no network.
|
|
18
|
+
*/
|
|
19
|
+
import type { Engine } from "./engine.js";
|
|
20
|
+
import type { LoopEvent } from "./events.js";
|
|
21
|
+
import { type TaskState } from "./mea.js";
|
|
22
|
+
export interface CheckResult {
|
|
23
|
+
name: string;
|
|
24
|
+
command: string;
|
|
25
|
+
pass: boolean;
|
|
26
|
+
/** `null` when the check timed out. */
|
|
27
|
+
exitCode: number | null;
|
|
28
|
+
excerpt: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CompletionProbe {
|
|
31
|
+
/** Run the repo's declared or detected checks. Empty when none exist. */
|
|
32
|
+
checks(): Promise<CheckResult[]>;
|
|
33
|
+
/** Test, spec, and workflow files deleted since the run started. */
|
|
34
|
+
tampering(): Promise<string[]>;
|
|
35
|
+
/** Stable digest of the workspace state; any edit changes it. */
|
|
36
|
+
fingerprint(): Promise<string>;
|
|
37
|
+
}
|
|
38
|
+
export interface CompletionBudget {
|
|
39
|
+
maxWallMs: number;
|
|
40
|
+
maxTotalSteps: number;
|
|
41
|
+
maxNonProgressRounds: number;
|
|
42
|
+
/** A round needs at least this long to be worth starting. Defaults to `MIN_ROUND_MS`. */
|
|
43
|
+
minRoundMs?: number;
|
|
44
|
+
}
|
|
45
|
+
export type CompletionOutcome = "satisfied" | "stalled" | "wall_clock" | "step_budget" | "blocked" | "aborted";
|
|
46
|
+
export type ContinueKind = "fix" | "nochange" | "audit";
|
|
47
|
+
export interface CompletionRound {
|
|
48
|
+
round: number;
|
|
49
|
+
kind: ContinueKind;
|
|
50
|
+
/** Names of every check the probe ran this round; empty when the workspace was unchanged or the repo declares none. */
|
|
51
|
+
checksRun: string[];
|
|
52
|
+
checksFailed: string[];
|
|
53
|
+
changed: boolean;
|
|
54
|
+
/** Parsed from the model's MOUSE_AUDIT block before this round, if any. */
|
|
55
|
+
audit: ModelAudit | null;
|
|
56
|
+
progressed: boolean;
|
|
57
|
+
stepsAfter: number;
|
|
58
|
+
elapsedMs: number;
|
|
59
|
+
model: string;
|
|
60
|
+
}
|
|
61
|
+
export interface CompletionResult {
|
|
62
|
+
outcome: CompletionOutcome;
|
|
63
|
+
rounds: CompletionRound[];
|
|
64
|
+
totalSteps: number;
|
|
65
|
+
state: TaskState;
|
|
66
|
+
}
|
|
67
|
+
export interface ModelAudit {
|
|
68
|
+
done: string[];
|
|
69
|
+
todo: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface RunCompletionLoopInput {
|
|
72
|
+
probe: CompletionProbe;
|
|
73
|
+
engine: Pick<Engine, "prompt">;
|
|
74
|
+
/** Session the first turn ran in; every continue prompt goes to it. */
|
|
75
|
+
sessionId: string;
|
|
76
|
+
/** Model the session runs; `escalate` may replace it. */
|
|
77
|
+
model: string;
|
|
78
|
+
signal: AbortSignal;
|
|
79
|
+
instruction: string;
|
|
80
|
+
onEvent?: (e: LoopEvent) => void | Promise<void>;
|
|
81
|
+
budget: CompletionBudget;
|
|
82
|
+
/** Epoch ms when the task started (the first turn counts against the clock). */
|
|
83
|
+
startedAt: number;
|
|
84
|
+
/** Probe fingerprint taken before the first turn. */
|
|
85
|
+
initialFingerprint: string;
|
|
86
|
+
/** Total model steps so far, engine-tracked. */
|
|
87
|
+
steps: () => number;
|
|
88
|
+
/** Final assistant text of the most recent turn. */
|
|
89
|
+
lastAssistantText: () => string;
|
|
90
|
+
/** Optional model ladder: after repeated non-progress, return a model id to switch to. */
|
|
91
|
+
escalate?: (nonProgressRounds: number) => Promise<string | null>;
|
|
92
|
+
onRound?: (round: CompletionRound) => void | Promise<void>;
|
|
93
|
+
now?: () => number;
|
|
94
|
+
}
|
|
95
|
+
/** A round needs at least this long to be worth starting. */
|
|
96
|
+
export declare const MIN_ROUND_MS = 60000;
|
|
97
|
+
/** The `escalate` callback is consulted once this many consecutive rounds made no progress. */
|
|
98
|
+
export declare const ESCALATE_AFTER_NON_PROGRESS_ROUNDS = 2;
|
|
99
|
+
/** Check output kept for the model and the trace; the tail is what carries the failure. */
|
|
100
|
+
export declare const EXCERPT_MAX_CHARS = 1500;
|
|
101
|
+
export declare const AUDIT_OPEN = "MOUSE_AUDIT";
|
|
102
|
+
export declare const AUDIT_CLOSE = "END_MOUSE_AUDIT";
|
|
103
|
+
/**
|
|
104
|
+
* Parse the model's self-audit. Format, one line per requirement:
|
|
105
|
+
* MOUSE_AUDIT
|
|
106
|
+
* - [done] <requirement>: <evidence>
|
|
107
|
+
* - [todo] <requirement>: <what is missing>
|
|
108
|
+
* END_MOUSE_AUDIT
|
|
109
|
+
* `[x]` / `[ ]` are accepted as done / todo. Returns null without a block.
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseAuditBlock(text: string): ModelAudit | null;
|
|
112
|
+
export declare function buildContinuePrompt(kind: ContinueKind, ctx: {
|
|
113
|
+
instruction: string;
|
|
114
|
+
state: TaskState;
|
|
115
|
+
failed: CheckResult[];
|
|
116
|
+
audit: ModelAudit | null;
|
|
117
|
+
}): string;
|
|
118
|
+
export declare function runCompletionLoop(input: RunCompletionLoopInput): Promise<CompletionResult>;
|
|
119
|
+
//# sourceMappingURL=loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAoD,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAE5F,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,uCAAuC;IACvC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,MAAM,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACjC,oEAAoE;IACpE,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/B,iEAAiE;IACjE,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;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} from "./mea.js";
|
|
2
|
+
/** A round needs at least this long to be worth starting. */
|
|
3
|
+
export const MIN_ROUND_MS = 60_000;
|
|
4
|
+
/** The `escalate` callback is consulted once this many consecutive rounds made no progress. */
|
|
5
|
+
export const ESCALATE_AFTER_NON_PROGRESS_ROUNDS = 2;
|
|
6
|
+
const INSTRUCTION_MAX_CHARS = 6_000;
|
|
7
|
+
/** Check output kept for the model and the trace; the tail is what carries the failure. */
|
|
8
|
+
export const EXCERPT_MAX_CHARS = 1_500;
|
|
9
|
+
export const AUDIT_OPEN = "MOUSE_AUDIT";
|
|
10
|
+
export const AUDIT_CLOSE = "END_MOUSE_AUDIT";
|
|
11
|
+
/**
|
|
12
|
+
* Parse the model's self-audit. Format, one line per requirement:
|
|
13
|
+
* MOUSE_AUDIT
|
|
14
|
+
* - [done] <requirement>: <evidence>
|
|
15
|
+
* - [todo] <requirement>: <what is missing>
|
|
16
|
+
* END_MOUSE_AUDIT
|
|
17
|
+
* `[x]` / `[ ]` are accepted as done / todo. Returns null without a block.
|
|
18
|
+
*/
|
|
19
|
+
export function parseAuditBlock(text) {
|
|
20
|
+
// The opener is a substring of the closer, so walk back past any
|
|
21
|
+
// `END_MOUSE_AUDIT` to the last real opener.
|
|
22
|
+
let open = text.lastIndexOf(AUDIT_OPEN);
|
|
23
|
+
while (open > 0 && text.startsWith(AUDIT_CLOSE, open - "END_".length)) {
|
|
24
|
+
open = text.lastIndexOf(AUDIT_OPEN, open - 1);
|
|
25
|
+
}
|
|
26
|
+
if (open < 0)
|
|
27
|
+
return null;
|
|
28
|
+
const closeAt = text.indexOf(AUDIT_CLOSE, open + AUDIT_OPEN.length);
|
|
29
|
+
const body = text.slice(open + AUDIT_OPEN.length, closeAt < 0 ? undefined : closeAt);
|
|
30
|
+
const done = [];
|
|
31
|
+
const todo = [];
|
|
32
|
+
for (const raw of body.split("\n")) {
|
|
33
|
+
const m = /^\s*[-*]\s*\[(done|todo|x|X| )\]\s*(.*)$/.exec(raw);
|
|
34
|
+
if (!m)
|
|
35
|
+
continue;
|
|
36
|
+
const item = m[2].trim();
|
|
37
|
+
if (m[1] === "done" || m[1] === "x" || m[1] === "X")
|
|
38
|
+
done.push(item);
|
|
39
|
+
else
|
|
40
|
+
todo.push(item);
|
|
41
|
+
}
|
|
42
|
+
if (done.length === 0 && todo.length === 0)
|
|
43
|
+
return null;
|
|
44
|
+
return { done, todo };
|
|
45
|
+
}
|
|
46
|
+
function auditFooter() {
|
|
47
|
+
return [
|
|
48
|
+
"When you are finished, end your reply with an audit of the original task, one line per requirement, in exactly this form:",
|
|
49
|
+
AUDIT_OPEN,
|
|
50
|
+
"- [done] <requirement>: <the file, test, or command output that proves it>",
|
|
51
|
+
"- [todo] <requirement>: <what is still missing>",
|
|
52
|
+
AUDIT_CLOSE,
|
|
53
|
+
"Mark a requirement done only with evidence you produced in this workspace.",
|
|
54
|
+
].join("\n");
|
|
55
|
+
}
|
|
56
|
+
function requirementLines(state) {
|
|
57
|
+
return state.requirements.map((r) => `- ${r.text}`);
|
|
58
|
+
}
|
|
59
|
+
export function buildContinuePrompt(kind, ctx) {
|
|
60
|
+
const lines = [];
|
|
61
|
+
if (kind === "fix") {
|
|
62
|
+
lines.push("Verification failed after your changes.", "");
|
|
63
|
+
for (const c of ctx.failed) {
|
|
64
|
+
lines.push(`Check \`${c.name}\` (\`${c.command}\`) ${c.exitCode == null ? "timed out" : `exited ${c.exitCode}`}:`, "```", c.excerpt.slice(-EXCERPT_MAX_CHARS), "```", "");
|
|
65
|
+
}
|
|
66
|
+
lines.push("Continue working on the task. Do not stop until these checks pass and every requirement below is done. Never weaken, skip, or delete tests to make them pass.");
|
|
67
|
+
}
|
|
68
|
+
else if (kind === "nochange") {
|
|
69
|
+
lines.push("No files in the workspace have changed, so the task is not done. Read the task again, then implement it here. If the task only requires producing files or output, produce them now.");
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
lines.push("Before finishing, verify the task is complete. Re-read each requirement below and confirm it is implemented and checked in this workspace. If anything is missing, untested, or only partially done, do it now.");
|
|
73
|
+
if (ctx.audit && ctx.audit.todo.length > 0) {
|
|
74
|
+
lines.push("", "You previously listed these as not done:");
|
|
75
|
+
for (const t of ctx.audit.todo)
|
|
76
|
+
lines.push(`- ${t}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
lines.push("", "## Requirements", ...requirementLines(ctx.state));
|
|
80
|
+
lines.push("", "## Original task", ctx.instruction.slice(0, INSTRUCTION_MAX_CHARS));
|
|
81
|
+
lines.push("", auditFooter());
|
|
82
|
+
return lines.join("\n");
|
|
83
|
+
}
|
|
84
|
+
export async function runCompletionLoop(input) {
|
|
85
|
+
const now = input.now ?? Date.now;
|
|
86
|
+
const { probe, budget, signal } = input;
|
|
87
|
+
const onEvent = input.onEvent ?? (() => { });
|
|
88
|
+
let state = initTaskState(input.instruction);
|
|
89
|
+
const targets = state.requirements.map((r) => r.id);
|
|
90
|
+
const rounds = [];
|
|
91
|
+
let nonProgress = 0;
|
|
92
|
+
let model = input.model;
|
|
93
|
+
const finish = (outcome) => ({
|
|
94
|
+
outcome,
|
|
95
|
+
rounds,
|
|
96
|
+
totalSteps: input.steps(),
|
|
97
|
+
state,
|
|
98
|
+
});
|
|
99
|
+
for (let round = 1;; round++) {
|
|
100
|
+
if (signal.aborted)
|
|
101
|
+
return finish("aborted");
|
|
102
|
+
const elapsed = now() - input.startedAt;
|
|
103
|
+
if (elapsed >= budget.maxWallMs)
|
|
104
|
+
return finish("wall_clock");
|
|
105
|
+
if (input.steps() >= budget.maxTotalSteps)
|
|
106
|
+
return finish("step_budget");
|
|
107
|
+
const fp = await probe.fingerprint();
|
|
108
|
+
const changed = fp !== input.initialFingerprint;
|
|
109
|
+
const checks = changed ? await probe.checks() : [];
|
|
110
|
+
const tampering = changed ? await probe.tampering() : [];
|
|
111
|
+
for (const c of checks) {
|
|
112
|
+
await onEvent({
|
|
113
|
+
type: "check_status",
|
|
114
|
+
name: c.name,
|
|
115
|
+
conclusion: c.pass ? "success" : "failure",
|
|
116
|
+
...(c.pass ? {} : { detail: c.excerpt.slice(-EXCERPT_MAX_CHARS), retryable: true }),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (tampering.length > 0) {
|
|
120
|
+
await onEvent({
|
|
121
|
+
type: "notice",
|
|
122
|
+
message: `Verification files were deleted: ${tampering.slice(0, 5).join(", ")}`,
|
|
123
|
+
level: "warn",
|
|
124
|
+
});
|
|
125
|
+
return finish("blocked");
|
|
126
|
+
}
|
|
127
|
+
const audit = auditFromSandboxProbe({
|
|
128
|
+
state,
|
|
129
|
+
contractTargets: targets,
|
|
130
|
+
workspaceChanged: changed,
|
|
131
|
+
checks,
|
|
132
|
+
tampering,
|
|
133
|
+
});
|
|
134
|
+
state = applyAudit(state, audit);
|
|
135
|
+
const failed = checks.filter((c) => !c.pass);
|
|
136
|
+
const modelAudit = parseAuditBlock(input.lastAssistantText());
|
|
137
|
+
if (changed && failed.length === 0 && modelAudit && modelAudit.todo.length === 0) {
|
|
138
|
+
return finish("satisfied");
|
|
139
|
+
}
|
|
140
|
+
const kind = !changed ? "nochange" : failed.length > 0 ? "fix" : "audit";
|
|
141
|
+
if (budget.maxWallMs - elapsed < (budget.minRoundMs ?? MIN_ROUND_MS))
|
|
142
|
+
return finish("wall_clock");
|
|
143
|
+
if (nonProgress >= ESCALATE_AFTER_NON_PROGRESS_ROUNDS && input.escalate) {
|
|
144
|
+
const next = await input.escalate(nonProgress);
|
|
145
|
+
if (next)
|
|
146
|
+
model = next;
|
|
147
|
+
}
|
|
148
|
+
const prompt = buildContinuePrompt(kind, {
|
|
149
|
+
instruction: input.instruction,
|
|
150
|
+
state,
|
|
151
|
+
failed,
|
|
152
|
+
audit: modelAudit,
|
|
153
|
+
});
|
|
154
|
+
try {
|
|
155
|
+
await input.engine.prompt(input.sessionId, prompt, signal, { model });
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
if (e?.name === "AbortError" || signal.aborted)
|
|
159
|
+
return finish("aborted");
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
const after = await probe.fingerprint();
|
|
163
|
+
const progressed = after !== fp;
|
|
164
|
+
nonProgress = progressed ? 0 : nonProgress + 1;
|
|
165
|
+
const record = {
|
|
166
|
+
round,
|
|
167
|
+
kind,
|
|
168
|
+
checksRun: checks.map((c) => c.name),
|
|
169
|
+
checksFailed: failed.map((c) => c.name),
|
|
170
|
+
changed,
|
|
171
|
+
audit: modelAudit,
|
|
172
|
+
progressed,
|
|
173
|
+
stepsAfter: input.steps(),
|
|
174
|
+
elapsedMs: now() - input.startedAt,
|
|
175
|
+
model,
|
|
176
|
+
};
|
|
177
|
+
rounds.push(record);
|
|
178
|
+
await input.onRound?.(record);
|
|
179
|
+
// An audit round that edits nothing but reports everything done is not a
|
|
180
|
+
// stall: the next iteration exits satisfied. Only repeated rounds that
|
|
181
|
+
// neither edit nor claim completion count.
|
|
182
|
+
const claimedDone = parseAuditBlock(input.lastAssistantText());
|
|
183
|
+
if (!progressed && claimedDone && claimedDone.todo.length === 0 && failed.length === 0) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (nonProgress >= budget.maxNonProgressRounds)
|
|
187
|
+
return finish("stalled");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=loop.js.map
|
package/dist/loop.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop.js","sourceRoot":"","sources":["../src/loop.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,aAAa,EAAkB,MAAM,UAAU,CAAC;AA0F5F,6DAA6D;AAC7D,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AACnC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,CAAC;AACpD,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,2FAA2F;AAC3F,MAAM,CAAC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L,IAAI;YACJ,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YACpC,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YACvC,OAAO;YACP,KAAK,EAAE,UAAU;YACjB,UAAU;YACV,UAAU,EAAE,KAAK,CAAC,KAAK,EAAE;YACzB,SAAS,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS;YAClC,KAAK;SACN,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpB,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;QAE9B,yEAAyE;QACzE,uEAAuE;QACvE,2CAA2C;QAC3C,MAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,UAAU,IAAI,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvF,SAAS;QACX,CAAC;QACD,IAAI,WAAW,IAAI,MAAM,CAAC,oBAAoB;YAAE,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
|
package/dist/mea.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task-state bookkeeping for the completion loop, after the Manage, Execute,
|
|
3
|
+
* Audit design in LongHorizon-Harness (arXiv:2608.01964): the state lives
|
|
4
|
+
* outside the model, and a requirement advances only on evidence the
|
|
5
|
+
* environment produced (a changed workspace, a passing check, a clean tamper
|
|
6
|
+
* scan), never on what the model said.
|
|
7
|
+
*
|
|
8
|
+
* `initTaskState` splits the instruction into requirement records,
|
|
9
|
+
* `auditFromSandboxProbe` turns one round of probe evidence into an
|
|
10
|
+
* `AuditReport`, and `applyAudit` folds that report into the state. The loop
|
|
11
|
+
* in `loop.ts` calls the three in that order every round.
|
|
12
|
+
*/
|
|
13
|
+
export type RecordStatus = "pending" | "completed" | "blocked" | "untrusted";
|
|
14
|
+
export type TaskRequirement = {
|
|
15
|
+
id: string;
|
|
16
|
+
text: string;
|
|
17
|
+
status: RecordStatus;
|
|
18
|
+
/** Audit evidence ids or short excerpts supporting status. */
|
|
19
|
+
evidenceRefs: string[];
|
|
20
|
+
};
|
|
21
|
+
export type TaskArtifact = {
|
|
22
|
+
id: string;
|
|
23
|
+
path: string;
|
|
24
|
+
status: RecordStatus;
|
|
25
|
+
evidenceRefs: string[];
|
|
26
|
+
};
|
|
27
|
+
export type TaskFact = {
|
|
28
|
+
id: string;
|
|
29
|
+
text: string;
|
|
30
|
+
status: RecordStatus;
|
|
31
|
+
evidenceRefs: string[];
|
|
32
|
+
};
|
|
33
|
+
export type TaskState = {
|
|
34
|
+
objective: string;
|
|
35
|
+
requirements: TaskRequirement[];
|
|
36
|
+
artifacts: TaskArtifact[];
|
|
37
|
+
facts: TaskFact[];
|
|
38
|
+
round: number;
|
|
39
|
+
};
|
|
40
|
+
export type AuditCompletion = "complete" | "incomplete" | "blocked";
|
|
41
|
+
export type AuditIntegrity = "clean" | "suspect" | "violation";
|
|
42
|
+
export type AuditReport = {
|
|
43
|
+
completion: AuditCompletion;
|
|
44
|
+
integrity: AuditIntegrity;
|
|
45
|
+
/** Requirement ids the auditor marks completed (only when integrity=clean). */
|
|
46
|
+
completedRequirementIds: string[];
|
|
47
|
+
/** Requirement ids still unmet. */
|
|
48
|
+
unmetRequirementIds: string[];
|
|
49
|
+
facts: {
|
|
50
|
+
text: string;
|
|
51
|
+
evidenceRef: string;
|
|
52
|
+
}[];
|
|
53
|
+
gaps: string[];
|
|
54
|
+
summary: string;
|
|
55
|
+
};
|
|
56
|
+
/** Split an objective into coarse pending requirements (heuristic manager). */
|
|
57
|
+
export declare function initTaskState(objective: string): TaskState;
|
|
58
|
+
/**
|
|
59
|
+
* Apply an audit report. Executor claims never call this — only auditor
|
|
60
|
+
* output. Completed marks require integrity=clean.
|
|
61
|
+
*/
|
|
62
|
+
export declare function applyAudit(state: TaskState, audit: AuditReport): TaskState;
|
|
63
|
+
/**
|
|
64
|
+
* One round of probe evidence as an audit report: the workspace changed,
|
|
65
|
+
* every declared check passed, and nothing that grades the work was deleted.
|
|
66
|
+
* `checks` are the repository's detected or declared checks; `tampering`
|
|
67
|
+
* lists verification files deleted since the run started.
|
|
68
|
+
*/
|
|
69
|
+
export declare function auditFromSandboxProbe(input: {
|
|
70
|
+
state: TaskState;
|
|
71
|
+
contractTargets: string[];
|
|
72
|
+
workspaceChanged: boolean;
|
|
73
|
+
checks?: ReadonlyArray<{
|
|
74
|
+
name: string;
|
|
75
|
+
pass: boolean;
|
|
76
|
+
exitCode: number | null;
|
|
77
|
+
}>;
|
|
78
|
+
tampering?: readonly string[];
|
|
79
|
+
}): AuditReport;
|
|
80
|
+
//# sourceMappingURL=mea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mea.d.ts","sourceRoot":"","sources":["../src/mea.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAE7E,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,8DAA8D;IAC9D,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACr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E,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACjF,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B,GAAG,WAAW,CAwEd"}
|
package/dist/mea.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task-state bookkeeping for the completion loop, after the Manage, Execute,
|
|
3
|
+
* Audit design in LongHorizon-Harness (arXiv:2608.01964): the state lives
|
|
4
|
+
* outside the model, and a requirement advances only on evidence the
|
|
5
|
+
* environment produced (a changed workspace, a passing check, a clean tamper
|
|
6
|
+
* scan), never on what the model said.
|
|
7
|
+
*
|
|
8
|
+
* `initTaskState` splits the instruction into requirement records,
|
|
9
|
+
* `auditFromSandboxProbe` turns one round of probe evidence into an
|
|
10
|
+
* `AuditReport`, and `applyAudit` folds that report into the state. The loop
|
|
11
|
+
* in `loop.ts` calls the three in that order every round.
|
|
12
|
+
*/
|
|
13
|
+
/** Split an objective into coarse pending requirements (heuristic manager). */
|
|
14
|
+
export function initTaskState(objective) {
|
|
15
|
+
const trimmed = objective.trim();
|
|
16
|
+
const chunks = trimmed
|
|
17
|
+
.split(/(?:^|\n)\s*(?:\d+[.)]\s+|[-*]\s+)/)
|
|
18
|
+
.map((s) => s.trim())
|
|
19
|
+
.filter((s) => s.length > 8);
|
|
20
|
+
const requirementTexts = chunks.length >= 2
|
|
21
|
+
? chunks.slice(0, 8)
|
|
22
|
+
: [
|
|
23
|
+
trimmed.slice(0, 500),
|
|
24
|
+
"Hard gates pass: build, tests, lint, and no verification tampering.",
|
|
25
|
+
"Changes are committed and reviewable (focused diff, clear commit message).",
|
|
26
|
+
];
|
|
27
|
+
return {
|
|
28
|
+
objective: trimmed,
|
|
29
|
+
requirements: requirementTexts.map((text, i) => ({
|
|
30
|
+
id: `req_${i + 1}`,
|
|
31
|
+
text,
|
|
32
|
+
status: "pending",
|
|
33
|
+
evidenceRefs: [],
|
|
34
|
+
})),
|
|
35
|
+
artifacts: [],
|
|
36
|
+
facts: [],
|
|
37
|
+
round: 0,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Apply an audit report. Executor claims never call this — only auditor
|
|
42
|
+
* output. Completed marks require integrity=clean.
|
|
43
|
+
*/
|
|
44
|
+
export function applyAudit(state, audit) {
|
|
45
|
+
const completed = new Set(audit.integrity === "clean" ? audit.completedRequirementIds : []);
|
|
46
|
+
const unmet = new Set(audit.unmetRequirementIds);
|
|
47
|
+
const blocked = audit.completion === "blocked";
|
|
48
|
+
const requirements = state.requirements.map((r) => {
|
|
49
|
+
if (completed.has(r.id)) {
|
|
50
|
+
return {
|
|
51
|
+
...r,
|
|
52
|
+
status: "completed",
|
|
53
|
+
evidenceRefs: [...r.evidenceRefs, ...audit.facts.map((f) => f.evidenceRef)].slice(0, 8),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (audit.integrity === "violation") {
|
|
57
|
+
return { ...r, status: "untrusted" };
|
|
58
|
+
}
|
|
59
|
+
if (blocked && unmet.has(r.id)) {
|
|
60
|
+
return { ...r, status: "blocked" };
|
|
61
|
+
}
|
|
62
|
+
if (unmet.has(r.id) && r.status === "completed") {
|
|
63
|
+
// Auditor contradicts a prior completion — demote.
|
|
64
|
+
return { ...r, status: "untrusted" };
|
|
65
|
+
}
|
|
66
|
+
return r;
|
|
67
|
+
});
|
|
68
|
+
const newFacts = audit.facts.map((f, i) => ({
|
|
69
|
+
id: `fact_${state.round}_${i + 1}`,
|
|
70
|
+
text: f.text,
|
|
71
|
+
status: audit.integrity === "violation" ? "untrusted" : "completed",
|
|
72
|
+
evidenceRefs: [f.evidenceRef],
|
|
73
|
+
}));
|
|
74
|
+
return {
|
|
75
|
+
...state,
|
|
76
|
+
requirements,
|
|
77
|
+
facts: [...state.facts, ...newFacts].slice(-40),
|
|
78
|
+
round: state.round + 1,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One round of probe evidence as an audit report: the workspace changed,
|
|
83
|
+
* every declared check passed, and nothing that grades the work was deleted.
|
|
84
|
+
* `checks` are the repository's detected or declared checks; `tampering`
|
|
85
|
+
* lists verification files deleted since the run started.
|
|
86
|
+
*/
|
|
87
|
+
export function auditFromSandboxProbe(input) {
|
|
88
|
+
const facts = [
|
|
89
|
+
{
|
|
90
|
+
text: `workspace ${input.workspaceChanged ? "changed" : "unchanged"} since the run started`,
|
|
91
|
+
evidenceRef: "fingerprint",
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
const checks = input.checks ?? [];
|
|
95
|
+
for (const c of checks) {
|
|
96
|
+
facts.push({
|
|
97
|
+
text: `check ${c.name}: ${c.pass ? "pass" : `fail (exit ${c.exitCode ?? "timeout"})`}`,
|
|
98
|
+
evidenceRef: `check:${c.name}`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const tampering = input.tampering ?? [];
|
|
102
|
+
if (tampering.length > 0) {
|
|
103
|
+
facts.push({
|
|
104
|
+
text: `Verification tampering: ${tampering.slice(0, 5).join(", ")}`,
|
|
105
|
+
evidenceRef: "verification_tampering",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const integrity = tampering.length > 0 ? "violation" : "clean";
|
|
109
|
+
const failedChecks = checks.filter((c) => !c.pass).map((c) => c.name);
|
|
110
|
+
const checksOk = failedChecks.length === 0;
|
|
111
|
+
const passes = input.workspaceChanged && checksOk && integrity === "clean";
|
|
112
|
+
const completedRequirementIds = [];
|
|
113
|
+
const unmetRequirementIds = [];
|
|
114
|
+
const gaps = [];
|
|
115
|
+
for (const id of input.contractTargets) {
|
|
116
|
+
if (passes)
|
|
117
|
+
completedRequirementIds.push(id);
|
|
118
|
+
else {
|
|
119
|
+
unmetRequirementIds.push(id);
|
|
120
|
+
if (!input.workspaceChanged)
|
|
121
|
+
gaps.push("Workspace unchanged since the run started.");
|
|
122
|
+
if (!checksOk)
|
|
123
|
+
gaps.push(`Checks failed: ${failedChecks.join(", ")}.`);
|
|
124
|
+
if (integrity !== "clean")
|
|
125
|
+
gaps.push("Verification files were deleted.");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Also advance matching heuristic requirements when change+checks hold.
|
|
129
|
+
if (passes) {
|
|
130
|
+
for (const r of input.state.requirements) {
|
|
131
|
+
if (r.status === "pending" && /commit|hard gates|build|tests/i.test(r.text)) {
|
|
132
|
+
completedRequirementIds.push(r.id);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const completion = integrity === "violation"
|
|
137
|
+
? "blocked"
|
|
138
|
+
: completedRequirementIds.length > 0 && unmetRequirementIds.length === 0
|
|
139
|
+
? "complete"
|
|
140
|
+
: "incomplete";
|
|
141
|
+
const passedNames = checks.filter((c) => c.pass).map((c) => c.name);
|
|
142
|
+
return {
|
|
143
|
+
completion,
|
|
144
|
+
integrity,
|
|
145
|
+
completedRequirementIds: [...new Set(completedRequirementIds)],
|
|
146
|
+
unmetRequirementIds: [...new Set(unmetRequirementIds)],
|
|
147
|
+
facts,
|
|
148
|
+
gaps: [...new Set(gaps)],
|
|
149
|
+
summary: completion === "complete"
|
|
150
|
+
? passedNames.length > 0
|
|
151
|
+
? `Sandbox audit: workspace changed; ${passedNames.join(", ")} passed.`
|
|
152
|
+
: "Sandbox audit: workspace changed; no checks to run."
|
|
153
|
+
: `Sandbox audit incomplete: ${[...new Set(gaps)].join(" ") || "criteria unmet"}`,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=mea.js.map
|
package/dist/mea.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mea.js","sourceRoot":"","sources":["../src/mea.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAiDH,+EAA+E;AAC/E,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C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odeJS.ProcessEnv): string;
|
|
2
|
+
/** `/Users/me/repo` becomes `--Users-me-repo--`, the same scheme pi uses. */
|
|
3
|
+
export declare function workspaceSlug(cwd: string): string;
|
|
4
|
+
export declare function runsDir(cwd: string, env?: NodeJS.ProcessEnv): string;
|
|
5
|
+
/** A fresh trace path for a run starting now. */
|
|
6
|
+
export declare function traceFile(cwd: string, env?: NodeJS.ProcessEnv, now?: Date): string;
|
|
7
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAQA,wBAAgB,SAAS,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAEtE;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAEjF;AAED,iDAAiD;AACjD,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,GAAG,OAAa,GACf,MAAM,CAGR"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where Mouse keeps its own state: `~/.mouse/runs/--<cwd>--/`. Nothing is
|
|
3
|
+
* ever written into the user's repository; `.mouse/` there holds only
|
|
4
|
+
* user-authored policy.
|
|
5
|
+
*/
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
export function mouseHome(env = process.env) {
|
|
9
|
+
return env.MOUSE_HOME?.trim() || path.join(homedir(), ".mouse");
|
|
10
|
+
}
|
|
11
|
+
/** `/Users/me/repo` becomes `--Users-me-repo--`, the same scheme pi uses. */
|
|
12
|
+
export function workspaceSlug(cwd) {
|
|
13
|
+
const abs = path
|
|
14
|
+
.resolve(cwd)
|
|
15
|
+
.replace(/[/\\:]+/g, "-")
|
|
16
|
+
.replace(/^-+|-+$/g, "");
|
|
17
|
+
return `--${abs || "root"}--`;
|
|
18
|
+
}
|
|
19
|
+
export function runsDir(cwd, env = process.env) {
|
|
20
|
+
return path.join(mouseHome(env), "runs", workspaceSlug(cwd));
|
|
21
|
+
}
|
|
22
|
+
/** A fresh trace path for a run starting now. */
|
|
23
|
+
export function traceFile(cwd, env = process.env, now = new Date()) {
|
|
24
|
+
const stamp = now.toISOString().replace(/[:.]/g, "-");
|
|
25
|
+
return path.join(runsDir(cwd, env), `${stamp}-${process.pid}.jsonl`);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,UAAU,SAAS,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC5D,OAAO,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,GAAG,GAAG,IAAI;SACb,OAAO,CAAC,GAAG,CAAC;SACZ,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC3B,OAAO,KAAK,GAAG,IAAI,MAAM,IAAI,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,GAAG,GAAsB,OAAO,CAAC,GAAG;IACvE,OAAO,IAAI,CAAC,IAAI,CAAC,SAA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