Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(#8662): check only a checkout resolved from the working directory; an explicit --path names its checkout (legacy sources are not in the managed-root record)
garrytanccab9a936f2c
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.mdindex 16bf222efa..c71db81a76 100644--- a/docs/guides/error-codes.md+++ b/docs/guides/error-codes.md@@ -638,7 +638,7 @@ More: [docs/guides/page-history.md#reasons](../../docs/guides/page-history.md#re| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable ||---|---|---|---|---|---|---|-| gbrain git commit-push resolved a checkout that is not one of this brain's source checkouts on this host (for example a wrapper that changed into another repository), so nothing was staged. | Committing there would write into an unrelated repository, or fail later with a confusing path refusal. | Correct the request using the message above, then retry. | user | `repeat the read that failed` | 1 | no |+| gbrain git commit-push resolved a checkout from the working directory that is not one of this brain's source checkouts on this host (for example a wrapper that changed into another repository), so nothing was staged. | Committing there would write into an unrelated repository, or fail later with a confusing path refusal. | Correct the request using the message above, then retry. | user | `repeat the read that failed` | 1 | no |More: [docs/guides/shared-checkout-git.md#checkout_not_a_source](../../docs/guides/shared-checkout-git.md#checkout_not_a_source)diff --git a/docs/guides/shared-checkout-git.md b/docs/guides/shared-checkout-git.mdindex 03d07bbc20..6ca4764213 100644--- a/docs/guides/shared-checkout-git.md+++ b/docs/guides/shared-checkout-git.md@@ -173,7 +173,7 @@ Follow the error's `fix.next` as the| `committed_local` | 0 | A managed canonical worktree, or a checkout with no Git remote (`no_remote: true`): the paths were committed locally and nothing was pushed. Report the commit; it reaches a remote on the owner's next publish, or after a remote is added and `--push-only` runs. || `pushed_checkout_lagging` | 0 | The push landed but this checkout was not advanced; a `[gbrain notice]` names the files that blocked it. Change nothing: the next commit-push or `--pull` catches the checkout up. Never stash or reset to "fix" it. || `commit_lock_busy` | 1 | Another writer held the lock for the whole wait; nothing was committed. Retry once. If it is still busy, tell the user which checkout and lock path the message names and stop. |-| <a id="checkout_not_a_source"></a>`checkout_not_a_source` | 1 | The checkout commit-push resolved (from `--path` or the working directory) is not one of the brain's source checkouts on this host, typically a wrapper that changed into another repository; nothing was staged. The message lists the brain's checkouts. Tell the user to make the script pass `--path` with the absolute brain checkout. A host whose brain records no source checkout, or a checkout with `gbrain.sourceRoot` set, is never refused this way. |+| <a id="checkout_not_a_source"></a>`checkout_not_a_source` | 1 | The checkout commit-push resolved from the working directory (no `--path`) is not one of the brain's source checkouts on this host, typically a wrapper that changed into another repository; nothing was staged. The message lists the brain's checkouts. Tell the user to make the script pass `--path` with the absolute brain checkout. A host whose brain records no source checkout, or a checkout with `gbrain.sourceRoot` set, is never refused this way. || `commit_paths_invalid` | 1 | No paths, a path outside the checkout, the checkout root itself, or a path git would not stage. Name the explicit files you wrote and rerun. || `commit_prestaged_paths` | 1 | Another writer staged files under a directory you named; nothing was staged or committed. Name your own files explicitly. Unstage the others (`git restore --staged -- <file>`, which keeps their bytes) only after the user agrees. || `commit_outside_source_root` | 1 | The commit, or a local commit about to be published, changes files outside the brain's [source root](#source-roots); nothing was pushed. Show the user `git show --stat <sha>`; rerun with `--allow-outside-source-root` only if they want it published. |@@ -270,7 +270,7 @@ commits come in. Four rules keep that checkout able to move:checkout diverges, and every later refresh refuses `refresh_diverged` andchanges nothing. Commit the files a script wrote with`gbrain git commit-push --path <absolute checkout> -m "<msg>" -- <paths>`- (a checkout that is not the brain's refuses `checkout_not_a_source`): on a managed worktree it+ (run from another repository without `--path`, it refuses `checkout_not_a_source`): on a managed worktree itcommits only those paths under the commit lock (`committed_local`) and theowner publishes them on its next Git publish. Pages can also go through`put_page`, `edit_page`, `remember` or `capture`. CLI calls go throughdiff --git a/src/commands/git.ts b/src/commands/git.tsindex 66704d4021..1d0b561b03 100644--- a/src/commands/git.ts+++ b/src/commands/git.ts@@ -137,8 +137,9 @@ function parseResolutions(specs: string[]): Map<string, Resolution> {}/**- * #8662: on a host whose brain records its source checkouts, a resolved checkout that is none of them and carries no- * gbrain.sourceRoot marker is refused before anything is staged (a wrapper that changed into another repository).+ * #8662: on a host whose brain records its source checkouts, a checkout resolved from the working directory that is none of+ * them and carries no gbrain.sourceRoot marker is refused before anything is staged (a wrapper that changed into another+ * repository). An explicit --path names its checkout and is not checked here (a legacy source is not in that record).*/function assertSourceCheckout(repo: string): void {const registered = registeredManagedRootRecords();@@ -172,7 +173,7 @@ export async function runGit(args: string[]): Promise<number> {if (p.sub !== 'commit-push') throw opError('commit_paths_invalid', `Unknown subcommand: gbrain git ${p.sub}.`, HELP.split('\n')[0]);if (p.install || p.uninstall) throw opError('commit_paths_invalid', '--install and --uninstall belong to gbrain git guard.', 'Run gbrain git guard --install.');const repo = checkoutRoot(p.path ?? process.cwd());- assertSourceCheckout(repo);+ if (!p.path) assertSourceCheckout(repo);const cwd = p.path ? realpathSync(p.path) : process.cwd();if ((p.pull && p.pushOnly) || (p.pull && (p.message || p.paths.length || p.resolve.length || p.branch))|| (p.pushOnly && (p.message || p.paths.length)) || ((p.resolve.length || p.branch || p.expectRemote || p.keepCheckout) && !p.pushOnly)diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex e364e28f0f..09fd5042a2 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1459,7 +1459,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: 'TBD', id: 'commit_push_base_prb', text: '`gbrain git commit-push` takes `--base <path>=<blob>|absent` (repeatable, each path one the command commits): it refuses `commit_base_moved`, committing nothing, when the file at HEAD is no longer the blob the caller read. Without `--base` nothing changes.' },{ since: 'TBD', id: 'file_drift_held_needs_prefer_8615', text: '`gbrain repair file-drift` with `--held`, `--side`, `--state`, `--cursor` or `--provenance` and no `--prefer` now refuses with the usage line (`invalid_params`, and `file_drift_state_required` for a deleted side without `--state`) instead of silently running the all-drifted survey, which counted a different set of pages (#8615).' },{ since: 'TBD', id: 'refresh_source_changed_retry_8617', text: 'A `gbrain sources refresh` run refused `refresh_source_changed` because the checkout HEAD moved (a writer committing) or work reached the checkout after the drain check now retries once from a fresh precheck in the same run, so the tick is not lost (#8617). When the retry is refused too, the run returns the first `refresh_source_changed` refusal with the retry\'s cause appended; ownership or source-membership changes are not retried.' },- { since: 'TBD', id: 'commit_push_checkout_not_a_source_8662', text: '`gbrain git commit-push` now refuses `checkout_not_a_source` before staging anything when this brain home records its source checkouts (a managed brain) and the checkout it resolved is none of them and has no `gbrain.sourceRoot`, for example a wrapper that changed into another repository (#8662). The refusal names the resolved path and the brain\'s checkouts; pass `--path` with the absolute brain checkout. Hosts whose brain records no source checkout behave as before.' },+ { since: 'TBD', id: 'commit_push_checkout_not_a_source_8662', text: '`gbrain git commit-push` now refuses `checkout_not_a_source` before staging anything when this brain home records its source checkouts (a managed brain) and the checkout it resolved from the working directory (no `--path`) is none of them and has no `gbrain.sourceRoot`, for example a wrapper that changed into another repository (#8662). The refusal names the resolved path and the brain\'s checkouts; pass `--path` with the absolute brain checkout. Hosts whose brain records no source checkout behave as before.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/error-registry.ts b/src/core/error-registry.tsindex 9426db0a51..329a493eff 100644--- a/src/core/error-registry.ts+++ b/src/core/error-registry.ts@@ -147,7 +147,7 @@ export const CODES = {change_reason_rejected: { class: 'caller', summary: "The write's reason was refused before anything was admitted: it is longer than 500 characters, or it looks like it holds a secret.", why: 'A reason is kept in page history and, on a page that reaches Git, in the commit message, which a push makes permanent; it is checked before the write is journaled so no copy of a refused reason is stored anywhere.', reasons: ['reason_too_long', 'reason_contains_secret'], legacy_error: 'invalid_params', docs: 'docs/guides/page-history.md#reasons', suggestion: 'Shorten the reason, or remove the secret from it, and send the write again.' },changed_since_preview: { class: 'caller', summary: "The file changed after its repair was previewed, so nothing was written.", why: "A repair writes exactly the bytes the operator approved; it binds approval to the previewed file hash and refuses when the file moved on.", suggestion: 'Preview the repair again, review the new proposal, and approve its new hash.' },chronicle_skipped: { class: 'unavailable', summary: "Automatic event extraction (auto_chronicle) skipped or failed this page; `reason` says why and `fix`, when present, is the next step.", reasons: ['auto_chronicle_off', 'auto_chronicle_invalid', 'slug_bound_client', 'operation_bound_client', 'no_extract', 'history', 'not_yet_happened', 'too_short', 'dream_generated', 'page_body_segmented', 'no_write_decision', 'not_chronicle_shaped', 'already_extracted', 'superseded', 'daily_limit', 'judge_llm_unavailable', 'no_pricing', 'budget_exhausted', 'campaign_exhausted', 'judge_chat_error', 'judge_truncated', 'judge_parse_failed', 'malformed_proposal', 'publish_error', 'judge_refused', 'page_missing', 'no_events', 'future_dated', 'date_imprecise', 'no_chat_provider'], docs: 'docs/guides/life-chronicle.md#skip-and-failure-codes', suggestion: 'Read the receipt or doctor `auto_chronicle` check: its `why` explains the reason and its `fix`, when present, is the next step (paid fixes need the user\'s agreement).' },- checkout_not_a_source: { class: 'caller', actor: 'user', summary: "gbrain git commit-push resolved a checkout that is not one of this brain's source checkouts on this host (for example a wrapper that changed into another repository), so nothing was staged.", why: 'Committing there would write into an unrelated repository, or fail later with a confusing path refusal.', docs: 'docs/guides/shared-checkout-git.md#checkout_not_a_source' },+ checkout_not_a_source: { class: 'caller', actor: 'user', summary: "gbrain git commit-push resolved a checkout from the working directory that is not one of this brain's source checkouts on this host (for example a wrapper that changed into another repository), so nothing was staged.", why: 'Committing there would write into an unrelated repository, or fail later with a confusing path refusal.', docs: 'docs/guides/shared-checkout-git.md#checkout_not_a_source' },checkpoint_missing: { class: 'caller', summary: "The approved source plan is missing; do not restart from a different revision." },checkpoint_validation_timeout: { class: 'retryable', summary: "Validating the managed-sync checkpoint timed out." },claim_already_used: { class: 'caller', summary: "Google connect credential error: claim already used.", docs: 'docs/guides/google-connect.md#troubleshooting' },diff --git a/test/git-commit-push-not-a-source-8662.test.ts b/test/git-commit-push-not-a-source-8662.test.tsindex 53e94d75e4..eb4bea05ec 100644--- a/test/git-commit-push-not-a-source-8662.test.ts+++ b/test/git-commit-push-not-a-source-8662.test.ts@@ -66,7 +66,7 @@ test('a checkout that is not a registered source is refused checkout_not_a_sourcexpect(git(other, 'status', '--porcelain')).toBe('?? notes/');}, 60_000);-test('the registered checkout still commits, and a gbrain source marker admits its checkout', async () => {+test('the registered checkout still commits, a gbrain source marker admits its checkout, and an explicit --path is not checked', async () => {const { home, brain } = brainHome('admitted');const result = await commitPush(dir, home, '--path', brain, '--', 'people/alice-example.md');expect(result.exitCode).toBe(0);@@ -77,6 +77,11 @@ test('the registered checkout still commits, and a gbrain source marker admits iconst published = await commitPush(marked, home, '--', 'notes/a.md');expect(published.exitCode).toBe(0);expect(JSON.parse(published.stdout)).toMatchObject({ outcome: 'pushed', paths: ['notes/a.md'] });+ // An explicit --path names its checkout: a legacy source the managed-root record does not list still commits.+ const legacy = otherRepo('admitted-legacy');+ const named = await commitPush(dir, home, '--path', legacy, '--', 'notes/a.md');+ expect(named.exitCode).toBe(0);+ expect(JSON.parse(named.stdout)).toMatchObject({ outcome: 'pushed', paths: ['notes/a.md'] });}, 60_000);test('a host whose brain records no source checkout commits in any checkout as before', async () => {