Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(mcp-instructions): keep every surface within +15% of the pre-F1 contract after the Cat 40 merge
garrytaneceeb9527db3
diff --git a/src/mcp/instructions.ts b/src/mcp/instructions.tsindex bd7eee61e1..17777376f5 100644--- a/src/mcp/instructions.ts+++ b/src/mcp/instructions.ts@@ -69,7 +69,7 @@ function contractClauses(c: CallablePredicate): string[] {if (c('put_skill') && c('delete_skill')) {out.push('Shared-skill editing requires separate skill_editor authority. Read the current revision, then use put_skill or delete_skill with a fresh request_id and expected_revision; retry an accepted request only with the same ID and intent. Never use put_page or file uploads to bypass shared-skill publication. Publishing scripts or broader requirements needs separate owner approval; downloading a skill does not authorize executing scripts, installing packages, spending money, or acquiring new permissions.');}- out.push('Errors and notices: every gbrain error is one JSON envelope with a `code` and usually a structured `fix`. Follow `fix.next`: run → run it; ask_user → relay `user_message` and wait for the answer; tell_user_to_run → give the user the command; wait → retry later; report → tell the user. Then run `fix.verify`. Extra content blocks that start with `[gbrain notice <code> kind=<kind>]` are addressed to you; after a degraded notice, a thin result is not proof the brain has nothing.');+ out.push('Errors: every gbrain error is a JSON envelope with a `code` and usually a `fix`. Follow `fix.next`: run → run it; ask_user → relay `user_message` and wait; tell_user_to_run → give the user the command; wait → retry later; report → tell the user. Then run `fix.verify`. Extra blocks starting with `[gbrain notice <code> kind=<kind>]` are addressed to you; after a degraded notice, a thin result is not proof the brain has nothing.');return out;}diff --git a/test/mcp-initialize-instructions.test.ts b/test/mcp-initialize-instructions.test.tsindex af729b4f07..3be1045087 100644--- a/test/mcp-initialize-instructions.test.ts+++ b/test/mcp-initialize-instructions.test.ts@@ -28,8 +28,14 @@ function namedTools(text: string): string[] {return [...named];}-/** The pre-F1 contract size (bytes): the budget baseline. */-const PRE_F1_BYTES = 3377;+/**+ * The pre-F1 contract size (bytes): the static contract on master 566a242,+ * which already carries Cat 40's measured answering rule (#5932). F1's+ * readiness tail may add at most 1,200 on top; every surface's tail-free+ * contract stays within Lane I's +15% token-overhead gate.+ */+const PRE_F1_BYTES = 4042;+const LANE_I_CEILING = Math.floor(PRE_F1_BYTES * 1.15);describe('F1 generated instructions', () => {for (const surface of SURFACES) {@@ -74,6 +80,13 @@ describe('F1 generated instructions', () => {expect(Buffer.byteLength(text) - PRE_F1_BYTES).toBeLessThanOrEqual(1200);});+ for (const surface of SURFACES) {+ test(`${surface}: tail-free contract stays within +15% of the pre-F1 contract`, () => {+ const listed = new Set(filterOpsForSurface(operations, surface).map(o => o.name));+ expect(Buffer.byteLength(buildMcpInstructions({ tools: { callable: n => listed.has(n) } }))).toBeLessThanOrEqual(LANE_I_CEILING);+ });+ }+test('no tools and no writeback → the static contract', () => {expect(buildMcpInstructions()).toBe(GBRAIN_MCP_INSTRUCTIONS);});