Public: anyone can read this; the crew can change it.

The client list says, per sent forge, whether the link was opened, the first login happened and what the crew did since #15784

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15746-the-client-list-says-per-sent-forge-whet → main 0 commits fork

  • Merged. scout/15746-the-client-list-says-per-sent-forge-whet was merged into main as dcd9806.

Review

Sign in to review this change.
12 files changed +209 −11
docs/features/client-crew-stage.md added +13
@@ -0,0 +1,13 @@
1 ---
2 topic: Hosting forges for others, and getting paid
3 row: The client list says whether the link was opened, the person signed in and the crew is working
4 ---
5 # The client list names each forge's stage, with the crew's counts (#15746)
6
7 Each forge you sent reads one of **Link not opened**, **Opened**, **Signed in** or **Crew working**, with the time that stage began, and the agent runs and pulls its crew has made **so far** (every run and pull the forge holds; it keeps no send date to cut by). Counts show for any forge that reported them. While the crew is working, the last tell keeps its own words beside the stage.
8
9 - **On the page.** `/forges` (admin): `forgeRow` in `src/web/pages/forges.ts`.
10 - **In the terminal.** *Forges you sent* from the palette (`ctrl+k`, admins): `forgeLines` in `src/tui/screens/forges.ts`, the same words.
11 - **In MCP.** The `forges` tool, `kind: clients`: `stage`, `stageAt`, `runs`, `pulls`, `tellAt` (`clientLines`).
12 - **Source.** `stageOf` and `crewCountWords` in `src/spawn/clients.ts`; the child's counts ride its heartbeat (`crewDone`, all three fields or none).
13 - **Tests.** `bun test test/client-list-stages.test.ts`.
src/core/next-steps.ts +13
@@ -97,6 +97,19 @@ export async function nextStepsFor(
9797 ];
9898 }
9999
100 /**
101 * What the crew did here: every agent run and pull this forge holds, and when the latest began.
102 * Counts and a time only. Two COUNT(*) reads a beat (about one a minute): cheap at the sizes a
103 * forge reaches, and each count is capped at a million before it is sent.
104 */
105 export function crewDone(app: App): { crewRuns: number; crewPulls: number; crewAt: string | null } {
106 const one = (sql: string) => app.db.query<{ n: number; at: string | null }, []>(sql).get();
107 const runs = one(`SELECT COUNT(*) AS n, MAX(created_at) AS at FROM run WHERE kind = 'agent'`);
108 const pulls = one(`SELECT COUNT(*) AS n, MAX(i.created_at) AS at FROM pull p JOIN issue i ON i.id = p.issue_id`);
109 const times = [runs?.at, pulls?.at].filter((t): t is string => typeof t === "string").sort();
110 return { crewRuns: Math.min(runs?.n ?? 0, 1_000_000), crewPulls: Math.min(pulls?.n ?? 0, 1_000_000), crewAt: times.at(-1) ?? null };
111 }
112
100113 /**
101114 * Where this forge's person stands, for the heartbeat: claimed, whether they
102115 * have an everyday account (or chose to keep working as admin), and when
src/http/mcp/tools/forges.ts +1 −1
@@ -17,7 +17,7 @@ const sentSays = (n: number) => (n === 0 ? "This forge has sent no forges yet."
1717
1818 export const tool: Tool = {
1919 name: "forges",
20 doc: "an admin's list of the forges sent from here: name, address, whom for, apps, claimed, stage (sent/opened/signed in/last tell; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large) or, with `plan`, grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge out of this forge's own process into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven and put back on any failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused lists the last 20 refused first asks; `kind` clients lists each client in the page's words; `action` resend + `forge`: previews, with `dryRun: false` replaces its link",
20 doc: "an admin's list of the forges sent from here: name, address, whom for, apps, claimed, stage (link not opened/opened/signed in/crew working/last tell, with stageAt; resend true when unopened 3 days: claim_link), last activity (a person or the crew, never a heartbeat), who claimed it and when, kept (its newest backup's age, or never kept), keep cost, archive reason, reachable, size, use, madeFrom; `{ forge, plan?, dryRun? }` reads a forge's plan (small|medium|large) or, with `plan`, grants it by hand; `size` workshop raises a forge; `{ forge, sandbox: true }` reads what moving a forge out of this forge's own process into a sandbox would meet (hooks, command-running keys, size) and with `dryRun: false` moves it, proven and put back on any failure (`acknowledge: true` when it was held for what its repositories hold); each forge carries `placement` and `where`; gift codes: `codes` true lists, `code` {plan, uses?, note?, expires?} makes (shown once), `revoke` id; planned unless `dryRun` is false; `archive` a name or names stops each, writes its data and ledger as one file to the backup destination, then removes it; `restore` a name brings an archived one back; `kind` refused lists the last 20 refused first asks; `kind` clients lists each client in the page's words, with runs and pulls so far, and tellAt while the crew is working; `action` resend + `forge`: previews, with `dryRun: false` replaces its link",
2121 description:
2222 "Forges sent from here (admin), clients, a forge plan or size.",
2323 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["refused", "clients"] }, forge: { type: "string" }, plan: { type: "string" }, codes: { type: "boolean" }, code: { type: "object" }, revoke: { type: "string" }, archive: { type: ["string", "array"], items: { type: "string" } }, restore: { type: "string" }, sandbox: { type: "boolean" }, size: { type: "string" }, acknowledge: { type: "boolean" }, dryRun: { type: "boolean" } } },
src/spawn/client_words.ts +11
@@ -13,6 +13,13 @@ export interface ClientLine {
1313 /** "sent · opened · last seen", each with its time when it has one. */
1414 seen: string | null;
1515 stage: string | null;
16 /** When the stage began (ISO), or null when unknown. */
17 stageAt: string | null;
18 /** Agent runs and pulls the crew has made so far; null until the forge reports them. */
19 runs: number | null;
20 /** The last tell (ISO) while the stage is crew working, which would otherwise hide it. */
21 tellAt: string | null;
22 pulls: number | null;
1623 next: string;
1724 }
1825
@@ -27,6 +34,10 @@ export function clientLines(rows: readonly ClientRow[]): ClientLine[] {
2734 attention: r.attention === null ? null : ATTENTION_WORDS[r.attention],
2835 seen: seen === null ? null : seenParts(seen).map((p) => (p.at === null ? p.words : `${p.words} ${p.at}`)).join(" · "),
2936 stage: r.stage === null ? null : r.stage.words,
37 stageAt: r.stage === null ? null : r.stage.at,
38 runs: r.crew?.runs ?? null,
39 tellAt: r.stage?.key === "crew" ? r.nextStep.lastTellAt : null,
40 pulls: r.crew?.pulls ?? null,
3041 next: r.nextStep.key === "going" && r.nextStep.lastTellAt ? `going: last tell ${r.nextStep.lastTellAt}` : r.nextStep.words,
3142 };
3243 });
src/spawn/clients.ts +23 −2
@@ -68,6 +68,8 @@ export interface ClientRow {
6868 readonly sentAt: string | null;
6969 /** When its person first told the crew something, from its last beat; null until then. */
7070 readonly firstTellAt?: string | null | undefined;
71 /** What its crew did since it was made, from its last beat; absent until the child says. */
72 readonly crew?: { readonly runs: number; readonly pulls: number; readonly at: string | null } | undefined;
7173 /** False while the child is still being made (a resumed spawn finishes it). */
7274 readonly made: boolean;
7375 readonly claimed: boolean | null;
@@ -433,6 +435,7 @@ export async function clientRows(app: App, options: { probe?: boolean } = {}): P
433435 sentAt: c.createdAt,
434436 // Undefined until the child has beaten with the field: unknown is not "not yet".
435437 firstTellAt: beats[i]?.beat.firstTellAt,
438 crew: crewOf(beats[i]?.beat),
436439 made: c.done,
437440 claimed: claimed[i] ?? null,
438441 lastActivityAt: people[i]?.lastAt ?? null,
@@ -666,7 +669,23 @@ export function daysLeftWords(link: LinkInfo | null, now: number): string | null
666669 return days === 1 ? "1 day left" : `${days} days left`;
667670 }
668671
669 export type StageKey = "sent" | "opened" | "signedin" | "tell";
672 export type StageKey = "sent" | "opened" | "signedin" | "crew" | "tell";
673
674 /** The crew's counts from a beat, or undefined when the child did not report them. */
675 function crewOf(b: Beat | undefined): ClientRow["crew"] {
676 return b?.crewRuns === undefined || b.crewPulls === undefined ? undefined : { runs: b.crewRuns, pulls: b.crewPulls, at: b.crewAt ?? null };
677 }
678
679 /**
680 * "3 runs and 1 pull so far", or null when the child has not said. Every agent run and pull the
681 * child holds, not only those after it was sent: the child keeps no send date to cut by. Shown for
682 * any row that reported them, claimed or not, on the page, in the terminal and in MCP alike.
683 */
684 export function crewCountWords(crew: ClientRow["crew"]): string | null {
685 if (crew === undefined) return null;
686 const n = (k: number, w: string) => `${k} ${w}${k === 1 ? "" : "s"}`;
687 return `${n(crew.runs, "run")} and ${n(crew.pulls, "pull")} so far`;
688 }
670689
671690 /** Where a sent link stands, the time that changed, and whether it is time to send it again. */
672691 export interface Stage {
@@ -680,9 +699,10 @@ export interface Stage {
680699 }
681700
682701 export const STAGE_WORDS: Record<StageKey, string> = {
683 sent: "Sent",
702 sent: "Link not opened",
684703 opened: "Opened",
685704 signedin: "Signed in",
705 crew: "Crew working",
686706 tell: "Last tell",
687707 };
688708
@@ -704,6 +724,7 @@ export function stageOf(r: Omit<ClientRow, "attention" | "stage">, now: number):
704724 resend,
705725 });
706726 if (r.claimed) {
727 if (r.crew !== undefined && r.crew.runs + r.crew.pulls > 0) return make("crew", r.crew.at);
707728 return r.nextStep.lastTellAt !== null
708729 ? make("tell", r.nextStep.lastTellAt)
709730 : make("signedin", at(r.link?.usedAt));
src/spawn/heartbeat.ts +16 −2
@@ -25,7 +25,7 @@ import { isParentLocal } from "./beat-door.ts";
2525 import { refreshFunding } from "./funding.ts";
2626 import { appTipsFor } from "./app_links.ts";
2727 import { upstreamState } from "./upstream.ts";
28 import { progress } from "../core/next-steps.ts";
28 import { crewDone, progress } from "../core/next-steps.ts";
2929 import { running } from "../kernel/version.ts";
3030 import { forgeCeiling } from "../flow/ceiling.ts";
3131 import { during } from "../perf/jobs.ts";
@@ -89,6 +89,13 @@ export interface Beat {
8989 readonly lastTellAt?: string | null;
9090 /** When its person first told the crew something; null before the first, absent likewise. */
9191 readonly firstTellAt?: string | null;
92 /**
93 * What its crew did since the forge was made: agent runs and pulls (counts only), and when the
94 * latest began (ISO, null before any); absent from an older child.
95 */
96 readonly crewRuns?: number;
97 readonly crewPulls?: number;
98 readonly crewAt?: string | null;
9299 /**
93100 * When a stranger last asked this forge's sender for a new forge link, and when that link expired
94101 * (ISO); absent when none.
@@ -98,7 +105,7 @@ export interface Beat {
98105 }
99106
100107 const OPTIONAL = new Set([
101 "forgeTip", "severedAt", "mode", "upstreamBehind", "conflict", "spendTodayUsd", "ceilingUsd", "crewHeld", "claimed", "everyday", "lastTellAt", "firstTellAt", "linkAskedAt", "linkExpiredAt",
108 "forgeTip", "severedAt", "mode", "upstreamBehind", "conflict", "spendTodayUsd", "ceilingUsd", "crewHeld", "claimed", "everyday", "lastTellAt", "firstTellAt", "crewRuns", "crewPulls", "crewAt", "linkAskedAt", "linkExpiredAt",
102109 ]);
103110 const USD_MAX = 1_000_000;
104111
@@ -115,6 +122,8 @@ function verified(key: string, body: string, shown: string | null): boolean {
115122 return timingSafeEqual(Buffer.from(sign(key, body)), Buffer.from(shown));
116123 }
117124
125 const isoTime = (v: unknown): v is string => typeof v === "string" && ISO_TIME.test(v) && !Number.isNaN(Date.parse(v));
126
118127 const count = (v: unknown): v is number =>
119128 typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= COUNT_MAX;
120129
@@ -157,6 +166,9 @@ export function parseBeat(raw: string): Beat | undefined {
157166 // punctuation.
158167 const toldOk =
159168 told === null || (typeof told === "string" && ISO_TIME.test(told) && !Number.isNaN(Date.parse(told)));
169 // The crew's counts are a hint too: all three or none, else the fields drop, never the beat.
170 const crewAt = d["crewAt"];
171 const crewOk = count(d["crewRuns"]) && count(d["crewPulls"]) && (crewAt === null || isoTime(crewAt));
160172 // Both or neither, strict ISO: they become words on the sender's page.
161173 const askedAt = d["linkAskedAt"];
162174 const expiredAt = d["linkExpiredAt"];
@@ -188,6 +200,7 @@ export function parseBeat(raw: string): Beat | undefined {
188200 ...(everydayOk ? { everyday } : {}),
189201 ...(told !== undefined && toldOk ? { lastTellAt: told as string | null } : {}),
190202 ...(first !== undefined && firstOk ? { firstTellAt: first as string | null } : {}),
203 ...(crewOk ? { crewRuns: d["crewRuns"] as number, crewPulls: d["crewPulls"] as number, crewAt: crewAt as string | null } : {}),
191204 ...(askedAt === undefined ? {} : { linkAskedAt: askedAt as string, linkExpiredAt: expiredAt as string }),
192205 };
193206 }
@@ -406,6 +419,7 @@ export async function sendBeat(
406419 ...spendReport(app),
407420 ...(forgeHasNoKey(app) ? { crewHeld: NO_KEY_HELD } : {}),
408421 ...progress(app),
422 ...crewDone(app),
409423 ...linkAsk(app),
410424 // Only a forge that carries a fork of its parent's code has these to say.
411425 ...(forge === undefined
src/tui/screens/forges.ts +2 −2
@@ -7,7 +7,7 @@
77 import type { Ctx, Screen } from "../app/app.ts";
88 import { binding } from "../app/keys.ts";
99 import { rowActivityWords } from "../../spawn/client_words.ts";
10 import { ATTENTION_WORDS, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, seenOf, seenParts, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts";
10 import { ATTENTION_WORDS, crewCountWords, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, seenOf, seenParts, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts";
1111 import { useLine } from "../../spawn/usage.ts";
1212 import { timeAgo } from "../../web/ui.ts";
1313 import { card } from "../ui/widgets.ts";
@@ -38,7 +38,7 @@ export function forgeLines(rows: readonly ClientRow[], sender = false, now = Dat
3838 if (rows.length === 0) return [["", "You have not sent a forge yet"]];
3939 return rows.flatMap((r): [string, string][] => [[
4040 r.name,
41 [r.made ? (r.awake === true ? "awake" : "asleep") : null, r.made && r.where.inProcess ? r.where.says : null, r.stopped ?? null, crewHeldWords(r), r.attention === null ? null : ATTENTION_WORDS[r.attention], r.for === null ? null : `for ${r.for}`, CLAIM_WORDS[claimState(r)], linkWords(r.link, claimState(r) === "no" ? now : null), runningWords(r), seenLine(r, sender) !== null && r.stage?.key !== "tell" && r.stage?.resend !== true ? null : r.stage?.words ?? null, seenLine(r, sender), r.nextStep.words, spendWords(r)?.words ?? null, monthWords(r)?.words ?? null, creditWords(r), graceWords(r), useLine(r.size, r.use), r.made ? diskWords(r.disk) : null, activityPiece(r, sender, now), claimedWords(r), keepWords(r), r.archive === null || r.archive === undefined ? null : `proposed for archive: ${r.archive.why}`, r.lastHeartbeatAt === null ? "no heartbeat yet" : `heartbeat ${timeAgo(r.lastHeartbeatAt)}`]
41 [r.made ? (r.awake === true ? "awake" : "asleep") : null, r.made && r.where.inProcess ? r.where.says : null, r.stopped ?? null, crewHeldWords(r), r.attention === null ? null : ATTENTION_WORDS[r.attention], r.for === null ? null : `for ${r.for}`, CLAIM_WORDS[claimState(r)], linkWords(r.link, claimState(r) === "no" ? now : null), runningWords(r), seenLine(r, sender) !== null && r.stage?.key !== "tell" && r.stage?.key !== "crew" && r.stage?.resend !== true ? null : r.stage?.words ?? null, r.stage?.key === "crew" && r.nextStep.lastTellAt !== null ? `last tell ${timeAgo(r.nextStep.lastTellAt)}` : null, crewCountWords(r.crew), seenLine(r, sender), r.nextStep.words, spendWords(r)?.words ?? null, monthWords(r)?.words ?? null, creditWords(r), graceWords(r), useLine(r.size, r.use), r.made ? diskWords(r.disk) : null, activityPiece(r, sender, now), claimedWords(r), keepWords(r), r.archive === null || r.archive === undefined ? null : `proposed for archive: ${r.archive.why}`, r.lastHeartbeatAt === null ? "no heartbeat yet" : `heartbeat ${timeAgo(r.lastHeartbeatAt)}`]
4242 .filter((m): m is string => m !== null)
4343 .join(" · "),
4444 ], ...firstScreenLines(r), ...appLinkLines(r), ...addressLines(r)]);
src/web/pages/forges.ts +5 −2
@@ -9,7 +9,7 @@
99 import type { Ctx } from "../../http/context.ts";
1010 import { claimsBill } from "../../actions/forge_bill.ts";
1111 import { billRow } from "./bills.ts";
12 import { ATTENTION_WORDS, STALE_WORDS, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, memoryOf, seenOf, seenParts, type Seen, servedRows, dropServed, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts";
12 import { ATTENTION_WORDS, STALE_WORDS, crewCountWords, daysLeftWords, firstScreenOf, CLAIM_WORDS, claimState, memoryOf, seenOf, seenParts, type Seen, servedRows, dropServed, creditWords, crewHeldWords, graceWords, runningWords, spendWords, monthWords, type ClientRow } from "../../spawn/clients.ts";
1313 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
1414 import { notFoundPage, pageHead } from "../chrome.ts";
1515 import { html, type Html } from "../html.ts";
@@ -111,9 +111,12 @@ export function forgeRow(r: ClientRow, now: number, reach?: ForgeReach, bill = f
111111 graceWords(r) === null ? null : html`<span data-grace>${graceWords(r)}</span>`,
112112 // With the seen line, the stage and the activity words would say the same thing twice;
113113 // only what it does not say (a resend, the last tell) keeps its own words.
114 r.stage === null || (seen !== null && r.stage.key !== "tell" && !r.stage.resend)
114 r.stage === null || (seen !== null && r.stage.key !== "tell" && r.stage.key !== "crew" && !r.stage.resend)
115115 ? null
116116 : html`<span data-stage="${r.stage.key}"${r.stage.resend ? html` data-resend` : null}>${r.stage.words}${r.stage.at === null ? null : html` ${time(r.stage.at)}`}</span>`,
117 // A crew stage replaces the tell stage's place, so the tell keeps its words beside it.
118 r.stage?.key === "crew" && r.nextStep.lastTellAt !== null ? html`<span data-stage="tell">Last tell ${time(r.nextStep.lastTellAt)}</span>` : null,
119 crewCountWords(r.crew) === null ? null : html`<span data-crew-did>${crewCountWords(r.crew)}</span>`,
117120 seen === null ? null : seenWords(seen),
118121 // One phrase for the fact; the exact moment stays in the title.
119122 activityNote(r, seen !== null, now),
test/client-list-stages.test.ts added +120
@@ -0,0 +1,120 @@
1 /**
2 * The client list says, per sent forge, one of: link not opened, opened, signed in, crew working,
3 * with the time, and counts the runs and pulls so far (#15746). The page, the terminal
4 * and the MCP answer carry the same fields.
5 */
6 import { describe, expect, test } from "bun:test";
7 import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp } from "../src/app.ts";
11 import { crewDone } from "../src/core/next-steps.ts";
12 import { clientRows, forgetHeard, orderRows, useChildFetch, crewCountWords, type ClientRow } from "../src/spawn/clients.ts";
13 import { clientLines } from "../src/spawn/client_words.ts";
14 import { parseBeat } from "../src/spawn/heartbeat.ts";
15 import { forgeLines } from "../src/tui/screens/forges.ts";
16 import { forgeRow } from "../src/web/pages/forges.ts";
17 import { tool } from "../src/http/mcp/tools/forges.ts";
18
19 const NOW = Date.parse("2026-11-10T12:00:00Z");
20 const ago = (ms: number) => new Date(NOW - ms).toISOString();
21 type Raw = Omit<ClientRow, "attention" | "stage" | "archive">;
22 const base = (over: Record<string, unknown> = {}): Raw =>
23 ({
24 name: "acme", url: "https://acme.example", for: "Maria", apps: [], sentAt: ago(86_400_000), made: true, claimed: false,
25 lastActivityAt: null, running: null, reach: null, link: { state: "open", revokedAt: null, usedAt: null }, spendTodayUsd: null,
26 ceilingUsd: null, size: "small", use: { kind: "shared" }, disk: { own: false }, lastHeartbeatAt: null,
27 placement: "cell", where: { placement: "cell", inProcess: false, says: "runs in its own sandbox", movable: false, held: false },
28 nextStep: { key: "claim", words: "not claimed yet", lastTellAt: null }, ...over,
29 }) as unknown as Raw;
30 type Run = Parameters<typeof tool.run>;
31 const admin = { isAdmin: true } as unknown as Run[1];
32 const clients = (app: unknown) => tool.run({ app } as unknown as Run[0], admin, { kind: "clients" });
33 const row = (over = {}): ClientRow => orderRows([base(over)], NOW)[0]!;
34 const text = (r: ClientRow) => String(forgeRow(r, NOW)).replace(/<[^>]*>/g, " ").replace(/\s+/g, " ");
35
36 describe("client list stages", () => {
37 const stages: [string, Record<string, unknown>, string, string][] = [
38 ["sent", {}, "Link not opened", ago(86_400_000)],
39 ["opened", { link: { state: "open", revokedAt: null, usedAt: null, openedAt: ago(3600_000) } }, "Opened", ago(3600_000)],
40 ["signedin", { claimed: true, link: { state: "used", revokedAt: null, usedAt: ago(1800_000) } }, "Signed in", ago(1800_000)],
41 ["crew", { claimed: true, crew: { runs: 3, pulls: 1, at: ago(60_000) }, link: { state: "used", revokedAt: null, usedAt: ago(1800_000) } }, "Crew working", ago(60_000)],
42 ];
43 for (const [key, over, words, at] of stages)
44 test(`${key}: words and time agree across the row and the MCP lines`, () => {
45 const r = row(over);
46 expect([r.stage?.key, r.stage?.words, r.stage?.at]).toEqual([key, words, at]);
47 const line = clientLines([r])[0]!;
48 expect([line.stage, line.stageAt]).toEqual([words, at]);
49 });
50
51 test("the page counts runs and pulls so far, and the last tell beside a crew stage", () => {
52 const r = row({ claimed: true, crew: { runs: 3, pulls: 1, at: ago(60_000) }, link: { state: "used", revokedAt: null, usedAt: ago(1800_000) } });
53 expect(text(r)).toContain("3 runs and 1 pull so far");
54 expect(text(r)).toContain("Crew working");
55 expect(crewCountWords(undefined)).toBeNull();
56 expect(clientLines([r])[0]).toMatchObject({ runs: 3, pulls: 1 });
57 expect(clientLines([row()])[0]).toMatchObject({ runs: null, pulls: null });
58 });
59
60 test("an unclaimed row that reported counts shows them on the page, the terminal and MCP alike", () => {
61 const r = row({ crew: { runs: 2, pulls: 0, at: ago(60_000) } });
62 expect(text(r)).toContain("2 runs and 0 pulls so far");
63 expect(forgeLines([r], true, NOW)[0]![1]).toContain("2 runs and 0 pulls so far");
64 expect(clientLines([r])[0]).toMatchObject({ runs: 2, pulls: 0 });
65 });
66
67 test("a crew stage still shows the last tell, on the page, in the terminal and in MCP", () => {
68 const told = ago(7200_000);
69 const r = row({ claimed: true, crew: { runs: 1, pulls: 0, at: ago(60_000) }, nextStep: { key: "going", words: "going", lastTellAt: told }, link: { state: "used", revokedAt: null, usedAt: ago(9000_000) } });
70 expect(r.stage?.key).toBe("crew");
71 expect(text(r)).toContain("Crew working");
72 expect(text(r)).toContain("Last tell");
73 expect(forgeLines([r], true, NOW)[0]![1]).toContain("last tell");
74 expect(clientLines([r])[0]?.tellAt).toBe(told);
75 expect(clientLines([row({ claimed: true, link: { state: "used", revokedAt: null, usedAt: ago(9000_000) } })])[0]?.tellAt).toBeNull();
76 });
77
78 test("a child counts its own crew, and the beat carries only counts and a time", () => {
79 const dir = mkdtempSync(join(tmpdir(), "forge-crew-"));
80 const app = createApp({ dataDir: dir, url: "https://forge.test", port: 0 });
81 try {
82 expect(crewDone(app)).toEqual({ crewRuns: 0, crewPulls: 0, crewAt: null });
83 const beat = { name: "kid", at: 5, version: "1.0.0", openProposals: 0, children: 0 };
84 const ok = parseBeat(JSON.stringify({ ...beat, crewRuns: 2, crewPulls: 1, crewAt: "2026-11-10T12:00:00.000Z" }));
85 expect([ok?.crewRuns, ok?.crewPulls, ok?.crewAt]).toEqual([2, 1, "2026-11-10T12:00:00.000Z"]);
86 const bad = parseBeat(JSON.stringify({ ...beat, crewRuns: -1, crewPulls: 1, crewAt: null }));
87 expect(bad).toBeDefined();
88 expect(bad?.crewRuns).toBeUndefined();
89 } finally {
90 app.close();
91 }
92 });
93
94 test("the MCP client list carries stage, its time and the counts", async () => {
95 const dir = mkdtempSync(join(tmpdir(), "forge-stages-"));
96 const app = createApp({ dataDir: dir, url: "https://forge.test", port: 0 });
97 try {
98 mkdirSync(join(dir, "spawn"), { recursive: true });
99 writeFileSync(join(dir, "spawn", "kid.json"), JSON.stringify({ name: "kid", bodyId: "cell-k", done: true, placement: "hosted", size: "small", apps: [], createdAt: new Date().toISOString() }));
100 useChildFetch(app, async () => Response.json({ claimed: false, link: { state: "open", revokedAt: null, usedAt: null } }));
101 expect((await clientRows(app))[0]?.crew).toBeUndefined();
102 const out = await clients(app);
103 const got = JSON.parse(JSON.stringify(out)).value.clients[0];
104 expect(got.stage).toBe("Link not opened");
105 expect(got).toHaveProperty("stageAt");
106 expect(got.runs).toBeNull();
107 // The same forge once its person signed in and its crew has worked: stage, time and counts.
108 mkdirSync(join(dir, "beats"), { recursive: true });
109 const at = new Date().toISOString();
110 const doc = { name: "kid", at: Date.now(), version: "1.0.0", openProposals: 0, children: 0, claimed: true, crewRuns: 4, crewPulls: 2, crewAt: at };
111 writeFileSync(join(dir, "beats", "kid.json"), JSON.stringify({ receivedAt: Date.now(), beat: doc }));
112 forgetHeard(app, "kid");
113 useChildFetch(app, async () => Response.json({ claimed: true, link: { state: "used", revokedAt: null, usedAt: at } }));
114 const crew = JSON.parse(JSON.stringify(await clients(app))).value.clients[0];
115 expect([crew.stage, crew.stageAt, crew.runs, crew.pulls]).toEqual(["Crew working", at, 4, 2]);
116 } finally {
117 app.close();
118 }
119 });
120 });
test/client-states.test.ts +1 −1
@@ -33,7 +33,7 @@ const stage = (over = {}) => orderRows([base(over)], NOW)[0]!;
3333 describe("client states", () => {
3434 test("sent, with the time it was sent", () => {
3535 const s = stage().stage!;
36 expect([s.key, s.words, s.at, s.resend]).toEqual(["sent", "Sent", ago(DAY), false]);
36 expect([s.key, s.words, s.at, s.resend]).toEqual(["sent", STAGE_WORDS.sent, ago(DAY), false]);
3737 });
3838
3939 test("opened once the link is spent but no one is signed in", () => {
test/family-heartbeat.test.ts +3
@@ -352,7 +352,10 @@ describe("family heartbeats", () => {
352352 "ceilingUsd",
353353 "children",
354354 "claimed",
355 "crewAt",
355356 "crewHeld",
357 "crewPulls",
358 "crewRuns",
356359 "everyday",
357360 "firstTellAt",
358361 "lastTellAt",
test/mcp-forges-card.test.ts +1 −1
@@ -99,7 +99,7 @@ describe("MCP forges card", () => {
9999 const rows = ok.structuredContent.card.rows;
100100 expect(rows.map((r: any) => r.label)).toEqual(["beta", "alpha"]);
101101 expect(rows[0].value).toBe("for Bob · resend");
102 expect(rows[1].value).toBe("for Ann · sent");
102 expect(rows[1].value).toBe("for Ann · link not opened");
103103 const no = await call(bobToken);
104104 expect(no.isError).toBe(true);
105105 expect(no.structuredContent?.card).toBeUndefined();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs