@namzu/sdk 61.3.0 → 62.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 (307) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/bridge/acp/permission.d.ts +8 -0
  6. package/dist/bridge/acp/permission.d.ts.map +1 -1
  7. package/dist/bridge/acp/permission.js.map +1 -1
  8. package/dist/bridge/acp/server.d.ts.map +1 -1
  9. package/dist/bridge/acp/server.js +8 -1
  10. package/dist/bridge/acp/server.js.map +1 -1
  11. package/dist/constants/tools/index.d.ts +2 -0
  12. package/dist/constants/tools/index.d.ts.map +1 -1
  13. package/dist/constants/tools/index.js +23 -0
  14. package/dist/constants/tools/index.js.map +1 -1
  15. package/dist/eval/harness-protection.js +1 -1
  16. package/dist/eval/harness-protection.js.map +1 -1
  17. package/dist/learning/cycle.d.ts +5 -3
  18. package/dist/learning/cycle.d.ts.map +1 -1
  19. package/dist/learning/cycle.js +11 -13
  20. package/dist/learning/cycle.js.map +1 -1
  21. package/dist/learning/guidance.d.ts +74 -0
  22. package/dist/learning/guidance.d.ts.map +1 -0
  23. package/dist/learning/guidance.js +259 -0
  24. package/dist/learning/guidance.js.map +1 -0
  25. package/dist/learning/skill.d.ts +2 -2
  26. package/dist/learning/skill.d.ts.map +1 -1
  27. package/dist/learning/skill.js +6 -6
  28. package/dist/learning/skill.js.map +1 -1
  29. package/dist/learning/store.d.ts.map +1 -1
  30. package/dist/learning/store.js +6 -6
  31. package/dist/learning/store.js.map +1 -1
  32. package/dist/pals/communication/ingress-schema.d.ts +8 -8
  33. package/dist/pals/communication/schema.d.ts +2 -2
  34. package/dist/peers/client.d.ts +2 -3
  35. package/dist/peers/client.d.ts.map +1 -1
  36. package/dist/peers/client.js +2 -3
  37. package/dist/peers/client.js.map +1 -1
  38. package/dist/peers/endpoint.d.ts +1 -2
  39. package/dist/peers/endpoint.d.ts.map +1 -1
  40. package/dist/peers/endpoint.js +1 -2
  41. package/dist/peers/endpoint.js.map +1 -1
  42. package/dist/peers/protocol.d.ts.map +1 -1
  43. package/dist/peers/protocol.js +1 -0
  44. package/dist/peers/protocol.js.map +1 -1
  45. package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
  46. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  47. package/dist/prompt/coding-agent-doctrine.js +5 -3
  48. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  49. package/dist/prompt/index.d.ts +0 -4
  50. package/dist/prompt/index.d.ts.map +1 -1
  51. package/dist/prompt/index.js +0 -2
  52. package/dist/prompt/index.js.map +1 -1
  53. package/dist/provider/fallback.d.ts.map +1 -1
  54. package/dist/provider/fallback.js +3 -0
  55. package/dist/provider/fallback.js.map +1 -1
  56. package/dist/provider/idle-timeout.d.ts.map +1 -1
  57. package/dist/provider/idle-timeout.js +5 -0
  58. package/dist/provider/idle-timeout.js.map +1 -1
  59. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  60. package/dist/provider/model-window-suffix.js +1 -0
  61. package/dist/provider/model-window-suffix.js.map +1 -1
  62. package/dist/provider/retry.d.ts.map +1 -1
  63. package/dist/provider/retry.js +5 -0
  64. package/dist/provider/retry.js.map +1 -1
  65. package/dist/provider/step-stopped.d.ts +19 -0
  66. package/dist/provider/step-stopped.d.ts.map +1 -0
  67. package/dist/provider/step-stopped.js +25 -0
  68. package/dist/provider/step-stopped.js.map +1 -0
  69. package/dist/provider/token-budget.d.ts.map +1 -1
  70. package/dist/provider/token-budget.js +6 -1
  71. package/dist/provider/token-budget.js.map +1 -1
  72. package/dist/public-runtime.d.ts +4 -15
  73. package/dist/public-runtime.d.ts.map +1 -1
  74. package/dist/public-runtime.js +3 -14
  75. package/dist/public-runtime.js.map +1 -1
  76. package/dist/public-tools.d.ts +0 -2
  77. package/dist/public-tools.d.ts.map +1 -1
  78. package/dist/public-tools.js +0 -2
  79. package/dist/public-tools.js.map +1 -1
  80. package/dist/public-types.d.ts +3 -21
  81. package/dist/public-types.d.ts.map +1 -1
  82. package/dist/runtime/query/iteration/index.d.ts +17 -0
  83. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  84. package/dist/runtime/query/iteration/index.js +168 -5
  85. package/dist/runtime/query/iteration/index.js.map +1 -1
  86. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  87. package/dist/runtime/query/iteration/phases/per-call-review.js +4 -5
  88. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  89. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  90. package/dist/runtime/query/iteration/phases/tool-review.js +6 -3
  91. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  92. package/dist/runtime/query/iteration/stream-turn.d.ts +9 -1
  93. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  94. package/dist/runtime/query/iteration/stream-turn.js +48 -2
  95. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  96. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  97. package/dist/runtime/query/resume-pending.js +7 -4
  98. package/dist/runtime/query/resume-pending.js.map +1 -1
  99. package/dist/runtime/query/review-policy.d.ts +40 -8
  100. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  101. package/dist/runtime/query/review-policy.js +139 -24
  102. package/dist/runtime/query/review-policy.js.map +1 -1
  103. package/dist/runtime/query/turn/completion-audit.d.ts +32 -0
  104. package/dist/runtime/query/turn/completion-audit.d.ts.map +1 -0
  105. package/dist/runtime/query/turn/completion-audit.js +56 -0
  106. package/dist/runtime/query/turn/completion-audit.js.map +1 -0
  107. package/dist/runtime/query/turn/stall-monitor.d.ts +78 -0
  108. package/dist/runtime/query/turn/stall-monitor.d.ts.map +1 -0
  109. package/dist/runtime/query/turn/stall-monitor.js +101 -0
  110. package/dist/runtime/query/turn/stall-monitor.js.map +1 -0
  111. package/dist/session/paths.d.ts +1 -2
  112. package/dist/session/paths.d.ts.map +1 -1
  113. package/dist/session/paths.js +1 -4
  114. package/dist/session/paths.js.map +1 -1
  115. package/dist/tools/builtins/bash.d.ts +2 -1
  116. package/dist/tools/builtins/bash.d.ts.map +1 -1
  117. package/dist/tools/builtins/bash.js +5 -2
  118. package/dist/tools/builtins/bash.js.map +1 -1
  119. package/dist/tools/builtins/computer-use.d.ts +80 -0
  120. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  121. package/dist/tools/builtins/computer-use.js +172 -9
  122. package/dist/tools/builtins/computer-use.js.map +1 -1
  123. package/dist/tools/builtins/content-fingerprint.d.ts +13 -0
  124. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  125. package/dist/tools/builtins/content-fingerprint.js +25 -0
  126. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  127. package/dist/tools/builtins/edit.d.ts.map +1 -1
  128. package/dist/tools/builtins/edit.js +7 -2
  129. package/dist/tools/builtins/edit.js.map +1 -1
  130. package/dist/tools/builtins/shell-read-credit.d.ts +15 -0
  131. package/dist/tools/builtins/shell-read-credit.d.ts.map +1 -0
  132. package/dist/tools/builtins/shell-read-credit.js +161 -0
  133. package/dist/tools/builtins/shell-read-credit.js.map +1 -0
  134. package/dist/tools/paths.d.ts +15 -2
  135. package/dist/tools/paths.d.ts.map +1 -1
  136. package/dist/tools/paths.js +17 -2
  137. package/dist/tools/paths.js.map +1 -1
  138. package/dist/turn/evidence-recall.d.ts +1 -1
  139. package/dist/turn/evidence-recall.d.ts.map +1 -1
  140. package/dist/turn/evidence-recall.js +5 -14
  141. package/dist/turn/evidence-recall.js.map +1 -1
  142. package/dist/types/acp/index.d.ts +6 -0
  143. package/dist/types/acp/index.d.ts.map +1 -1
  144. package/dist/types/agent/base.d.ts +4 -0
  145. package/dist/types/agent/base.d.ts.map +1 -1
  146. package/dist/types/hitl/index.d.ts +8 -0
  147. package/dist/types/hitl/index.d.ts.map +1 -1
  148. package/dist/types/hitl/index.js.map +1 -1
  149. package/dist/types/ids/index.d.ts +1 -1
  150. package/dist/types/message/index.d.ts +1 -1
  151. package/dist/types/message/index.d.ts.map +1 -1
  152. package/dist/types/message/index.js +1 -0
  153. package/dist/types/message/index.js.map +1 -1
  154. package/dist/types/provider/interface.d.ts +12 -0
  155. package/dist/types/provider/interface.d.ts.map +1 -1
  156. package/dist/types/session/config.d.ts +25 -0
  157. package/dist/types/session/config.d.ts.map +1 -1
  158. package/dist/types/session/records.d.ts.map +1 -1
  159. package/dist/types/session/records.js +2 -0
  160. package/dist/types/session/records.js.map +1 -1
  161. package/dist/types/session/turn.d.ts +1 -1
  162. package/dist/types/session/turn.d.ts.map +1 -1
  163. package/dist/types/session/turn.js.map +1 -1
  164. package/package.json +1 -1
  165. package/src/agents/QueryAgent.ts +2 -0
  166. package/src/bridge/acp/permission.ts +8 -0
  167. package/src/bridge/acp/server.ts +7 -1
  168. package/src/constants/tools/index.ts +27 -0
  169. package/src/eval/harness-protection.ts +1 -1
  170. package/src/learning/cycle.ts +15 -16
  171. package/src/learning/guidance.ts +339 -0
  172. package/src/learning/skill.ts +7 -7
  173. package/src/learning/store.ts +5 -6
  174. package/src/peers/client.ts +2 -3
  175. package/src/peers/endpoint.ts +1 -2
  176. package/src/peers/protocol.ts +1 -0
  177. package/src/prompt/coding-agent-doctrine.ts +5 -3
  178. package/src/prompt/index.ts +0 -4
  179. package/src/provider/fallback.ts +7 -0
  180. package/src/provider/idle-timeout.ts +8 -0
  181. package/src/provider/model-window-suffix.ts +1 -0
  182. package/src/provider/retry.ts +8 -0
  183. package/src/provider/step-stopped.ts +27 -0
  184. package/src/provider/token-budget.ts +6 -1
  185. package/src/public-runtime.ts +10 -28
  186. package/src/public-tools.ts +0 -3
  187. package/src/public-types.ts +5 -137
  188. package/src/runtime/query/iteration/index.ts +207 -5
  189. package/src/runtime/query/iteration/phases/per-call-review.ts +7 -5
  190. package/src/runtime/query/iteration/phases/tool-review.ts +5 -3
  191. package/src/runtime/query/iteration/stream-turn.ts +51 -1
  192. package/src/runtime/query/resume-pending.ts +11 -4
  193. package/src/runtime/query/review-policy.ts +157 -24
  194. package/src/runtime/query/turn/completion-audit.ts +71 -0
  195. package/src/runtime/query/turn/stall-monitor.ts +158 -0
  196. package/src/session/paths.ts +2 -6
  197. package/src/tools/builtins/bash.ts +6 -2
  198. package/src/tools/builtins/computer-use.ts +245 -7
  199. package/src/tools/builtins/content-fingerprint.ts +25 -0
  200. package/src/tools/builtins/edit.ts +11 -2
  201. package/src/tools/builtins/shell-read-credit.ts +159 -0
  202. package/src/tools/paths.ts +18 -2
  203. package/src/turn/evidence-recall.ts +7 -15
  204. package/src/types/acp/index.ts +6 -0
  205. package/src/types/agent/base.ts +4 -0
  206. package/src/types/hitl/index.ts +8 -0
  207. package/src/types/ids/index.ts +1 -1
  208. package/src/types/message/index.ts +1 -0
  209. package/src/types/provider/interface.ts +13 -0
  210. package/src/types/session/config.ts +27 -0
  211. package/src/types/session/records.ts +2 -0
  212. package/src/types/session/turn.ts +2 -1
  213. package/dist/learning/deprecated.d.ts +0 -86
  214. package/dist/learning/deprecated.d.ts.map +0 -1
  215. package/dist/learning/deprecated.js +0 -22
  216. package/dist/learning/deprecated.js.map +0 -1
  217. package/dist/manager/resident/activity.d.ts +0 -74
  218. package/dist/manager/resident/activity.d.ts.map +0 -1
  219. package/dist/manager/resident/activity.js +0 -125
  220. package/dist/manager/resident/activity.js.map +0 -1
  221. package/dist/manager/resident/agenda.d.ts +0 -167
  222. package/dist/manager/resident/agenda.d.ts.map +0 -1
  223. package/dist/manager/resident/agenda.js +0 -588
  224. package/dist/manager/resident/agenda.js.map +0 -1
  225. package/dist/manager/resident/consumption.d.ts +0 -98
  226. package/dist/manager/resident/consumption.d.ts.map +0 -1
  227. package/dist/manager/resident/consumption.js +0 -237
  228. package/dist/manager/resident/consumption.js.map +0 -1
  229. package/dist/manager/resident/delivery-window.d.ts +0 -28
  230. package/dist/manager/resident/delivery-window.d.ts.map +0 -1
  231. package/dist/manager/resident/delivery-window.js +0 -80
  232. package/dist/manager/resident/delivery-window.js.map +0 -1
  233. package/dist/manager/resident/evidence-recall.d.ts +0 -30
  234. package/dist/manager/resident/evidence-recall.d.ts.map +0 -1
  235. package/dist/manager/resident/evidence-recall.js +0 -297
  236. package/dist/manager/resident/evidence-recall.js.map +0 -1
  237. package/dist/manager/resident/history-disk.d.ts +0 -10
  238. package/dist/manager/resident/history-disk.d.ts.map +0 -1
  239. package/dist/manager/resident/history-disk.js +0 -50
  240. package/dist/manager/resident/history-disk.js.map +0 -1
  241. package/dist/manager/resident/history.d.ts +0 -115
  242. package/dist/manager/resident/history.d.ts.map +0 -1
  243. package/dist/manager/resident/history.js +0 -203
  244. package/dist/manager/resident/history.js.map +0 -1
  245. package/dist/manager/resident/host.d.ts +0 -112
  246. package/dist/manager/resident/host.d.ts.map +0 -1
  247. package/dist/manager/resident/host.js +0 -254
  248. package/dist/manager/resident/host.js.map +0 -1
  249. package/dist/manager/resident/initiative.d.ts +0 -86
  250. package/dist/manager/resident/initiative.d.ts.map +0 -1
  251. package/dist/manager/resident/initiative.js +0 -131
  252. package/dist/manager/resident/initiative.js.map +0 -1
  253. package/dist/manager/resident/loop.d.ts +0 -49
  254. package/dist/manager/resident/loop.d.ts.map +0 -1
  255. package/dist/manager/resident/loop.js +0 -75
  256. package/dist/manager/resident/loop.js.map +0 -1
  257. package/dist/manager/resident/outbox.d.ts +0 -124
  258. package/dist/manager/resident/outbox.d.ts.map +0 -1
  259. package/dist/manager/resident/outbox.js +0 -216
  260. package/dist/manager/resident/outbox.js.map +0 -1
  261. package/dist/manager/resident/proposal.d.ts +0 -65
  262. package/dist/manager/resident/proposal.d.ts.map +0 -1
  263. package/dist/manager/resident/proposal.js +0 -77
  264. package/dist/manager/resident/proposal.js.map +0 -1
  265. package/dist/manager/resident/store.d.ts +0 -108
  266. package/dist/manager/resident/store.d.ts.map +0 -1
  267. package/dist/manager/resident/store.js +0 -205
  268. package/dist/manager/resident/store.js.map +0 -1
  269. package/dist/manager/resident/tool-evidence.d.ts +0 -112
  270. package/dist/manager/resident/tool-evidence.d.ts.map +0 -1
  271. package/dist/manager/resident/tool-evidence.js +0 -289
  272. package/dist/manager/resident/tool-evidence.js.map +0 -1
  273. package/dist/prompt/resident-learning.d.ts +0 -29
  274. package/dist/prompt/resident-learning.d.ts.map +0 -1
  275. package/dist/prompt/resident-learning.js +0 -126
  276. package/dist/prompt/resident-learning.js.map +0 -1
  277. package/dist/prompt/resident-step.d.ts +0 -42
  278. package/dist/prompt/resident-step.d.ts.map +0 -1
  279. package/dist/prompt/resident-step.js +0 -137
  280. package/dist/prompt/resident-step.js.map +0 -1
  281. package/dist/tools/resident-history.d.ts +0 -12
  282. package/dist/tools/resident-history.d.ts.map +0 -1
  283. package/dist/tools/resident-history.js +0 -82
  284. package/dist/tools/resident-history.js.map +0 -1
  285. package/dist/tools/resident-tool-evidence.d.ts +0 -9
  286. package/dist/tools/resident-tool-evidence.d.ts.map +0 -1
  287. package/dist/tools/resident-tool-evidence.js +0 -61
  288. package/dist/tools/resident-tool-evidence.js.map +0 -1
  289. package/src/learning/deprecated.ts +0 -124
  290. package/src/manager/resident/activity.ts +0 -211
  291. package/src/manager/resident/agenda.ts +0 -937
  292. package/src/manager/resident/consumption.ts +0 -335
  293. package/src/manager/resident/delivery-window.ts +0 -99
  294. package/src/manager/resident/evidence-recall.ts +0 -369
  295. package/src/manager/resident/history-disk.ts +0 -63
  296. package/src/manager/resident/history.ts +0 -348
  297. package/src/manager/resident/host.ts +0 -390
  298. package/src/manager/resident/initiative.ts +0 -231
  299. package/src/manager/resident/loop.ts +0 -119
  300. package/src/manager/resident/outbox.ts +0 -341
  301. package/src/manager/resident/proposal.ts +0 -119
  302. package/src/manager/resident/store.ts +0 -279
  303. package/src/manager/resident/tool-evidence.ts +0 -455
  304. package/src/prompt/resident-learning.ts +0 -152
  305. package/src/prompt/resident-step.ts +0 -182
  306. package/src/tools/resident-history.ts +0 -88
  307. package/src/tools/resident-tool-evidence.ts +0 -72
