gcf-board 0.28.0 → 0.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,7 +44,7 @@ The board knows no domain by name: the project's board read gives its columns, m
44
44
 
45
45
  - **Command**: **waiting for me**, what only the operator moves on (Board-PRD §1.3), by group, each a grid of tiles (board 0.16.0, the designer's final round): failed run reports and a paused queue (its tile opens Runs), a card waiting in a chat (its tile opens the chat), the decisions, the items to play and judge, to decide, to unblock (the columns the domain marks `human`), and a `paused: limit` item to resume. Beside it **Live**: the runs going on with their plan progress, **Follow** and **Stop**, the console runs and sessions, **Run next**, the queue, the run reports, and what the board did by itself.
46
46
  - **Board**: columns ready, running, blocked, awaiting-verdict, awaiting-decision, unplayed, parked. A card shows the type, the gate, the plan progress (`2/5`), the severity, `verified`, the model, **needs N** and **needed by N**. A running card shows when its run log was last written (`active 12 s ago`), and `quiet 6 min` when the log has been silent for 5 minutes or more. A run's end report gives each item's cost when the agent reported it. Pointing at a card (or focusing it from the keyboard) lights up the cards it needs and the cards that need it, each saying how, and dims the rest. The toolbar (board 0.9.0, core 0.13.0) searches ids and titles, keeps **waiting for me**, filters by the fields the domain marks `filter` (GCF: type, gate, severity, system, milestone; several values at once, each a chip to take off) and lays the board out in lanes by a field it marks `group` (system, parent, milestone): an item with two systems stands in both lanes, one with none in **none**, a parent lane is named by the feature's title. The mouse drags the board sideways from its empty space; the wheel over a column with no scroll of its own pans it.
47
- - **An item** (a window over the screen, dragged by its head; a page on a phone; board 0.14.0): its **Status** (why it is blocked or waits, its fields, its dependencies; it opens there when it is blocked or waits), its file (the front matter folded, a `key:` body by sections), its plan and its run log as it grows, its **Lessons**, and the moves the core offers for it (`items[].moves`, Methodology §4.1): run, verdict, decide, block, unblock, drop, close, submit, depends. Each move's form comes from the core; the core still checks the rest itself, and the board shows its answer. **Dependencies**: what it needs that has not ended in history (an item with its column, a design unit with its TBDs or the questions that block it, a graveyard line, an unknown id) and the items that need it, each a link; **Edit…** opens the picker of the board's items and design units (search by id and title, or type an id), and Save sends the `depends` move's adds and removes. **History** (core 0.13.0): its moves newest first, when, which, who (a run, your session, you; unknown on a commit older than the framework's marks), the commit and its subject; then its runs, as on the Runs screen. **Related**: its feature's other children, and the graveyard lines tagged with its system ("did we kill this before?"). An item that ended opens from **Ended** with its History.
47
+ - **An item** (a window over the screen, dragged by its head; a page on a phone; board 0.14.0): its **Status** (why it is blocked or waits, its fields, its dependencies; it opens there when it is blocked or waits, unless you last clicked another tab: the next item opens on that one; a tuned item lists its tune notes there), its file (the front matter folded, a `key:` body by sections), its plan and its run log as it grows, its **Lessons**, and the moves the core offers for it (`items[].moves`, Methodology §4.1): run, verdict, decide, block, unblock, drop, close, submit, depends. Each move's form comes from the core; the core still checks the rest itself, and the board shows its answer. **Dependencies**: what it needs that has not ended in history (an item with its column, a design unit with its TBDs or the questions that block it, a graveyard line, an unknown id) and the items that need it, each a link; **Edit…** opens the picker of the board's items and design units (search by id and title, or type an id), and Save sends the `depends` move's adds and removes. **History** (core 0.13.0): its moves newest first, when, which, who (a run, your session, you; unknown on a commit older than the framework's marks), the commit and its subject; then its runs, as on the Runs screen. **Related**: its feature's other children, and the graveyard lines tagged with its system ("did we kill this before?"). An item that ended opens from **Ended** with its History.
48
48
  - **Runs** (harness 0.13.0): what runs now with the run's model and effort, its last log lines, **Whole log** and **Stop**; the queue with what each item will run on; the past runs of the harness's run log, newest first, 50 at a time: start, end, mode, cost, and per item its result word, the reason word for word, cost, tokens, turns, handoffs, a broken step and what it ran on. **log** opens the part of the item's log that run wrote, **chat** that run's chat. Every start the operator asks for (Run selected, Run next, a drop on running, this screen) asks first with a model and effort picker for that run only (**default: each item's own**); the drawer's Run is one click. An older harness shows the active runs only, and the dialog has no pickers. The API: `GET /api/p/<project>/runs/past?limit=` (`gcf-harness runs --json`; 404 without a harness that keeps them), `GET …/item/<id>/history` (`{id, moves, runs}`), `GET …/log/<id>?from=&to=` (a past run's part, once: `{text, cut}`, at most its last 2 MB; without `from` and `to` the log as it grows), `POST …/run` with `model` and `effort`, `POST …/inbox/<entry>/draft` (`{thread, created}`).
49
49
  - **Log** (board 0.20.1, gcf-session 0.18.1): a subagent's lines say so (`subagent:`, `subagent tool:`, `subagent tool error:`), drawn as the main agent's kinds; the pulse's current action names a subagent's call as one.
50
50
  - **Play** (board 0.24.0, core 0.26.0): a card waiting for play shows its build (one per code, `Same build as` when shared), **Play** per target of `play:` that builds first when there is none, **Stop** and **Change** (find again with agent, edit, build again), on its run's end card, in its window and on Playtest; **Set up** opens a chat thread whose agent finds the commands, **by hand** opens the form; **Play main** and **Build main** play the checkout as it is; a verdict stops the card's player and removes a build no other card holds.
@@ -74,7 +74,7 @@ The board knows no domain by name: the project's board read gives its columns, m
74
74
  - **An item's chat** (its drawer's **Chat** tab; harness 0.11.1, core 0.11.1): every run the board starts keeps its agent sessions open; the project's `chat:` settings (Settings: `chat.ask`, `chat.answer_timeout_min`) say what the agent asks and how long a question waits. The tab shows the run's chat, then the item's own thread of the project chat: the talk, question cards (picks, several questions, **Submit**), the run's milestones, its sessions, the limit wait, the context share. A message goes where the server puts it: the live run (its limit wait too), else the item's thread, and the line under the box says where it went. `GET /api/p/<project>/chat/<id>` follows the item's chat from its start, in raw chunks of JSON lines (the page splits them). `POST` there sends `{type: 'say', text, images?, attach?}`, `{type: 'interrupt'}` or `{type: 'answer', request_id, answers}` through `gcf-harness chat`; with no live run a message goes to the item's thread (answer `{talk}`), else a message with no session to read it gets 409, bad input 400. `attach` (`[{kind: item | unit | file, ref}]`) goes into the message's text as a line the agent reads; a file picked on the operator's machine (`{kind: file, ref: <name>, data: <base64>}`, the composer's 📎) is written into `.gcf-session/uploads/` and goes as `file <its absolute path>`; a move's `file` field (`attach`) takes `{name, data}` the same way, its copy removed after the command; a design unit (the composer's **+ unit**, from the board read's `units`) goes as `unit <id> (<file>)`. `GET /api/p/<project>/chat/<id>/att/<file>` serves a chat picture; **attach to item…** under a picture gives it to an item (`gcf item attach`).
