Files
loki/scripts/test/multi-dispatch-prompt.ts
CatoandClaude Opus 5.5 b376ead370 feat(orangecat): a bot follows a run to its answer, and asks a one-off in a fresh session (#1658)
* feat(orangecat): a bot follows a run to its answer, and asks a one-off in a fresh session

A bot that sent a task could not reliably read the answer:
- the runner streams a conversation only while someone watches it, so a read
  a minute later found nothing, or an older conversation passed off as current
- a read by project took the project's latest open run, so an answer in a
  separate session could come back as the shared session's conversation
- a one-off session closes when it reports, leaving nothing to ask for after
- /api/orangecat/task could not ask for the fresh one-off session (#1640)

Now, on /api/orangecat/sessions:
- runId + watch (seconds, <= 300): the bot holds that run's session as a
  viewer for that long (lib/integrations/orangecat-watch.ts), so the runner
  streams the conversation while the agent works
- runId + items: the last items of THAT run's own session (its lane or
  one-off tab), on that run's builder
- every row carries the agent's handoff once it reports (lib/run-handoff):
  the answer survives the session being closed
- a read with nobody viewing waits for a snapshot newer than its join; an
  older copy alone comes back marked live: false

On /api/orangecat/task: session "fresh" (and separateSession as its alias)
gives each project a one-off session; a busy project is no reason to refuse it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsQh5BSKKaJXnf4KjU

* fix(orangecat): a signed task outside its window is refused; a run whose track fails is never read as idle

From review of the rail:
- /api/orangecat/task had no freshness window, so a captured signed request
  could be replayed to start agent sessions later. It now takes issuedAt and
  refuses one older than the read doors' window (optional until every
  OrangeCat sends it; OrangeCat sends it from now on)
- a sessions read whose run track failed to load reported the run as Idle
  with no runId, which a follower took for settled. Such a run is now said
  from its own row: working while open, done or failed once closed, with
  its handoff

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsQh5BSKKaJXnf4KjU

* fix(orangecat): a follower's poll never reaches GitHub; a transcript read waits for the whole snapshot

From review:
- a bot following a run reads it every few seconds, and every runId read
  loaded the owner's full track, which looks at GitHub. poll: true reads the
  run's own facts and cached ledger only
- the runner posts a snapshot in batches of 100; a read returned on the
  first batch, so a long conversation came back without its tail. It now
  waits until the batches stop arriving

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsQh5BSKKaJXnf4KjU

* fix(orangecat): a session's task says what was asked, not the cross-project preamble

From review: for a task sent to several projects, the row's one-line task
was the first line of the preamble the agent is given ('Cross-project task.
The same request below was sent to ...'). askedOf takes the preamble off;
a prompt without one comes back as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmsQh5BSKKaJXnf4KjU

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 09:10:19 +01:00

50 lines
2.0 KiB
TypeScript

// One task, several projects — the pure half (src/lib/multi-dispatch-prompt.ts).
// Run: npx tsx scripts/test/multi-dispatch-prompt.ts
import {
askedOf,
buildProjectTaskPrompt,
normalizeTaskProjects,
} from "@/lib/multi-dispatch-prompt";
let pass = 0;
let fail = 0;
function ok(cond: boolean, label: string) {
if (cond) pass++;
else {
fail++;
console.error(`✗ ${label}`);
}
}
// normalize: trims, drops blanks, dedupes case-insensitively, keeps first spelling
const norm = normalizeTaskProjects([" OrangeCat ", "loki", "", "Loki", "orangecat", "solon"]);
ok(JSON.stringify(norm) === JSON.stringify(["OrangeCat", "loki", "solon"]), "normalize dedupes");
// one project → the task verbatim, no coordination preamble
ok(
buildProjectTaskPrompt(" Fix the header ", "Loki", ["Loki"]) === "Fix the header",
"single project verbatim",
);
// several → names everyone, names THIS project, and lists only the others as siblings
const p = buildProjectTaskPrompt("Post prompts from both apps", "Loki", ["OrangeCat", "Loki"]);
ok(p.includes("sent to 2 projects at once: OrangeCat, Loki"), "preamble lists all projects");
ok(p.includes("You are working in Loki."), "preamble names this project");
ok(p.includes("OrangeCat is handling its own part"), "siblings exclude this project (singular)");
ok(p.endsWith("Post prompts from both apps"), "task follows the preamble verbatim");
ok(askedOf(p) === "Post prompts from both apps", "askedOf takes the preamble off");
ok(
askedOf("Fix the header\n\n---\n\nmore") === "Fix the header\n\n---\n\nmore",
"askedOf leaves a plain prompt alone",
);
ok(p.includes("state the contract you assumed"), "asks for cross-repo contracts");
const three = buildProjectTaskPrompt("x", "solon", ["OrangeCat", "Loki", "Solon"]);
ok(
three.includes("OrangeCat, Loki are handling their own part"),
"siblings plural, case-insensitive self match",
);
console.log(`${pass}/${pass + fail} multi-dispatch-prompt cases passed`);
if (fail > 0) process.exit(1);