@namzu/sdk 39.0.0 → 40.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 (183) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/dist/connector/mcp/adapter.d.ts.map +1 -1
  3. package/dist/connector/mcp/adapter.js +20 -6
  4. package/dist/connector/mcp/adapter.js.map +1 -1
  5. package/dist/manager/run/persistence.d.ts +8 -0
  6. package/dist/manager/run/persistence.d.ts.map +1 -1
  7. package/dist/manager/run/persistence.js +12 -0
  8. package/dist/manager/run/persistence.js.map +1 -1
  9. package/dist/public-runtime.d.ts +3 -1
  10. package/dist/public-runtime.d.ts.map +1 -1
  11. package/dist/public-runtime.js +5 -1
  12. package/dist/public-runtime.js.map +1 -1
  13. package/dist/public-tools.d.ts +11 -0
  14. package/dist/public-tools.d.ts.map +1 -1
  15. package/dist/public-tools.js +14 -0
  16. package/dist/public-tools.js.map +1 -1
  17. package/dist/registry/tool/execute.d.ts.map +1 -1
  18. package/dist/registry/tool/execute.js +2 -3
  19. package/dist/registry/tool/execute.js.map +1 -1
  20. package/dist/registry/tool/portable.d.ts +65 -0
  21. package/dist/registry/tool/portable.d.ts.map +1 -0
  22. package/dist/registry/tool/portable.js +244 -0
  23. package/dist/registry/tool/portable.js.map +1 -0
  24. package/dist/registry/tool/schema.d.ts +32 -5
  25. package/dist/registry/tool/schema.d.ts.map +1 -1
  26. package/dist/registry/tool/schema.js +35 -9
  27. package/dist/registry/tool/schema.js.map +1 -1
  28. package/dist/registry/toolset/catalog.js +8 -8
  29. package/dist/registry/toolset/catalog.js.map +1 -1
  30. package/dist/runtime/jobs/awaited-jobs.d.ts +215 -0
  31. package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -0
  32. package/dist/runtime/jobs/awaited-jobs.js +259 -0
  33. package/dist/runtime/jobs/awaited-jobs.js.map +1 -0
  34. package/dist/runtime/jobs/registry.d.ts +33 -2
  35. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  36. package/dist/runtime/jobs/registry.js +37 -0
  37. package/dist/runtime/jobs/registry.js.map +1 -1
  38. package/dist/runtime/query/executor.d.ts +28 -0
  39. package/dist/runtime/query/executor.d.ts.map +1 -1
  40. package/dist/runtime/query/executor.js +39 -1
  41. package/dist/runtime/query/executor.js.map +1 -1
  42. package/dist/runtime/query/file-evidence-context.d.ts.map +1 -1
  43. package/dist/runtime/query/file-evidence-context.js +159 -43
  44. package/dist/runtime/query/file-evidence-context.js.map +1 -1
  45. package/dist/runtime/query/file-evidence-replay.d.ts +260 -0
  46. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -0
  47. package/dist/runtime/query/file-evidence-replay.js +647 -0
  48. package/dist/runtime/query/file-evidence-replay.js.map +1 -0
  49. package/dist/runtime/query/file-evidence-seed.d.ts +50 -0
  50. package/dist/runtime/query/file-evidence-seed.d.ts.map +1 -0
  51. package/dist/runtime/query/file-evidence-seed.js +100 -0
  52. package/dist/runtime/query/file-evidence-seed.js.map +1 -0
  53. package/dist/runtime/query/index.d.ts.map +1 -1
  54. package/dist/runtime/query/index.js +94 -2
  55. package/dist/runtime/query/index.js.map +1 -1
  56. package/dist/runtime/query/iteration/index.d.ts +87 -9
  57. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  58. package/dist/runtime/query/iteration/index.js +193 -28
  59. package/dist/runtime/query/iteration/index.js.map +1 -1
  60. package/dist/runtime/query/iteration/phases/context.d.ts +10 -0
  61. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  62. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  63. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  64. package/dist/runtime/query/iteration/phases/tool-review.js +5 -1
  65. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  66. package/dist/runtime/query/plugin-hooks.d.ts +14 -0
  67. package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
  68. package/dist/runtime/query/plugin-hooks.js +18 -0
  69. package/dist/runtime/query/plugin-hooks.js.map +1 -1
  70. package/dist/runtime/query/repeat-call.d.ts +17 -4
  71. package/dist/runtime/query/repeat-call.d.ts.map +1 -1
  72. package/dist/runtime/query/repeat-call.js +26 -19
  73. package/dist/runtime/query/repeat-call.js.map +1 -1
  74. package/dist/runtime/query/steering.d.ts +11 -1
  75. package/dist/runtime/query/steering.d.ts.map +1 -1
  76. package/dist/runtime/query/steering.js +12 -1
  77. package/dist/runtime/query/steering.js.map +1 -1
  78. package/dist/runtime/query/tooling.d.ts +2 -0
  79. package/dist/runtime/query/tooling.d.ts.map +1 -1
  80. package/dist/runtime/query/tooling.js +1 -0
  81. package/dist/runtime/query/tooling.js.map +1 -1
  82. package/dist/scheduler/completion-inbox.d.ts +48 -2
  83. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  84. package/dist/scheduler/completion-inbox.js +102 -10
  85. package/dist/scheduler/completion-inbox.js.map +1 -1
  86. package/dist/tools/builtins/bash.d.ts.map +1 -1
  87. package/dist/tools/builtins/bash.js +4 -10
  88. package/dist/tools/builtins/bash.js.map +1 -1
  89. package/dist/tools/builtins/edit-apply.d.ts +126 -0
  90. package/dist/tools/builtins/edit-apply.d.ts.map +1 -0
  91. package/dist/tools/builtins/edit-apply.js +360 -0
  92. package/dist/tools/builtins/edit-apply.js.map +1 -0
  93. package/dist/tools/builtins/edit.d.ts +143 -1
  94. package/dist/tools/builtins/edit.d.ts.map +1 -1
  95. package/dist/tools/builtins/edit.js +37 -219
  96. package/dist/tools/builtins/edit.js.map +1 -1
  97. package/dist/tools/builtins/index.d.ts +1 -0
  98. package/dist/tools/builtins/index.d.ts.map +1 -1
  99. package/dist/tools/builtins/index.js +9 -3
  100. package/dist/tools/builtins/index.js.map +1 -1
  101. package/dist/tools/builtins/job.js +1 -1
  102. package/dist/tools/builtins/job.js.map +1 -1
  103. package/dist/tools/builtins/read-file.d.ts +2 -2
  104. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  105. package/dist/tools/builtins/read-file.js +50 -65
  106. package/dist/tools/builtins/read-file.js.map +1 -1
  107. package/dist/tools/builtins/read-render.d.ts +56 -0
  108. package/dist/tools/builtins/read-render.d.ts.map +1 -0
  109. package/dist/tools/builtins/read-render.js +73 -0
  110. package/dist/tools/builtins/read-render.js.map +1 -0
  111. package/dist/tools/builtins/wait-for-job-bounds.d.ts +67 -0
  112. package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -0
  113. package/dist/tools/builtins/wait-for-job-bounds.js +108 -0
  114. package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -0
  115. package/dist/tools/builtins/wait-for-job.d.ts +6 -0
  116. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -0
  117. package/dist/tools/builtins/wait-for-job.js +162 -0
  118. package/dist/tools/builtins/wait-for-job.js.map +1 -0
  119. package/dist/tools/builtins/write-file.js +5 -0
  120. package/dist/tools/builtins/write-file.js.map +1 -1
  121. package/dist/tools/coordinator/index.d.ts.map +1 -1
  122. package/dist/tools/coordinator/index.js +1 -7
  123. package/dist/tools/coordinator/index.js.map +1 -1
  124. package/dist/tools/file-read-tracker.d.ts.map +1 -1
  125. package/dist/tools/file-read-tracker.js +88 -10
  126. package/dist/tools/file-read-tracker.js.map +1 -1
  127. package/dist/types/message/index.d.ts +1 -1
  128. package/dist/types/message/index.d.ts.map +1 -1
  129. package/dist/types/message/index.js +2 -0
  130. package/dist/types/message/index.js.map +1 -1
  131. package/dist/types/run/entity.d.ts +13 -0
  132. package/dist/types/run/entity.d.ts.map +1 -1
  133. package/dist/types/sandbox/index.d.ts +15 -14
  134. package/dist/types/sandbox/index.d.ts.map +1 -1
  135. package/dist/types/sandbox/index.js.map +1 -1
  136. package/dist/types/tool/index.d.ts +109 -0
  137. package/dist/types/tool/index.d.ts.map +1 -1
  138. package/dist/types/tool/index.js.map +1 -1
  139. package/dist/utils/env.d.ts +19 -0
  140. package/dist/utils/env.d.ts.map +1 -0
  141. package/dist/utils/env.js +25 -0
  142. package/dist/utils/env.js.map +1 -0
  143. package/package.json +1 -1
  144. package/src/connector/mcp/adapter.ts +20 -6
  145. package/src/manager/run/persistence.ts +12 -0
  146. package/src/public-runtime.ts +9 -1
  147. package/src/public-tools.ts +18 -0
  148. package/src/registry/tool/execute.ts +2 -4
  149. package/src/registry/tool/portable.ts +264 -0
  150. package/src/registry/tool/schema.ts +38 -8
  151. package/src/registry/toolset/catalog.ts +8 -9
  152. package/src/runtime/jobs/awaited-jobs.ts +271 -0
  153. package/src/runtime/jobs/registry.ts +50 -0
  154. package/src/runtime/query/executor.ts +49 -1
  155. package/src/runtime/query/file-evidence-context.ts +190 -46
  156. package/src/runtime/query/file-evidence-replay.ts +776 -0
  157. package/src/runtime/query/file-evidence-seed.ts +126 -0
  158. package/src/runtime/query/index.ts +104 -2
  159. package/src/runtime/query/iteration/index.ts +202 -28
  160. package/src/runtime/query/iteration/phases/context.ts +10 -0
  161. package/src/runtime/query/iteration/phases/tool-review.ts +4 -0
  162. package/src/runtime/query/plugin-hooks.ts +20 -0
  163. package/src/runtime/query/repeat-call.ts +28 -18
  164. package/src/runtime/query/steering.ts +11 -0
  165. package/src/runtime/query/tooling.ts +3 -0
  166. package/src/scheduler/completion-inbox.ts +105 -9
  167. package/src/tools/builtins/bash.ts +4 -10
  168. package/src/tools/builtins/edit-apply.ts +456 -0
  169. package/src/tools/builtins/edit.ts +39 -270
  170. package/src/tools/builtins/index.ts +9 -3
  171. package/src/tools/builtins/job.ts +1 -1
  172. package/src/tools/builtins/read-file.ts +56 -77
  173. package/src/tools/builtins/read-render.ts +104 -0
  174. package/src/tools/builtins/wait-for-job-bounds.ts +179 -0
  175. package/src/tools/builtins/wait-for-job.ts +184 -0
  176. package/src/tools/builtins/write-file.ts +5 -0
  177. package/src/tools/coordinator/index.ts +1 -7
  178. package/src/tools/file-read-tracker.ts +85 -7
  179. package/src/types/message/index.ts +2 -0
  180. package/src/types/run/entity.ts +14 -0
  181. package/src/types/sandbox/index.ts +15 -14
  182. package/src/types/tool/index.ts +104 -0
  183. package/src/utils/env.ts +23 -0
