pi-codebuddy-sdk 0.1.7 → 0.1.9
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/package.json +1 -1
- package/src/context.ts +34 -6
package/package.json
CHANGED
package/src/context.ts
CHANGED
|
@@ -71,15 +71,18 @@ function buildMessage(context: Context, startIndex: number): string | CbUserMess
|
|
|
71
71
|
* The latest user message is always excluded (handled separately).
|
|
72
72
|
*/
|
|
73
73
|
function buildHistoryPrefix(context: Context, startIndex: number): string {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
74
|
+
// ponytail: on first turn, send only previous user messages as context.
|
|
75
|
+
// Assistant messages, tool calls, tool results, system injections
|
|
76
|
+
// (context-mode state, compaction XML, MCP references) are all from
|
|
77
|
+
// another provider and confuse CodeBuddy models.
|
|
78
|
+
if (startIndex === 0) {
|
|
79
|
+
return buildUserOnlyPrefix(context);
|
|
80
|
+
}
|
|
79
81
|
|
|
82
|
+
// Continuation turns: include all new messages (from this CodeBuddy session).
|
|
83
|
+
const parts: string[] = [];
|
|
80
84
|
const messages = context.messages;
|
|
81
85
|
|
|
82
|
-
// All messages in range except the last user message
|
|
83
86
|
for (let i = startIndex; i < messages.length; i++) {
|
|
84
87
|
const msg = messages[i];
|
|
85
88
|
if (i === messages.length - 1 && msg.role === "user") continue;
|
|
@@ -133,6 +136,31 @@ function truncateToolResult(text: string): string {
|
|
|
133
136
|
|
|
134
137
|
// ── helpers ──
|
|
135
138
|
|
|
139
|
+
/**
|
|
140
|
+
* First-turn prefix: only previous user messages.
|
|
141
|
+
* Skips assistant, tool results, system injections — all provider noise.
|
|
142
|
+
*/
|
|
143
|
+
function buildUserOnlyPrefix(context: Context): string {
|
|
144
|
+
const messages = context.messages;
|
|
145
|
+
if (messages.length <= 1) return "";
|
|
146
|
+
|
|
147
|
+
const parts: string[] = [];
|
|
148
|
+
for (let i = 0; i < messages.length - 1; i++) {
|
|
149
|
+
const msg = messages[i];
|
|
150
|
+
if (msg.role === "user") {
|
|
151
|
+
const text = extractTextContent(msg.content);
|
|
152
|
+
const hasImages = extractImages(msg).length > 0;
|
|
153
|
+
if (text) {
|
|
154
|
+
parts.push(`User: ${text}${hasImages ? " [image omitted]" : ""}`);
|
|
155
|
+
} else if (hasImages) {
|
|
156
|
+
parts.push("User: [image omitted]");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// skip everything else: assistant, toolResult, system injections
|
|
160
|
+
}
|
|
161
|
+
return parts.length > 0 ? parts.join("\n") + "\n\n" : "";
|
|
162
|
+
}
|
|
163
|
+
|
|
136
164
|
function findLastUserMessage(context: Context, startIndex: number) {
|
|
137
165
|
for (let i = context.messages.length - 1; i >= startIndex; i--) {
|
|
138
166
|
if (context.messages[i].role === "user") return context.messages[i];
|