Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(git): the managed put_page fix names its source in the CLI argv and MCP arguments (GST-2116)
garrytand88b3b71be04
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.tsindex d4323934a2..6c2433c93e 100644--- a/src/core/git/commit-push.ts+++ b/src/core/git/commit-push.ts@@ -518,14 +518,16 @@ function skippedPathsError(root: string, skipped: SkippedPath[], result: CommitP({ argv, consent: [], actor: 'agent', requires_exclusive: false, why: 'Clears the flag so git sees the edit on disk; the file keeps its bytes.', ...(then ? { then } : {}) }), last);const pages = managed ? skipped.filter(s => isSyncable(s.path)) : [];if (managed && pages.length) {- const put: Action = { argv: ['gbrain', 'put', '<slug>'], mcp: { tool: 'put_page', arguments: { slug: '<slug>', content: '<the page file>' } },+ const source = managed.sourceId ? { argv: ['--source-id', managed.sourceId], mcp: { source_id: managed.sourceId } } : { argv: [], mcp: {} };+ const put: Action = { argv: ['gbrain', 'put', ...source.argv, '<slug>'],+ mcp: { tool: 'put_page', arguments: { slug: '<slug>', ...source.mcp, content: '<the page file>' } },inputs: [{ name: 'slug', how: `Each listed page path without its .md extension; pass the file's content on stdin: ${pages.slice(0, 5).map(s => s.path).join(', ')}` }],consent: [], actor: 'agent', requires_exclusive: false,why: 'put_page saves the page through the owner, which writes the file, commits only that path and pushes it.',verify: { argv: ['gbrain', 'sources', 'writer', 'status', managed.sourceId ?? '<source>', '--json'] } };return opError('writer_coordinator_required',`${root} is the managed canonical worktree${managed.sourceId ? ` of source ${managed.sourceId}` : ''}, and git did not commit ${skipped.length} named path(s): ${list}. ${rest}`,- `${clears.length ? `First, with the user's agreement, clear the flags (${clearCommand}), since the owner's own Git step cannot see a flagged edit either. ` : ''}Then save those pages through gbrain (put_page, edit_page or capture; on the CLI, gbrain put with the page slug and the page on stdin): the persistence owner commits and pushes them. Never commit page files around it.`,+ `${clears.length ? `First, with the user's agreement, clear the flags (${clearCommand}), since the owner's own Git step cannot see a flagged edit either. ` : ''}Then save those pages through gbrain (put_page, edit_page or capture; on the CLI, gbrain put${managed.sourceId ? ` --source-id ${managed.sourceId}` : ''} with the page slug and the page on stdin): the persistence owner commits and pushes them. Never commit page files around it.`,{ docs, detail,why: 'The persistence owner is the only Git writer of pages in a managed worktree; a page file written there directly and left uncommitted is neither in Git nor in the database, so reporting success would lose the write silently.',fix: { ...(chain(clears, put) ?? put), ask_user: true,diff --git a/test/git-commit-push-skipped-paths-gst2116.test.ts b/test/git-commit-push-skipped-paths-gst2116.test.tsindex ba170adb82..37ee3adf31 100644--- a/test/git-commit-push-skipped-paths-gst2116.test.ts+++ b/test/git-commit-push-skipped-paths-gst2116.test.ts@@ -14,7 +14,7 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSyimport { tmpdir } from 'node:os';import { join } from 'node:path';import { renderCommitPushHelper } from '../src/core/brain-repo-durability.ts';-import { commitPathsLocked } from '../src/core/git/commit-push.ts';+import { commitAndPush, commitPathsLocked } from '../src/core/git/commit-push.ts';import { recordManagedRoots } from '../src/core/persistence/root-registry.ts';import { runCli } from './helpers/cli-spawn.ts';import { withEnv } from './helpers/with-env.ts';@@ -337,3 +337,22 @@ test('classic: a named assume-unchanged gitlink beside a committed page leaves texpect(git(f.brain, 'diff', '--cached', '--name-only')).toBe('');}, 60_000);+test('managed: the put_page fix names the managed source in both the CLI argv and the MCP arguments', async () => {+ const f = fixture('managed-source', 'managed');+ const path = nestedPage(f, 'carol-example.md');+ const r = await commitPush(f, path);+ expect(r.exitCode).not.toBe(0);+ const e = JSON.parse(r.stdout) as { code: string; fix?: { argv?: string[] } };+ expect(e.code).toBe('writer_coordinator_required');+ const argv = e.fix?.argv ?? [];+ expect(argv.slice(0, 2)).toEqual(['gbrain', 'put']);+ expect(argv.indexOf('--source-id')).toBeGreaterThan(1);+ expect(argv[argv.indexOf('--source-id') + 1]).toBe('source-a');+ const thrown = await withEnv({ GBRAIN_HOME: f.home }, () => {+ try { commitAndPush({ repo: f.brain, paths: [path], message: 'write pages', cwd: f.brain }); } catch (err) { return err as { code?: string; fix?: { mcp?: { tool: string; arguments: Record<string, unknown> } } }; }+ return null;+ });+ expect(thrown?.code).toBe('writer_coordinator_required');+ expect(thrown?.fix?.mcp?.tool).toBe('put_page');+ expect(thrown?.fix?.mcp?.arguments.source_id).toBe('source-a');+}, 60_000);