@farmslot/agent-runtime 0.48.1 → 0.48.3
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/CHANGELOG.md +19 -0
- package/dist/task-init/required-skills.js +1 -1
- package/dist/task-init/required-skills.js.map +1 -1
- package/dist/task-init/task-document.d.ts +13 -0
- package/dist/task-init/task-document.d.ts.map +1 -1
- package/dist/task-init/task-document.js +20 -2
- package/dist/task-init/task-document.js.map +1 -1
- package/dist/task-init/write.d.ts.map +1 -1
- package/dist/task-init/write.js +12 -2
- package/dist/task-init/write.js.map +1 -1
- package/dist/tool-usage/adapters/claude.d.ts +3 -0
- package/dist/tool-usage/adapters/claude.d.ts.map +1 -0
- package/dist/tool-usage/adapters/claude.js +56 -0
- package/dist/tool-usage/adapters/claude.js.map +1 -0
- package/dist/tool-usage/adapters/codex.d.ts +3 -0
- package/dist/tool-usage/adapters/codex.d.ts.map +1 -0
- package/dist/tool-usage/adapters/codex.js +81 -0
- package/dist/tool-usage/adapters/codex.js.map +1 -0
- package/dist/tool-usage/adapters/cursor.d.ts +3 -0
- package/dist/tool-usage/adapters/cursor.d.ts.map +1 -0
- package/dist/tool-usage/adapters/cursor.js +47 -0
- package/dist/tool-usage/adapters/cursor.js.map +1 -0
- package/dist/tool-usage/adapters/grok.d.ts +3 -0
- package/dist/tool-usage/adapters/grok.d.ts.map +1 -0
- package/dist/tool-usage/adapters/grok.js +55 -0
- package/dist/tool-usage/adapters/grok.js.map +1 -0
- package/dist/tool-usage/adapters/jsonl.d.ts +9 -0
- package/dist/tool-usage/adapters/jsonl.d.ts.map +1 -0
- package/dist/tool-usage/adapters/jsonl.js +40 -0
- package/dist/tool-usage/adapters/jsonl.js.map +1 -0
- package/dist/tool-usage/adapters/native.d.ts +3 -0
- package/dist/tool-usage/adapters/native.d.ts.map +1 -0
- package/dist/tool-usage/adapters/native.js +31 -0
- package/dist/tool-usage/adapters/native.js.map +1 -0
- package/dist/tool-usage/adapters/pi.d.ts +3 -0
- package/dist/tool-usage/adapters/pi.d.ts.map +1 -0
- package/dist/tool-usage/adapters/pi.js +46 -0
- package/dist/tool-usage/adapters/pi.js.map +1 -0
- package/dist/tool-usage/count.d.ts +13 -0
- package/dist/tool-usage/count.d.ts.map +1 -0
- package/dist/tool-usage/count.js +160 -0
- package/dist/tool-usage/count.js.map +1 -0
- package/dist/tool-usage/index.d.ts +19 -0
- package/dist/tool-usage/index.d.ts.map +1 -0
- package/dist/tool-usage/index.js +32 -0
- package/dist/tool-usage/index.js.map +1 -0
- package/dist/tool-usage/ledger.d.ts +11 -0
- package/dist/tool-usage/ledger.d.ts.map +1 -0
- package/dist/tool-usage/ledger.js +29 -0
- package/dist/tool-usage/ledger.js.map +1 -0
- package/dist/tool-usage/stream.d.ts +32 -0
- package/dist/tool-usage/stream.d.ts.map +1 -0
- package/dist/tool-usage/stream.js +17 -0
- package/dist/tool-usage/stream.js.map +1 -0
- package/package.json +10 -4
- package/scripts/check-task-artifact-contract.mjs +36 -0
- package/scripts/checklist-order.cjs +165 -0
- package/scripts/checklist-target.cjs +20 -0
- package/scripts/mark-checklist-step.cjs +294 -23
- package/scripts/proof-artifacts.cjs +258 -0
- package/scripts/subtask-unit.cjs +22 -1
- package/scripts/worker-terminal-contract.cjs +4 -6
|
@@ -14,6 +14,9 @@ const {
|
|
|
14
14
|
deterministicChecks,
|
|
15
15
|
} = require('./worker-terminal-contract.cjs');
|
|
16
16
|
const { SUBTASK_INDEX_REL, openSubtaskUnits } = require('./subtask-unit.cjs');
|
|
17
|
+
const proofArtifacts = require('./proof-artifacts.cjs');
|
|
18
|
+
const checklistOrder = require('./checklist-order.cjs');
|
|
19
|
+
const { resolveChecklistTarget } = require('./checklist-target.cjs');
|
|
17
20
|
const { acceptanceContractIssues, readAcceptanceLedger } = require('./acceptance-ledger.cjs');
|
|
18
21
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
19
22
|
const workspaceProtocolRoot = path.resolve(packageRoot, '../protocol');
|
|
@@ -94,6 +97,8 @@ const rawArgs = process.argv.slice(3);
|
|
|
94
97
|
const flags = new Set();
|
|
95
98
|
let contractPath;
|
|
96
99
|
let terminalCommand;
|
|
100
|
+
let proofChecklist;
|
|
101
|
+
let proofSignal;
|
|
97
102
|
for (let i = 0; i < rawArgs.length; i += 1) {
|
|
98
103
|
const arg = rawArgs[i];
|
|
99
104
|
if (arg === '--contract') {
|
|
@@ -106,6 +111,18 @@ for (let i = 0; i < rawArgs.length; i += 1) {
|
|
|
106
111
|
i += 1;
|
|
107
112
|
continue;
|
|
108
113
|
}
|
|
114
|
+
// The caller's selection, when it has one: `mark --checklist X --signal Y`
|
|
115
|
+
// completes X and keeps its claims in Y, which the manifest need not name.
|
|
116
|
+
if (arg === '--proof-checklist') {
|
|
117
|
+
proofChecklist = rawArgs[i + 1];
|
|
118
|
+
i += 1;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (arg === '--proof-signal') {
|
|
122
|
+
proofSignal = rawArgs[i + 1];
|
|
123
|
+
i += 1;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
109
126
|
flags.add(arg);
|
|
110
127
|
}
|
|
111
128
|
|
|
@@ -674,6 +691,25 @@ if (contractPath && terminalCommand && !existsSync(contractPath)) {
|
|
|
674
691
|
}
|
|
675
692
|
}
|
|
676
693
|
|
|
694
|
+
// A checked proof step must have the evidence it declared, written no later than
|
|
695
|
+
// the claim (proof-artifacts.cjs). A step that declares nothing is not inspected
|
|
696
|
+
// here, so a checklist without the marker reaches completion exactly as before.
|
|
697
|
+
if (terminalCommand !== 'blocked' && !proofMeasurement) {
|
|
698
|
+
try {
|
|
699
|
+
// Only the checklist that is completing: a reviewer finishing REVIEW.md
|
|
700
|
+
// answers for its own declarations, never for the worker's CHECKLIST.md,
|
|
701
|
+
// whose unproven steps are what the reviewer is reporting on. The caller's
|
|
702
|
+
// own selection wins over the manifest, which it may not have written.
|
|
703
|
+
const checklist = proofChecklist ?? resolveChecklistTarget(taskDir).checklist;
|
|
704
|
+
issues.push(...proofArtifacts.issues(taskDir, checklist, terminalContract, proofSignal));
|
|
705
|
+
// Steps are claimed in order, and only a step the template declared optional
|
|
706
|
+
// may be skipped. A checklist edited around the mark engine shows up here.
|
|
707
|
+
issues.push(...checklistOrder.issues(taskDir, checklist, terminalContract, proofSignal));
|
|
708
|
+
} catch (error) {
|
|
709
|
+
issues.push(`Proof declarations cannot be validated: ${error.message}`);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
677
713
|
const deterministicResults = [];
|
|
678
714
|
if (terminalCommand !== 'blocked') {
|
|
679
715
|
const checklists = new Set(
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Checklist order: a step is claimed after the ones before it, or not at all.
|
|
2
|
+
//
|
|
3
|
+
// A checked box records a claim, and a claim made out of order is not a smaller
|
|
4
|
+
// claim — it is a different one. Blind trial 40d98f79 marked step 13, the
|
|
5
|
+
// changed-file CI gate, while it was still on step 1, having applied a fix with
|
|
6
|
+
// no baseline behind it. Nothing refused that.
|
|
7
|
+
//
|
|
8
|
+
// `./mark N` now refuses while an earlier step is unchecked. The exception is
|
|
9
|
+
// declared in the template, never by the worker: a step whose title carries
|
|
10
|
+
//
|
|
11
|
+
// - [ ] 11. Exit early if already fixed or not reproduced [OPTIONAL: the bug still reproduces]
|
|
12
|
+
//
|
|
13
|
+
// may be skipped with `./mark 11 --skip "<reason>"`, which records the reason in
|
|
14
|
+
// the ledger beside the step. A step without that marker can never be skipped,
|
|
15
|
+
// and completion refuses a checklist with a gap in it.
|
|
16
|
+
//
|
|
17
|
+
// `[OPTIONAL:]` and `[DETERMINISTIC:]` on one row are refused: a step a command
|
|
18
|
+
// receipt proves cannot also be one the worker may declare inapplicable.
|
|
19
|
+
|
|
20
|
+
const fs = require('node:fs');
|
|
21
|
+
const path = require('node:path');
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
enumerateChecklistCheckboxes,
|
|
25
|
+
readFrozenTerminalContract,
|
|
26
|
+
signalFileForChecklist,
|
|
27
|
+
} = require('./checklist-target.cjs');
|
|
28
|
+
const { readJson } = require('./mark-io.cjs');
|
|
29
|
+
|
|
30
|
+
const OPTIONAL_REFERENCE = /\[OPTIONAL:\s*([^\]]+?)\s*\]/;
|
|
31
|
+
|
|
32
|
+
function optionalDeclarations(markdown, checklist) {
|
|
33
|
+
return enumerateChecklistCheckboxes(markdown).flatMap((item) => {
|
|
34
|
+
const match = item.rawLabel.match(OPTIONAL_REFERENCE);
|
|
35
|
+
if (!match && item.rawLabel.includes('[OPTIONAL'))
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Invalid optional declaration in ${checklist} step ${item.stepNumber}: ` +
|
|
38
|
+
'use [OPTIONAL: <when it does not apply>]',
|
|
39
|
+
);
|
|
40
|
+
// A deterministic step is verified by a command receipt, so "the worker may
|
|
41
|
+
// decide this one does not apply" and "a recorded command proves this one"
|
|
42
|
+
// are contradictory claims about the same row. Refusing the combination at
|
|
43
|
+
// the declaration keeps one answer per step instead of carrying a skip
|
|
44
|
+
// through every gate that wants the receipt (ADR-064 Amendment 7).
|
|
45
|
+
if (match && item.rawLabel.includes('[DETERMINISTIC'))
|
|
46
|
+
throw new Error(
|
|
47
|
+
`${checklist} step ${item.stepNumber} is declared both [OPTIONAL:] and ` +
|
|
48
|
+
'[DETERMINISTIC:]: a step proven by a command receipt cannot also be skippable. ' +
|
|
49
|
+
'Drop one marker, or split the row into the optional work and its check.',
|
|
50
|
+
);
|
|
51
|
+
return match ? [{ checklist, stepNumber: item.stepNumber, when: match[1].trim() }] : [];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Freeze the checklist's optional steps into the contract, as ADR-064 does for commands. */
|
|
56
|
+
function freezeOptionalSteps(contract, markdown, checklist) {
|
|
57
|
+
const steps = optionalDeclarations(markdown, checklist);
|
|
58
|
+
return steps.length ? { ...contract, optionalSteps: steps } : contract;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The optional steps the template granted, from the frozen contract only.
|
|
63
|
+
*
|
|
64
|
+
* Unlike a proof declaration, which a later row can only add to, optional is a
|
|
65
|
+
* privilege: honouring a marker found in the live checklist would let a worker
|
|
66
|
+
* refused at a step write `[OPTIONAL: ...]` on that row and skip it. The
|
|
67
|
+
* template declares the exception at init, never the worker (ADR-064
|
|
68
|
+
* Amendment 7), so a task whose contract predates the marker has no optional
|
|
69
|
+
* steps: it does the step, or stops with `mark blocked`.
|
|
70
|
+
*/
|
|
71
|
+
function declaredOptionalSteps(taskDir, checklist, contract) {
|
|
72
|
+
const steps = new Map();
|
|
73
|
+
for (const step of contract?.optionalSteps ?? []) {
|
|
74
|
+
if (step.checklist === checklist) steps.set(step.stepNumber, step.when);
|
|
75
|
+
}
|
|
76
|
+
return steps;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Steps the worker skipped, with the reason it recorded, from the ledger. */
|
|
80
|
+
function skippedSteps(taskDir, checklist, signalFile) {
|
|
81
|
+
const signal = readJson(path.join(taskDir, signalFile ?? signalFileForChecklist(checklist)));
|
|
82
|
+
const events = Array.isArray(signal?.checklistTiming?.events)
|
|
83
|
+
? signal.checklistTiming.events
|
|
84
|
+
: [];
|
|
85
|
+
const skipped = new Map();
|
|
86
|
+
for (const event of events) {
|
|
87
|
+
if (event?.skipped === true && typeof event.stepNumber === 'number')
|
|
88
|
+
skipped.set(event.stepNumber, typeof event.reason === 'string' ? event.reason : '');
|
|
89
|
+
}
|
|
90
|
+
return skipped;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Steps whose skip the template authorized and the worker recorded: the one
|
|
95
|
+
* definition of "this step is settled by its skip". The proof check asks here so
|
|
96
|
+
* a skip accepted at the mark is not refused for missing evidence at
|
|
97
|
+
* completion. Deterministic steps cannot be optional, so no receipt gate needs
|
|
98
|
+
* this.
|
|
99
|
+
*/
|
|
100
|
+
function authorizedSkips(taskDir, checklist, contract, signalFile) {
|
|
101
|
+
const optional = declaredOptionalSteps(
|
|
102
|
+
taskDir,
|
|
103
|
+
checklist,
|
|
104
|
+
contract ?? readFrozenTerminalContract(taskDir, checklist),
|
|
105
|
+
);
|
|
106
|
+
return new Set(
|
|
107
|
+
[...skippedSteps(taskDir, checklist, signalFile).keys()].filter((step) => optional.has(step)),
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function checklistItems(taskDir, checklist) {
|
|
112
|
+
const file = path.join(taskDir, checklist);
|
|
113
|
+
if (!fs.existsSync(file)) return [];
|
|
114
|
+
return enumerateChecklistCheckboxes(fs.readFileSync(file, 'utf8'));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The first step before `stepNumber` that is still unchecked, or null. A skipped
|
|
119
|
+
* step is checked, so it does not hold the next one back.
|
|
120
|
+
*/
|
|
121
|
+
function firstUnmarkedEarlierStep(items, stepNumber) {
|
|
122
|
+
return items.find((item) => item.stepNumber < stepNumber && !item.checked) ?? null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Completion issues: a gap, and a skip the template never allowed. The mark path
|
|
127
|
+
* refuses both as they happen; these catch a checklist edited around it.
|
|
128
|
+
*/
|
|
129
|
+
function orderIssues(taskDir, checklist, contract, signalFile) {
|
|
130
|
+
const items = checklistItems(taskDir, checklist);
|
|
131
|
+
const optional = declaredOptionalSteps(taskDir, checklist, contract);
|
|
132
|
+
const skipped = skippedSteps(taskDir, checklist, signalFile);
|
|
133
|
+
const issues = [];
|
|
134
|
+
const lastChecked = items.filter((item) => item.checked).pop();
|
|
135
|
+
if (lastChecked) {
|
|
136
|
+
for (const item of items) {
|
|
137
|
+
if (item.stepNumber >= lastChecked.stepNumber || item.checked) continue;
|
|
138
|
+
issues.push(
|
|
139
|
+
`${checklist} step ${item.stepNumber} is unchecked while step ${lastChecked.stepNumber} ` +
|
|
140
|
+
'is checked: steps are claimed in order, and an optional step is skipped with ' +
|
|
141
|
+
`\`./mark ${item.stepNumber} --skip "<reason>"\``,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
for (const [stepNumber, reason] of skipped) {
|
|
146
|
+
if (!optional.has(stepNumber))
|
|
147
|
+
issues.push(
|
|
148
|
+
`${checklist} step ${stepNumber} was skipped (${reason || 'no reason recorded'}) but the ` +
|
|
149
|
+
'template does not declare it optional',
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return issues;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
OPTIONAL_REFERENCE,
|
|
157
|
+
authorizedSkips,
|
|
158
|
+
declarations: optionalDeclarations,
|
|
159
|
+
freeze: freezeOptionalSteps,
|
|
160
|
+
declared: declaredOptionalSteps,
|
|
161
|
+
skipped: skippedSteps,
|
|
162
|
+
items: checklistItems,
|
|
163
|
+
firstUnmarkedEarlierStep,
|
|
164
|
+
issues: orderIssues,
|
|
165
|
+
};
|
|
@@ -129,6 +129,25 @@ function checklistStepName(rawLabel) {
|
|
|
129
129
|
return rawLabel.replace(/^\*\*(.+?)\*\*.*$/, '$1').trim();
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* The frozen terminal contract for a checklist: its own input when a role wrote
|
|
134
|
+
* one, else the task's root contract. Returns null when neither exists, and
|
|
135
|
+
* throws when one exists but cannot be read, so a caller can tell "no contract"
|
|
136
|
+
* from "unreadable contract" rather than treating a transient failure as a
|
|
137
|
+
* contract that grants nothing.
|
|
138
|
+
*/
|
|
139
|
+
function readFrozenTerminalContract(taskDir, checklist) {
|
|
140
|
+
for (const input of [
|
|
141
|
+
terminalContractInputForChecklist(checklist),
|
|
142
|
+
WORKER_TERMINAL_CONTRACT_INPUT,
|
|
143
|
+
]) {
|
|
144
|
+
const file = path.join(taskDir, input);
|
|
145
|
+
if (!fs.existsSync(file)) continue;
|
|
146
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
132
151
|
function signalFileForChecklist(checklistBasename) {
|
|
133
152
|
if (
|
|
134
153
|
checklistBasename === TASK_PROGRESS_MARKDOWN ||
|
|
@@ -369,6 +388,7 @@ module.exports = {
|
|
|
369
388
|
checklistTargetForAgentRole,
|
|
370
389
|
taskDirRelPath,
|
|
371
390
|
signalFileForChecklist,
|
|
391
|
+
readFrozenTerminalContract,
|
|
372
392
|
targetForChecklistBasename,
|
|
373
393
|
terminalContractInputForChecklist,
|
|
374
394
|
defaultWorkerTarget,
|