@@ -113,6 +113,33 @@ export interface BackgroundJobRegistryRef {
113
113
  }
114
114
  kill(id: string): Promise<{ id: string; status: string }>
115
115
  list(): readonly { id: string; command: string; status: string }[]
116
+ /**
117
+ * Await this job's exit instead of reading it in a loop; resolves at
118
+ * once for a job that has already stopped. Optional, and added after
119
+ * the rest of this surface: a host implementing this interface directly
120
+ * rather than through `bindOwner` may not have it yet, so `wait_for_job`
121
+ * checks for it and says so rather than assuming every host can wait.
122
+ */
123
+ waitForExit?(
124
+ id: string,
125
+ opts?: { signal?: AbortSignal },
126
+ ): Promise<{
127
+ id: string
128
+ status: string
129
+ exitCode?: number
130
+ }>
131
+ /**
132
+ * Say that the model is waiting on this job, so the run stays open for it
133
+ * when the model stops calling tools.
134
+ *
135
+ * Called by `wait_for_job` and nothing else. The kernel holds a finishing
136
+ * run open — bounded, and for no model tokens — only for a job marked
137
+ * here; a job nobody marked never delays a run, which is what a dev server
138
+ * or a watcher needs. Optional for the reason `waitForExit` is: a host
139
+ * implementing this interface directly may have nowhere to record the
140
+ * intent, and then there is simply no hold.
141
+ */
142
+ markAwaited?(id: string): void
116
143
  }
