From 0400d7bbe7a2c6f4bf65b5242b993a2c508b28aa Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 03:47:41 +0100 Subject: [PATCH] FORGE-5: forge_calls reads the merge calls; forge_call_say_again says one again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit forge_calls answers the kept calls newest first with each member's base, head and state; forge_call_say_again, with call and why, says a call's merge-called again once the hand-act log took it. Builds: design 47 H §766 (its tools); H-A-18 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy --- modules/gitea/index.ts | 2 +- modules/gitea/test/calls.test.ts | 25 +++++++++++++ modules/gitea/test/merge-partial.test.ts | 4 +-- modules/gitea/tools/calls.ts | 45 ++++++++++++++++++++++-- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/modules/gitea/index.ts b/modules/gitea/index.ts index 11bf2f3d9..03d24ebd4 100644 --- a/modules/gitea/index.ts +++ b/modules/gitea/index.ts @@ -422,7 +422,7 @@ registerModuleTools("gitea", () => [eventsTool(pace), ...readAllTools(readAll), async (act) => { await broker().request("seat:mesh-hand-acts.hand-act", act); }), ...(gitea ? seatTools(gitea, { run, container: FORGE_CONTAINER, statuses: gates, registered: () => registrations.written, judge: (head) => failedSteps.judge(head), watched: () => registrations.watched, calls, say: seatPublish, partials }) : []), - ...callTools(partials, async (act) => { await broker().request("seat:mesh-hand-acts.hand-act", act); }), + ...callTools(calls, partials, seatPublish, async (act) => { await broker().request("seat:mesh-hand-acts.hand-act", act); }), ...failedStepsTools(failedSteps, async (act) => { await broker().request("seat:mesh-hand-acts.hand-act", act); })]); /** What the forge's event asks of the announcer at once (issue 729, 1422): see watch.ts. */ diff --git a/modules/gitea/test/calls.test.ts b/modules/gitea/test/calls.test.ts index 5caeb15b0..fddb0574a 100644 --- a/modules/gitea/test/calls.test.ts +++ b/modules/gitea/test/calls.test.ts @@ -92,3 +92,28 @@ test("a call says one merge-called of what landed; none for a call that landed n assert.equal(said[0].body.refused, undefined, "a member not merged after a stop is no refused member"); assert.deepEqual(await sayUnsaid(calls, say), [], "said once"); }); + +// The merge calls' tools (design 47 H §766): forge_calls answers the calls newest first with each member's state, and +// forge_call_say_again says a call's merge-called again once the hand-act log took it. +test("forge_calls reads the calls newest first; forge_call_say_again says one again after the hand-act log", async () => { + const { Calls } = await import("../dist/calls.js"); + const { Partials } = await import("../dist/partials.js"); + const { callTools } = await import("../dist/tools/calls.js"); + const { st } = memory(); + const calls = new Calls(st as any); + const m = (n: number, state: string) => ({ repository: "novox/app", number: n, branch: "main", head: A, state, ...(state === "merged" ? { commit: String(n).repeat(40) } : {}) }); + await calls.put("00000000000000aa", { by: "a@b", account: "x", at: "2026-11-20T01:00:00Z", members: [m(1, "merged")], said: true } as any); + await calls.put("00000000000000bb", { by: "a@b", account: "x", at: "2026-11-20T02:00:00Z", members: [m(2, "refused")], said: true } as any); + const said: any[] = [], acts: any[] = []; + const tools = callTools(calls, new Partials(memory().st as any, calls), async (subject: string, body: unknown) => { said.push([subject, body]); }, + async (a) => { acts.push(a); }); + const tool = (name: string) => tools.find((t) => t.name === name)!; + const read: any = await tool("forge_calls").run({}); + assert.deepEqual(read.calls.map((c: any) => [c.call, c.members[0].state]), [["00000000000000bb", "refused"], ["00000000000000aa", "merged"]]); + await assert.rejects(tool("forge_call_say_again").run({ call: "00000000000000aa" }), /names the call .* and why/); + await assert.rejects(tool("forge_call_say_again").run({ call: "00000000000000ff", why: "x" }), /keeps no merge call/); + const again: any = await tool("forge_call_say_again").run({ call: "00000000000000aa", why: "the gate missed it" }); + assert.deepEqual([again.said, acts[0].verb, said[0][0]], [true, "forge_call_say_again", "mesh.seat.git.event.merge-called.00000000000000aa"]); + const none: any = await tool("forge_call_say_again").run({ call: "00000000000000bb", why: "x" }); + assert.equal(none.said, false, "a call that landed none says none"); +}); diff --git a/modules/gitea/test/merge-partial.test.ts b/modules/gitea/test/merge-partial.test.ts index fbb1b1ffd..12d6a5b7d 100644 --- a/modules/gitea/test/merge-partial.test.ts +++ b/modules/gitea/test/merge-partial.test.ts @@ -57,9 +57,9 @@ test("the forge refusing the second merge says what landed, raises merge-partial await run("00000000000000cc", [5, 9]); assert.equal(findings.kv.has(partialKey("00000000000000cc")), true); const acts: any[] = []; - const tool = callTools(partials, async (a) => { acts.push(a); }).find((t) => t.name === "forge_partial_clear")!; + const tool = callTools(calls, partials, async () => {}, async (a) => { acts.push(a); }).find((t) => t.name === "forge_partial_clear")!; await assert.rejects(tool.run({ call: "00000000000000cc" }), /names the call .* and why/); - const failing = callTools(partials, async () => { throw new Error("down"); }).find((t) => t.name === "forge_partial_clear")!; + const failing = callTools(calls, partials, async () => {}, async () => { throw new Error("down"); }).find((t) => t.name === "forge_partial_clear")!; await assert.rejects(failing.run({ call: "00000000000000cc", why: "dropped" }), /not recorded, so nothing was cleared/); assert.equal(findings.kv.has(partialKey("00000000000000cc")), true); const done: any = await runAs({ "mesh/caller": "person.jochen" }, {}, () => tool.run({ call: "00000000000000cc", why: "the lib change is dropped" })); diff --git a/modules/gitea/tools/calls.ts b/modules/gitea/tools/calls.ts index 15ddaa5a4..5737a80eb 100644 --- a/modules/gitea/tools/calls.ts +++ b/modules/gitea/tools/calls.ts @@ -1,15 +1,54 @@ -// The tools of the forge module's merge calls (novox/hq design 47 H §766, §767): forge_partial_clear clears a call's -// merge-partial by hand, written in the hand-act log before it is done. +// The tools of the forge module's merge calls (novox/hq design 47 H §766, §767): forge_calls reads the calls, newest first, +// with each member's state; forge_call_say_again says a call's merge-called again; forge_partial_clear clears a call's +// merge-partial by hand. Each act is written in the hand-act log before it is done. import type { ToolDefinition } from "@novox/mesh-sdk/tools"; import { callerOf } from "@novox/mesh-sdk/callers"; import type { HandAct } from "@novox/mesh-sdk/views"; import type { Partials } from "../partials.js"; +import { sayCall, type Calls, type Say } from "../calls.js"; const word = (v: unknown): string => (typeof v === "string" ? v.trim() : ""); -export function callTools(partials: Partials, acts: (act: HandAct) => Promise): ToolDefinition[] { +export function callTools(calls: Calls, partials: Partials, say: Say, acts: (act: HandAct) => Promise): ToolDefinition[] { return [ + { + name: "forge_calls", + description: "The merge calls the forge module keeps (its state calls), newest first: each call's by, account, when, whether its merge-called " + + "was said, and each member with its base, head and state (judged, merged with its commit, or refused with why) (design 47 H §766).", + input: { type: "object", properties: { call: { type: "string", description: "only this merge call" } } }, + run: async (args: Record) => { + const only = word(args.call); + const all = await calls.all(); + return { calls: only ? all.filter((c) => c.call === only) : all }; + }, + }, + { + name: "forge_call_say_again", + description: "Says one merge call's merge-called again, for what it landed, with why: a gate that missed it takes the call in. " + + "Written in the hand-act log first (design 47 H §766).", + input: { type: "object", required: ["call", "why"], properties: { + call: { type: "string", description: "the merge call, 16 lowercase hex characters" }, + why: { type: "string", description: "why it is said again, in plain words" } } }, + run: async (args: Record) => { + const call = word(args.call), why = word(args.why); + if (!/^[0-9a-f]{16}$/.test(call) || !why) throw new Error("forge_call_say_again names the call (16 lowercase hex characters) and why"); + const kept = await calls.get(call); + if (!kept) throw new Error(`the forge module keeps no merge call ${call}`); + const by = callerOf(args); + try { + await acts({ what: `said the merge-called of the merge call ${call} again`, why: `${why} (${by})`, cause: "merge-called-said-again", verb: "forge_call_say_again" }); + } catch (err) { + throw new Error(`the hand act was not recorded, so nothing was said: ${err instanceof Error ? err.message : String(err)}`); + } + const said = await sayCall(kept, say); + if (said && !kept.said) { + const { call: _c, ...value } = kept; + await calls.put(call, { ...value, said: true }); + } + return { call, said, why, by, ...(said ? {} : { "said-none": "the call landed no member, so it says no merge-called" }) }; + }, + }, { name: "forge_partial_clear", description: "Clears the finding merge-partial of one merge call (a call the forge refused a member of after every member was judged), " +