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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/context.ts +34 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-codebuddy-sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "CodeBuddy Agent SDK provider for Pi — native tool execution, 29+ models, thinking controls, session pool",
5
5
  "author": "slahser",
6
6
  "license": "MIT",
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
- const parts: string[] = [];
75
-
76
- // ponytail: skip Pi systemPrompt — CodeBuddy uses its own.
77
- // Pi's prompt references MCP/tool ecosystem not present in CodeBuddy,
78
- // which confuses the model into calling non-existent tools.
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];