@farmslot/agent-runtime 0.48.0 → 0.48.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/native/claude.d.ts.map +1 -1
  3. package/dist/native/claude.js +1 -1
  4. package/dist/native/claude.js.map +1 -1
  5. package/dist/native/client.d.ts.map +1 -1
  6. package/dist/native/client.js +12 -1
  7. package/dist/native/client.js.map +1 -1
  8. package/dist/native/codex.d.ts.map +1 -1
  9. package/dist/native/codex.js +2 -1
  10. package/dist/native/codex.js.map +1 -1
  11. package/dist/native/conversation.d.ts +1 -1
  12. package/dist/native/conversation.d.ts.map +1 -1
  13. package/dist/native/conversation.js +1 -1
  14. package/dist/native/conversation.js.map +1 -1
  15. package/dist/native/ipc.d.ts +1 -1
  16. package/dist/native/ipc.d.ts.map +1 -1
  17. package/dist/native/ipc.js +1 -1
  18. package/dist/native/ipc.js.map +1 -1
  19. package/dist/native/manager.d.ts +1 -1
  20. package/dist/native/manager.d.ts.map +1 -1
  21. package/dist/native/manager.js +1 -1
  22. package/dist/native/manager.js.map +1 -1
  23. package/dist/native/observation.d.ts +7 -1
  24. package/dist/native/observation.d.ts.map +1 -1
  25. package/dist/native/observation.js +24 -7
  26. package/dist/native/observation.js.map +1 -1
  27. package/dist/native/pi.d.ts.map +1 -1
  28. package/dist/native/pi.js +1 -1
  29. package/dist/native/pi.js.map +1 -1
  30. package/dist/native/profile-service.d.ts.map +1 -1
  31. package/dist/native/profile-service.js +1 -1
  32. package/dist/native/profile-service.js.map +1 -1
  33. package/dist/native/registry.js +1 -1
  34. package/dist/native/registry.js.map +1 -1
  35. package/dist/native/service.d.ts +1 -1
  36. package/dist/native/service.d.ts.map +1 -1
  37. package/dist/native/service.js +2 -1
  38. package/dist/native/service.js.map +1 -1
  39. package/dist/native/supervisor.js +6 -2
  40. package/dist/native/supervisor.js.map +1 -1
  41. package/dist/task-init/required-skills.js +1 -1
  42. package/dist/task-init/required-skills.js.map +1 -1
  43. package/dist/task-init/task-document.d.ts.map +1 -1
  44. package/dist/task-init/task-document.js +1 -1
  45. package/dist/task-init/task-document.js.map +1 -1
  46. package/dist/task-init/write.d.ts.map +1 -1
  47. package/dist/task-init/write.js +12 -2
  48. package/dist/task-init/write.js.map +1 -1
  49. package/dist/tool-usage/adapters/claude.d.ts +3 -0
  50. package/dist/tool-usage/adapters/claude.d.ts.map +1 -0
  51. package/dist/tool-usage/adapters/claude.js +56 -0
  52. package/dist/tool-usage/adapters/claude.js.map +1 -0
  53. package/dist/tool-usage/adapters/codex.d.ts +3 -0
  54. package/dist/tool-usage/adapters/codex.d.ts.map +1 -0
  55. package/dist/tool-usage/adapters/codex.js +81 -0
  56. package/dist/tool-usage/adapters/codex.js.map +1 -0
  57. package/dist/tool-usage/adapters/cursor.d.ts +3 -0
  58. package/dist/tool-usage/adapters/cursor.d.ts.map +1 -0
  59. package/dist/tool-usage/adapters/cursor.js +47 -0
  60. package/dist/tool-usage/adapters/cursor.js.map +1 -0
  61. package/dist/tool-usage/adapters/grok.d.ts +3 -0
  62. package/dist/tool-usage/adapters/grok.d.ts.map +1 -0
  63. package/dist/tool-usage/adapters/grok.js +55 -0
  64. package/dist/tool-usage/adapters/grok.js.map +1 -0
  65. package/dist/tool-usage/adapters/jsonl.d.ts +9 -0
  66. package/dist/tool-usage/adapters/jsonl.d.ts.map +1 -0
  67. package/dist/tool-usage/adapters/jsonl.js +40 -0
  68. package/dist/tool-usage/adapters/jsonl.js.map +1 -0
  69. package/dist/tool-usage/adapters/native.d.ts +3 -0
  70. package/dist/tool-usage/adapters/native.d.ts.map +1 -0
  71. package/dist/tool-usage/adapters/native.js +31 -0
  72. package/dist/tool-usage/adapters/native.js.map +1 -0
  73. package/dist/tool-usage/adapters/pi.d.ts +3 -0
  74. package/dist/tool-usage/adapters/pi.d.ts.map +1 -0
  75. package/dist/tool-usage/adapters/pi.js +46 -0
  76. package/dist/tool-usage/adapters/pi.js.map +1 -0
  77. package/dist/tool-usage/count.d.ts +13 -0
  78. package/dist/tool-usage/count.d.ts.map +1 -0
  79. package/dist/tool-usage/count.js +160 -0
  80. package/dist/tool-usage/count.js.map +1 -0
  81. package/dist/tool-usage/index.d.ts +19 -0
  82. package/dist/tool-usage/index.d.ts.map +1 -0
  83. package/dist/tool-usage/index.js +32 -0
  84. package/dist/tool-usage/index.js.map +1 -0
  85. package/dist/tool-usage/ledger.d.ts +11 -0
  86. package/dist/tool-usage/ledger.d.ts.map +1 -0
  87. package/dist/tool-usage/ledger.js +29 -0
  88. package/dist/tool-usage/ledger.js.map +1 -0
  89. package/dist/tool-usage/stream.d.ts +32 -0
  90. package/dist/tool-usage/stream.d.ts.map +1 -0
  91. package/dist/tool-usage/stream.js +17 -0
  92. package/dist/tool-usage/stream.js.map +1 -0
  93. package/package.json +10 -4
  94. package/scripts/check-task-artifact-contract.mjs +36 -0
  95. package/scripts/checklist-order.cjs +165 -0
  96. package/scripts/checklist-target.cjs +20 -0
  97. package/scripts/mark-checklist-step.cjs +285 -23
  98. package/scripts/proof-artifacts.cjs +258 -0
  99. package/scripts/subtask-unit.cjs +22 -1
  100. package/scripts/worker-terminal-contract.cjs +4 -6
