Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

chore(guards): keep init.ts and runPublish under their ratchets; regenerate skills lock and structural manifest

garrytan5deb1f167349
diff --git a/scripts/function-size-baseline.tsv b/scripts/function-size-baseline.tsv
index a7ec836d9a..9ab87a68fb 100644
--- a/scripts/function-size-baseline.tsv
+++ b/scripts/function-size-baseline.tsv
@@ -24,7 +24,6 @@ src/commands/mcp-expose.ts runPublish 443 seed: W5 baseline, refactor wave 1 (de
src/commands/migrate-engine.ts runMigrateEngine 405 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/serve.ts installStdioLifecycle 315 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/commands/sources.ts runAdd 365 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 fix wave 4 #5673: connector sources print that autopilot keeps them synced after the first sync
-src/commands/upgrade.ts runPostUpgrade 302 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/ai/gateway.ts chat 311 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/bootstrap/harness.ts applyHarness 1167 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/brainstorm/orchestrator.ts _runBrainstormInner 413 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +1 #5890 close-set spreads INTERNAL_BREADTH_SEARCH_OPTS
diff --git a/scripts/module-size-limits.tsv b/scripts/module-size-limits.tsv
index fbe3553896..537d49d3e2 100644
--- a/scripts/module-size-limits.tsv
+++ b/scripts/module-size-limits.tsv
@@ -25,7 +25,7 @@ src/core/postgres-engine.ts 2914 ratchet +1 System One v1 evals: search arms cla
src/core/search/hybrid.ts 1584 ratchet +2 System One v1: HybridSearchOpts.decide (search/decide-stage.ts); refactor wave 1 split target (W4 hybrid, cut line); ceiling rationale: docs/architecture/key-files/core-search-1.md entry for src/core/search/hybrid.ts; +10 #5691: per-request embedding_query_prefix read once and threaded to the embeds and cache key
src/core/types.ts 2123 ratchet +5 System One v1 retrieval lane: SearchResult injection_p/injection_suspected, HybridSearchMeta answerability, egress_denied degraded reason; +4 System One v1: SearchResult rerank_score_kind/decide_evidence, HybridSearchMeta decide/rerank; +3 wave review: PAGE_SORT_SQL.updated_asc source_id + id tiebreakers (total order under federated scopes); +5 #4881: OntologyReadOpts extends PageReadScope doc; +3 #4857: PAGE_SORT_SQL.slug total-order tiebreaker comment; grown v0.46.26.0 megawave: EvidenceOpts, pacing/usage result fields, PageFilters growth (#4352 #4218); wave-k: +9 SalienceOpts/AnomaliesOpts source scope (#3867); +20 2026-09 adversarial batch 2: keyword_relaxed_carried stage + relaxed_dropped meta field docs; +16 2026-09 fix wave: SearchResult.keyword_relaxed field + full fusion-demotion doc; (#3867); +9: #4648 rerank_passthrough degraded stage + empty_result_set/malformed_shape reasons | merged v0.48.1.0 true-up; +master v0.48 merge true-up (reranker succession: no_key preflight, reranker_skipped stage, readiness); corrective release: shared internal PageReadScope and PageReadPolicy; ranker wave v0.48.4.0: HybridSearchMeta relational_rerank_pin / keyword_arm_confidence / metadata_boost_gate + SearchResult.relational_pinned (+48 over master's peel); +12: #4681 Page.updated_at_iso + keyset cursor precision docs; #5105: canonical page state shared module and transaction/snapshot delegates; #5105: public page revision fields; upstream integration: preserve independently reviewed master additions with branch facade extraction; #5252 wave: typed vector pool and readiness metadata; merged company ingestion/schema routing changes; retired provider integration removed; +1 write-path wave: 'created' effective-date source; +3 read-path wave: rerank_failed degraded stage + budget reason (closed vocabularies) and its recall classification note; +8 fw3-search: SearchOpts.source_boosts + keyword_arm_failed/title_arm_failed stages; +2 wave-2 W4: ChunkInput.embedding_input_hash (#5553); fix wave 3 x fix wave 2 (v0.60.5.0) composition: +2 at the merge; evidence delivery: optional SearchResult.delivered (+2; shape in search/evidence-delivery.ts); +2 eval wave N1-3: OntologyReadOpts.visibility (remote world-only ontology reads); +4 #5827: GraphNode.source_id and GraphPath from_source_id/to_source_id; +2 #5824: SearchOpts.vectorLegacyGuard rollback switch; +7 #5154: PageFilters.listColumnsOnly (interface field); +11 Foundations 1 F1b: WriteAttributionView + AttributedPageVersion (get_versions / get_write_attribution read shapes)
src/core/minions/queue.ts 2522 ratchet grown #4078 + megawave probe-liveness unlatch (#4310) + master private-queue lifecycle: recovery classifier + monotonic lease; security: durable queued authority and confined filesystem dispatch; master integration: grown #4078 + megawave probe-liveness unlatch (#4310) + master private-queue lifecycle: recovery classifier + monotonic lease; harness support: boundary wiring to shared grants, isolated setup, withdrawal and delegated guards; merged v0.49: durable authority and delegated admission both enforced; typed readiness, configuration-blocked lifecycle and bounded release; +9: prune archives completed dream synthesis keys
-src/commands/init.ts 1883 ratchet grown v0.46.x keyless capability notices; grown db-availability loop: initPostgresCore typed-failure extraction + --prefer-postgres ladder hook + pgvector rethrow fix; +1 at megawave/wave-k merge; +master-merge true-up; wave-k: merge; #3753 --force re-init engine-preservation guard; +1 wave-k merge-union brace (--prefer-postgres close); +10 ambient-writeback WP8: runWritebackNudge consent ask in both engine epilogues (logic lives in core/onboard/writeback-nudge.ts); +4: v0.48.2 reranker readiness at init + test seam; +1: v0.48.2 provider normalization; +3: v0.48.2 review fixes; master integration: +2: preserve typed PGLite busy errors in schema-only init; shared-skills integration on company-ingestion base; retired provider integration removed; retain stored-vector identity on re-init
+src/commands/init.ts 1869 ratchet grown v0.46.x keyless capability notices; grown db-availability loop: initPostgresCore typed-failure extraction + --prefer-postgres ladder hook + pgvector rethrow fix; +1 at megawave/wave-k merge; +master-merge true-up; wave-k: merge; #3753 --force re-init engine-preservation guard; +1 wave-k merge-union brace (--prefer-postgres close); +10 ambient-writeback WP8: runWritebackNudge consent ask in both engine epilogues (logic lives in core/onboard/writeback-nudge.ts); +4: v0.48.2 reranker readiness at init + test seam; +1: v0.48.2 provider normalization; +3: v0.48.2 review fixes; master integration: +2: preserve typed PGLite busy errors in schema-only init; shared-skills integration on company-ingestion base; retired provider integration removed; retain stored-vector identity on re-init; -14: first-run bundle + quickstart registration helpers live in init-first-run.ts (writeback/skills asks folded into the bundle)
src/commands/integrations.ts 1739 ratchet grown v0.46.26.0 megawave (#4039 connector compat) + 1 nosemgrep dataflow annotation (path-traversal audit); wave-k: exported heartbeatPath seam (#3900)
src/core/minions/handlers/subagent.ts 1918 ratchet merged: master v131 settle rework + dream-wave C5 peel + C6 accounting + C7 lease heartbeats/lost-lease aborts + C9 oneshot dispatch + adversarial fix batches; grown by #4078 subagent-loop capability fix; +6 lines (reasoning-item replay: adaptContentBlocksToChatBlocks handles 'reasoning' blocks); +3 wave G #4514: Anthropic-via-OpenRouter allowed on the subagent loop; +36 lines (code review, same PR): isPromptTooLongError walks a bounded .cause chain so it still matches post-normalizeAIError() wrapping, plus extractPromptTooLongDetail so the dead-lettered job's error carries the matched provider detail instead of the generic normalizeAIError() wrapper text; master integration: harness support: boundary wiring to shared grants, isolated setup, withdrawal and delegated guards; #5105: +13 call-site wiring to shared tool-write-identity helper across fresh and replay dispatch
src/commands/bootstrap.ts 2142 ratchet grandfathered at merge (grew past the 1500 cap on master); raised for #4066 HOME_WORKSPACE_GUARD_EXEMPT (status/uninstall/harness); +5 for the harnessDetect test seam (bulk lives in core/bootstrap/harness.ts); +23 for the contract subcommand dispatcher glue (#4105 absorb — bulk lives in core/bootstrap/contract.ts); +codex hooks-consent gate + mcp+hooks receipt registration + uninstall arm; +42 ambient-writeback WP8: interview-time SURFACE_MULTIUSER audience apply (pre-init ordering) + applyDeclaredAudienceFromInterview; +3 #4897 harness usage clause documenting --source ID semantics; +5 #5878: --refresh-skills dispatch and usage lines (logic in core/bootstrap/harness-skills.ts); +11 #5488: SUBCOMMAND_HELP harness entry (gate on --help / -h / help) — CLI help line, cannot move; +11 #4618 seat: --seat/--no-seat help lines and the runHooks parse (parse + notes live in core/bootstrap/hooks.ts parseSeatFlags)
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 27672b5538..d2d318e7e6 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -335,7 +335,6 @@ test/think-save-source.test.ts #5426 think --save persists into the think source
test/timing-safe.test.ts extraction contract 1 source-surface-helper
test/title-fuzzy-index.test.ts findByTitleFuzzy indexed threshold 2 source-surface-helper
test/transcription-injection.test.ts transcription — command injection (#245) 2 readFileSync
-test/upgrade-skill-publish-prompt-race.test.ts gbrain upgrade — skill-publish prompt wiring (#4318 residual) 3 readFileSync
test/upgrade.serial.test.ts detectInstallMethod — package-install classification (in-process) 4 readFileSync
test/upgrade.serial.test.ts runUpgrade target verification (#4366) 8 readFileSync
test/v0_37_fix_wave.serial.test.ts v0.37 Lane A — defaults sweep 8 source-surface-helper
diff --git a/skills/skills.lock.json b/skills/skills.lock.json
index c31f2ed92c..bb5581fb92 100644
--- a/skills/skills.lock.json
+++ b/skills/skills.lock.json
@@ -92,7 +92,7 @@
"idea-lineage/SKILL.md": "3432a9cca1626c7876eb12d7ec0d6cc37feeb8f3c18cf99f08028ef3174ae0e0",
"idea-lineage/routing-eval.jsonl": "ee2e00704b9accb7dd58bb8f126a3bc04a2c40be499180fa505dbf6d5061cd41",
"ingest/SKILL.md": "c11d2a032932bbbe1122be9bbeaea0bf32be3a44cb28164fcb22011a7ed55e0f",
- "maintain/SKILL.md": "4034f43163ec7a4cfd1d3bb27f1089bab478e06726f2c6f40a8a1cf82d0a01e1",
+ "maintain/SKILL.md": "5613fa8339d8760613851ae3c2b5d09cb96102177b0aa22cc147749b330f22a8",
"manifest.json": "357aa185d380f0a357cb15cd513317e290cbc5fcf5ca4e3860b0e829fdcbf1e4",
"mcp-access/SKILL.md": "d308714208f457a9853fec4e83fe035dcd911bc8e506cefec817bd218f3340df",
"measure-before-you-fix/SKILL.md": "ec55bac9b8b052b854c828a4b60ec37108ecc21c8d2dcede266181026b191c2d",
@@ -151,7 +151,7 @@
"migrations/v0.59.0.0.md": "7903e547e79ad3429a393d9102a610e2674388bfaa71607431b1cd857b4af939",
"migrations/v0.59.10.0.md": "e0268a05ab184d5518f88747313e772629b2af91db59eacbba728f2ebd9db3cd",
"migrations/v0.59.2.0.md": "b6d61af8ef48c154a26e8d427dd6f6570e99efb82b891728426046eea493247b",
- "migrations/v0.60.11.0.md": "ad3086df4eceff272f08bf16d674be404b97963292729b280f44268c583f77c5",
+ "migrations/v0.60.11.0.md": "7de96c359c693e4a73c9fcae3a8b85a27968cd492c7564f413c461e192e7370f",
"migrations/v0.60.20.0.md": "9266863a9f76164c64a72b1be17b8ddb3bb97e1c3c5db9f666b69ebc7a228fdd",
"migrations/v0.60.26.0.md": "30d761ef5a2361bad66053f97b7b659304a591274be33e281f4f6df0d7d5566e",
"migrations/v0.60.27.0.md": "1c3ac6a23ccfce8ad299457799b02958f7d21fcd967c471634f73bdb66f2b603",
diff --git a/src/cli/help/doctor.ts b/src/cli/help/doctor.ts
index a1100a7415..2d23ad018f 100644
--- a/src/cli/help/doctor.ts
+++ b/src/cli/help/doctor.ts
@@ -40,7 +40,6 @@ export const help: CliHelpSpec = {
'gbrain doctor --json',
'gbrain doctor --only harness_wiring --json',
'gbrain doctor --remediation-plan --json',
- 'gbrain doctor --remediate --yes --max-usd 5 --target-score 90',
'gbrain doctor --remediate --yes --include-repairs --expect <plan_hash> --max-usd 5',
],
};
diff --git a/src/commands/init-first-run.ts b/src/commands/init-first-run.ts
index 4323cb0daa..1158ce7e33 100644
--- a/src/commands/init-first-run.ts
+++ b/src/commands/init-first-run.ts
@@ -14,9 +14,11 @@
* init's separate writeback ask and skills pointer. Extend
* `buildInitFirstRunNotices` rather than adding a second notice.
*/
-import type { Decision, Notice } from '../core/agent-output.ts';
-import type { GBrainConfig } from '../core/config.ts';
-import { configReadiness } from '../core/readiness.ts';
+import { cliRenderContext, renderNotice, shellQuote, type Decision, type Notice } from '../core/agent-output.ts';
+import { loadConfig, type GBrainConfig } from '../core/config.ts';
+import type { BrainEngine } from '../core/engine.ts';
+import { resolveGbrainBin } from '../core/gbrain-bin.ts';
+import { configReadiness, harnessWiringEntry } from '../core/readiness.ts';
import type { SearchMode } from '../core/search/mode.ts';
export interface InitFirstRunInputs {
@@ -110,3 +112,30 @@ export function buildInitFirstRunNotices(inputs: InitFirstRunInputs): Notice[] {
decisions,
}];
}
+
+/** init's bundle for this brain: reads the writeback gate and the agent workspace's missing skills. */
+export async function firstRunBundle(engine: BrainEngine, searchMode: { mode: SearchMode; reason: string } | undefined): Promise<Notice[]> {
+ const { writebackAskApplies } = await import('../core/onboard/writeback-nudge.ts');
+ const { initSkillsScaffold } = await import('../core/skillpack/post-install-advisory.ts');
+ return buildInitFirstRunNotices({ searchMode, config: loadConfig(), writeback: await writebackAskApplies(engine), skillsScaffold: initSkillsScaffold() });
+}
+
+/** D2/G5: the bundle rendered into init's --json document (`notices`, empty → omitted). */
+export function firstRunJson(bundle: Notice[]): { notices?: unknown[]; contract_version: 1 } {
+ const notices = bundle.map(n => renderNotice(n, cliRenderContext()));
+ return { ...(notices.length ? { notices } : {}), contract_version: 1 };
+}
+
+/**
+ * The harness registration line for init's quickstart: the readiness
+ * `harness_wiring` fix (absolute binary, `--surface verbs`) for the detected
+ * harness, else the Claude Code registration built the same way. Null when
+ * the gbrain binary has no absolute path (never registered bare).
+ */
+export function harnessRegistrationCommand(): string | null {
+ const cfg = loadConfig();
+ const detected = cfg ? configReadiness(cfg, { transport: 'cli' }).entries.find(e => e.capability === 'harness_wiring')?.fix : undefined;
+ if (detected?.argv) return shellQuote(detected.argv);
+ const claude = harnessWiringEntry({ transport: 'cli', harnesses: ['claude-code'], lockOwner: null, gbrainBin: resolveGbrainBin() }).fix;
+ return claude?.argv ? shellQuote(claude.argv) : null;
+}
diff --git a/src/commands/init.ts b/src/commands/init.ts
index 3cf1f9e677..eb300b7698 100644
--- a/src/commands/init.ts
+++ b/src/commands/init.ts
@@ -17,11 +17,8 @@ import { resolveSourceId } from '../core/source-resolver.ts';
import type { BrainEngine } from '../core/engine.ts';
import { readPrimaryEmbeddingStores, readStoredEmbeddingIdentity } from '../core/stored-embedding-identity.ts';
import { deferInitJsonError, flushInitJsonResult, initJsonError, setInitJsonResult, writeDeferredInitJsonError } from './init-json.ts';
-import { buildInitFirstRunNotices } from './init-first-run.ts';
-import { renderNotice, cliRenderContext, shellQuote, type Notice } from '../core/agent-output.ts';
+import { firstRunBundle, firstRunJson, harnessRegistrationCommand } from './init-first-run.ts';
import { writeCliNotices } from '../core/interop-notices.ts';
-import { configReadiness, harnessWiringEntry } from '../core/readiness.ts';
-import { resolveGbrainBin } from '../core/gbrain-bin.ts';
import { exitCodeForCode } from '../core/error-catalogue.ts';
import { promptLineStderr } from '../core/interaction.ts';
import type { SearchMode as SearchModeName } from '../core/search/mode.ts';
@@ -1308,37 +1305,6 @@ export async function initPGLite(opts: {
const INIT_EMBEDDING_HINT = 'Pick an embedding model whose dimensions match (`gbrain init --help`), or pass --no-embedding for a keyless brain.';
-/**
- * G5: the ONE first-run decision bundle: search mode, writeback (personal
- * brain, unanswered), harness wiring and the optional skills scaffold. Human
- * output writes it through the CLI notice channel; --json carries it.
- */
-async function firstRunBundle(engine: BrainEngine, searchMode: { mode: SearchModeName; reason: string } | undefined): Promise<Notice[]> {
- const { writebackAskApplies } = await import('../core/onboard/writeback-nudge.ts');
- const { initSkillsScaffold } = await import('../core/skillpack/post-install-advisory.ts');
- return buildInitFirstRunNotices({ searchMode, config: loadConfig(), writeback: await writebackAskApplies(engine), skillsScaffold: initSkillsScaffold() });
-}
-
-/** D2/G5: the bundle rendered into init's --json document (`notices`, empty → omitted). */
-function firstRunJson(bundle: Notice[]): { notices?: unknown[]; contract_version: 1 } {
- const notices = bundle.map(n => renderNotice(n, cliRenderContext()));
- return { ...(notices.length ? { notices } : {}), contract_version: 1 };
-}
-
-/**
- * The harness registration line for the quickstart: the readiness
- * `harness_wiring` fix (absolute binary, `--surface verbs`) for the detected
- * harness, else the Claude Code registration built the same way. Null when
- * the gbrain binary has no absolute path (never registered bare).
- */
-function harnessRegistrationCommand(): string | null {
- const cfg = loadConfig();
- const detected = cfg ? configReadiness(cfg, { transport: 'cli' }).entries.find(e => e.capability === 'harness_wiring')?.fix : undefined;
- if (detected?.argv) return shellQuote(detected.argv);
- const claude = harnessWiringEntry({ transport: 'cli', harnesses: ['claude-code'], lockOwner: null, gbrainBin: resolveGbrainBin() }).fix;
- return claude?.argv ? shellQuote(claude.argv) : null;
-}
-
/**
* MEMORY_VERBS v1 quickstart funnel (E3 + D4B + T1 consent). Printed LAST in
* both init epilogues as the ONE primary action. The copy-next block is
diff --git a/src/commands/mcp-expose.ts b/src/commands/mcp-expose.ts
index 77f2348503..7bd9031a07 100644
--- a/src/commands/mcp-expose.ts
+++ b/src/commands/mcp-expose.ts
@@ -452,6 +452,21 @@ interface ConsentExtra {
user_message: string;
}
+/** The publish run's consent request: effects, the approved command and the words to relay. */
+function publishConsent(opts: ExposeOptions): ConsentExtra {
+ const where = opts.noTailscale ? 'on this machine' : opts.funnel ? 'on the public internet through Tailscale Funnel' : 'on your Tailscale network';
+ return {
+ yes: opts.yes, nextAction: rerunCommand(opts),
+ confirmationMessage: 'These are system-state changes (Tailscale, serve config, a user service). Pass --yes to confirm.',
+ argv: ['gbrain', 'mcp', 'expose', ...publishFlags(opts)],
+ effects: ['persistent_install', 'egress'],
+ what: 'mcp expose',
+ why: `Publishes this brain's MCP server ${where}${opts.noService ? '' : ' and installs a user service that keeps it running'}, so authorized agents on other machines can reach it.`,
+ risk: 'Changes system state (Tailscale serve config, a user service, files under the serve directory); `gbrain mcp expose --remove` undoes it.',
+ user_message: `I'd like to publish your gbrain MCP server ${where}${opts.noService ? '' : ' and install a background service for it'}. OK?`,
+ };
+}
+
/**
* The `consent` check, through the consent primitive (requireConsent). Returns
* the exit code to hand back when the run must stop, or null to proceed.
@@ -665,16 +680,7 @@ async function runPublish(d: Resolved, s: Session, opts: ExposeOptions): Promise
}
// 2. consent -------------------------------------------------------------
- const consent = await confirmOrFinish(d, s, 'Proceed with the plan above? [y/N] ', {
- yes: opts.yes, nextAction: rerunCommand(opts),
- confirmationMessage: 'These are system-state changes (Tailscale, serve config, a user service). Pass --yes to confirm.',
- argv: ['gbrain', 'mcp', 'expose', ...publishFlags(opts)],
- effects: ['persistent_install', 'egress'],
- what: 'mcp expose',
- why: `Publishes this brain's MCP server ${opts.noTailscale ? 'on loopback' : opts.funnel ? 'to the public internet (Tailscale Funnel)' : 'on your tailnet (Tailscale serve)'}${opts.noService ? '' : ' and installs a user service that keeps it running'}, so authorized agents on other machines can reach it.`,
- risk: 'Changes system state (Tailscale serve config, a user service, files under the serve directory); `gbrain mcp expose --remove` undoes it.',
- user_message: `I'd like to publish your gbrain MCP server ${opts.noTailscale ? 'on this machine' : opts.funnel ? 'on the public internet through Tailscale Funnel' : 'on your Tailscale network'}${opts.noService ? '' : ' and install a background service for it'}. OK?`,
- });
+ const consent = await confirmOrFinish(d, s, 'Proceed with the plan above? [y/N] ', publishConsent(opts));
if (consent !== null) return consent;
// 3-6. tailscale ---------------------------------------------------------