From 9d7273c599f040163287920c29acf7395be0a353 Mon Sep 17 00:00:00 2001 From: Mute Date: Wed, 11 Nov 2026 21:26:26 +0000 Subject: [PATCH] bridge: roll tool for the player, glm 5.3 example config --- README.md | 5 +++-- bridge.example.json | 6 +++--- runs/boutique/canon/status.md | 2 +- runs/boutique/dumps/memory.sql | 3 ++- runs/prisoners/dumps/memory.sql | 2 ++ tool/bridge.mjs | 34 ++++++++++++++++++++++++--------- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4f494e1..1cd1386 100644 --- a/README.md +++ b/README.md @@ -263,8 +263,9 @@ pedantic, whatever housekeeping needs. The two prompts are independent. **Substrate:** `tool/bridge.mjs` is the thin bridge — a player session with native tools, no UI. It assembles the bundle from the run's files (views -refreshed), offers the player tools (status always; records only when the -run's gate allows — the tool list is the capability surface), executes +refreshed), offers the player tools (status and a coin-flip roll always; +records only when the run's gate allows — the tool list is the capability +surface), executes model tool calls against the clerk, logs the full exchange to `runs//sessions/.jsonl` (the housekeeping transcript), and elides old tool results to stubs in the live context (use-and-discard). diff --git a/bridge.example.json b/bridge.example.json index da5132b..ee6647e 100644 --- a/bridge.example.json +++ b/bridge.example.json @@ -1,5 +1,5 @@ { - "baseUrl": "https://api.openai.com/v1", - "model": "gpt-4o", - "apiKeyEnv": "RP_API_KEY" + "baseUrl": "https://open.bigmodel.cn/api/paas/v4", + "model": "glm-5.3", + "apiKeyEnv": "ZHIPU_API_KEY" } diff --git a/runs/boutique/canon/status.md b/runs/boutique/canon/status.md index 0ff0f52..eac1356 100644 --- a/runs/boutique/canon/status.md +++ b/runs/boutique/canon/status.md @@ -4,4 +4,4 @@ # Status -- **mood:** testing the bridge +(nothing set — fresh start) diff --git a/runs/boutique/dumps/memory.sql b/runs/boutique/dumps/memory.sql index 49ff949..345927e 100644 --- a/runs/boutique/dumps/memory.sql +++ b/runs/boutique/dumps/memory.sql @@ -51,6 +51,7 @@ CREATE TABLE IF NOT EXISTS events ( CREATE INDEX IF NOT EXISTS events_window ON events (window); BEGIN TRANSACTION; -INSERT INTO status VALUES ('mood','','testing the bridge','2026-11-11'); INSERT INTO events VALUES (1,'pc','status','s:mood','mock turn'); +INSERT INTO events VALUES (2,'pc','status','s:mood','excursion declared'); +INSERT INTO events VALUES (3,'pc','status','s:mood','field dropped'); COMMIT; diff --git a/runs/prisoners/dumps/memory.sql b/runs/prisoners/dumps/memory.sql index 2e9d9e8..14086e2 100644 --- a/runs/prisoners/dumps/memory.sql +++ b/runs/prisoners/dumps/memory.sql @@ -51,4 +51,6 @@ CREATE TABLE IF NOT EXISTS events ( CREATE INDEX IF NOT EXISTS events_window ON events (window); BEGIN TRANSACTION; +INSERT INTO events VALUES (1,'pc','status','s:mood','excursion declared'); +INSERT INTO events VALUES (2,'pc','status','s:mood','field dropped'); COMMIT; diff --git a/tool/bridge.mjs b/tool/bridge.mjs index f30c1ea..026bbe9 100644 --- a/tool/bridge.mjs +++ b/tool/bridge.mjs @@ -67,6 +67,11 @@ const STATUS_TOOLS = [ { key: { type: 'string' } }), ]; +const ROLL_TOOL = T('roll', + 'Flip a coin: pick one of the options at random. For genuinely non-obvious choices, or in-fiction chance she herself controls (a tossed coin, a drawn straw). Randomizes choices, never outcomes — whether an attempt succeeds is the GM\'s to resolve. Commit to the result; do not re-roll.', + { options: { type: 'array', items: { type: 'string' }, minItems: 2, description: 'the options, equal weight' } }, + ['options']); + const RECORD_TOOLS = [ T('records_search', 'Consult her files. Narrow terms — what this beat needs. The result is capped at 10. A miss is a miss: do not rephrase, broaden, or retry this scene.', { terms: { type: 'array', items: { type: 'string' }, description: 'all terms must match' } }, @@ -87,7 +92,7 @@ function recordsEnabled() { return false; } } -const TOOLS = [...STATUS_TOOLS, ...(recordsEnabled() ? RECORD_TOOLS : [])]; +const TOOLS = [...STATUS_TOOLS, ROLL_TOOL, ...(recordsEnabled() ? RECORD_TOOLS : [])]; // tool name → clerk argv const DISPATCH = { @@ -95,6 +100,7 @@ const DISPATCH = { status_norm: (a) => ['norm', a.key, a.baseline], status_clear: (a) => ['clear', a.key], status_drop: (a) => ['unset', a.key], + roll: (a) => ['pick', ...a.options], records_search: (a) => ['search', ...a.terms], records_file: (a) => ['file', a.kind, a.label, a.detail ?? ''], records_amend: (a) => ['amend', a.rid, a.detail], @@ -142,8 +148,10 @@ function assembleSystem() { + 'Tool mode: the mechanical verbs described above — status declarations' + ' and records work — are available to you as function tools. Prefer the' + ' tools over writing the ((...)) lines; tool calls happen between prose' - + ' beats without narrating them. The OOC channel remains for talking to' - + ' the GM: points of order, canon questions, proposals.\n'; + + ' beats without narrating them. The roll tool is your coin flip for' + + ' non-obvious choices — commit to what it returns. The OOC channel' + + ' remains for talking to the GM: points of order, canon questions,' + + ' proposals.\n'; if (!recordsEnabled()) { sys += 'There are no records tools: this character keeps no files to consult.\n'; } @@ -181,18 +189,26 @@ async function callModel(cfg, messages, tools) { function mockModel(messages) { const last = messages[messages.length - 1]; if (last.role === 'tool') { - return { role: 'assistant', content: 'Mock: the tool result is noted. *She settles back against the container, watching the light.* ((mock turn complete))' }; + if (last.content.startsWith('picked:')) { + return { + role: 'assistant', + content: null, + tool_calls: [{ + id: `mock-status-${messages.length}`, + type: 'function', + function: { name: 'status_set', arguments: JSON.stringify({ key: 'mood', value: 'committed to the roll' }) }, + }], + }; + } + return { role: 'assistant', content: 'Mock: noted. *She commits to the path the coin chose.*' }; } return { role: 'assistant', content: null, tool_calls: [{ - id: `mock-${messages.length}`, + id: `mock-roll-${messages.length}`, type: 'function', - function: { - name: 'status_set', - arguments: JSON.stringify({ key: 'mood', value: 'testing the bridge', reason: 'mock turn' }), - }, + function: { name: 'roll', arguments: JSON.stringify({ options: ['press on to the lighthouse', 'go back for Dessa'] }) }, }], }; }