Three-phase session status: derived summaries for the picker

- core/phases.ts: Phase3 (probe/plan/teach) + pure derivations —
  phaseOfTree (point-in-time, from the stored plan tree: no nodes → probe,
  no occupied node → plan, occupied → teach) and phaseAt3 (monotonic
  transcript fold for the dividers: failed plan_init never marks a seam;
  phase only advances).
- contracts.ts: ChatSummary gains record-derived phase + pendingQuestion;
  ChatListItem adds liveness-merged busy.
- store/chats.ts listChats computes the record-derived fields (tree +
  pending question scan).
- api/chats route merges busy = turn running || running background job.

Lane crossing granted by master: contracts/store/api (schema arbitration).
Data-only inference: pre-plan planning reads as probe until the plan lands.
This commit is contained in:
Amos
2026-09-01 18:24:13 +03:00
parent cf3225fb23
commit 1c3d288d08
5 changed files with 241 additions and 5 deletions
+11 -2
View File
@@ -1,7 +1,16 @@
import { createChat, listChats, titleFromPrompt } from "@/src/server";
import { createChat, isTurnRunning, listChats, listJobs, titleFromPrompt } from "@/src/server";
import type { ChatListItem } from "@/src/core";
/** The session picker's list: record-derived summaries (phase, pending
* question) + live liveness — a running turn OR a background job marks
* the session busy (contracts.ts ChatListItem; the store can't see
* liveness, the route is the merge point). */
export async function GET() {
return Response.json({ chats: listChats() });
const chats: ChatListItem[] = listChats().map((c) => ({
...c,
busy: isTurnRunning(c.id) || listJobs(c.id).some((j) => j.status === "running"),
}));
return Response.json({ chats });
}
export async function POST(req: Request) {