Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytan9ff403413108
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a8a579824..8307448797 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,11 +16,11 @@ identifiers and attribution are available in the pre-removal Git revision
### Itemized changes
-- `src/core/git/range-secret-scan.ts` (new): reads the range with plumbing only (`rev-list`, `git cat-file commit` per message, one `git diff-tree --stdin -p --root --cc` streamed to a private temporary file and read in chunks), so no log, diff or encoding setting and no replace ref changes what is scanned, and memory stays bounded however large the binaries in the range are. It scans each commit's message, each file's added lines and each merge's lines no parent has with `scanText` and the workspace allowlist (`.gbrain-scan-allow`). Binary is git's own rule (a NUL in the first 8000 bytes) with attributes read from the empty tree; a file git still calls binary is checked by its own bytes when its old side was not empty or an attribute could apply, and scanned whole when it is text. Added text over the scan cap is reported unscanned, and output it does not recognise, a git failure or its 300 s budget make the result unreadable.
+- `src/core/git/range-secret-scan.ts` (new): reads the range with plumbing only (`rev-list`, `git cat-file commit` per message, one `git diff-tree --stdin -p --root --cc` streamed to a private temporary file and read in chunks), so no log, diff or encoding setting, no replace ref and no system attributes file changes what is scanned, and memory stays bounded however large the binaries in the range are. It scans each commit's message (also as raw bytes when it declares an encoding other than UTF-8), each file's added lines and each merge's lines no parent has with `scanText` and the workspace allowlist (`.gbrain-scan-allow`). Binary is git's own rule (a NUL in the first 8000 bytes) with attributes read from the empty tree; a file git still calls binary is checked by its own bytes when its old side was not empty or an attribute could apply, and scanned whole when it is text. Added text over the scan cap is reported unscanned, and output it does not recognise, a git failure or its 300 s budget make the result unreadable.
- `src/core/persistence/worktree-refresh.ts`: an unset `sources.refresh_publish_diverged` publishes only when `gitDurabilityPolicy` says durable (otherwise `refresh_diverged` names the durability and the `--enable` command); the publish child runs with `--scan-secrets`.
- `src/core/git/commit-push.ts`, `src/commands/git.ts`: `scanSecrets` / `--scan-secrets` (push-only) scans `trackingRef..target` inside the publish lock, right before the push, and refuses `publish_secret_found` (new error code) on a finding or an over-cap file, and `publish_scan_unreadable` (new error code: no secret was reported, check the checkout with `git fsck`) when the scan could not read the range in full; the secret refusal's fix lists the commits and asks the user to remove the value or allowlist a false positive, never to push anyway.
- Docs: `docs/guides/shared-checkout-git.md` (`publish_secret_found` row), `docs/guides/write-refusals.md` (`refresh_diverged`), `docs/guides/live-sync.md`, `docs/guides/shared-checkout-git.md`, `docs/guides/troubleshooting.md`, `docs/architecture/canonical-writers.md`.
-- Tests: `test/guarded-publish.test.ts` (a secret added then removed, one in a commit message and one in a merge resolution each refuse with nothing pushed and no value printed; an allowlisted fingerprint and a binary file are skipped; a clean range publishes; a NUL past a text file's first 8000 bytes, a repository log encoding and `log.showRoot=false` with a merged root commit never hide a secret; a range the scan cannot read refuses `publish_scan_unreadable`); `test/refresh-publish-diverged-7686.test.ts` (unset with durability off refuses naming `--enable`, unset with durability on publishes, a secret in the local commits refuses `publish_secret_found` with nothing pushed or fenced).
+- Tests: `test/guarded-publish.test.ts` (a secret added then removed, one in a commit message and one in a merge resolution each refuse with nothing pushed and no value printed; an allowlisted fingerprint and a binary file are skipped; a clean range publishes; a NUL past a text file's first 8000 bytes, a repository log encoding `log.showRoot=false` with a merged root commit and a message declaring UTF-16 never hide a secret; a range the scan cannot read, or a message encoding it cannot decode, refuses `publish_scan_unreadable`; every scan git call runs with the system attributes file off); `test/refresh-publish-diverged-7686.test.ts` (unset with durability off refuses naming `--enable`, unset with durability on publishes, a secret in the local commits refuses `publish_secret_found` with nothing pushed or fenced).
## [0.60.619.0] - 2026-11-08
**`gbrain git commit-push` on a managed checkout no longer reports commits the remote lacks as already pushed.** On a managed canonical worktree, commit-push commits only the named paths and leaves publishing to the persistence owner. When the commit already existed (a script's bare commit, or one an earlier call made), it printed `nothing to commit; origin/main at -`, exited 0 and logged `[push] ok-already-on-remote`, which the push-log reader behind `put_page`'s `lastPushStatus` and doctor counts as a push that landed, while the branch sat ahead of (or diverged from) its upstream. It now says nothing was pushed, reports how many commits the upstream lacks as last fetched (`unpublished` in `--json`), names the command that publishes them, and writes no push-log line. Nothing is pushed or moved; exit codes are unchanged.
diff --git a/src/core/git/range-secret-scan.ts b/src/core/git/range-secret-scan.ts
index 8c9e02bccd..621eda0024 100644
--- a/src/core/git/range-secret-scan.ts
+++ b/src/core/git/range-secret-scan.ts
@@ -7,7 +7,8 @@
* Findings carry the path, line, rule, fingerprint and commit, never the matched value.
*
* Only plumbing reads the commits (`rev-list`, `cat-file commit`, one `diff-tree --stdin --root --cc`), so no log, diff or
- * encoding setting changes what is read, and replace refs are off. The diff streams to a private temporary file and is
+ * encoding setting changes what is read, and replace refs and the system attributes file are off. A message that declares
+ * an encoding other than UTF-8 is also scanned as its raw bytes, and one the scan cannot decode makes the result unreadable. The diff streams to a private temporary file and is
* read in chunks, so memory stays bounded. Binary detection is git's own (a NUL in a blob's first 8000 bytes), with
* attributes read from the empty tree: a file git still calls binary is checked by its own bytes when its old side was
* not empty or attributes could still apply, and a text file is then scanned whole. Added text over the scan cap is
@@ -47,7 +48,7 @@ function run(root: string, args: string[], deadline: number, opts: { input?: str
const timeout = deadline - Date.now();
if (timeout <= 0) throw new Unreadable('the scan ran past its time budget');
return spawnSync('git', ['-C', root, ...args], { input: opts.input ?? '', stdio: ['pipe', opts.out ?? 'pipe', 'pipe'], timeout,
- maxBuffer: opts.maxBuffer ?? 64 * 1024 * 1024, env: gitChildEnv({ ...GIT_ENV, ...GIT_READ_ENV, LC_ALL: 'C', GIT_NO_REPLACE_OBJECTS: '1' }) });
+ maxBuffer: opts.maxBuffer ?? 64 * 1024 * 1024, env: gitChildEnv({ ...GIT_ENV, ...GIT_READ_ENV, LC_ALL: 'C', GIT_NO_REPLACE_OBJECTS: '1', GIT_ATTR_NOSYSTEM: '1' }) });
}
function must(r: Run, what: string): Buffer {
if (r.error || r.status !== 0) {
@@ -117,11 +118,18 @@ export function scanRange(root: string, base: string, head: string, timeoutMs =
const object = must(raw, 'cat-file commit');
const split = object.indexOf('\n\n');
const encoding = /^encoding (.+)$/m.exec(object.subarray(0, split < 0 ? object.length : split).toString('latin1'))?.[1]?.trim() ?? 'utf-8';
+ const bytes = split < 0 ? Buffer.alloc(0) : object.subarray(split + 2);
let message: string;
- try { message = new TextDecoder(encoding).decode(split < 0 ? Buffer.alloc(0) : object.subarray(split + 2)); } catch {
- scan.unscanned.push({ path: MESSAGE_PATH, commit }); continue;
+ try { message = new TextDecoder(encoding).decode(bytes); } catch {
+ throw new Unreadable(`commit ${commit.slice(0, 12)} declares message encoding ${JSON.stringify(encoding.slice(0, 40))}, which the scan cannot decode`);
}
+ const before = scan.findings.length;
scanned(MESSAGE_PATH, commit, message);
+ if (/^utf-?8$/i.test(encoding)) continue;
+ const seen = new Set(scan.findings.slice(before).map(f => `${f.line}:${f.fingerprint}`));
+ for (const f of scanText(bytes.toString('latin1'), { allowlist })) {
+ if (!seen.has(`${f.line}:${f.fingerprint}`)) scan.findings.push({ path: MESSAGE_PATH, commit, line: f.line, pattern: f.pattern, fingerprint: f.fingerprint });
+ }
}
const neutral = attributesNeutral(root, deadline);
diff --git a/test/guarded-publish.test.ts b/test/guarded-publish.test.ts
index 5d1b42c65b..516527cd7c 100644
--- a/test/guarded-publish.test.ts
+++ b/test/guarded-publish.test.ts
@@ -11,11 +11,13 @@
*/
import { afterAll, expect, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
-import { mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { commitAndPush } from '../src/core/git/commit-push.ts';
+import { scanRange } from '../src/core/git/range-secret-scan.ts';
import { SCAN_MAX_FILE_BYTES } from '../src/core/secret-scan.ts';
+import { withEnv } from './helpers/with-env.ts';
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'gbrain-guarded-publish-')));
afterAll(() => rmSync(dir, { recursive: true, force: true }));
@@ -187,3 +189,35 @@ test('commits the scan cannot read refuse with their own code, not as secrets to
expect(error.message).not.toContain('look like secrets');
expect(remoteTip(r)).toBe(r.base);
});
+
+test('a token in a commit message that declares UTF-16 is still found in its raw bytes', () => {
+ const r = repo('utf16-message');
+ git(r.root, 'config', 'i18n.commitEncoding', 'UTF-16LE');
+ commit(r.root, 'page.md', 'a page\n', `rotate ${token}`);
+ expect(refused(() => publish(r.root)).message).toContain('(commit message):1 (');
+ expect(remoteTip(r)).toBe(r.base);
+});
+
+test('a commit message in an encoding the scan cannot decode refuses as unreadable, not as too large', () => {
+ const r = repo('utf7-message');
+ git(r.root, 'config', 'i18n.commitEncoding', 'UTF-7');
+ commit(r.root, 'page.md', 'a page\n', 'plain message');
+ const error = refused(() => publish(r.root));
+ expect(error.code).toBe('publish_scan_unreadable');
+ expect(error.message).not.toContain('too large to scan');
+ expect(remoteTip(r)).toBe(r.base);
+});
+
+test('every git call the scan makes ignores the system gitattributes file', async () => {
+ const r = repo('nosystem');
+ commit(r.root, 'notes.md', 'plain\n');
+ const bin = join(dir, 'git-spy'), log = join(dir, 'git-spy.log');
+ const real = execFileSync('sh', ['-c', 'command -v git'], { encoding: 'utf8' }).trim();
+ mkdirSync(bin);
+ writeFileSync(join(bin, 'git'), `#!/bin/sh\nprintf '%s\\n' "\${GIT_ATTR_NOSYSTEM:-unset}" >> '${log}'\nexec '${real}' "$@"\n`, { mode: 0o755 });
+ const scan = await withEnv({ PATH: `${bin}:${process.env.PATH}` }, async () => scanRange(r.root, 'refs/remotes/origin/main', 'HEAD'));
+ expect(scan.unreadable).toBeUndefined();
+ const calls = readFileSync(log, 'utf8').trim().split('\n');
+ expect(calls.length).toBeGreaterThan(3);
+ expect(calls.filter(value => value !== '1')).toEqual([]);
+});