@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.
- package/CHANGELOG.md +32 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +1 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/compaction/extractor.d.ts.map +1 -1
- package/dist/compaction/extractor.js +5 -1
- package/dist/compaction/extractor.js.map +1 -1
- package/dist/compaction/managers/structured.d.ts.map +1 -1
- package/dist/compaction/managers/structured.js +5 -0
- package/dist/compaction/managers/structured.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +6 -0
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/serializer.d.ts +6 -0
- package/dist/compaction/serializer.d.ts.map +1 -1
- package/dist/compaction/serializer.js +21 -3
- package/dist/compaction/serializer.js.map +1 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +27 -6
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/constants/compaction/index.d.ts +1 -0
- package/dist/constants/compaction/index.d.ts.map +1 -1
- package/dist/constants/compaction/index.js +1 -0
- package/dist/constants/compaction/index.js.map +1 -1
- package/dist/manager/resident/proposal.d.ts +2 -2
- package/dist/manager/resident/store.d.ts +4 -4
- package/dist/prompt/coding-agent-doctrine.d.ts +3 -3
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +18 -20
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/public-runtime.d.ts +1 -1
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +1 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/runtime/query/checkpoint.d.ts +12 -2
- package/dist/runtime/query/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/checkpoint.js +42 -8
- package/dist/runtime/query/checkpoint.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +39 -1
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +115 -7
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +18 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +20 -1
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +17 -8
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +24 -2
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js +22 -22
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts +78 -0
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/per-call-review.js +494 -0
- package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -0
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +129 -62
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/step-context.d.ts +14 -0
- package/dist/runtime/query/iteration/step-context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/step-context.js +29 -0
- package/dist/runtime/query/iteration/step-context.js.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.js +6 -2
- package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +16 -3
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/project-instructions.d.ts +24 -5
- package/dist/runtime/query/project-instructions.d.ts.map +1 -1
- package/dist/runtime/query/project-instructions.js +107 -35
- package/dist/runtime/query/project-instructions.js.map +1 -1
- package/dist/runtime/query/prompt.d.ts +6 -0
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +10 -49
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts +8 -0
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +101 -0
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +18 -0
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +10 -0
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +55 -56
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +78 -72
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +8 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +13 -18
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser.d.ts.map +1 -1
- package/dist/tools/builtins/browser.js +38 -12
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/edit.js +4 -4
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/job.js +1 -1
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/skill.js +1 -1
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/builtins/structuredOutput.js +1 -1
- package/dist/tools/builtins/structuredOutput.js.map +1 -1
- package/dist/tools/builtins/verify-outputs.js +1 -1
- package/dist/tools/builtins/verify-outputs.js.map +1 -1
- package/dist/tools/builtins/write-file.js +4 -4
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts +6 -0
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +6 -1
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +10 -3
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
- package/dist/tools/schedules/loop-tool.js +4 -2
- package/dist/tools/schedules/loop-tool.js.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +2 -2
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/task/create.js +1 -1
- package/dist/tools/task/create.js.map +1 -1
- package/dist/tools/untrusted-envelope.js +1 -1
- package/dist/tools/untrusted-envelope.js.map +1 -1
- package/dist/turn/evidence-query.d.ts.map +1 -1
- package/dist/turn/evidence-query.js +16 -1
- package/dist/turn/evidence-query.js.map +1 -1
- package/dist/turn/evidence-recall.js +1 -1
- package/dist/turn/evidence-recall.js.map +1 -1
- package/dist/types/agent/base.d.ts +7 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/hitl/index.d.ts +66 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +8 -0
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +12 -2
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/message/notice-frame.d.ts +41 -0
- package/dist/types/message/notice-frame.d.ts.map +1 -0
- package/dist/types/message/notice-frame.js +65 -0
- package/dist/types/message/notice-frame.js.map +1 -0
- package/package.json +1 -1
- package/src/agents/QueryAgent.ts +1 -0
- package/src/compaction/extractor.ts +8 -1
- package/src/compaction/managers/structured.ts +3 -0
- package/src/compaction/manual.ts +5 -0
- package/src/compaction/serializer.ts +28 -3
- package/src/compaction/verifier.ts +32 -6
- package/src/constants/compaction/index.ts +1 -0
- package/src/prompt/coding-agent-doctrine.ts +18 -20
- package/src/public-runtime.ts +1 -0
- package/src/runtime/query/checkpoint.ts +49 -8
- package/src/runtime/query/executor.ts +165 -15
- package/src/runtime/query/index.ts +45 -1
- package/src/runtime/query/iteration/index.ts +19 -6
- package/src/runtime/query/iteration/phases/context.ts +37 -11
- package/src/runtime/query/iteration/phases/per-call-review.ts +598 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +168 -83
- package/src/runtime/query/iteration/step-context.ts +29 -0
- package/src/runtime/query/iteration/step-shaping.ts +6 -2
- package/src/runtime/query/prepare-turn.ts +18 -1
- package/src/runtime/query/project-instructions.ts +119 -38
- package/src/runtime/query/prompt.ts +11 -54
- package/src/runtime/query/resume-pending.ts +131 -0
- package/src/runtime/query/review-policy.ts +28 -0
- package/src/runtime/query/steering.ts +100 -96
- package/src/tools/builtins/bash.ts +13 -19
- package/src/tools/builtins/browser.ts +38 -12
- package/src/tools/builtins/edit.ts +4 -4
- package/src/tools/builtins/job.ts +1 -1
- package/src/tools/builtins/skill.ts +1 -1
- package/src/tools/builtins/structuredOutput.ts +1 -1
- package/src/tools/builtins/verify-outputs.ts +1 -1
- package/src/tools/builtins/write-file.ts +4 -4
- package/src/tools/coordinator/ask-user-question.ts +12 -1
- package/src/tools/coordinator/index.ts +10 -3
- package/src/tools/schedules/loop-tool.ts +4 -2
- package/src/tools/schedules/schedule-tool.ts +2 -2
- package/src/tools/task/create.ts +1 -1
- package/src/tools/untrusted-envelope.ts +1 -1
- package/src/turn/evidence-query.ts +19 -1
- package/src/turn/evidence-recall.ts +1 -1
- package/src/types/agent/base.ts +8 -0
- package/src/types/hitl/index.ts +67 -0
- package/src/types/message/index.ts +20 -2
- 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 `<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, '<$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
|
+
}
|