@@ -0,0 +1,32 @@
1
+ // Tool-call usage per agent session: runner adapters translate a transcript into one stream,
2
+ // one counter splits it at the checklist marks. Farm accounting and the direct-skill path share it.
3
+ import { claudeToolUsage } from './adapters/claude.js';
4
+ import { codexToolUsage } from './adapters/codex.js';
5
+ import { cursorToolUsage } from './adapters/cursor.js';
6
+ import { grokToolUsage } from './adapters/grok.js';
7
+ import { nativeToolUsage } from './adapters/native.js';
8
+ import { piToolUsage } from './adapters/pi.js';
9
+ import { countToolUsage } from './count.js';
10
+ export { countToolUsage, mergeToolUsage } from './count.js';
11
+ export { checklistMarks, checklistMarksFromSignal } from './ledger.js';
12
+ export { pairToolEvents } from './stream.js';
13
+ const ADAPTERS = [
14
+ piToolUsage,
15
+ claudeToolUsage,
16
+ codexToolUsage,
17
+ grokToolUsage,
18
+ cursorToolUsage,
19
+ nativeToolUsage,
20
+ ];
21
+ export function toolUsageAdapter(runner) {
22
+ return ADAPTERS.find((adapter) => adapter.runner === runner);
23
+ }
24
+ /** Reads one session with its runner's adapter and counts it against the marks. */
25
+ export async function measureToolUsage(params) {
26
+ const adapter = toolUsageAdapter(params.runner);
27
+ if (!adapter)
28
+ throw new Error(`No tool-usage adapter for runner ${params.runner}`);
29
+ const stream = await adapter.read(params.sessionPath, { home: params.home });
30
+ return countToolUsage(stream, params.marks ?? [], params.window);
31
+ }
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool-usage/index.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,oGAAoG;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAwC,MAAM,YAAY,CAAC;AAKlF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,QAAQ,GAAgC;IAC5C,WAAW;IACX,eAAe;IACf,cAAc;IACd,aAAa;IACb,eAAe;IACf,eAAe;CAChB,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAMtC;IACC,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACnF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7E,OAAO,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,11 @@
1
+ export interface ChecklistMark {
2
+ stepNumber: number;
3
+ label: string;
4
+ checkedAt: string;
5
+ skipped?: boolean;
6
+ }
7
+ /** Valid marks in ledger order. Malformed entries are dropped, as the gateway reader does. */
8
+ export declare function checklistMarks(timing: unknown): ChecklistMark[];
9
+ /** Marks from a parsed SIGNAL.json document. */
10
+ export declare function checklistMarksFromSignal(signal: unknown): ChecklistMark[];
11
+ //# sourceMappingURL=ledger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/tool-usage/ledger.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAMD,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,EAAE,CAY/D;AAED,gDAAgD;AAChD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,EAAE,CAEzE"}
@@ -0,0 +1,29 @@
1
+ // Checklist marks from the mark ledger: SIGNAL.json `checklistTiming` (schemaVersion 1), which
2
+ // the gateway also keeps as `run.metrics.checklistTiming`. Nothing here depends on the runner.
3
+ function isRecord(value) {
4
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
5
+ }
6
+ /** Valid marks in ledger order. Malformed entries are dropped, as the gateway reader does. */
7
+ export function checklistMarks(timing) {
8
+ if (!isRecord(timing) || timing.schemaVersion !== 1 || !Array.isArray(timing.events))
9
+ return [];
10
+ const marks = [];
11
+ for (const event of timing.events) {
12
+ if (!isRecord(event))
13
+ continue;
14
+ const { stepNumber, label, checkedAt, skipped } = event;
15
+ if (typeof stepNumber !== 'number' || !Number.isInteger(stepNumber) || stepNumber < 1)
16
+ continue;
17
+ if (typeof label !== 'string' || typeof checkedAt !== 'string')
18
+ continue;
19
+ if (!Number.isFinite(Date.parse(checkedAt)))
20
+ continue;
21
+ marks.push({ stepNumber, label, checkedAt, ...(skipped === true ? { skipped: true } : {}) });
22
+ }
23
+ return marks;
24
+ }
25
+ /** Marks from a parsed SIGNAL.json document. */
26
+ export function checklistMarksFromSignal(signal) {
27
+ return isRecord(signal) ? checklistMarks(signal.checklistTiming) : [];
28
+ }
29
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/tool-usage/ledger.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,+FAA+F;AAS/F,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,aAAa,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IAChG,MAAM,KAAK,GAAoB,EAAE,CAAC;IAClC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,SAAS;QAC/B,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;QACxD,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC;YAAE,SAAS;QAChG,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,SAAS,KAAK,QAAQ;YAAE,SAAS;QACzE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAAE,SAAS;QACtD,KAAK,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,wBAAwB,CAAC,MAAe;IACtD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACxE,CAAC"}
@@ -0,0 +1,32 @@
1
+ export interface ToolCallEvent {
2
+ /** Runner call id, used only to pair a completion with its call. */
3
+ id?: string;
4
+ name: string;
5
+ /** ISO time the model issued the call. Absent when the transcript records no times. */
6
+ issuedAt?: string;
7
+ completedAt?: string;
8
+ }
9
+ export interface TokenSample {
10
+ at: string;
11
+ /** Tokens this record added (input + output + cache, as in the session totals). */
12
+ tokens: number;
13
+ }
14
+ export interface ToolUsageStream {
15
+ tools: ToolCallEvent[];
16
+ /** Null when the runner records no timed token usage, so per-step tokens are unknown. */
17
+ tokens: TokenSample[] | null;
18
+ }
19
+ /** Translates one runner's transcript into the stream. Adding a runner means adding one. */
20
+ export interface ToolUsageAdapter {
21
+ runner: string;
22
+ /** `sessionPath` is the transcript file or session directory the usage accounting reads. */
23
+ read(sessionPath: string, options?: {
24
+ home?: string;
25
+ }): Promise<ToolUsageStream>;
26
+ }
27
+ /** Pairs completions with calls by id. Unmatched completions are ignored; they have no call. */
28
+ export declare function pairToolEvents(calls: ToolCallEvent[], completions: Array<{
29
+ id: string;
30
+ completedAt: string;
31
+ }>): ToolCallEvent[];
32
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/tool-usage/stream.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,yFAAyF;IACzF,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;CAC9B;AAED,4FAA4F;AAC5F,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAClF;AAED,gGAAgG;AAChG,wBAAgB,cAAc,CAC5B,KAAK,EAAE,aAAa,EAAE,EACtB,WAAW,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,GACtD,aAAa,EAAE,CAQjB"}
@@ -0,0 +1,17 @@
1
+ // The normalized stream every runner adapter produces. Tool calls carry the same fields as the
2
+ // native `tool.started` / `tool.completed` events; token samples let per-step cost use the same
3
+ // boundaries as the tool counts.
4
+ /** Pairs completions with calls by id. Unmatched completions are ignored; they have no call. */
5
+ export function pairToolEvents(calls, completions) {
6
+ const byId = new Map();
7
+ for (const call of calls)
8
+ if (call.id && !byId.has(call.id))
9
+ byId.set(call.id, call);
10
+ for (const completion of completions) {
11
+ const call = byId.get(completion.id);
12
+ if (call && !call.completedAt)
13
+ call.completedAt = completion.completedAt;
14
+ }
15
+ return calls;
16
+ }
17
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/tool-usage/stream.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,gGAAgG;AAChG,iCAAiC;AA8BjC,gGAAgG;AAChG,MAAM,UAAU,cAAc,CAC5B,KAAsB,EACtB,WAAuD;IAEvD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC9C,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACrF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QACrC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAC3E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farmslot/agent-runtime",
3
- "version": "0.48.0",
3
+ "version": "0.48.2",
4
4
  "minimumRuntimeVersion": "0.42.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,6 +29,8 @@