75
75
  - **Functional base A** (board 0.10.0, core and harness 0.14.0; docs/Base-A-Plan.md): Settings has `session_timeout_min` and the project's `agent.model` / `agent.effort`; the drawer shows the project's model on an item without its own, "(project)". The drawer's Run is off with the run gate's reason when the gate refuses the item now, and the start dialog marks each refused item and runs the rest (`GET /api/p/<project>/gate?ids=` runs `gcf-harness gate --each`). An item's attachments and an inbox entry's pictures are links (`GET /api/p/<project>/attachment?path=`: only `gcf/work/<id>/attachments/` and `gcf/inbox/in-<hex>/attachments/`, no `..`, no link on the way, a picture shown, any other file a download, `nosniff` and `default-src 'none'`), and a picture or link in File or Plan that points there loads through it. A permission card for one MCP tool offers Always, saying it allows every call of the tool with any arguments.
76
76
  - **Model and effort** (board 0.8.0, core 0.12.3; a closed select since board 0.15.0, Board-PRD decision 33): pickers in the New item form, in the drawer (**change** beside the model and effort, and **model / effort** under **More**), in a thread's composer and in Settings (`agent.model` / `agent.effort`). Each is one select: Default first — "Default (Opus)" / "Default (High)", or "Default - project setting (Sonnet)" when the project sets one, and "Default - each item's own" in the run dialog; Default sends `default` — then the agent's presets by name (Fable, Opus, xHigh). Nothing set anywhere runs on Opus / High (decision 36). A thread's composer has no Default row: it shows what holds, and **↺ project** takes the thread's own pick off (board 0.16.2). No own word; a value set from the console that the presets lack shows as its own row, so a form sent unchanged keeps it. An item's next run takes them; a thread's next session does (`chats/<t>/agent.json`), and its line in the chat says so.
