@namzu/sdk 54.0.0 → 55.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 (188) hide show
  1. package/CHANGELOG.md +32 -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/compaction/extractor.d.ts.map +1 -1
  6. package/dist/compaction/extractor.js +5 -1
  7. package/dist/compaction/extractor.js.map +1 -1
  8. package/dist/compaction/managers/structured.d.ts.map +1 -1
  9. package/dist/compaction/managers/structured.js +5 -0
  10. package/dist/compaction/managers/structured.js.map +1 -1
  11. package/dist/compaction/manual.d.ts.map +1 -1
  12. package/dist/compaction/manual.js +6 -0
  13. package/dist/compaction/manual.js.map +1 -1
  14. package/dist/compaction/serializer.d.ts +6 -0
  15. package/dist/compaction/serializer.d.ts.map +1 -1
  16. package/dist/compaction/serializer.js +21 -3
  17. package/dist/compaction/serializer.js.map +1 -1
  18. package/dist/compaction/verifier.d.ts.map +1 -1
  19. package/dist/compaction/verifier.js +27 -6
  20. package/dist/compaction/verifier.js.map +1 -1
  21. package/dist/constants/compaction/index.d.ts +1 -0
  22. package/dist/constants/compaction/index.d.ts.map +1 -1
  23. package/dist/constants/compaction/index.js +1 -0
  24. package/dist/constants/compaction/index.js.map +1 -1
  25. package/dist/manager/resident/proposal.d.ts +2 -2
  26. package/dist/manager/resident/store.d.ts +4 -4
  27. package/dist/prompt/coding-agent-doctrine.d.ts +3 -3
  28. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  29. package/dist/prompt/coding-agent-doctrine.js +18 -20
  30. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  31. package/dist/public-runtime.d.ts +1 -1
  32. package/dist/public-runtime.d.ts.map +1 -1
  33. package/dist/public-runtime.js +1 -1
  34. package/dist/public-runtime.js.map +1 -1
  35. package/dist/runtime/query/checkpoint.d.ts +12 -2
  36. package/dist/runtime/query/checkpoint.d.ts.map +1 -1
  37. package/dist/runtime/query/checkpoint.js +42 -8
  38. package/dist/runtime/query/checkpoint.js.map +1 -1
  39. package/dist/runtime/query/executor.d.ts +39 -1
  40. package/dist/runtime/query/executor.d.ts.map +1 -1
  41. package/dist/runtime/query/executor.js +115 -7
  42. package/dist/runtime/query/executor.js.map +1 -1
  43. package/dist/runtime/query/index.d.ts +18 -0
  44. package/dist/runtime/query/index.d.ts.map +1 -1
  45. package/dist/runtime/query/index.js +20 -1
  46. package/dist/runtime/query/index.js.map +1 -1
  47. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  48. package/dist/runtime/query/iteration/index.js +17 -8
  49. package/dist/runtime/query/iteration/index.js.map +1 -1
  50. package/dist/runtime/query/iteration/phases/context.d.ts +24 -2
  51. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  52. package/dist/runtime/query/iteration/phases/context.js +22 -22
  53. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  54. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +78 -0
  55. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -0
  56. package/dist/runtime/query/iteration/phases/per-call-review.js +494 -0
  57. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -0
  58. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  59. package/dist/runtime/query/iteration/phases/tool-review.js +129 -62
  60. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  61. package/dist/runtime/query/iteration/step-context.d.ts +14 -0
  62. package/dist/runtime/query/iteration/step-context.d.ts.map +1 -1
  63. package/dist/runtime/query/iteration/step-context.js +29 -0
  64. package/dist/runtime/query/iteration/step-context.js.map +1 -1
  65. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  66. package/dist/runtime/query/iteration/step-shaping.js +6 -2
  67. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  68. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  69. package/dist/runtime/query/prepare-turn.js +16 -3
  70. package/dist/runtime/query/prepare-turn.js.map +1 -1
  71. package/dist/runtime/query/project-instructions.d.ts +24 -5
  72. package/dist/runtime/query/project-instructions.d.ts.map +1 -1
  73. package/dist/runtime/query/project-instructions.js +107 -35
  74. package/dist/runtime/query/project-instructions.js.map +1 -1
  75. package/dist/runtime/query/prompt.d.ts +6 -0
  76. package/dist/runtime/query/prompt.d.ts.map +1 -1
  77. package/dist/runtime/query/prompt.js +10 -49
  78. package/dist/runtime/query/prompt.js.map +1 -1
  79. package/dist/runtime/query/resume-pending.d.ts +8 -0
  80. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  81. package/dist/runtime/query/resume-pending.js +101 -0
  82. package/dist/runtime/query/resume-pending.js.map +1 -1
  83. package/dist/runtime/query/review-policy.d.ts +18 -0
  84. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  85. package/dist/runtime/query/review-policy.js +10 -0
  86. package/dist/runtime/query/review-policy.js.map +1 -1
  87. package/dist/runtime/query/steering.d.ts +55 -56
  88. package/dist/runtime/query/steering.d.ts.map +1 -1
  89. package/dist/runtime/query/steering.js +78 -72
  90. package/dist/runtime/query/steering.js.map +1 -1
  91. package/dist/tools/builtins/bash.d.ts +8 -0
  92. package/dist/tools/builtins/bash.d.ts.map +1 -1
  93. package/dist/tools/builtins/bash.js +13 -18
  94. package/dist/tools/builtins/bash.js.map +1 -1
  95. package/dist/tools/builtins/browser.d.ts.map +1 -1
  96. package/dist/tools/builtins/browser.js +38 -12
  97. package/dist/tools/builtins/browser.js.map +1 -1
  98. package/dist/tools/builtins/edit.js +4 -4
  99. package/dist/tools/builtins/edit.js.map +1 -1
  100. package/dist/tools/builtins/job.js +1 -1
  101. package/dist/tools/builtins/job.js.map +1 -1
  102. package/dist/tools/builtins/skill.js +1 -1
  103. package/dist/tools/builtins/skill.js.map +1 -1
  104. package/dist/tools/builtins/structuredOutput.js +1 -1
  105. package/dist/tools/builtins/structuredOutput.js.map +1 -1
  106. package/dist/tools/builtins/verify-outputs.js +1 -1
  107. package/dist/tools/builtins/verify-outputs.js.map +1 -1
  108. package/dist/tools/builtins/write-file.js +4 -4
  109. package/dist/tools/builtins/write-file.js.map +1 -1
  110. package/dist/tools/coordinator/ask-user-question.d.ts +6 -0
  111. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  112. package/dist/tools/coordinator/ask-user-question.js +6 -1
  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 +10 -3
  116. package/dist/tools/coordinator/index.js.map +1 -1
  117. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  118. package/dist/tools/schedules/loop-tool.js +4 -2
  119. package/dist/tools/schedules/loop-tool.js.map +1 -1
  120. package/dist/tools/schedules/schedule-tool.js +2 -2
  121. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  122. package/dist/tools/task/create.js +1 -1
  123. package/dist/tools/task/create.js.map +1 -1
  124. package/dist/tools/untrusted-envelope.js +1 -1
  125. package/dist/tools/untrusted-envelope.js.map +1 -1
  126. package/dist/turn/evidence-query.d.ts.map +1 -1
  127. package/dist/turn/evidence-query.js +16 -1
  128. package/dist/turn/evidence-query.js.map +1 -1
  129. package/dist/turn/evidence-recall.js +1 -1
  130. package/dist/turn/evidence-recall.js.map +1 -1
  131. package/dist/types/agent/base.d.ts +7 -0
  132. package/dist/types/agent/base.d.ts.map +1 -1
  133. package/dist/types/hitl/index.d.ts +66 -0
  134. package/dist/types/hitl/index.d.ts.map +1 -1
  135. package/dist/types/hitl/index.js.map +1 -1
  136. package/dist/types/message/index.d.ts +8 -0
  137. package/dist/types/message/index.d.ts.map +1 -1
  138. package/dist/types/message/index.js +12 -2
  139. package/dist/types/message/index.js.map +1 -1
  140. package/dist/types/message/notice-frame.d.ts +41 -0
  141. package/dist/types/message/notice-frame.d.ts.map +1 -0
  142. package/dist/types/message/notice-frame.js +65 -0
  143. package/dist/types/message/notice-frame.js.map +1 -0
  144. package/package.json +1 -1
  145. package/src/agents/QueryAgent.ts +1 -0
  146. package/src/compaction/extractor.ts +8 -1
  147. package/src/compaction/managers/structured.ts +3 -0
  148. package/src/compaction/manual.ts +5 -0
  149. package/src/compaction/serializer.ts +28 -3
  150. package/src/compaction/verifier.ts +32 -6
  151. package/src/constants/compaction/index.ts +1 -0
  152. package/src/prompt/coding-agent-doctrine.ts +18 -20
  153. package/src/public-runtime.ts +1 -0
  154. package/src/runtime/query/checkpoint.ts +49 -8
  155. package/src/runtime/query/executor.ts +165 -15
  156. package/src/runtime/query/index.ts +45 -1
  157. package/src/runtime/query/iteration/index.ts +19 -6
  158. package/src/runtime/query/iteration/phases/context.ts +37 -11
  159. package/src/runtime/query/iteration/phases/per-call-review.ts +598 -0
  160. package/src/runtime/query/iteration/phases/tool-review.ts +168 -83
  161. package/src/runtime/query/iteration/step-context.ts +29 -0
  162. package/src/runtime/query/iteration/step-shaping.ts +6 -2
  163. package/src/runtime/query/prepare-turn.ts +18 -1
  164. package/src/runtime/query/project-instructions.ts +119 -38
  165. package/src/runtime/query/prompt.ts +11 -54
  166. package/src/runtime/query/resume-pending.ts +131 -0
  167. package/src/runtime/query/review-policy.ts +28 -0
  168. package/src/runtime/query/steering.ts +100 -96
  169. package/src/tools/builtins/bash.ts +13 -19
  170. package/src/tools/builtins/browser.ts +38 -12
  171. package/src/tools/builtins/edit.ts +4 -4
  172. package/src/tools/builtins/job.ts +1 -1
  173. package/src/tools/builtins/skill.ts +1 -1
  174. package/src/tools/builtins/structuredOutput.ts +1 -1
  175. package/src/tools/builtins/verify-outputs.ts +1 -1
  176. package/src/tools/builtins/write-file.ts +4 -4
  177. package/src/tools/coordinator/ask-user-question.ts +12 -1
  178. package/src/tools/coordinator/index.ts +10 -3
  179. package/src/tools/schedules/loop-tool.ts +4 -2
  180. package/src/tools/schedules/schedule-tool.ts +2 -2
  181. package/src/tools/task/create.ts +1 -1
  182. package/src/tools/untrusted-envelope.ts +1 -1
  183. package/src/turn/evidence-query.ts +19 -1
  184. package/src/turn/evidence-recall.ts +1 -1
  185. package/src/types/agent/base.ts +8 -0
  186. package/src/types/hitl/index.ts +67 -0
  187. package/src/types/message/index.ts +20 -2
  188. package/src/types/message/notice-frame.ts +88 -0
