@qvac/harness 1.0.0-rc.20 → 1.0.0-rc.21

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 (191) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist-lib/index.d.ts +7 -5
  3. package/dist-lib/index.js +5 -4
  4. package/dist-lib/lib/agent/resolve.js +2 -1
  5. package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +2 -2
  6. package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +1 -1
  7. package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +1 -1
  8. package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +8 -6
  9. package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +1 -1
  10. package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +1 -1
  11. package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +2 -1
  12. package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +8 -3
  13. package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +10 -4
  14. package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +2 -1
  15. package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +8 -8
  16. package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +2 -2
  17. package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +3 -2
  18. package/dist-lib/lib/capabilities/completion-engine/loop.js +1 -0
  19. package/dist-lib/lib/capabilities/completion-engine/round.js +9 -9
  20. package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -1
  21. package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +5 -41
  22. package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +4 -133
  23. package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
  24. package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +42 -0
  25. package/dist-lib/lib/capabilities/completion-engine/tool-preflight.d.ts +43 -0
  26. package/dist-lib/lib/capabilities/completion-engine/tool-preflight.js +91 -0
  27. package/dist-lib/lib/capabilities/completion-engine/turns.js +7 -4
  28. package/dist-lib/lib/capabilities/tool-turns/attachments.d.ts +7 -0
  29. package/dist-lib/lib/capabilities/tool-turns/attachments.js +39 -0
  30. package/dist-lib/lib/capabilities/tool-turns/copy.d.ts +13 -0
  31. package/dist-lib/lib/capabilities/tool-turns/copy.js +29 -0
  32. package/dist-lib/lib/capabilities/tool-turns/result-turn.d.ts +22 -0
  33. package/dist-lib/lib/capabilities/tool-turns/result-turn.js +120 -0
  34. package/dist-lib/lib/capabilities/tool-turns/run-limits.d.ts +6 -0
  35. package/dist-lib/lib/capabilities/tool-turns/run-limits.js +32 -0
  36. package/dist-lib/lib/capabilities/tool-turns/skill-loads.d.ts +9 -0
  37. package/dist-lib/lib/capabilities/tool-turns/skill-loads.js +71 -0
  38. package/dist-lib/lib/capabilities/tool-turns.d.ts +8 -54
  39. package/dist-lib/lib/capabilities/tool-turns.js +6 -281
  40. package/dist-lib/lib/client/index.js +3 -3
  41. package/dist-lib/lib/connect/abort.d.ts +6 -0
  42. package/dist-lib/lib/connect/abort.js +52 -0
  43. package/dist-lib/lib/connect/bridges.d.ts +21 -0
  44. package/dist-lib/lib/connect/bridges.js +185 -0
  45. package/dist-lib/lib/connect/decode.d.ts +31 -0
  46. package/dist-lib/lib/connect/decode.js +114 -0
  47. package/dist-lib/lib/connect/host-run-log.d.ts +16 -0
  48. package/dist-lib/lib/connect/host-run-log.js +74 -0
  49. package/dist-lib/lib/connect/served.d.ts +7 -0
  50. package/dist-lib/lib/connect/served.js +45 -0
  51. package/dist-lib/lib/connect.d.ts +3 -3
  52. package/dist-lib/lib/connect.js +24 -468
  53. package/dist-lib/lib/context-window.d.ts +13 -7
  54. package/dist-lib/lib/context-window.js +13 -6
  55. package/dist-lib/lib/contract/agent.d.ts +12 -1
  56. package/dist-lib/lib/contract/completion.d.ts +5 -1
  57. package/dist-lib/lib/contract/drive.d.ts +130 -4
  58. package/dist-lib/lib/contract/ocr.d.ts +5 -1
  59. package/dist-lib/lib/contract-types.d.ts +5 -3
  60. package/dist-lib/lib/errors.js +3 -3
  61. package/dist-lib/lib/helpers/goal-check/asks.d.ts +25 -0
  62. package/dist-lib/lib/helpers/goal-check/asks.js +52 -0
  63. package/dist-lib/lib/helpers/goal-check/checks.d.ts +8 -0
  64. package/dist-lib/lib/helpers/goal-check/checks.js +92 -0
  65. package/dist-lib/lib/helpers/goal-check/commands.d.ts +7 -0
  66. package/dist-lib/lib/helpers/goal-check/commands.js +130 -0
  67. package/dist-lib/lib/helpers/goal-check/paths.d.ts +5 -0
  68. package/dist-lib/lib/helpers/goal-check/paths.js +44 -0
  69. package/dist-lib/lib/helpers/goal-check/shell.d.ts +9 -0
  70. package/dist-lib/lib/helpers/goal-check/shell.js +96 -0
  71. package/dist-lib/lib/helpers/goal-check.d.ts +35 -43
  72. package/dist-lib/lib/helpers/goal-check.js +34 -406
  73. package/dist-lib/lib/helpers/recent-map.d.ts +7 -0
  74. package/dist-lib/lib/helpers/recent-map.js +23 -0
  75. package/dist-lib/lib/helpers/tool-call-markup/emit.d.ts +6 -0
  76. package/dist-lib/lib/helpers/tool-call-markup/emit.js +15 -0
  77. package/dist-lib/lib/helpers/tool-call-markup/recover.d.ts +22 -0
  78. package/dist-lib/lib/helpers/tool-call-markup/recover.js +130 -0
  79. package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.d.ts +3 -0
  80. package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.js +56 -0
  81. package/dist-lib/lib/helpers/tool-call-markup/strip.d.ts +4 -0
  82. package/dist-lib/lib/helpers/tool-call-markup/strip.js +149 -0
  83. package/dist-lib/lib/helpers/tool-call-markup.d.ts +19 -24
  84. package/dist-lib/lib/helpers/tool-call-markup.js +17 -343
  85. package/dist-lib/lib/machine/completion/actions/completion.d.ts +12 -18
  86. package/dist-lib/lib/machine/completion/actions/completion.js +19 -178
  87. package/dist-lib/lib/machine/completion/actions/goal.d.ts +10 -0
  88. package/dist-lib/lib/machine/completion/actions/goal.js +93 -0
  89. package/dist-lib/lib/machine/completion/actions/prepare.js +2 -1
  90. package/dist-lib/lib/machine/completion/actions/reject-tool.d.ts +16 -0
  91. package/dist-lib/lib/machine/completion/actions/reject-tool.js +147 -0
  92. package/dist-lib/lib/machine/completion/actions/retry-round.d.ts +6 -0
  93. package/dist-lib/lib/machine/completion/actions/retry-round.js +50 -0
  94. package/dist-lib/lib/machine/completion/actions/rounds.d.ts +5 -0
  95. package/dist-lib/lib/machine/completion/actions/rounds.js +31 -0
  96. package/dist-lib/lib/machine/completion/actions/tools.d.ts +1 -16
  97. package/dist-lib/lib/machine/completion/actions/tools.js +16 -161
  98. package/dist-lib/lib/machine/completion/context.js +3 -3
  99. package/dist-lib/lib/machine/completion/implementations.d.ts +2 -2
  100. package/dist-lib/lib/machine/completion/implementations.js +6 -2
  101. package/dist-lib/lib/machine/completion/machine.d.ts +2 -2
  102. package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
  103. package/dist-lib/lib/machine/completion/metrics.js +68 -0
  104. package/dist-lib/lib/machine/completion/nudges.d.ts +5 -0
  105. package/dist-lib/lib/machine/completion/nudges.js +33 -0
  106. package/dist-lib/lib/machine/completion/rules.d.ts +5 -34
  107. package/dist-lib/lib/machine/completion/rules.js +4 -120
  108. package/dist-lib/lib/machine/completion/splice.d.ts +9 -0
  109. package/dist-lib/lib/machine/completion/splice.js +19 -0
  110. package/dist-lib/lib/machine/completion/types.d.ts +4 -13
  111. package/dist-lib/lib/machine/index.d.ts +3 -3
  112. package/dist-lib/lib/machine/index.js +2 -2
  113. package/dist-lib/lib/media-host.js +2 -2
  114. package/dist-lib/lib/media-wire.js +2 -2
  115. package/dist-lib/lib/residency/completion-runtime.d.ts +2 -1
  116. package/dist-lib/lib/residency/completion-runtime.js +44 -1
  117. package/dist-lib/lib/residency/index.d.ts +3 -2
  118. package/dist-lib/lib/residency/index.js +2 -2
  119. package/dist-lib/lib/round-host.js +3 -3
  120. package/dist-lib/lib/round-port.js +3 -3
  121. package/dist-lib/lib/run-log/redact.js +7 -7
  122. package/dist-lib/lib/serve/completion.d.ts +7 -0
  123. package/dist-lib/lib/serve/completion.js +553 -0
  124. package/dist-lib/lib/serve/downloads.d.ts +4 -0
  125. package/dist-lib/lib/serve/downloads.js +79 -0
  126. package/dist-lib/lib/serve/models.d.ts +5 -0
  127. package/dist-lib/lib/serve/models.js +120 -0
  128. package/dist-lib/lib/serve/noop.d.ts +1 -0
  129. package/dist-lib/lib/serve/noop.js +1 -0
  130. package/dist-lib/lib/serve/requests.d.ts +147 -0
  131. package/dist-lib/lib/serve/requests.js +1 -0
  132. package/dist-lib/lib/serve/rounds.d.ts +11 -0
  133. package/dist-lib/lib/serve/rounds.js +67 -0
  134. package/dist-lib/lib/serve/run-log-start.d.ts +38 -0
  135. package/dist-lib/lib/serve/run-log-start.js +254 -0
  136. package/dist-lib/lib/serve/skills.d.ts +32 -0
  137. package/dist-lib/lib/serve/skills.js +46 -0
  138. package/dist-lib/lib/serve.d.ts +5 -1
  139. package/dist-lib/lib/serve.js +14 -1071
  140. package/dist-lib/lib/skills-host/index.d.ts +4 -2
  141. package/dist-lib/lib/skills-host/index.js +20 -8
  142. package/dist-lib/lib/tools/fs/drive.d.ts +1 -17
  143. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +1 -81
  144. package/dist-lib/lib/tools/fs/scope.d.ts +2 -17
  145. package/dist-lib/lib/tools/fs/search.d.ts +2 -18
  146. package/dist-lib/lib/tools/fs/walk.d.ts +1 -5
  147. package/dist-lib/lib/tools/pdf/build.d.ts +2 -2
  148. package/dist-lib/lib/tools/pdf/recognize.js +4 -8
  149. package/dist-lib/lib/tools/pdf/request.d.ts +3 -8
  150. package/dist-lib/lib/tools/pdf/request.js +4 -4
  151. package/dist-lib/lib/tools/pdf.d.ts +0 -1
  152. package/dist-lib/lib/tools/pdf.js +0 -1
  153. package/dist-lib/lib/tools/skill.js +13 -4
  154. package/dist-lib/lib/tools/skills/bundled-dir.d.ts +3 -0
  155. package/dist-lib/lib/tools/skills/bundled-dir.js +27 -24
  156. package/dist-lib/lib/tools/skills/bundled-hash.d.ts +1 -0
  157. package/dist-lib/lib/tools/skills/bundled-hash.js +4 -1
  158. package/dist-lib/lib/tools/skills/catalog-loader.d.ts +12 -0
  159. package/dist-lib/lib/tools/skills/catalog-loader.js +173 -0
  160. package/dist-lib/lib/tools/skills/catalog.d.ts +5 -8
  161. package/dist-lib/lib/tools/skills/catalog.js +1 -162
  162. package/dist-lib/lib/tools/skills/index.d.ts +1 -0
  163. package/dist-lib/lib/tools/skills/index.js +1 -0
  164. package/dist-lib/lib/tools/skills/skill-tree.d.ts +5 -0
  165. package/dist-lib/lib/tools/skills/skill-tree.js +54 -0
  166. package/dist-lib/lib/wire/download.d.ts +10 -0
  167. package/dist-lib/lib/wire/download.js +35 -0
  168. package/dist-lib/lib/wire/event.d.ts +41 -0
  169. package/dist-lib/lib/wire/event.js +306 -0
  170. package/dist-lib/lib/wire/fields.d.ts +3 -0
  171. package/dist-lib/lib/wire/fields.js +12 -0
  172. package/dist-lib/lib/wire/knowledge.d.ts +9 -0
  173. package/dist-lib/lib/wire/knowledge.js +68 -0
  174. package/dist-lib/lib/wire/round.d.ts +14 -0
  175. package/dist-lib/lib/wire/round.js +45 -0
  176. package/dist-lib/lib/wire/vectors.d.ts +6 -0
  177. package/dist-lib/lib/wire/vectors.js +33 -0
  178. package/dist-lib/lib/wire.d.ts +28 -77
  179. package/dist-lib/lib/wire.js +24 -489
  180. package/dist-lib/plugins/ocr/coverage.d.ts +3 -0
  181. package/dist-lib/plugins/ocr/coverage.js +67 -0
  182. package/dist-lib/plugins/ocr/ocr-runtime.d.ts +4 -2
  183. package/dist-lib/plugins/ocr/ocr-runtime.js +25 -4
  184. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
  185. package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
  186. package/dist-lib/schema/harness.js +4 -1
  187. package/dist-lib/spec/hrpc/messages.js +25 -1
  188. package/dist-lib/spec/hyperschema/index.js +25 -1
  189. package/dist-lib/spec/hyperschema/schema.json +6 -1
  190. package/dist-lib/spec/hyperschema/types.d.ts +1 -0
  191. package/package.json +2 -2