77
- - **Project chat** (the **Chat** screen; core 0.12): threads of an agent in the project's folder, listed newest first and filtered by their item; a new thread is made when its first message is sent. Each thread is run by the bundled session engine (`gcf-session`) through the same detached relay as runs. It asks a card before each edit, git command and framework move (**allow once**, **always** — saved in `.claude/settings.local.json`; the card says saved only when it was — or **deny**); a new item it proposes through the board's MCP server `gcf` (tool `propose_item_new`, asked with no card: the proposal card is the question), the proposal card shows every field it proposed, and the operator's **Create** makes it with `POST /move` (`proposal: {talk, id}`), **Edit…** first in the new-item form. A proposed item has no id: the server asks `gcf item new --dry-run` for it, records it, then creates the item with it, so a board that stops halfway does not make it twice. An inbox entry the agent proposed is filed with origin `agent`: the server adds `--origin=agent`, never from the request. With core 0.16 (board 0.12.0, Board-PRD decision 27) it also proposes a move on an item or an inbox entry already there — `block`, `drop`, `depends`, and the inbox's `add` (with its category), sort, Later and erase (sort and Later with core 0.18, board 0.15.0) — naming it in `id`: the card shows the item's id, title and status now (or the entry's first line), warns when the item does not take the move now or is not on the board, its button is the move's name (a drop or an erase asks first), and **Edit…** opens that move's form. A thread's list entry names the card that waits in it and its limit wait (`card`, `limit_until`); a running item names the card of its run's chat (`chat_card`). A long talk hands over to a fresh agent from a summary; an idle agent closes after `chat.answer_timeout_min` (0 means 15) and the next message resumes it. Each item has at most one thread: a message to an item with no live run goes there. `GET /api/p/<project>/talks[?item=]` lists the threads with their proposals' states; `POST` there makes one (`{item?}`); `GET /api/p/<project>/talk/<t>` follows a thread's events; `POST` there sends `say`, `interrupt`, `answer`, `allow`, `deny` or `handoff`; `POST …/talk/<t>/stop` is the composer's **close agent** (board 0.8.1): the thread's agent ends with everything it started, or its limit wait does, and what it had not taken in is dropped with a "not sent" line; the next message resumes the talk; `GET …/talk/<t>/att/<file>` serves its pictures. The files live in `.gcf-session/chats/` (docs/Chat-Plan.md §3).
77
+ - **Project chat** (the **Chat** screen; core 0.12): threads of an agent in the project's folder, listed by their last message and filtered by their item; **Reply** on an agent message sends your words with it quoted; a new thread is made when its first message is sent. Each thread is run by the bundled session engine (`gcf-session`) through the same detached relay as runs. It asks a card before each edit, git command and framework move (**allow once**, **always** — saved in `.claude/settings.local.json`; the card says saved only when it was — or **deny**); a new item it proposes through the board's MCP server `gcf` (tool `propose_item_new`, asked with no card: the proposal card is the question), the proposal card shows every field it proposed, and the operator's **Create** makes it with `POST /move` (`proposal: {talk, id}`), **Edit…** first in the new-item form. A proposed item has no id: the server asks `gcf item new --dry-run` for it, records it, then creates the item with it, so a board that stops halfway does not make it twice. An inbox entry the agent proposed is filed with origin `agent`: the server adds `--origin=agent`, never from the request. With core 0.16 (board 0.12.0, Board-PRD decision 27) it also proposes a move on an item or an inbox entry already there — `block`, `drop`, `depends`, and the inbox's `add` (with its category), sort, Later and erase (sort and Later with core 0.18, board 0.15.0) — naming it in `id`: the card shows the item's id, title and status now (or the entry's first line), warns when the item does not take the move now or is not on the board, its button is the move's name (a drop or an erase asks first), and **Edit…** opens that move's form. A thread's list entry names the card that waits in it and its limit wait (`card`, `limit_until`); a running item names the card of its run's chat (`chat_card`). A long talk hands over to a fresh agent from a summary; an idle agent closes after `chat.answer_timeout_min` (0 means 15) and the next message resumes it. Each item has at most one thread: a message to an item with no live run goes there. `GET /api/p/<project>/talks[?item=]` lists the threads with their proposals' states; `POST` there makes one (`{item?}`); `GET /api/p/<project>/talk/<t>` follows a thread's events; `POST` there sends `say`, `interrupt`, `answer`, `allow`, `deny` or `handoff`; `POST …/talk/<t>/stop` is the composer's **close agent** (board 0.8.1): the thread's agent ends with everything it started, or its limit wait does, and what it had not taken in is dropped with a "not sent" line; the next message resumes the talk; `GET …/talk/<t>/att/<file>` serves its pictures. The files live in `.gcf-session/chats/` (docs/Chat-Plan.md §3).
78
78
  - **Inbox** (categories since board 0.15.0, core 0.18.0; Board-PRD decision 32): add an entry (Ctrl+Enter adds, Enter breaks the line; a category of the ones you may file, Note by default, and a detail), **Sort…** it into another category, put it away to **Later** and take it **Back**, erase it, or turn it into an item (its first line the title, the rest the note). Each entry shows its category and detail, its origin, its lines and date. Search the entries, filter them by category (or "in Later") and by detail. Since board 0.16.0 each group is a panel of tiles, Needs you first; a tile opens the record in the detail window (the item window's frame); the filter takes a category, its details, the origin, an item and the text; on the Inbox `j` / `k` move between tiles, Enter opens, `s` sorts, `l` puts Later or Back, `e` erases. The decisions and the agent's assumptions are records of their own categories there too. **Draft with agent** opens a project chat thread bound to the entry and sends "Draft an item from inbox entry <id>:" with its text; a second click opens the same thread. The first proposal's **Create** takes the entry (it is erased); a later one makes an item with no entry. Off while the usage limit holds.
79
79
  - **Design**: where a game starts and its design changes. The steps from an empty project to the first work (the design, the pillars, the open questions, a ready unit), each with what does it: **Import GDD** (a markdown file), **Review GDD first**, **Create with agent**, **Draft with agent** for the glossary, **Pillars interview**, **Name with agent** for pillars without a name; each opens a project chat thread that follows its own skill and writes the design files without a card. **Record design** commits what a thread wrote, and **Discard draft…** takes an agent's unrecorded draft back (`gcf design discard`); a form save of the drafted part takes the draft along. The pillars, the vision, the glossary, a subsystem's purpose and each unit open in a form whose fields come from the core; a save goes through the core's checks, a refusal says why. A pillar is edited by its name, its id read-only (a changed name renames the id after the save); Retire. **Add unit** asks a subsystem, a type and a title, no id, and opens the new unit. A subsystem's purpose has **Draft with agent**. A unit's Drop, the design questions with their answer box, the designer's Export and Import. Until the first work, while steps are left, Command says how many and opens Design.
80
80
  - **Keys**: `/` search, `i` a new inbox entry, `n` a new item, `j` / `k` between cards, Enter opens one, `r` runs the focused card (it asks), `1`–`7` a column, `?` Help, `g` then a letter goes to a screen (`g c` Command, `g b` Board, `g t` Chat, `g i` Inbox, `g d` Design, `g r` Runs, `g p` Playtest, `g e` Ended, `g a` Agent, `g m` Metrics, `g s` Settings; the nav's icons say theirs), Esc closes a dialog, Help, the item's or the detail window; none while a field has the focus. Board 0.16.0: the nav is a rail of icons, the project switcher sits at the header's left.
@@ -667,7 +667,7 @@ export function createApp(o) {
667
667
  },
668
668
  ],
669
669
  [
670
- // The project chat's threads (AD-46: `?item=` its bound one), newest first.
670
+ // The project chat's threads (AD-46: `?item=` its bound one), the last used first.
671
671
  'GET',
672
672
  /^\/api\/p\/([^/]+)\/talks$/,
673
673
  async (_req, res, m, url) => {
@@ -1,3 +1,6 @@
1
+ // What the operator writes into an item's chat (docs/Chat-Plan.md): its shape checked here, at
2
+ // the board's edge; `gcf-harness chat` checks the rest and writes it for the session.
3
+ import { replyBlock } from '../shared/board.js';
1
4
  import { HttpError } from './http-error.js';
2
5
  import { saveUpload } from './upload.js';
3
6
  /** A chat message may carry images: a body up to 10 MB. */
@@ -93,6 +96,18 @@ export async function withUploads(root, body) {
93
96
  /** Whether a body attaches a design unit: its route reads the board's units for it. */
94
97
  export const attachesUnit = (body) => Array.isArray(body.attach) &&
95
98
  body.attach.some((a) => a?.kind === 'unit');
99
+ /** A request's `reply_to` (Board-Use-Plan d1): the agent message's `at` and its text; null for none. */
100
+ function replyTo(r) {
101
+ if (r === undefined || r === null)
102
+ return null;
103
+ const { at, text } = r;
104
+ if (typeof at !== 'string' ||
105
+ !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z$/.test(at) ||
106
+ typeof text !== 'string')
107
+ throw bad("reply_to is {at: <the agent message's ISO time>, text: <its text>}");
108
+ // The body's own limit bounds it; only its first REPLY_QUOTE_MAX characters are quoted.
109
+ return { at, text };
110
+ }
96
111
  /**
97
112
  * The line a request writes into the chat input: a message, a stop of the step, an answer.
98
113
  * `units`: the design units an attachment may name.
@@ -101,7 +116,18 @@ export function chatInput(body, units) {
101
116
  if (body.type === 'interrupt')
102
117
  return { type: 'interrupt' };
103
118
  if (body.type === 'say') {
104
- const text = typeof body.text === 'string' ? body.text + attachLine(body.attach, units) : body.text;
119
+ const attach = typeof body.text === 'string' ? attachLine(body.attach, units) : '';
120
+ const reply = replyTo(body.reply_to);
121
+ if (reply && !(typeof body.text === 'string' && body.text.trim()))
122
+ throw bad('a reply carries your own words: the quote alone says nothing');
123
+ // The quote gives way to the operator's words and the attachments: it is cut, not refused.
124
+ const text = typeof body.text === 'string'
125
+ ? body.text +
126
+ (reply
127
+ ? replyBlock(reply.at, reply.text, TEXT_MAX - body.text.length - attach.length)
128
+ : '') +
129
+ attach
130
+ : body.text;
105
131
  if (typeof text !== 'string' || !text.trim() || text.length > TEXT_MAX)
106
132
  throw bad(`a message is text, up to ${TEXT_MAX} characters`);
107
133
  const list = images(body.images);
@@ -31,7 +31,7 @@ export function aiFactoryEntry() {
31
31
  function globalRoots() {
32
32
  const roots = [];
33
33
  try {
34
- roots.push(execSync('npm root -g', { encoding: 'utf8', stdio: 'pipe' }).trim());
34
+ roots.push(execSync('npm root -g', { windowsHide: true, encoding: 'utf8', stdio: 'pipe' }).trim());
35
35
  }
36
36
  catch {
37
37
  // No npm on PATH: the folders beside this node still hold the global packages.
@@ -112,6 +112,7 @@ export function runCli(entry, cwd, args, timeoutMs = 120_000, input) {
112
112
  const { CLAUDE_CODE_SESSION_ID: _, GCF_RUN_OWNER: __, GCF_MOVE_BY: ___, GCF_RUN_ITEM: ____, ...env } = process.env;
113
113
  return new Promise((resolve) => {
114
114
  const child = spawn(process.execPath, [entry, ...args], {
115
+ windowsHide: true,
115
116
  cwd,
116
117
  env,
117
118
  shell: false,
@@ -132,7 +133,10 @@ export function runCli(entry, cwd, args, timeoutMs = 120_000, input) {
132
133
  err += `\nstopped after ${timeoutMs / 1000} s`;
133
134
  // On Windows a kill stops node alone: a build it started (Unity) would go on.
134
135
  if (process.platform === 'win32' && child.pid)
135
- spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore' });
136
+ spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], {
137
+ windowsHide: true,
138
+ stdio: 'ignore',
139
+ });
136
140
  else
137
141
  child.kill();
138
142
  // A grandchild holding the pipes keeps close from firing: the answer does not wait for it.
@@ -72,6 +72,7 @@ export function createShortcut(main, port) {
72
72
  const plan = shortcutPlan(process.platform, process.execPath, main, port);
73
73
  if ('powershell' in plan) {
74
74
  const r = spawnSync('powershell', ['-NoProfile', '-Command', plan.powershell], {
75
+ windowsHide: true,
75
76
  encoding: 'utf8',
76
77
  });
77
78
  if (r.error)
@@ -173,7 +173,7 @@ export function talkSpec(p, board, mcp, start = null) {
173
173
  };
174
174
  }
175
175
  /** A command's output in the project, or empty. */
176
- const git = (cwd, ...args) => spawnSync('git', args, { cwd, encoding: 'utf8' }).stdout?.trim() ?? '';
176
+ const git = (cwd, ...args) => spawnSync('git', args, { windowsHide: true, cwd, encoding: 'utf8' }).stdout?.trim() ?? '';
177
177
  // The most lines of a log or of commits a thread's context gives: it goes into every session.
178
178
  const CONTEXT_LINES = 30;
179
179
  /** The last lines of a csv log (no header, Harness-PRD §11) whose fields include the id. */
@@ -841,6 +841,8 @@ async function talkOf(p, th, ids, questionOf) {
841
841
  start: th.start?.id ?? null,
842
842
  created_at: th.created_at,
843
843
  last_at: events.at(-1)?.at ?? null,
844
+ // A close, a limit or a session's end is no use of it (Board-Use-Plan d4).
845
+ used_at: events.findLast((e) => e.type === 'say' || e.type === 'agent')?.at ?? th.created_at,
844
846
  cost_usd: Math.round(cost * 100) / 100,
845
847
  model: pick.model ?? null,
846
848
  effort: pick.effort ?? null,
@@ -854,7 +856,7 @@ async function talkOf(p, th, ids, questionOf) {
854
856
  };
855
857
  }
856
858
  /**
857
- * The project's threads, newest first; with `item`, its bound one only. `ids()` reads the
859
+ * The project's threads, the last used first (`used_at`); with `item`, its bound one only. `ids()` reads the
858
860
  * board's items when a proposal needs settling; `questionOf` the question an answer proposal
859
861
  * answers, when it is first seen.
860
862
  */
@@ -863,7 +865,8 @@ export async function listTalks(p, ids, item, questionOf) {
863
865
  // One board read at most, and only when a proposal needs it.
864
866
  let read = null;
865
867
  const once = () => (read ??= ids());
866
- return Promise.all(threads.map((th) => talkOf(p, th, once, questionOf)));
868
+ const talks = await Promise.all(threads.map((th) => talkOf(p, th, once, questionOf)));
869
+ return talks.sort((a, b) => b.used_at.localeCompare(a.used_at));
867
870
  }
868
871
  /** Where a thread's input is read to, and how far it is written. */
869
872
  function unread(td) {
@@ -59,3 +59,48 @@ export function moveOfTool(moves, raw) {
59
59
  const keys = Object.keys(moves).filter((k) => toolOf(k) === tool);
60
60
  return keys.find((k) => moves[k].propose) ?? (Object.hasOwn(moves, raw) ? raw : keys[0]) ?? null;
61
61
  }
62
+ /**
63
+ * A selection of the chat as a Markdown quote: `> ` before each of its lines, an empty line
64
+ * after it, so the reply starts below.
65
+ */
66
+ export function quoted(sel) {
67
+ const lines = sel
68
+ .replace(/\r\n?/g, '\n')
69
+ .replace(/^\n+|\n+$/g, '')
70
+ .split('\n');
71
+ return `${lines.map((l) => (l ? `> ${l}` : '>')).join('\n')}\n\n`;
72
+ }
73
+ // A reply to an agent's message (Board-Use-Plan d1): the board server writes it into the text
74
+ // after the operator's words, so every way in (a run, a thread, the queue, a fresh session) carries it.
75
+ const REPLY_HEAD = (at) => `[in reply to the agent's message of ${at}]`;
76
+ const REPLY_LINE = /^\[in reply to the agent's message of (\d{4}-\d\d-\d\dT[\d:.]+Z)\]$/gm;
77
+ /** The longest part of the agent's text a reply quotes. */
78
+ export const REPLY_QUOTE_MAX = 2000;
79
+ /**
80
+ * The block a reply adds to the operator's words: its head, then the agent's text quoted, cut to
81
+ * REPLY_QUOTE_MAX and to `room` characters of the whole block.
82
+ */
83
+ export function replyBlock(at, text, room = Infinity) {
84
+ const head = `\n\n${REPLY_HEAD(at)}\n`;
85
+ let take = Math.min(REPLY_QUOTE_MAX, text.length);
86
+ for (;;) {
87
+ const part = text.slice(0, take).trimEnd();
88
+ const block = `${head}${quoted(take < text.length ? `${part} …` : part).trimEnd()}`;
89
+ if (block.length <= room)
90
+ return block;
91
+ // No room for even its head: the words go without the link rather than be refused.
92
+ if (take === 0)
93
+ return '';
94
+ take = Math.max(0, take - (block.length - room));
95
+ }
96
+ }
97
+ /** A message's last reply marker: the agent message it answers, and the text without its line. */
98
+ export function replyOf(text) {
99
+ const last = [...text.matchAll(REPLY_LINE)].at(-1);
100
+ if (!last || last.index === undefined)
101
+ return { at: null, text };
102
+ return {
103
+ at: last[1],
104
+ text: text.slice(0, last.index) + text.slice(last.index + last[0].length + 1),
105
+ };
106
+ }