117
144
 
118
145
  /**
@@ -138,6 +165,83 @@ export interface FileReadTracker {
138
165
  * preserves it; different or unknown content clears it. Never infer from a name.
139
166
  */
140
167
  writeCallId?(key: string): string | undefined
168
+ /**
169
+ * Optional chain of calls whose bodies compose the current content: the
170
+ * full-body write that started it, then the successful edits applied on
171
+ * top of it, in order.
172
+ *
173
+ * Defined only while at least one edit sits on a witnessed write — exactly
174
+ * when `writeCallId` is not. An edited file's body is no longer the write
175
+ * call's body, and a consumer that knows only `writeCallId` has to keep
176
+ * seeing nothing there rather than a claim that has quietly stopped being
177
+ * true. The chain names INPUTS: reconstructing the body means replaying
178
+ * those calls' visible arguments and checking the result against
179
+ * `fingerprint(key)`, never asserting it.
180
+ */
181
+ editChain?(key: string): { rootWriteCallId: string; editCallIds: readonly string[] } | undefined
182
+ /**
183
+ * Optional record of a successful edit's resulting content, with the call
184
+ * that produced it.
185
+ *
186
+ * Does everything `recordRead(key, content)` does, and additionally extends
187
+ * the chain when this edit ran against content the ledger already had a
188
+ * fingerprint for and a witnessed write underneath it — the two facts that
189
+ * make the replay reproducible. Missing either, it is an ordinary
190
+ * observation of a body nobody can replay: the fingerprint advances and the
191
+ * chain is cleared. Pass ToolContext.toolUseId only after the edit succeeded.
192
+ */
193
+ recordEdit?(key: string, content: string, callId: string): void
194
+ /**
195
+ * Optional witness of a read that returned the file WHOLE, with the
196
+ * fingerprint of the rendering it returned.
197
+ *
198
+ * Does everything `recordRead(key, content)` does, and additionally records
199
+ * that the body is visible in `callId`'s receipt — not as text this ledger
200
+ * holds, but as the exact rendering `callId` emitted, so a consumer can
201
+ * check the receipt it can see against `renderedFingerprint` before
202
+ * referencing it. A partial read never calls this: a window proves nothing
203
+ * about the rest of the file. Pass `ToolContext.toolUseId` and the
204
+ * fingerprint of the tool's own output string.
205
+ *
206
+ * The witness is recorded only where no write witness or chain survives the
207
+ * observation, because a write-rooted body is one the model composed and
208
+ * can be replayed through. It is cleared by exactly what clears a write
209
+ * witness — different or unknown content — and additionally by any
210
+ * `recordEdit`, because a read roots no chain: the body it witnesses exists
211
+ * only as a rendering, and nothing may be replayed on top of it.
212
+ */
213
+ recordFullRead?(key: string, content: string, callId: string, renderedFingerprint: string): void
214
+ /**
215
+ * Optional witness of the full read above: the call whose receipt holds the
216
+ * body, and the fingerprint of what that call emitted.
217
+ *
218
+ * `renderedFingerprint` is deliberately not the body's fingerprint —
219
+ * `fingerprint(key)` is that. It describes the RECEIPT, so a consumer
220
+ * admits the reference only while the receipt it can see is byte-for-byte
221
+ * what the tool returned; an elided, spilled or cleared one is not.
222
+ *
223
+ * The derived work context asks a tracker for `writeCallId` and
224
+ * `fingerprint` before it reads any witness at all — a name alone does not
225
+ * say the ledger is the one execution wrote — so a tracker implementing
226
+ * this pair and neither of those still establishes nothing.
227
+ */
228
+ readWitness?(key: string): { callId: string; renderedFingerprint: string } | undefined
229
+ /**
230
+ * Optional note that a built-in mutation has just refused this path because
231
+ * the body on disk differs from the fingerprint above.
232
+ *
233
+ * Not an observation. The refusing tool read the disk, but all it reports
234
+ * here is the disagreement — recording the body it found would re-baseline
235
+ * the drift check and admit the very mutation that was refused. An
236
+ * implementation must therefore leave `fingerprint`, `hasRead`,
237
+ * `writeCallId`, `editChain` and `readWitness` exactly as they were, and any
238
+ * later content observation clears the flag. It exists so a consumer that
239
+ * cannot read the filesystem — the derived work context — can stop
240
+ * referencing a body it has been told is stale, without a check of its own.
241
+ */
242
+ recordDriftObserved?(key: string): void
243
+ /** Whether a refused mutation has reported this path stale since the last observation. */
244
+ driftObserved?(key: string): boolean
141
245
  /**
142
246
  * Fingerprint of the body captured at the last read, when one was.
143
247
  *
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A positive whole number of milliseconds from the environment, or the
3
+ * caller's own default.
4
+ *
5
+ * Every bound that can be tuned wants the same three answers, and the third
6
+ * is the one worth sharing: a variable set to `soon`, to `-1` or to nothing
7
+ * at all falls back rather than parsing, because a run must not wait, hold or
8
+ * time out for `NaN`.
9
+ *
10
+ * `process.env` is read on every call, so where it is called decides when the
11
+ * value is sampled — `wait_for_job` fixes its bounds at module load and names
12
+ * them in a tool schema, and the kernel's hold ceiling asks per hold. That
13
+ * choice is why this lives here rather than being imported from the tool: the
14
+ * kernel reaching into `wait_for_job` for the parse would pull the tool's
15
+ * module-load sampling into the runtime's own graph, and move when the
16
+ * `NAMZU_JOB_WAIT_*` bounds are read.
17
+ */
18
+ export function readPositiveIntEnv(key: string, fallback: number): number {
19
+ const value = process.env[key]?.trim()
20
+ if (!value) return fallback
21
+ const parsed = Number(value)
22
+ return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : fallback
23
+ }