mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-14 00:48:18 +00:00
* feat(bootstrap): TTY DX exploration harness + Krug onboarding fix wave Add a real-PTY exploration harness and land 16 verified "Don't Make Me Think" fixes on the paste-in install experience for Claude Code and Codex. Harness: - test/helpers/tty-harness.ts — spawns any CLI (gbrain/claude/codex) under a real pseudo-terminal (Bun terminal: spawn), timestamps every output burst, and turns silence windows into a measurable stall report. Hermetic; pure helpers unit-tested in test/tty-harness.test.ts. - scripts/dx-explore.ts — drives the fresh-user funnel (help / init / real claude-install / real codex-install / manual drive mode), writing transcripts to .context/dx-runs/ (gitignored). Fixes (all adversarially verified against the code first): - Keyless bare `gbrain init` completes in keyless mode instead of exit 1; multi-key non-TTY auto-picks the canonical default; typo stays fail-loud. - Provider picker probe-gates ollama (daemon-up != model-pulled) and offers an explicit "continue keyless" option that is the bare-Enter default. - Fresh-brain init prints one schema-setup line instead of ~240 migration names (GBRAIN_MIGRATE_VERBOSE=1 restores detail). - Init epilogue: memory-verbs funnel is last-on-screen; skills advisory compacted for init; Mod Status trimmed. - PGLite live-serve lock error names the fix (close the agent session). - Mode-picker banner interpolates the applied mode; expansion-key gate is Anthropic/OpenAI/Google, not OpenAI-only. - Missing `claude` binary skips MCP but still installs hooks; honest copy. - Foreign MCP-registration removal targets the conflicting scope and fails loud if it does not land. - Upgrade marker compares the running binary to latest and self-spawns via execPath, so a current/newer binary no longer nags from a stale cache. - interview --set/--skip after --confirm warns it voided the confirmation. - init --help matches behavior; init --supabase fails loud on non-TTY. - Provider capabilities attributed per provider across README / runbook / questions bank / bootstrap.md. - First-run tour: restart-first, prompt 3 true on day one, withheld on FAIL; README gives Codex the same scripted magic moment. - Empty-brain "0 takes" onboard nudge suppressed. - Broken settings.local.json aborts the hooks write fail-closed instead of silently dropping the user's permissions. Regenerated cli-flag-registry.generated.ts and llms-full.txt. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(bootstrap): second DX polish wave — clean the success screen + honest copy (F17-F21) Follow-up to the DX fix wave, closing the top-5 remaining gaps the scorecard flagged (all human-facing polish, not survival): F17 — machine markers no longer leak to humans: - verify report drops the `[D3.6]` plan-tag from the first_run_tour detail. - the raw `UPGRADE_AVAILABLE <cur> <latest>` marker line prints ONLY on a non-TTY stderr (parsers still get it); an interactive human sees just the "gbrain X -> Y available" sentence. - per-migration "what changed" notices (v123/v124, incl. the #2704 ref) are suppressed on a FRESH-install replay via a module quiet flag; upgrades still narrate. (GBRAIN_MIGRATE_VERBOSE=1 restores them.) F18 — one obvious next action on the init success screen: the memory-verbs demo is the single "→ Do this next" hero, last on screen; import/migrate/doctor collapse into one terse "More:" footer; the graph block only shows for a non-empty brain. F19 — README "moment it clicks" is now the genuine cross-session brain round-trip (remember → restart → recall), explicitly distinguished from the identity-file recall, on both the Codex and Claude Code paths. F20 — the compact init skills advisory is human-voiced (no `[AGENT]` stage-direction on the human-facing success screen; the mode-picker's agent-directed block stays gated to the non-TTY channel). F21 — time promise reconciled: headline is ~15 min (personal-agent path) / ~30 min (always-on OpenClaw/Hermes); the runbook's search-mode line no longer claims "balanced" when keyless applies "conservative". README hooks copy says "on by default, with an opt-out" to match the runbook. Regenerated llms-full.txt. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(bootstrap): address two-model adversarial review of the DX wave Fixes the regressions the 5-specialist + red-team + Claude/Codex adversarial pass found in the F1–F21 changes, each with a test: - Keyless upgrade hint pointed at `config set embedding_model`, which config.ts hard-refuses as a schema-sizing no-op — now names the working re-init recipe (`gbrain init --force --pglite --embedding-model <id>`), zero-key AND multi-key paths. - Multi-key TTY picker offered "continue keyless" but the caller aborted on it — now honors keyless like the zero-key path. - Detached update-refresh spawn used a `/gbrain$/` basename check that misfires for a renamed/official-named compiled binary (`gbrain-darwin-arm64`) and prepends the /$bunfs entrypoint — now detects dev-vs-compiled by the runtime basename (bun|node) so the refresh always runs. - `bootstrap status` reported the wire phase "done" on a hooks-only receipt (host CLI missing at wire time) — now "partial" with a re-run hint, so a resuming agent doesn't trust a false complete. - Post-repair MCP mismatch re-verifies and aborts instead of blessing a registration a racing writer may have re-claimed. - probeOpenAICompat's abort timer now spans the body read (was cleared before it), so a stalled `/v1/models` body can't hang init past the 1s cap. - Centralized the 4-copy stale-cache upgrade predicate into `pendingUpgradeVersion`; UPGRADE_AVAILABLE gains a GBRAIN_FORCE_UPGRADE_MARKER override for PTY-based agent harnesses. - Mode picker's expansion-key gate adds GEMINI_API_KEY; picker prompt is article-aware ("an embedding" / "a chat"); dead `!brainEmpty` clause removed; migrate.ts try/finally widened + stamp failures named in quiet mode. - DX harness: credential copies scrubbed even on SIGINT/interrupt (+chmod 600), child process TREE reaped on teardown, advisory made fail-open, KEY_MAP typed as a literal union. New tests: migrate quiet-replay, self-upgrade pending predicate + negative cache cases, bootstrap 127/scoped-remove/broken-settings dispatch, interview invalidation flag, verify tour-withheld-on-FAIL, init keyless/supabase/multi-key, init-nudge branches, ai-probes model parsing. Regenerated flag registry + template-repo. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * v0.45.8.0 fix(bootstrap): onboarding DX polish wave (F17-F21) + review fixes DX fix wave on the paste-in install/first-run experience for Claude Code and Codex, driven by a new real-PTY exploration harness. Keyless init completes instead of erroring, the migration wall collapses to one line, the success screen leads with one action, and the "magic moment" copy points at the genuine cross-session round-trip. Full detail in CHANGELOG. Version trio + openclaw manifest + runbook stamp bumped to 0.45.8.0; CHANGELOG release entry; TODOS onboarding-DX follow-ups filed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(bootstrap): OOBE hand-off — you own the brain, cold-start is skill #1 A working install now ends by making the two facts that matter actually land: - `gbrain bootstrap verify` prints (and returns as `handoff` in --json) an ownership block — the actual private-repo URL with what owning it means (read it, `gbrain bootstrap attach` on machine two, delete it and the brain is gone), or the local-only variant pointing at `gbrain bootstrap repo` — followed by the ONE next action: run the cold-start skill (Gmail/calendar/ contacts via ClawVisor, an OAuth vault so the agent never holds raw tokens; or offline archives), one consented phase at a time. Withheld on FAIL like the tour; shape stays unconditional for machine consumers. - cold-start ships in the downstream bundle (61 skills): its plugin exclusion ("host onboarding flow") predated the v0.45 personal-agent bootstrap and is deliberately reversed — the paste-in audience is exactly who day-one onboarding is for. It now LEADS the recommended set (ahead of book-mirror: every flagship skill only becomes magical once the brain holds the user's real life). - New drift guard: every recommended slug must be scaffoldable from the plugin bundle — recommended-but-unscaffoldable is a dead-end CTA and now fails the suite. - Runbook Hand off rewritten around the two must-land facts + the on-the-spot cold-start offer; README's Codex and Claude Code paths carry the same two follow-ups. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * v0.45.10.0 feat(bootstrap): the OOBE hand-off release Version trio + runbook stamp + template tree to 0.45.10.0; CHANGELOG entry; llms bundles regenerated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(ci): stop memory-verbs-conformance leaking a fake-keyed gateway into shard-mates The deterministic-embedder helper configures the MODULE-GLOBAL gateway with a fake OpenAI key; the file's afterAll never reset it. The bunfig preload's per-test restore only fires when the gateway is UNCONFIGURED, so the fake-keyed config persisted for every later file in the shard process — turn-context's corpus writes then embedded against real OpenAI and 401'd (CI shard-8 failure; shard re-binning from this branch's new test files exposed it). Fix both sides: conformance's afterAll now resetGateway()s back to the preload baseline and nulls both test transports; turn-context's beforeAll does the same defensively so it stays hermetic regardless of shard composition. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
313 lines
10 KiB
TypeScript
313 lines
10 KiB
TypeScript
/**
|
|
* Tests for src/core/skillpack/post-install-advisory.ts (v0.25.1).
|
|
*
|
|
* The advisory is meant to be read by the agent (openclaw, claude-code)
|
|
* from the terminal output of `gbrain init` and `gbrain post-upgrade`.
|
|
* These tests pin:
|
|
* - empty/no-workspace path renders a workspace-detection note
|
|
* - all-installed path returns null (no-op)
|
|
* - partial-install path lists ONLY the missing skills
|
|
* - the rendered text contains the explicit "ASK THE USER FIRST"
|
|
* framing so future changes to the prose can't accidentally
|
|
* drop the user-sovereignty contract
|
|
*/
|
|
|
|
import { describe, expect, it, afterEach } from 'bun:test';
|
|
import {
|
|
existsSync,
|
|
mkdirSync,
|
|
mkdtempSync,
|
|
rmSync,
|
|
writeFileSync,
|
|
} from 'fs';
|
|
import { join } from 'path';
|
|
import { tmpdir } from 'os';
|
|
import {
|
|
buildAdvisory,
|
|
detectInstalledSlugs,
|
|
printAdvisoryIfRecommended,
|
|
} from '../src/core/skillpack/post-install-advisory.ts';
|
|
import { currentRecommendedSet } from '../src/core/advisor/recommended-set.ts';
|
|
|
|
const cleanup: string[] = [];
|
|
|
|
afterEach(() => {
|
|
while (cleanup.length) {
|
|
const d = cleanup.pop();
|
|
if (d && existsSync(d)) rmSync(d, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
function scratchWorkspace(receiptSlugs: string[] | null): {
|
|
workspace: string;
|
|
skillsDir: string;
|
|
} {
|
|
const workspace = mkdtempSync(join(tmpdir(), 'advisory-test-'));
|
|
cleanup.push(workspace);
|
|
const skillsDir = join(workspace, 'skills');
|
|
mkdirSync(skillsDir, { recursive: true });
|
|
|
|
if (receiptSlugs === null) {
|
|
writeFileSync(
|
|
join(skillsDir, 'RESOLVER.md'),
|
|
'# RESOLVER\n\n| Trigger | Skill |\n|---------|-------|\n',
|
|
);
|
|
} else {
|
|
const slugList = receiptSlugs.sort().join(',');
|
|
const block = [
|
|
'# RESOLVER',
|
|
'',
|
|
'| Trigger | Skill |',
|
|
'|---------|-------|',
|
|
'',
|
|
'<!-- gbrain:skillpack:begin -->',
|
|
`<!-- gbrain:skillpack:manifest cumulative-slugs="${slugList}" version="0.25.1" -->`,
|
|
...receiptSlugs.map(
|
|
(s) => `| "${s}" | \`skills/${s}/SKILL.md\` |`,
|
|
),
|
|
'<!-- gbrain:skillpack:end -->',
|
|
'',
|
|
].join('\n');
|
|
writeFileSync(join(skillsDir, 'RESOLVER.md'), block);
|
|
}
|
|
|
|
return { workspace, skillsDir };
|
|
}
|
|
|
|
describe('detectInstalledSlugs', () => {
|
|
it('returns empty set when no managed block', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace(null);
|
|
expect(detectInstalledSlugs(skillsDir, workspace).size).toBe(0);
|
|
});
|
|
|
|
it('reads cumulative-slugs receipt', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([
|
|
'brain-ops',
|
|
'idea-ingest',
|
|
]);
|
|
const set = detectInstalledSlugs(skillsDir, workspace);
|
|
expect(set.has('brain-ops')).toBe(true);
|
|
expect(set.has('idea-ingest')).toBe(true);
|
|
expect(set.size).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe('recommended set — OOBE invariants', () => {
|
|
it('cold-start is the FIRST recommendation (the day-one "now what?" answer)', () => {
|
|
// The compact init advisory previews the first slugs and `gbrain advisor`
|
|
// ranks by list order — cold-start leads because every other recommended
|
|
// skill only becomes magical once the brain holds the user's real life.
|
|
expect(currentRecommendedSet()[0]!.slug).toBe('cold-start');
|
|
});
|
|
});
|
|
|
|
describe('buildAdvisory — partial-install path', () => {
|
|
it('lists ONLY missing skills when most are already installed', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([
|
|
'brain-ops',
|
|
'cold-start',
|
|
'article-enrichment',
|
|
'strategic-reading',
|
|
'concept-synthesis',
|
|
'perplexity-research',
|
|
'archive-crawler',
|
|
'academic-verify',
|
|
'brain-pdf',
|
|
'voice-note-ingest',
|
|
]);
|
|
const advisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'upgrade',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
});
|
|
expect(advisory).not.toBeNull();
|
|
expect(advisory).toContain('book-mirror');
|
|
expect(advisory).not.toContain('article-enrichment');
|
|
expect(advisory).not.toContain('strategic-reading');
|
|
expect(advisory).toContain('gbrain skillpack scaffold book-mirror');
|
|
});
|
|
|
|
it('uses --all command when ALL recommended are missing (fresh workspace)', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([]);
|
|
const advisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
});
|
|
expect(advisory).not.toBeNull();
|
|
expect(advisory).toContain('gbrain skillpack scaffold --all');
|
|
expect(advisory).toContain('book-mirror');
|
|
expect(advisory).toContain('article-enrichment');
|
|
expect(advisory).toContain('strategic-reading');
|
|
});
|
|
});
|
|
|
|
describe('buildAdvisory — all-installed → null (no nag)', () => {
|
|
it('returns null when every recommended skill is already installed', () => {
|
|
const allRecommended = [
|
|
'cold-start',
|
|
'book-mirror',
|
|
'article-enrichment',
|
|
'strategic-reading',
|
|
'concept-synthesis',
|
|
'perplexity-research',
|
|
'archive-crawler',
|
|
'academic-verify',
|
|
'brain-pdf',
|
|
'voice-note-ingest',
|
|
];
|
|
const { workspace, skillsDir } = scratchWorkspace(allRecommended);
|
|
const advisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'upgrade',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
});
|
|
expect(advisory).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('buildAdvisory — agent-readable framing', () => {
|
|
it('contains the user-sovereignty contract phrasing', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([]);
|
|
const advisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
})!;
|
|
expect(advisory).toContain('ACTION FOR THE AGENT');
|
|
expect(advisory).toContain('Ask the user');
|
|
expect(advisory).toContain('Do NOT scaffold without asking');
|
|
expect(advisory).toContain('user owns this decision');
|
|
});
|
|
|
|
it('names the version + context (init vs upgrade)', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([]);
|
|
const initAdvisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
})!;
|
|
const upgradeAdvisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'upgrade',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
})!;
|
|
expect(initAdvisory).toContain('0.25.1');
|
|
expect(initAdvisory).toContain('installed');
|
|
expect(upgradeAdvisory).toContain('0.25.1');
|
|
expect(upgradeAdvisory).toContain('upgraded to');
|
|
});
|
|
|
|
it('describes each skill with a one-line value prop', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([]);
|
|
const advisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
})!;
|
|
expect(advisory).toContain('FLAGSHIP');
|
|
expect(advisory).toContain('two-column');
|
|
expect(advisory).toContain('verbatim');
|
|
expect(advisory).toContain('Brain-augmented web research');
|
|
});
|
|
|
|
it('shows the exact install command per the missing-set', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([]);
|
|
const advisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
})!;
|
|
expect(advisory).toContain('gbrain skillpack scaffold --all');
|
|
expect(advisory).toContain('ACTION FOR THE AGENT');
|
|
});
|
|
});
|
|
|
|
describe('printAdvisoryIfRecommended — compact init pointer vs full upgrade banner', () => {
|
|
function captureStderr(fn: () => void): string {
|
|
const orig = process.stderr.write;
|
|
let out = '';
|
|
process.stderr.write = ((chunk: unknown) => {
|
|
out += String(chunk);
|
|
return true;
|
|
}) as typeof process.stderr.write;
|
|
try {
|
|
fn();
|
|
} finally {
|
|
process.stderr.write = orig;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
it('context init with all skills missing prints the compact human-voiced pointer', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([]);
|
|
const out = captureStderr(() =>
|
|
printAdvisoryIfRecommended({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
}),
|
|
);
|
|
const names = currentRecommendedSet().map((s) => s.slug);
|
|
expect(out).toContain('recommended skill(s) not installed yet');
|
|
// Preview truncates at 4 slugs + ellipsis; the 5th slug never appears
|
|
// (the scaffold command is --all when everything is missing).
|
|
expect(out).toContain(`(${names.slice(0, 4).join(', ')}, …)`);
|
|
expect(out).not.toContain(names[4]);
|
|
expect(out).toContain('gbrain advisor');
|
|
// The compact init pointer is human-voiced — no agent stage directions.
|
|
expect(out).not.toContain('ACTION FOR THE AGENT');
|
|
expect(out).not.toContain('[AGENT]');
|
|
});
|
|
|
|
it('context init with everything installed prints NOTHING', () => {
|
|
const allSlugs = currentRecommendedSet().map((s) => s.slug);
|
|
const { workspace, skillsDir } = scratchWorkspace(allSlugs);
|
|
const out = captureStderr(() =>
|
|
printAdvisoryIfRecommended({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
}),
|
|
);
|
|
expect(out).toBe('');
|
|
});
|
|
|
|
it('context upgrade with missing skills keeps the full agent-addressed banner', () => {
|
|
const { workspace, skillsDir } = scratchWorkspace([]);
|
|
const out = captureStderr(() =>
|
|
printAdvisoryIfRecommended({
|
|
version: '0.25.1',
|
|
context: 'upgrade',
|
|
targetWorkspace: workspace,
|
|
targetSkillsDir: skillsDir,
|
|
}),
|
|
);
|
|
expect(out).toContain('ACTION FOR THE AGENT');
|
|
});
|
|
});
|
|
|
|
describe('buildAdvisory — no workspace detected', () => {
|
|
it('still renders an advisory with a workspace-detection note', () => {
|
|
const advisory = buildAdvisory({
|
|
version: '0.25.1',
|
|
context: 'init',
|
|
targetWorkspace: '/non/existent/workspace-xyz-' + Math.random().toString(36).slice(2),
|
|
targetSkillsDir: '/non/existent/skills-xyz-' + Math.random().toString(36).slice(2),
|
|
});
|
|
expect(advisory).not.toBeNull();
|
|
// No workspace -> empty installed set -> all recommended treated as missing.
|
|
expect(advisory).toContain('gbrain skillpack scaffold --all');
|
|
});
|
|
});
|