29
29
  "./scripts/acceptance-cli.cjs": "./scripts/acceptance-cli.cjs",
30
30
  "./scripts/subtask-unit.cjs": "./scripts/subtask-unit.cjs",
31
31
  "./scripts/worker-terminal-contract.cjs": "./scripts/worker-terminal-contract.cjs",
32
+ "./scripts/proof-artifacts.cjs": "./scripts/proof-artifacts.cjs",
33
+ "./scripts/checklist-order.cjs": "./scripts/checklist-order.cjs",
32
34
  "./scripts/check-task-artifact-contract.mjs": "./scripts/check-task-artifact-contract.mjs",
33
35
  "./scripts/retained-recipe-attempt.cjs": {
34
36
  "types": "./scripts/retained-recipe-attempt.d.cts",
@@ -45,6 +47,10 @@
45
47
  "types": "./dist/native/*.d.ts",
46
48
  "import": "./dist/native/*.js"
47
49
  },
50
+ "./tool-usage": {
51
+ "types": "./dist/tool-usage/index.d.ts",
52
+ "import": "./dist/tool-usage/index.js"
53
+ },
48
54
  "./scripts/branch-update.mjs": "./scripts/branch-update.mjs",
49
55
  "./scripts/git-diff.cjs": {
50
56
  "types": "./scripts/git-diff.d.cts",
@@ -73,7 +79,7 @@
73
79
  },
