@peer-agent/runtime-core 0.0.1-beta.43 → 0.0.1-beta.45

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.
@@ -12,9 +12,17 @@ export type CompactionMessage = Readonly<{
12
12
  _compaction?: unknown;
13
13
  }>;
14
14
  export type CompactionMethod = 'llm' | 'structured' | 'fallback_drop';
15
- export declare const COMPACTION_SUMMARY_SYSTEM_PROMPT = "\u4F60\u662F\u5BF9\u8BDD\u6458\u8981\u4E13\u5BB6\u3002\u8BF7\u5C06\u4EE5\u4E0B\u5BF9\u8BDD\u5386\u53F2\u538B\u7F29\u4E3A\u8BE6\u7EC6\u6458\u8981\uFF0C\u4FDD\u7559\u5173\u952E\u4FE1\u606F\uFF1A\u7528\u6237\u610F\u56FE\u3001\u91CD\u8981\u51B3\u7B56\u3001\u6280\u672F\u6982\u5FF5\u3001\u6587\u4EF6\u53D8\u66F4\u3001\u9519\u8BEF\u4FEE\u590D\u3001\u5F85\u529E\u4E8B\u9879\u3002\u7279\u522B\u8981\u8BE6\u7EC6\u8BB0\u5F55\u7528\u6237\u7684\u5177\u4F53\u6267\u884C\u52A8\u4F5C\u4E0E\u64CD\u4F5C\u6B65\u9AA4\u2014\u2014\u7528\u6237\u8981\u6C42\u505A\u4E86\u4EC0\u4E48\u3001\u5B9E\u9645\u6539\u52A8\u4E86\u54EA\u4E9B\u6587\u4EF6\u3001\u547D\u4EE4/\u64CD\u4F5C\u6267\u884C\u5230\u54EA\u4E00\u6B65\u3001\u5F53\u524D\u505C\u5728\u4F55\u5904\u2014\u2014\u56E0\u4E3A\u539F\u6587\u5DF2\u5168\u91CF\u538B\u7F29\u3001\u4E0D\u518D\u4FDD\u7559\uFF0C\u8FDE\u7EED\u6027\u5B8C\u5168\u4F9D\u8D56\u672C\u6458\u8981\u627F\u8F7D\u3002\u8F93\u51FA\u7EAF\u6587\u672C\uFF0C\u4E0D\u8981\u7528 markdown\u3002";
16
- export declare const COMPACTION_SUMMARY_PROMPT = "Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.\nThis summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.\n\nBefore providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:\n\n1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:\n - The user's explicit requests and intents\n - Your approach to addressing the user's requests\n - Key decisions, technical concepts and code patterns\n - Specific details like file names, full code snippets, function signatures, file edits, etc\n - Errors that you ran into and how you fixed them\n - Pay special attention to specific user feedback that may have led to a change in your approach.\n2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.\n\nYour summary should include the following sections:\n\n1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail\n2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.\n3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Include a summary of why this file read or edit is important.\n4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback.\n5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.\n6. All user messages: List ALL user messages that are not tool results. These are critical for understanding user feedback and changing intent.\n7. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.\n8. Current Work: Describe in detail precisely what was being worked on immediately before this summary request. CRITICAL \u2014 record the user's concrete execution actions and operation steps in detail: what the user asked to do, which files were actually changed, what commands/operations were run and to which step they progressed, and exactly where things currently stand. The original conversation is fully compacted and NOT retained, so continuity depends entirely on this summary capturing those execution details.\n9. Optional Next Step: List the next step related to the most recent work. Include direct quotes from the most recent conversation.\n\nCRITICAL: Respond with TEXT ONLY. Do NOT call any tools.\n\nPlease provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.";
17
- export declare function formatCompactionMessagesForSummary(messages: readonly CompactionMessage[]): string;
15
+ export declare const COMPACTION_SUMMARY_SYSTEM_PROMPT = "\u4F60\u662F\u4E0A\u4E0B\u6587\u4EA4\u63A5\u4E13\u5BB6\u3002\u8BF7\u628A\u5386\u53F2\u538B\u7F29\u6210\u53EF\u9A8C\u8BC1\u3001\u53EF\u7EE7\u7EED\u6267\u884C\u7684\u4EA4\u63A5\u6E05\u5355\u3002\u5FC5\u987B\u533A\u5206\u4E8B\u5B9E\u4E0E\u8BA1\u5212\uFF0C\u7A33\u5B9A\u4FDD\u7559\uFF1A\u5F53\u524D\u76EE\u6807\u4E0E\u9A8C\u6536\u6807\u51C6\uFF1B\u7528\u6237\u6700\u8FD1\u8981\u6C42\u53CA\u5173\u952E\u539F\u8BDD\uFF1B\u5DF2\u786E\u8BA4\u3001\u5DF2\u5426\u51B3\uFF08\u542B\u539F\u56E0\uFF09\u548C\u5F85\u786E\u8BA4\u7684\u51B3\u7B56\uFF1B\u5DF2\u8BFB\u53D6\u3001\u5DF2\u4FEE\u6539\u3001\u5DF2\u521B\u5EFA\u7684\u6587\u4EF6\uFF1B\u5DF2\u6267\u884C\u547D\u4EE4\u53CA\u771F\u5B9E\u7ED3\u679C\uFF1B\u9519\u8BEF\u3001\u5931\u8D25\u5C1D\u8BD5\u4E0E\u539F\u56E0\uFF1B\u5F53\u524D\u8FD0\u884C\u72B6\u6001\uFF1B\u7CBE\u786E\u4E0B\u4E00\u6B65\uFF1BEvidence\u3001artifact ref \u548C\u53EF\u91CD\u65B0\u8BFB\u53D6\u4F4D\u7F6E\uFF1B\u5DF2\u7ECF\u5B8C\u6210\u4E14\u4E0D\u5E94\u91CD\u590D\u6267\u884C\u7684\u5DE5\u4F5C\u3002\u6CA1\u6709\u8BC1\u636E\u7684\u4E8B\u9879\u4E0D\u5F97\u5199\u6210\u5DF2\u5B8C\u6210\u3002\u539F\u6587\u538B\u7F29\u540E\u4E0D\u518D\u4FDD\u7559\uFF0C\u8FDE\u7EED\u6027\u5B8C\u5168\u4F9D\u8D56\u672C\u6458\u8981\u627F\u8F7D\u3002\u8F93\u51FA\u7EAF\u6587\u672C\uFF0C\u4E0D\u8981\u7528 markdown\u3002";
16
+ export declare const COMPACTION_SUMMARY_PROMPT = "Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.\nThis summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.\n\nBefore providing your final summary, wrap your analysis in <analysis> tags to organize your thoughts and ensure you've covered all necessary points. In your analysis process:\n\n1. Chronologically analyze each message and section of the conversation. For each section thoroughly identify:\n - The user's explicit requests and intents\n - Your approach to addressing the user's requests\n - Key decisions, technical concepts and code patterns\n - Specific details like file names, full code snippets, function signatures, file edits, etc\n - Errors that you ran into and how you fixed them\n - Pay special attention to specific user feedback that may have led to a change in your approach.\n2. Double-check for technical accuracy and completeness, addressing each required element thoroughly.\n\nYour summary should include the following sections:\n\n1. Primary Request and Intent: Capture all of the user's explicit requests and intents in detail\n2. Key Technical Concepts: List all important technical concepts, technologies, and frameworks discussed.\n3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Include a summary of why this file read or edit is important.\n4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback.\n5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.\n6. Decisions: Separate confirmed, rejected (with reasons), and pending decisions. Never collapse a rejected option into the final choice.\n7. All user messages: List ALL user messages that are not tool results. Quote the most recent requirements that affect current work.\n8. Evidence and recovery: Preserve Tool Result/Evidence/artifact refs, rerunnable retrieval hints, and exact locations that can be read again. Do not present an unverified plan as completed work.\n9. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.\n10. Current Work: Describe in detail precisely what was being worked on immediately before this summary request. CRITICAL \u2014 record the user's concrete execution actions and operation steps in detail: what the user asked to do, which files were actually changed, what commands/operations were run and their real outcomes, and exactly where things currently stand. The original conversation is fully compacted and NOT retained, so continuity depends entirely on this summary capturing those execution details.\n11. Do Not Repeat: List completed, rejected, or failed work that must not be rerun without new evidence or a changed requirement.\n12. Exact Next Step: State the next executable step, its success criterion, and any blocker. Include direct quotes from the most recent conversation.\n\nCRITICAL: Respond with TEXT ONLY. Do NOT call any tools.\n\nPlease provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.";
17
+ export declare const COMPACTION_SUMMARY_PROJECTION_LIMITS: Readonly<{
18
+ textChars: 12000;
19
+ thinkingChars: 512;
20
+ toolInputChars: 2000;
21
+ toolResultChars: 6000;
22
+ unknownBlockChars: 4000;
23
+ }>;
24
+ type SummaryProjectionLimits = Readonly<typeof COMPACTION_SUMMARY_PROJECTION_LIMITS>;
25
+ export declare function formatCompactionMessagesForSummary(messages: readonly CompactionMessage[], limits?: SummaryProjectionLimits): string;
18
26
  export interface CompactionSplit<TMessage extends CompactionMessage> {
19
27
  readonly systemMessages: readonly TMessage[];
20
28
  readonly oldMessages: readonly TMessage[];
@@ -39,6 +47,7 @@ export interface CompactionSummaryCascadeOptions<TMessage extends CompactionMess
39
47
  */
40
48
  export declare function splitMessagesForCompaction<TMessage extends CompactionMessage>(messages: readonly TMessage[], options?: {
41
49
  readonly preserveLatestUserTurn?: boolean;
50
+ readonly preserveRecentTurns?: number;
42
51
  readonly keepRecentCount?: number;
43
52
  }): CompactionSplit<TMessage>;
44
53
  /** Desktop's summary preference order, expressed behind a host-provided model port. */
@@ -62,9 +71,11 @@ export type CompactionStrategyResult<TMessage extends CompactionMessage> = Reado
62
71
  export declare function compactMessagesWithSummaryStrategy<TMessage extends CompactionMessage>(options: Readonly<{
63
72
  messages: readonly TMessage[];
64
73
  preserveLatestUserTurn?: boolean;
74
+ preserveRecentTurns?: number;
65
75
  keepRecentCount?: number;
66
76
  summarizeWithLlm?: (oldMessages: readonly TMessage[]) => Promise<string | null | undefined>;
67
77
  summarizeStructurally: (oldMessages: readonly TMessage[]) => string | null | undefined;
68
78
  buildHandoffContent: (summary: string, oldCount: number) => string;
69
79
  fallbackSummary?: string;
70
80
  }>): Promise<CompactionStrategyResult<TMessage>>;
81
+ export {};
@@ -1,4 +1,4 @@
1
- export const COMPACTION_SUMMARY_SYSTEM_PROMPT = '你是对话摘要专家。请将以下对话历史压缩为详细摘要,保留关键信息:用户意图、重要决策、技术概念、文件变更、错误修复、待办事项。特别要详细记录用户的具体执行动作与操作步骤——用户要求做了什么、实际改动了哪些文件、命令/操作执行到哪一步、当前停在何处——因为原文已全量压缩、不再保留,连续性完全依赖本摘要承载。输出纯文本,不要用 markdown。';
1
+ export const COMPACTION_SUMMARY_SYSTEM_PROMPT = '你是上下文交接专家。请把历史压缩成可验证、可继续执行的交接清单。必须区分事实与计划,稳定保留:当前目标与验收标准;用户最近要求及关键原话;已确认、已否决(含原因)和待确认的决策;已读取、已修改、已创建的文件;已执行命令及真实结果;错误、失败尝试与原因;当前运行状态;精确下一步;Evidence、artifact ref 和可重新读取位置;已经完成且不应重复执行的工作。没有证据的事项不得写成已完成。原文压缩后不再保留,连续性完全依赖本摘要承载。输出纯文本,不要用 markdown。';
2
2
  export const COMPACTION_SUMMARY_PROMPT = `Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.
3
3
  This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing development work without losing context.
4
4
 
@@ -20,22 +20,84 @@ Your summary should include the following sections:
20
20
  3. Files and Code Sections: Enumerate specific files and code sections examined, modified, or created. Include a summary of why this file read or edit is important.
21
21
  4. Errors and fixes: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback.
22
22
  5. Problem Solving: Document problems solved and any ongoing troubleshooting efforts.
23
- 6. All user messages: List ALL user messages that are not tool results. These are critical for understanding user feedback and changing intent.
24
- 7. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
25
- 8. Current Work: Describe in detail precisely what was being worked on immediately before this summary request. CRITICAL — record the user's concrete execution actions and operation steps in detail: what the user asked to do, which files were actually changed, what commands/operations were run and to which step they progressed, and exactly where things currently stand. The original conversation is fully compacted and NOT retained, so continuity depends entirely on this summary capturing those execution details.
26
- 9. Optional Next Step: List the next step related to the most recent work. Include direct quotes from the most recent conversation.
23
+ 6. Decisions: Separate confirmed, rejected (with reasons), and pending decisions. Never collapse a rejected option into the final choice.
24
+ 7. All user messages: List ALL user messages that are not tool results. Quote the most recent requirements that affect current work.
25
+ 8. Evidence and recovery: Preserve Tool Result/Evidence/artifact refs, rerunnable retrieval hints, and exact locations that can be read again. Do not present an unverified plan as completed work.
26
+ 9. Pending Tasks: Outline any pending tasks that you have explicitly been asked to work on.
27
+ 10. Current Work: Describe in detail precisely what was being worked on immediately before this summary request. CRITICAL — record the user's concrete execution actions and operation steps in detail: what the user asked to do, which files were actually changed, what commands/operations were run and their real outcomes, and exactly where things currently stand. The original conversation is fully compacted and NOT retained, so continuity depends entirely on this summary capturing those execution details.
28
+ 11. Do Not Repeat: List completed, rejected, or failed work that must not be rerun without new evidence or a changed requirement.
29
+ 12. Exact Next Step: State the next executable step, its success criterion, and any blocker. Include direct quotes from the most recent conversation.
27
30
 
28
31
  CRITICAL: Respond with TEXT ONLY. Do NOT call any tools.
29
32
 
30
33
  Please provide your summary based on the conversation so far, following this structure and ensuring precision and thoroughness in your response.`;
31
- export function formatCompactionMessagesForSummary(messages) {
34
+ export const COMPACTION_SUMMARY_PROJECTION_LIMITS = Object.freeze({
35
+ textChars: 12_000,
36
+ thinkingChars: 512,
37
+ toolInputChars: 2_000,
38
+ toolResultChars: 6_000,
39
+ unknownBlockChars: 4_000,
40
+ });
41
+ function stringifyForSummary(value) {
42
+ if (typeof value === 'string')
43
+ return value;
44
+ try {
45
+ return JSON.stringify(value);
46
+ }
47
+ catch {
48
+ return String(value);
49
+ }
50
+ }
51
+ function truncateSummaryValue(value, maxChars, label) {
52
+ const text = stringifyForSummary(value);
53
+ if (text.length <= maxChars)
54
+ return text;
55
+ const marker = `\n…[${label} truncated: ${text.length} chars total]…\n`;
56
+ const available = Math.max(0, maxChars - marker.length);
57
+ const headChars = Math.ceil(available * 0.6);
58
+ const tailChars = Math.max(0, available - headChars);
59
+ return `${text.slice(0, headChars)}${marker}${tailChars > 0 ? text.slice(-tailChars) : ''}`;
60
+ }
61
+ function projectSummaryContent(content, limits) {
62
+ if (typeof content === 'string') {
63
+ return truncateSummaryValue(content, limits.textChars, 'message text');
64
+ }
65
+ if (!Array.isArray(content)) {
66
+ return truncateSummaryValue(content, limits.unknownBlockChars, 'message content');
67
+ }
68
+ return content.map((rawBlock) => {
69
+ if (!rawBlock || typeof rawBlock !== 'object') {
70
+ return truncateSummaryValue(rawBlock, limits.unknownBlockChars, 'content block');
71
+ }
72
+ const block = rawBlock;
73
+ const type = typeof block.type === 'string' ? block.type : 'unknown';
74
+ if (type === 'text') {
75
+ return `[text] ${truncateSummaryValue(block.text ?? block.content, limits.textChars, 'text block')}`;
76
+ }
77
+ if (type === 'thinking' || type === 'reasoning') {
78
+ return `[${type}] ${truncateSummaryValue(block.content ?? block.thinking ?? block.text, limits.thinkingChars, `${type} block`)}`;
79
+ }
80
+ if (type === 'tool_use' || type === 'tool_call') {
81
+ const id = stringifyForSummary(block.id ?? block.tool_use_id ?? 'unknown');
82
+ const name = stringifyForSummary(block.name ?? block.function?.name ?? 'unknown');
83
+ const input = block.input
84
+ ?? block.arguments
85
+ ?? block.function?.arguments;
86
+ return `[${type} id=${id} name=${name}] ${truncateSummaryValue(input, limits.toolInputChars, 'tool input')}`;
87
+ }
88
+ if (type === 'tool_result' || type === 'tool_response') {
89
+ const id = stringifyForSummary(block.tool_use_id ?? block.toolCallId ?? block.id ?? 'unknown');
90
+ return `[${type} id=${id}] ${truncateSummaryValue(block.content ?? block.result ?? block.output, limits.toolResultChars, 'tool result')}`;
91
+ }
92
+ if (type === 'image' || type === 'image_url') {
93
+ return `[${type} omitted from summary input]`;
94
+ }
95
+ return `[${type}] ${truncateSummaryValue(block, limits.unknownBlockChars, `${type} block`)}`;
96
+ }).join('\n');
97
+ }
98
+ export function formatCompactionMessagesForSummary(messages, limits = COMPACTION_SUMMARY_PROJECTION_LIMITS) {
32
99
  return messages
33
- .map((message) => {
34
- const content = typeof message.content === 'string'
35
- ? message.content
36
- : JSON.stringify(message.content);
37
- return `[${message.role}]: ${content}`;
38
- })
100
+ .map((message) => `[${message.role}]: ${projectSummaryContent(message.content, limits)}`)
39
101
  .join('\n\n');
40
102
  }
41
103
  function contentBlocks(message) {
@@ -70,12 +132,16 @@ function isHumanUserMessage(message) {
70
132
  const blocks = contentBlocks(message);
71
133
  return blocks.length === 0 || blocks.some((block) => block.type !== 'tool_result');
72
134
  }
73
- function findCurrentTurnStart(messages) {
135
+ function findRecentTurnStart(messages, turnCount) {
136
+ let remaining = Math.max(1, Math.floor(turnCount));
74
137
  for (let index = messages.length - 1; index >= 0; index -= 1) {
75
- if (isHumanUserMessage(messages[index]))
138
+ if (!isHumanUserMessage(messages[index]))
139
+ continue;
140
+ remaining -= 1;
141
+ if (remaining === 0)
76
142
  return index;
77
143
  }
78
- return -1;
144
+ return messages.length > 0 ? 0 : -1;
79
145
  }
80
146
  function findUnclosedToolTailStart(messages) {
81
147
  const pending = new Map();
@@ -106,14 +172,27 @@ function expandKeepForToolContinuity(keepMessages, oldMessages) {
106
172
  export function splitMessagesForCompaction(messages, options = {}) {
107
173
  const systemMessages = messages.filter((message) => message.role === 'system');
108
174
  const conversation = messages.filter((message) => message.role !== 'system');
109
- const currentTurnStart = options.preserveLatestUserTurn ? findCurrentTurnStart(conversation) : -1;
175
+ const recentTurnCount = options.preserveLatestUserTurn
176
+ ? Math.max(1, Math.floor(options.preserveRecentTurns ?? 1))
177
+ : 0;
178
+ const recentTurnStart = recentTurnCount > 0
179
+ ? findRecentTurnStart(conversation, recentTurnCount)
180
+ : -1;
181
+ const hasHumanTurn = conversation.some(isHumanUserMessage);
110
182
  let keepMessages;
111
183
  let oldMessages;
112
- if (currentTurnStart >= 0) {
113
- const currentTail = conversation.slice(currentTurnStart + 1);
114
- const unclosedTailStart = findUnclosedToolTailStart(currentTail);
115
- keepMessages = [conversation[currentTurnStart], ...currentTail.slice(unclosedTailStart)];
116
- oldMessages = [...conversation.slice(0, currentTurnStart), ...currentTail.slice(0, unclosedTailStart)];
184
+ if (recentTurnStart >= 0 && hasHumanTurn) {
185
+ const recentTail = conversation.slice(recentTurnStart);
186
+ if (recentTurnCount === 1) {
187
+ const currentTail = recentTail.slice(1);
188
+ const unclosedTailStart = findUnclosedToolTailStart(currentTail);
189
+ keepMessages = [recentTail[0], ...currentTail.slice(unclosedTailStart)];
190
+ oldMessages = [...conversation.slice(0, recentTurnStart), ...currentTail.slice(0, unclosedTailStart)];
191
+ }
192
+ else {
193
+ keepMessages = recentTail;
194
+ oldMessages = conversation.slice(0, recentTurnStart);
195
+ }
117
196
  }
118
197
  else {
119
198
  const requested = Math.max(0, Math.floor(options.keepRecentCount ?? 0));
@@ -161,6 +240,7 @@ export async function runCompactionSummaryCascade(options) {
161
240
  export async function compactMessagesWithSummaryStrategy(options) {
162
241
  const split = splitMessagesForCompaction(options.messages, {
163
242
  preserveLatestUserTurn: options.preserveLatestUserTurn,
243
+ preserveRecentTurns: options.preserveRecentTurns,
164
244
  keepRecentCount: options.keepRecentCount,
165
245
  });
166
246
  if (split.oldMessages.length === 0) {
@@ -0,0 +1,226 @@
1
+ export declare const GOAL_CHECKPOINT_SCHEMA_VERSION: 1;
2
+ export declare const GOAL_CHECKPOINT_STATUSES: readonly ["preparing", "committed", "consumed", "superseded", "invalid"];
3
+ export declare const GOAL_CHECKPOINT_REASONS: readonly ["soft_threshold", "hard_threshold", "provider_overflow", "task_boundary", "manual_compact", "process_recovery"];
4
+ export declare const GOAL_RESUME_POLICIES: readonly ["continue_same_turn", "start_recovery_turn", "verify_then_continue", "wait_for_user"];
5
+ export declare const GOAL_CHECKPOINT_LIMITS: {
6
+ readonly maxRecentActions: number;
7
+ readonly maxDecisions: number;
8
+ readonly maxBlockers: number;
9
+ readonly maxRisks: number;
10
+ readonly maxOpenQuestions: number;
11
+ readonly maxPendingVerifications: number;
12
+ readonly maxDoNotRepeat: number;
13
+ readonly maxEvidenceRefs: number;
14
+ readonly maxOpenToolCalls: number;
15
+ readonly maxTextChars: number;
16
+ readonly maxHandoffChars: number;
17
+ readonly maxInstructionChars: number;
18
+ };
19
+ type CheckpointStatus = (typeof GOAL_CHECKPOINT_STATUSES)[number];
20
+ type CheckpointReason = (typeof GOAL_CHECKPOINT_REASONS)[number];
21
+ type ResumePolicy = (typeof GOAL_RESUME_POLICIES)[number];
22
+ /**
23
+ * Digest excludes lifecycle fields so content identity stays stable across
24
+ * preparing → committed → consumed transitions.
25
+ */
26
+ export declare function computeGoalCheckpointDigest(checkpoint: Record<string, unknown>): string;
27
+ export declare function isGoalCheckpointStatus(value: unknown): value is CheckpointStatus;
28
+ export declare function isGoalCheckpointReason(value: unknown): value is CheckpointReason;
29
+ export declare function isGoalResumePolicy(value: unknown): value is ResumePolicy;
30
+ export declare function createGoalCheckpointIds(now?: Date): {
31
+ checkpointId: string;
32
+ compactionId: string;
33
+ };
34
+ export declare function normalizeGoalCheckpoint(input: unknown, options?: {
35
+ readonly fallbackPlanId?: string;
36
+ readonly fallbackRunId?: string;
37
+ readonly fallbackPlanVersion?: number;
38
+ readonly now?: string;
39
+ }): {
40
+ digest: string;
41
+ consumedAt?: string | undefined;
42
+ committedAt?: string | undefined;
43
+ progress: {
44
+ total: number;
45
+ completed: number;
46
+ failed: number;
47
+ blocked: number;
48
+ percent: number;
49
+ nextRunnableTaskIds: string[];
50
+ };
51
+ objectiveNow: string;
52
+ currentWork: string;
53
+ recentActions: {
54
+ occurredAt?: string | undefined;
55
+ result?: string | undefined;
56
+ evidenceRefs: string[];
57
+ target?: string | undefined;
58
+ actionId: string;
59
+ kind: string;
60
+ summary: string;
61
+ status: string;
62
+ }[];
63
+ completedSincePrevious: string[];
64
+ mostImportantFact: string;
65
+ decisions: string[];
66
+ blockers: string[];
67
+ risks: string[];
68
+ openQuestions: string[];
69
+ pendingVerifications: string[];
70
+ doNotRepeat: string[];
71
+ handoffNote: string;
72
+ firstAction: {
73
+ forbiddenUntilComplete?: string[] | undefined;
74
+ successCheck: string;
75
+ requiredEvidenceRefs: string[];
76
+ target?: string | undefined;
77
+ kind: string;
78
+ instruction: string;
79
+ };
80
+ evidenceRefs: string[];
81
+ mustReadEvidenceRefs: string[];
82
+ openToolCalls: {
83
+ idempotencyKey?: string | undefined;
84
+ status: string;
85
+ resultEvidenceRefs: string[];
86
+ replayPolicy: string;
87
+ toolName?: string | undefined;
88
+ toolCallId: string;
89
+ }[];
90
+ budget: {
91
+ contextWindow: number | null;
92
+ beforeTokens: number;
93
+ targetTokens: number;
94
+ systemTokens: number;
95
+ toolsTokens: number;
96
+ checkpointTokens: number;
97
+ continuityTokens: number;
98
+ recentTailTokens: number;
99
+ keepBudgetTokens: number;
100
+ compactionCount: number;
101
+ };
102
+ resumePolicy: "continue_same_turn" | "start_recovery_turn" | "verify_then_continue" | "wait_for_user";
103
+ createdAt: string;
104
+ runnerIntent?: string | undefined;
105
+ runnerPhase?: string | undefined;
106
+ currentTaskId?: string | undefined;
107
+ conversationRevision?: string | undefined;
108
+ contextEpochId?: string | undefined;
109
+ streamId?: string | undefined;
110
+ conversationId?: string | undefined;
111
+ schemaVersion: 1;
112
+ checkpointId: string;
113
+ compactionId: string;
114
+ sequence: number;
115
+ status: "preparing" | "committed" | "consumed" | "superseded" | "invalid";
116
+ reason: "provider_overflow" | "manual_compact" | "soft_threshold" | "hard_threshold" | "task_boundary" | "process_recovery";
117
+ planId: string;
118
+ planVersion: number;
119
+ runId: string;
120
+ };
121
+ export declare function validateGoalCheckpoint(checkpoint: unknown): {
122
+ readonly ok: boolean;
123
+ readonly errors: string[];
124
+ readonly checkpoint: ReturnType<typeof normalizeGoalCheckpoint> | null;
125
+ };
126
+ /**
127
+ * Deterministic checkpoint builder used when no LLM handoff is available.
128
+ * Callers may overlay narrative fields before normalizeGoalCheckpoint().
129
+ */
130
+ export declare function buildDeterministicGoalCheckpoint(input: {
131
+ readonly plan: Record<string, unknown>;
132
+ readonly reason?: unknown;
133
+ readonly runId?: string;
134
+ readonly sequence?: number;
135
+ readonly checkpointId?: string;
136
+ readonly compactionId?: string;
137
+ readonly conversationId?: string;
138
+ readonly streamId?: string;
139
+ readonly openToolCalls?: readonly unknown[];
140
+ readonly recentActions?: readonly unknown[];
141
+ readonly budget?: unknown;
142
+ readonly now?: string;
143
+ }): {
144
+ digest: string;
145
+ consumedAt?: string | undefined;
146
+ committedAt?: string | undefined;
147
+ progress: {
148
+ total: number;
149
+ completed: number;
150
+ failed: number;
151
+ blocked: number;
152
+ percent: number;
153
+ nextRunnableTaskIds: string[];
154
+ };
155
+ objectiveNow: string;
156
+ currentWork: string;
157
+ recentActions: {
158
+ occurredAt?: string | undefined;
159
+ result?: string | undefined;
160
+ evidenceRefs: string[];
161
+ target?: string | undefined;
162
+ actionId: string;
163
+ kind: string;
164
+ summary: string;
165
+ status: string;
166
+ }[];
167
+ completedSincePrevious: string[];
168
+ mostImportantFact: string;
169
+ decisions: string[];
170
+ blockers: string[];
171
+ risks: string[];
172
+ openQuestions: string[];
173
+ pendingVerifications: string[];
174
+ doNotRepeat: string[];
175
+ handoffNote: string;
176
+ firstAction: {
177
+ forbiddenUntilComplete?: string[] | undefined;
178
+ successCheck: string;
179
+ requiredEvidenceRefs: string[];
180
+ target?: string | undefined;
181
+ kind: string;
182
+ instruction: string;
183
+ };
184
+ evidenceRefs: string[];
185
+ mustReadEvidenceRefs: string[];
186
+ openToolCalls: {
187
+ idempotencyKey?: string | undefined;
188
+ status: string;
189
+ resultEvidenceRefs: string[];
190
+ replayPolicy: string;
191
+ toolName?: string | undefined;
192
+ toolCallId: string;
193
+ }[];
194
+ budget: {
195
+ contextWindow: number | null;
196
+ beforeTokens: number;
197
+ targetTokens: number;
198
+ systemTokens: number;
199
+ toolsTokens: number;
200
+ checkpointTokens: number;
201
+ continuityTokens: number;
202
+ recentTailTokens: number;
203
+ keepBudgetTokens: number;
204
+ compactionCount: number;
205
+ };
206
+ resumePolicy: "continue_same_turn" | "start_recovery_turn" | "verify_then_continue" | "wait_for_user";
207
+ createdAt: string;
208
+ runnerIntent?: string | undefined;
209
+ runnerPhase?: string | undefined;
210
+ currentTaskId?: string | undefined;
211
+ conversationRevision?: string | undefined;
212
+ contextEpochId?: string | undefined;
213
+ streamId?: string | undefined;
214
+ conversationId?: string | undefined;
215
+ schemaVersion: 1;
216
+ checkpointId: string;
217
+ compactionId: string;
218
+ sequence: number;
219
+ status: "preparing" | "committed" | "consumed" | "superseded" | "invalid";
220
+ reason: "provider_overflow" | "manual_compact" | "soft_threshold" | "hard_threshold" | "task_boundary" | "process_recovery";
221
+ planId: string;
222
+ planVersion: number;
223
+ runId: string;
224
+ };
225
+ export declare function formatGoalCheckpointForPrompt(checkpoint: unknown): string;
226
+ export {};