@sayknow-cli/agent-core 0.7.8 → 0.7.10
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 +18 -0
- package/dist/types/compaction/utils.d.ts +2 -0
- package/package.json +4 -4
- package/src/agent-loop.ts +21 -2
- package/src/compaction/compaction.ts +3 -2
- package/src/compaction/messages.ts +5 -2
- package/src/compaction/prompts/compaction-summary-context.md +1 -1
- package/src/compaction/prompts/compaction-summary.md +1 -1
- package/src/compaction/prompts/compaction-update-summary.md +1 -1
- package/src/compaction/prompts/handoff-document.md +1 -1
- package/src/compaction/utils.ts +17 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.7.10] - 2026-10-20
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- The post-compaction context message now presents the summary as this session's compacted work state instead of "a summary of another language model's thinking process". The old framing read as handing over another model's reasoning and correlated with Anthropic `reasoning_extraction` refusals in long sessions.
|
|
10
|
+
- The compaction summary, compaction update, and handoff-document prompts no longer describe the summary as written "for another LLM" or "another instance of yourself"; they describe resuming the task after older context is dropped.
|
|
11
|
+
- Compaction keeps the category of a provider refusal (`Refusal (<category>)`) but replaces the provider's explanation with `[provider explanation omitted]` in serialized conversations, previous summaries, stored summaries, and rendered summary context. The "preserve exact error messages" rule otherwise copied the policy prose into every later summary and re-sent it on every request.
|
|
12
|
+
|
|
13
|
+
## [0.7.9] - 2026-10-17
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Compaction and branch summaries no longer paste assistant thinking into the summarization prompt; `serializeConversation` emits only visible assistant text, tool calls, user messages, and tool results.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Fallback-managed runs keep replay metadata on committed assistant content: `thinkingSignature`, `itemId`, `provenance`, `summaryText`, and `rawText` on thinking blocks and `textSignature` on text blocks. Dropping them made every managed turn persist unsigned thinking, which later requests replayed as plain text instead of signed reasoning.
|
|
22
|
+
|
|
5
23
|
## [0.7.8] - 2026-10-09
|
|
6
24
|
|
|
7
25
|
### Changed
|
|
@@ -23,6 +23,8 @@ export declare function computeFileLists(fileOps: FileOperations): {
|
|
|
23
23
|
};
|
|
24
24
|
export declare function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string;
|
|
25
25
|
export declare function upsertFileOperations(summary: string, readFiles: string[], modifiedFiles: string[]): string;
|
|
26
|
+
export declare const PROVIDER_REFUSAL_EXPLANATION_OMITTED = "[provider explanation omitted]";
|
|
27
|
+
export declare function redactProviderRefusalExplanations(text: string): string;
|
|
26
28
|
/**
|
|
27
29
|
* Serialize LLM messages to text for summarization.
|
|
28
30
|
* This prevents the model from treating it as a conversation to continue.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sayknow-cli/agent-core",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.10",
|
|
5
5
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
6
6
|
"homepage": "https://sayknow-cli.com",
|
|
7
7
|
"author": "jaybeyond",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"fmt": "biome format --write ."
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@sayknow-cli/ai": "0.7.
|
|
39
|
-
"@sayknow-cli/natives": "0.7.
|
|
40
|
-
"@sayknow-cli/utils": "0.7.
|
|
38
|
+
"@sayknow-cli/ai": "0.7.10",
|
|
39
|
+
"@sayknow-cli/natives": "0.7.10",
|
|
40
|
+
"@sayknow-cli/utils": "0.7.10",
|
|
41
41
|
"@opentelemetry/api": "^1.9.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
package/src/agent-loop.ts
CHANGED
|
@@ -666,11 +666,30 @@ function managedAssistantContent(value: unknown): AssistantMessage["content"][nu
|
|
|
666
666
|
const type = managedProperty(value, "type");
|
|
667
667
|
if (type === "text") {
|
|
668
668
|
const text = managedProperty(value, "text");
|
|
669
|
-
|
|
669
|
+
if (typeof text !== "string") return undefined;
|
|
670
|
+
const textSignature = managedProperty(value, "textSignature");
|
|
671
|
+
return { type, text, ...(typeof textSignature === "string" ? { textSignature } : {}) };
|
|
670
672
|
}
|
|
671
673
|
if (type === "thinking") {
|
|
672
674
|
const thinking = managedProperty(value, "thinking");
|
|
673
|
-
|
|
675
|
+
if (typeof thinking !== "string") return undefined;
|
|
676
|
+
// Replay metadata must survive the shell: without `thinkingSignature` the
|
|
677
|
+
// provider can no longer replay this block as native signed thinking and
|
|
678
|
+
// degrades the private reasoning to plain assistant text on later requests.
|
|
679
|
+
const thinkingSignature = managedProperty(value, "thinkingSignature");
|
|
680
|
+
const itemId = managedProperty(value, "itemId");
|
|
681
|
+
const provenance = managedProperty(value, "provenance");
|
|
682
|
+
const summaryText = managedProperty(value, "summaryText");
|
|
683
|
+
const rawText = managedProperty(value, "rawText");
|
|
684
|
+
return {
|
|
685
|
+
type,
|
|
686
|
+
thinking,
|
|
687
|
+
...(typeof thinkingSignature === "string" ? { thinkingSignature } : {}),
|
|
688
|
+
...(typeof itemId === "string" ? { itemId } : {}),
|
|
689
|
+
...(provenance === "summary" || provenance === "raw" || provenance === "mixed" ? { provenance } : {}),
|
|
690
|
+
...(typeof summaryText === "string" ? { summaryText } : {}),
|
|
691
|
+
...(typeof rawText === "string" ? { rawText } : {}),
|
|
692
|
+
};
|
|
674
693
|
}
|
|
675
694
|
if (type === "redactedThinking") {
|
|
676
695
|
const data = managedProperty(value, "data");
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
createFileOps,
|
|
41
41
|
extractFileOpsFromMessage,
|
|
42
42
|
type FileOperations,
|
|
43
|
+
redactProviderRefusalExplanations,
|
|
43
44
|
SUMMARIZATION_SYSTEM_PROMPT,
|
|
44
45
|
serializeConversation,
|
|
45
46
|
upsertFileOperations,
|
|
@@ -1023,7 +1024,7 @@ export async function generateSummary(
|
|
|
1023
1024
|
// Build the prompt with conversation wrapped in tags
|
|
1024
1025
|
let promptText = `<conversation>\n${conversationText}\n</conversation>\n\n`;
|
|
1025
1026
|
if (previousSummary) {
|
|
1026
|
-
promptText += `<previous-summary>\n${previousSummary}\n</previous-summary>\n\n`;
|
|
1027
|
+
promptText += `<previous-summary>\n${redactProviderRefusalExplanations(previousSummary)}\n</previous-summary>\n\n`;
|
|
1027
1028
|
}
|
|
1028
1029
|
promptText += formatAdditionalContext(options?.extraContext);
|
|
1029
1030
|
promptText += basePrompt;
|
|
@@ -1560,7 +1561,7 @@ export async function compact(
|
|
|
1560
1561
|
|
|
1561
1562
|
// Compute file lists and append to summary
|
|
1562
1563
|
const { readFiles, modifiedFiles } = computeFileLists(fileOps);
|
|
1563
|
-
summary = upsertFileOperations(summary, readFiles, modifiedFiles);
|
|
1564
|
+
summary = upsertFileOperations(redactProviderRefusalExplanations(summary), readFiles, modifiedFiles);
|
|
1564
1565
|
const shortSummary = deriveShortSummary(summary);
|
|
1565
1566
|
|
|
1566
1567
|
if (!firstKeptEntryId) {
|
|
@@ -11,6 +11,7 @@ import { prompt } from "@sayknow-cli/utils";
|
|
|
11
11
|
import type { AgentMessage } from "../types";
|
|
12
12
|
import branchSummaryContextPrompt from "./prompts/branch-summary-context.md" with { type: "text" };
|
|
13
13
|
import compactionSummaryContextPrompt from "./prompts/compaction-summary-context.md" with { type: "text" };
|
|
14
|
+
import { redactProviderRefusalExplanations } from "./utils";
|
|
14
15
|
|
|
15
16
|
const COMPACTION_SUMMARY_TEMPLATE = compactionSummaryContextPrompt;
|
|
16
17
|
const BRANCH_SUMMARY_TEMPLATE = branchSummaryContextPrompt;
|
|
@@ -76,11 +77,13 @@ function getPrunedToolResultContent(message: ToolResultMessage): (TextContent |
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
export function renderBranchSummaryContext(summary: string): string {
|
|
79
|
-
return prompt.render(BRANCH_SUMMARY_TEMPLATE, { summary });
|
|
80
|
+
return prompt.render(BRANCH_SUMMARY_TEMPLATE, { summary: redactProviderRefusalExplanations(summary) });
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
// Summaries persisted before refusal redaction existed still carry the provider's
|
|
84
|
+
// explanation; redact at render time so stored sessions stop re-sending it.
|
|
82
85
|
export function renderCompactionSummaryContext(summary: string): string {
|
|
83
|
-
return prompt.render(COMPACTION_SUMMARY_TEMPLATE, { summary });
|
|
86
|
+
return prompt.render(COMPACTION_SUMMARY_TEMPLATE, { summary: redactProviderRefusalExplanations(summary) });
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
export function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
Earlier turns of this session were compacted to save context. The summary below records the work completed so far, the decisions made, and the current state of the task; the files and tool state it describes are still in place. Continue the task from this state: build on the completed work and NEVER redo it.
|
|
2
2
|
|
|
3
3
|
<summary>
|
|
4
4
|
{{summary}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
You MUST summarize the conversation above into a structured context checkpoint handoff summary
|
|
1
|
+
You MUST summarize the conversation above into a structured context checkpoint handoff summary so the task can resume from it after older context is dropped.
|
|
2
2
|
|
|
3
3
|
IMPORTANT: If conversation ends with unanswered question to user or imperative/request awaiting user response (e.g., "Please run command and paste output"), you MUST preserve that exact question/request.
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
You MUST incorporate new messages above into the existing handoff summary in <previous-summary> tags
|
|
1
|
+
You MUST incorporate new messages above into the existing handoff summary in <previous-summary> tags; the task resumes from this summary after older context is dropped.
|
|
2
2
|
RULES:
|
|
3
3
|
- MUST preserve all information from previous summary
|
|
4
4
|
- MUST add new progress, decisions, and context from new messages
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<critical>
|
|
2
|
-
Write a handoff document
|
|
2
|
+
Write a handoff document so this work can continue in a fresh session.
|
|
3
3
|
The handoff MUST be sufficient for seamless continuation without access to this conversation.
|
|
4
4
|
Output ONLY the handoff document. No preamble, no commentary, no wrapper text.
|
|
5
5
|
</critical>
|
package/src/compaction/utils.ts
CHANGED
|
@@ -118,6 +118,20 @@ function truncateForSummary(text: string, maxChars: number): string {
|
|
|
118
118
|
return `${text.slice(0, maxChars)}\n\n[... ${truncatedChars} more characters truncated]`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Provider refusal errors render as `Refusal (<category>): <explanation>` (see the
|
|
123
|
+
* Anthropic adapter). The explanation is the provider's own policy prose; once it
|
|
124
|
+
* lands in a compaction summary, the "preserve exact error messages" rule copies it
|
|
125
|
+
* into every later summary and re-sends it with every request. Keep the category,
|
|
126
|
+
* which is what the work needs, and drop the explanation.
|
|
127
|
+
*/
|
|
128
|
+
const PROVIDER_REFUSAL_EXPLANATION = /\bRefusal \(([A-Za-z0-9_.-]+)\): [^\n`"]+/g;
|
|
129
|
+
export const PROVIDER_REFUSAL_EXPLANATION_OMITTED = "[provider explanation omitted]";
|
|
130
|
+
|
|
131
|
+
export function redactProviderRefusalExplanations(text: string): string {
|
|
132
|
+
return text.replace(PROVIDER_REFUSAL_EXPLANATION, `Refusal ($1): ${PROVIDER_REFUSAL_EXPLANATION_OMITTED}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
121
135
|
/**
|
|
122
136
|
* Serialize LLM messages to text for summarization.
|
|
123
137
|
* This prevents the model from treating it as a conversation to continue.
|
|
@@ -138,14 +152,13 @@ export function serializeConversation(messages: Message[]): string {
|
|
|
138
152
|
if (content) parts.push(`[User]: ${content}`);
|
|
139
153
|
} else if (msg.role === "assistant") {
|
|
140
154
|
const textParts: string[] = [];
|
|
141
|
-
const thinkingParts: string[] = [];
|
|
142
155
|
const toolCalls: string[] = [];
|
|
143
156
|
|
|
157
|
+
// Thinking is private model reasoning; summarize only what the assistant
|
|
158
|
+
// visibly said and did, never paste prior reasoning into the summary prompt.
|
|
144
159
|
for (const block of msg.content) {
|
|
145
160
|
if (block.type === "text") {
|
|
146
161
|
textParts.push(block.text);
|
|
147
|
-
} else if (block.type === "thinking") {
|
|
148
|
-
thinkingParts.push(block.thinking);
|
|
149
162
|
} else if (block.type === "toolCall") {
|
|
150
163
|
// `arguments` is typed non-null, but persisted history can carry a
|
|
151
164
|
// null/non-object payload from an aborted or malformed tool call.
|
|
@@ -159,9 +172,6 @@ export function serializeConversation(messages: Message[]): string {
|
|
|
159
172
|
}
|
|
160
173
|
}
|
|
161
174
|
|
|
162
|
-
if (thinkingParts.length > 0) {
|
|
163
|
-
parts.push(`[Assistant thinking]: ${thinkingParts.join("\n")}`);
|
|
164
|
-
}
|
|
165
175
|
if (textParts.length > 0) {
|
|
166
176
|
parts.push(`[Assistant]: ${textParts.join("\n")}`);
|
|
167
177
|
}
|
|
@@ -179,7 +189,7 @@ export function serializeConversation(messages: Message[]): string {
|
|
|
179
189
|
}
|
|
180
190
|
}
|
|
181
191
|
|
|
182
|
-
return parts.join("\n\n");
|
|
192
|
+
return redactProviderRefusalExplanations(parts.join("\n\n"));
|
|
183
193
|
}
|
|
184
194
|
|
|
185
195
|
// ============================================================================
|