74
80
  "scripts": {
75
81
  "typecheck": "yarn workspace @farmslot/protocol build && tsc --noEmit --project tsconfig.json",
76
- "test": "node --test test/proof-measurement.test.cjs test/scripted-command-contract.test.cjs test/evidence-manifest.test.cjs test/mark-operator-wait.test.cjs test/mark-autonomous-refusal.test.cjs test/review-diff-scope.test.cjs test/review-coverage.test.cjs test/review-compaction.test.cjs test/claim-review-gate.test.mjs test/deterministic-checks.test.cjs && node test/mark-checklist-step.test.cjs && node test/mark-subtask.test.cjs && node --test test/acceptance-ledger.test.cjs test/acceptance-ledger-cutover.test.cjs test/acceptance-contract.test.cjs test/acceptance-derivation.test.cjs && node test/checklist-target-sync.test.mjs && node test/acceptance-ledger-sync.test.mjs && node test/package-exports.test.cjs && node test/check-task-artifact-contract.test.cjs && node --test test/recipe-shape-feedback.test.cjs && node test/recipe-quality-builder.test.cjs && node test/task-init.test.mjs && node --import tsx ../../scripts/e2e-subtask-mark.mts && node ../../scripts/quality/run-tsx-tests.mjs --cwd . --tsconfig tsconfig.json src/execution-template && node ../../scripts/quality/run-tsx-tests.mjs --cwd . --tsconfig tsconfig.json src/task-init && node ../../scripts/quality/run-tsx-tests.mjs --cwd . --tsconfig tsconfig.json src/native",
82
+ "test": "node --test --test-concurrency=2 test/*.test.cjs test/*.test.mjs && node --import tsx ../../scripts/e2e-subtask-mark.mts && node ../../scripts/quality/run-tsx-tests.mjs --cwd . --tsconfig tsconfig.json --workers 2 src/execution-template && node ../../scripts/quality/run-tsx-tests.mjs --cwd . --tsconfig tsconfig.json --workers 2 src/task-init && node ../../scripts/quality/run-tsx-tests.mjs --cwd . --tsconfig tsconfig.json --workers 2 src/native src/tool-usage",
77
83
  "format": "prettier --write --ignore-path ../../.prettierignore .",
78
84
  "format:check": "prettier --check --ignore-path ../../.prettierignore .",
79
85
  "lint": "eslint \"src/**/*.ts\"",
@@ -87,8 +93,8 @@
87
93
  "test:native-observation-live": "NATIVE_OBSERVATION_LIVE=1 node --import tsx --test --test-name-pattern='source admits the actual supervisor' src/native/observation.test.ts"
88
94
  },
89
95
  "dependencies": {
90
- "@farmslot/adapter-sdk": "0.27.8",
91
- "@farmslot/protocol": "0.85.0"
96
+ "@farmslot/adapter-sdk": "0.27.10",
97
+ "@farmslot/protocol": "0.86.1"
92
98
  },
93
99
  "devDependencies": {
94
100
  "@types/node": "^22.0.0",
@@ -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,