@namzu/sdk 58.1.1 → 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 (312) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/dist/account/binding.d.ts +20 -0
  3. package/dist/account/binding.d.ts.map +1 -0
  4. package/dist/account/binding.js +27 -0
  5. package/dist/account/binding.js.map +1 -0
  6. package/dist/account/index.d.ts +9 -0
  7. package/dist/account/index.d.ts.map +1 -0
  8. package/dist/account/index.js +5 -0
  9. package/dist/account/index.js.map +1 -0
  10. package/dist/account/lock.d.ts +33 -0
  11. package/dist/account/lock.d.ts.map +1 -0
  12. package/dist/account/lock.js +170 -0
  13. package/dist/account/lock.js.map +1 -0
  14. package/dist/account/registry.d.ts +21 -0
  15. package/dist/account/registry.d.ts.map +1 -0
  16. package/dist/account/registry.js +340 -0
  17. package/dist/account/registry.js.map +1 -0
  18. package/dist/account/types.d.ts +124 -0
  19. package/dist/account/types.d.ts.map +1 -0
  20. package/dist/account/types.js +35 -0
  21. package/dist/account/types.js.map +1 -0
  22. package/dist/compaction/context-window.d.ts +53 -0
  23. package/dist/compaction/context-window.d.ts.map +1 -1
  24. package/dist/compaction/context-window.js +141 -2
  25. package/dist/compaction/context-window.js.map +1 -1
  26. package/dist/execution/workflow/index.d.ts +3 -1
  27. package/dist/execution/workflow/index.d.ts.map +1 -1
  28. package/dist/execution/workflow/index.js +2 -1
  29. package/dist/execution/workflow/index.js.map +1 -1
  30. package/dist/execution/workflow/journal.d.ts +24 -4
  31. package/dist/execution/workflow/journal.d.ts.map +1 -1
  32. package/dist/execution/workflow/journal.js +131 -9
  33. package/dist/execution/workflow/journal.js.map +1 -1
  34. package/dist/execution/workflow/prelude.d.ts +2 -0
  35. package/dist/execution/workflow/prelude.d.ts.map +1 -1
  36. package/dist/execution/workflow/prelude.js +49 -8
  37. package/dist/execution/workflow/prelude.js.map +1 -1
  38. package/dist/execution/workflow/resume.d.ts +59 -0
  39. package/dist/execution/workflow/resume.d.ts.map +1 -0
  40. package/dist/execution/workflow/resume.js +273 -0
  41. package/dist/execution/workflow/resume.js.map +1 -0
  42. package/dist/execution/workflow/runtime.d.ts.map +1 -1
  43. package/dist/execution/workflow/runtime.js +112 -8
  44. package/dist/execution/workflow/runtime.js.map +1 -1
  45. package/dist/execution/workflow/types.d.ts +105 -1
  46. package/dist/execution/workflow/types.d.ts.map +1 -1
  47. package/dist/index.d.ts +3 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +4 -0
  50. package/dist/index.js.map +1 -1
  51. package/dist/pals/communication/ingress-schema.d.ts +38 -38
  52. package/dist/peers/record.d.ts +98 -0
  53. package/dist/peers/record.d.ts.map +1 -1
  54. package/dist/peers/record.js +17 -0
  55. package/dist/peers/record.js.map +1 -1
  56. package/dist/peers/registry.d.ts.map +1 -1
  57. package/dist/peers/registry.js +2 -2
  58. package/dist/peers/registry.js.map +1 -1
  59. package/dist/plugin/compat.d.ts +24 -0
  60. package/dist/plugin/compat.d.ts.map +1 -0
  61. package/dist/plugin/compat.js +149 -0
  62. package/dist/plugin/compat.js.map +1 -0
  63. package/dist/plugin/loader.d.ts +2 -1
  64. package/dist/plugin/loader.d.ts.map +1 -1
  65. package/dist/plugin/loader.js +6 -0
  66. package/dist/plugin/loader.js.map +1 -1
  67. package/dist/pricing/index.d.ts.map +1 -1
  68. package/dist/pricing/index.js +2 -1
  69. package/dist/pricing/index.js.map +1 -1
  70. package/dist/process/kill-tree.d.ts +44 -0
  71. package/dist/process/kill-tree.d.ts.map +1 -1
  72. package/dist/process/kill-tree.js +102 -4
  73. package/dist/process/kill-tree.js.map +1 -1
  74. package/dist/prompt/coding-agent-doctrine.d.ts +1 -1
  75. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  76. package/dist/prompt/coding-agent-doctrine.js +9 -1
  77. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  78. package/dist/provider/errors.d.ts.map +1 -1
  79. package/dist/provider/errors.js +25 -2
  80. package/dist/provider/errors.js.map +1 -1
  81. package/dist/provider/model-window-suffix.d.ts +18 -0
  82. package/dist/provider/model-window-suffix.d.ts.map +1 -0
  83. package/dist/provider/model-window-suffix.js +77 -0
  84. package/dist/provider/model-window-suffix.js.map +1 -0
  85. package/dist/provider/token-budget.d.ts.map +1 -1
  86. package/dist/provider/token-budget.js +9 -1
  87. package/dist/provider/token-budget.js.map +1 -1
  88. package/dist/public-runtime.d.ts +6 -3
  89. package/dist/public-runtime.d.ts.map +1 -1
  90. package/dist/public-runtime.js +6 -4
  91. package/dist/public-runtime.js.map +1 -1
  92. package/dist/public-types.d.ts +3 -0
  93. package/dist/public-types.d.ts.map +1 -1
  94. package/dist/registry/command/kernel-commands.d.ts +1 -4
  95. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  96. package/dist/registry/command/kernel-commands.js +0 -28
  97. package/dist/registry/command/kernel-commands.js.map +1 -1
  98. package/dist/runtime/jobs/awaited-jobs.d.ts +6 -0
  99. package/dist/runtime/jobs/awaited-jobs.d.ts.map +1 -1
  100. package/dist/runtime/jobs/awaited-jobs.js +11 -0
  101. package/dist/runtime/jobs/awaited-jobs.js.map +1 -1
  102. package/dist/runtime/jobs/host-exit-finalizer.d.ts +20 -0
  103. package/dist/runtime/jobs/host-exit-finalizer.d.ts.map +1 -0
  104. package/dist/runtime/jobs/host-exit-finalizer.js +57 -0
  105. package/dist/runtime/jobs/host-exit-finalizer.js.map +1 -0
  106. package/dist/runtime/jobs/liveness.d.ts +67 -0
  107. package/dist/runtime/jobs/liveness.d.ts.map +1 -0
  108. package/dist/runtime/jobs/liveness.js +94 -0
  109. package/dist/runtime/jobs/liveness.js.map +1 -0
  110. package/dist/runtime/jobs/registry.d.ts +21 -0
  111. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  112. package/dist/runtime/jobs/registry.js +104 -2
  113. package/dist/runtime/jobs/registry.js.map +1 -1
  114. package/dist/runtime/jobs/wake-budget.d.ts +35 -0
  115. package/dist/runtime/jobs/wake-budget.d.ts.map +1 -0
  116. package/dist/runtime/jobs/wake-budget.js +48 -0
  117. package/dist/runtime/jobs/wake-budget.js.map +1 -0
  118. package/dist/runtime/query/detached-calls.d.ts +65 -0
  119. package/dist/runtime/query/detached-calls.d.ts.map +1 -0
  120. package/dist/runtime/query/detached-calls.js +116 -0
  121. package/dist/runtime/query/detached-calls.js.map +1 -0
  122. package/dist/runtime/query/executor.d.ts +11 -3
  123. package/dist/runtime/query/executor.d.ts.map +1 -1
  124. package/dist/runtime/query/executor.js +100 -8
  125. package/dist/runtime/query/executor.js.map +1 -1
  126. package/dist/runtime/query/index.d.ts +20 -0
  127. package/dist/runtime/query/index.d.ts.map +1 -1
  128. package/dist/runtime/query/index.js +31 -5
  129. package/dist/runtime/query/index.js.map +1 -1
  130. package/dist/runtime/query/iteration/outstanding-work.d.ts.map +1 -1
  131. package/dist/runtime/query/iteration/outstanding-work.js +11 -3
  132. package/dist/runtime/query/iteration/outstanding-work.js.map +1 -1
  133. package/dist/runtime/query/iteration/phases/context.d.ts +7 -0
  134. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  135. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  136. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  137. package/dist/runtime/query/iteration/phases/tool-review.js +63 -1
  138. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  139. package/dist/runtime/query/session-storage.d.ts.map +1 -1
  140. package/dist/runtime/query/session-storage.js +8 -3
  141. package/dist/runtime/query/session-storage.js.map +1 -1
  142. package/dist/runtime/query/steering.d.ts +29 -3
  143. package/dist/runtime/query/steering.d.ts.map +1 -1
  144. package/dist/runtime/query/steering.js +58 -3
  145. package/dist/runtime/query/steering.js.map +1 -1
  146. package/dist/runtime/query/tooling.d.ts +1 -0
  147. package/dist/runtime/query/tooling.d.ts.map +1 -1
  148. package/dist/runtime/query/tooling.js +1 -0
  149. package/dist/runtime/query/tooling.js.map +1 -1
  150. package/dist/runtime/system-events.d.ts +5 -0
  151. package/dist/runtime/system-events.d.ts.map +1 -1
  152. package/dist/runtime/system-events.js +7 -1
  153. package/dist/runtime/system-events.js.map +1 -1
  154. package/dist/sandbox/denial.d.ts +11 -0
  155. package/dist/sandbox/denial.d.ts.map +1 -0
  156. package/dist/sandbox/denial.js +61 -0
  157. package/dist/sandbox/denial.js.map +1 -0
  158. package/dist/sandbox/file-walk-program.d.ts.map +1 -1
  159. package/dist/sandbox/file-walk-program.js +31 -13
  160. package/dist/sandbox/file-walk-program.js.map +1 -1
  161. package/dist/sandbox/file-walk.d.ts +2 -0
  162. package/dist/sandbox/file-walk.d.ts.map +1 -1
  163. package/dist/sandbox/file-walk.js +64 -13
  164. package/dist/sandbox/file-walk.js.map +1 -1
  165. package/dist/sandbox/ignore-matcher.d.ts +30 -0
  166. package/dist/sandbox/ignore-matcher.d.ts.map +1 -0
  167. package/dist/sandbox/ignore-matcher.js +11 -0
  168. package/dist/sandbox/ignore-matcher.js.map +1 -0
  169. package/dist/sandbox/ignore-source.d.ts +26 -0
  170. package/dist/sandbox/ignore-source.d.ts.map +1 -0
  171. package/dist/sandbox/ignore-source.js +221 -0
  172. package/dist/sandbox/ignore-source.js.map +1 -0
  173. package/dist/sandbox/provider/local.d.ts.map +1 -1
  174. package/dist/sandbox/provider/local.js +11 -1
  175. package/dist/sandbox/provider/local.js.map +1 -1
  176. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  177. package/dist/scheduler/completion-inbox.js +1 -0
  178. package/dist/scheduler/completion-inbox.js.map +1 -1
  179. package/dist/session/log-hash.d.ts.map +1 -1
  180. package/dist/session/log-hash.js +18 -1
  181. package/dist/session/log-hash.js.map +1 -1
  182. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  183. package/dist/store/session-index/sqlite.js +169 -16
  184. package/dist/store/session-index/sqlite.js.map +1 -1
  185. package/dist/tools/builtins/bash.d.ts.map +1 -1
  186. package/dist/tools/builtins/bash.js +10 -4
  187. package/dist/tools/builtins/bash.js.map +1 -1
  188. package/dist/tools/builtins/computer-use.d.ts +35 -0
  189. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  190. package/dist/tools/builtins/computer-use.js +512 -67
  191. package/dist/tools/builtins/computer-use.js.map +1 -1
  192. package/dist/tools/builtins/glob.d.ts +1 -0
  193. package/dist/tools/builtins/glob.d.ts.map +1 -1
  194. package/dist/tools/builtins/glob.js +65 -28
  195. package/dist/tools/builtins/glob.js.map +1 -1
  196. package/dist/tools/builtins/grep.d.ts +2 -0
  197. package/dist/tools/builtins/grep.d.ts.map +1 -1
  198. package/dist/tools/builtins/grep.js +94 -40
  199. package/dist/tools/builtins/grep.js.map +1 -1
  200. package/dist/tools/builtins/job.d.ts +1 -1
  201. package/dist/tools/builtins/job.d.ts.map +1 -1
  202. package/dist/tools/builtins/job.js +34 -7
  203. package/dist/tools/builtins/job.js.map +1 -1
  204. package/dist/tools/builtins/search-support.d.ts +44 -0
  205. package/dist/tools/builtins/search-support.d.ts.map +1 -0
  206. package/dist/tools/builtins/search-support.js +89 -0
  207. package/dist/tools/builtins/search-support.js.map +1 -0
  208. package/dist/tools/builtins/wait-for-job-bounds.d.ts +2 -0
  209. package/dist/tools/builtins/wait-for-job-bounds.d.ts.map +1 -1
  210. package/dist/tools/builtins/wait-for-job-bounds.js +3 -1
  211. package/dist/tools/builtins/wait-for-job-bounds.js.map +1 -1
  212. package/dist/tools/builtins/wait-for-job.d.ts +1 -1
  213. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  214. package/dist/tools/builtins/wait-for-job.js +13 -2
  215. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  216. package/dist/tools/command-shell.d.ts.map +1 -1
  217. package/dist/tools/command-shell.js +14 -5
  218. package/dist/tools/command-shell.js.map +1 -1
  219. package/dist/types/computer-use/index.d.ts +129 -13
  220. package/dist/types/computer-use/index.d.ts.map +1 -1
  221. package/dist/types/computer-use/index.js.map +1 -1
  222. package/dist/types/errors/catalog.d.ts.map +1 -1
  223. package/dist/types/errors/catalog.js +6 -0
  224. package/dist/types/errors/catalog.js.map +1 -1
  225. package/dist/types/plugin/index.d.ts +24 -0
  226. package/dist/types/plugin/index.d.ts.map +1 -1
  227. package/dist/types/plugin/index.js +4 -0
  228. package/dist/types/plugin/index.js.map +1 -1
  229. package/dist/types/provider/errors.d.ts +7 -0
  230. package/dist/types/provider/errors.d.ts.map +1 -1
  231. package/dist/types/provider/errors.js +27 -3
  232. package/dist/types/provider/errors.js.map +1 -1
  233. package/dist/types/sandbox/index.d.ts +38 -1
  234. package/dist/types/sandbox/index.d.ts.map +1 -1
  235. package/dist/types/sandbox/index.js.map +1 -1
  236. package/dist/types/session/records.d.ts +479 -1
  237. package/dist/types/session/records.d.ts.map +1 -1
  238. package/dist/types/session/records.js +45 -1
  239. package/dist/types/session/records.js.map +1 -1
  240. package/dist/types/tool/index.d.ts +30 -0
  241. package/dist/types/tool/index.d.ts.map +1 -1
  242. package/dist/types/tool/index.js.map +1 -1
  243. package/dist/types/tool/presentation.d.ts +8 -0
  244. package/dist/types/tool/presentation.d.ts.map +1 -1
  245. package/package.json +1 -1
  246. package/src/account/binding.ts +43 -0
  247. package/src/account/index.ts +32 -0
  248. package/src/account/lock.ts +184 -0
  249. package/src/account/registry.ts +413 -0
  250. package/src/account/types.ts +137 -0
  251. package/src/compaction/context-window.ts +163 -2
  252. package/src/execution/workflow/index.ts +14 -1
  253. package/src/execution/workflow/journal.ts +161 -11
  254. package/src/execution/workflow/prelude.ts +51 -8
  255. package/src/execution/workflow/resume.ts +313 -0
  256. package/src/execution/workflow/runtime.ts +127 -9
  257. package/src/execution/workflow/types.ts +109 -1
  258. package/src/index.ts +17 -0
  259. package/src/peers/record.ts +18 -0
  260. package/src/peers/registry.ts +2 -2
  261. package/src/plugin/compat.ts +173 -0
  262. package/src/plugin/loader.ts +7 -1
  263. package/src/pricing/index.ts +2 -1
  264. package/src/process/kill-tree.ts +106 -4
  265. package/src/prompt/coding-agent-doctrine.ts +9 -1
  266. package/src/provider/errors.ts +27 -1
  267. package/src/provider/model-window-suffix.ts +84 -0
  268. package/src/provider/token-budget.ts +9 -3
  269. package/src/public-runtime.ts +38 -2
  270. package/src/public-types.ts +16 -0
  271. package/src/registry/command/kernel-commands.ts +1 -32
  272. package/src/runtime/jobs/awaited-jobs.ts +11 -0
  273. package/src/runtime/jobs/host-exit-finalizer.ts +67 -0
  274. package/src/runtime/jobs/liveness.ts +144 -0
  275. package/src/runtime/jobs/registry.ts +114 -2
  276. package/src/runtime/jobs/wake-budget.ts +55 -0
  277. package/src/runtime/query/detached-calls.ts +135 -0
  278. package/src/runtime/query/executor.ts +102 -12
  279. package/src/runtime/query/index.ts +50 -7
  280. package/src/runtime/query/iteration/outstanding-work.ts +12 -3
  281. package/src/runtime/query/iteration/phases/context.ts +7 -0
  282. package/src/runtime/query/iteration/phases/tool-review.ts +73 -8
  283. package/src/runtime/query/session-storage.ts +8 -3
  284. package/src/runtime/query/steering.ts +77 -6
  285. package/src/runtime/query/tooling.ts +2 -0
  286. package/src/runtime/system-events.ts +12 -1
  287. package/src/sandbox/denial.ts +79 -0
  288. package/src/sandbox/file-walk-program.ts +32 -13
  289. package/src/sandbox/file-walk.ts +75 -12
  290. package/src/sandbox/ignore-matcher.ts +46 -0
  291. package/src/sandbox/ignore-source.ts +220 -0
  292. package/src/sandbox/provider/local.ts +11 -1
  293. package/src/scheduler/completion-inbox.ts +1 -0
  294. package/src/session/log-hash.ts +21 -0
  295. package/src/store/session-index/sqlite.ts +171 -16
  296. package/src/tools/builtins/bash.ts +11 -4
  297. package/src/tools/builtins/computer-use.ts +593 -68
  298. package/src/tools/builtins/glob.ts +79 -32
  299. package/src/tools/builtins/grep.ts +107 -43
  300. package/src/tools/builtins/job.ts +42 -12
  301. package/src/tools/builtins/search-support.ts +107 -0
  302. package/src/tools/builtins/wait-for-job-bounds.ts +5 -1
  303. package/src/tools/builtins/wait-for-job.ts +14 -2
  304. package/src/tools/command-shell.ts +13 -5
  305. package/src/types/computer-use/index.ts +157 -15
  306. package/src/types/errors/catalog.ts +6 -0
  307. package/src/types/plugin/index.ts +8 -0
  308. package/src/types/provider/errors.ts +40 -3
  309. package/src/types/sandbox/index.ts +40 -1
  310. package/src/types/session/records.ts +52 -2
  311. package/src/types/tool/index.ts +30 -0
  312. package/src/types/tool/presentation.ts +8 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Keeps the `[1m]` window marker off the wire.
