@namzu/sdk 59.0.0 → 60.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/dist/compaction/context-window.d.ts +53 -0
  3. package/dist/compaction/context-window.d.ts.map +1 -1
  4. package/dist/compaction/context-window.js +141 -2
  5. package/dist/compaction/context-window.js.map +1 -1
  6. package/dist/execution/workflow/index.d.ts +3 -1
  7. package/dist/execution/workflow/index.d.ts.map +1 -1
  8. package/dist/execution/workflow/index.js +2 -1
  9. package/dist/execution/workflow/index.js.map +1 -1
  10. package/dist/execution/workflow/journal.d.ts +24 -4
  11. package/dist/execution/workflow/journal.d.ts.map +1 -1
  12. package/dist/execution/workflow/journal.js +131 -9
  13. package/dist/execution/workflow/journal.js.map +1 -1
  14. package/dist/execution/workflow/prelude.d.ts +2 -0
  15. package/dist/execution/workflow/prelude.d.ts.map +1 -1
  16. package/dist/execution/workflow/prelude.js +49 -8
  17. package/dist/execution/workflow/prelude.js.map +1 -1
  18. package/dist/execution/workflow/resume.d.ts +59 -0
  19. package/dist/execution/workflow/resume.d.ts.map +1 -0
  20. package/dist/execution/workflow/resume.js +273 -0
  21. package/dist/execution/workflow/resume.js.map +1 -0
  22. package/dist/execution/workflow/runtime.d.ts.map +1 -1
  23. package/dist/execution/workflow/runtime.js +112 -8
  24. package/dist/execution/workflow/runtime.js.map +1 -1
  25. package/dist/execution/workflow/types.d.ts +105 -1
  26. package/dist/execution/workflow/types.d.ts.map +1 -1
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +4 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/plugin/compat.d.ts +24 -0
  32. package/dist/plugin/compat.d.ts.map +1 -0
  33. package/dist/plugin/compat.js +149 -0
  34. package/dist/plugin/compat.js.map +1 -0
  35. package/dist/plugin/loader.d.ts +2 -1
  36. package/dist/plugin/loader.d.ts.map +1 -1
  37. package/dist/plugin/loader.js +6 -0
  38. package/dist/plugin/loader.js.map +1 -1
  39. package/dist/pricing/index.d.ts.map +1 -1
  40. package/dist/pricing/index.js +2 -1
  41. package/dist/pricing/index.js.map +1 -1
  42. package/dist/process/kill-tree.d.ts +44 -0
  43. package/dist/process/kill-tree.d.ts.map +1 -1
  44. package/dist/process/kill-tree.js +102 -4
  45. package/dist/process/kill-tree.js.map +1 -1
  46. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  47. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  48. package/dist/prompt/coding-agent-doctrine.js +9 -1
  49. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  50. package/dist/provider/model-window-suffix.d.ts +18 -0
  51. package/dist/provider/model-window-suffix.d.ts.map +1 -0
  52. package/dist/provider/model-window-suffix.js +77 -0
  53. package/dist/provider/model-window-suffix.js.map +1 -0
  54. package/dist/public-runtime.d.ts +5 -3
  55. package/dist/public-runtime.d.ts.map +1 -1
  56. package/dist/public-runtime.js +5 -4
  57. package/dist/public-runtime.js.map +1 -1
  58. package/dist/public-types.d.ts +1 -0
  59. package/dist/public-types.d.ts.map +1 -1
  60. package/dist/registry/command/kernel-commands.d.ts +1 -4
  61. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  62. package/dist/registry/command/kernel-commands.js +0 -28
  63. package/dist/registry/command/kernel-commands.js.map +1 -1
  64. package/dist/runtime/jobs/awaited-jobs.d.ts +6 -0
  65. package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -1
  66. package/dist/runtime/jobs/awaited-jobs.js +11 -0
  67. package/dist/runtime/jobs/awaited-jobs.js.map +1 -1
  68. package/dist/runtime/jobs/host-exit-finalizer.d.ts +20 -0
  69. package/dist/runtime/jobs/host-exit-finalizer.d.ts.map +1 -0
  70. package/dist/runtime/jobs/host-exit-finalizer.js +57 -0
  71. package/dist/runtime/jobs/host-exit-finalizer.js.map +1 -0
  72. package/dist/runtime/jobs/liveness.d.ts +67 -0
  73. package/dist/runtime/jobs/liveness.d.ts.map +1 -0
  74. package/dist/runtime/jobs/liveness.js +94 -0
  75. package/dist/runtime/jobs/liveness.js.map +1 -0
  76. package/dist/runtime/jobs/registry.d.ts +21 -0
  77. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  78. package/dist/runtime/jobs/registry.js +104 -2
  79. package/dist/runtime/jobs/registry.js.map +1 -1
  80. package/dist/runtime/jobs/wake-budget.d.ts +35 -0
  81. package/dist/runtime/jobs/wake-budget.d.ts.map +1 -0
  82. package/dist/runtime/jobs/wake-budget.js +48 -0
  83. package/dist/runtime/jobs/wake-budget.js.map +1 -0
  84. package/dist/runtime/query/detached-calls.d.ts +65 -0
  85. package/dist/runtime/query/detached-calls.d.ts.map +1 -0
  86. package/dist/runtime/query/detached-calls.js +116 -0
  87. package/dist/runtime/query/detached-calls.js.map +1 -0
  88. package/dist/runtime/query/executor.d.ts +4 -1
  89. package/dist/runtime/query/executor.d.ts.map +1 -1
  90. package/dist/runtime/query/executor.js +90 -6
  91. package/dist/runtime/query/executor.js.map +1 -1
  92. package/dist/runtime/query/index.d.ts +20 -0
  93. package/dist/runtime/query/index.d.ts.map +1 -1
  94. package/dist/runtime/query/index.js +31 -5
  95. package/dist/runtime/query/index.js.map +1 -1
  96. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  97. package/dist/runtime/query/iteration/outstanding-work.js +11 -3
  98. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  99. package/dist/runtime/query/iteration/phases/context.d.ts +7 -0
  100. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  101. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  102. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  103. package/dist/runtime/query/iteration/phases/tool-review.js +63 -1
  104. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  105. package/dist/runtime/query/session-storage.d.ts.map +1 -1
  106. package/dist/runtime/query/session-storage.js +8 -3
  107. package/dist/runtime/query/session-storage.js.map +1 -1
  108. package/dist/runtime/query/steering.d.ts +29 -3
  109. package/dist/runtime/query/steering.d.ts.map +1 -1
  110. package/dist/runtime/query/steering.js +58 -3
  111. package/dist/runtime/query/steering.js.map +1 -1
  112. package/dist/runtime/query/tooling.d.ts +1 -0
  113. package/dist/runtime/query/tooling.d.ts.map +1 -1
  114. package/dist/runtime/query/tooling.js +1 -0
  115. package/dist/runtime/query/tooling.js.map +1 -1
  116. package/dist/runtime/system-events.d.ts +5 -0
  117. package/dist/runtime/system-events.d.ts.map +1 -1
  118. package/dist/runtime/system-events.js +7 -1
  119. package/dist/runtime/system-events.js.map +1 -1
  120. package/dist/sandbox/denial.d.ts +11 -0
  121. package/dist/sandbox/denial.d.ts.map +1 -0
  122. package/dist/sandbox/denial.js +61 -0
  123. package/dist/sandbox/denial.js.map +1 -0
  124. package/dist/sandbox/file-walk-program.d.ts.map +1 -1
  125. package/dist/sandbox/file-walk-program.js +31 -13
  126. package/dist/sandbox/file-walk-program.js.map +1 -1
  127. package/dist/sandbox/file-walk.d.ts +2 -0
  128. package/dist/sandbox/file-walk.d.ts.map +1 -1
  129. package/dist/sandbox/file-walk.js +64 -13
  130. package/dist/sandbox/file-walk.js.map +1 -1
  131. package/dist/sandbox/ignore-matcher.d.ts +30 -0
  132. package/dist/sandbox/ignore-matcher.d.ts.map +1 -0
  133. package/dist/sandbox/ignore-matcher.js +11 -0
  134. package/dist/sandbox/ignore-matcher.js.map +1 -0
  135. package/dist/sandbox/ignore-source.d.ts +26 -0
  136. package/dist/sandbox/ignore-source.d.ts.map +1 -0
  137. package/dist/sandbox/ignore-source.js +221 -0
  138. package/dist/sandbox/ignore-source.js.map +1 -0
  139. package/dist/sandbox/provider/local.d.ts.map +1 -1
  140. package/dist/sandbox/provider/local.js +11 -1
  141. package/dist/sandbox/provider/local.js.map +1 -1
  142. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  143. package/dist/scheduler/completion-inbox.js +1 -0
  144. package/dist/scheduler/completion-inbox.js.map +1 -1
  145. package/dist/session/log-hash.d.ts.map +1 -1
  146. package/dist/session/log-hash.js +18 -1
  147. package/dist/session/log-hash.js.map +1 -1
  148. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  149. package/dist/store/session-index/sqlite.js +169 -16
  150. package/dist/store/session-index/sqlite.js.map +1 -1
  151. package/dist/tools/builtins/bash.d.ts.map +1 -1
  152. package/dist/tools/builtins/bash.js +10 -4
  153. package/dist/tools/builtins/bash.js.map +1 -1
  154. package/dist/tools/builtins/computer-use.d.ts +35 -0
  155. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  156. package/dist/tools/builtins/computer-use.js +512 -67
  157. package/dist/tools/builtins/computer-use.js.map +1 -1
  158. package/dist/tools/builtins/glob.d.ts +1 -0
  159. package/dist/tools/builtins/glob.d.ts.map +1 -1
  160. package/dist/tools/builtins/glob.js +65 -28
  161. package/dist/tools/builtins/glob.js.map +1 -1
  162. package/dist/tools/builtins/grep.d.ts +2 -0
  163. package/dist/tools/builtins/grep.d.ts.map +1 -1
  164. package/dist/tools/builtins/grep.js +94 -40
  165. package/dist/tools/builtins/grep.js.map +1 -1
  166. package/dist/tools/builtins/job.d.ts +1 -1
  167. package/dist/tools/builtins/job.d.ts.map +1 -1
  168. package/dist/tools/builtins/job.js +34 -7
  169. package/dist/tools/builtins/job.js.map +1 -1
  170. package/dist/tools/builtins/search-support.d.ts +44 -0
  171. package/dist/tools/builtins/search-support.d.ts.map +1 -0
  172. package/dist/tools/builtins/search-support.js +89 -0
  173. package/dist/tools/builtins/search-support.js.map +1 -0
  174. package/dist/tools/builtins/wait-for-job-bounds.d.ts +2 -0
  175. package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
  176. package/dist/tools/builtins/wait-for-job-bounds.js +3 -1
  177. package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
  178. package/dist/tools/builtins/wait-for-job.d.ts +1 -1
  179. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  180. package/dist/tools/builtins/wait-for-job.js +13 -2
  181. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  182. package/dist/tools/command-shell.d.ts.map +1 -1
  183. package/dist/tools/command-shell.js +14 -5
  184. package/dist/tools/command-shell.js.map +1 -1
  185. package/dist/types/computer-use/index.d.ts +129 -13
  186. package/dist/types/computer-use/index.d.ts.map +1 -1
  187. package/dist/types/computer-use/index.js.map +1 -1
  188. package/dist/types/plugin/index.d.ts +24 -0
  189. package/dist/types/plugin/index.d.ts.map +1 -1
  190. package/dist/types/plugin/index.js +4 -0
  191. package/dist/types/plugin/index.js.map +1 -1
  192. package/dist/types/sandbox/index.d.ts +38 -1
  193. package/dist/types/sandbox/index.d.ts.map +1 -1
  194. package/dist/types/sandbox/index.js.map +1 -1
  195. package/dist/types/session/records.d.ts +264 -0
  196. package/dist/types/session/records.d.ts.map +1 -1
  197. package/dist/types/session/records.js +32 -1
  198. package/dist/types/session/records.js.map +1 -1
  199. package/dist/types/tool/index.d.ts +30 -0
  200. package/dist/types/tool/index.d.ts.map +1 -1
  201. package/dist/types/tool/index.js.map +1 -1
  202. package/dist/types/tool/presentation.d.ts +8 -0
  203. package/dist/types/tool/presentation.d.ts.map +1 -1
  204. package/package.json +1 -1
  205. package/src/compaction/context-window.ts +163 -2
  206. package/src/execution/workflow/index.ts +14 -1
  207. package/src/execution/workflow/journal.ts +161 -11
  208. package/src/execution/workflow/prelude.ts +51 -8
  209. package/src/execution/workflow/resume.ts +313 -0
  210. package/src/execution/workflow/runtime.ts +127 -9
  211. package/src/execution/workflow/types.ts +109 -1
  212. package/src/index.ts +17 -0
  213. package/src/plugin/compat.ts +173 -0
  214. package/src/plugin/loader.ts +7 -1
  215. package/src/pricing/index.ts +2 -1
  216. package/src/process/kill-tree.ts +106 -4
  217. package/src/prompt/coding-agent-doctrine.ts +9 -1
  218. package/src/provider/model-window-suffix.ts +84 -0
  219. package/src/public-runtime.ts +21 -2
  220. package/src/public-types.ts +1 -0
  221. package/src/registry/command/kernel-commands.ts +1 -32
  222. package/src/runtime/jobs/awaited-jobs.ts +11 -0
  223. package/src/runtime/jobs/host-exit-finalizer.ts +67 -0
  224. package/src/runtime/jobs/liveness.ts +144 -0
  225. package/src/runtime/jobs/registry.ts +114 -2
  226. package/src/runtime/jobs/wake-budget.ts +55 -0
  227. package/src/runtime/query/detached-calls.ts +135 -0
  228. package/src/runtime/query/executor.ts +92 -10
  229. package/src/runtime/query/index.ts +50 -7
  230. package/src/runtime/query/iteration/outstanding-work.ts +12 -3
  231. package/src/runtime/query/iteration/phases/context.ts +7 -0
  232. package/src/runtime/query/iteration/phases/tool-review.ts +73 -8
  233. package/src/runtime/query/session-storage.ts +8 -3
  234. package/src/runtime/query/steering.ts +77 -6
  235. package/src/runtime/query/tooling.ts +2 -0
  236. package/src/runtime/system-events.ts +12 -1
  237. package/src/sandbox/denial.ts +79 -0
  238. package/src/sandbox/file-walk-program.ts +32 -13
  239. package/src/sandbox/file-walk.ts +75 -12
  240. package/src/sandbox/ignore-matcher.ts +46 -0
  241. package/src/sandbox/ignore-source.ts +220 -0
  242. package/src/sandbox/provider/local.ts +11 -1
  243. package/src/scheduler/completion-inbox.ts +1 -0
  244. package/src/session/log-hash.ts +21 -0
  245. package/src/store/session-index/sqlite.ts +171 -16
  246. package/src/tools/builtins/bash.ts +11 -4
  247. package/src/tools/builtins/computer-use.ts +593 -68
  248. package/src/tools/builtins/glob.ts +79 -32
  249. package/src/tools/builtins/grep.ts +107 -43
  250. package/src/tools/builtins/job.ts +42 -12
  251. package/src/tools/builtins/search-support.ts +107 -0
  252. package/src/tools/builtins/wait-for-job-bounds.ts +5 -1
  253. package/src/tools/builtins/wait-for-job.ts +14 -2
  254. package/src/tools/command-shell.ts +13 -5
  255. package/src/types/computer-use/index.ts +157 -15
  256. package/src/types/plugin/index.ts +8 -0
  257. package/src/types/sandbox/index.ts +40 -1
  258. package/src/types/session/records.ts +36 -2
  259. package/src/types/tool/index.ts +30 -0
  260. package/src/types/tool/presentation.ts +8 -0
