Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Keep the published QM contract versions unchanged (GBRA-504)
garrytan529a81495f02
diff --git a/docs/contracts/qm-memory-provider/v2.json b/docs/contracts/qm-memory-provider/v2.jsonindex 8d5dd9cf9d..1dad8d23eb 100644--- a/docs/contracts/qm-memory-provider/v2.json+++ b/docs/contracts/qm-memory-provider/v2.json@@ -42,7 +42,6 @@"loops_mute","loops_unmute","ontology_propose",- "promote_guest_note","put_page","put_pages","put_raw_data",diff --git a/docs/contracts/qm-memory-provider/v3.json b/docs/contracts/qm-memory-provider/v3.jsonindex 292180bd32..d8b9d8f2d7 100644--- a/docs/contracts/qm-memory-provider/v3.json+++ b/docs/contracts/qm-memory-provider/v3.json@@ -42,7 +42,6 @@"loops_mute","loops_unmute","ontology_propose",- "promote_guest_note","put_page","put_pages","put_raw_data",diff --git a/docs/contracts/qm-memory-provider/v4.json b/docs/contracts/qm-memory-provider/v4.jsonindex 9e90eadeda..6e4f25180f 100644--- a/docs/contracts/qm-memory-provider/v4.json+++ b/docs/contracts/qm-memory-provider/v4.json@@ -42,7 +42,6 @@"loops_mute","loops_unmute","ontology_propose",- "promote_guest_note","put_page","put_pages","put_raw_data",diff --git a/docs/contracts/qm-memory-provider/v5.json b/docs/contracts/qm-memory-provider/v5.jsonindex d49ce542a4..12264cfd0c 100644--- a/docs/contracts/qm-memory-provider/v5.json+++ b/docs/contracts/qm-memory-provider/v5.json@@ -42,7 +42,6 @@"loops_mute","loops_unmute","ontology_propose",- "promote_guest_note","put_page","put_pages","put_raw_data",diff --git a/scripts/build-qm-memory-contract.ts b/scripts/build-qm-memory-contract.tsindex 5b11535d5c..39b1a08da1 100644--- a/scripts/build-qm-memory-contract.ts+++ b/scripts/build-qm-memory-contract.ts@@ -42,6 +42,11 @@ const V1_PARAMS: Record<string, readonly string[]> = { memory_recall: ['query',const V2_PARAMS: Record<string, readonly string[]> = { memory_recall: [...V1_PARAMS.memory_recall!, 'source_id', 'source_ids'], memory_write: [...V1_PARAMS.memory_write!, 'source_id'] };/** The deferred operations v1 published, frozen: GST-1158 F9 deferred more from v2 on. */const V1_DEFERRED_OPS: readonly string[] = ['capture', 'extract_facts', 'list_write_conflicts', 'takes_add', 'takes_resolve', 'takes_supersede', 'takes_update'];+/**+ * Operations deferred after v5 was published (GBRA-504 promote_guest_note). A published version never changes, so v1 to+ * v5 leave them out and every later version lists them; an attested call is refused them either way.+ */+const DEFERRED_AFTER_V5: ReadonlySet<string> = new Set(['promote_guest_note']);/** Catalogue summaries v1 published before they changed, frozen. */const V1_SUMMARIES: Record<string, string> = {actor_not_attested: "A call named the person it serves (the x-qm-actor header or the acting_user argument) in a way gbrain does not honour: the credential holds no attest right, the operation is not in its attested operations, the argument differs from the header or comes without an attested header, or the id is not 1-256 visible ASCII characters; or a write that saves only as an attested person (memory_write) named none; or the request carries x-qm-audience, a channel audience gbrain does not serve yet. Nothing was read or written.",@@ -199,7 +204,7 @@ export function buildQmMemoryContract(version: QmContractVersion): Record<string? 'optional; on an attested call it must equal the header; with no header it is accepted only from a credential bound to a member and only naming that member (its member id or a canonical id linked to it), and the call then runs exactly as the credential; never chooses the person on its own': 'optional; must equal the header; never chooses the person on its own',actor_id: { pattern: EXTERNAL_ID_RE.source, case_folding: false },- system: 'qm', default_attest_ops: [...DEFAULT_ATTEST_OPS], deferred_ops: v2 ? [...ACTOR_DEFERRED_OPS].sort() : [...V1_DEFERRED_OPS],+ system: 'qm', default_attest_ops: [...DEFAULT_ATTEST_OPS], deferred_ops: v2 ? [...ACTOR_DEFERRED_OPS].filter(op => version > 5 || !DEFERRED_AFTER_V5.has(op)).sort() : [...V1_DEFERRED_OPS],audit: 'the audit trail and stored writes record the canonical external id as sent, with its linked member',},tools: [...QM_MEMORY_OPS, ...(v4 ? ['memory_propose'] : [])].sort().map(name => toolEntry(name, version)),diff --git a/test/qm-memory-contract.test.ts b/test/qm-memory-contract.test.tsindex 90e91b6242..4e0ba3bc4f 100644--- a/test/qm-memory-contract.test.ts+++ b/test/qm-memory-contract.test.ts@@ -30,6 +30,8 @@ const V2_SHA256 = '5458aa92d9495c391b7ec96978a16d4f7ea9841994e8e9163da1205223f1fconst V3_SHA256 = 'cf4e3f514c57bcd381c1bc0846a0de105dd2a0fbbf361aaa08175cd8bfe0760b';/** The v4 bytes as they landed (v0.60.666.0, #9152). */const V4_SHA256 = '51f2ee77f0925f6ac19ecc116eeb6d7527d00b8a2962ebbad939f61d0afa3b2f';+/** The v5 bytes as they landed on master (GST-2407); an operation deferred later (GBRA-504 promote_guest_note) stays out. */+const V5_SHA256 = '524b3d62fcf2a30c5c2a08d08467461b0995f0503069c84356d15a08724129f2';describe('QM memory-provider contract v1', () => {const fixture = JSON.parse(readFileSync(QM_CONTRACT_PATH, 'utf8'));@@ -358,8 +360,8 @@ describe('QM memory-provider contract v5 (GST-2407: context_pack reads its namedexpect(readFileSync(QM_CONTRACT_PATHS[5], 'utf8')).toBe(renderQmMemoryContract(5));});- test('v1 to v4 stay byte for byte as published, on disk and as the builder renders them', () => {- for (const [version, want] of [[1, V1_SHA256], [2, V2_SHA256], [3, V3_SHA256], [4, V4_SHA256]] as const) {+ test('v1 to v5 stay byte for byte as published, on disk and as the builder renders them', () => {+ for (const [version, want] of [[1, V1_SHA256], [2, V2_SHA256], [3, V3_SHA256], [4, V4_SHA256], [5, V5_SHA256]] as const) {expect({ version, disk: sha(readFileSync(QM_CONTRACT_PATHS[version])), built: sha(renderQmMemoryContract(version)) }).toEqual({ version, disk: want, built: want });}});