@@ -0,0 +1,96 @@
1
+ import { samePath } from './paths.js';
2
+ export const SHELL_OPERATOR = /(&&|\|\||;|\||\n)/;
3
+ const RUNNER = /^(python[\d.]*|bash|sh|node|bun|pytest)$/;
4
+ export const COMPARISON = /^(!?=+|-(eq|ne|lt|le|gt|ge))$/;
5
+ const WRAPPERS = new Map([
6
+ ['timeout', /^(-s|-k|--signal|--kill-after)$/],
7
+ ['env', /^(-u|-C|--unset|--chdir)$/],
8
+ ['nice', /^(-n|--adjustment)$/],
9
+ ['stdbuf', /^(-i|-o|-e|--input|--output|--error)$/],
10
+ ['npx', /^(-p|--package)$/],
11
+ ['bunx', /^(-p|--package)$/]
12
+ ]);
13
+ export const BRACKETS = new Map([
14
+ ['[', ']'],
15
+ ['[[', ']]']
16
+ ]);
17
+ export function scriptOf(tokens) {
18
+ let at = 0;
19
+ if (RUNNER.test(tokens[0]?.split('/').at(-1) ?? '')) {
20
+ at++;
21
+ while (tokens[at]?.startsWith('-')) {
22
+ at += tokens[at] === '-m' ? 2 : 1;
23
+ }
24
+ }
25
+ return tokens[at];
26
+ }
27
+ export function exitSegments(command) {
28
+ const parts = command.split(SHELL_OPERATOR);
29
+ for (let at = parts.length - 1; at >= 0; at -= 2) {
30
+ if (!parts[at].trim()) {
31
+ parts.splice(at === parts.length - 1 ? Math.max(at - 1, 0) : at, 2);
32
+ }
33
+ }
34
+ const segments = [];
35
+ for (let at = 0; at < parts.length; at += 2) {
36
+ const after = parts.slice(at + 1).filter((_, n) => n % 2 === 0);
37
+ if (parts[at - 1] !== '||' && after.every((operator) => operator === '&&')) {
38
+ segments.push(parts[at].trim());
39
+ }
40
+ }
41
+ return segments;
42
+ }
43
+ export function commandOf(segment) {
44
+ const all = words(segment);
45
+ return all.slice(Math.max(commandStart(all), 0));
46
+ }
47
+ export function words(text) {
48
+ return text
49
+ .trim()
50
+ .split(/\s+/)
51
+ .filter(Boolean)
52
+ .map((word) => word.replace(/^['"]|['"]$/g, ''));
53
+ }
54
+ export function invokes(tokens, wanted) {
55
+ let start = commandStart(tokens);
56
+ if (start < 0) {
57
+ return false;
58
+ }
59
+ if (leads(tokens.slice(start), wanted)) {
60
+ return true;
61
+ }
62
+ if (!RUNNER.test(tokens[start].split('/').at(-1) ?? '')) {
63
+ return false;
64
+ }
65
+ start++;
66
+ while (tokens[start]?.startsWith('-')) {
67
+ start++;
68
+ }
69
+ return leads(tokens.slice(start), wanted);
70
+ }
71
+ export function commandStart(tokens) {
72
+ let at = 0;
73
+ while (at < tokens.length) {
74
+ if (/^\w+=/.test(tokens[at])) {
75
+ at++;
76
+ continue;
77
+ }
78
+ const wrapper = tokens[at].split('/').at(-1) ?? '';
79
+ const takesValue = WRAPPERS.get(wrapper);
80
+ if (!takesValue) {
81
+ return at;
82
+ }
83
+ at++;
84
+ while (tokens[at]?.startsWith('-')) {
85
+ at += takesValue.test(tokens[at]) ? 2 : 1;
86
+ }
87
+ if (wrapper === 'timeout') {
88
+ at++;
89
+ }
90
+ }
91
+ return -1;
92
+ }
93
+ function leads(tokens, wanted) {
94
+ return (wanted.length > 0 &&
95
+ wanted.every((word, at) => tokens[at] !== undefined && samePath(tokens[at], word)));
96
+ }
@@ -1,44 +1,36 @@
1
- export declare const MAX_GOAL_CHECKS = 8;
2
- export declare const MAX_PROVING: number;
3
- export declare const GOAL_CHECKS_ASK: string;
4
- export declare const GOAL_PROOF_ASK: string;
5
- export declare const GOAL_REVIEW_ASK: string;
6
- export declare const GOAL_CASES_ASK: string;
7
- export declare const GOAL_DELIVERABLE_ASK: string;
8
- export declare const GOAL_RUN_ASK: string;
9
- export declare const MAX_PROOF_ASKS = 2;
10
- export interface AskedGoal {
11
- checkable?: boolean;
12
- named?: boolean;
13
- checks: readonly {
14
- name: string;
15
- passed?: boolean;
16
- }[];
17
- turns: number;
18
- deliverable?: readonly string[];
19
- proving?: readonly string[];
20
- edited?: readonly string[];
21
- proof?: string;
1
+ import { asksChecks, asksDeliverable, asksRun, codeUnrun, deliverableAsk, deliverableChecked, runAsk } from './goal-check/asks.ts';
2
+ import { citesPassed, existenceOnly, mergeChecks, namedChecks, pathsOf, runsDeliverable } from './goal-check/checks.ts';
3
+ import { provesResult, runsCheck, runsCode, runsCodeCheck, runsScript } from './goal-check/commands.ts';
4
+ import { namesPath, samePath, sourceFile, writtenTexts } from './goal-check/paths.ts';
5
+ export type { AskedGoal } from './goal-check/asks.ts';
6
+ export declare class GoalCheck {
7
+ static GOAL_CASES_ASK: string;
8
+ static GOAL_CHECKS_ASK: string;
9
+ static GOAL_PROOF_ASK: string;
10
+ static GOAL_REVIEW_ASK: string;
11
+ static MAX_GOAL_CHECKS: number;
12
+ static MAX_PROOF_ASKS: number;
13
+ static MAX_PROVING: number;
14
+ static asksChecks: typeof asksChecks;
15
+ static asksDeliverable: typeof asksDeliverable;
16
+ static asksRun: typeof asksRun;
17
+ static citesPassed: typeof citesPassed;
18
+ static codeUnrun: typeof codeUnrun;
19
+ static deliverableAsk: typeof deliverableAsk;
20
+ static deliverableChecked: typeof deliverableChecked;
21
+ static existenceOnly: typeof existenceOnly;
22
+ static mergeChecks: typeof mergeChecks;
23
+ static namedChecks: typeof namedChecks;
24
+ static namesPath: typeof namesPath;
25
+ static pathsOf: typeof pathsOf;
26
+ static provesResult: typeof provesResult;
27
+ static runAsk: typeof runAsk;
28
+ static runsCheck: typeof runsCheck;
29
+ static runsCode: typeof runsCode;
30
+ static runsCodeCheck: typeof runsCodeCheck;
31
+ static runsDeliverable: typeof runsDeliverable;
32
+ static runsScript: typeof runsScript;
33
+ static samePath: typeof samePath;
34
+ static sourceFile: typeof sourceFile;
35
+ static writtenTexts: typeof writtenTexts;
22
36
  }
23
- export declare function deliverableAsk(paths: readonly string[]): string;
24
- export declare function deliverableChecked(goal: AskedGoal): boolean;
25
- export declare function asksDeliverable(goal: AskedGoal): boolean;
26
- export declare function runAsk(path: string): string;
27
- export declare function codeUnrun(goal: AskedGoal): boolean;
28
- export declare function asksRun(goal: AskedGoal): boolean;
29
- export declare function asksChecks(goal: AskedGoal): boolean;
30
- export declare function existenceOnly(checks: readonly string[]): boolean;
31
- export declare function pathsOf(checks: readonly string[]): string[];
32
- export declare function runsDeliverable(check: string, deliverable: readonly string[], proving: readonly string[]): boolean;
33
- export declare function sourceFile(path: string): boolean;
34
- export declare function runsCode(command: string, edited: readonly string[]): string | undefined;
35
- export declare function runsCodeCheck(command: string, checks: readonly string[]): string | undefined;
36
- export declare function runsScript(check: string, paths: readonly string[]): boolean;
37
- export declare function namesPath(text: string, paths: readonly string[]): boolean;
38
- export declare function writtenTexts(args: Readonly<Record<string, unknown>>): [string, string][];
39
- export declare function provesResult(command: string): string | undefined;
40
- export declare function citesPassed(text: string, passed: readonly string[]): boolean;
41
- export declare function namedChecks(text: string): string[];
42
- export declare function mergeChecks(host: readonly string[], named: readonly string[]): string[];
43
- export declare function runsCheck(command: string, check: string): boolean;
44
- export declare function samePath(a: string, b: string): boolean;
@@ -1,407 +1,35 @@
1
- const SHELL_OPERATOR = /(&&|\|\||;|\||\n)/;
2
- const RUNNER = /^(python[\d.]*|bash|sh|node|bun|pytest)$/;
3
- const CHECKS_HEADING = /^[\s*#_]*checks:?[\s*_]*$/i;
4
- const CHECK_LINE = /^\s*(?:[-*]|\d+[.)])?\s*`([^`]+)`\s*$/;
5
- const SPAN = /`([^`\n]+)`/g;
6
- const FILE_TEST = /^-[sfed]$/;
7
- const NOT_A_PATH = /^(-\w+|!|!?=+|<|>|\]\]?)$/;
8
- const COMPARISON = /^(!?=+|-(eq|ne|lt|le|gt|ge))$/;
9
- const TEST_SCRIPT = /^(tests?|checks?|verify|validate)(?=[_.-]|$)/;
10
- const PACKAGE_TEST = /^tests?(?=[:_.-]|$)/;
11
- const PACKAGE_MANAGER = /^(npm|yarn|pnpm|bun)$/;
12
- const PYTHON = /^python[\d.]*$/;
13
- const COMPARE = /^(diff|cmp)$/;
14
- const QUIET = /^(-[a-zA-Z]*q[a-zA-Z]*|--quiet)$/;
15
- const NEVER_RUNS = /^(cat|ls|head|tail|stat|file|wc|echo|printf|touch|chmod|chown|cp|mv|mkdir|rm|ln|unlink|rmdir|true|\w*sum)$/;
16
- const INTERPRETER = /^(python[\d.]*|bash|sh|zsh|node|bun|deno|go|ruby|perl|php|lua|Rscript|julia|tsx|ts-node|java)$/;
17
- const SYNTAX_ONLY = /^((ba|z)?sh -n|node (-c|--check)|(perl|ruby) -c|php -l)$/;
18
- const SOURCE = /\.(py|js|mjs|cjs|ts|mts|cts|jsx|tsx|sh|bash|zsh|rb|pl|php|lua|r|jl|go|rs|c|h|cc|cpp|cxx|hpp|java)$/i;
19
- const COMPILER = /^(gcc|g\+\+|cc|c\+\+|clang|clang\+\+|rustc)$/;
20
- const SYSTEM_BIN = /^\/(usr\/)?s?bin\//;
21
- const MAKE_DRY_RUN = /^(-n|-q|--dry-run|--just-print|--question)$/;
22
- const CLEAN = /^(clean|distclean)$/;
23
- const PATH_BREAK = /[\s'"`(),;:=<>|&[\]{}]+/;
24
- const WRITE = /(?<![>&\d])>\|?\s*(['"]?)([^\s'";|&<>()]+)\1/g;
25
- const HEREDOC = /(<<-?\s*(['"]?)(\w+)\2[^\n]*)\n([\s\S]*?\n)?\t*\3(?=\n|$)/g;
26
- const WRAPPERS = new Map([
27
- ['timeout', /^(-s|-k|--signal|--kill-after)$/],
28
- ['env', /^(-u|-C|--unset|--chdir)$/],
29
- ['nice', /^(-n|--adjustment)$/],
30
- ['stdbuf', /^(-i|-o|-e|--input|--output|--error)$/],
31
- ['npx', /^(-p|--package)$/],
32
- ['bunx', /^(-p|--package)$/]
33
- ]);
34
- const BRACKETS = new Map([
35
- ['[', ']'],
36
- ['[[', ']]']
37
- ]);
38
- export const MAX_GOAL_CHECKS = 8;
39
- export const MAX_PROVING = MAX_GOAL_CHECKS * 2;
40
- export const GOAL_CHECKS_ASK = '[This goal has no checks yet. Name the commands that will prove the task is done: write a ' +
41
- 'line `Checks:`, then one command per line in backticks, such as `test -s /app/result.json` ' +
42
- 'or `python3 check.py`. Each must exit 0 only once the task is done, with no pipe, ; or && ' +
43
- 'in it. The goal is met only once each of them ran on its own and exited 0.]';
44
- export const GOAL_PROOF_ASK = '[The checks this goal has so far may only show that the output exists, not that it is right. Name the ' +
45
- 'commands that will prove the result is correct, such as running the program on an input ' +
46
- "and comparing with what the task asks, or the task's own tests: write a line `Checks:`, " +
47
- 'then one command per line in backticks, with no pipe, ; or && in it. A command that repeats ' +
48
- 'one of those checks does not count. The goal is met only once each check ran on its own and exited 0.]';
49
- export const GOAL_REVIEW_ASK = '[Before the goal is met, read the task again and list each requirement it states, one line ' +
50
- 'each, with the command that proves it in backticks and the output it gave. Then write a ' +
51
- 'line `Checks:` and, one per line in backticks, a command for each requirement nothing proved ' +
52
- 'yet, that exits 0 only when it holds, with no pipe, ; or && in it. If every requirement is ' +
53
- 'proved, name no command.]';
54
- export const GOAL_CASES_ASK = '[The checks pass with most of the budget left. Read the task again and quote each case it ' +
55
- 'names, such as an input, an edge case or an output format, one line each. For each one, ' +
56
- 'run a command that feeds it to your result and show the output it gave. Fix what does not ' +
57
- 'hold, then answer.]';
58
- export const GOAL_DELIVERABLE_ASK = '[The checks pass, but none of them runs or reads {paths}, what the task asks for. A check ' +
59
- 'counts only when its command, or a script it runs that you wrote, names one of those paths. ' +
60
- 'Write a line `Checks:`, then one command per line in backticks that runs or reads it on an ' +
61
- 'input and exits 0 only when the result is right, with no pipe, ; or && in it. The checks so ' +
62
- 'far stay.]';
63
- export const GOAL_RUN_ASK = '[No command ran `{path}` after your last edit. Run a test that exercises it. It counts only ' +
64
- 'when it exits 0 on its own, with no pipe, `|| true` or ; after it.]';
65
- export const MAX_PROOF_ASKS = 2;
66
- export function deliverableAsk(paths) {
67
- return GOAL_DELIVERABLE_ASK.replaceAll('{paths}', paths.join(', '));
68
- }
69
- export function deliverableChecked(goal) {
70
- const { deliverable, proving = [] } = goal;
71
- return (!deliverable || goal.checks.some((check) => runsDeliverable(check.name, deliverable, proving)));
72
- }
73
- export function asksDeliverable(goal) {
74
- return (!asksChecks(goal) && goal.checks.every((check) => check.passed) && !deliverableChecked(goal));
75
- }
76
- export function runAsk(path) {
77
- return GOAL_RUN_ASK.replaceAll('{path}', path);
78
- }
79
- export function codeUnrun(goal) {
80
- return !!goal.checkable && !!goal.edited?.length && !goal.proof;
81
- }
82
- export function asksRun(goal) {
83
- return (codeUnrun(goal) &&
84
- !asksChecks(goal) &&
85
- goal.checks.every((check) => check.passed) &&
86
- deliverableChecked(goal));
87
- }
88
- export function asksChecks(goal) {
89
- return !!goal.checkable && !goal.named && goal.turns < MAX_PROOF_ASKS;
90
- }
91
- export function existenceOnly(checks) {
92
- return (checks.length > 0 &&
93
- checks.every((check) => check
94
- .split(SHELL_OPERATOR)
95
- .filter((part, at) => at % 2 === 0 && part.trim())
96
- .every((part) => testsExistence(commandOf(part)))));
97
- }
98
- function testsExistence(tokens) {
99
- const close = BRACKETS.get(tokens[0]);
100
- if ((tokens[0] !== 'test' && !close) || (close && tokens.at(-1) !== close)) {
101
- return false;
102
- }
103
- const path = tokens.slice(2, close ? -1 : undefined);
104
- return (FILE_TEST.test(tokens[1] ?? '') &&
105
- path.length > 0 &&
106
- !path.some((token) => NOT_A_PATH.test(token)));
107
- }
108
- export function pathsOf(checks) {
109
- const paths = checks.flatMap((check) => check
110
- .split(SHELL_OPERATOR)
111
- .filter((part, at) => at % 2 === 0)
112
- .map(commandOf)
113
- .filter(testsExistence)
114
- .flatMap((tokens) => tokens.slice(2, BRACKETS.has(tokens[0]) ? -1 : undefined)));
115
- return [...new Set(paths)];
116
- }
117
- export function runsDeliverable(check, deliverable, proving) {
118
- return (!existenceOnly([check]) &&
119
- exitSegments(check).some((segment) => {
120
- const tokens = commandOf(segment);
121
- const program = tokens[0]?.split('/').at(-1) ?? '';
122
- const tests = program === 'test' || BRACKETS.has(program);
123
- if ((tests && !tokens.some((token) => COMPARISON.test(token))) || NEVER_RUNS.test(program)) {
124
- return false;
125
- }
126
- const script = scriptOf(tokens);
127
- return (namesPath(tokens.join(' '), deliverable) ||
128
- (script !== undefined && proving.some((path) => samePath(script, path))) ||
129
- runsTests(tokens));
130
- }));
131
- }
132
- export function sourceFile(path) {
133
- return SOURCE.test(path);
134
- }
135
- export function runsCode(command, edited) {
136
- const segments = exitSegments(command.replace(HEREDOC, '$1'));
137
- return segments.find((segment, at) => {
138
- const tokens = commandOf(segment);
139
- const program = tokens[0]?.split('/').at(-1) ?? '';
140
- if (program === 'test' || BRACKETS.has(program)) {
141
- return false;
142
- }
143
- const script = INTERPRETER.test(program) ? interpreted(tokens) : tokens[0];
144
- return (runsSuite(tokens) ||
145
- runsProject(tokens) ||
146
- (!!tokens[0]?.includes('/') &&
147
- !SYSTEM_BIN.test(tokens[0]) &&
148
- segments.slice(0, at).some((part) => builds(commandOf(part)))) ||
149
- (script !== undefined &&
150
- (edited.some((path) => samePath(script, path)) ||
151
- TEST_SCRIPT.test(script.split('/').at(-1) ?? ''))));
152
- });
153
- }
154
- export function runsCodeCheck(command, checks) {
155
- return checks.find((check) => runsCheck(command, check) &&
156
- exitSegments(check).some((segment) => {
157
- const tokens = commandOf(segment);
158
- return runsSuite(tokens) || sourceFile(scriptOf(tokens) ?? '');
159
- }));
160
- }
161
- function interpreted(tokens) {
162
- const program = tokens[0]?.split('/').at(-1) ?? '';
163
- let at = 1;
164
- for (; tokens[at]?.startsWith('-'); at++) {
165
- if (tokens[at] === '-m' || SYNTAX_ONLY.test(`${program} ${tokens[at]}`)) {
166
- return undefined;
167
- }
168
- }
169
- return (program === 'bun' || program === 'deno' || program === 'go') && tokens[at] === 'run'
170
- ? tokens[at + 1]
171
- : tokens[at];
172
- }
173
- function runsProject(tokens) {
174
- const program = tokens[0]?.split('/').at(-1) ?? '';
175
- const [, next, target = ''] = tokens;
176
- return ((program === 'cargo' && next === 'run') ||
177
- (program === 'go' && next === 'run' && !target.endsWith('.go')));
178
- }
179
- function builds(tokens) {
180
- const program = tokens[0]?.split('/').at(-1) ?? '';
181
- const next = tokens[1];
182
- return ((COMPILER.test(program) && !tokens.includes('-c')) ||
183
- ((program === 'go' || program === 'cargo') && next === 'build') ||
184
- (program === 'make' &&
185
- !tokens.some((token) => MAKE_DRY_RUN.test(token)) &&
186
- !cleansOnly(tokens.slice(1).filter((token) => !token.startsWith('-')))) ||
187
- (program === 'cmake' &&
188
- tokens.includes('--build') &&
189
- !cleansOnly(tokens.slice(tokens.indexOf('--target') + 1))));
190
- }
191
- function cleansOnly(tokens) {
192
- const end = tokens.findIndex((token) => token.startsWith('-'));
193
- const targets = end === -1 ? tokens : tokens.slice(0, end);
194
- return targets.length > 0 && targets.every((target) => CLEAN.test(target));
195
- }
196
- export function runsScript(check, paths) {
197
- return exitSegments(check).some((segment) => {
198
- const script = scriptOf(commandOf(segment));
199
- return script !== undefined && paths.some((path) => samePath(script, path));
200
- });
201
- }
202
- function runsTests(tokens) {
203
- const program = tokens[0]?.split('/').at(-1) ?? '';
204
- if (program === 'pytest' || PYTHON.test(program)) {
205
- return (program === 'pytest' || testRunner(tokens)) && scriptOf(tokens) === undefined;
206
- }
207
- return testRunner(tokens);
208
- }
209
- function runsSuite(tokens) {
210
- const program = tokens[0]?.split('/').at(-1) ?? '';
211
- return (program === 'pytest' ||
212
- program === 'ctest' ||
213
- (program === 'node' && tokens.includes('--test')) ||
214
- testRunner(tokens));
215
- }
216
- function testRunner(tokens) {
217
- const program = tokens[0]?.split('/').at(-1) ?? '';
218
- const [, next = '', third = ''] = tokens;
219
- const module = tokens.indexOf('-m');
220
- return ((PACKAGE_MANAGER.test(program) && PACKAGE_TEST.test(next === 'run' ? third : next)) ||
221
- ((program === 'cargo' || program === 'go') && next === 'test') ||
222
- (program === 'make' && (next === 'test' || next === 'check')) ||
223
- (PYTHON.test(program) && module > 0 && /^(pytest|unittest)$/.test(tokens[module + 1] ?? '')));
224
- }
225
- export function namesPath(text, paths) {
226
- return text
227
- .split(PATH_BREAK)
228
- .some((token) => token && paths.some((path) => samePath(token, path)));
229
- }
230
- export function writtenTexts(args) {
231
- const text = args.content ?? args.new;
232
- if (typeof args.path === 'string' && typeof text === 'string') {
233
- return [[args.path, text]];
234
- }
235
- const { command } = args;
236
- if (typeof command !== 'string') {
237
- return [];
238
- }
239
- const heredocs = [...command.matchAll(HEREDOC)].map((match) => ({
240
- opened: match.index + match[1].length,
241
- end: match.index + match[0].length,
242
- body: match[4] ?? ''
243
- }));
244
- const written = [];
245
- for (const match of command.matchAll(WRITE)) {
246
- const [, , target] = match;
247
- const inBody = heredocs.some(({ opened, end }) => match.index > opened && match.index < end);
248
- if (inBody || target.startsWith('/dev/')) {
249
- continue;
250
- }
251
- const close = command.indexOf('\n', match.index);
252
- const line = command.slice(command.lastIndexOf('\n', match.index) + 1, close < 0 ? undefined : close);
253
- written.push([target, heredocs.find(({ opened }) => opened === close)?.body ?? line]);
254
- }
255
- return written;
256
- }
257
- export function provesResult(command) {
258
- return exitSegments(command).find(proves);
259
- }
260
- function proves(segment) {
261
- if (segment.split('"').length % 2 === 0 || segment.split("'").length % 2 === 0) {
262
- return false;
263
- }
264
- const tokens = commandOf(segment);
265
- const program = tokens[0]?.split('/').at(-1) ?? '';
266
- const python = PYTHON.test(program);
267
- if (program === 'test' || program === '[' || program === '[[') {
268
- return tokens.some((token) => COMPARISON.test(token));
269
- }
270
- if ((python && tokens.includes('-c')) || (program === 'node' && tokens.includes('-e'))) {
271
- return /\bassert\b/.test(segment);
272
- }
273
- return (COMPARE.test(program) ||
274
- (program === 'grep' && tokens.some((token) => QUIET.test(token))) ||
275
- runsSuite(tokens) ||
276
- TEST_SCRIPT.test(scriptOf(tokens)?.split('/').at(-1) ?? ''));
277
- }
278
- function scriptOf(tokens) {
279
- let at = 0;
280
- if (RUNNER.test(tokens[0]?.split('/').at(-1) ?? '')) {
281
- at++;
282
- while (tokens[at]?.startsWith('-')) {
283
- at += tokens[at] === '-m' ? 2 : 1;
284
- }
285
- }
286
- return tokens[at];
287
- }
288
- export function citesPassed(text, passed) {
289
- const lines = text.split('\n');
290
- const heading = lines.findIndex((line) => CHECKS_HEADING.test(line));
291
- const cited = lines.slice(0, heading < 0 ? undefined : heading).join('\n');
292
- return [...cited.matchAll(SPAN)].some(([, span]) => passed.some((command) => runsCheck(span, command)));
293
- }
294
- export function namedChecks(text) {
295
- const lines = text.split('\n');
296
- const heading = lines.findIndex((line) => CHECKS_HEADING.test(line));
297
- if (heading < 0) {
298
- return [];
299
- }
300
- const named = [];
301
- for (const line of lines.slice(heading + 1)) {
302
- const command = CHECK_LINE.exec(line)?.[1].trim();
303
- if (!command) {
304
- if (line.trim() || named.length) {
305
- break;
306
- }
307
- continue;
308
- }
309
- if (runsCheck(command, command) && !named.includes(command)) {
310
- named.push(command);
311
- }
312
- }
313
- return named.slice(0, MAX_GOAL_CHECKS);
314
- }
315
- export function mergeChecks(host, named) {
316
- const known = new Set(host.map(normalize));
317
- const fresh = named
318
- .filter((name) => !known.has(normalize(name)))
319
- .slice(0, host.length ? MAX_GOAL_CHECKS - 1 : MAX_GOAL_CHECKS);
320
- if (!fresh.length) {
321
- return [];
322
- }
323
- return [...host.slice(0, MAX_GOAL_CHECKS - fresh.length), ...fresh];
324
- }
325
- function normalize(command) {
326
- return command.trim().replace(/\s+/g, ' ');
327
- }
328
- export function runsCheck(command, check) {
329
- const named = words(check);
330
- const wanted = named.slice(Math.max(commandStart(named), 0));
331
- return exitSegments(command).some((segment) => invokes(words(segment), wanted));
332
- }
333
- function exitSegments(command) {
334
- const parts = command.split(SHELL_OPERATOR);
335
- for (let at = parts.length - 1; at >= 0; at -= 2) {
336
- if (!parts[at].trim()) {
337
- parts.splice(at === parts.length - 1 ? Math.max(at - 1, 0) : at, 2);
338
- }
339
- }
340
- const segments = [];
341
- for (let at = 0; at < parts.length; at += 2) {
342
- const after = parts.slice(at + 1).filter((_, n) => n % 2 === 0);
343
- if (parts[at - 1] !== '||' && after.every((operator) => operator === '&&')) {
344
- segments.push(parts[at].trim());
345
- }
346
- }
347
- return segments;
348
- }
349
- function commandOf(segment) {
350
- const all = words(segment);
351
- return all.slice(Math.max(commandStart(all), 0));
352
- }
353
- function words(text) {
354
- return text
355
- .trim()
356
- .split(/\s+/)
357
- .filter(Boolean)
358
- .map((word) => word.replace(/^['"]|['"]$/g, ''));
359
- }
360
- function invokes(tokens, wanted) {
361
- let start = commandStart(tokens);
362
- if (start < 0) {
363
- return false;
364
- }
365
- if (leads(tokens.slice(start), wanted)) {
366
- return true;
367
- }
368
- if (!RUNNER.test(tokens[start].split('/').at(-1) ?? '')) {
369
- return false;
370
- }
371
- start++;
372
- while (tokens[start]?.startsWith('-')) {
373
- start++;
374
- }
375
- return leads(tokens.slice(start), wanted);
376
- }
377
- function commandStart(tokens) {
378
- let at = 0;
379
- while (at < tokens.length) {
380
- if (/^\w+=/.test(tokens[at])) {
381
- at++;
382
- continue;
383
- }
384
- const wrapper = tokens[at].split('/').at(-1) ?? '';
385
- const takesValue = WRAPPERS.get(wrapper);
386
- if (!takesValue) {
387
- return at;
388
- }
389
- at++;
390
- while (tokens[at]?.startsWith('-')) {
391
- at += takesValue.test(tokens[at]) ? 2 : 1;
392
- }
393
- if (wrapper === 'timeout') {
394
- at++;
395
- }
396
- }
397
- return -1;
398
- }
399
- function leads(tokens, wanted) {
400
- return (wanted.length > 0 &&
401
- wanted.every((word, at) => tokens[at] !== undefined && samePath(tokens[at], word)));
402
- }
403
- export function samePath(a, b) {
404
- const left = a.replace(/^\.\//, '');
405
- const right = b.replace(/^\.\//, '');
406
- return left === right || left.endsWith(`/${right}`) || right.endsWith(`/${left}`);
1
+ import { GOAL_CASES_ASK, GOAL_CHECKS_ASK, GOAL_PROOF_ASK, GOAL_REVIEW_ASK, MAX_PROOF_ASKS, asksChecks, asksDeliverable, asksRun, codeUnrun, deliverableAsk, deliverableChecked, runAsk } from './goal-check/asks.js';
2
+ import { MAX_GOAL_CHECKS, MAX_PROVING, citesPassed, existenceOnly, mergeChecks, namedChecks, pathsOf, runsDeliverable } from './goal-check/checks.js';
3
+ import { provesResult, runsCheck, runsCode, runsCodeCheck, runsScript } from './goal-check/commands.js';
4
+ import { namesPath, samePath, sourceFile, writtenTexts } from './goal-check/paths.js';
5
+ export class GoalCheck {
6
+ static GOAL_CASES_ASK = GOAL_CASES_ASK;
7
+ static GOAL_CHECKS_ASK = GOAL_CHECKS_ASK;
8
+ static GOAL_PROOF_ASK = GOAL_PROOF_ASK;
9
+ static GOAL_REVIEW_ASK = GOAL_REVIEW_ASK;
10
+ static MAX_GOAL_CHECKS = MAX_GOAL_CHECKS;
11
+ static MAX_PROOF_ASKS = MAX_PROOF_ASKS;
12
+ static MAX_PROVING = MAX_PROVING;
13
+ static asksChecks = asksChecks;
14
+ static asksDeliverable = asksDeliverable;
15
+ static asksRun = asksRun;
16
+ static citesPassed = citesPassed;
17
+ static codeUnrun = codeUnrun;
18
+ static deliverableAsk = deliverableAsk;
19
+ static deliverableChecked = deliverableChecked;
20
+ static existenceOnly = existenceOnly;
21
+ static mergeChecks = mergeChecks;
22
+ static namedChecks = namedChecks;
23
+ static namesPath = namesPath;
24
+ static pathsOf = pathsOf;
25
+ static provesResult = provesResult;
26
+ static runAsk = runAsk;
27
+ static runsCheck = runsCheck;
28
+ static runsCode = runsCode;
29
+ static runsCodeCheck = runsCodeCheck;
30
+ static runsDeliverable = runsDeliverable;
31
+ static runsScript = runsScript;
32
+ static samePath = samePath;
33
+ static sourceFile = sourceFile;
34
+ static writtenTexts = writtenTexts;
407
35
  }
@@ -0,0 +1,7 @@
1
+ export declare class RecentMap<K, V> {
2
+ private readonly _max;
3
+ private readonly _entries;
4
+ constructor(max: number);
5
+ get(key: K): V | undefined;
6
+ set(key: K, value: V): void;
7
+ }
@@ -0,0 +1,23 @@
1
+ export class RecentMap {
2
+ _max;
3
+ _entries = new Map();
4
+ constructor(max) {
5
+ this._max = max;
6
+ }
7
+ get(key) {
8
+ const value = this._entries.get(key);
9
+ if (value !== undefined) {
10
+ this.set(key, value);
11
+ }
12
+ return value;
13
+ }
14
+ set(key, value) {
15
+ this._entries.delete(key);
16
+ this._entries.set(key, value);
17
+ for (const oldest of this._entries.keys()) {
18
+ if (this._entries.size <= this._max)
19
+ break;
20
+ this._entries.delete(oldest);
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,6 @@
1
+ export interface MarkupToolCall {
2
+ readonly name: string;
3
+ readonly arguments?: Record<string, unknown>;
4
+ }
5
+ export declare function toolCallMarkup(calls: ReadonlyArray<MarkupToolCall>): string;
6
+ export declare function functionMarkup(call: MarkupToolCall): string;