Files
mesh-catalog/modules/gitea/partials.ts
T
jschoubben 3ba309c5e4 FORGE-4: a member the forge refuses after judging raises merge-partial
The call stops merging, says merge-called with what landed and refused,
and raises merge-partial (scope delivery, id the call, urgent, resolver
operator) in the module's findings; a later call landing every refused
member clears it, and forge_partial_clear clears one by hand after the
hand-act log took it.

Builds: design 47 H §767; H-A-1, H-A-18, H-A-81

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 03:46:59 +01:00

79 lines
4.2 KiB
TypeScript

// **A member refused after every member was judged is said and raised** (novox/hq design 47 H §767; H-A-1, H-A-18,
// H-A-81): when the forge refuses a member after all were judged, the call stops merging and the forge module raises the
// finding `merge-partial`, scope `delivery`, id the call, naming each refused member, severity urgent, resolver operator,
// in its own state `findings`, which the condition keeper reads. It clears it when a later call lands every refused member
// (read from its own `calls`), or by its tool `forge_partial_clear` with `call` and `why`, written in the hand-act log.
import type { State } from "@novox/mesh-sdk/state";
import { findingKey } from "./catalog.js";
import type { Calls, KeptCall } from "./calls.js";
export const MERGE_PARTIAL = "merge-partial";
const SCOPE = "delivery";
/** The key of a call's merge-partial in the state findings. */
export const partialKey = (call: string): string => findingKey(SCOPE, call, MERGE_PARTIAL);
/** A member's name in a finding, `<repository>#<number>`. */
const named = (m: { repository: string; number: number }) => `${m.repository}#${m.number}`;
/** The merge-partial of a call the forge refused a member of after judging, as the condition keeper reads it. */
export function partialValue(c: KeptCall, observer = "gitea"): { key: string; value: Record<string, unknown> } {
const key = partialKey(c.call);
const landed = c.members.filter((m) => m.state === "merged").map(named);
const refused = c.members.filter((m) => m.state === "refused");
const summary = `the merge call ${c.call} by ${c.by} landed ${landed.length ? landed.join(", ") : "none"} and not ` +
refused.map((m) => `${named(m)} (${m.why ?? "refused"})`).join(", ");
return { key, value: {
v: 1, key, kind: MERGE_PARTIAL, subject: { scope: SCOPE, id: c.call }, severity: "urgent", resolver: "operator", summary,
headline: `A merge call landed in part: ${refused.map(named).join(", ")} not merged`,
explanation: `The forge refused ${refused.map(named).join(", ")} after every member of the merge call ${c.call} was judged, so ` +
`the repositories stand half-merged. A later merge call that lands them clears this, or forge_partial_clear with why.`,
resolved: "", evidence: [{ at: c.at, said: summary }], source: `${observer}.${MERGE_PARTIAL}`, observer, at: c.at,
} };
}
export class Partials {
constructor(private readonly findings: State<unknown>, private readonly calls: Calls,
private readonly log: (line: string) => void = () => {}) {}
/** Raises merge-partial for a call the forge refused a member of after judging. */
async raise(c: KeptCall): Promise<void> {
const f = partialValue(c);
await this.findings.put(f.key, f.value);
this.log(`merge-partial raised: ${String(f.value.summary)}`);
}
/** The calls whose merge-partial is held, newest first. */
async held(): Promise<KeptCall[]> {
const out: KeptCall[] = [];
for (const c of await this.calls.all()) if ((await this.findings.get(partialKey(c.call)))?.value) out.push(c);
return out;
}
/** After a call landed members: every held merge-partial whose refused members a later call landed, each, is cleared.
* Answers the calls cleared. */
async landed(): Promise<string[]> {
const all = await this.calls.all(); // newest first
const cleared: string[] = [];
for (const [i, c] of all.entries()) {
if (!(await this.findings.get(partialKey(c.call)))?.value) continue;
const later = new Set(all.slice(0, i).flatMap((x) => x.members.filter((m) => m.state === "merged").map(named)));
const refused = c.members.filter((m) => m.state === "refused").map(named);
if (refused.every((r) => later.has(r))) {
await this.findings.delete(partialKey(c.call));
cleared.push(c.call);
this.log(`merge-partial of ${c.call} cleared: a later call landed ${refused.join(", ")}`);
}
}
return cleared;
}
/** Clears one call's merge-partial by hand (forge_partial_clear); answers whether one was held. */
async clear(call: string): Promise<boolean> {
const held = !!(await this.findings.get(partialKey(call)))?.value;
if (held) await this.findings.delete(partialKey(call));
return held;
}
}