@@ -1,455 +0,0 @@
1
- import { z } from 'zod'
2
- import {
3
- evidenceSearchInput,
4
- evidenceTermRefinement,
5
- evidenceTermsSchema,
6
- } from '../../store/evidence/search-input.js'
7
- import { evidenceExclusionsSchema } from '../../store/evidence/selection.js'
8
- import type {
9
- SessionEvidenceReadOptions,
10
- SessionEvidenceReadResult,
11
- SessionEvidenceSearchResult,
12
- SessionEvidenceSource,
13
- } from '../../store/evidence/types.js'
14
- import type {
15
- ResidentHistoryMatch,
16
- ResidentHistoryScope,
17
- ResidentHistorySource,
18
- } from './history.js'
19
-
20
- /**
21
- * @experimental Host authority for one pursuit, project and admission boundary.
22
- *
23
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
24
- */
25
- export interface ResidentToolEvidenceScope extends ResidentHistoryScope {
26
- readonly projectId: string
27
- }
28
- /**
29
- * @experimental Identity of an agenda-verified settlement, not a fabricated transcript.
30
- *
31
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
32
- */
33
- export type ResidentSettledInvocation = Pick<
34
- ResidentHistoryMatch,
35
- 'revision' | 'claimId' | 'step' | 'kind'
36
- >
37
- /**
38
- * @experimental Settlement is checked before the host resolves the attempt's invocation.
39
- *
40
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
41
- */
42
- export interface ResidentToolEvidenceOptions {
43
- readonly history: ResidentHistorySource
44
- readonly projectId: string
45
- /** Host-enforced upper bound for resolveTurn's document reads, charged in full.
46
- * Required only when an operation supplies maxReadBytes. Zero asserts no
47
- * document reads. This is a declared bound, not a measured receipt.
48
- */
49
- readonly resolutionReadBytes?: number
50
- /**
51
- * The evidence of the one turn that performed a settled invocation. Its
52
- * scope must name that turn (`turnId` present): a source spanning a whole
53
- * session could answer with another turn's records.
54
- */
55
- readonly resolveTurn: (
56
- settled: ResidentSettledInvocation,
57
- signal?: AbortSignal,
58
- ) => Promise<SessionEvidenceSource>
59
- }
60
- /**
61
- * @experimental An optional shared ceiling covers history, resolution and turn evidence.
62
- *
63
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
64
- */
65
- export interface ResidentToolEvidenceSearchOptions {
66
- readonly query?: string
67
- /** Token discovery: 1–16 terms, matched case-insensitively. Combined query/filter JSON ≤512 UTF-8 bytes. */
68
- readonly terms?: readonly string[]
69
- /** Omit successful retrieval copies before they consume candidate slots. */
70
- readonly excludeSuccessfulTools?: readonly string[]
71
- /** Omit query/terms/filter to continue the exact captured search. */
72
- readonly cursor?: string
73
- /** With a token cursor, continue using a strict subset of its terms. Requires
74
- * supportsTermRefinement. Scope, exclusions and the original cursor stay intact.
75
- */
76
- readonly refineTerms?: readonly string[]
77
- readonly maxReadBytes?: number
78
- }
79
- /**
80
- * @experimental Tool records from at most one settled invocation per bounded search page.
81
- *
82
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
83
- */
84
- export interface ResidentToolEvidenceSearchResult {
85
- readonly scope: ResidentToolEvidenceScope
86
- readonly revision: number | null
87
- readonly claimId: string | null
88
- readonly evidence: SessionEvidenceSearchResult | null
89
- readonly nextCursor: string | null
90
- readonly incomplete: boolean
91
- readonly unavailableRevisions: readonly number[]
92
- readonly historyBytes: number
93
- /** Present for bounded calls: history + declared resolution + turn evidence reads.
94
- * Failed source reads without a receipt conservatively consume the remainder.
95
- */
96
- readonly chargedBytes?: number
97
- }
98
- /**
99
- * @experimental The revision is authorized anew on every read, including after restart.
100
- *
101
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
102
- */
103
- export interface ResidentToolEvidenceReadOptions
104
- extends Omit<SessionEvidenceReadOptions, 'maxReadBytes'> {
105
- readonly revision: number
106
- /** Shared operation ceiling, at most 8 MiB; reserves at least 1 MiB for turn evidence reads. */
107
- readonly maxReadBytes?: number
108
- }
109
- /**
110
- * @experimental Exact invocation text plus the settled claim that authorized access.
111
- *
112
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
113
- */
114
- export interface ResidentToolEvidenceReadResult extends SessionEvidenceReadResult {
115
- readonly revision: number
116
- readonly claimId: string
117
- readonly chargedBytes?: number
118
- }
119
- /**
120
- * @experimental A host must bind tool access to the executing turn, not just this source.
121
- *
122
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
123
- */
124
- export interface ResidentToolEvidenceSource {
125
- readonly scope: ResidentToolEvidenceScope
126
- readonly supportsTermRefinement?: boolean
127
- search(
128
- options?: ResidentToolEvidenceSearchOptions,
129
- signal?: AbortSignal,
130
- ): Promise<ResidentToolEvidenceSearchResult>
131
- read(
132
- options: ResidentToolEvidenceReadOptions,
133
- signal?: AbortSignal,
134
- ): Promise<ResidentToolEvidenceReadResult>
135
- }
136
-
137
- /**
138
- * @experimental Reuses the immutable agenda boundary; it never enumerates arbitrary sessions.
139
- *
140
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
141
- */
142
- export function createResidentToolEvidenceSource(
143
- options: ResidentToolEvidenceOptions,
144
- ): ResidentToolEvidenceSource {
145
- const { history, resolveTurn } = options
146
- const resolutionReadBytes = z
147
- .number()
148
- .int()
149
- .min(0)
150
- .max(8 * 1024 * 1024)
151
- .optional()
152
- .parse(options.resolutionReadBytes)
153
- function operationBudget(maxReadBytes: number | undefined) {
154
- if (maxReadBytes === undefined) return undefined
155
- if (resolutionReadBytes === undefined)
156
- throw new Error('Bounded resident retrieval requires a declared resolution read bound.')
157
- const limit = z
158
- .number()
159
- .int()
160
- .positive()
161
- .max(8 * 1024 * 1024)
162
- .parse(maxReadBytes)
163
- const historyLimit = limit - resolutionReadBytes - 1024 * 1024
164
- if (historyLimit < 1)
165
- throw new Error(
166
- 'Resident read budget cannot fit history, resolution and turn evidence reads.',
167
- )
168
- let charged = 0
169
- return {
170
- historyLimit,
171
- get remaining() {
172
- return limit - charged
173
- },
174
- get chargedBytes() {
175
- return charged
176
- },
177
- charge(bytes: number, allowance: number) {
178
- if (
179
- !Number.isSafeInteger(bytes) ||
180
- bytes < 0 ||
181
- bytes > allowance ||
182
- charged + bytes > limit
183
- )
184
- throw new Error('Resident evidence returned an invalid read budget receipt.')
185
- charged += bytes
186
- },
187
- resolve() {
188
- charged += resolutionReadBytes
189
- },
190
- exhaust() {
191
- charged = limit
192
- },
193
- }
194
- }
195
- const scope = Object.freeze({
196
- ...history.scope,
197
- projectId: z.string().uuid().parse(options.projectId),
198
- })
199
- const revision = z.number().int().min(1).max(scope.throughRevision).safe()
200
- const searchSchema = z
201
- .object({
202
- query: z.string().max(256).optional(),
203
- terms: evidenceTermsSchema,
204
- excludeSuccessfulTools: evidenceExclusionsSchema.optional(),
205
- })
206
- .strict()
207
- function searchInput(value: unknown) {
208
- const parsed = searchSchema.parse(value)
209
- const search = evidenceSearchInput({
210
- ...parsed,
211
- ...(parsed.terms ? { matchMode: 'token' as const } : {}),
212
- })
213
- const result: z.infer<typeof searchSchema> = {
214
- ...(search.terms ? { terms: search.terms } : { query: search.query }),
215
- ...(parsed.excludeSuccessfulTools?.length
216
- ? { excludeSuccessfulTools: [...new Set(parsed.excludeSuccessfulTools)].sort() }
217
- : {}),
218
- }
219
- if (
220
- (search.terms || result.excludeSuccessfulTools) &&
221
- Buffer.byteLength(JSON.stringify(result)) > 512
222
- )
223
- throw new Error('Resident search terms and filters exceed 512 UTF-8 bytes.')
224
- return result
225
- }
226
- const cursorBase = {
227
- scope: z.literal(JSON.stringify(scope)),
228
- revision,
229
- turnCursor: z.string().max(4096).optional(),
230
- }
231
- const cursorSchema = z.discriminatedUnion('version', [
232
- z.object({ ...cursorBase, version: z.literal(1), query: z.string().max(256) }).strict(),
233
- z.object({ ...cursorBase, version: z.literal(2), search: searchSchema }).strict(),
234
- ])
235
- const encode = (value: z.infer<typeof cursorSchema>) => {
236
- const encoded = Buffer.from(JSON.stringify(cursorSchema.parse(value))).toString('base64url')
237
- if (encoded.length > 8192) throw new Error('Resident continuation exceeds its encoded bound.')
238
- return encoded
239
- }
240
- async function turn(entry: ResidentSettledInvocation, signal?: AbortSignal) {
241
- signal?.throwIfAborted()
242
- const source = await resolveTurn(entry, signal)
243
- signal?.throwIfAborted()
244
- if (source.scope.tenantId !== scope.tenantId || source.scope.projectId !== scope.projectId)
245
- throw new Error('Historical invocation belongs to a different owner.')
246
- const owner = z
247
- .object({
248
- tenantId: z.string().uuid(),
249
- projectId: z.string().uuid(),
250
- sessionId: z.string().uuid(),
251
- turnId: z.string().uuid(),
252
- })
253
- .parse(source.scope)
254
- return { source, owner }
255
- }
256
- function assertOwner(
257
- page: { scope: SessionEvidenceSource['scope'] },
258
- owner: SessionEvidenceSource['scope'],
259
- signal?: AbortSignal,
260
- ) {
261
- signal?.throwIfAborted()
262
- if (
263
- !page?.scope ||
264
- Object.entries(owner).some(([key, value]) => page.scope[key as keyof typeof owner] !== value)
265
- )
266
- throw new Error('Historical evidence result belongs to a different owner.')
267
- }
268
- return Object.freeze({
269
- scope,
270
- supportsTermRefinement: true,
271
- async search(input: ResidentToolEvidenceSearchOptions = {}, signal?: AbortSignal) {
272
- signal?.throwIfAborted()
273
- const budget = operationBudget(input.maxReadBytes)
274
- const prior = input.cursor
275
- ? cursorSchema.parse(
276
- JSON.parse(
277
- Buffer.from(z.string().max(8192).parse(input.cursor), 'base64url').toString('utf8'),
278
- ),
279
- )
280
- : undefined
281
- const supplied =
282
- input.query !== undefined ||
283
- input.terms !== undefined ||
284
- input.excludeSuccessfulTools !== undefined
285
- const previous = prior
286
- ? searchInput(prior.version === 1 ? { query: prior.query } : prior.search)
287
- : undefined
288
- const search =
289
- supplied || !previous
290
- ? searchInput({
291
- ...(input.query !== undefined ? { query: input.query } : {}),
292
- ...(input.terms !== undefined ? { terms: input.terms } : {}),
293
- ...(input.excludeSuccessfulTools !== undefined
294
- ? { excludeSuccessfulTools: input.excludeSuccessfulTools }
295
- : {}),
296
- })
297
- : previous
298
- if (previous && JSON.stringify(previous) !== JSON.stringify(search))
299
- throw new Error('Resident tool search query changed.')
300
- const refined =
301
- input.refineTerms !== undefined
302
- ? searchInput({
303
- terms: evidenceTermRefinement(
304
- {
305
- terms: search.terms,
306
- cursor: input.cursor,
307
- matchMode: 'token',
308
- caseSensitive: false,
309
- },
310
- input.refineTerms,
311
- ),
312
- excludeSuccessfulTools: search.excludeSuccessfulTools,
313
- })
314
- : undefined
315
- const cursor: z.infer<typeof cursorSchema> =
316
- prior ??
317
- (search.terms || search.excludeSuccessfulTools
318
- ? {
319
- version: 2 as const,
320
- scope: JSON.stringify(scope),
321
- search,
322
- revision: scope.throughRevision,
323
- }
324
- : {
325
- version: 1 as const,
326
- scope: JSON.stringify(scope),
327
- query: search.query ?? '',
328
- revision: scope.throughRevision,
329
- })
330
- let selected: ResidentSettledInvocation | null = null
331
- const advancedCursor = refined ? { ...cursor, version: 2 as const, search: refined } : cursor
332
- let nextRevision: number | null = null
333
- let historyBytes = 0
334
- const unavailable = new Set<number>()
335
- if (cursor.turnCursor) {
336
- const page = await history.read(
337
- {
338
- revision: cursor.revision,
339
- part: 0,
340
- ...(budget ? { maxReadBytes: budget.historyLimit } : {}),
341
- },
342
- signal,
343
- )
344
- signal?.throwIfAborted()
345
- budget?.charge(page.scannedBytes, budget.historyLimit)
346
- selected = page.entry
347
- historyBytes += page.scannedBytes
348
- for (const missing of page.unavailableRevisions) unavailable.add(missing)
349
- nextRevision = cursor.revision > 2 ? cursor.revision - 1 : null
350
- } else {
351
- const page = await history.search(
352
- {
353
- cursor: cursor.revision,
354
- limit: 1,
355
- ...(budget ? { maxReadBytes: budget.historyLimit } : {}),
356
- },
357
- signal,
358
- )
359
- signal?.throwIfAborted()
360
- budget?.charge(page.scannedBytes, budget.historyLimit)
361
- historyBytes += page.scannedBytes
362
- for (const missing of page.unavailableRevisions) unavailable.add(missing)
363
- nextRevision = page.nextCursor
364
- const match = page.matches[0]
365
- // Browse always selects the settled summary (part 0). The bounded history
366
- // source has already verified both sides of this settlement transition.
367
- if (match) selected = match
368
- }
369
- let evidence: SessionEvidenceSearchResult | null = null
370
- if (selected) {
371
- try {
372
- budget?.resolve()
373
- const { source, owner } = await turn(selected, signal)
374
- const narrowAtCursor =
375
- !!refined && !!cursor.turnCursor && source.supportsTermRefinement === true
376
- const page = await source.search(
377
- {
378
- ...(refined && !narrowAtCursor ? refined : search),
379
- ...(search.terms ? { matchMode: 'token' as const, caseSensitive: false } : {}),
380
- ...(cursor.turnCursor && (!refined || narrowAtCursor)
381
- ? { cursor: cursor.turnCursor }
382
- : {}),
383
- ...(narrowAtCursor ? { refineTerms: refined?.terms } : {}),
384
- ...(budget ? { maxReadBytes: budget.remaining } : {}),
385
- },
386
- signal,
387
- )
388
- assertOwner(page, owner, signal)
389
- budget?.charge(page.scannedBytes, budget.remaining)
390
- evidence = page
391
- } catch {
392
- signal?.throwIfAborted()
393
- // A throwing host/source returned no reliable byte receipt. The
394
- // caller must not reuse that allowance for another automatic page.
395
- budget?.exhaust()
396
- unavailable.add(selected.revision)
397
- }
398
- }
399
- const nextCursor =
400
- evidence?.nextCursor && selected
401
- ? encode({
402
- ...advancedCursor,
403
- revision: selected.revision,
404
- turnCursor: evidence.nextCursor,
405
- })
406
- : nextRevision
407
- ? encode({ ...advancedCursor, revision: nextRevision, turnCursor: undefined })
408
- : null
409
- return {
410
- scope,
411
- revision: selected?.revision ?? null,
412
- claimId: selected?.claimId ?? null,
413
- evidence,
414
- nextCursor,
415
- incomplete: unavailable.size > 0 || !!evidence?.incomplete || nextCursor !== null,
416
- unavailableRevisions: [...unavailable],
417
- historyBytes,
418
- ...(budget ? { chargedBytes: budget.chargedBytes } : {}),
419
- }
420
- },
421
- async read(input: ResidentToolEvidenceReadOptions, signal?: AbortSignal) {
422
- signal?.throwIfAborted()
423
- const budget = operationBudget(input.maxReadBytes)
424
- const page = await history.read(
425
- {
426
- revision: revision.parse(input.revision),
427
- part: 0,
428
- ...(budget ? { maxReadBytes: budget.historyLimit } : {}),
429
- },
430
- signal,
431
- )
432
- signal?.throwIfAborted()
433
- budget?.charge(page.scannedBytes, budget.historyLimit)
434
- if (!page.entry) throw new Error('The requested settled claim is unavailable.')
435
- budget?.resolve()
436
- const { source, owner } = await turn(page.entry, signal)
437
- const result = await source.read(
438
- {
439
- address: input.address,
440
- ...(input.byteOffset !== undefined ? { byteOffset: input.byteOffset } : {}),
441
- ...(budget ? { maxReadBytes: budget.remaining } : {}),
442
- },
443
- signal,
444
- )
445
- assertOwner(result, owner, signal)
446
- budget?.charge(result.scannedBytes, budget.remaining)
447
- return {
448
- ...result,
449
- revision: page.entry.revision,
450
- claimId: page.entry.claimId,
451
- ...(budget ? { chargedBytes: budget.chargedBytes } : {}),
452
- }
453
- },
454
- })
455
- }
@@ -1,152 +0,0 @@
1
- import { z } from 'zod'
2
- import { freezeLearning, projectLearning } from '../learning/skill.js'
3
- import { defineTool } from '../tools/defineTool.js'
4
- import type { ToolContext, ToolDefinition } from '../types/tool/index.js'
5
- import type { PromptContribution } from './contributions.js'
6
- import { type ResidentStepPromptOptions, createResidentStepContributions } from './resident-step.js'
7
-
8
- /**
9
- * @experimental One admission's context and read-only access to its evaluated guidance.
10
- *
11
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
12
- */
13
- export interface ResidentStepContextBundle {
14
- readonly contributions: readonly PromptContribution[]
15
- readonly tools: readonly ToolDefinition[]
16
- }
17
-
18
- /**
19
- * @experimental The host must reject reads from runs outside the admitted scope.
20
- *
21
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
22
- */
23
- export interface ResidentStepContextOptions extends ResidentStepPromptOptions {
24
- readonly authorizeLearningRead: (context: ToolContext) => boolean
25
- }
26
-
27
- /**
28
- * @experimental List guidance descriptions first; disclose complete bodies only
29
- * when requested. Selection is local to this admission, never persisted as a
30
- * preference or inferred from keywords. Mount both returned tools and context.
31
- *
32
- * @deprecated Residents are deprecated and removed in the next major release. Learning (`runLearningCycle` and the other `Learning*` names) keeps working, but `runLearningCycle` still takes a resident agenda until learning gets its own activation target in the next major release; for long-running work use scheduled tasks (`LocalTaskScheduler`), session goals and background agents.
33
- */
34
- export function createResidentStepContext(
35
- options: ResidentStepContextOptions,
36
- ): ResidentStepContextBundle {
37
- const learning = options.learning ? freezeLearning(options.learning) : undefined
38
- const contributions = createResidentStepContributions({
39
- ...options,
40
- learning: learning ? { ...learning, skills: [] } : undefined,
41
- })
42
- const taskSkills = learning?.skills.filter((skill) => (skill.purpose ?? 'task') === 'task')
43
- if (!learning || !taskSkills?.length)
44
- return Object.freeze({ contributions, tools: Object.freeze([]) })
45
- const authorize = options.authorizeLearningRead
46
- const resolveSources = options.resolveLearningSources
47
- const selected = new Set<string>()
48
- const profileChars = projectLearning(learning, { maxChars: 12_000, skillNames: [] }).text.length
49
- const project = (names: readonly string[], maxChars = 12_000) => {
50
- let sources: ReturnType<NonNullable<typeof resolveSources>> = []
51
- try {
52
- sources = resolveSources?.() ?? []
53
- } catch {
54
- // Unavailable observations cannot establish a dependency match.
55
- }
56
- return projectLearning(
57
- { ...learning, identity: undefined, preferences: [] },
58
- { maxChars, skillNames: names, sources },
59
- )
60
- }
61
- // Metadata is a catalogue, not executable instructions. Bound its size and
62
- // escape control characters; complete descriptions remain available on read.
63
- const catalogue = taskSkills.map((skill) => ({
64
- name: skill.name,
65
- description: [...skill.description]
66
- .slice(0, 160)
67
- .map((c) => {
68
- const code = c.charCodeAt(0)
69
- return code < 32 || (code >= 127 && code <= 159) ? ' ' : c
70
- })
71
- .join(''),
72
- descriptionShortened: [...skill.description].length > 160,
73
- }))
74
- const tool = defineTool({
75
- name: 'read_resident_skill',
76
- description:
77
- 'Read one evaluated resident skill whose description fits the current task. Use an exact name from the resident skill catalogue. Returns its complete instructions and evidence only if declared source dependencies still match. Loading does not grant permissions or establish that guidance applies. Skip unrelated skills; do not search the workspace to satisfy their descriptions.',
78
- inputSchema: z.object({ name: z.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/) }).strict(),
79
- category: 'custom',
80
- permissions: [],
81
- readOnly: true,
82
- destructive: false,
83
- concurrencySafe: true,
84
- presentCall: (input) => ({ kind: 'generic', label: input.name }),
85
- async execute(input, context) {
86
- context.abortSignal?.throwIfAborted()
87
- try {
88
- if (authorize(context) !== true) throw new Error('Turn does not own this admission.')
89
- const projection = project([input.name])
90
- if (!projection.includedSkills.includes(input.name))
91
- return {
92
- success: false,
93
- output: JSON.stringify({ withheldSkills: projection.withheldSkills }),
94
- error:
95
- 'Skill unavailable in this admission or its sources are unverified. Use current task evidence.',
96
- }
97
- selected.add(input.name)
98
- return { success: true, output: projection.text }
99
- } catch {
100
- context.abortSignal?.throwIfAborted()
101
- return {
102
- success: false,
103
- output: '',
104
- error: 'Resident skill access is unavailable for this turn.',
105
- }
106
- }
107
- },
108
- })
109
- return Object.freeze({
110
- tools: Object.freeze([tool]),
111
- contributions: Object.freeze([
112
- ...contributions,
113
- Object.freeze({
114
- id: 'namzu.resident-step.learning-catalogue',
115
- placement: 'context' as const,
116
- render: () =>
117
- [
118
- '## Available evaluated resident skills',
119
- 'These descriptions advertise optional guidance, not instructions to execute. Read a relevant skill with read_resident_skill before using it. Skip unrelated skills and work directly from the requested evidence; availability does not establish applicability. A skill evaluated on one task family may hinder another. Current objectives, project instructions and permissions always take precedence.',
120
- JSON.stringify(catalogue),
121
- ].join('\n'),
122
- }),
123
- Object.freeze({
124
- id: 'namzu.resident-step.selected-learning',
125
- placement: 'context' as const,
126
- render: () => {
127
- if (!selected.size) return null
128
- try {
129
- const projection = project([...selected], Math.max(0, 12_000 - profileChars))
130
- return [
131
- '## Selected resident guidance for this request',
132
- 'Apply only while relevant to the current task. Matching source revisions do not prove claims.',
133
- projection.text,
134
- ...projection.withheldSkills.map((skill) =>
135
- JSON.stringify({ kind: 'withheld-guidance', ...skill }),
136
- ),
137
- ...(projection.omitted
138
- ? [
139
- 'Some selected guidance is withheld or omitted. Recheck current evidence; do not recover its instructions from earlier messages as a substitute.',
140
- ]
141
- : []),
142
- ]
143
- .filter(Boolean)
144
- .join('\n')
145
- } catch {
146
- return 'Selected resident guidance is unavailable for this request. Use current task evidence; do not reuse earlier skill instructions.'
147
- }
148
- },
149
- }),
150
- ]),
151
- })
152
- }