@@ -1,6 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { appendFile, mkdir, writeFile } from 'node:fs/promises';
3
- import { join } from 'node:path';
2
+ import { mkdir, open, readFile, stat, writeFile } from 'node:fs/promises';
3
+ import { basename, dirname, join, resolve } from 'node:path';
4
+ import { formatWorkflowJournalLine, readWorkflowJournalChecked, workflowJournalLineHash, workflowJournalSeed, } from './resume.js';
4
5
  export function sha256(text) {
5
6
  return createHash('sha256').update(text).digest('hex');
6
7
  }
@@ -14,30 +15,151 @@ export function preview(text, max = 500) {
14
15
  end--;
15
16
  return `${text.slice(0, end)}…`;
16
17
  }
18
+ const chains = new Map();
19
+ /** Records after which a crash must not lose the line: a saved result, the end of a pass, the start of one. */
20
+ function mustSurviveCrash(record) {
21
+ return (record.type === 'run_finished' ||
22
+ record.type === 'run_started' ||
23
+ (record.type === 'agent_outcome' && Object.hasOwn(record, 'result')));
24
+ }
17
25
  /**
18
26
  * A journal in a directory: `script.js` (the exact script text, mode 0600)
19
27
  * and `journal.jsonl` (one JSON record per line, append-only). The caller
20
28
  * chooses the directory, normally `<session>/runs/<runId>/workflow/`.
29
+ *
30
+ * Every line carries `seq` and `prev` (the hash of the line before it, the
31
+ * first chaining from a seed bound to the run id), so a line that was edited,
32
+ * removed or cut short is found when the journal is read back. One writer per
33
+ * file serves the whole process: a resumed pass and a late agent of the pass
34
+ * before it append through the same queue and the same chain, and nothing is
35
+ * appended after a pass's `run_finished` until the next pass starts. This
36
+ * assumes one process writes the file at a time, which the session lease
37
+ * already guarantees. A chain proves the file was not damaged or edited by
38
+ * accident; someone who can rewrite the whole file can rewrite the chain too.
21
39
  */
