@namzu/sdk 72.0.0 → 73.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 (228) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  3. package/dist/agents/examples/SupervisorAgent.js +5 -0
  4. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  5. package/dist/authorization/protected-paths.d.ts.map +1 -1
  6. package/dist/authorization/protected-paths.js +4 -0
  7. package/dist/authorization/protected-paths.js.map +1 -1
  8. package/dist/compaction/manual.d.ts +16 -1
  9. package/dist/compaction/manual.d.ts.map +1 -1
  10. package/dist/compaction/manual.js +63 -8
  11. package/dist/compaction/manual.js.map +1 -1
  12. package/dist/compaction/precompute.d.ts +179 -0
  13. package/dist/compaction/precompute.d.ts.map +1 -0
  14. package/dist/compaction/precompute.js +274 -0
  15. package/dist/compaction/precompute.js.map +1 -0
  16. package/dist/config/runtime.d.ts +4 -0
  17. package/dist/config/runtime.d.ts.map +1 -1
  18. package/dist/config/runtime.js +17 -0
  19. package/dist/config/runtime.js.map +1 -1
  20. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  21. package/dist/manager/agent/lifecycle.js +8 -0
  22. package/dist/manager/agent/lifecycle.js.map +1 -1
  23. package/dist/manager/session/turn-recorder.d.ts +26 -0
  24. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  25. package/dist/manager/session/turn-recorder.js +72 -5
  26. package/dist/manager/session/turn-recorder.js.map +1 -1
  27. package/dist/peers/protocol.d.ts +9 -0
  28. package/dist/peers/protocol.d.ts.map +1 -1
  29. package/dist/peers/protocol.js +4 -0
  30. package/dist/peers/protocol.js.map +1 -1
  31. package/dist/peers/record.d.ts +6 -0
  32. package/dist/peers/record.d.ts.map +1 -1
  33. package/dist/peers/record.js +4 -0
  34. package/dist/peers/record.js.map +1 -1
  35. package/dist/plugin/index.d.ts +2 -2
  36. package/dist/plugin/index.d.ts.map +1 -1
  37. package/dist/plugin/index.js +1 -1
  38. package/dist/plugin/index.js.map +1 -1
  39. package/dist/plugin/shell-hook.d.ts +30 -0
  40. package/dist/plugin/shell-hook.d.ts.map +1 -1
  41. package/dist/plugin/shell-hook.js +35 -0
  42. package/dist/plugin/shell-hook.js.map +1 -1
  43. package/dist/public-runtime.d.ts +5 -3
  44. package/dist/public-runtime.d.ts.map +1 -1
  45. package/dist/public-runtime.js +5 -3
  46. package/dist/public-runtime.js.map +1 -1
  47. package/dist/public-tools.d.ts +1 -1
  48. package/dist/public-tools.d.ts.map +1 -1
  49. package/dist/public-tools.js +1 -1
  50. package/dist/public-tools.js.map +1 -1
  51. package/dist/public-types.d.ts +3 -2
  52. package/dist/public-types.d.ts.map +1 -1
  53. package/dist/registry/command/kernel-commands.d.ts +7 -1
  54. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  55. package/dist/registry/command/kernel-commands.js +40 -2
  56. package/dist/registry/command/kernel-commands.js.map +1 -1
  57. package/dist/registry/tool/execute.d.ts +8 -0
  58. package/dist/registry/tool/execute.d.ts.map +1 -1
  59. package/dist/registry/tool/execute.js +12 -0
  60. package/dist/registry/tool/execute.js.map +1 -1
  61. package/dist/runtime/query/budget-nudge.d.ts +27 -0
  62. package/dist/runtime/query/budget-nudge.d.ts.map +1 -0
  63. package/dist/runtime/query/budget-nudge.js +66 -0
  64. package/dist/runtime/query/budget-nudge.js.map +1 -0
  65. package/dist/runtime/query/compact-session.d.ts +9 -0
  66. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  67. package/dist/runtime/query/compact-session.js +157 -80
  68. package/dist/runtime/query/compact-session.js.map +1 -1
  69. package/dist/runtime/query/guard.d.ts +8 -0
  70. package/dist/runtime/query/guard.d.ts.map +1 -1
  71. package/dist/runtime/query/guard.js +20 -0
  72. package/dist/runtime/query/guard.js.map +1 -1
  73. package/dist/runtime/query/iteration/index.d.ts +2 -0
  74. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  75. package/dist/runtime/query/iteration/index.js +27 -1
  76. package/dist/runtime/query/iteration/index.js.map +1 -1
  77. package/dist/runtime/query/iteration/phases/compaction.d.ts +1 -0
  78. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  79. package/dist/runtime/query/iteration/phases/compaction.js +143 -40
  80. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  81. package/dist/runtime/query/iteration/phases/precompute.d.ts +60 -0
  82. package/dist/runtime/query/iteration/phases/precompute.d.ts.map +1 -0
  83. package/dist/runtime/query/iteration/phases/precompute.js +240 -0
  84. package/dist/runtime/query/iteration/phases/precompute.js.map +1 -0
  85. package/dist/runtime/query/turn/outcome-ledger.d.ts +14 -0
  86. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  87. package/dist/runtime/query/turn/outcome-ledger.js +28 -0
  88. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  89. package/dist/store/goal/gates.d.ts +53 -0
  90. package/dist/store/goal/gates.d.ts.map +1 -0
  91. package/dist/store/goal/gates.js +664 -0
  92. package/dist/store/goal/gates.js.map +1 -0
  93. package/dist/store/goal/index.d.ts +16 -1
  94. package/dist/store/goal/index.d.ts.map +1 -1
  95. package/dist/store/goal/index.js +74 -0
  96. package/dist/store/goal/index.js.map +1 -1
  97. package/dist/tools/builtins/bash.js +1 -1
  98. package/dist/tools/builtins/bash.js.map +1 -1
  99. package/dist/tools/builtins/browser.d.ts.map +1 -1
  100. package/dist/tools/builtins/browser.js +2 -0
  101. package/dist/tools/builtins/browser.js.map +1 -1
  102. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  103. package/dist/tools/builtins/monitor.js +1 -0
  104. package/dist/tools/builtins/monitor.js.map +1 -1
  105. package/dist/tools/builtins/search-tools.js +2 -2
  106. package/dist/tools/builtins/search-tools.js.map +1 -1
  107. package/dist/tools/builtins/sleep-guard.js +1 -1
  108. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  109. package/dist/tools/builtins/wait-for-job.js +1 -1
  110. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  111. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  112. package/dist/tools/coordinator/ask-user-question.js +25 -0
  113. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  114. package/dist/tools/coordinator/index.d.ts.map +1 -1
  115. package/dist/tools/coordinator/index.js +3 -0
  116. package/dist/tools/coordinator/index.js.map +1 -1
  117. package/dist/tools/defineTool.d.ts +2 -0
  118. package/dist/tools/defineTool.d.ts.map +1 -1
  119. package/dist/tools/defineTool.js +3 -0
  120. package/dist/tools/defineTool.js.map +1 -1
  121. package/dist/tools/goal/confirmation.d.ts +40 -2
  122. package/dist/tools/goal/confirmation.d.ts.map +1 -1
  123. package/dist/tools/goal/confirmation.js +117 -0
  124. package/dist/tools/goal/confirmation.js.map +1 -1
  125. package/dist/tools/goal/index.d.ts.map +1 -1
  126. package/dist/tools/goal/index.js +14 -2
  127. package/dist/tools/goal/index.js.map +1 -1
  128. package/dist/tools/memory/save.d.ts.map +1 -1
  129. package/dist/tools/memory/save.js +1 -0
  130. package/dist/tools/memory/save.js.map +1 -1
  131. package/dist/tools/schedules/index.d.ts +1 -0
  132. package/dist/tools/schedules/index.d.ts.map +1 -1
  133. package/dist/tools/schedules/index.js +1 -0
  134. package/dist/tools/schedules/index.js.map +1 -1
  135. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  136. package/dist/tools/schedules/loop-tool.js +1 -0
  137. package/dist/tools/schedules/loop-tool.js.map +1 -1
  138. package/dist/tools/schedules/present.d.ts.map +1 -1
  139. package/dist/tools/schedules/present.js +2 -0
  140. package/dist/tools/schedules/present.js.map +1 -1
  141. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  142. package/dist/tools/schedules/schedule-tool.js +79 -9
  143. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  144. package/dist/tools/schedules/self-tool.d.ts +16 -0
  145. package/dist/tools/schedules/self-tool.d.ts.map +1 -0
  146. package/dist/tools/schedules/self-tool.js +140 -0
  147. package/dist/tools/schedules/self-tool.js.map +1 -0
  148. package/dist/tools/schedules/timer-tools.d.ts.map +1 -1
  149. package/dist/tools/schedules/timer-tools.js +1 -0
  150. package/dist/tools/schedules/timer-tools.js.map +1 -1
  151. package/dist/tools/schedules/types.d.ts +63 -0
  152. package/dist/tools/schedules/types.d.ts.map +1 -1
  153. package/dist/toolsets/manager.d.ts +10 -0
  154. package/dist/toolsets/manager.d.ts.map +1 -1
  155. package/dist/toolsets/manager.js +56 -7
  156. package/dist/toolsets/manager.js.map +1 -1
  157. package/dist/types/agent/supervisor.d.ts +10 -0
  158. package/dist/types/agent/supervisor.d.ts.map +1 -1
  159. package/dist/types/agent/task.d.ts +6 -0
  160. package/dist/types/agent/task.d.ts.map +1 -1
  161. package/dist/types/goal/index.d.ts +66 -0
  162. package/dist/types/goal/index.d.ts.map +1 -1
  163. package/dist/types/session/events.d.ts +7 -0
  164. package/dist/types/session/events.d.ts.map +1 -1
  165. package/dist/types/session/events.js.map +1 -1
  166. package/dist/types/session/outcome.d.ts +12 -0
  167. package/dist/types/session/outcome.d.ts.map +1 -1
  168. package/dist/types/session/outcome.js.map +1 -1
  169. package/dist/types/session/records.d.ts +79 -1
  170. package/dist/types/session/records.d.ts.map +1 -1
  171. package/dist/types/session/records.js +24 -0
  172. package/dist/types/session/records.js.map +1 -1
  173. package/dist/types/tool/index.d.ts +7 -0
  174. package/dist/types/tool/index.d.ts.map +1 -1
  175. package/dist/types/tool/index.js.map +1 -1
  176. package/package.json +1 -1
  177. package/src/agents/examples/SupervisorAgent.ts +5 -0
  178. package/src/authorization/protected-paths.ts +4 -0
  179. package/src/compaction/manual.ts +83 -12
  180. package/src/compaction/precompute.ts +390 -0
  181. package/src/config/runtime.ts +17 -0
  182. package/src/manager/agent/lifecycle.ts +9 -0
  183. package/src/manager/session/turn-recorder.ts +92 -5
  184. package/src/peers/protocol.ts +4 -0
  185. package/src/peers/record.ts +4 -0
  186. package/src/plugin/index.ts +2 -0
  187. package/src/plugin/shell-hook.ts +60 -0
  188. package/src/public-runtime.ts +27 -0
  189. package/src/public-tools.ts +2 -0
  190. package/src/public-types.ts +8 -0
  191. package/src/registry/command/kernel-commands.ts +62 -3
  192. package/src/registry/tool/execute.ts +14 -0
  193. package/src/runtime/query/budget-nudge.ts +92 -0
  194. package/src/runtime/query/compact-session.ts +194 -74
  195. package/src/runtime/query/guard.ts +22 -0
  196. package/src/runtime/query/iteration/index.ts +26 -1
  197. package/src/runtime/query/iteration/phases/compaction.ts +147 -41
  198. package/src/runtime/query/iteration/phases/precompute.ts +277 -0
  199. package/src/runtime/query/turn/outcome-ledger.ts +34 -0
  200. package/src/store/goal/gates.ts +738 -0
  201. package/src/store/goal/index.ts +109 -0
  202. package/src/tools/builtins/bash.ts +1 -1
  203. package/src/tools/builtins/browser.ts +4 -0
  204. package/src/tools/builtins/monitor.ts +2 -0
  205. package/src/tools/builtins/search-tools.ts +2 -2
  206. package/src/tools/builtins/sleep-guard.ts +1 -1
  207. package/src/tools/builtins/wait-for-job.ts +1 -1
  208. package/src/tools/coordinator/ask-user-question.ts +37 -10
  209. package/src/tools/coordinator/index.ts +3 -0
  210. package/src/tools/defineTool.ts +5 -0
  211. package/src/tools/goal/confirmation.ts +171 -3
  212. package/src/tools/goal/index.ts +15 -3
  213. package/src/tools/memory/save.ts +2 -0
  214. package/src/tools/schedules/index.ts +1 -0
  215. package/src/tools/schedules/loop-tool.ts +2 -0
  216. package/src/tools/schedules/present.ts +2 -0
  217. package/src/tools/schedules/schedule-tool.ts +84 -9
  218. package/src/tools/schedules/self-tool.ts +152 -0
  219. package/src/tools/schedules/timer-tools.ts +2 -0
  220. package/src/tools/schedules/types.ts +62 -0
  221. package/src/toolsets/manager.ts +55 -8
  222. package/src/types/agent/supervisor.ts +11 -0
  223. package/src/types/agent/task.ts +7 -0
  224. package/src/types/goal/index.ts +72 -0
  225. package/src/types/session/events.ts +7 -0
  226. package/src/types/session/outcome.ts +16 -1
  227. package/src/types/session/records.ts +27 -0
  228. package/src/types/tool/index.ts +7 -0
