Skip to content

Commit 58acca6

Browse files
committed
fix(sidebar): KbWatcher onCreated hardcoded setupDone=true — pill flipped to ready on Enable
Root cause survived the previous isAxmeInitialized fix: that function was only used at activate time. The kb-watcher's onCreated callback (fires when .axme-code/ first appears) bypassed it entirely: this.push({ setupDone: true, ... }) // unconditional So when Enable semantic search ran 'axme-code config set context.mode search', the CLI created .axme-code/config.yaml as side effect → root watcher detected .axme-code/ creation → onCreated fired → pushed setupDone=true blindly. Pill flipped to 'ready' even though no oracle, no decisions, no memories existed. Fix: every code path that pushes setupDone now reads via isAxmeInitialized(workspaceRoot). Four sites updated: - KbWatcher onChange (poll) — recompute setupDone every tick so when the agent's first save creates oracle, pill flips immediately - KbWatcher onCreated — replaced hardcode with isAxmeInitialized() - refreshAll() — also pushes setupDone - resolveWebviewView initial push — re-reads instead of trusting initialState (which can be stale by the time webview resolves) Exported isAxmeInitialized to accept optional path so sidebar's bound workspaceRoot is canonical (was reading the global workspaceFolders[0]). Walkthrough context key axme.workspaceInitialized uses same signal — fixes Step 2 auto-completing on Enable side-effects.
1 parent 3bacaa1 commit 58acca6

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

extension/src/setup-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function workspaceRoot(): string | undefined {
2424
return folders[0].uri.fsPath;
2525
}
2626

27-
export function isAxmeInitialized(): boolean {
28-
const root = workspaceRoot();
27+
export function isAxmeInitialized(rootOverride?: string): boolean {
28+
const root = rootOverride ?? workspaceRoot();
2929
if (!root) return false;
3030
// The directory alone is NOT a setup-complete signal: enabling
3131
// semantic search runs `axme-code config set context.mode search`

extension/src/sidebar-webview.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { readHealth, HealthSnapshot } from "./health-reader.js";
2424
import { detectCurrentMode } from "./auditor-auth.js";
2525
import { hooksAreInstalled } from "./hooks-state.js";
2626
import { readContextMode, indexedCount, ContextMode } from "./search-mode.js";
27+
import { isAxmeInitialized } from "./setup-controller.js";
2728
import { log } from "./log.js";
2829

2930
/**
@@ -115,28 +116,46 @@ export class AxmeSidebarProvider implements vscode.WebviewViewProvider {
115116
// mode changes (a saved memory means a session is in-flight,
116117
// a reindex bumps indexedEntries), so we refresh all live
117118
// signals together on the watcher tick — saves wiring extra
118-
// polling timers.
119+
// polling timers. setupDone is re-checked here too because
120+
// the agent's first save during cooperative setup creates
121+
// oracle/stack.md, which is exactly the moment the pill
122+
// should flip from "setup required" to "ready".
123+
const setupDone = isAxmeInitialized(workspaceRoot);
119124
this.push({
120125
counts,
121126
backlog: readBacklog(workspaceRoot).slice(0, 5),
122127
health: readHealth(workspaceRoot),
123128
contextMode: readContextMode(workspaceRoot),
124129
indexedEntries: indexedCount(workspaceRoot),
130+
setupDone,
125131
});
132+
void vscode.commands.executeCommand(
133+
"setContext",
134+
"axme.workspaceInitialized",
135+
setupDone,
136+
);
126137
},
127138
() => {
139+
// .axme-code/ just appeared on disk. This is NOT the same as
140+
// "setup completed" — `axme-code config set context.mode search`
141+
// creates .axme-code/ as a side effect of writing config.yaml
142+
// even without any setup. Re-check the canonical signal
143+
// (isAxmeInitialized → oracle/stack.md or any D-NNN-*.md) and
144+
// flip setupDone + the walkthrough context key only when it's
145+
// really true.
146+
const setupDone = isAxmeInitialized(workspaceRoot);
128147
this.push({
129-
setupDone: true,
148+
setupDone,
130149
health: readHealth(workspaceRoot),
131150
contextMode: readContextMode(workspaceRoot),
132151
indexedEntries: indexedCount(workspaceRoot),
133152
});
134153
void vscode.commands.executeCommand(
135154
"setContext",
136155
"axme.workspaceInitialized",
137-
true,
156+
setupDone,
138157
);
139-
log("KbWatcher: .axme-code/ createdsidebar + walkthrough updated.");
158+
log(`KbWatcher: .axme-code/ appearedsetupDone=${setupDone}.`);
140159
},
141160
);
142161
}
@@ -173,6 +192,7 @@ export class AxmeSidebarProvider implements vscode.WebviewViewProvider {
173192
contextMode: readContextMode(this.workspaceRoot),
174193
indexedEntries: indexedCount(this.workspaceRoot),
175194
hooksOk: hooksAreInstalled(),
195+
setupDone: isAxmeInitialized(this.workspaceRoot),
176196
});
177197
}
178198

@@ -194,13 +214,20 @@ export class AxmeSidebarProvider implements vscode.WebviewViewProvider {
194214
const health = this.workspaceRoot ? readHealth(this.workspaceRoot) : { pendingAudits: 0 };
195215
const contextMode = this.workspaceRoot ? readContextMode(this.workspaceRoot) : "full";
196216
const indexedEntries = this.workspaceRoot ? indexedCount(this.workspaceRoot) : 0;
217+
// setupDone overrides whatever was passed in via initialState. The
218+
// initial value was computed at activate time; by the time the
219+
// webview first resolves, the user may have flipped state via
220+
// Enable semantic search (which creates .axme-code/ without doing
221+
// setup) — re-check on disk so the pill reflects truth.
222+
const setupDone = this.workspaceRoot ? isAxmeInitialized(this.workspaceRoot) : false;
197223
this.push({
198224
...this.initialState,
199225
counts,
200226
backlog,
201227
health,
202228
contextMode,
203229
indexedEntries,
230+
setupDone,
204231
hooksOk: hooksAreInstalled(),
205232
...this.pendingState,
206233
});

0 commit comments

Comments
 (0)