Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(trust): thin-client trust refusal keeps the typed ref in its fix argv; write_origin.channel names the verb, never a caller's fact or take kind
garrytan3dd0a8dd7783
diff --git a/src/cli.ts b/src/cli.tsindex 6193b19810..5787e39876 100755--- a/src/cli.ts+++ b/src/cli.ts@@ -1913,11 +1913,11 @@ function refuseThinClient(command: string, mcpUrl: string): never {}), command);}-/** The refused invocation's subcommand word (id-shaped only, per A1 argv safety), for the host-side fix. */+/** The refused invocation's subcommand word and, for `trust`, its typed ref (id-shaped only, per A1 argv safety), for the host-side fix. */function thinRefusalSubcommand(command: string): string[] {const argv = process.argv.slice(2);- const next = argv[argv.indexOf(command) + 1] ?? '';- return argv.includes(command) && /^[a-z][a-z0-9-]*$/.test(next) ? [next] : [];+ const [next = '', ref = ''] = argv.slice(argv.indexOf(command) + 1); // #5575: `trust <verb> <ref>` keeps its typed ref (f12, tp7, p:source/slug)+ return argv.includes(command) && /^[a-z][a-z0-9-]*$/.test(next) ? [next, ...(command === 'trust' && /^(?:(?:f|t|h|e|a|tp)\d{1,18}|p:[a-z0-9_-]{1,64}\/[a-z0-9][a-z0-9/_.-]{0,200})$/.test(ref) ? [ref] : [])] : [];}const THIN_CLIENT_BRAIN_FLAG_MESSAGE = '--brain is not supported on a thin-client install: the remote server is a single brain.';diff --git a/src/core/trust/channel.ts b/src/core/trust/channel.tsindex c60909edbb..7ebd102b4b 100644--- a/src/core/trust/channel.ts+++ b/src/core/trust/channel.ts@@ -55,9 +55,19 @@ export const OWN_SESSION_HARNESSES: readonly string[] = ['claude-code', 'codex', 'openclaw', 'cursor', 'hermes', 'gemini-cli', 'opencode', 'chatgpt', 'claude', 'grok',];+/**+ * The internal intent kind of a journaled request (`managed_*`, `connector_v2_*`,+ * `canonical_reconcile`, `code_projection_reindex`), or ''. A caller's own `kind`+ * param (a fact kind on remember, a take kind on takes_add) is not a channel.+ */+function internalIntentKind(intent: Record<string, unknown> | null | undefined): string {+ const kind = typeof intent?.kind === 'string' ? intent.kind : '';+ return /^(?:managed_|connector_v2_|canonical_|code_projection_)/.test(kind) ? kind : '';+}+/** The origin channel name of a journaled request, e.g. `mcp:put_page`, `cli:remember`, `connector:google`. */export function requestChannel(row: Pick<WriteRequest, 'operation' | 'authority' | 'intent'>): string {- const kind = typeof row.intent?.kind === 'string' ? row.intent.kind : '';+ const kind = internalIntentKind(row.intent);if (kind.startsWith('connector_v2_') || kind.startsWith('managed_connector_')) return `connector:${kind}`;if (kind) return kind;return `${row.authority?.remote === true ? 'mcp' : 'cli'}:${row.operation}`;@@ -75,7 +85,7 @@ export function intentContentOrigin(intent: Record<string, unknown> | null | und* maintenance) or that write no tiered rows. Undeclared rows stamp `unknown`.*/export function requestChannelTrust(row: Pick<WriteRequest, 'id' | 'operation' | 'authority' | 'intent'>): WriteTrust | undefined {- const kind = typeof row.intent?.kind === 'string' ? row.intent.kind : '';+ const kind = internalIntentKind(row.intent);const origin = { channel: requestChannel(row), request_id: row.id };if (kind.startsWith('connector_v2_') || kind.startsWith('managed_connector_')) return effectiveWriteTrust({ channel: 'external_untrusted', origin });if (row.authority?.remote === true) {diff --git a/test/trust-channel-writes.test.ts b/test/trust-channel-writes.test.tsindex 4017b149dd..21e8e7b4c3 100644--- a/test/trust-channel-writes.test.ts+++ b/test/trust-channel-writes.test.ts@@ -172,6 +172,10 @@ describe('channel tiers on journaled writes', () => {const fenced = await pageRow(b, 'people/alice-example');expect(fenced.compiled_truth).toContain('Alice prefers green tea');expect(fenced.trust_tier).toBe('operator_curated');+ // The origin channel names the verb, never the caller's fact kind.+ const pref = await run(b.remote, 'remember', { fact: 'Alice prefers window seats', provenance: 'chat', entity: 'people/alice-example', kind: 'preference' });+ const [origin] = await engine.executeRaw<{ channel: string }>(`SELECT write_origin->>'channel' AS channel FROM facts WHERE id=$1`, [Number(pref.id)]);+ expect(origin?.channel).toBe('mcp:remember');const tool = await run(b.remote, 'remember', { fact: 'Alice moved to acme-example', provenance: 'email', entity: 'people/alice-example', content_origin: 'tool_output' });const [external] = await engine.executeRaw<{ trust_tier: string }>('SELECT trust_tier FROM facts WHERE id=$1', [Number(tool.id)]);expect(external.trust_tier).toBe('external_untrusted');diff --git a/test/trust-thin-client-refusal.test.ts b/test/trust-thin-client-refusal.test.tsnew file mode 100644index 0000000000..c0a6e313aa--- /dev/null+++ b/test/trust-thin-client-refusal.test.ts@@ -0,0 +1,36 @@+/**+ * A thin-client install refuses `gbrain trust` (owner actions run on the brain+ * host) with a host-side fix that keeps the typed ref, so the user can run the+ * exact command there (#5575 DX-3/DX-7). Spawns the CLI against a seeded+ * thin-client home; no engine or network is reached.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { runCli } from './helpers/cli-spawn.ts';++let home: string;+beforeAll(() => {+ home = mkdtempSync(join(tmpdir(), 'gbrain-trust-thin-'));+ mkdirSync(join(home, '.gbrain'), { recursive: true });+ writeFileSync(join(home, '.gbrain', 'config.json'), JSON.stringify({ engine: 'postgres', remote_mcp: {+ issuer_url: 'https://brain-host.example', mcp_url: 'https://brain-host.example/mcp', oauth_client_id: 'cid', oauth_client_secret: 'csecret' } }));+});+afterAll(() => rmSync(home, { recursive: true, force: true }));++describe('thin-client gbrain trust refusal', () => {+ test('the fix argv carries the subcommand and its typed ref; an unsafe ref is left out', async () => {+ const env = { GBRAIN_REMOTE_CLIENT_SECRET: undefined };+ const fixOf = async (args: string[]) => {+ const r = await runCli([...args, '--json'], { home, env });+ expect(r.exitCode).toBe(1);+ return (JSON.parse(r.stdout) as { code: string; fix: { argv: string[]; next: string } });+ };+ const confirm = await fixOf(['trust', 'confirm', 'f12']);+ expect(confirm.code).toBe('requires_local_engine');+ expect(confirm.fix).toMatchObject({ argv: ['gbrain', 'trust', 'confirm', 'f12'], next: 'tell_user_to_run' });+ expect((await fixOf(['trust', 'revert', 'p:default/notes/alice-example'])).fix.argv).toEqual(['gbrain', 'trust', 'revert', 'p:default/notes/alice-example']);+ expect((await fixOf(['trust', 'confirm', '$(rm -rf ~)'])).fix.argv).toEqual(['gbrain', 'trust', 'confirm']);+ }, 120_000);+});