22
40
  export class FileWorkflowJournal {
23
41
  dir;
42
+ options;
24
43
  ready;
25
- constructor(dir) {
44
+ file;
45
+ constructor(dir, options = {}) {
26
46
  this.dir = dir;
47
+ this.options = options;
48
+ this.file = resolve(dir, 'journal.jsonl');
27
49
  }
28
50
  ensure() {
29
51
  this.ready ??= mkdir(this.dir, { recursive: true, mode: 0o700 }).then(() => undefined);
30
52
  return this.ready;
31
53
  }
32
- async writeScript(source) {
33
- await this.ensure();
34
- await writeFile(join(this.dir, 'script.js'), source, { mode: 0o600 });
54
+ /** The run id of the file's first line, learned from the file or from the first `run_started` written. */
55
+ learned;
56
+ runId(record, text) {
57
+ if (this.options.runId !== undefined)
58
+ return this.options.runId;
59
+ if (record?.type === 'run_started')
60
+ this.learned = record.runId;
61
+ if (this.learned !== undefined)
62
+ return this.learned;
63
+ const first = text?.slice(0, text.indexOf('\n') < 0 ? undefined : text.indexOf('\n'));
64
+ if (first) {
65
+ try {
66
+ const parsed = JSON.parse(first);
67
+ if (parsed.type === 'run_started' && typeof parsed.runId === 'string') {
68
+ this.learned = parsed.runId;
69
+ return parsed.runId;
70
+ }
71
+ }
72
+ catch {
73
+ // Not a record: fall back to the folder name below.
74
+ }
75
+ }
76
+ return basename(dirname(resolve(this.dir)));
35
77
  }
36
- async append(record) {
78
+ async writeScript(source, _sha256, pass = 1) {
37
79
  await this.ensure();
38
- await appendFile(join(this.dir, 'journal.jsonl'), `${JSON.stringify(record)}\n`, {
39
- mode: 0o600,
80
+ const name = pass <= 1 ? 'script.js' : `script.${pass}.js`;
81
+ await writeFile(join(this.dir, name), source, { mode: 0o600 });
82
+ }
83
+ async read() {
84
+ let text;
85
+ try {
86
+ text = await readFile(this.file, 'utf8');
87
+ }
88
+ catch (error) {
89
+ if (error.code !== 'ENOENT')
90
+ throw error;
91
+ text = '';
92
+ }
93
+ return readWorkflowJournalChecked(text, this.runId(undefined, text), {
94
+ ...(this.options.key !== undefined ? { key: this.options.key } : {}),
95
+ });
96
+ }
97
+ append(record) {
98
+ let state = chains.get(this.file);
99
+ if (state === undefined) {
100
+ state = {
101
+ queue: Promise.resolve(),
102
+ loaded: false,
103
+ seq: 0,
104
+ prev: '',
105
+ needsNewline: false,
106
+ finished: false,
107
+ size: 0,
108
+ pending: 0,
109
+ };
110
+ chains.set(this.file, state);
111
+ }
112
+ const chain = state;
113
+ chain.pending++;
114
+ const run = chain.queue.then(async () => {
115
+ await this.ensure();
116
+ const onDisk = await stat(this.file).then((info) => info.size, () => 0);
117
+ if (!chain.loaded || onDisk !== chain.size) {
118
+ const checked = await this.read();
119
+ chain.seq = checked.lastSeq;
120
+ chain.prev = checked.lastHash;
121
+ chain.needsNewline = !checked.endsWithNewline;
122
+ chain.finished = checked.records.at(-1)?.type === 'run_finished';
123
+ chain.loaded = true;
124
+ chain.size = onDisk;
125
+ }
126
+ if (record.type === 'run_started')
127
+ chain.finished = false;
128
+ // Nothing belongs after the pass's end; a late agent of that pass is dropped here.
129
+ else if (chain.finished)
130
+ return;
131
+ if (chain.seq === 0)
132
+ chain.prev = workflowJournalSeed(this.runId(record));
133
+ const seq = chain.seq + 1;
134
+ const line = formatWorkflowJournalLine(record, seq, chain.prev, this.options.key);
135
+ const handle = await open(this.file, 'a', 0o600);
136
+ try {
137
+ const text = `${chain.needsNewline ? '\n' : ''}${line}\n`;
138
+ await handle.appendFile(text);
139
+ chain.size += Buffer.byteLength(text);
140
+ if (mustSurviveCrash(record))
141
+ await handle.datasync();
142
+ }
143
+ finally {
144
+ await handle.close();
145
+ }
146
+ chain.needsNewline = false;
147
+ chain.seq = seq;
148
+ chain.prev = workflowJournalLineHash(line);
149
+ if (record.type === 'run_finished')
150
+ chain.finished = true;
151
+ });
152
+ chain.queue = run
153
+ .catch(() => undefined)
154
+ .then(() => {
155
+ chain.pending--;
156
+ // A finished run keeps no state: the next append reads the file again, and
157
+ // what it finds (a last `run_finished`) is the same thing the state held.
158
+ if (chain.pending === 0 && chain.finished && chains.get(this.file) === chain) {
159
+ chains.delete(this.file);
160
+ }
40
161
  });
162
+ return run;
41
163
  }
42
164
  }
43
165
  //# sourceMappingURL=journal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal.js","sourceRoot":"","sources":["../../../src/execution/workflow/journal.ts"],"names":[],"mappings":"AAAA,OAAO,E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AAK,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAA;gBACzD,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;gBAC7B,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;gBACrC,IAAI,gBAAgB,CAAC,MAAM,CAAC;oBAAE,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAA;YACtD,CAAC;oBAAS,CAAC;gBACV,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;YACrB,CAAC;YACD,KAAK,CAAC,YAAY,GAAG,KAAK,CAAA;YAC1B,KAAK,CAAC,GAAG,GAAG,GAAG,CAAA;YACf,KAAK,CAAC,IAAI,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;YAC1C,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc;gBAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAA;QAC1D,CAAC,CAAC,CAAA;QACF,KAAK,CAAC,KAAK,GAAG,GAAG;aACf,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;aACtB,IAAI,CAAC,GAAG,EAAE;YACV,KAAK,CAAC,OAAO,EAAE,CAAA;YACf,2EAA2E;YAC3E,0EAA0E;YAC1E,IAAI,KAAK,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;gBAC9E,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACzB,CAAC;QACF,CAAC,CAAC,CAAA;QACH,OAAO,GAAG,CAAA;IACX,CAAC;CACD"}
@@ -6,10 +6,12 @@
6
6
  export declare function preludeLineCount(config: {
7
7
  args: unknown;
8
8
  tokenLimit: number | null;
9
+ deterministic?: boolean;
9
10
  }): number;
10
11
  /** Source that installs the workflow globals, ready to prepend to a script body. */
11
12
  export declare function buildPrelude(config: {
12
13
  args: unknown;
13
14
  tokenLimit: number | null;
15
+ deterministic?: boolean;
14
16
  }): string;
15
17
  //# sourceMappingURL=prelude.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prelude.d.ts","sourceRoot":"","sources":["../../../src/execution/workflow/prelude.ts"],"names":[],"mappings":"AAiJA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACxC,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,GAAG,MAAM,CAET;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,MAAM,EAAE;IACpC,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,GAAG,MAAM,CAOT"}
1
+ {"version":3,"file":"prelude.d.ts","sourceRoot":"","sources":["../../../src/execution/workflow/prelude.ts"],"names":[],"mappings":"AA0LA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACxC,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,MAAM,CAET;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,MAAM,EAAE;IACpC,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,MAAM,CAOT"}
@@ -28,7 +28,7 @@ const PRELUDE_SOURCE = String.raw `(function (config) {
28
28
  }
29
29
  function phase(title) {
30
30
  var t = clean(title, 120);
31
- if (!t) throw new TypeError('phase() needs a non-empty title.');
31
+ if (!t) throw misuse('phase() needs a non-empty title.');
32
32
  cursor = t;
33
33
  emit({ k: 'phase', title: t });
34
34
  }
@@ -53,13 +53,26 @@ const PRELUDE_SOURCE = String.raw `(function (config) {
53
53
  return e;
54
54
  }
55
55
  function isBudgetError(e) { return !!e && e.name === 'WorkflowBudgetExceededError'; }
56
+ function misuse(message) {
57
+ var e = new TypeError(message);
58
+ e.workflowMisuse = true;
59
+ return e;
60
+ }
61
+ function isMisuse(e) { return !!e && e.workflowMisuse === true; }
62
+ var optionNames = ['label', 'phase', 'schema', 'agentType', 'model', 'effort'];
56
63
  async function agent(prompt, opts) {
57
64
  if (typeof prompt !== 'string' || prompt.length === 0) {
58
- throw new TypeError('agent(prompt, options?): the prompt must be a non-empty string, got ' + kind(prompt));
65
+ throw misuse('agent(prompt, options?): the prompt must be a non-empty string, got ' + kind(prompt));
59
66
  }
60
67
  var o = opts == null ? {} : opts;
61
68
  if (typeof o !== 'object' || Array.isArray(o)) {
62
- throw new TypeError('agent(prompt, options?): options must be an object, got ' + kind(o));
69
+ throw misuse('agent(prompt, options?): options must be an object, got ' + kind(o));
70
+ }
71
+ var unknown = Object.keys(o).filter(function (k) { return optionNames.indexOf(k) < 0; });
72
+ if (unknown.length > 0) {
73
+ // Ignored, as it always was, but no longer silently: a saved script that
74
+ // misspells an option keeps running and the line says why it had no effect.
75
+ log('agent(prompt, options?): ignoring unknown option "' + unknown[0] + '"; the options are ' + optionNames.join(', ') + '.');
63
76
  }
64
77
  if (overBudget()) throw budgetError();
65
78
  var request = { prompt: prompt, cursor: cursor };
@@ -69,23 +82,32 @@ const PRELUDE_SOURCE = String.raw `(function (config) {
69
82
  if (o.agentType != null) request.agentType = clean(o.agentType, 120);
70
83
  if (o.model != null) request.model = clean(o.model, 120);
71
84
  if (o.effort != null) request.effort = clean(o.effort, 32);
72
- var reply = await rawCall('agent', request);
85
+ var reply;
86
+ try {
87
+ reply = await rawCall('agent', request);
88
+ } catch (e) {
89
+ // The host rejects a malformed request with an "agent(): ..." message;
90
+ // that is the script's mistake, not a failed child.
91
+ if (e && typeof e.message === 'string' && e.message.indexOf('agent(): ') === 0) throw misuse(e.message);
92
+ throw e;
93
+ }
73
94
  spent.tokensUsed = reply.t;
74
95
  return reply.v;
75
96
  }
76
97
  async function parallel(thunks) {
77
98
  if (!Array.isArray(thunks)) {
78
- throw new TypeError('parallel(thunks): the argument must be an array of functions, got ' + kind(thunks));
99
+ throw misuse('parallel(thunks): the argument must be an array of functions, got ' + kind(thunks));
79
100
  }
80
101
  for (var p = 0; p < thunks.length; p++) {
81
102
  if (typeof thunks[p] !== 'function') {
82
- throw new TypeError('parallel(thunks): item ' + (p + 1) + ' must be a function (wrap the work as () => agent(...)), got ' + kind(thunks[p]));
103
+ throw misuse('parallel(thunks): item ' + (p + 1) + ' must be a function (wrap the work as () => agent(...)), got ' + kind(thunks[p]));
83
104
  }
84
105
  }
85
106
  var dropped = 0;
86
107
  var results = await Promise.all(thunks.map(function (t, n) {
87
108
  return Promise.resolve().then(t).catch(function (e) {
88
109
  if (isBudgetError(e)) { dropped++; return null; }
110
+ if (isMisuse(e)) throw e;
89
111
  log('Step ' + (n + 1) + ' stopped: ' + clean(e && e.message ? e.message : e, 300));
90
112
  return null;
91
113
  });
@@ -95,12 +117,12 @@ const PRELUDE_SOURCE = String.raw `(function (config) {
95
117
  }
96
118
  async function pipeline(items) {
97
119
  if (!Array.isArray(items)) {
98
- throw new TypeError('pipeline(items, ...stages): the first argument must be an array, got ' + kind(items));
120
+ throw misuse('pipeline(items, ...stages): the first argument must be an array, got ' + kind(items));
99
121
  }
100
122
  var stages = Array.prototype.slice.call(arguments, 1);
101
123
  for (var s = 0; s < stages.length; s++) {
102
124
  if (typeof stages[s] !== 'function') {
103
- throw new TypeError('pipeline(items, ...stages): stage ' + (s + 1) + ' must be a function, got ' + kind(stages[s]));
125
+ throw misuse('pipeline(items, ...stages): stage ' + (s + 1) + ' must be a function, got ' + kind(stages[s]));
104
126
  }
105
127
  }
106
128
  if (items.length > 0 && overBudget()) throw budgetError();
@@ -112,6 +134,7 @@ const PRELUDE_SOURCE = String.raw `(function (config) {
112
134
  value = await stages[i](value, item, index);
113
135
  } catch (e) {
114
136
  if (isBudgetError(e)) { dropped++; return null; }
137
+ if (isMisuse(e)) throw e;
115
138
  log('Item ' + (index + 1) + ' stopped at step ' + (i + 1) + ': ' + clean(e && e.message ? e.message : e, 300));
116
139
  return null;
117
140
  }
@@ -141,6 +164,24 @@ const PRELUDE_SOURCE = String.raw `(function (config) {
141
164
  install('log', log);
142
165
  install('budget', budget);
143
166
  install('args', config.args);
167
+ if (config.deterministic) {
168
+ var RealDate = Date;
169
+ var clockMessage = 'Date.now() / new Date() are unavailable in workflow scripts (breaks resume). Stamp results after the workflow returns, or pass timestamps through args.';
170
+ var randomMessage = 'Math.random() is unavailable in workflow scripts (breaks resume). For N independent samples, include the index in the agent label or prompt.';
171
+ var ShimDate = function Date(a, b, c, d, e, f, g) {
172
+ if (!new.target || arguments.length === 0) throw new Error(clockMessage);
173
+ return Reflect.construct(RealDate, Array.prototype.slice.call(arguments), new.target === ShimDate ? RealDate : new.target);
174
+ };
175
+ Object.defineProperty(ShimDate, 'prototype', { value: RealDate.prototype, writable: false, configurable: false });
176
+ Object.defineProperty(ShimDate, 'now', { value: function now() { throw new Error(clockMessage); }, writable: false, configurable: false });
177
+ Object.defineProperty(ShimDate, 'parse', { value: RealDate.parse, writable: false, configurable: false });
178
+ Object.defineProperty(ShimDate, 'UTC', { value: RealDate.UTC, writable: false, configurable: false });
179
+ Object.defineProperty(RealDate.prototype, 'constructor', { value: ShimDate, writable: false, configurable: false });
180
+ Object.defineProperty(globalThis, 'Date', { value: ShimDate, writable: false, configurable: false, enumerable: false });
181
+ Object.defineProperty(Math, 'random', { value: function random() { throw new Error(randomMessage); }, writable: false, configurable: false });
182
+ try { delete globalThis.eval; } catch (ignored) {}
183
+ Object.freeze(RealDate);
184
+ }
144
185
  })`;
145
186
  /**
146
187
  * Lines the prelude occupies in the interpreter source, plus the newline that
@@ -1 +1 @@
1
- {"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../../src/execution/workflow/prelude.ts"],"names":[],"mappings":"AA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C,CAAC,MAAM,CAAA;AAC/C,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,YAAY,CAAC,MAI5B;IACA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;SACpC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;SAClC,IAAI,CAAC,SAAS,CAAC;SACf,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;SAClC,IAAI,CAAC,SAAS,CAAC,CAAA;IACjB,OAAO,GAAG,cAAc,IAAI,OAAO,IAAI,CAAA;AACxC,CAAC"}
@@ -0,0 +1,59 @@
1
+ import type { CheckedWorkflowJournal, WorkflowJournalRecord, WorkflowResumeState } from './types.js';
2
+ /** What of an `agent()` call decides its result. `label`, `phase` and progress callbacks do not. */
3
+ export interface WorkflowCallIdentity {
4
+ readonly schema?: unknown;
5
+ readonly model?: string;
6
+ readonly effort?: string;
7
+ readonly agentType?: string;
8
+ }
9
+ /**
10
+ * The key a call is saved and looked up under: the prompt, the options that
11
+ * change what the agent does (schema, model, effort, agent type) and how many
12
+ * identical calls came before it in the same pass. Each part is length-prefixed
13
+ * so one cannot be read as part of another.
14
+ */
15
+ export declare function workflowCallKey(prompt: string, call: WorkflowCallIdentity, ordinal: number): string;
16
+ /**
17
+ * What makes two calls the same call: the prompt and the options that change
18
+ * the agent, in a form where key order and `undefined` do not matter. The
19
+ * runtime counts repeats of this text to give identical calls distinct slots,
20
+ * and the key hashes the same text, so the two can never disagree.
21
+ */
22
+ export declare function workflowCallContent(prompt: string, call: WorkflowCallIdentity): string;
23
+ /** The hash the first line of a run's journal chains from. It binds the file to its run id. */
24
+ export declare function workflowJournalSeed(runId: string): string;
25
+ /** The hash a line contributes to the next one: its exact bytes, newline included. */
26
+ export declare function workflowJournalLineHash(line: string): string;
27
+ /** The line `record` is written as. With a key, a `mac` over the rest of the line is added last. */
28
+ export declare function formatWorkflowJournalLine(record: WorkflowJournalRecord, seq: number, prev: string, key?: string | Uint8Array): string;
29
+ /**
30
+ * Reads a journal's text and keeps only the records that can be trusted.
31
+ *
32
+ * Every line carries `seq` (counting trusted lines from 1) and `prev` (the hash
33
+ * of the line before; the first chains from a seed bound to the run id). A
34
+ * line that does not chain, a line that does not parse, and anything after
35
+ * one is dropped until a `run_started` of a resumed pass picks the chain up
36
+ * again at the last trusted line. A last line without its newline that is not
37
+ * whole JSON is a torn write and is ignored; one that is whole JSON is read
38
+ * like any other line. The file is never rewritten.
39
+ *
40
+ * The chain alone cannot notice an edit to the final line (nothing chains from
41
+ * it yet). With `key`, every line must also carry a `mac` made with that
42
+ * secret, which closes that gap against anyone who does not hold the key.
43
+ */
44
+ export declare function readWorkflowJournalChecked(text: string, runId: string, options?: {
45
+ readonly key?: string | Uint8Array;
46
+ }): CheckedWorkflowJournal;
47
+ /**
48
+ * Folds a checked journal into what a resumed pass needs.
49
+ *
50
+ * The last saved result for a key wins. An agent that was asked for again
51
+ * after a result was saved gives that result up until it finishes again. A
52
+ * failed or skipped outcome removes the result and marks the key failed; an
53
+ * outcome the run recorded as interrupted (stopped, not failed) leaves the key
54
+ * as seen but unfinished. Lines marked `cached` repeat an earlier result and
55
+ * are skipped, and so is any agent record from a pass older than the latest
56
+ * `run_started`, which a slow agent of an earlier pass can still write.
57
+ */
58
+ export declare function loadWorkflowResume(checked: CheckedWorkflowJournal): WorkflowResumeState;
59
+ //# sourceMappingURL=resume.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume.d.ts","sourceRoot":"","sources":["../../../src/execution/workflow/resume.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEX,sBAAsB,EAEtB,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,YAAY,CAAA;AAsBnB,oGAAoG;AACpG,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,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