3
+ *
4
+ * A model id ending in `[1m]` declares a one-million-token window to Namzu
5
+ * (see `splitModelWindowSuffix`). The marker belongs to the person and the UI,
6
+ * not to the vendor, so every driver and every request sees the bare id. This
7
+ * wraps a provider once, where it is built, so no caller that holds the marked
8
+ * id (a main model, a sub-agent, a side-job model, a fallback chain member)
9
+ * has to remember to strip it.
10
+ */
11
+
12
+ import { stripModelWindowSuffix } from '../compaction/context-window.js'
13
+ import type { LLMProvider } from '../types/provider/interface.js'
14
+
15
+ /** Provider methods whose first argument is a model id. */
16
+ const MODEL_FIRST_METHODS: ReadonlySet<string> = new Set([
17
+ 'supportsHostedWebSearchFor',
18
+ 'supportsImageInputFor',
19
+ 'reasoningEffortLevelsFor',
20
+ 'reasoningEffortDefaultFor',
21
+ 'effortLevelsFor',
22
+ 'resolveContextWindow',
23
+ 'healthCheck',
24
+ 'doctorCheck',
25
+ ])
26
+
27
+ function stripParams(params: unknown): unknown {
28
+ if (typeof params !== 'object' || params === null) return params
29
+ const model = (params as { model?: unknown }).model
30
+ if (typeof model !== 'string') return params
31
+ const bare = stripModelWindowSuffix(model)
32
+ return bare === model ? params : { ...params, model: bare }
33
+ }
34
+
35
+ const WRAPPED = Symbol.for('namzu.modelWindowSuffixStripped')
36
+
37
+ type AnyMethod = (...args: unknown[]) => unknown
38
+
39
+ function wrapMethod(name: string, method: AnyMethod): AnyMethod | undefined {
40
+ if (name === 'chatStream' || name === 'chat') {
41
+ return function (this: unknown, params: unknown, ...rest: unknown[]) {
42
+ return method.call(this, stripParams(params), ...rest)
43
+ }
44
+ }
45
+ if (MODEL_FIRST_METHODS.has(name)) {
46
+ return function (this: unknown, model: unknown, ...rest: unknown[]) {
47
+ return method.call(
48
+ this,
49
+ typeof model === 'string' ? stripModelWindowSuffix(model) : model,
50
+ ...rest,
51
+ )
52
+ }
53
+ }
54
+ return undefined
55
+ }
56
+
57
+ /**
58
+ * The same provider, now stripping the marker from every model it is handed.
59
+ * The instance is patched in place (not proxied) so a host that keys state on
60
+ * the provider object keeps finding it; wrapping twice changes nothing.
61
+ */
62
+ export function withModelWindowSuffixStripped<T extends LLMProvider>(provider: T): T {
63
+ const target = provider as unknown as Record<PropertyKey, unknown>
64
+ if (target[WRAPPED] === true) return provider
65
+ if (!Object.isExtensible(provider)) {
66
+ return new Proxy(provider, {
67
+ get(object, property) {
68
+ const value: unknown = Reflect.get(object, property, object)
69
+ if (typeof value !== 'function') return value
70
+ const wrapped =
71
+ typeof property === 'string' ? wrapMethod(property, value as AnyMethod) : undefined
72
+ return (wrapped ?? (value as AnyMethod)).bind(object)
73
+ },
74
+ })
75
+ }
76
+ for (const name of ['chatStream', 'chat', ...MODEL_FIRST_METHODS]) {
77
+ const method = target[name]
78
+ if (typeof method !== 'function') continue
79
+ const wrapped = wrapMethod(name, method as AnyMethod)
80
+ if (wrapped) target[name] = wrapped
81
+ }
82
+ Object.defineProperty(provider, WRAPPED, { value: true, enumerable: false })
83
+ return provider
84
+ }
@@ -29,9 +29,14 @@ function rejectedBeforeGeneration(error: unknown): boolean {
29
29
  [400, 401, 403, 404, 413, 422, 429].includes(classified.status))
