Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(cli): D3 flip selfHelp on 20 shadowed handlers, help engine-free
garrytanc6990839c06f
diff --git a/src/cli.ts b/src/cli.tsindex 92cbe03d5e..0abe605059 100755--- a/src/cli.ts+++ b/src/cli.ts@@ -113,7 +113,7 @@ export function normalizeLocalResult(rawResult: unknown): unknown {* test/cli-help-without-brain.serial.test.ts, which runs the CLI with an empty* GBRAIN_HOME and requires exit 0 plus real help output.*/-const SELF_HELP_WITHOUT_ENGINE: Record<string, () => Promise<(engine: never, args: string[]) => unknown>> = {+const SELF_HELP_WITHOUT_ENGINE: Record<string, true | (() => Promise<(engine: never, args: string[]) => unknown>)> = {export: async () => (await import('./commands/export.ts')).runExport as never,models: async () => (await import('./commands/models.ts')).runModels as never,watch: async () => (await import('./commands/watch.ts')).runWatch as never,@@ -146,12 +146,16 @@ const SELF_HELP_WITHOUT_ENGINE: Record<string, () => Promise<(engine: never, arg// runAgent accepts BrainEngine | null; help (incl. `register --help`) is// answered before any engine or job-queue work (cathedral-6).agent: async () => (await import('./commands/agent.ts')).runAgent as never,+ // D3: post-connect records whose handler answers --help before the engine; run through the table.+ advisor: true, anomalies: true, backfill: true, 'book-mirror': true, 'edges-backfill': true, features: true,+ founder: true, 'graph-query': true, orphans: true, salience: true, think: true,};/** Returns true when the command's own help was printed. */async function printSelfHelpWithoutEngine(command: string, args: string[]): Promise<boolean> {const load = SELF_HELP_WITHOUT_ENGINE[command];if (!load) return false;+ if (load === true) return dispatchConnectedCommand(command, null as never, args).then(() => true);const run = await load();// The engine is never read on the help path; passing a placeholder keeps the// handler signatures untouched. skillopt already declares `BrainEngine | null`diff --git a/src/cli/command-table.ts b/src/cli/command-table.tsindex 6fcbfca287..ab71bed90e 100644--- a/src/cli/command-table.ts+++ b/src/cli/command-table.ts@@ -158,7 +158,7 @@ export const CLI_COMMANDS: readonly CliCommandRecord[] = [ // Pre-connect: disp// would hide the [SHOW USER] setup contract agents depend on.{ name: 'google', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/google.ts') },{ name: 'creds', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/creds.ts') },- { name: 'remote', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/remote.ts') },+ { name: 'remote', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/remote.ts') },// selfHelp: `gbrain connect --help` prints its own usage (flags + examples) from runConnect; route// around the generic one-line short-circuit.{ name: 'connect', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/connect.ts') },@@ -185,21 +185,21 @@ export const CLI_COMMANDS: readonly CliCommandRecord[] = [ // Pre-connect: disp// selfHelp: v0.42 self-upgrade ships its own usage (flags + the agent-skill story).{ name: 'self-upgrade', phase: 'pre-connect', thinClient: 'none', selfHelp: true, skipStartupHooks: true, load: () => import('./commands/self-upgrade.ts') },{ name: 'integrations', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/integrations.ts') },- { name: 'providers', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/providers.ts') },- { name: 'resolvers', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/resolvers.ts') },- { name: 'integrity', phase: 'pre-connect', thinClient: 'refuse', load: () => import('./commands/integrity.ts') },+ { name: 'providers', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/providers.ts') },+ { name: 'resolvers', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/resolvers.ts') },+ { name: 'integrity', phase: 'pre-connect', thinClient: 'refuse', selfHelp: true, load: () => import('./commands/integrity.ts') },{ name: 'publish', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/publish.ts') },{ name: 'check-backlinks', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/check-backlinks.ts') },{ name: 'frontmatter', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/frontmatter.ts') },{ name: 'lint', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/lint.ts') },{ name: 'check-resolvable', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/check-resolvable.ts') },- { name: 'mounts', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/mounts.ts') },+ { name: 'mounts', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/mounts.ts') },{ name: 'cache', phase: 'pre-connect', thinClient: 'route-then-refuse', selfHelp: true, load: () => import('./commands/cache.ts') },- { name: 'routing-eval', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/routing-eval.ts') },- { name: 'skillify', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/skillify.ts') },+ { name: 'routing-eval', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/routing-eval.ts') },+ { name: 'skillify', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/skillify.ts') },{ name: 'skillpack', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/skillpack.ts') },{ name: 'friction', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/friction.ts') },- { name: 'claw-test', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/claw-test.ts') },+ { name: 'claw-test', phase: 'pre-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/claw-test.ts') },{ name: 'report', phase: 'pre-connect', thinClient: 'none', load: () => import('./commands/report.ts') },{ name: 'apply-migrations', phase: 'pre-connect', thinClient: 'refuse', help: () => import('./help/apply-migrations.ts'), load: () => import('./commands/apply-migrations.ts') },{ name: 'repair-jsonb', phase: 'pre-connect', thinClient: 'refuse', load: () => import('./commands/repair-jsonb.ts') },@@ -274,7 +274,7 @@ export const CLI_COMMANDS: readonly CliCommandRecord[] = [ // Pre-connect: disp// below so a brainless machine gets real help, and with the `--`-aware help scan in main() so// `agent run -- --help` submits the literal prompt instead.{ name: 'agent', phase: 'post-connect', thinClient: 'none', selfHelp: true, end_of_options: true, load: () => import('./commands/agent.ts') },- { name: 'book-mirror', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/book-mirror.ts') },+ { name: 'book-mirror', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/book-mirror.ts') },// selfHelp: v0.37 fix wave (Lane D.4 + CDX2-12): sync's --no-embed flag was unreachable via help// because the dispatcher's generic CLI-only short-circuit fired before runSync could print its own// usage block. Adding `sync` here routes `gbrain sync --help` into runSync.@@ -289,23 +289,23 @@ export const CLI_COMMANDS: readonly CliCommandRecord[] = [ // Pre-connect: disp// selfHelp: v0.41.39 (#1700) — enrich ships its own detailed HELP (ordering, budget best-effort// caveat, provenance, --reenrich-after). Route around the stub.{ name: 'enrich', phase: 'post-connect', thinClient: 'refuse', selfHelp: true, load: () => import('./commands/enrich.ts') },- { name: 'features', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/features.ts') },+ { name: 'features', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/features.ts') },{ name: 'autopilot', phase: 'post-connect', thinClient: 'none', help: () => import('./help/autopilot.ts'), load: () => import('./commands/autopilot.ts') },- { name: 'graph-query', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/graph-query.ts') },+ { name: 'graph-query', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/graph-query.ts') },{ name: 'reconcile-links', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/reconcile-links.ts') },// selfHelp: gbrain repair prints REPAIR_HELP (kinds + dry-run/apply contract).// thin client: Wave 2 repair core: repairs publish coordinated writes on the brain host.{ name: 'repair', phase: 'post-connect', thinClient: 'refuse', selfHelp: true, load: () => import('./commands/repair.ts') },- { name: 'orphans', phase: 'post-connect', thinClient: 'refuse', load: () => import('./commands/orphans.ts') },+ { name: 'orphans', phase: 'post-connect', thinClient: 'refuse', selfHelp: true, load: () => import('./commands/orphans.ts') },// selfHelp: maintain (#3015) prints its own usage block (modes + not-auto-applied list).{ name: 'maintain', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/maintain.ts') },{ name: 'reindex', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/reindex.ts') },- { name: 'salience', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/salience.ts') },- { name: 'anomalies', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/anomalies.ts') },+ { name: 'salience', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/salience.ts') },+ { name: 'anomalies', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/anomalies.ts') },{ name: 'status', phase: 'post-connect', thinClient: 'none', help: () => import('./help/status.ts'), load: () => import('./commands/status.ts') },- { name: 'advisor', phase: 'post-connect', thinClient: 'refuse', load: () => import('./commands/advisor.ts') },- { name: 'conversation-parser', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/conversation-parser.ts') },- { name: 'edges-backfill', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/edges-backfill.ts') },+ { name: 'advisor', phase: 'post-connect', thinClient: 'refuse', selfHelp: true, load: () => import('./commands/advisor.ts') },+ { name: 'conversation-parser', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/conversation-parser.ts') },+ { name: 'edges-backfill', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/edges-backfill.ts') },// CLI_ONLY: #2035 class (wired the #3502 way): `case 'whoknows'` had a live handler (runWhoknows:// ranked table, per-factor explain, thin-client routing) that was shadowed by find_experts'// non-hidden cliHints. The op hint is now hidden (ops/insights.ts); this entry makes the richer@@ -333,8 +333,8 @@ export const CLI_COMMANDS: readonly CliCommandRecord[] = [ // Pre-connect: disp// follow-up TODO.{ name: 'takes', phase: 'post-connect', thinClient: 'route-then-refuse', selfHelp: true, load: () => import('./commands/takes.ts') },{ name: 'onboard', phase: 'post-connect', thinClient: 'none', help: () => import('./help/onboard.ts'), load: () => import('./commands/onboard.ts') },- { name: 'founder', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/founder.ts') },- { name: 'think', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/think.ts') },+ { name: 'founder', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/founder.ts') },+ { name: 'think', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/think.ts') },{ name: 'recall', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/recall.ts') },// CLI_ONLY: v0.42.58 (#2035 class, caught by the handleCliOnly reachability sweep): full handler// at `case 'notability-eval'` but never dispatchable.@@ -372,7 +372,7 @@ export const CLI_COMMANDS: readonly CliCommandRecord[] = [ // Pre-connect: disp{ name: 'reindex-code', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/reindex-code.ts') },{ name: 'reindex-search-vector', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/reindex-search-vector.ts') },{ name: 'reindex-frontmatter', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/reindex-frontmatter.ts') },- { name: 'backfill', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/backfill.ts') },+ { name: 'backfill', phase: 'post-connect', thinClient: 'none', selfHelp: true, load: () => import('./commands/backfill.ts') },{ name: 'code-callers', phase: 'post-connect', thinClient: 'refuse', load: () => import('./commands/code-callers.ts') },{ name: 'code-callees', phase: 'post-connect', thinClient: 'refuse', load: () => import('./commands/code-callees.ts') },{ name: 'repos', phase: 'post-connect', thinClient: 'none', load: () => import('./commands/repos.ts') },diff --git a/src/commands/founder-scorecard.ts b/src/commands/founder-scorecard.tsindex 620cd70838..457951454d 100644--- a/src/commands/founder-scorecard.ts+++ b/src/commands/founder-scorecard.ts@@ -207,6 +207,7 @@ Examples:`;function parseArgs(args: string[]): RunOpts | { help: true } | { error: string } {+ if (args[0] === '--help' || args[0] === '-h') return { help: true };if (args[0] !== 'scorecard') {return { error: `Unknown founder subcommand: ${args[0] ?? '(none)'}. Did you mean "founder scorecard"?` };}diff --git a/src/commands/graph-query.ts b/src/commands/graph-query.tsindex 693482f8d8..b78ef31554 100644--- a/src/commands/graph-query.ts+++ b/src/commands/graph-query.ts@@ -148,7 +148,7 @@ export async function runGraphQuery(engine: BrainEngine, argv: string[]) {const args = parseArgs(argv);if (args.showHelp || !args.slug) {printHelp();- if (!args.slug) process.exit(1);+ if (!args.slug && !args.showHelp) process.exit(1);return;}diff --git a/test/cli-help-discoverability.test.ts b/test/cli-help-discoverability.test.tsindex 3063fa21db..a6d658b18d 100644--- a/test/cli-help-discoverability.test.ts+++ b/test/cli-help-discoverability.test.ts@@ -396,3 +396,35 @@ describe('`gbrain takes --help` reaches the detailed subcommand block', () => {expect(stdout).toContain('--dir <path>');});});++describe('D3: shadowed handler help and curated help are reachable', () => {+ // Each printed its own usage but was hidden behind the generic one-line+ // stub (record lacked selfHelp). One distinctive line per handler.+ const SELF_HELP_MARKERS: Record<string, string> = {+ advisor: 'gbrain advisor [--json] [--apply <finding-id>]',+ backfill: 'gbrain backfill',+ 'book-mirror': 'gbrain book-mirror',+ 'claw-test': 'gbrain claw-test',+ founder: 'Usage: gbrain founder scorecard <entity-slug>',+ 'graph-query': 'Usage: gbrain graph-query <slug>',+ mounts: 'gbrain mounts',+ think: 'Usage: gbrain think',+ };+ for (const [command, marker] of Object.entries(SELF_HELP_MARKERS)) {+ test(`\`${command} --help\` prints the handler's own usage, not the stub`, async () => {+ const { stdout, exitCode } = await help([command, '--help']);+ expect(exitCode).toBe(0);+ expect(stdout).toContain(marker);+ expect(stdout).not.toContain('run gbrain --help for the full command list');+ });+ }++ test('`doctor --help` lists the remediation flags with their consent effects', async () => {+ const { stdout, exitCode } = await help(['doctor', '--help']);+ expect(exitCode).toBe(0);+ for (const flag of ['--remediation-plan', '--remediate', '--include-repairs', '--max-usd', '--target-score', '--yes']) {+ expect(stdout).toContain(flag);+ }+ expect(stdout).toContain('[consent: destructive]');+ });+});diff --git a/test/cli-help-without-brain.serial.test.ts b/test/cli-help-without-brain.serial.test.tsindex c1200a5c80..c74bbfb2bd 100644--- a/test/cli-help-without-brain.serial.test.ts+++ b/test/cli-help-without-brain.serial.test.ts@@ -39,6 +39,13 @@ const HELP_WITHOUT_BRAIN = ['repair',// System One: the decide dispatch module prints its help before connecting.'decide',+ // D3: handlers that print their own help, once shadowed by the generic stub+ // (selfHelp flipped). Pre-connect records answer before any engine...+ 'remote', 'providers', 'resolvers', 'integrity', 'mounts', 'routing-eval', 'skillify', 'claw-test',+ // ...conversation-parser through its engine-free subcommand route, the rest+ // through SELF_HELP_WITHOUT_ENGINE's table entries.+ 'conversation-parser', 'advisor', 'anomalies', 'backfill', 'book-mirror', 'edges-backfill', 'features',+ 'founder', 'graph-query', 'orphans', 'salience', 'think',];/**diff --git a/test/fixtures/goldens/cli/membership-sets.json b/test/fixtures/goldens/cli/membership-sets.jsonindex 9f04050630..800eba59b3 100644--- a/test/fixtures/goldens/cli/membership-sets.json+++ b/test/fixtures/goldens/cli/membership-sets.json@@ -202,24 +202,31 @@"whoknows"],"CLI_ONLY_SELF_HELP": [+ "advisor","agent",+ "anomalies","auth",+ "backfill","backup","bench",+ "book-mirror","bootstrap","brainstorm","cache","capture","check-resolvable","check-update",+ "claw-test","compile-context","config","connect","connectors",+ "conversation-parser","creds","db-repair","decide","dream",+ "edges-backfill","embed","embeddings","engine",@@ -230,12 +237,16 @@"extract","extract-conversation-facts","facts",+ "features",+ "founder","friction","frontmatter","google",+ "graph-query","hook","init","integrations",+ "integrity","jobs","loops","lsd",@@ -243,19 +254,27 @@"mcp","migrate","models",+ "mounts","notices",+ "orphans","pages","pglite-repair","post-upgrade","pricing","projections","protocol",+ "providers","reindex","reinit-pglite",+ "remote","repair",+ "resolvers","retrieval-upgrade",+ "routing-eval",+ "salience","schema","self-upgrade",+ "skillify","skillopt","skillpack","skillpack-check",@@ -264,6 +283,7 @@"sweep","sync","takes",+ "think","transcripts","upgrade","waiting",@@ -271,19 +291,30 @@"whoknows"],"SELF_HELP_WITHOUT_ENGINE": [+ "advisor","agent",+ "anomalies",+ "backfill",+ "book-mirror","compile-context","connectors","dream",+ "edges-backfill","export","extract-conversation-facts",+ "features",+ "founder",+ "graph-query","jobs","loops","maintain","models",+ "orphans","repair",+ "salience","skillopt","sources",+ "think","transcripts","waiting","watch"