@namzu/sdk 71.0.1 → 72.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 (268) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +1 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/authorization/readonly-commands.d.ts +9 -1
  6. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  7. package/dist/authorization/readonly-commands.js +70 -4
  8. package/dist/authorization/readonly-commands.js.map +1 -1
  9. package/dist/authorization/shell-paths.d.ts.map +1 -1
  10. package/dist/authorization/shell-paths.js +68 -16
  11. package/dist/authorization/shell-paths.js.map +1 -1
  12. package/dist/compaction/index.d.ts +1 -1
  13. package/dist/compaction/index.d.ts.map +1 -1
  14. package/dist/compaction/index.js +1 -1
  15. package/dist/compaction/index.js.map +1 -1
  16. package/dist/compaction/manual.d.ts +8 -0
  17. package/dist/compaction/manual.d.ts.map +1 -1
  18. package/dist/compaction/manual.js +18 -14
  19. package/dist/compaction/manual.js.map +1 -1
  20. package/dist/compaction/model-summary.d.ts +24 -6
  21. package/dist/compaction/model-summary.d.ts.map +1 -1
  22. package/dist/compaction/model-summary.js +152 -28
  23. package/dist/compaction/model-summary.js.map +1 -1
  24. package/dist/compaction/restore.d.ts +23 -0
  25. package/dist/compaction/restore.d.ts.map +1 -1
  26. package/dist/compaction/restore.js +59 -1
  27. package/dist/compaction/restore.js.map +1 -1
  28. package/dist/compaction/summary.d.ts +37 -2
  29. package/dist/compaction/summary.d.ts.map +1 -1
  30. package/dist/compaction/summary.js +46 -6
  31. package/dist/compaction/summary.js.map +1 -1
  32. package/dist/config/registry.d.ts +2 -0
  33. package/dist/config/registry.d.ts.map +1 -1
  34. package/dist/config/registry.js +76 -5
  35. package/dist/config/registry.js.map +1 -1
  36. package/dist/config/runtime.js +3 -3
  37. package/dist/config/runtime.js.map +1 -1
  38. package/dist/connector/index.d.ts +2 -2
  39. package/dist/connector/index.d.ts.map +1 -1
  40. package/dist/connector/index.js +1 -1
  41. package/dist/connector/index.js.map +1 -1
  42. package/dist/connector/mcp/adapter.d.ts +8 -0
  43. package/dist/connector/mcp/adapter.d.ts.map +1 -1
  44. package/dist/connector/mcp/adapter.js +131 -1
  45. package/dist/connector/mcp/adapter.js.map +1 -1
  46. package/dist/connector/mcp/client.d.ts +26 -6
  47. package/dist/connector/mcp/client.d.ts.map +1 -1
  48. package/dist/connector/mcp/client.js +49 -7
  49. package/dist/connector/mcp/client.js.map +1 -1
  50. package/dist/connector/mcp/index.d.ts +2 -0
  51. package/dist/connector/mcp/index.d.ts.map +1 -1
  52. package/dist/connector/mcp/index.js +1 -0
  53. package/dist/connector/mcp/index.js.map +1 -1
  54. package/dist/connector/mcp/sandbox-stdio.d.ts +67 -0
  55. package/dist/connector/mcp/sandbox-stdio.d.ts.map +1 -0
  56. package/dist/connector/mcp/sandbox-stdio.js +178 -0
  57. package/dist/connector/mcp/sandbox-stdio.js.map +1 -0
  58. package/dist/connector/mcp/stdio-program.d.ts +34 -0
  59. package/dist/connector/mcp/stdio-program.d.ts.map +1 -0
  60. package/dist/connector/mcp/stdio-program.js +47 -0
  61. package/dist/connector/mcp/stdio-program.js.map +1 -0
  62. package/dist/connector/mcp/stdio.d.ts +12 -0
  63. package/dist/connector/mcp/stdio.d.ts.map +1 -1
  64. package/dist/connector/mcp/stdio.js +54 -7
  65. package/dist/connector/mcp/stdio.js.map +1 -1
  66. package/dist/connector/web/guarded-fetch.d.ts +51 -2
  67. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  68. package/dist/connector/web/guarded-fetch.js +140 -19
  69. package/dist/connector/web/guarded-fetch.js.map +1 -1
  70. package/dist/connector/web/index.d.ts +2 -2
  71. package/dist/connector/web/index.d.ts.map +1 -1
  72. package/dist/connector/web/index.js +1 -1
  73. package/dist/connector/web/index.js.map +1 -1
  74. package/dist/constants/mcp/index.d.ts +29 -0
  75. package/dist/constants/mcp/index.d.ts.map +1 -1
  76. package/dist/constants/mcp/index.js +29 -0
  77. package/dist/constants/mcp/index.js.map +1 -1
  78. package/dist/manager/agent/lifecycle.d.ts +18 -1
  79. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  80. package/dist/manager/agent/lifecycle.js +53 -8
  81. package/dist/manager/agent/lifecycle.js.map +1 -1
  82. package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
  83. package/dist/plugin/hook-module/capabilities.js +24 -13
  84. package/dist/plugin/hook-module/capabilities.js.map +1 -1
  85. package/dist/plugin/hook-module/host.d.ts +31 -0
  86. package/dist/plugin/hook-module/host.d.ts.map +1 -1
  87. package/dist/plugin/hook-module/host.js +56 -13
  88. package/dist/plugin/hook-module/host.js.map +1 -1
  89. package/dist/plugin/hook-module/index.d.ts +3 -2
  90. package/dist/plugin/hook-module/index.d.ts.map +1 -1
  91. package/dist/plugin/hook-module/index.js +2 -1
  92. package/dist/plugin/hook-module/index.js.map +1 -1
  93. package/dist/plugin/index.d.ts +2 -1
  94. package/dist/plugin/index.d.ts.map +1 -1
  95. package/dist/plugin/index.js +1 -0
  96. package/dist/plugin/index.js.map +1 -1
  97. package/dist/plugin/shell-hook-execute.d.ts +55 -0
  98. package/dist/plugin/shell-hook-execute.d.ts.map +1 -0
  99. package/dist/plugin/shell-hook-execute.js +73 -0
  100. package/dist/plugin/shell-hook-execute.js.map +1 -0
  101. package/dist/plugin/shell-hook-restrict.d.ts +31 -0
  102. package/dist/plugin/shell-hook-restrict.d.ts.map +1 -0
  103. package/dist/plugin/shell-hook-restrict.js +69 -0
  104. package/dist/plugin/shell-hook-restrict.js.map +1 -0
  105. package/dist/plugin/shell-hook.d.ts +73 -4
  106. package/dist/plugin/shell-hook.d.ts.map +1 -1
  107. package/dist/plugin/shell-hook.js +118 -17
  108. package/dist/plugin/shell-hook.js.map +1 -1
  109. package/dist/public-runtime.d.ts +9 -7
  110. package/dist/public-runtime.d.ts.map +1 -1
  111. package/dist/public-runtime.js +6 -5
  112. package/dist/public-runtime.js.map +1 -1
  113. package/dist/public-types.d.ts +4 -2
  114. package/dist/public-types.d.ts.map +1 -1
  115. package/dist/runtime/jobs/websocket-source.d.ts +2 -22
  116. package/dist/runtime/jobs/websocket-source.d.ts.map +1 -1
  117. package/dist/runtime/jobs/websocket-source.js +2 -33
  118. package/dist/runtime/jobs/websocket-source.js.map +1 -1
  119. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  120. package/dist/runtime/query/compact-session.js +5 -0
  121. package/dist/runtime/query/compact-session.js.map +1 -1
  122. package/dist/runtime/query/events.d.ts +7 -0
  123. package/dist/runtime/query/events.d.ts.map +1 -1
  124. package/dist/runtime/query/events.js +29 -11
  125. package/dist/runtime/query/events.js.map +1 -1
  126. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  127. package/dist/runtime/query/executor/tool-call-admission.js +51 -10
  128. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  129. package/dist/runtime/query/index.d.ts +6 -0
  130. package/dist/runtime/query/index.d.ts.map +1 -1
  131. package/dist/runtime/query/index.js +3 -0
  132. package/dist/runtime/query/index.js.map +1 -1
  133. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  134. package/dist/runtime/query/iteration/phases/compaction.js +21 -3
  135. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  136. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  137. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  138. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  139. package/dist/runtime/query/path-escalation.d.ts.map +1 -1
  140. package/dist/runtime/query/path-escalation.js +90 -17
  141. package/dist/runtime/query/path-escalation.js.map +1 -1
  142. package/dist/runtime/query/steering.d.ts +15 -0
  143. package/dist/runtime/query/steering.d.ts.map +1 -1
  144. package/dist/runtime/query/steering.js +27 -3
  145. package/dist/runtime/query/steering.js.map +1 -1
  146. package/dist/scheduler/completion-inbox.d.ts.map +1 -1
  147. package/dist/scheduler/completion-inbox.js +15 -0
  148. package/dist/scheduler/completion-inbox.js.map +1 -1
  149. package/dist/session/workspace/driver.d.ts +12 -0
  150. package/dist/session/workspace/driver.d.ts.map +1 -1
  151. package/dist/session/workspace/git-worktree.d.ts +16 -0
  152. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  153. package/dist/session/workspace/git-worktree.js +35 -0
  154. package/dist/session/workspace/git-worktree.js.map +1 -1
  155. package/dist/session/workspace/holds.d.ts +78 -0
  156. package/dist/session/workspace/holds.d.ts.map +1 -0
  157. package/dist/session/workspace/holds.js +150 -0
  158. package/dist/session/workspace/holds.js.map +1 -0
  159. package/dist/session/workspace/index.d.ts +3 -1
  160. package/dist/session/workspace/index.d.ts.map +1 -1
  161. package/dist/session/workspace/index.js +2 -1
  162. package/dist/session/workspace/index.js.map +1 -1
  163. package/dist/store/config/index.d.ts +3 -0
  164. package/dist/store/config/index.d.ts.map +1 -1
  165. package/dist/store/config/index.js +3 -0
  166. package/dist/store/config/index.js.map +1 -1
  167. package/dist/store/session-index/index.d.ts +13 -0
  168. package/dist/store/session-index/index.d.ts.map +1 -1
  169. package/dist/store/session-index/index.js +1 -0
  170. package/dist/store/session-index/index.js.map +1 -1
  171. package/dist/store/session-index/rebuild.d.ts +12 -0
  172. package/dist/store/session-index/rebuild.d.ts.map +1 -1
  173. package/dist/store/session-index/rebuild.js +20 -4
  174. package/dist/store/session-index/rebuild.js.map +1 -1
  175. package/dist/store/session-index/sqlite.d.ts +20 -0
  176. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  177. package/dist/store/session-index/sqlite.js +50 -12
  178. package/dist/store/session-index/sqlite.js.map +1 -1
  179. package/dist/tools/admit-facts.d.ts.map +1 -1
  180. package/dist/tools/admit-facts.js +59 -0
  181. package/dist/tools/admit-facts.js.map +1 -1
  182. package/dist/tools/builtins/grep.d.ts.map +1 -1
  183. package/dist/tools/builtins/grep.js +57 -0
  184. package/dist/tools/builtins/grep.js.map +1 -1
  185. package/dist/tools/builtins/lsp.d.ts.map +1 -1
  186. package/dist/tools/builtins/lsp.js +41 -4
  187. package/dist/tools/builtins/lsp.js.map +1 -1
  188. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  189. package/dist/tools/coordinator/ask-user-question.js +67 -3
  190. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  191. package/dist/turn/memory-promoter.d.ts.map +1 -1
  192. package/dist/turn/memory-promoter.js +20 -4
  193. package/dist/turn/memory-promoter.js.map +1 -1
  194. package/dist/types/agent/base.d.ts +6 -0
  195. package/dist/types/agent/base.d.ts.map +1 -1
  196. package/dist/types/agent/task.d.ts +5 -0
  197. package/dist/types/agent/task.d.ts.map +1 -1
  198. package/dist/types/agent/task.js.map +1 -1
  199. package/dist/types/code-navigation/index.d.ts +34 -4
  200. package/dist/types/code-navigation/index.d.ts.map +1 -1
  201. package/dist/types/hitl/index.d.ts +8 -0
  202. package/dist/types/hitl/index.d.ts.map +1 -1
  203. package/dist/types/hitl/index.js.map +1 -1
  204. package/dist/types/message/index.d.ts +7 -0
  205. package/dist/types/message/index.d.ts.map +1 -1
  206. package/dist/types/message/index.js.map +1 -1
  207. package/dist/types/tool/presentation.d.ts +21 -0
  208. package/dist/types/tool/presentation.d.ts.map +1 -1
  209. package/package.json +6 -6
  210. package/src/agents/QueryAgent.ts +1 -0
  211. package/src/authorization/readonly-commands.ts +72 -4
  212. package/src/authorization/shell-paths.ts +75 -18
  213. package/src/compaction/index.ts +1 -0
  214. package/src/compaction/manual.ts +48 -12
  215. package/src/compaction/model-summary.ts +163 -28
  216. package/src/compaction/restore.ts +74 -1
  217. package/src/compaction/summary.ts +69 -3
  218. package/src/config/registry.ts +87 -5
  219. package/src/config/runtime.ts +3 -3
  220. package/src/connector/index.ts +3 -0
  221. package/src/connector/mcp/adapter.ts +137 -1
  222. package/src/connector/mcp/client.ts +49 -7
  223. package/src/connector/mcp/index.ts +5 -0
  224. package/src/connector/mcp/sandbox-stdio.ts +214 -0
  225. package/src/connector/mcp/stdio-program.ts +68 -0
  226. package/src/connector/mcp/stdio.ts +61 -7
  227. package/src/connector/web/guarded-fetch.ts +197 -30
  228. package/src/connector/web/index.ts +4 -1
  229. package/src/constants/mcp/index.ts +31 -0
  230. package/src/manager/agent/lifecycle.ts +58 -13
  231. package/src/plugin/hook-module/capabilities.ts +36 -14
  232. package/src/plugin/hook-module/host.ts +86 -13
  233. package/src/plugin/hook-module/index.ts +3 -0
  234. package/src/plugin/index.ts +4 -0
  235. package/src/plugin/shell-hook-execute.ts +126 -0
  236. package/src/plugin/shell-hook-restrict.ts +66 -0
  237. package/src/plugin/shell-hook.ts +209 -16
  238. package/src/public-runtime.ts +19 -0
  239. package/src/public-types.ts +20 -0
  240. package/src/runtime/jobs/websocket-source.ts +2 -46
  241. package/src/runtime/query/compact-session.ts +5 -0
  242. package/src/runtime/query/events.ts +29 -11
  243. package/src/runtime/query/executor/tool-call-admission.ts +62 -17
  244. package/src/runtime/query/index.ts +10 -0
  245. package/src/runtime/query/iteration/phases/compaction.ts +26 -2
  246. package/src/runtime/query/iteration/phases/context.ts +6 -0
  247. package/src/runtime/query/path-escalation.ts +102 -16
  248. package/src/runtime/query/steering.ts +38 -3
  249. package/src/scheduler/completion-inbox.ts +14 -0
  250. package/src/session/workspace/driver.ts +12 -0
  251. package/src/session/workspace/git-worktree.ts +49 -0
  252. package/src/session/workspace/holds.ts +201 -0
  253. package/src/session/workspace/index.ts +13 -1
  254. package/src/store/config/index.ts +6 -0
  255. package/src/store/session-index/index.ts +14 -0
  256. package/src/store/session-index/rebuild.ts +22 -4
  257. package/src/store/session-index/sqlite.ts +63 -14
  258. package/src/tools/admit-facts.ts +64 -0
  259. package/src/tools/builtins/grep.ts +52 -0
  260. package/src/tools/builtins/lsp.ts +47 -4
  261. package/src/tools/coordinator/ask-user-question.ts +88 -4
  262. package/src/turn/memory-promoter.ts +24 -3
  263. package/src/types/agent/base.ts +7 -0
  264. package/src/types/agent/task.ts +5 -0
  265. package/src/types/code-navigation/index.ts +48 -4
  266. package/src/types/hitl/index.ts +8 -0
  267. package/src/types/message/index.ts +7 -0
  268. package/src/types/tool/presentation.ts +22 -0
