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

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,8 +12,8 @@ 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.";
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
17
  export declare function formatCompactionMessagesForSummary(messages: readonly CompactionMessage[]): string;
18
18
  export interface CompactionSplit<TMessage extends CompactionMessage> {
19
19
  readonly systemMessages: readonly TMessage[];
@@ -39,6 +39,7 @@ export interface CompactionSummaryCascadeOptions<TMessage extends CompactionMess
39
39
  */
40
40
  export declare function splitMessagesForCompaction<TMessage extends CompactionMessage>(messages: readonly TMessage[], options?: {
41
41
  readonly preserveLatestUserTurn?: boolean;
42
+ readonly preserveRecentTurns?: number;
42
43
  readonly keepRecentCount?: number;
43
44
  }): CompactionSplit<TMessage>;
44
45
  /** Desktop's summary preference order, expressed behind a host-provided model port. */
@@ -62,6 +63,7 @@ export type CompactionStrategyResult<TMessage extends CompactionMessage> = Reado
62
63
  export declare function compactMessagesWithSummaryStrategy<TMessage extends CompactionMessage>(options: Readonly<{
63
64
  messages: readonly TMessage[];
64
65
  preserveLatestUserTurn?: boolean;
66
+ preserveRecentTurns?: number;
65
67
  keepRecentCount?: number;
66
68
  summarizeWithLlm?: (oldMessages: readonly TMessage[]) => Promise<string | null | undefined>;
67
69
  summarizeStructurally: (oldMessages: readonly TMessage[]) => string | null | undefined;
@@ -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,10 +20,13 @@ 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
 
@@ -70,12 +73,16 @@ function isHumanUserMessage(message) {
70
73
  const blocks = contentBlocks(message);
71
74
  return blocks.length === 0 || blocks.some((block) => block.type !== 'tool_result');
72
75
  }
73
- function findCurrentTurnStart(messages) {
76
+ function findRecentTurnStart(messages, turnCount) {
77
+ let remaining = Math.max(1, Math.floor(turnCount));
74
78
  for (let index = messages.length - 1; index >= 0; index -= 1) {
75
- if (isHumanUserMessage(messages[index]))
79
+ if (!isHumanUserMessage(messages[index]))
80
+ continue;
81
+ remaining -= 1;
82
+ if (remaining === 0)
76
83
  return index;
77
84
  }
78
- return -1;
85
+ return messages.length > 0 ? 0 : -1;
79
86
  }
80
87
  function findUnclosedToolTailStart(messages) {
81
88
  const pending = new Map();
@@ -106,14 +113,27 @@ function expandKeepForToolContinuity(keepMessages, oldMessages) {
106
113
  export function splitMessagesForCompaction(messages, options = {}) {
107
114
  const systemMessages = messages.filter((message) => message.role === 'system');
108
115
  const conversation = messages.filter((message) => message.role !== 'system');
109
- const currentTurnStart = options.preserveLatestUserTurn ? findCurrentTurnStart(conversation) : -1;
116
+ const recentTurnCount = options.preserveLatestUserTurn
117
+ ? Math.max(1, Math.floor(options.preserveRecentTurns ?? 1))
118
+ : 0;
119
+ const recentTurnStart = recentTurnCount > 0
120
+ ? findRecentTurnStart(conversation, recentTurnCount)
121
+ : -1;
122
+ const hasHumanTurn = conversation.some(isHumanUserMessage);
110
123
  let keepMessages;
111
124
  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)];
125
+ if (recentTurnStart >= 0 && hasHumanTurn) {
126
+ const recentTail = conversation.slice(recentTurnStart);
127
+ if (recentTurnCount === 1) {
128
+ const currentTail = recentTail.slice(1);
129
+ const unclosedTailStart = findUnclosedToolTailStart(currentTail);
130
+ keepMessages = [recentTail[0], ...currentTail.slice(unclosedTailStart)];
131
+ oldMessages = [...conversation.slice(0, recentTurnStart), ...currentTail.slice(0, unclosedTailStart)];
132
+ }
133
+ else {
134
+ keepMessages = recentTail;
135
+ oldMessages = conversation.slice(0, recentTurnStart);
136
+ }
117
137
  }
118
138
  else {
119
139
  const requested = Math.max(0, Math.floor(options.keepRecentCount ?? 0));
@@ -161,6 +181,7 @@ export async function runCompactionSummaryCascade(options) {
161
181
  export async function compactMessagesWithSummaryStrategy(options) {
162
182
  const split = splitMessagesForCompaction(options.messages, {
163
183
  preserveLatestUserTurn: options.preserveLatestUserTurn,
184
+ preserveRecentTurns: options.preserveRecentTurns,
164
185
  keepRecentCount: options.keepRecentCount,
165
186
  });
166
187
  if (split.oldMessages.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/runtime-core",
3
- "version": "0.0.1-beta.43",
3
+ "version": "0.0.1-beta.44",
4
4
  "description": "Host-neutral capability, permission, projection, and Evidence primitives for Peer Agent runtimes.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,12 +10,12 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/yinLiangDream/Peer-Agent.git",
13
+ "url": "git+https://github.com/ly-ccx/Peer-Agent.git",
14
14
  "directory": "packages/runtime-core"
15
15
  },
16
- "homepage": "https://github.com/yinLiangDream/Peer-Agent#readme",
16
+ "homepage": "https://github.com/ly-ccx/Peer-Agent#readme",
17
17
  "bugs": {
18
- "url": "https://github.com/yinLiangDream/Peer-Agent/issues"
18
+ "url": "https://github.com/ly-ccx/Peer-Agent/issues"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public"
@@ -34,7 +34,7 @@
34
34
  "LICENSE"
35
35
  ],
36
36
  "dependencies": {
37
- "@peer-agent/protocol": "0.0.1-beta.43"
37
+ "@peer-agent/protocol": "0.0.1-beta.44"
38
38
  },
39
39
  "devDependencies": {
40
40
  "typescript": "^5.9.3"