@ramarivera/coding-buddy 0.4.0-alpha.5 → 0.4.0-alpha.7
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.
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
},
|
|
6
6
|
"metadata": {
|
|
7
7
|
"description": "Permanent coding companion for Claude Code",
|
|
8
|
-
"version": "0.4.0-alpha.
|
|
8
|
+
"version": "0.4.0-alpha.7"
|
|
9
9
|
},
|
|
10
10
|
"plugins": [
|
|
11
11
|
{
|
|
12
12
|
"name": "claude-buddy",
|
|
13
13
|
"source": "./",
|
|
14
14
|
"description": "Permanent coding companion for Claude Code \u2014 survives any update. MCP-based terminal pet with ASCII art, stats, reactions, and personality.",
|
|
15
|
-
"version": "0.4.0-alpha.
|
|
15
|
+
"version": "0.4.0-alpha.7",
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "1270011"
|
|
18
18
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-buddy",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.7"
|
|
4
4
|
"description": "Permanent coding companion for Claude Code \u2014 survives any update. MCP-based terminal pet with ASCII art, stats, reactions, and personality.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "1270011"
|
package/adapters/pi/events.ts
CHANGED
|
@@ -9,12 +9,13 @@ import type {
|
|
|
9
9
|
} from "@mariozechner/pi-coding-agent";
|
|
10
10
|
import { isBashToolResult } from "@mariozechner/pi-coding-agent";
|
|
11
11
|
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
|
12
|
-
import type
|
|
12
|
+
import { complete, type AssistantMessage, type TextContent, type UserMessage } from "@mariozechner/pi-ai";
|
|
13
13
|
import { BuddyCommandService } from "../../core/command-service.ts";
|
|
14
14
|
import type { Achievement } from "../../core/achievements.ts";
|
|
15
15
|
import type { Companion } from "../../core/model.ts";
|
|
16
16
|
import { getNameReaction, getSuccessReaction } from "../../core/reactions.ts";
|
|
17
17
|
import { PiBuddyStorage } from "./storage.ts";
|
|
18
|
+
import { buildBuddyReactionPrompt, normalizeBuddyComment, stripBuddyComments } from "./prompt.ts";
|
|
18
19
|
import { PiBuddyUI } from "./ui.ts";
|
|
19
20
|
|
|
20
21
|
interface RegisterBuddyEventsDeps {
|
|
@@ -88,12 +89,7 @@ export function registerBuddyEvents(pi: ExtensionAPI, deps: RegisterBuddyEventsD
|
|
|
88
89
|
return;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
deps.ui.refresh(ctx, progress.companion, deps.storage.loadLatest(), progress.achievements);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const comment = deriveTurnComment(progress.companion, event.message);
|
|
92
|
+
const comment = await generateTurnComment(ctx, progress.companion, event);
|
|
97
93
|
if (!comment) {
|
|
98
94
|
deps.ui.refresh(ctx, progress.companion, deps.storage.loadLatest(), progress.achievements);
|
|
99
95
|
return;
|
|
@@ -177,10 +173,66 @@ function isAssistantMessage(message: AgentMessage): message is AssistantMessage
|
|
|
177
173
|
function getAssistantText(message: AssistantMessage): string {
|
|
178
174
|
return message.content
|
|
179
175
|
.filter((block): block is TextContent => block.type === "text")
|
|
180
|
-
.map((block) => block.text)
|
|
176
|
+
.map((block) => stripBuddyComments(block.text))
|
|
181
177
|
.join("\n");
|
|
182
178
|
}
|
|
183
179
|
|
|
180
|
+
async function generateTurnComment(
|
|
181
|
+
ctx: ExtensionContext,
|
|
182
|
+
companion: Companion,
|
|
183
|
+
event: TurnEndEvent,
|
|
184
|
+
): Promise<string | null> {
|
|
185
|
+
const assistantText = isAssistantMessage(event.message) ? getAssistantText(event.message) : "";
|
|
186
|
+
if (!assistantText.trim()) return null;
|
|
187
|
+
|
|
188
|
+
if (ctx.model) {
|
|
189
|
+
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(ctx.model);
|
|
190
|
+
if (auth.ok && auth.apiKey) {
|
|
191
|
+
const userMessage: UserMessage = {
|
|
192
|
+
role: "user",
|
|
193
|
+
content: [{ type: "text", text: buildBuddyReactionPrompt(companion, assistantText, getToolResultsText(event)) }],
|
|
194
|
+
timestamp: Date.now(),
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
const response = await complete(
|
|
199
|
+
ctx.model,
|
|
200
|
+
{ messages: [userMessage] },
|
|
201
|
+
{
|
|
202
|
+
apiKey: auth.apiKey,
|
|
203
|
+
headers: auth.headers,
|
|
204
|
+
signal: ctx.signal,
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (response.stopReason !== "aborted") {
|
|
209
|
+
const text = response.content
|
|
210
|
+
.filter((block): block is TextContent => block.type === "text")
|
|
211
|
+
.map((block) => block.text)
|
|
212
|
+
.join("\n");
|
|
213
|
+
const normalized = normalizeBuddyComment(text);
|
|
214
|
+
if (normalized) return normalized;
|
|
215
|
+
}
|
|
216
|
+
} catch {
|
|
217
|
+
// Fall through to heuristic fallback.
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return deriveTurnComment(companion, event.message);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function getToolResultsText(event: TurnEndEvent): string {
|
|
226
|
+
return event.toolResults
|
|
227
|
+
.map((result) => result.content
|
|
228
|
+
.filter((block): block is TextContent => block.type === "text")
|
|
229
|
+
.map((block) => block.text)
|
|
230
|
+
.join("\n"))
|
|
231
|
+
.filter(Boolean)
|
|
232
|
+
.join("\n\n")
|
|
233
|
+
.slice(0, 4000);
|
|
234
|
+
}
|
|
235
|
+
|
|
184
236
|
export function deriveTurnComment(companion: Companion, message: AgentMessage): string | null {
|
|
185
237
|
if (!isAssistantMessage(message)) return null;
|
|
186
238
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Companion } from "../../core/model.ts";
|
|
2
|
+
|
|
3
|
+
export function buildBuddyReactionPrompt(
|
|
4
|
+
companion: Companion,
|
|
5
|
+
assistantText: string,
|
|
6
|
+
toolText: string,
|
|
7
|
+
): string {
|
|
8
|
+
return [
|
|
9
|
+
`You are generating a single end-of-turn buddy reaction for ${companion.name}, a ${companion.bones.rarity} ${companion.bones.species}.`,
|
|
10
|
+
`Buddy personality: ${companion.personality}`,
|
|
11
|
+
`Peak stat: ${companion.bones.peak} (${companion.bones.stats[companion.bones.peak]}). Dump stat: ${companion.bones.dump} (${companion.bones.stats[companion.bones.dump]}).`,
|
|
12
|
+
"",
|
|
13
|
+
"Write exactly one short in-character reaction sentence as the buddy.",
|
|
14
|
+
"Rules:",
|
|
15
|
+
`- Write as ${companion.name}, not as the assistant.`,
|
|
16
|
+
"- Reference something specific from the turn.",
|
|
17
|
+
"- Max 150 characters.",
|
|
18
|
+
"- Use *asterisks* for physical actions when useful.",
|
|
19
|
+
"- Output only the reaction line, with no quotes, labels, markdown fences, or explanation.",
|
|
20
|
+
"",
|
|
21
|
+
"Assistant response:",
|
|
22
|
+
assistantText || "(empty)",
|
|
23
|
+
"",
|
|
24
|
+
"Tool result summary:",
|
|
25
|
+
toolText || "(none)",
|
|
26
|
+
].join("\n");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function stripBuddyComments(text: string): string {
|
|
30
|
+
return text.replace(/<!--\s*buddy:\s*[\s\S]*?-->/gi, "").trimEnd();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function normalizeBuddyComment(text: string): string {
|
|
34
|
+
return text
|
|
35
|
+
.replace(/<!--\s*buddy:\s*([\s\S]*?)\s*-->/gi, "$1")
|
|
36
|
+
.replace(/^buddy\s*:\s*/i, "")
|
|
37
|
+
.replace(/^['"`]+|['"`]+$/g, "")
|
|
38
|
+
.replace(/\s+/g, " ")
|
|
39
|
+
.trim()
|
|
40
|
+
.slice(0, 150)
|
|
41
|
+
.trim();
|
|
42
|
+
}
|