Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytan9bc0d1f81c89
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 63d9d4acd9..a52f91a555 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,12 +12,12 @@ identifiers and attribution are available in the pre-removal Git revision
## [Unreleased]
-**A source that a remote caller added by URL keeps its clone settings when a managed brain reclones it, and `gbrain frontmatter install-hook` leaves that clone's hooks off.** v0.60.601.0 wrote git-lfs downloads off and hooks off into such a clone's own git config, but `gbrain sources reclone` on a managed brain cloned it again without them. `install-hook` read the clone's hooks-off setting as a hooks directory someone else chose, wrote a hook it would never run, and told the operator how to turn hooks back on.
+**A source that a remote caller adds by URL keeps its clone settings on a managed brain, both when it is first cloned and when it is recloned, and `gbrain frontmatter install-hook` leaves that clone's hooks off.** v0.60.601.0 wrote git-lfs downloads off and hooks off into such a clone's own git config, but on a managed brain the add path did not record the source as remote-added and `gbrain sources reclone` cloned it again without the settings. `install-hook` read the clone's hooks-off setting as a hooks directory someone else chose, wrote a hook it would never run, and told the operator how to turn hooks back on.
### Itemized changes
-- `src/core/persistence/topology-filesystem.ts`, `src/core/persistence/topology-clone.ts`: the managed reclone of a source recorded `added_by_remote_caller` clones with the same `git clone --config` settings as `cloneRepo`'s `skipLfs` (shared as `LFS_OFF_CLONE_CONFIG` in `src/core/git-remote.ts`).
-- `src/commands/frontmatter-install-hook.ts`: a checkout whose `core.hooksPath` is `/dev/null` is skipped (`skipped_hooks_off`) with nothing written and no wiring advice, `--force` included.
+- `src/core/persistence/managed-sources.ts`, `src/core/persistence/topology-filesystem.ts`, `src/core/persistence/topology-clone.ts`: a managed add by a remote caller records `added_by_remote_caller` on the source, and the managed clone of such a source, on add and on reclone, uses the same `git clone --config` settings as `cloneRepo`'s `skipLfs` (shared as `LFS_OFF_CLONE_CONFIG` in `src/core/git-remote.ts`).
+- `src/commands/frontmatter-install-hook.ts`: a checkout whose own (`--local`) `core.hooksPath` is `/dev/null` is skipped (`skipped_hooks_off`) with nothing written and no wiring advice, `--force` included, and doctor's `frontmatter_hook` check no longer asks to refresh a hook there. A machine-wide `core.hooksPath=/dev/null` keeps the earlier behaviour: the hook is written unwired, with the usual advice.
- Tests: `test/persistence-source-lifecycle.test.ts` (PGLite and Postgres), `test/sources-remote-lfs.test.ts`, `test/frontmatter-install-hook.test.ts`.
## [0.60.602.0] - 2026-11-07
diff --git a/docs/architecture/key-files/commands-3-continued.md b/docs/architecture/key-files/commands-3-continued.md
index fec20b46f8..071a10a7af 100644
--- a/docs/architecture/key-files/commands-3-continued.md
+++ b/docs/architecture/key-files/commands-3-continued.md
@@ -15,6 +15,6 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/commands/friction.ts` + `src/core/friction.ts` — `gbrain friction {log,render,list,summary,diff}` reporter. Append-only JSONL under `$GBRAIN_HOME/.gbrain/friction/<run-id>.jsonl`. Schema is a flat extension of `StructuredAgentError`; every claw-test run opens with a `phase-marker`/`start` meta record carrying `agent` + `scenario` + `harness_schema` (agent-name resolution depends on it). Render groups by severity → phase, defaults to `--redact` for md output (strips `$HOME`/`$CWD` to placeholders so reports paste safely in PRs). `diff --base <run-or-agent> --compare <run-or-agent>` is the cross-agent instrument: exact run-id wins, else agent name resolves to that agent's latest run; identity is `(kind, phase, normalized 80-char message prefix — digit runs collapsed so durations/counts don't split identities)` over `kind ∈ {friction, delight}` as MULTISETS (per-severity counts + totals are the compared attributes: `count_changed` = volume, `severity_changed` = distribution shape via exact integer proportion test, so a delight→friction flip or a 2×error+1×nit → 1×error+2×nit redistribution always surfaces; markers/interrupted feed the compatibility banner, which warns on scenario/version mismatch); output labels sections "unique to <run>" — an instrument, never a blame-attributor. Run-id resolves from `--run-id` > `$GBRAIN_FRICTION_RUN_ID` > `standalone.jsonl`. Skills the claw-test exercises carry a `_friction-protocol.md` callout so agents know when to log friction.
-- `src/commands/frontmatter-install-hook.ts` — `gbrain frontmatter install-hook [--source <id>] [--force] [--uninstall]`: writes the frontmatter pre-commit hook at `<git root>/.githooks/pre-commit` and sets `core.hooksPath` when unset. The root comes from `discoverGitRoot` (the same `git rev-parse --show-toplevel` walk `gbrain sync` uses, realpath'd on both sides), so a source registered as a SUBDIRECTORY of a host repo (bootstrap's `<workspace>/brain`) is accepted rather than skipped: the hook lands at the host root with `git diff --cached` limited to that subdirectory via shell-quoted git pathspecs, recorded as `# gbrain-scope: <dir>/` marker lines (one per guarded scope). The script carries `# gbrain-hook-version: N` (`FRONTMATTER_HOOK_VERSION`; no marker = version 1, which validated working-tree bytes), lists staged paths with `-z | tr '\0' '\n'`, collects them in a heredoc-fed `while IFS= read -r` loop (spaces and non-ASCII names survive; a newline inside a name is unsupported) and runs ONE `gbrain frontmatter validate --staged -- <paths>`, which checks the staged blobs under the strict producer rule and names failures as staged content. `inspectFrontmatterHook(localPath, sourceId?)` (read-only) returns the installed gbrain hook's version, `current`, and the `install-hook --force` refresh argv for doctor and post-upgrade. One hook per root — nested sources union their scopes on install and drop only their own on uninstall (the last one removes the file); a root-registered source renders the unscoped script and owns the whole hook. A foreign `.githooks/pre-commit` still needs `--force` (`.bak` saved, restored on uninstall). Both install and uninstall resolve the hook location through `hookPaths(root)`, which lstat-refuses a symlinked `.githooks/` or `pre-commit` (a committed link in a host repo would redirect the write/chmod/rm elsewhere); the CLI prints the refusal as a `skipped` line and continues with the other sources. Only a path outside any repo is otherwise skipped. Every branch that leaves a hook on disk — fresh write, `--force` overwrite, or a byte-identical refresh — reaches the wiring step, because the hook FILE travels with the repo while `core.hooksPath` is per-clone config: a fresh clone of a repo that committed the hook reports `installed` (and gets wired) rather than `unchanged` while inert; `unchanged` means current AND wired. Before wiring `core.hooksPath`, `hooksPathBlocker(root)` returns the operator-facing reason wiring is unsafe, or null: a `core.hooksPath` already set (any scope — a global/corporate value counts; `--type=path`-expanded and resolved against the root) to anywhere that does not realpath to `.githooks` (theirs to keep; git never reads `.githooks/` then — one resolving to `.githooks` counts as wired), a foreign executable under `.githooks/` (wiring would start running it — third-party clones commit hooks there) or an active hook in the repo's own hooks dir (`activeGitHooks` — executable non-`*.sample` entries under `<git rev-parse --git-common-dir>/hooks`, immune to a foreign `core.hooksPath`; wiring would make git ignore them). Every git spawn passes `env: process.env` (Bun's default child env is a startup snapshot), so `GIT_CONFIG_*` overrides reach the child. A `core.hooksPath` of `/dev/null` (a URL source a remote caller added: hooks off on purpose) returns `skipped_hooks_off` before anything is written, `--force` included, and `hooksPathBlocker` names it without wiring advice. Any other blocker returns `installed_unwired` — the hook is written, `core.hooksPath` stays untouched, and the CLI prints the reason + the manual `git config core.hooksPath .githooks` step. Pinned by `test/frontmatter-install-hook.test.ts`.
+- `src/commands/frontmatter-install-hook.ts` — `gbrain frontmatter install-hook [--source <id>] [--force] [--uninstall]`: writes the frontmatter pre-commit hook at `<git root>/.githooks/pre-commit` and sets `core.hooksPath` when unset. The root comes from `discoverGitRoot` (the same `git rev-parse --show-toplevel` walk `gbrain sync` uses, realpath'd on both sides), so a source registered as a SUBDIRECTORY of a host repo (bootstrap's `<workspace>/brain`) is accepted rather than skipped: the hook lands at the host root with `git diff --cached` limited to that subdirectory via shell-quoted git pathspecs, recorded as `# gbrain-scope: <dir>/` marker lines (one per guarded scope). The script carries `# gbrain-hook-version: N` (`FRONTMATTER_HOOK_VERSION`; no marker = version 1, which validated working-tree bytes), lists staged paths with `-z | tr '\0' '\n'`, collects them in a heredoc-fed `while IFS= read -r` loop (spaces and non-ASCII names survive; a newline inside a name is unsupported) and runs ONE `gbrain frontmatter validate --staged -- <paths>`, which checks the staged blobs under the strict producer rule and names failures as staged content. `inspectFrontmatterHook(localPath, sourceId?)` (read-only) returns the installed gbrain hook's version, `current`, and the `install-hook --force` refresh argv for doctor and post-upgrade. One hook per root — nested sources union their scopes on install and drop only their own on uninstall (the last one removes the file); a root-registered source renders the unscoped script and owns the whole hook. A foreign `.githooks/pre-commit` still needs `--force` (`.bak` saved, restored on uninstall). Both install and uninstall resolve the hook location through `hookPaths(root)`, which lstat-refuses a symlinked `.githooks/` or `pre-commit` (a committed link in a host repo would redirect the write/chmod/rm elsewhere); the CLI prints the refusal as a `skipped` line and continues with the other sources. Only a path outside any repo is otherwise skipped. Every branch that leaves a hook on disk — fresh write, `--force` overwrite, or a byte-identical refresh — reaches the wiring step, because the hook FILE travels with the repo while `core.hooksPath` is per-clone config: a fresh clone of a repo that committed the hook reports `installed` (and gets wired) rather than `unchanged` while inert; `unchanged` means current AND wired. Before wiring `core.hooksPath`, `hooksPathBlocker(root)` returns the operator-facing reason wiring is unsafe, or null: a `core.hooksPath` already set (any scope — a global/corporate value counts; `--type=path`-expanded and resolved against the root) to anywhere that does not realpath to `.githooks` (theirs to keep; git never reads `.githooks/` then — one resolving to `.githooks` counts as wired), a foreign executable under `.githooks/` (wiring would start running it — third-party clones commit hooks there) or an active hook in the repo's own hooks dir (`activeGitHooks` — executable non-`*.sample` entries under `<git rev-parse --git-common-dir>/hooks`, immune to a foreign `core.hooksPath`; wiring would make git ignore them). Every git spawn passes `env: process.env` (Bun's default child env is a startup snapshot), so `GIT_CONFIG_*` overrides reach the child. A `core.hooksPath` of `/dev/null` in the clone's own (`--local`) config (a URL source a remote caller added: hooks off on purpose; a global or system value does not count) returns `skipped_hooks_off` before anything is written, `--force` included, `hooksPathBlocker` names it without wiring advice, and `inspectFrontmatterHook` returns null so doctor never proposes a refresh install-hook would skip. Any other blocker returns `installed_unwired` — the hook is written, `core.hooksPath` stays untouched, and the CLI prints the reason + the manual `git config core.hooksPath .githooks` step. Pinned by `test/frontmatter-install-hook.test.ts`.
- `src/commands/doctor/checks/outside-content-fences.ts` — `outside_content_fences` (GBRA-221, BRAIN, registered before `fence_integrity`). Lists facts (`row_num` set, active; world-visible counted apart), active takes and `links_fence` links indexed from a fence on an imported page whose body is outside-authored text (Google `email`/`meeting` pages, every GitHub-source page, pages with `transcript_import` frontmatter). Reads the derived rows, never a page body, so segmented pages are covered. Before GBRA-221 a sender could plant such rows and a re-render carries a stored fence forward; gbrain writers also add rows on purpose, so it only lists pages (location and counts, never a cell value) with an `ask_user` review fix (`gbrain get`) and removes nothing.
- `src/commands/doctor/checks/owner-host-stale.ts` + `src/commands/doctor/checks/embedding-plane.ts` — GBRA-248: doctor `owner_host_stale` (writes waiting on worktrees whose owner is stale per persistence/owner-activity.ts; fix is the read-only writer status) and `embedding_plane_disagreement` (the config file disables embeddings while the database does not and holds vectors; fix is `enableArgv` from core/readiness.ts for the stored model and width).
diff --git a/docs/architecture/key-files/core-persistence.md b/docs/architecture/key-files/core-persistence.md
index 7a4a9f4c2d..c60e126b2e 100644
--- a/docs/architecture/key-files/core-persistence.md
+++ b/docs/architecture/key-files/core-persistence.md
@@ -47,4 +47,4 @@ Managed facts extraction (withdrawn-candidate skip and recovery, conversation fa
- `src/core/persistence/{semantic,semantic-pages}.ts` — revision-bound semantic tag/timeline merges through the journal. Supported merges reprepare against a newer snapshot (`mayReprepare`: `revision_conflict` or, #5385 [R13], `revision_required`, both only when the caller named no `expected_revision`); exact timeline replay leaves canonical bytes, revision, versions and structured rows unchanged. The `add_timeline_entry` receipt carries `bullet`, the rendered Markdown line (#5970): there is no update/remove verb because the page is the system of record, so the caller corrects an entry by editing that line with `edit_page` and the row follows the page (both timeline op descriptions say so; `test/timeline-correction-path-5970.test.ts`). #5251: `add_tag` / `remove_tag` prepare with `deferEmbedding: true` (a tag change leaves every chunk's text as it was, so no `embedding` effect is queued and `embedding_state` reads `deferred`; the stale sweep still covers any chunk the republication left without a vector); the full page republication they ride stays, so the issue stays open. The public timeline handler resolves durable replay before page-existence preflight, retaining original outcomes after page purge or recreation; fresh writes preserve same-source diagnostics. `page-state/projections.ts` completes sanitized text and page search vectors together, and installs delayed embeddings with UPDATE-only revision/chunk/text/index-context checks. New vectors receive the full provider:model captured before provider execution, and a runtime model switch invalidates the prepared indexing context. Metadata updates preserve the sanitized vector. Tests: `persistence-semantic-pages.test.ts`, `page-projection-concurrency.test.ts`.
-- `src/core/persistence/{source-lifecycle,managed-sources,topology-schema,topology-locks,topology-receipts,topology-clone,topology-clone-model,topology-filesystem,topology-recovery}.ts` — migration 157 coordinates source add/claim/archive/restore/remove/purge/rebind/reclone. Native root locks precede topology/source/grant/counter/request guards; `withTopologyLocks(..., { relocation: true })` (rebind only, #5914 P1.3c) verifies a recorded root that now resolves through a symlink to the rebind target with `inspectRelocatedPhysicalRoot` instead of the realpath check, and the rebind transaction then calls `relocatePhysicalRoot` and moves `local_path`, the host binding and `relative_path` in place of a new worktree; a shared root advances every membership and permanently conflicts accepted old-topology requests. Withdrawal mirrors and running publication must settle first. Administrative UUIDs share the page journal's principal-scoped conflict domain and permanent capacity counters. Directory replacement reserves the configured recovery budget before provider/staging work, records a verified manifest and physical identity, and recovers only known bytes; clone failure retains the original checkout and a replayable failure receipt. A reclone of a source recorded `added_by_remote_caller` passes `skipLfs` to `cloneTopologyCheckout`, which writes `LFS_OFF_CLONE_CONFIG` (`git-remote.ts`) into the clone as `cloneRepo` does. Rebinding accepts a fresh candidate with exactly matching canonical content, including deletions. Stored worktree manifests and clone recovery records keep `digest`, `file_count`, `canonical_stamp` and `self_transfer` but no per-file map (#5790), so their size is independent of the worktree; `compactStoredManifest` drops a legacy map on rewrite, and transfer prepare/accept hash under the native lock before their transaction. #5200 (W14 P1.4): only a lifecycle operation that compares or records checkout bytes (`add` at an existing root, `claim`, `rebind`, `restore`; `reclone` in `topology-clone.ts`) walks and hashes the checkout; `archive`, `remove` and `purge` skip the walk when every binding of the source already carries a verified `digest` and refresh the stored manifest's `canonical_stamp` in place (`manifest = COALESCE(manifest,'{}') || {canonical_stamp}`), so a symlink that appeared after the claim no longer refuses a retire (a binding claimed before activation has no digest yet, and the retire records that first manifest because clone recovery needs it), and every dry run reports `manifest_required` so preview and real run agree (`test/source-retire-symlink-manifest.test.ts`). The `writer_manifest_unsafe` text names the manifest, not a transfer, since claim and rebind raise it too. Large-repo tests: `test/persistence-large-manifest.test.ts` (12k files, both engines via `test/e2e/persistence-large-manifest-postgres.test.ts`) and `test/e2e/persistence-large-manifest-50k.test.ts`. Old root refusal records remain. Metadata deletion retains local storage. Restart recovery rotates a bounded root scan so one conflict cannot starve other roots. Tests: `test/persistence-source-lifecycle.test.ts` on PGLite and guarded isolated Postgres. #6099: manifests are Git-scoped for Git checkouts; see `worktree-manifest.ts` in [managed sync and persistence stalls](persistence-stalls.md).
+- `src/core/persistence/{source-lifecycle,managed-sources,topology-schema,topology-locks,topology-receipts,topology-clone,topology-clone-model,topology-filesystem,topology-recovery}.ts` — migration 157 coordinates source add/claim/archive/restore/remove/purge/rebind/reclone. Native root locks precede topology/source/grant/counter/request guards; `withTopologyLocks(..., { relocation: true })` (rebind only, #5914 P1.3c) verifies a recorded root that now resolves through a symlink to the rebind target with `inspectRelocatedPhysicalRoot` instead of the realpath check, and the rebind transaction then calls `relocatePhysicalRoot` and moves `local_path`, the host binding and `relative_path` in place of a new worktree; a shared root advances every membership and permanently conflicts accepted old-topology requests. Withdrawal mirrors and running publication must settle first. Administrative UUIDs share the page journal's principal-scoped conflict domain and permanent capacity counters. Directory replacement reserves the configured recovery budget before provider/staging work, records a verified manifest and physical identity, and recovers only known bytes; clone failure retains the original checkout and a replayable failure receipt. A managed add by a remote caller records `added_by_remote_caller` in the source config (`managedSourceAddInput`), and an add or reclone of such a source passes `skipLfs` to `cloneTopologyCheckout`, which writes `LFS_OFF_CLONE_CONFIG` (`git-remote.ts`) into the clone as `cloneRepo` does. Rebinding accepts a fresh candidate with exactly matching canonical content, including deletions. Stored worktree manifests and clone recovery records keep `digest`, `file_count`, `canonical_stamp` and `self_transfer` but no per-file map (#5790), so their size is independent of the worktree; `compactStoredManifest` drops a legacy map on rewrite, and transfer prepare/accept hash under the native lock before their transaction. #5200 (W14 P1.4): only a lifecycle operation that compares or records checkout bytes (`add` at an existing root, `claim`, `rebind`, `restore`; `reclone` in `topology-clone.ts`) walks and hashes the checkout; `archive`, `remove` and `purge` skip the walk when every binding of the source already carries a verified `digest` and refresh the stored manifest's `canonical_stamp` in place (`manifest = COALESCE(manifest,'{}') || {canonical_stamp}`), so a symlink that appeared after the claim no longer refuses a retire (a binding claimed before activation has no digest yet, and the retire records that first manifest because clone recovery needs it), and every dry run reports `manifest_required` so preview and real run agree (`test/source-retire-symlink-manifest.test.ts`). The `writer_manifest_unsafe` text names the manifest, not a transfer, since claim and rebind raise it too. Large-repo tests: `test/persistence-large-manifest.test.ts` (12k files, both engines via `test/e2e/persistence-large-manifest-postgres.test.ts`) and `test/e2e/persistence-large-manifest-50k.test.ts`. Old root refusal records remain. Metadata deletion retains local storage. Restart recovery rotates a bounded root scan so one conflict cannot starve other roots. Tests: `test/persistence-source-lifecycle.test.ts` on PGLite and guarded isolated Postgres. #6099: manifests are Git-scoped for Git checkouts; see `worktree-manifest.ts` in [managed sync and persistence stalls](persistence-stalls.md).
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 152ce8cbfb..215b6f1252 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -201,7 +201,7 @@ test/fix-wave-structural.test.ts v0.41.8.0 #1340 — PGLite WASM init classifier
test/fix-wave-structural.test.ts v0.42.20.0 — background-work registry drains every sink before disconnect 9 readFileSync,source-surface-helper
test/fix-wave-structural.test.ts v0.42.20.0 — search-cache drained via the background-work registry 1 source-surface-helper
test/fix-wave-structural.test.ts v0.42.43.0 #2095 — volunteer-events sink + cycle purge wiring (structural pins) 2 readFileSync,source-surface-helper
-test/frontmatter-install-hook.test.ts frontmatter install-hook (B13) 26 readFileSync
+test/frontmatter-install-hook.test.ts frontmatter install-hook (B13) 28 readFileSync
test/fts-cjk-boundary.test.ts one copy of the DDL 2 readFileSync
test/gbrain-owned-page-types.test.ts #5881 gbrain-owned page types are declared by gbrain-base-v2 3 readFileSync
test/get-page-federated-scope.test.ts #2555 get_chunks federated scope 5 source-surface-helper
diff --git a/src/commands/frontmatter-install-hook.ts b/src/commands/frontmatter-install-hook.ts
index b77c75a557..4f0121bbd7 100644
--- a/src/commands/frontmatter-install-hook.ts
+++ b/src/commands/frontmatter-install-hook.ts
@@ -139,18 +139,20 @@ export interface InstalledFrontmatterHook {
/**
* The gbrain pre-commit hook guarding `localPath`, read-only: null when the
- * path is outside git, the hook path is a symlink, or no gbrain hook is
- * installed at its root. Doctor and post-upgrade use `current` to recommend
+ * path is outside git, the hook path is a symlink, no gbrain hook is
+ * installed at its root, or the clone has hooks off on purpose (git never runs
+ * the file, and install-hook skips it). Doctor and post-upgrade use `current` to recommend
* `gbrain frontmatter install-hook --force`.
*/
export function inspectFrontmatterHook(localPath: string, sourceId?: string): InstalledFrontmatterHook | null {
- let hookPath: string;
+ let root: string, hookPath: string;
try {
- hookPath = hookPaths(resolveHookTarget(localPath).root).hookPath;
+ root = resolveHookTarget(localPath).root;
+ hookPath = hookPaths(root).hookPath;
} catch {
return null;
}
- if (!existsSync(hookPath)) return null;
+ if (!existsSync(hookPath) || hooksOffInClone(root)) return null;
const version = frontmatterHookVersion(readFileSync(hookPath, 'utf8'));
if (version === null) return null;
const current = version >= FRONTMATTER_HOOK_VERSION;
@@ -404,6 +406,15 @@ function currentHooksPath(root: string): string {
}
}
+/** The clone's own config turns hooks off (LFS_OFF_CLONE_CONFIG on a URL source a remote caller added); a global or system value does not count. */
+function hooksOffInClone(root: string): boolean {
+ try {
+ return git(root, ['config', '--local', '--get', 'core.hooksPath']) === HOOKS_OFF;
+ } catch {
+ return false;
+ }
+}
+
const samePath = (a: string, b: string): boolean => {
try { return realpathSync(a) === realpathSync(b); } catch { return a === b; }
};
@@ -418,8 +429,8 @@ const samePath = (a: string, b: string): boolean => {
* `.githooks/<hook>` or a live `.git/hooks/<hook>` both block it too.
*/
export function hooksPathBlocker(root: string): string | null {
+ if (hooksOffInClone(root)) return `hooks are off in this clone on purpose (core.hooksPath=${HOOKS_OFF}, set on a source a remote caller added by URL), and gbrain leaves them off`;
const current = currentHooksPath(root);
- if (current === HOOKS_OFF) return `hooks are off in this clone on purpose (core.hooksPath=${HOOKS_OFF}, set on a source a remote caller added by URL), and gbrain leaves them off`;
if (current) {
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- fixed literal tail under the discovered git root
if (samePath(current, join(root, '.githooks'))) return null;
@@ -436,7 +447,7 @@ export function hooksPathBlocker(root: string): string | null {
export function installHook(localPath: string, force: boolean): InstallResult {
const { root, scope } = resolveHookTarget(localPath);
- if (currentHooksPath(root) === HOOKS_OFF) return 'skipped_hooks_off';
+ if (hooksOffInClone(root)) return 'skipped_hooks_off';
const { hooksDir, hookPath } = hookPaths(root);
mkdirSync(hooksDir, { recursive: true });
diff --git a/src/core/persistence/managed-sources.ts b/src/core/persistence/managed-sources.ts
index 46dd9d3c91..1e1d33bb3c 100644
--- a/src/core/persistence/managed-sources.ts
+++ b/src/core/persistence/managed-sources.ts
@@ -33,7 +33,7 @@ export function managedSourceAddInput(opts:AddSourceOpts):SourceLifecycleInput{
throw new OperationError('invalid_params','force and federated must be boolean values.','Pass force and federated as true or false, or omit them.');
let path=opts.localPath?resolve(msysToNativePath(opts.localPath)):undefined;
let config:Record<string,unknown>=opts.federated==null?{}:{federated:opts.federated};
- if(opts.remoteUrl){path=resolve(opts.cloneDir??defaultCloneDir(opts.id));config={...config,remote_url:opts.remoteUrl,managed_clone:true};}
+ if(opts.remoteUrl){path=resolve(opts.cloneDir??defaultCloneDir(opts.id));config={...config,remote_url:opts.remoteUrl,managed_clone:true,...(opts.addedByRemoteCaller?{added_by_remote_caller:true}:{})};}
if(opts.github){
const gh=opts.github;path=resolve(msysToNativePath(gh.dir));
config={kind:'github',gh_token_env:gh.tokenEnv,gh_handle:gh.handle,gh_scope:gh.scope,gh_repos:gh.repos.join(','),gh_involvement:gh.involvement,
diff --git a/src/core/persistence/topology-clone.ts b/src/core/persistence/topology-clone.ts
index dbe4469049..ebcb8a1a13 100644
--- a/src/core/persistence/topology-clone.ts
+++ b/src/core/persistence/topology-clone.ts
@@ -166,7 +166,7 @@ export async function runManagedSourceClone(engine:BrainEngine,input:SourceLifec
await tx.executeRaw("SELECT set_config('synchronous_commit','on',true)");
await tx.executeRaw("UPDATE persistence_topology_changes SET recovery=$2::text::jsonb,updated_at=now() WHERE id=$1::uuid AND state='recovering'",[accepted!.id,JSON.stringify(recovery)]);
});
- await (hooks.clone??cloneTopologyCheckout)(url,recovery.stage,recovery.cloneBudget,{skipLfs:lfsDownloadsOff(source?.config)});
+ await (hooks.clone??cloneTopologyCheckout)(url,recovery.stage,recovery.cloneBudget,{skipLfs:lfsDownloadsOff(source?.config??input.config)});
const stageBytes=await topologyDirectoryBytes(recovery.stage,recovery.cloneBudget);
const candidate=worktreeManifest(recovery.stage,{progress:humanManifestProgress(),scope:recovery.hashScope});
if(recovery.manifest&&candidate.digest!==recovery.manifest.digest)throw opError('writer_manifest_mismatch','The cloned checkout differs from the verified canonical manifest, including deletions.',
diff --git a/test/frontmatter-install-hook.test.ts b/test/frontmatter-install-hook.test.ts
index e70c894e5d..d972fec420 100644
--- a/test/frontmatter-install-hook.test.ts
+++ b/test/frontmatter-install-hook.test.ts
@@ -337,6 +337,28 @@ describe('frontmatter install-hook (B13)', () => {
expect(localHooksPath(tmp)).toBe('/dev/null');
});
+ test('hooks off machine-wide (a global core.hooksPath=/dev/null) is not a hooks-off clone: the hook is written unwired with the usual advice', () => {
+ const globalConfig = join(tmp, '..', `fm-global-${process.pid}.gitconfig`);
+ writeFileSync(globalConfig, '[core]\n\thooksPath = /dev/null\n');
+ try {
+ withEnv({ GIT_CONFIG_GLOBAL: globalConfig, GIT_CONFIG_SYSTEM: '/dev/null' }, () => {
+ expect(installHook(tmp, false)).toBe('installed_unwired');
+ expect(hooksPathBlocker(tmp)).toContain('core.hooksPath already points at /dev/null');
+ });
+ expect(existsSync(join(tmp, '.githooks', 'pre-commit'))).toBe(true);
+ } finally {
+ rmSync(globalConfig, { force: true });
+ }
+ });
+
+ test('doctor does not ask to refresh an old gbrain hook in a clone with hooks off on purpose (install-hook would skip it)', () => {
+ mkdirSync(join(tmp, '.githooks'), { recursive: true });
+ writeFileSync(join(tmp, '.githooks', 'pre-commit'), '#!/bin/sh\n# gbrain frontmatter pre-commit hook (v0.22.4+)\ngbrain frontmatter validate "$f"\n');
+ expect(inspectFrontmatterHook(tmp, 'source-a')).toMatchObject({ version: 1, current: false });
+ execFileSync('git', ['-C', tmp, 'config', 'core.hooksPath', '/dev/null']);
+ expect(inspectFrontmatterHook(tmp, 'source-a')).toBeNull();
+ });
+
test('a fresh clone that carries the committed gbrain hook gets wired on install (not "unchanged" while inert)', async () => {
// The hook FILE travels with the repo; core.hooksPath is per-clone config
// and does not. Install on the clone must fall through to the wiring step
diff --git a/test/persistence-source-lifecycle.test.ts b/test/persistence-source-lifecycle.test.ts
index de0e398cfc..67923bf4ae 100644
--- a/test/persistence-source-lifecycle.test.ts
+++ b/test/persistence-source-lifecycle.test.ts
@@ -15,7 +15,8 @@ import { admitWrite, claimNextWrite } from '../src/core/persistence/journal.ts';
import { submissionAuthority } from '../src/core/persistence/authority.ts';
import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
import { runManagedSourceClone } from '../src/core/persistence/topology-clone.ts';
-import { addSource, removeSource } from '../src/core/sources-ops.ts';
+import { addSource, lfsDownloadsOff, removeSource } from '../src/core/sources-ops.ts';
+import { managedSourceAddInput } from '../src/core/persistence/managed-sources.ts';
import { softDeleteSource, restoreSource } from '../src/core/destructive-guard.ts';
import { topologyDirectoryBytes } from '../src/core/persistence/topology-filesystem.ts';
import { topologyPrincipal } from '../src/core/persistence/topology-locks.ts';
@@ -381,4 +382,18 @@ test('a reclone of a source a remote caller added by URL clones with git-lfs dow
expect(seen.map(options=>options?.skipLfs===true)).toEqual([true,false]);
}),60_000);
+test('a managed add by a remote caller clones with git-lfs downloads and hooks off and records it for later reclones',()=>fixture(async(_home,_source,root)=>{
+ const seen:Array<{skipLfs?:boolean}|undefined>=[];
+ for(const [id,addedByRemoteCaller] of [['remote-a',true],['local-a',false]] as const){
+ const input={...managedSourceAddInput({id,remoteUrl:'https://example.invalid/brain.git',addedByRemoteCaller}),requestId:randomUUID()};
+ const result=await runManagedSourceClone(engine,input,await topologyPrincipal(engine),input.requestId,{...input,requestId:undefined,dryRun:undefined},{
+ clone:async(_url,stage,_budget,options)=>{seen.push(options);cpSync(root,stage,{recursive:true,filter:path=>!isPhysicalRootMetadata(basename(path))});},
+ });
+ expect(result).toMatchObject({state:'committed'});
+ const [row]=await engine.executeRaw<{config:unknown}>('SELECT config FROM sources WHERE id=$1',[id]);
+ expect(lfsDownloadsOff(row!.config)).toBe(addedByRemoteCaller);
+ }
+ expect(seen.map(options=>options?.skipLfs===true)).toEqual([true,false]);
+}),60_000);
+
});