@@ -1,5 +1,6 @@
1
1
  import type { GoalId, MessageId } from '../ids/index.js'
2
2
  import { type InboundDeliveryRef, isInboundDeliveryRef } from './inbound-delivery.js'
3
+ import { escapeNoticeFrame } from './notice-frame.js'
3
4
 
4
5
  export type MessageRole = 'system' | 'user' | 'assistant' | 'tool'
5
6
 
@@ -335,6 +336,12 @@ export interface GoalRoundMessageSource {
335
336
  export interface ProjectInstructionMessageSource {
336
337
  readonly type: 'project-instructions'
337
338
  readonly files: readonly string[]
339
+ /**
340
+ * Set on a changed copy sent after the conversation's first one. It carries
341
+ * the complete new policy under a header that says it replaces the earlier
342
+ * copy, so the earlier copy keeps its place in the request.
343
+ */
344
+ readonly update?: true
338
345
  }
339
346
 
340
347
  /**
@@ -647,7 +654,7 @@ export function createProjectInstructionMessage(
647
654
  'Project instruction paths must be unique, canonical project-relative paths.',
648
655
  )
649
656
  }
650
- return { ...createUserMessage(content, undefined, source), retain: true }
657
+ return { ...createUserMessage(escapeNoticeFrame(content), undefined, source), retain: true }
651
658
  }
652
659
 
653
660
  export function createAssistantMessage(
@@ -670,6 +677,15 @@ export function createAssistantMessage(
670
677
  }
671
678
  }
672
679
 
680
+ /** A tool's output can print anything; it cannot print the kernel's notice tag. */
681
+ function escapeToolResult(content: ToolResultContent): ToolResultContent {
682
+ if (typeof content === 'string') return escapeNoticeFrame(content)
683
+ if (!content.some((block) => block.type === 'text' && block.text.includes('<'))) return content
684
+ return content.map((block) =>
685
+ block.type === 'text' ? { ...block, text: escapeNoticeFrame(block.text) } : block,
686
+ )
687
+ }
688
+
673
689
  export function createToolMessage(
674
690
  content: ToolResultContent,
675
691
  toolCallId: string,
@@ -678,7 +694,7 @@ export function createToolMessage(
678
694
  ): ToolMessage {
679
695
  return {
680
696
  role: 'tool',
681
- content,
697
+ content: escapeToolResult(content),
682
698
  toolCallId,
683
699
  ...(isError !== undefined ? { isError } : {}),
684
700
  ...(revealedTools && revealedTools.length > 0 ? { revealedTools } : {}),
@@ -686,6 +702,8 @@ export function createToolMessage(
686
702
  }
687
703
  }
688
704
 
705
+ export { escapeNoticeFrame, frameNotice, NOTICE_TAG } from './notice-frame.js'
706
+ export type { NoticeKind } from './notice-frame.js'
689
707
  export {
690
708
  hasNonTextBlocks,
691
709
  toToolResultBlocks,
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The frame the kernel puts around a notice it sends the model: the operator's
3
+ * message typed while a tool ran, a background job's exit, a monitor's events.
4
+ *
5
+ * A notice is its own user-role message at the next request boundary. It is
6
+ * never appended to a tool result: a tool result carries only what the tool
7
+ * returned, and Namzu's own words inside that slot read as tool output.
8
+ *
9
+ * The frame says what the text is and whose it is, and its tag carries a
10
+ * random marker drawn after the text is fixed (`<namzu-notice-1f3a...>`), so
11
+ * nothing the text says can spell the closing tag. {@link escapeNoticeFrame}
12
+ * is the second layer: it turns every spelling of the tag prefix in tool
13
+ * output and file content into inert text before it reaches the conversation.
14
+ */
15
+
16
+ import {
17
+ generateRenderNonce,
18
+ nonceClosureStatement,
19
+ pickRenderNonce,
20
+ } from '../../tools/render-nonce.js'
21
+
22
+ /** The fixed prefix of every notice tag; the real tag adds `-<marker>`. */
23
+ export const NOTICE_TAG = 'namzu-notice'
24
+
25
+ export type NoticeKind = 'operator-message' | 'job' | 'monitor'
26
+
27
+ const OPEN_OR_CLOSE = /<(\/?)(namzu-notice)/gi
28
+
29
+ /**
30
+ * Make the notice tag inert: `<namzu-notice` becomes `&lt;namzu-notice`, in any
31
+ * case, opening or closing, with or without a marker after it. Idempotent, so
32
+ * text that passes through twice (a result rebuilt on resume) is not changed
33
+ * again.
34
+ */
35
+ export function escapeNoticeFrame(text: string): string {
36
+ return text.includes('<') ? text.replace(OPEN_OR_CLOSE, '&lt;$1$2') : text
37
+ }
38
+
39
+ /** What a frame says about whose words are inside it. */
40
+ export const NOTICE_PREAMBLE: Readonly<Record<NoticeKind, string>> = {
41
+ 'operator-message': '',
42
+ job: 'Namzu sent this automatically. The operator did not write it, so it is neither an answer to a question you asked nor an approval.',
43
+ monitor:
44
+ 'Namzu sent this automatically. The operator did not write it, so it is neither an answer to a question you asked nor an approval.',
45
+ }
46
+
47
+ export function noticeTag(nonce: string): string {
48
+ return `${NOTICE_TAG}-${nonce}`
49
+ }
50
+
51
+ export function noticeOpen(kind: NoticeKind, nonce: string): string {
52
+ return `<${noticeTag(nonce)} kind="${kind}">`
53
+ }
54
+
55
+ export function noticeClose(nonce: string): string {
56
+ return `</${noticeTag(nonce)}>`
57
+ }
58
+
59
+ /**
60
+ * `label`, the preamble and the body inside one frame, the body escaped. The
61
+ * marker is drawn fresh for each frame and never occurs in the label or body.
62
+ */
63
+ export function frameNotice(
64
+ kind: NoticeKind,
65
+ label: string,
66
+ body: string,
67
+ generateNonce: () => string = generateRenderNonce,
68
+ ): string {
69
+ const safe = escapeNoticeFrame(body)
70
+ const nonce = pickRenderNonce(generateNonce, [label, safe])
71
+ const lines = [noticeOpen(kind, nonce), label]
72
+ if (NOTICE_PREAMBLE[kind]) lines.push(NOTICE_PREAMBLE[kind])
73
+ lines.push(nonceClosureStatement(noticeClose(nonce)), safe, noticeClose(nonce))
74
+ return lines.join('\n')
75
+ }
76
+
77
+ const OPERATOR_FRAME = new RegExp(
78
+ `^<${NOTICE_TAG}-([0-9a-f]+) kind="operator-message">\\n[^\\n]*\\n[^\\n]*\\n([\\s\\S]*)\\n</${NOTICE_TAG}-\\1>$`,
79
+ )
80
+
81
+ /**
82
+ * The operator's text inside a frame {@link frameNotice} made for an operator
83
+ * message, as the frame held it (tag already made inert), or `undefined` for
84
+ * any other text.
85
+ */
86
+ export function readOperatorNotice(content: string): string | undefined {
87
+ return OPERATOR_FRAME.exec(content)?.[2]
88
+ }