30
30
  return (
31
31
  explicitRejection &&
32
- ['auth', 'rate_limit', 'context_length_exceeded', 'invalid_request', 'not_found'].includes(
33
- classified.code,
34
- )
32
+ [
33
+ 'auth',
34
+ 'rate_limit',
35
+ 'usage_limit',
36
+ 'context_length_exceeded',
37
+ 'invalid_request',
38
+ 'not_found',
39
+ ].includes(classified.code)
35
40
  )
36
41
  }
37
42
 
@@ -96,6 +101,7 @@ export function withTokenBudget(provider: LLMProvider, budget: SessionTokenBudge
96
101
  ![
97
102
  'auth',
98
103
  'rate_limit',
104
+ 'usage_limit',
99
105
  'context_length_exceeded',
100
106
  'invalid_request',
101
107
  'not_found',
@@ -24,11 +24,17 @@ export { WorkerCodeRuntime } from './execution/code-runtime/worker.js'
24
24
  // interpreter above, with `agent()` as its only host call.
25
25
  export {
26
26
  FileWorkflowJournal,
27
+ formatWorkflowJournalLine,
28
+ loadWorkflowResume,
27
29
  parseWorkflowMeta,
30
+ readWorkflowJournalChecked,
28
31
  resolveWorkflowLimits,
29
32
  summarizeWorkflowPhases,
30
33
  WorkflowRuntime,
31
34
  WorkflowScriptError,
35
+ workflowCallKey,
36
+ workflowJournalLineHash,
37
+ workflowJournalSeed,
32
38
  } from './execution/workflow/index.js'
33
39
 
34
40
  export {
@@ -608,7 +614,7 @@ export { resolveSessionLogReplay } from './types/session/log-cursor.js'
608
614
 
609
615
  // Commands a HOST offers its operator. Deliberately NOT tools: no
610
616
  // descriptor reaches a provider and no dispatch path reaches the model — a
611
- // `/tasks` readout is a question the operator asked, and making it callable
617
+ // `/skills` readout is a question the operator asked, and making it callable
612
618
  // would let the model spend a turn on it and record the output as a finding.
613
619
  export {
614
620
  HostCommandNameCollisionError,
@@ -1109,6 +1115,7 @@ export { wrapProviderWithProbes } from './provider/instrumentation.js'
1109
1115
  export type { ProviderInstrumentationOptions } from './provider/instrumentation.js'
1110
1116
  export type { ResolvedProviderCapabilities } from './provider/capabilities.js'
1111
1117
  export { collectChatCompletion } from './provider/collect-chat-completion.js'
1118
+ export { withModelWindowSuffixStripped } from './provider/model-window-suffix.js'
1112
1119
 
1113
1120
  // Old spellings of renamed exports, still live for one deprecation window.
1114
1121
  // The file explains why each is a `const`+`type` pair rather than a
@@ -1591,7 +1598,18 @@ export {
1591
1598
  // consumer (`SpanProcessorLike`, then `CompactNowInput` and `CompactionResult`).
1592
1599
  // The gate is the reason this is a list rather than a fourth accident.
1593
1600
  export type { ResolvedContextWindow } from './compaction/context-window.js'
1594
- export { resolveTriggerThreshold } from './compaction/context-window.js'
1601
+ export {
1602
+ AUTO_COMPACT_WINDOW_MAX_TOKENS,
1603
+ AUTO_COMPACT_WINDOW_MIN_TOKENS,
1604
+ ONE_MILLION_WINDOW_TOKENS,
1605
+ oneMillionWindowDisabled,
1606
+ parseAutoCompactWindow,
1607
+ resolveAutoCompactWindowSetting,
1608
+ resolveTriggerThreshold,
1609
+ splitModelWindowSuffix,
1610
+ stripModelWindowSuffix,
1611
+ } from './compaction/context-window.js'
1612
+ export type { AutoCompactWindowParse } from './compaction/context-window.js'
1595
1613
  // What the context window is made of, for a host that draws the answer to
1596
1614
  // "where did my context go".
1597
1615
  export {
@@ -1744,6 +1762,7 @@ export {
1744
1762
  ChildSessionMetaSchema,
1745
1763
  CompactionRecordSchema,
1746
1764
  ExternalRefSchema,
1765
+ IgnorableRecordSchema,
1747
1766
  MessageRecordSchema,
1748
1767
  MessageReplacedRecordSchema,
1749
1768
  OriginSchema,
@@ -1869,6 +1888,23 @@ export {
1869
1888
  udsPeerAddress,
1870
1889
  writePeerRecord,
1871
1890
  } from './peers/index.js'
1891
+ export {
1892
+ ACCOUNTS_FILE_NAME,
1893
+ ACCOUNTS_FILE_VERSION,
1894
+ AccountLockError,
1895
+ AccountRegistryError,
1896
+ CredentialWithdrawnError,
1897
+ DEFAULT_ACCOUNT_LABEL,
1898
+ accountBoundPayload,
1899
+ accountId,
1900
+ codexRefreshLockPath,
1901
+ createAccountRegistry,
1902
+ parseAccountId,
1903
+ resolveBoundAccount,
1904
+ withAccountLock,
1905
+ withAccountLockSync,
1906
+ withAccountRefreshLock,
1907
+ } from './account/index.js'
1872
1908
  export { DiskPalStore, PalConflictError } from './pals/store.js'
1873
1909
  export { PalRuntime, PalUnavailableError } from './pals/runtime.js'
1874
1910
  export { buildPalSystemPrompt, palConversationGreeting } from './pals/prompt.js'
@@ -35,6 +35,7 @@ export type * from './types/job/index.js'
35
35
  export type * from './execution/workflow/types.js'
36
36
  export type { PhaseAgentView, PhaseRecord } from './execution/workflow/phases.js'
37
37
  export type { WorkflowRuntimeOptions } from './execution/workflow/runtime.js'
38
+ export type { WorkflowCallIdentity } from './execution/workflow/resume.js'
38
39
  export type { WorkerCodeRuntimeOptions } from './execution/code-runtime/worker.js'
39
40
  export type {
40
41
  CodeRunOutcome,
@@ -800,6 +801,21 @@ export type {
800
801
  ResolvePeerRuntimeDirOptions,
801
802
  } from './peers/dir.js'
802
803
  export type { PeerRecord } from './peers/record.js'
804
+ export type { AccountBoundRecord } from './types/session/records.js'
805
+ export type {
806
+ Account,
807
+ AccountBoundReason,
808
+ AccountCredentialReaders,
809
+ AccountId,
810
+ AccountLockOptions,
811
+ AccountLockSyncOptions,
812
+ AccountRegistry,
813
+ AccountRegistryOptions,
814
+ AccountSource,
815
+ BoundAccount,
816
+ NewAccount,
817
+ ResolvedAccountCredential,
818
+ } from './account/index.js'
803
819
  export type {
804
820
  ListLivePeersOptions,
805
821
  PeerLivenessOptions,
@@ -12,14 +12,13 @@ import type { GoalRef, SessionGoal } from '../../types/goal/index.js'
12
12
  import type { SessionId, TenantId } from '../../types/ids/index.js'
13
13
  import type { Skill } from '../../types/skills/index.js'
14
14
  import { isInvocableBy, skillInvocation } from '../../types/skills/index.js'
15
- import type { TaskStore } from '../../types/task/index.js'
16
15
 
17
16
  /**
18
17
  * The commands whose facts the kernel already owns.
19
18
  *
20
19
  * A registry with nothing in it is a declaration, and this repo has a rule
21
20
  * about those. These are facts a host would otherwise have to reach into
22
- * kernel internals to answer: the current Session goal, tracked work,
21
+ * kernel internals to answer: the current Session goal,
23
22
  * operator-invocable skills, and the agents this turn may delegate to. Each is
24
23
  * computed or owned here and should not acquire a second host-specific source.
25
24
  *
@@ -31,8 +30,6 @@ import type { TaskStore } from '../../types/task/index.js'
31
30
  */
32
31
 
33
32
  export interface KernelCommandOptions {
34
- /** Absent is a real state — not every turn tracks tasks. */
35
- readonly taskStore?: TaskStore
36
33
  readonly allowedAgentIds?: readonly string[]
37
34
  /**
38
35
  * The turn's skills, for the operator-facing half of the listing.
@@ -263,34 +260,6 @@ export function kernelHostCommands(options: KernelCommandOptions): HostCommandDe
263
260
  hint: GOAL_ARGUMENTS,
264
261
  handler: async ({ args }) => await runGoalCommand(options.goal, args),
265
262
  },
266
- {
267
- name: 'tasks',
268
- description: 'List the work this turn is tracking.',
269
- hint: 'id, status, owner and subject for every task in the store',
270
- async handler() {
271
- // REFUSED rather than an empty report. "There are no tasks" and
272
- // "this turn has no task store" are different answers, and a host
273
- // that shows the first for the second gives an operator a
274
- // confident zero nobody computed.
275
- if (!options.taskStore) {
276
- return {
277
- kind: 'refused',
278
- reason: 'This turn has no task store, so there is nothing to list.',
279
- }
280
- }
281
- const tasks = await options.taskStore.list()
282
- return {
283
- kind: 'report',
284
- title: 'Tasks',
285
- rows: tasks.map((task) => ({
286
- id: task.id,
287
- status: task.status,
288
- owner: task.owner ?? null,
289
- subject: task.subject,
290
- })),
291
- }
292
- },
293
- },
294
263
  {
295
264
  name: 'skills',
296
265
  description: 'List the skills an operator may invoke.',
@@ -327,6 +327,17 @@ export class AwaitedJobs {
327
327
  this.exits = []
328
328
  }
329
329
 
330
+ /**
331
+ * Say that a tool result has handed the model this job's exit and output.
332
+ * Its entry goes, so a hold is not opened for a result the model has read;
333
+ * the notice for the same exit is withdrawn by the caller.
334
+ */
335
+ collected(id: string): void {
336
+ this.outstanding.delete(id)
337
+ this.exits = this.exits.filter((job) => job.id !== id)
338
+ for (const wake of [...this.arrivals]) wake()
339
+ }
340
+
330
341
  /**
331
342
  * Take the recorded exits together with the text that delivers them, or
332
343
  * take neither.
@@ -0,0 +1,67 @@
1
+ import { killTrees } from '../../process/kill-tree.js'
2
+
3
+ /**
4
+ * What the host's exit has to stop: a job's process, and how to signal it.
5
+ */
6
+ export interface HostExitTarget {
7
+ readonly child: { readonly pid?: number | undefined }
8
+ /** The spawner's own kill, when it gave one; otherwise the process group is signalled. */
9
+ readonly kill?: (signal: NodeJS.Signals) => void
10
+ }
11
+
12
+ const live = new Set<HostExitTarget>()
13
+ let installed = false
14
+
15
+ /**
16
+ * Runs when the host process is about to end, by whatever road: `process.exit`,
17
+ * an uncaught exception, the event loop emptying. It is synchronous on purpose.
18
+ * An `exit` listener cannot await, so it starts no promise and no timer, signals
19
+ * each live job with SIGKILL (its own kill when it gave one, then its process
20
+ * group and any descendant found by the environment tag), and does not wait for any of them
21
+ * to stop or claim that they have. A job that was already stopped has been
22
+ * untracked and is not touched.
23
+ *
24
+ * It does not cover a SIGKILL of the host itself, which no listener can see.
25
+ */
26
+ function finalizeAtHostExit(): void {
27
+ const children: HostExitTarget['child'][] = []
28
+ for (const target of live) {
29
+ children.push(target.child)
30
+ try {
31
+ target.kill?.('SIGKILL')
32
+ } catch {
33
+ // The process is already gone; the host is exiting either way.
34
+ }
35
+ }
36
+ live.clear()
37
+ try {
38
+ // One pass over the machine's processes for all the jobs, not one each.
39
+ // Every job goes through it, whether or not it has a kill of its own, so
40
+ // a descendant that left the process group is found in both cases.
41
+ killTrees(children, 'SIGKILL')
42
+ } catch {
43
+ // As above.
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Track a running job so the host's exit stops it. Returns the untrack, to be
49
+ * called once the job has ended. The listener is installed once per process, on
50
+ * the first job, and is put first so a later listener that throws cannot
51
+ * keep it from running.
52
+ */
53
+ export function stopAtHostExit(target: HostExitTarget): () => void {
54
+ live.add(target)
55
+ if (!installed) {
56
+ installed = true
57
+ process.prependListener('exit', finalizeAtHostExit)
58
+ }
59
+ return () => {
60
+ live.delete(target)
61
+ }
62
+ }
63
+
64
+ /** Jobs the host's exit would stop. For tests. */
65
+ export function trackedForHostExit(): number {
66
+ return live.size
67
+ }
@@ -0,0 +1,144 @@
1
+ /**
2
+ * What a host can say about one running item, from three facts it reads
3
+ * itself: where it is, when it last made progress, and whether it is alive.
4
+ *
5
+ * Pure: no clock, no process probe. The caller passes `now` and the probe's
6
+ * answer, so the same table of cases runs under a fake clock. The kinds
7
+ * (background job, monitor, delegated agent, workflow run) share one verdict
8
+ * so the outstanding-work note and every status read print the same words.
9
+ */
10
+
11
+ /** Silence shorter than this still reads as progress. */
12
+ export const LIVENESS_QUIET_MS = 30_000
13
+
14
+ /**
15
+ * Silence from an item that is alive and has no known reason to wait. The
16
+ * same number `wait_for_job` uses for its idle bound, so there is one
17
+ * threshold to explain.
18
+ */
19
+ export const LIVENESS_STALLED_MS = 2 * 60 * 1000
20
+
21
+ export type LivenessKind = 'job' | 'monitor' | 'agent' | 'workflow'
22
+
23
+ export type LivenessVerdict = 'progressing' | 'waiting' | 'stalled' | 'dead' | 'finished'
24
+
25
+ export interface LivenessInput {
26
+ readonly kind: LivenessKind
27
+ readonly id: string
28
+ /** Short name the person would recognise: a command, a description, a workflow name. */
29
+ readonly label: string
30
+ /** Where it is: the last output line, the current tool, the phase. One line, already bounded. */
31
+ readonly where?: string
32
+ readonly startedAt: number
33
+ /** When it last made progress (epoch ms). Absent means it has not yet: the start counts. */
34
+ readonly lastProgressAt?: number
35
+ /** The probe's answer: is the process or run still there. */
36
+ readonly alive: boolean
37
+ /** A result or an end has arrived. */
38
+ readonly finished?: boolean
39
+ /** What it is known to be waiting on, when it is waiting for a reason (a tool, a free slot). */
40
+ readonly waitingOn?: string
41
+ readonly waitingSince?: number
42
+ }
43
+
44
+ export interface Liveness {
45
+ readonly kind: LivenessKind
46
+ readonly id: string
47
+ readonly label: string
48
+ readonly where?: string
49
+ readonly verdict: LivenessVerdict
50
+ /** Whole seconds since the last progress (or the start). */
51
+ readonly idleSeconds: number
52
+ /** Whole seconds since it started. */
53
+ readonly ageSeconds: number
54
+ /** Present when the verdict is `waiting` with a reason. */
55
+ readonly waitingOn?: string
56
+ readonly waitingSeconds?: number
57
+ }
58
+
59
+ export interface LivenessThresholds {
60
+ readonly quietMs?: number
61
+ readonly stalledMs?: number
62
+ }
63
+
64
+ const seconds = (ms: number): number => Math.max(0, Math.floor(ms / 1000))
65
+
66
+ /** Decide the verdict. Order matters: a result beats everything, then death, then the reason to wait. */
67
+ export function judgeLiveness(
68
+ input: LivenessInput,
69
+ now: number,
70
+ thresholds: LivenessThresholds = {},
71
+ ): Liveness {
72
+ const quietMs = thresholds.quietMs ?? LIVENESS_QUIET_MS
73
+ const stalledMs = thresholds.stalledMs ?? LIVENESS_STALLED_MS
74
+ const last = Math.max(input.startedAt, input.lastProgressAt ?? input.startedAt)
75
+ const idle = Math.max(0, now - last)
76
+ let verdict: LivenessVerdict
77
+ if (input.finished) verdict = 'finished'
78
+ else if (!input.alive) verdict = 'dead'
79
+ else if (input.waitingOn !== undefined) verdict = 'waiting'
80
+ else if (idle >= stalledMs) verdict = 'stalled'
81
+ else if (idle >= quietMs) verdict = 'waiting'
82
+ else verdict = 'progressing'
83
+ const waitingOn =
84
+ verdict === 'waiting' && input.waitingOn !== undefined ? input.waitingOn : undefined
85
+ const waitingSince = input.waitingSince ?? last
86
+ return {
87
+ kind: input.kind,
88
+ id: input.id,
89
+ label: input.label,
90
+ ...(input.where !== undefined ? { where: input.where } : {}),
91
+ verdict,
92
+ idleSeconds: seconds(idle),
93
+ ageSeconds: seconds(now - input.startedAt),
94
+ ...(waitingOn !== undefined ? { waitingOn, waitingSeconds: seconds(now - waitingSince) } : {}),
95
+ }
96
+ }
97
+
98
+ /** `45s`, `3m 05s`, `1h 02m`: short, for a line a person or the model reads. */
99
+ export function formatLivenessAge(totalSeconds: number): string {
100
+ const s = Math.max(0, Math.floor(totalSeconds))
101
+ if (s < 60) return `${s}s`
102
+ const m = Math.floor(s / 60)
103
+ if (m < 60) return `${m}m ${String(s % 60).padStart(2, '0')}s`
104
+ return `${Math.floor(m / 60)}h ${String(m % 60).padStart(2, '0')}m`
105
+ }
106
+
107
+ function oneLine(text: string, max: number): string {
108
+ const flat = text.replace(/\s+/g, ' ').trim()
109
+ return flat.length <= max ? flat : `${flat.slice(0, max - 1)}…`
110
+ }
111
+
112
+ const LABEL_MAX = 80
113
+ const WHERE_MAX = 120
114
+
115
+ /**
116
+ * One line per item, the same for the note and for the list reads:
117
+ * `job b1a2 "npm test" - progressing - last progress 4s ago - at: compiling`.
118
+ * Everything free-form is clipped and flattened; the line carries data, not
119
+ * instructions.
120
+ */
121
+ export function formatLivenessLine(item: Liveness): string {
122
+ const parts = [`${item.kind} ${item.id} "${oneLine(item.label, LABEL_MAX)}"`]
123
+ if (item.verdict === 'waiting' && item.waitingOn !== undefined) {
124
+ parts.push(
125
+ `waiting on ${oneLine(item.waitingOn, LABEL_MAX)} for ${formatLivenessAge(item.waitingSeconds ?? item.idleSeconds)}`,
126
+ )
127
+ } else if (item.verdict === 'finished') {
128
+ parts.push(`finished after ${formatLivenessAge(item.ageSeconds)}`)
129
+ } else if (item.verdict === 'dead') {
130
+ parts.push(
131
+ `dead: gone without a result after ${formatLivenessAge(item.ageSeconds)}, last progress ${formatLivenessAge(item.idleSeconds)} ago`,
132
+ )
133
+ } else {
134
+ parts.push(item.verdict)
135
+ parts.push(
136
+ item.idleSeconds === 0
137
+ ? 'last progress just now'
138
+ : `last progress ${formatLivenessAge(item.idleSeconds)} ago`,
139
+ )
140
+ }
141
+ if (item.where !== undefined && item.where.length > 0)
142
+ parts.push(`at: ${oneLine(item.where, WHERE_MAX)}`)
143
+ return parts.join(' - ')
144
+ }