@@ -110,8 +110,22 @@ export const LspTool = defineTool({
110
110
  }
111
111
  }
112
112
 
113
+ // Checked before anything is spawned. A turn that was stopped must not
114
+ // pay for starting a language server, and the server must not be asked a
115
+ // question whose answer nobody will read.
116
+ if (context.abortSignal?.aborted) {
117
+ return interruptedResult(
118
+ input.operation,
119
+ 'The turn was stopped before the language server was asked.',
120
+ )
121
+ }
122
+ // The turn's own signal, so Esc reaches the request instead of leaving it
123
+ // to the provider's deadline: a server that is still indexing would hold
124
+ // the turn open with nothing able to end it.
125
+ const options = { signal: context.abortSignal }
126
+
113
127
  if (input.operation === 'symbols') {
114
- const result = await provider.symbols(input.query, absolute)
128
+ const result = await provider.symbols(input.query, absolute, options)
115
129
  switch (result.kind) {
116
130
  case 'symbols': {
117
131
  if (result.symbols.length === 0) {
@@ -133,11 +147,13 @@ export const LspTool = defineTool({
133
147
  return { success: false, output: '', error: unsupportedMessage(result.reason) }
134
148
  case 'failed':
135
149
  return { success: false, output: '', error: failedMessage(result.error) }
150
+ case 'interrupted':
151
+ return interruptedResult('symbols', result.reason)
136
152
  }
137
153
  }
138
154
 
139
155
  if (input.operation === 'hover') {
140
- const result = await provider.hover(absolute as string, input.line, input.character)
156
+ const result = await provider.hover(absolute as string, input.line, input.character, options)
141
157
  switch (result.kind) {
142
158
  case 'hover':
143
159
  return {
@@ -154,13 +170,15 @@ export const LspTool = defineTool({
154
170
  return { success: false, output: '', error: unsupportedMessage(result.reason) }
155
171
  case 'failed':
156
172
  return { success: false, output: '', error: failedMessage(result.error) }
173
+ case 'interrupted':
174
+ return interruptedResult('hover', result.reason)
157
175
  }
158
176
  }
159
177
 
160
178
  const result =
161
179
  input.operation === 'definition'
162
- ? await provider.definition(absolute as string, input.line, input.character)
163
- : await provider.references(absolute as string, input.line, input.character)
180
+ ? await provider.definition(absolute as string, input.line, input.character, options)
181
+ : await provider.references(absolute as string, input.line, input.character, options)
164
182
 
165
183
  switch (result.kind) {
166
184
  case 'locations': {
@@ -189,6 +207,8 @@ export const LspTool = defineTool({
189
207
  return { success: false, output: '', error: unsupportedMessage(result.reason) }
190
208
  case 'failed':
191
209
  return { success: false, output: '', error: failedMessage(result.error) }
210
+ case 'interrupted':
211
+ return interruptedResult(input.operation, result.reason)
192
212
  }
193
213
  },
194
214
  })
@@ -203,6 +223,29 @@ function failedMessage(error: string): string {
203
223
  return `Code navigation failed, so this answer is unknown rather than empty: ${error}`
204
224
  }
205
225
 
226
+ /**
227
+ * An answer nobody finished asking for.
228
+ *
229
+ * The ordinary end of a call the person stopped, and the one case that must
230
+ * not read as a broken server: the next move is to ask again, not to fall
231
+ * back to `grep` or to conclude the symbol has no callers. It says "unknown
232
+ * rather than empty" for the same reason a failure does — a model acts on the
233
+ * absence of an answer.
234
+ */
235
+ function interruptedMessage(reason: string): string {
236
+ return `The call was interrupted before the language server answered, so this answer is unknown rather than empty: ${reason} Ask again if the answer is still needed.`
237
+ }
238
+
239
+ /** Structured as well as worded, because a host renders a stopped call differently. */
240
+ function interruptedResult(operation: LspInput['operation'], reason: string): ToolResult {
241
+ return {
242
+ success: false,
243
+ output: '',
244
+ error: interruptedMessage(reason),
245
+ data: { operation, interrupted: true },
246
+ }
247
+ }
248
+
206
249
  /**
207
250
  * The tool, only when there is something for it to call.
208
251
  *
@@ -20,7 +20,7 @@ import type {
20
20
  UserQuestionOption,
21
21
  } from '../../types/hitl/index.js'
22
22
  import type { SessionId, TurnId } from '../../types/ids/index.js'
23
- import type { ToolDefinition } from '../../types/tool/index.js'
23
+ import type { ToolDefinition, ToolFacts } from '../../types/tool/index.js'
24
24
  import { generateCheckpointId } from '../../utils/id.js'
25
25
  import { defineTool } from '../defineTool.js'
26
26
  import { questionOptions } from './question-options.js'
@@ -246,6 +246,23 @@ export interface AskUserQuestionToolOptions {
246
246
  const NO_ANSWER_TEXT =
247
247
  'The user did not answer this question. Do not assume a choice or consent; proceed on your best judgment or continue without this information.'
248
248
 
249
+ const DISCUSS_TEXT =
250
+ "The user doesn't want to answer yet: they want to talk the question over first. Do not assume a choice or consent, and do not ask again. Reply briefly, ask what is unclear, and follow what they say next."
251
+
252
+ const DISCUSS_BATCH_TEXT =
253
+ "The user doesn't want to answer yet: they want to talk these questions over first. Do not assume a choice or consent, and do not ask again. Reply briefly, ask what is unclear, and follow what they say next."
254
+
255
+ /** The questions a talk-it-over left open, each with its options and the fact that nothing was answered. */
256
+ function discussQuestions(items: readonly UserQuestionItem[]): string {
257
+ return items
258
+ .map((i) => {
259
+ const options =
260
+ i.options.length > 0 ? `\n Options: ${i.options.map((o) => o.label).join(' / ')}` : ''
261
+ return `- "${i.question}"${options}\n (No answer provided)`
262
+ })
263
+ .join('\n')
264
+ }
265
+
249
266
  const NO_ANSWER_BATCH_TEXT =
250
267
  'The user did not answer these questions. Do not assume a choice or consent; proceed on your best judgment or continue without this information.'
251
268
 
@@ -255,6 +272,7 @@ interface ReadAnswer {
255
272
  readonly selected: readonly {
256
273
  id: string
257
274
  label: string
275
+ description?: string
258
276
  recommended?: true
259
277
  }[]
260
278
  readonly freeText: string
@@ -299,15 +317,53 @@ function readAnswers(
299
317
  const selected = (item.multiSelect ? chosen : chosen.slice(0, 1)).map((opt) => ({
300
318
  id: opt.id,
301
319
  label: opt.label,
320
+ ...(opt.description ? { description: opt.description } : {}),
302
321
  ...(opt.recommended === true ? { recommended: true as const } : {}),
303
322
  }))
304
323
  return { item, selected, freeText: entry?.freeText?.trim() ?? '' }
305
324
  })
306
325
  }
307
326
 
327
+ /**
328
+ * What each picked option means, in the context of the question it answers:
329
+ * the option's description, which the model wrote and the person read when
330
+ * choosing. Nothing for an option that carried none, and nothing broader
331
+ * than the options that were actually picked.
332
+ */
333
+ function pickedMeanings(answers: readonly ReadAnswer[], batch: boolean): string {
334
+ const lines = answers.flatMap(({ item, selected }) =>
335
+ selected.flatMap((s) =>
336
+ s.description
337
+ ? [`- "${s.label}"${batch ? ` (${labelOf(item)})` : ''}: ${s.description}`]
338
+ : [],
339
+ ),
340
+ )
341
+ return lines.length > 0 ? `\nWhat the picked options mean:\n${lines.join('\n')}` : ''
342
+ }
343
+
344
+ /** What the person answered, as typed fields: the host draws its block from these, not from the receipt text. */
345
+ function questionFacts(
346
+ outcome: 'answered' | 'discussed',
347
+ answers: readonly ReadAnswer[],
348
+ ): ToolFacts {
349
+ return {
350
+ kind: 'questions',
351
+ outcome,
352
+ questions: answers.map(({ item, selected, freeText }) => ({
353
+ question: item.question,
354
+ ...(item.header !== undefined ? { header: item.header } : {}),
355
+ options: item.options.map((o) => o.label),
356
+ ...(selected.length > 0 ? { picked: selected.map((s) => s.label) } : {}),
357
+ ...(freeText ? { freeText } : {}),
358
+ answered: outcome === 'answered' && isAnswered({ item, selected, freeText }),
359
+ })),
360
+ }
361
+ }
362
+
308
363
  function describeSingle(answer: ReadAnswer): {
309
364
  output: string
310
365
  data: Record<string, unknown>
366
+ facts: ToolFacts
311
367
  } {
312
368
  const { item, selected, freeText } = answer
313
369
  let output: string
@@ -318,8 +374,10 @@ function describeSingle(answer: ReadAnswer): {
318
374
  } else {
319
375
  output = `User answered "${item.question}" in their own words: "${freeText}"`
320
376
  }
377
+ output += pickedMeanings([answer], false)
321
378
  return {
322
379
  output,
380
+ facts: questionFacts('answered', [answer]),
323
381
  data: {
324
382
  question: item.question,
325
383
  selected,
@@ -334,6 +392,7 @@ const labelOf = (item: UserQuestionItem): string => item.header ?? item.question
334
392
  function describeBatch(answers: readonly ReadAnswer[]): {
335
393
  output: string
336
394
  data: Record<string, unknown>
395
+ facts: ToolFacts
337
396
  } {
338
397
  const lines = answers.map((answer) => {
339
398
  const { item, selected, freeText } = answer
@@ -346,7 +405,8 @@ function describeBatch(answers: readonly ReadAnswer[]): {
346
405
  })
347
406
  const answered = answers.filter(isAnswered).length
348
407
  return {
349
- output: `The user answered ${answered} of ${answers.length} questions:\n${lines.join('\n')}`,
408
+ output: `The user answered ${answered} of ${answers.length} questions:\n${lines.join('\n')}${pickedMeanings(answers, true)}`,
409
+ facts: questionFacts('answered', answers),
350
410
  data: {
351
411
  questions: answers.map(({ item }) => ({
352
412
  questionId: item.id,
@@ -377,7 +437,7 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
377
437
  description:
378
438
  'Ask the user when you are blocked on a decision that is genuinely theirs to make: one you cannot resolve from their request, your tools, the files you can read, or sensible defaults. The question must be the one undecidable thing in this task. Look up anything a tool can discover (what you can read, list or search) and reuse what the conversation already answered, because asking for it wastes the user\'s time. Leave out questions like "Shall I proceed?"; plan ratification goes through ' +
379
439
  planApproval +
380
- '. Provide 2-4 genuinely distinct options derived from the actual context, with concrete paths rather than generic placeholders (for example, asked to prepare a presentation, ask who the audience is, with an option for each plausible audience). Give each option a short label (1-5 words) and a one-line description of what practically changes if it is chosen; put qualifiers in the description, since a label with a trailing note reads as two choices. To recommend an option, put it first and set recommended: true on it: the host marks it for the user, so the label stays plain. Set multiSelect: true only when several options can apply at once. An option may carry a preview (plain text or markdown) that the host shows beside the list while it is focused; use it only when seeing the thing helps the choice. A free-text "Something else" choice is always shown by the host, so the options cover only the real alternatives. Put the questions in the questions array: one entry for a single decision. Put several entries in the same call only when they are related decisions that all block your next step and the user can answer them together (for example which account, for what purpose, which environment before a credentialed step), at most 4, each with a short unique header; the user answers them all in one card and you get one answer per question. Ask questions that depend on one another\'s answers one at a time, since the first answer changes the second. Most work needs at most 2-3 questions in all, so prefer proceeding on stated defaults over interrogating the user. Answers come only from the user, because a made-up answer or synthetic content would pass for their decision (unless they explicitly asked for a random/test scenario). The answers arrive as this tool\'s result; a question the result says was not answered stays open, and if the result says the user did not answer at all, do not ask again: proceed on your best judgment without assuming consent. Example call: {"questions":[{"header":"Scope","question":"Which part of the project should the change cover?","options":[{"label":"One module","description":"Only the module you named","recommended":true},{"label":"Whole project","description":"Every module that uses it"}]}]}.',
440
+ '. Provide 2-4 genuinely distinct options derived from the actual context, with concrete paths rather than generic placeholders (for example, asked to prepare a presentation, ask who the audience is, with an option for each plausible audience). Give each option a short label (1-5 words) and a one-line description of what practically changes if it is chosen; put qualifiers in the description, since a label with a trailing note reads as two choices. To recommend an option, put it first and set recommended: true on it: the host marks it for the user, so the label stays plain. Set multiSelect: true only when several options can apply at once. An option may carry a preview (plain text or markdown) that the host shows beside the list while it is focused; use it only when seeing the thing helps the choice. A free-text "Other" choice is always shown by the host, so the options cover only the real alternatives. Put the questions in the questions array: one entry for a single decision. Put several entries in the same call only when they are related decisions that all block your next step and the user can answer them together (for example which account, for what purpose, which environment before a credentialed step), at most 4, each with a short unique header; the user answers them all in one card and you get one answer per question. Ask questions that depend on one another\'s answers one at a time, since the first answer changes the second. Most work needs at most 2-3 questions in all, so prefer proceeding on stated defaults over interrogating the user. Answers come only from the user, because a made-up answer or synthetic content would pass for their decision (unless they explicitly asked for a random/test scenario). The answers arrive as this tool\'s result; a question the result says was not answered stays open, and if the result says the user did not answer at all, do not ask again: proceed on your best judgment without assuming consent. Example call: {"questions":[{"header":"Scope","question":"Which part of the project should the change cover?","options":[{"label":"One module","description":"Only the module you named","recommended":true},{"label":"Whole project","description":"Every module that uses it"}]}]}.',
381
441
  inputSchema,
382
442
  modelInputSchema: structuredClone(askUserQuestionModelInputSchema),
383
443
  enforceModelInput: true,
@@ -500,6 +560,25 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
500
560
  }
501
561
 
502
562
  if (decision.action !== 'answer_question') return noAnswer
563
+ if (decision.discuss === true) {
564
+ if (decision.questionId !== undefined && decision.questionId !== toolUseId) return noAnswer
565
+ // An error result, not a success: nothing was answered, and the
566
+ // model must not read the call as having gone through.
567
+ return {
568
+ success: false,
569
+ output: `${batch ? DISCUSS_BATCH_TEXT : DISCUSS_TEXT}\n\nQuestions asked:\n${discussQuestions(items)}`,
570
+ facts: questionFacts(
571
+ 'discussed',
572
+ items.map((item) => ({ item, selected: [], freeText: '' })),
573
+ ),
574
+ data: {
575
+ question: first.question,
576
+ ...(batch ? { questions: items.map((i) => i.question) } : {}),
577
+ answered: false,
578
+ discuss: true,
579
+ },
580
+ }
581
+ }
503
582
  if (decision.questionId !== undefined && decision.questionId !== toolUseId) {
504
583
  // Misdirection guard: this answer was meant for a different
505
584
  // question parked under the same turn (stale client). Never
@@ -511,7 +590,12 @@ export function buildAskUserQuestionTool(config: AskUserQuestionToolOptions): To
511
590
  if (!answers.some(isAnswered)) return noAnswer
512
591
 
513
592
  const described = batch ? describeBatch(answers) : describeSingle(answers[0] as ReadAnswer)
514
- return { success: true, output: described.output, data: described.data }
593
+ return {
594
+ success: true,
595
+ output: described.output,
596
+ data: described.data,
597
+ facts: described.facts,
598
+ }
515
599
  },
516
600
  })
517
601
  }
@@ -88,6 +88,25 @@ function knowledge(
88
88
  return out
89
89
  }
90
90
 
91
+ const TITLE_MAX = 80
92
+
93
+ /**
94
+ * A record's title from what it holds: its first claim, in the order the
95
+ * sections are rendered. The turn's task is the session's first message and
96
+ * is the same for every record the session writes, so it names none of them.
97
+ * A candidate with no usable claim falls back to the turn id.
98
+ */
99
+ function titleOf(
100
+ candidate: SessionMemoryCandidate,
101
+ sections: readonly (readonly [string, readonly string[]])[],
102
+ ): string {
103
+ const first = sections[0]?.[1][0]?.replace(/\s+/g, ' ').trim()
104
+ if (!first) return `Turn ${candidate.turnId}`
105
+ return first.length <= TITLE_MAX
106
+ ? first
107
+ : `${first.slice(0, TITLE_MAX - 1).replace(/[\uD800-\uDBFF]$/, '')}…`
108
+ }
109
+
91
110
  /** Carry actual claims into search results, with their category attribution. */
92
111
  function summarize(sections: readonly (readonly [string, readonly string[]])[]): string {
93
112
  const text = sections.map(([heading, items]) => `${heading}: ${items[0]}`).join('; ')
@@ -96,6 +115,7 @@ function summarize(sections: readonly (readonly [string, readonly string[]])[]):
96
115
 
97
116
  function render(
98
117
  candidate: SessionMemoryCandidate,
118
+ title: string,
99
119
  sections: readonly (readonly [string, readonly string[]])[],
100
120
  ): string {
101
121
  const body = sections.map(
@@ -116,7 +136,7 @@ function render(
116
136
  if (candidate.files.length > 0) {
117
137
  body.push(`## Files touched\n\n${candidate.files.map((f) => `- ${f}`).join('\n')}`)
118
138
  }
119
- return `# ${candidate.task}\n\n${body.join('\n\n')}\n`
139
+ return `# ${title}\n\n${body.join('\n\n')}\n`
120
140
  }
121
141
 
122
142
  /**
@@ -155,10 +175,11 @@ export function createMemoryPromoter(options: MemoryPromoterOptions): PromoteMem
155
175
  )
156
176
  return
157
177
 
178
+ const title = titleOf(candidate, sections)
158
179
  await options.store.create({
159
- title: candidate.task.trim() || `Turn ${candidate.turnId}`,
180
+ title,
160
181
  summary: summarize(sections),
161
- content: render(candidate, sections),
182
+ content: render(candidate, title, sections),
162
183
  tags: [...tags, knowledgeTag],
163
184
  type: 'project',
164
185
  format: 'markdown',
@@ -134,6 +134,13 @@ export interface BaseAgentConfig {
134
134
  */
135
135
  compactionSummaryRoute?: CompactionSummaryRouter
136
136
 
137
+ /**
138
+ * Close a compaction summary with the wording that lets the model ask when
139
+ * something is unclear. Absent or false, it tells the model to continue
140
+ * directly.
141
+ */
142
+ compactionAskWhenUnclear?: boolean
143
+
137
144
  allowedTools?: readonly string[]
138
145
 
139
146
  /**
@@ -26,6 +26,11 @@ export type ChildWorkspaceRequest =
26
26
  readonly mode: 'isolated'
27
27
  readonly backend: 'git-worktree'
28
28
  readonly baseRef?: string
29
+ /**
30
+ * Name of the checkout below the managed worktree folder, and so of its branch
31
+ * (`<branch prefix>/<label>`). Absent, the child's sub-session id names both.
32
+ */
33
+ readonly label?: string
29
34
  /** Relative directory within the checkout where this child starts. */
30
35
  readonly subdirectory?: string
31
36
  /**
@@ -36,11 +36,19 @@ export interface SourceLocation {
36
36
  * looked, and there are none", which is a real answer and the one a
37
37
  * deletion depends on; conflating it with a failure is how an agent
38
38
  * concludes a symbol has no callers because the server never started.
39
+ *
40
+ * `interrupted` is the fourth case and it is neither of the other two: the
41
+ * caller aborted the request (the turn was stopped) before the server
42
+ * answered, so nobody finished asking. Reporting that as `failed` says the
43
+ * resolver broke, which is false and invites a retry against a server that
44
+ * is fine; reporting it as an empty list says the symbol has no callers,
45
+ * which is how a deletion gets made on an answer nobody gave.
39
46
  */
40
47
  export type CodeNavigationResult =
41
48
  | { readonly kind: 'locations'; readonly locations: readonly SourceLocation[] }
42
49
  | { readonly kind: 'unsupported'; readonly reason: string }
43
50
  | { readonly kind: 'failed'; readonly error: string }
51
+ | { readonly kind: 'interrupted'; readonly reason: string }
44
52
 
45
53
  /** A symbol found by name rather than by position. */
46
54
  export interface SymbolLocation extends SourceLocation {
@@ -63,19 +71,51 @@ export type HoverResult =
63
71
  | { readonly kind: 'hover'; readonly contents: string }
64
72
  | { readonly kind: 'unsupported'; readonly reason: string }
65
73
  | { readonly kind: 'failed'; readonly error: string }
74
+ | { readonly kind: 'interrupted'; readonly reason: string }
66
75
 
67
76
  export type SymbolSearchResult =
68
77
  | { readonly kind: 'symbols'; readonly symbols: readonly SymbolLocation[] }
69
78
  | { readonly kind: 'unsupported'; readonly reason: string }
70
79
  | { readonly kind: 'failed'; readonly error: string }
80
+ | { readonly kind: 'interrupted'; readonly reason: string }
81
+
82
+ /**
83
+ * Per-call control, passed alongside a request.
84
+ *
85
+ * `signal` is the turn's abort signal, so a Stop ends the request instead of
86
+ * leaving it to the provider's own deadline: a language server that is still
87
+ * indexing, wedged, or waiting on a binary that never became ready would
88
+ * otherwise hold the turn open with nothing able to end it. A provider that
89
+ * receives an aborted signal answers `interrupted` — never `failed`, and
90
+ * never an empty result — because the answer is unknown for a reason that
91
+ * says nothing about the server.
92
+ */
93
+ export interface CodeNavigationRequestOptions {
94
+ readonly signal?: AbortSignal
95
+ }
71
96
 
72
97
  export interface CodeNavigationProvider {
73
98
  /** Where the symbol under this position is declared. */
74
- definition(file: string, line: number, character: number): Promise<CodeNavigationResult>
99
+ definition(
100
+ file: string,
101
+ line: number,
102
+ character: number,
103
+ options?: CodeNavigationRequestOptions,
104
+ ): Promise<CodeNavigationResult>
75
105
  /** Everywhere the symbol under this position is used. */
76
- references(file: string, line: number, character: number): Promise<CodeNavigationResult>
106
+ references(
107
+ file: string,
108
+ line: number,
109
+ character: number,
110
+ options?: CodeNavigationRequestOptions,
111
+ ): Promise<CodeNavigationResult>
77
112
  /** The symbol's type and documentation, without opening the file. */
78
- hover(file: string, line: number, character: number): Promise<HoverResult>
113
+ hover(
114
+ file: string,
115
+ line: number,
116
+ character: number,
117
+ options?: CodeNavigationRequestOptions,
118
+ ): Promise<HoverResult>
79
119
  /**
80
120
  * Find a declaration by NAME, with no position.
81
121
  *
@@ -88,7 +128,11 @@ export interface CodeNavigationProvider {
88
128
  * `scope` is a file path or an extension that picks which language's
89
129
  * server answers. Absent means every configured language.
90
130
  */
91
- symbols(query: string, scope?: string): Promise<SymbolSearchResult>
131
+ symbols(
132
+ query: string,
133
+ scope?: string,
134
+ options?: CodeNavigationRequestOptions,
135
+ ): Promise<SymbolSearchResult>
92
136
  /**
93
137
  * Stop whatever backs it.
94
138
  *
@@ -123,6 +123,14 @@ export type HITLResumeDecision =
123
123
  * question.
124
124
  */
125
125
  questionId?: string
126
+ /**
127
+ * The person chose to talk the question over instead of answering
128
+ * it. Nothing is picked (send `[]`); the tool returns an error
129
+ * result telling the model the person wants to talk the questions
130
+ * over first, lists them with no answer, and says not to assume a
131
+ * choice and to take the person's next message as the way forward.
132
+ */
133
+ discuss?: true
126
134
  }
127
135
  | { action: 'pause'; reason: string }
128
136
  | { action: 'abort'; reason: string }
@@ -311,6 +311,13 @@ export interface SystemMessage extends BaseMessage {
311
311
  * what an earlier one did.
312
312
  */
313
313
  revealedTools?: readonly ToolRevealReceipt[]
314
+ /**
315
+ * On a compaction summary: the names of the tools the conversation called
316
+ * before the pass cut the calls. Written only by the summary renderer, from
317
+ * the calls themselves, and read back from here and never from the summary's
318
+ * text, so words in a summary cannot add a name. Cumulative across passes.
319
+ */
320
+ toolsUsed?: readonly string[]
314
321
  }
315
322
 
316
323
  /**
@@ -233,6 +233,28 @@ export type ToolFacts =
233
233
  /** The one file is an image the agent made: the prompt it was made from. A host draws the picture itself. */
234
234
  readonly generatedImage?: { readonly prompt: string }
235
235
  }
236
+ | {
237
+ /**
238
+ * What the person answered to an `ask_user_question` call, one entry per
239
+ * question, as they gave it. A host draws its block from these and never
240
+ * reads the person's words back out of the model's receipt.
241
+ */
242
+ readonly kind: 'questions'
243
+ /** `discussed`: the person set the questions aside to talk them over; nothing was answered. */
244
+ readonly outcome: 'answered' | 'discussed'
245
+ readonly questions: readonly {
246
+ readonly question: string
247
+ /** The short label a batch answer is keyed by. */
248
+ readonly header?: string
249
+ /** The options offered, in order (what a talk-it-over lists). */
250
+ readonly options?: readonly string[]
251
+ /** The labels the person picked. */
252
+ readonly picked?: readonly string[]
253
+ /** What the person typed: their own words when nothing was picked, or a note beside the pick. */
254
+ readonly freeText?: string
255
+ readonly answered: boolean
256
+ }[]
257
+ }
236
258
  | {
237
259
  readonly kind: 'failure'
238
260
  readonly reason: ToolFailureReason