@@ -2123,6 +2123,37 @@ export type ShellHookMcpToolCaller = (request: {
2123
2123
  readonly signal: AbortSignal
2124
2124
  }) => Promise<ShellHookMcpToolAnswer | undefined>
2125
2125
 
2126
+ /** A part `matcherForms: 'names'` accepts: a name, or a prefix with one `*` at the end only. */
2127
+ const NAME_ONLY_PART = /^[A-Za-z0-9_.:-]+\*?$|^\*$/
2128
+
2129
+ /** The types an entry can have (`type` absent reads as `command`). */
2130
+ export type ShellHookHandlerType = 'command' | 'http' | 'prompt' | 'mcp_tool'
2131
+
2132
+ /**
2133
+ * Why `entry` may not be registered under `options.handlerTypes` and
2134
+ * `options.matcherForms`, or `undefined` when it may. The wording names what
2135
+ * was refused and which option refused it.
2136
+ */
2137
+ export function shellHookEntryLimitProblem(
2138
+ entry: Pick<ShellHookHandler, 'matcher'> & { readonly type?: ShellHookHandlerType },
2139
+ options: Pick<ShellHookOptions, 'handlerTypes' | 'matcherForms'>,
2140
+ ): string | undefined {
2141
+ const type: ShellHookHandlerType = entry.type ?? 'command'
2142
+ if (options.handlerTypes !== undefined && !options.handlerTypes.includes(type)) {
2143
+ const allowed = options.handlerTypes.length > 0 ? options.handlerTypes.join(', ') : 'none'
2144
+ return `a ${type} hook is refused: this host accepts only ${allowed} hooks (handlerTypes), so the entry was not attached`
2145
+ }
2146
+ if (options.matcherForms === 'names') {
2147
+ const matcher = entry.matcher
2148
+ if (matcher === undefined || matcher.trim() === '' || matcher.trim() === '*') return undefined
2149
+ const parts = matcher.split(/[|,]/).map((part) => part.trim())
2150
+ if (!parts.every((part) => NAME_ONLY_PART.test(part)) || matcher.includes('.*')) {
2151
+ return `the matcher "${matcher}" is refused: this host accepts only a name, names joined by |, a prefix ending in * (mcp__server__*), empty or * (matcherForms: names), so the entry was not attached`
2152
+ }
2153
+ }
2154
+ return undefined
2155
+ }
2156
+
2126
2157
  export interface ShellHookOptions {
2127
2158
  /** Answers `prompt` hooks. Without it a `prompt` hook is logged and lets the action go ahead. */
2128
2159
  readonly judge?: ShellHookJudge
@@ -2209,6 +2240,26 @@ export interface ShellHookOptions {
2209
2240
  * is read as before.
2210
2241
  */
2211
2242
  readonly restrictVerdicts?: boolean
2243
+ /**
2244
+ * The entry types this adapter accepts: an allow-list of `command`, `http`,
2245
+ * `prompt` and `mcp_tool`. An entry of any other type is refused when it is
2246
+ * registered, before anything is attached, with a refusal that names the
2247
+ * entry's type and the list (`createShellHook` and `attachShellHooks` throw
2248
+ * it). For a host that runs untrusted entries and wants no web request, no
2249
+ * judge call and no tool call to leave from its own process. Absent, every
2250
+ * type is accepted. An entry with no `type` is a `command`.
2251
+ */
2252
+ readonly handlerTypes?: readonly ShellHookHandlerType[]
2253
+ /**
2254
+ * How an entry's `matcher` may be written. `'names'` refuses, when the entry
2255
+ * is registered, any matcher that is not a plain name list: a name, names
2256
+ * joined by `|` (or `,`), a prefix ending in `*` (`mcp__server__*`), empty or
2257
+ * `*`. A regular expression is never compiled or run then, so a pattern that
2258
+ * backtracks without bound cannot reach the host. The refusal names the
2259
+ * matcher. Absent, a matcher is read as before (a name list, or a regular
2260
+ * expression).
2261
+ */
2262
+ readonly matcherForms?: 'names'
2212
2263
  /**
2213
2264
  * Called when a hook of this adapter ran out its deadline and was ended.
2214
2265
  * `hook` is the command, URL or prompt text the entry names.
@@ -2518,6 +2569,8 @@ export function createShellHook(
2518
2569
  configured: ShellHookHandler,
2519
2570
  options: ShellHookOptions,
2520
2571
  ): PluginHookDefinition {
2572
+ const refusal = shellHookEntryLimitProblem(configured, options)
2573
+ if (refusal !== undefined) throw new Error(`Shell hook ${event}: ${refusal}`)
2521
2574
  const log = options.log ?? NOOP_LOGGER
2522
2575
  const envSlot = nextHookEnvSlot++
2523
2576
  const eventDefault = options.defaultTimeoutMs?.[event]
@@ -2741,6 +2794,13 @@ export function attachShellHooks(
2741
2794
  )
2742
2795
  }
2743
2796
  }
2797
+ // Every entry is checked against the limits first, so a refusal leaves nothing attached.
2798
+ for (const event of SHELL_HOOK_EVENTS) {
2799
+ for (const entry of hooks[event] ?? []) {
2800
+ const refusal = shellHookEntryLimitProblem(entry, options)
2801
+ if (refusal !== undefined) throw new Error(`Shell hook ${event}: ${refusal}`)
2802
+ }
2803
+ }
2744
2804
  const pluginId = options.pluginId ?? SHELL_HOOKS_PLUGIN_ID
2745
2805
  let count = 0
2746
2806
  for (const event of SHELL_HOOK_EVENTS) {
@@ -288,6 +288,26 @@ export { DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES } from './runtime/query/request-
288
288
  export { DEFAULT_SANDBOX_TEARDOWN_TIMEOUT_MS } from './runtime/query/sandbox-lifecycle.js'
289
289
 
290
290
  export { isTrustedReadOnly } from './tools/trusted-read-only.js'
291
+ export {
292
+ GOAL_GATES_BLOCK_CODE,
293
+ GOAL_GATE_DEFAULT_MAX_FAILING_ROUNDS,
294
+ GOAL_GATE_DEFAULT_TIMEOUT_MS,
295
+ GOAL_GATE_MAX_ARGS,
296
+ GOAL_GATE_MAX_ARG_CHARS,
297
+ GOAL_GATE_MAX_CWD_CHARS,
298
+ GOAL_GATE_MAX_ENTRIES,
299
+ GOAL_GATE_MAX_NAME_CHARS,
300
+ GOAL_GATE_MAX_TAIL_CHARS,
301
+ GOAL_GATE_MAX_TIMEOUT_MS,
302
+ GOAL_GATE_MIN_TIMEOUT_MS,
303
+ goalGateCommandText,
304
+ goalGateFailedNames,
305
+ goalGatePassed,
306
+ goalGateTail,
307
+ goalGatesBlockSentence,
308
+ goalGatesFrom,
309
+ parseGoalGateEntry,
310
+ } from './store/goal/gates.js'
291
311
  export {
292
312
  GoalRoundAuthorityError,
293
313
  MIN_GOAL_BLOCK_ROUND,
@@ -301,6 +321,7 @@ export {
301
321
  NO_CHECK_REASON_CODE,
302
322
  decideGoalConfirmation,
303
323
  describeGoalEnding,
324
+ gateFailureNote,
304
325
  parseGoalEvidence,
305
326
  recordSentence,
306
327
  } from './tools/goal/confirmation.js'
@@ -488,6 +509,10 @@ export type { AbandonTurnOptions, SessionLocatorOptions } from './runtime/query/
488
509
  export { CacheClock } from './runtime/cache-clock.js'
489
510
  export type { CacheClockState } from './runtime/cache-clock.js'
490
511
  export { compactSession, compactSessionRange } from './runtime/query/compact-session.js'
512
+ export {
513
+ type PreparedSpend,
514
+ releasePreparedSummary,
515
+ } from './compaction/precompute.js'
491
516
  export type {
492
517
  CompactSessionParams,
493
518
  CompactSessionRangeParams,
@@ -809,6 +834,7 @@ export {
809
834
  MAX_COMPACTION_SUMMARY_HOOK_CHARS,
810
835
  MAX_LAST_MESSAGE_HOOK_CHARS,
811
836
  createShellHook,
837
+ shellHookEntryLimitProblem,
812
838
  DEFAULT_SHELL_HOOK_TIMEOUT_MS,
813
839
  definePlugin,
814
840
  frameOperatorHookContext,
@@ -2123,6 +2149,7 @@ export {
2123
2149
  export {
2124
2150
  ChildOutcomeRecordedRecordSchema,
2125
2151
  ChildSessionMetaSchema,
2152
+ CompactionMeasuredRecordSchema,
2126
2153
  CompactionRecordSchema,
2127
2154
  ExternalRefSchema,
2128
2155
  IgnorableRecordSchema,
@@ -286,6 +286,7 @@ export { buildAgentTool, type AgentToolOptions } from './tools/coordinator/agent
286
286
  // jobs, draws the confirmation and computes every field it shows. Register
287
287
  // only where a person can confirm (never headless, scheduled or delegated).
288
288
  export {
289
+ buildScheduleSelfTool,
289
290
  buildScheduleTools,
290
291
  buildSessionLoopTools,
291
292
  buildSessionTimerTools,
@@ -293,6 +294,7 @@ export {
293
294
  clampWakeUpDelay,
294
295
  revealHiddenCharacters,
295
296
  scanSchedulePrompt,
297
+ SCHEDULE_SELF_TOOL_NAME,
296
298
  SCHEDULE_TOOL_NAME,
297
299
  SESSION_LOOP_TOOL_NAME,
298
300
  TIMER_CANCEL_TOOL_NAME,
@@ -254,6 +254,7 @@ export type {
254
254
  ShellHookOnFailure,
255
255
  ShellHookCall,
256
256
  ShellHookInput,
257
+ ShellHookHandlerType,
257
258
  ShellHookOptions,
258
259
  ShellHookPathFilter,
259
260
  ShellHookOutcome,
@@ -464,6 +465,10 @@ export type {
464
465
  SessionGoalStore,
465
466
  } from './store/goal/index.js'
466
467
  export type { ResolveGoalRoundAuthority } from './tools/goal/index.js'
468
+ export type {
469
+ GoalGateHost,
470
+ GoalGateRunInput,
471
+ } from './tools/goal/confirmation.js'
467
472
  export type {
468
473
  GoalConfirmationOptions,
469
474
  GoalDecision,
@@ -754,7 +759,10 @@ export type {
754
759
  ScheduleJobPreview,
755
760
  ScheduleJobSummary,
756
761
  ScheduleJobUpdateProposal,
762
+ ScheduleNoteSummary,
757
763
  ScheduleRuleEffect,
764
+ ScheduleSelfChanges,
765
+ ScheduleSelfHost,
758
766
  ScheduleToolHost,
759
767
  ScheduleUpdateRequest,
760
768
  SelfPacedHost,
@@ -1,4 +1,5 @@
1
1
  import type { SessionGoalActivation } from '../../manager/goal/activation.js'
2
+ import { goalGateCommandText } from '../../store/goal/gates.js'
2
3
  import {
3
4
  GoalExistsError,
4
5
  GoalNotFoundError,
@@ -10,7 +11,15 @@ import {
10
11
  goalTokensText,
11
12
  } from '../../store/goal/index.js'
12
13
  import type { HostCommandDescriptor } from '../../types/command/index.js'
13
- import type { GoalConfirmedBy, GoalGuards, GoalRef, SessionGoal } from '../../types/goal/index.js'
14
+ import type {
15
+ GoalConfirmedBy,
16
+ GoalGateResult,
17
+ GoalGates,
18
+ GoalGatesSpec,
19
+ GoalGuards,
20
+ GoalRef,
21
+ SessionGoal,
22
+ } from '../../types/goal/index.js'
14
23
  import type { SessionId, TenantId } from '../../types/ids/index.js'
15
24
  import type { Skill } from '../../types/skills/index.js'
16
25
  import { isInvocableBy, skillInvocation } from '../../types/skills/index.js'
@@ -63,6 +72,10 @@ export interface GoalCommandScope {
63
72
  export interface GoalCommandDefaults {
64
73
  readonly maxGoalRounds?: number
65
74
  readonly guards?: GoalGuards
75
+ /** Completion gates a goal created here carries, shown when it starts. */
76
+ readonly gates?: GoalGatesSpec
77
+ /** A sentence added to a new goal's answer, for example why configured gates were left off. */
78
+ readonly gatesNotice?: string
66
79
  }
67
80
 
68
81
  const GOAL_ARGUMENTS =
@@ -189,6 +202,42 @@ function goalCommands(goal: SessionGoal, armed: boolean): string {
189
202
  return '/goal set <objective>, /goal clear'
190
203
  }
191
204
 
205
+ function gateResultText(result: GoalGateResult | undefined): string {
206
+ if (result === undefined) return 'not run yet'
207
+ const when = new Date(result.at).toISOString().replace('T', ' ').slice(0, 19)
208
+ switch (result.status) {
209
+ case 'passed':
210
+ return `passed (${when} UTC)${result.notRerun ? ', files unchanged since' : ''}`
211
+ case 'failed':
212
+ return `failed${result.exitCode !== undefined ? `, exit ${result.exitCode}` : ''} (${when} UTC)${result.notRerun ? ', not run again: files unchanged since' : ''}`
213
+ case 'timed-out':
214
+ return `timed out (${when} UTC)${result.notRerun ? ', not run again: files unchanged since' : ''}`
215
+ case 'refused':
216
+ return `not run: ${result.reason ?? 'refused'} (${when} UTC)`
217
+ }
218
+ }
219
+
220
+ /** The gates a goal carries and what they last showed, as lines of the status. */
221
+ export function renderGoalGates(gates: GoalGates | undefined): string[] {
222
+ if (gates === undefined || gates.entries.length === 0) return []
223
+ const lines = [
224
+ 'Completion gates (run by Namzu when each round ends; the goal is complete only when every one passes on the files as they are):',
225
+ ]
226
+ for (const [index, entry] of gates.entries.entries()) {
227
+ const result = gates.results.find((candidate) => candidate.name === entry.name)
228
+ const where = entry.cwd !== undefined ? ` in ${entry.cwd}` : ''
229
+ const limit =
230
+ entry.timeoutMs !== undefined ? `, limit ${Math.round(entry.timeoutMs / 1000)} s` : ''
231
+ lines.push(
232
+ ` ${index + 1}. ${entry.name}: ${goalGateCommandText(entry.command)}${where}${limit} - ${gateResultText(result)}`,
233
+ )
234
+ }
235
+ lines.push(
236
+ ` Failing rounds in a row: ${gates.failingRounds} of ${gates.maxFailingRounds}; the goal stops at ${gates.maxFailingRounds}.`,
237
+ )
238
+ return lines
239
+ }
240
+
192
241
  function renderGoal(
193
242
  title: string,
194
243
  goal: SessionGoal,
@@ -219,12 +268,17 @@ function renderGoal(
219
268
  ...(goal.missing && goal.missing.length > 0
220
269
  ? [`Still missing: ${goal.missing.join('; ')}`]
221
270
  : []),
271
+ ...renderGoalGates(goal.gates),
222
272
  `Objective: ${goal.objective}`,
223
273
  '',
224
274
  `Commands: ${goalCommands(goal, armed)}`,
225
275
  ].join('\n')
226
276
  }
227
277
 
278
+ function withGatesNotice(message: string, defaults: GoalCommandDefaults | undefined): string {
279
+ return defaults?.gatesNotice ? `${message}\n${defaults.gatesNotice}` : message
280
+ }
281
+
228
282
  function renderScopedGoal(title: string, goal: SessionGoal, scope: GoalCommandScope): string {
229
283
  return renderGoal(
230
284
  title,
@@ -306,13 +360,14 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
306
360
  ...(maxGoalRounds !== undefined ? { maxGoalRounds } : {}),
307
361
  ...(Object.keys(guards).length > 0 ? { guards } : {}),
308
362
  ...(flag.confirmedBy !== undefined ? { confirmedBy: flag.confirmedBy } : {}),
363
+ ...(defaults?.gates ? { gates: defaults.gates } : {}),
309
364
  },
310
365
  scope.tenantId,
311
366
  )
312
367
  scope.activation?.arm(created)
313
368
  return {
314
369
  kind: 'ack' as const,
315
- message: renderScopedGoal('Goal created', created, scope),
370
+ message: withGatesNotice(renderScopedGoal('Goal created', created, scope), defaults),
316
371
  }
317
372
  }
