From a8d9ee47505a7bf06924e621ff09b49cddbc0c90 Mon Sep 17 00:00:00 2001 From: terpjwu1 Date: Mon, 27 Apr 2026 11:36:23 -0400 Subject: [PATCH 1/2] fix: add insight mode claim extraction instructions to CLAUDE.md injection (v3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The v2 prompt injection only told hosts to pass a summary on buddy_observe. Insight mode requires claims/edges/cwd but the extraction instruction was only returned in the observer prompt response — which hosts don't reliably act on across turns. This caused "inert insight mode" where the feature was on but no claims were collected. v3 adds explicit instructions for passing claims/edges/cwd when insight mode is on. The installer upgrade logic strips old v2 blocks and replaces them. Doctor sentinel updated to recognize both v2 and v3 as current. Co-Authored-By: Claude Opus 4.6 (1M context) --- install.ps1 | 23 +++++++++++++++++++---- install.sh | 20 ++++++++++++++++---- src/__tests__/doctor.test.ts | 15 ++++++++------- src/lib/doctor.ts | 5 +++-- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/install.ps1 b/install.ps1 index 3bf4b6f..4a79571 100644 --- a/install.ps1 +++ b/install.ps1 @@ -348,30 +348,45 @@ if (Get-Command codex -ErrorAction SilentlyContinue) { # ── Inject buddy instructions into CLI prompt files ── $BUDDY_INSTRUCTIONS = @" - + ## Buddy Companion You have a coding companion available via the buddy MCP server. **After completing any coding task** (writing code, fixing bugs, refactoring, deploying, running tests), **automatically call ``buddy_observe``** with a 1-sentence summary of what you did. This gives your companion XP and triggers a personality-flavored reaction. Do this every time — the user expects it. +**When insight mode is on**, also pass ``claims``, ``edges``, and ``cwd`` on every ``buddy_observe`` call: +- ``claims``: 1-4 substantive assertions from the turn that just ended. Each claim needs ``text`` (≤240 chars), ``basis`` (research/empirical/deduction/analogy/definition/llm_output/assumption/vibes), ``speaker`` (user/assistant), ``confidence`` (low/medium/high), and ``external_id`` (e.g. c1). +- ``edges``: relationships between claims — ``{ from, to, type }`` where type is supports/depends_on/contradicts/questions. +- ``cwd``: absolute path of the current project root for workspace isolation. +Skip claims/edges if the turn had no substantive structure. Check ``buddy_status`` or ``buddy_reasoning_status`` to see if insight mode is on. + At the start of each conversation, call ``buddy_status`` to check on your buddy. If the user addresses the buddy by name, respond briefly in character before your normal response. After calling buddy_observe, relay the buddy's reaction to the user. The first text content is an ASCII speech bubble — include it verbatim. - + "@ function Inject-BuddyPrompt($filePath, $cliName) { $dir = Split-Path $filePath -Parent if (!(Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null } - if ((Test-Path $filePath) -and (Select-String -Path $filePath -Pattern "buddy-companion" -Quiet)) { - Write-Host " ✓ $cliName prompt already has buddy instructions" -ForegroundColor Green + if ((Test-Path $filePath) -and (Select-String -Path $filePath -Pattern "buddy-companion v3" -Quiet)) { + Write-Host " ✓ $cliName prompt already has buddy instructions (v3)" -ForegroundColor Green return } + # Upgrade from older version: strip the old block before appending new one + if ((Test-Path $filePath) -and (Select-String -Path $filePath -Pattern "buddy-companion" -Quiet)) { + $content = Get-Content $filePath -Raw + $content = $content -replace '(?s)', '' + $content = $content.Trim() + Set-Content -Path $filePath -Value $content -Encoding UTF8 + Write-Host " ↑ $cliName prompt upgrading buddy instructions to v3" -ForegroundColor Green + } + Add-Content -Path $filePath -Value "`n$BUDDY_INSTRUCTIONS" -Encoding UTF8 Write-Host " ✓ $cliName prompt updated ($filePath)" -ForegroundColor Green } diff --git a/install.sh b/install.sh index 2570bad..56b4654 100644 --- a/install.sh +++ b/install.sh @@ -466,19 +466,25 @@ configure_codex_hooks # ── Inject buddy instructions into CLI prompt files ── -BUDDY_INSTRUCTIONS=' +BUDDY_INSTRUCTIONS=' ## Buddy Companion You have a coding companion available via the buddy MCP server. **After completing any coding task** (writing code, fixing bugs, refactoring, deploying, running tests), **automatically call `buddy_observe`** with a 1-sentence summary of what you did. This gives your companion XP and triggers a personality-flavored reaction. Do this every time — the user expects it. +**When insight mode is on**, also pass `claims`, `edges`, and `cwd` on every `buddy_observe` call: +- `claims`: 1-4 substantive assertions from the turn that just ended. Each claim needs `text` (≤240 chars), `basis` (research/empirical/deduction/analogy/definition/llm_output/assumption/vibes), `speaker` (user/assistant), `confidence` (low/medium/high), and `external_id` (e.g. c1). +- `edges`: relationships between claims — `{ from, to, type }` where type is supports/depends_on/contradicts/questions. +- `cwd`: absolute path of the current project root for workspace isolation. +Skip claims/edges if the turn had no substantive structure. Check `buddy_status` or `buddy_reasoning_status` to see if insight mode is on. + At the start of each conversation, call `buddy_status` to check on your buddy. If the user addresses the buddy by name, respond briefly in character before your normal response. After calling buddy_observe, relay the buddy'\''s reaction to the user. The first text content is an ASCII speech bubble — include it verbatim. -' +' inject_prompt() { local file="$1" @@ -488,11 +494,17 @@ inject_prompt() { mkdir -p "$dir" - if [ -f "$file" ] && grep -q "buddy-companion" "$file" 2>/dev/null; then - echo -e " ${GREEN}✓${NC} $cli_name prompt already has buddy instructions" + if [ -f "$file" ] && grep -q "buddy-companion v3" "$file" 2>/dev/null; then + echo -e " ${GREEN}✓${NC} $cli_name prompt already has buddy instructions (v3)" return 0 fi + # Upgrade from older version: strip the old block before appending new one + if [ -f "$file" ] && grep -q "buddy-companion" "$file" 2>/dev/null; then + sed -i '/'); - expect(installSh).toContain(''); - expect(installPs1).toContain(''); - expect(installPs1).toContain(''); + expect(installSh).toContain(''); + expect(installSh).toContain(''); + expect(installPs1).toContain(''); + expect(installPs1).toContain(''); }); }); diff --git a/src/lib/doctor.ts b/src/lib/doctor.ts index 8c1c09b..772aea0 100644 --- a/src/lib/doctor.ts +++ b/src/lib/doctor.ts @@ -12,8 +12,9 @@ import { levelProgress } from './leveling.js'; import { REASONING_CONFIG, telemetry } from './reasoning/index.js'; import { basisDistributionHealth } from './reasoning/telemetry.js'; -// Shared sentinel — keep in sync with install.sh / install.ps1 +// Shared sentinels — keep in sync with install.sh / install.ps1 export const PROMPT_SENTINEL_V2 = 'buddy-companion v2'; +export const PROMPT_SENTINEL_V3 = 'buddy-companion v3'; /** Default clone/build root from install.sh (INSTALL_DIR) */ export function canonicalBuddyInstallDir(): string { @@ -571,7 +572,7 @@ function checkPromptInjection(): DiagnosticCheck { for (const file of hostPromptFiles()) { const content = readTextSafe(file.path); if (!content) continue; - if (content.includes(PROMPT_SENTINEL_V2)) found.push(`${file.host} (${file.path})`); + if (content.includes(PROMPT_SENTINEL_V3) || content.includes(PROMPT_SENTINEL_V2)) found.push(`${file.host} (${file.path})`); else if (content.includes('buddy-companion')) legacy.push(`${file.host} (${file.path})`); } From 31d24139e17f51eeeb05227a5aacd37842aa0c07 Mon Sep 17 00:00:00 2001 From: terpjwu1 Date: Mon, 27 Apr 2026 11:42:20 -0400 Subject: [PATCH 2/2] fix: address Codex review feedback on v3 upgrade logic - install.sh: add safety guard to verify closing marker exists before sed range delete; falls back to single-line removal if malformed - install.ps1: tighten regex closing pattern from [^>]* to v\d+\s* Co-Authored-By: Claude Opus 4.6 (1M context) --- install.ps1 | 2 +- install.sh | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/install.ps1 b/install.ps1 index 4a79571..d570508 100644 --- a/install.ps1 +++ b/install.ps1 @@ -381,7 +381,7 @@ function Inject-BuddyPrompt($filePath, $cliName) { # Upgrade from older version: strip the old block before appending new one if ((Test-Path $filePath) -and (Select-String -Path $filePath -Pattern "buddy-companion" -Quiet)) { $content = Get-Content $filePath -Raw - $content = $content -replace '(?s)', '' + $content = $content -replace '(?s)', '' $content = $content.Trim() Set-Content -Path $filePath -Value $content -Encoding UTF8 Write-Host " ↑ $cliName prompt upgrading buddy instructions to v3" -ForegroundColor Green diff --git a/install.sh b/install.sh index 56b4654..35c002d 100644 --- a/install.sh +++ b/install.sh @@ -501,7 +501,12 @@ inject_prompt() { # Upgrade from older version: strip the old block before appending new one if [ -f "$file" ] && grep -q "buddy-companion" "$file" 2>/dev/null; then - sed -i '/