318
373
  case 'edit': {
@@ -326,13 +381,17 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
326
381
  ? { maxGoalRounds: scope.defaults.maxGoalRounds }
327
382
  : {}),
328
383
  ...(scope.defaults?.guards ? { guards: scope.defaults.guards } : {}),
384
+ ...(scope.defaults?.gates ? { gates: scope.defaults.gates } : {}),
329
385
  },
330
386
  scope.tenantId,
331
387
  )
332
388
  scope.activation?.arm(replacement)
333
389
  return {
334
390
  kind: 'ack' as const,
335
- message: renderScopedGoal('Goal created', replacement, scope),
391
+ message: withGatesNotice(
392
+ renderScopedGoal('Goal created', replacement, scope),
393
+ scope.defaults,
394
+ ),
336
395
  }
337
396
  }
338
397
  const wasArmed = scope.activation?.isArmed(scope.sessionId, current) ?? false
@@ -107,3 +107,17 @@ export function toolDiscoveryHint(description: string, maxLength = 100): string
107
107
  if (sentence.length <= maxLength) return sentence
108
108
  return `${sentence.slice(0, maxLength - 1).trimEnd()}…`
109
109
  }
110
+
111
+ /**
112
+ * The catalogue line of a deferred tool: its explicit `discoveryHint` when it
113
+ * has one, else the first-sentence rule of {@link toolDiscoveryHint}.
114
+ */
115
+ export function toolCatalogueHint(
116
+ tool: { readonly description: string; readonly discoveryHint?: string },
117
+ maxLength = 100,
118
+ ): string {
119
+ const explicit = tool.discoveryHint?.trim().replace(/\s+/g, ' ') ?? ''
120
+ if (explicit.length === 0) return toolDiscoveryHint(tool.description, maxLength)
121
+ if (explicit.length <= maxLength) return explicit
122
+ return `${explicit.slice(0, maxLength - 1).trimEnd()}…`
123
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The line a run reads shortly before one of its own limits ends it.
3
+ *
4
+ * Without it the iteration cap and the time limit cut a run off between two
5
+ * calls with no word to the model, which is the moment it most needs to leave
6
+ * its work in a state someone can pick up. The line is a request, never a
7
+ * change of limit: nothing here moves the cap or the clock.
8
+ */
9
+
10
+ /** Where the line is due: first when the remaining share is small, again when it is smaller. */
11
+ export type BudgetNudgeStage = 0 | 1 | 2
12
+
13
+ export interface BudgetLeft {
14
+ /** Calls left before the iteration cap, counting the one being prepared. */
15
+ iterations?: { left: number; total: number }
16
+ /** Milliseconds left before the time limit. */
17
+ timeMs?: { left: number; total: number }
18
+ }
19
+
20
+ const FIRST_ITERATION_FLOOR = 5
21
+ const SECOND_ITERATION_FLOOR = 2
22
+ const FIRST_TIME_FLOOR_MS = 2 * 60_000
23
+ const SECOND_TIME_FLOOR_MS = 30_000
24
+ const FIRST_SHARE = 0.1
25
+ const SECOND_SHARE = 0.03
26
+
27
+ /**
28
+ * The larger of the fixed floor and the share, held to half of what the
29
+ * stage before it allowed so a short budget is not nagged from its first
30
+ * call: a ten-call run is told at four calls left, never at the start.
31
+ */
32
+ function threshold(total: number, floor: number, share: number, ceiling: number): number {
33
+ return Math.min(Math.max(floor, total * share), ceiling)
34
+ }
35
+
36
+ function reached(left: number, total: number, floors: [number, number], shares: [number, number]) {
37
+ const first = threshold(total, floors[0], shares[0], total / 2)
38
+ const second = threshold(total, floors[1], shares[1], first / 2)
39
+ if (left <= second) return 2
40
+ if (left <= first) return 1
41
+ return 0
42
+ }
43
+
44
+ /** The stage the remaining budget has reached; 0 when no limit is near or none is set. */
45
+ export function budgetNudgeStage(left: BudgetLeft): BudgetNudgeStage {
46
+ let stage: BudgetNudgeStage = 0
47
+ if (left.iterations && left.iterations.total > 0) {
48
+ stage = Math.max(
49
+ stage,
50
+ reached(
51
+ left.iterations.left,
52
+ left.iterations.total,
53
+ [FIRST_ITERATION_FLOOR, SECOND_ITERATION_FLOOR],
54
+ [FIRST_SHARE, SECOND_SHARE],
55
+ ),
56
+ ) as BudgetNudgeStage
57
+ }
58
+ if (left.timeMs && Number.isFinite(left.timeMs.total) && left.timeMs.total > 0) {
59
+ stage = Math.max(
60
+ stage,
61
+ reached(
62
+ left.timeMs.left,
63
+ left.timeMs.total,
64
+ [FIRST_TIME_FLOOR_MS, SECOND_TIME_FLOOR_MS],
65
+ [FIRST_SHARE, SECOND_SHARE],
66
+ ),
67
+ ) as BudgetNudgeStage
68
+ }
69
+ return stage
70
+ }
71
+
72
+ function duration(ms: number): string {
73
+ const seconds = Math.max(0, Math.round(ms / 1000))
74
+ if (seconds < 90) return `${seconds} seconds`
75
+ return `${Math.round(seconds / 60)} minutes`
76
+ }
77
+
78
+ /** The one line: how much is left, and what to do with it. */
79
+ export function budgetNudgeText(left: BudgetLeft, stage: BudgetNudgeStage): string | null {
80
+ if (stage === 0) return null
81
+ const parts: string[] = []
82
+ if (left.iterations && left.iterations.total > 0) {
83
+ const n = Math.max(0, left.iterations.left)
84
+ parts.push(`${n} more ${n === 1 ? 'step' : 'steps'}`)
85
+ }
86
+ if (left.timeMs && Number.isFinite(left.timeMs.total) && left.timeMs.total > 0) {
87
+ parts.push(`about ${duration(left.timeMs.left)}`)
88
+ }
89
+ if (parts.length === 0) return null
90
+ const urgency = stage === 2 ? 'Very little is left' : 'This run is nearing its limit'
91
+ return `${urgency}: ${parts.join(' and ')} before it is stopped. Leave the work in a working state, write down what is unfinished, then finish. The limit does not move.`
92
+ }