@vibefield/rosetta-room 0.1.2 → 0.1.4
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 +82 -4
- package/dist/HistoryRoom.d.ts +15 -2
- package/dist/HistoryRoom.js +82 -25
- package/dist/TranscriptReader.d.ts +7 -0
- package/dist/TranscriptReader.js +4 -4
- package/dist/components/ColdStart.js +1 -1
- package/dist/components/IngestStatus.d.ts +13 -0
- package/dist/components/IngestStatus.js +39 -3
- package/dist/components/ListActivityNotice.d.ts +9 -1
- package/dist/components/ListActivityNotice.js +9 -2
- package/dist/components/SummaryPanels.d.ts +5 -0
- package/dist/components/SummaryPanels.js +16 -5
- package/dist/components/Transcript.d.ts +5 -0
- package/dist/components/Transcript.js +20 -5
- package/dist/components/artifacts/ArtifactLibrary.d.ts +14 -0
- package/dist/components/artifacts/ArtifactLibrary.js +156 -0
- package/dist/components/artifacts/content.d.ts +8 -0
- package/dist/components/artifacts/content.js +27 -0
- package/dist/components/artifacts/load-all.d.ts +5 -0
- package/dist/components/artifacts/load-all.js +31 -0
- package/dist/components/artifacts/preview.d.ts +4 -0
- package/dist/components/artifacts/preview.js +37 -0
- package/dist/components/artifacts/thumbnails.d.ts +13 -0
- package/dist/components/artifacts/thumbnails.js +43 -0
- package/dist/components/projects/ProjectList.d.ts +9 -3
- package/dist/components/projects/ProjectList.js +3 -3
- package/dist/components/projects/ProjectListItem.d.ts +9 -3
- package/dist/components/projects/ProjectListItem.js +18 -12
- package/dist/components/projects/ProjectsColumn.d.ts +4 -1
- package/dist/components/projects/ProjectsColumn.js +23 -9
- package/dist/components/search/SearchSheet.d.ts +39 -2
- package/dist/components/search/SearchSheet.js +81 -17
- package/dist/components/sessions/SessionList.d.ts +6 -1
- package/dist/components/sessions/SessionList.js +50 -20
- package/dist/components/sessions/SessionListItem.d.ts +3 -1
- package/dist/components/sessions/SessionListItem.js +17 -7
- package/dist/components/sessions/SessionsColumn.d.ts +3 -1
- package/dist/components/sessions/SessionsColumn.js +2 -2
- package/dist/components/sessions/session-display.d.ts +4 -1
- package/dist/components/sessions/session-display.js +13 -2
- package/dist/components/transcript/Attachments.js +6 -1
- package/dist/components/transcript/Document.d.ts +6 -1
- package/dist/components/transcript/Document.js +19 -6
- package/dist/components/transcript/ImportState.d.ts +35 -0
- package/dist/components/transcript/ImportState.js +86 -0
- package/dist/components/transcript/TranscriptLoading.js +15 -5
- package/dist/components/transcript/attachment-file-source.d.ts +2 -0
- package/dist/components/transcript/attachment-file-source.js +6 -6
- package/dist/components/transcript/attachment-gallery.d.ts +2 -1
- package/dist/components/transcript/attachment-gallery.js +2 -1
- package/dist/components/transcript/detail-parts.js +7 -6
- package/dist/components/transcript/timeline-meta-file-source.d.ts +2 -1
- package/dist/components/transcript/timeline-meta-file-source.js +45 -5
- package/dist/components/ui/EmptyState.d.ts +5 -1
- package/dist/components/ui/EmptyState.js +2 -2
- package/dist/components/ui/Meter.d.ts +8 -0
- package/dist/components/ui/Meter.js +9 -0
- package/dist/components/ui/SegmentedControl.d.ts +2 -0
- package/dist/components/ui/SegmentedControl.js +1 -1
- package/dist/components/ui/Veil.d.ts +2 -1
- package/dist/components/ui/Veil.js +9 -2
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/fixtures/cold-import-corpus.d.ts +76 -0
- package/dist/fixtures/cold-import-corpus.js +349 -0
- package/dist/fixtures/cold-import-daemon.d.ts +25 -0
- package/dist/fixtures/cold-import-daemon.js +82 -0
- package/dist/fixtures/cold-import-schedule.d.ts +74 -0
- package/dist/fixtures/cold-import-schedule.js +191 -0
- package/dist/fixtures/cold-import.d.ts +151 -0
- package/dist/fixtures/cold-import.js +786 -0
- package/dist/fixtures/index.d.ts +2 -0
- package/dist/fixtures/index.js +21 -2
- package/dist/lib/activity-order.d.ts +15 -0
- package/dist/lib/activity-order.js +24 -1
- package/dist/lib/conversation-readiness.d.ts +48 -0
- package/dist/lib/conversation-readiness.js +149 -0
- package/dist/lib/figure-order.d.ts +35 -0
- package/dist/lib/figure-order.js +68 -0
- package/dist/lib/hooks.d.ts +32 -10
- package/dist/lib/hooks.js +118 -54
- package/dist/lib/image-media.d.ts +12 -2
- package/dist/lib/image-media.js +40 -6
- package/dist/lib/import-state.d.ts +98 -0
- package/dist/lib/import-state.js +129 -0
- package/dist/lib/ingest-activity.d.ts +51 -0
- package/dist/lib/ingest-activity.js +109 -10
- package/dist/lib/model.d.ts +16 -0
- package/dist/lib/model.js +27 -1
- package/dist/lib/search-sheet.d.ts +43 -0
- package/dist/lib/search-sheet.js +56 -7
- package/dist/lib/session-activity.d.ts +4 -1
- package/dist/lib/session-activity.js +4 -1
- package/dist/lib/title-search.d.ts +82 -0
- package/dist/lib/title-search.js +194 -0
- package/dist/lib/transcript/images.js +2 -2
- package/dist/lib/transcript/sittings.d.ts +7 -4
- package/dist/lib/transcript/sittings.js +14 -8
- package/dist/lib/use-deferred-list-order.d.ts +6 -0
- package/dist/lib/use-deferred-list-order.js +8 -1
- package/dist/lib/use-ingest-activity.d.ts +5 -1
- package/dist/lib/use-ingest-activity.js +54 -18
- package/dist/ports.d.ts +15 -2
- package/dist/styles/artifacts.css +66 -0
- package/dist/styles/history-room.css +1 -0
- package/dist/styles/ingest.css +26 -3
- package/dist/styles/room.css +15 -0
- package/dist/styles/search.css +17 -0
- package/package.json +2 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// The simulated daemon's REST doors, as a `fetch` a host's RosettaClient takes
|
|
2
|
+
// (`RosettaClientOptions.fetchFn`): the routes and the wire shapes rosettad
|
|
3
|
+
// answers (crates/server/src/http.rs), each JSON body stamped with the
|
|
4
|
+
// protocol version the SDK checks, each refusal the daemon's error body. A
|
|
5
|
+
// host that builds the room's ports over its own client (rosetta's app:
|
|
6
|
+
// `catalogOver`, the roll call) then runs its real code against the
|
|
7
|
+
// simulator; only the sockets stay the simulator's (`cold-import.ts`).
|
|
8
|
+
import { PROTOCOL_VERSION } from "@vibefield/rosetta-protocol";
|
|
9
|
+
/** A refusal, as the daemon words it (`ApiError`). */
|
|
10
|
+
export class ColdWireError extends Error {
|
|
11
|
+
status;
|
|
12
|
+
code;
|
|
13
|
+
constructor(status, code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const aborted = () => new DOMException("The ask was aborted", "AbortError");
|
|
20
|
+
function answer(status, body) {
|
|
21
|
+
return new Response(JSON.stringify(body), {
|
|
22
|
+
status,
|
|
23
|
+
headers: { "content-type": "application/json", "x-rosetta-protocol-version": String(PROTOCOL_VERSION) },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function bodyOf(init) {
|
|
27
|
+
return typeof init?.body === "string" ? JSON.parse(init.body) : {};
|
|
28
|
+
}
|
|
29
|
+
/** The routes the SDK asks (clients/ts/client.ts), answered over `wire`. */
|
|
30
|
+
export function fetchOver(wire) {
|
|
31
|
+
const route = async (url, init) => {
|
|
32
|
+
const method = init?.method ?? "GET";
|
|
33
|
+
const signal = init?.signal ?? undefined;
|
|
34
|
+
const path = url.pathname.split("/").filter((part) => part !== "").map(decodeURIComponent);
|
|
35
|
+
const query = (key) => url.searchParams.get(key);
|
|
36
|
+
const at = `${method} /${path.join("/")}`;
|
|
37
|
+
if (at === "GET /api/status")
|
|
38
|
+
return wire.status(signal);
|
|
39
|
+
if (at === "GET /api/discoveries")
|
|
40
|
+
return wire.discoveries();
|
|
41
|
+
if (at === "POST /api/runtimes/enable")
|
|
42
|
+
return wire.enableRuntimes(bodyOf(init).kinds ?? []);
|
|
43
|
+
if (at === "POST /api/ingest/boost")
|
|
44
|
+
return wire.boost(String(bodyOf(init).session_id ?? ""));
|
|
45
|
+
if (at === "GET /api/artifacts")
|
|
46
|
+
return wire.artifacts();
|
|
47
|
+
if (at === "GET /api/search") {
|
|
48
|
+
return wire.search({
|
|
49
|
+
q: query("q") ?? "", limit: Number(query("limit") ?? 50), project: query("project"), kind: query("kind"), agent: query("agent"),
|
|
50
|
+
}, signal);
|
|
51
|
+
}
|
|
52
|
+
if (method === "GET" && path[0] === "api" && path[1] === "projects" && path[2] !== undefined) {
|
|
53
|
+
const projectId = path[2];
|
|
54
|
+
const rest = path.slice(3).join("/");
|
|
55
|
+
if (rest === "heatmap")
|
|
56
|
+
return wire.heatmap(projectId);
|
|
57
|
+
if (rest === "contribution")
|
|
58
|
+
return wire.contribution(projectId);
|
|
59
|
+
if (rest === "usage")
|
|
60
|
+
return wire.usage(projectId);
|
|
61
|
+
if (rest === "usage/day")
|
|
62
|
+
return wire.dayUsage(projectId, query("day") ?? "");
|
|
63
|
+
}
|
|
64
|
+
throw new ColdWireError(404, "not_found", `The simulated daemon has no route ${at}`);
|
|
65
|
+
};
|
|
66
|
+
return async (input, init) => {
|
|
67
|
+
const href = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
68
|
+
if (init?.signal?.aborted)
|
|
69
|
+
throw aborted();
|
|
70
|
+
try {
|
|
71
|
+
const body = await route(new URL(href), init);
|
|
72
|
+
if (init?.signal?.aborted)
|
|
73
|
+
throw aborted();
|
|
74
|
+
return answer(200, body);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof ColdWireError)
|
|
78
|
+
return answer(error.status, { error: { code: error.code, message: error.message } });
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { RuntimeRow } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { ColdCorpus, ColdTree } from "./cold-import-corpus.js";
|
|
3
|
+
/** The hub's per-subscriber queue (crates/server/src/hub.rs:44). */
|
|
4
|
+
export declare const SUBSCRIBER_QUEUE = 1024;
|
|
5
|
+
/** Before consent the daemon's first walk is still discovering. */
|
|
6
|
+
export declare const DISCOVERY_MS = 300;
|
|
7
|
+
export type ColdPhase = "consent" | "restoring" | "metadata" | "first-flip" | "newest-giant" | "reading-done" | "runtime-close" | "finalizing" | "publishing" | "canonical" | "reveal" | "live" | "search-indexing" | "search-optimizing" | "search-validating" | "search-publishing" | "search-ready";
|
|
8
|
+
export interface Lane {
|
|
9
|
+
readonly start: number;
|
|
10
|
+
readonly end: number;
|
|
11
|
+
readonly bytes: number;
|
|
12
|
+
/** Each tree's byte span inside the lane, in walk order. */
|
|
13
|
+
readonly spans: readonly {
|
|
14
|
+
readonly tree: ColdTree;
|
|
15
|
+
readonly from: number;
|
|
16
|
+
readonly to: number;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
/** One runtime's stages, in simulated ms. */
|
|
20
|
+
export interface RuntimeTimes {
|
|
21
|
+
readonly runtime: RuntimeRow;
|
|
22
|
+
/** Registered, queued, with discovery's census denominators. */
|
|
23
|
+
readonly register: number;
|
|
24
|
+
/** A resume's replay of the staged ledger (`restoring`); null when fresh. */
|
|
25
|
+
readonly replay: {
|
|
26
|
+
readonly start: number;
|
|
27
|
+
readonly end: number;
|
|
28
|
+
readonly bytes: number;
|
|
29
|
+
} | null;
|
|
30
|
+
readonly skimStart: number;
|
|
31
|
+
/** The skim lands and its metadata is public. */
|
|
32
|
+
readonly metaPublic: number;
|
|
33
|
+
/** Capture (fresh) or catch-up (resumed) streams from here. */
|
|
34
|
+
readonly streamStart: number;
|
|
35
|
+
/** Reading is over: `preparing`. */
|
|
36
|
+
readonly readEnd: number;
|
|
37
|
+
/** The producer's close applies (fresh only). */
|
|
38
|
+
readonly applying: number | null;
|
|
39
|
+
/** `done`. */
|
|
40
|
+
readonly close: number;
|
|
41
|
+
/** What this run reads: fresh, every tree; resumed, the catch-up. */
|
|
42
|
+
readonly lanes: readonly Lane[];
|
|
43
|
+
readonly trees: readonly ColdTree[];
|
|
44
|
+
readonly bytes: number;
|
|
45
|
+
readonly files: number;
|
|
46
|
+
readonly sessions: number;
|
|
47
|
+
}
|
|
48
|
+
/** How a batch of trees leaves Pending. `tree`: a flip transaction during
|
|
49
|
+
* capture. `close`: bound trees at their producer's close. `publication`:
|
|
50
|
+
* a resume's one commit, public only at publication. */
|
|
51
|
+
export type FlipKind = "tree" | "close" | "publication";
|
|
52
|
+
/** One flip: these trees' rostered sessions leave Pending. */
|
|
53
|
+
export interface FlipBatch {
|
|
54
|
+
readonly at: number;
|
|
55
|
+
/** Empty for a resume's publication, which spans every runtime. */
|
|
56
|
+
readonly runtimeId: string;
|
|
57
|
+
readonly trees: readonly ColdTree[];
|
|
58
|
+
readonly sessions: readonly string[];
|
|
59
|
+
readonly kind: FlipKind;
|
|
60
|
+
}
|
|
61
|
+
export interface Schedule {
|
|
62
|
+
readonly course: "fresh" | "resumed";
|
|
63
|
+
/** Runtimes (by id) a fresh build admits whole, at their close. */
|
|
64
|
+
readonly whole: ReadonlySet<string>;
|
|
65
|
+
readonly consentAt: number;
|
|
66
|
+
readonly runtimes: readonly RuntimeTimes[];
|
|
67
|
+
readonly batches: readonly FlipBatch[];
|
|
68
|
+
readonly flipAt: ReadonlyMap<string, number>;
|
|
69
|
+
readonly phases: ReadonlyMap<ColdPhase, number>;
|
|
70
|
+
/** A resume's commit into the RAM store (snapshots read it; the hub does
|
|
71
|
+
* not); null for a fresh build, whose flips commit and publish at once. */
|
|
72
|
+
readonly commitAt: number | null;
|
|
73
|
+
}
|
|
74
|
+
export declare function planSchedule(corpus: ColdCorpus, enrolled: readonly RuntimeRow[], consentAt: number, course: "fresh" | "resumed", whole?: ReadonlySet<string>): Schedule;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/** The hub's per-subscriber queue (crates/server/src/hub.rs:44). */
|
|
2
|
+
export const SUBSCRIBER_QUEUE = 1_024;
|
|
3
|
+
const FLIP_INTERVAL_MS = 100;
|
|
4
|
+
const FLIP_MAX_TREES = 64;
|
|
5
|
+
const FLIP_MAX_SESSIONS = 512;
|
|
6
|
+
const FLIP_MAX_TAIL_BYTES = 16 * 1024 * 1024;
|
|
7
|
+
const TAIL_SHARE = 0.025;
|
|
8
|
+
/** The sole writer returns to the flip loop between apply transactions;
|
|
9
|
+
* this grid gives about the trace's cadence (178 batches over ~106 s). */
|
|
10
|
+
const WRITER_RETURN_MS = 600;
|
|
11
|
+
/** Before consent the daemon's first walk is still discovering. */
|
|
12
|
+
export const DISCOVERY_MS = 300;
|
|
13
|
+
/** A fresh build: offsets from consent, ms. Two entries: claude-code, codex. */
|
|
14
|
+
const FRESH = {
|
|
15
|
+
register: 40, skimStart: 80,
|
|
16
|
+
metaPublic: [2_400, 2_480], captureLatency: 2_200,
|
|
17
|
+
readEnd: [108_900, 32_700], applying: [110_400, 33_200], close: [110_900, 33_500],
|
|
18
|
+
publishing: 133_000, canonical: 139_200, reveal: 139_290, live: 139_350,
|
|
19
|
+
search: { indexing: 139_600, optimizing: 144_600, validating: 144_800, publishing: 145_000, ready: 145_300 },
|
|
20
|
+
};
|
|
21
|
+
/** A resume: each runtime's stages in turn (ms each), then the end, as
|
|
22
|
+
* offsets from the last runtime's close. */
|
|
23
|
+
const RESUMED = {
|
|
24
|
+
runtimes: [
|
|
25
|
+
{ replay: 2_400, skim: 300, catchUp: 21_000, prepare: 500 },
|
|
26
|
+
{ replay: 800, skim: 150, catchUp: 3_500, prepare: 300 },
|
|
27
|
+
],
|
|
28
|
+
finalizing: 5, publishing: 8_705, canonical: 12_705, reveal: 12_745, live: 12_805,
|
|
29
|
+
search: { indexing: 13_005, optimizing: 16_005, validating: 16_205, publishing: 16_505, ready: 16_705 },
|
|
30
|
+
};
|
|
31
|
+
/** Walk one lane newest first (recency, then tree id) at a constant rate
|
|
32
|
+
* over [start, end]: a tree is ready once its last byte is read. */
|
|
33
|
+
function walkLane(trees, start, end) {
|
|
34
|
+
const ordered = [...trees].sort((a, b) => b.recency - a.recency || a.id.localeCompare(b.id));
|
|
35
|
+
let at = 0;
|
|
36
|
+
const spans = ordered.map((tree) => {
|
|
37
|
+
const from = at;
|
|
38
|
+
at += tree.bytes;
|
|
39
|
+
return { tree, from, to: at };
|
|
40
|
+
});
|
|
41
|
+
return { start, end, bytes: at, spans };
|
|
42
|
+
}
|
|
43
|
+
const tailOf = (tree) => Math.round(tree.bytes * TAIL_SHARE);
|
|
44
|
+
/** D9: the first ready batch at once, then at most one per 100 ms, taken
|
|
45
|
+
* when the writer comes back, capped by trees, sessions and tail bytes; a
|
|
46
|
+
* batch's first tree is always taken. */
|
|
47
|
+
function batchFlips(runtimeId, ready) {
|
|
48
|
+
const queue = [...ready].sort((a, b) => a.at - b.at || a.tree.id.localeCompare(b.tree.id));
|
|
49
|
+
const batches = [];
|
|
50
|
+
let last = null;
|
|
51
|
+
let next = 0;
|
|
52
|
+
while (next < queue.length) {
|
|
53
|
+
const head = queue[next].at;
|
|
54
|
+
let at = last === null ? head : Math.max(head, last + FLIP_INTERVAL_MS);
|
|
55
|
+
if (last !== null)
|
|
56
|
+
at = Math.ceil(at / WRITER_RETURN_MS) * WRITER_RETURN_MS;
|
|
57
|
+
const trees = [];
|
|
58
|
+
let sessions = 0;
|
|
59
|
+
let tails = 0;
|
|
60
|
+
while (next < queue.length && queue[next].at <= at && trees.length < FLIP_MAX_TREES) {
|
|
61
|
+
const tree = queue[next].tree;
|
|
62
|
+
if (trees.length > 0 && (sessions + tree.members.length > FLIP_MAX_SESSIONS || tails + tailOf(tree) > FLIP_MAX_TAIL_BYTES))
|
|
63
|
+
break;
|
|
64
|
+
trees.push(tree);
|
|
65
|
+
sessions += tree.members.length;
|
|
66
|
+
tails += tailOf(tree);
|
|
67
|
+
next += 1;
|
|
68
|
+
}
|
|
69
|
+
batches.push({ at, runtimeId, trees, sessions: trees.flatMap((tree) => tree.members), kind: "tree" });
|
|
70
|
+
last = at;
|
|
71
|
+
}
|
|
72
|
+
return batches;
|
|
73
|
+
}
|
|
74
|
+
const filesOf = (trees) => Math.round(trees.reduce((sum, tree) => sum + tree.members.length, 0) * 1.72);
|
|
75
|
+
const bytesOf = (trees) => trees.reduce((sum, tree) => sum + tree.bytes, 0);
|
|
76
|
+
function planFresh(corpus, enrolled, consentAt, whole) {
|
|
77
|
+
const runtimes = [];
|
|
78
|
+
const batches = [];
|
|
79
|
+
for (const runtime of enrolled) {
|
|
80
|
+
const slot = corpus.runtimes.indexOf(runtime);
|
|
81
|
+
const trees = corpus.trees.filter((tree) => tree.runtimeId === runtime.id);
|
|
82
|
+
const metaPublic = consentAt + FRESH.metaPublic[slot];
|
|
83
|
+
const laneStart = metaPublic + FRESH.captureLatency;
|
|
84
|
+
const readEnd = consentAt + FRESH.readEnd[slot];
|
|
85
|
+
const lanes = [walkLane(trees.filter((t) => !t.big), laneStart, readEnd), walkLane(trees.filter((t) => t.big), laneStart, readEnd)];
|
|
86
|
+
const times = {
|
|
87
|
+
runtime, register: consentAt + FRESH.register, replay: null, skimStart: consentAt + FRESH.skimStart,
|
|
88
|
+
metaPublic, streamStart: metaPublic, readEnd,
|
|
89
|
+
applying: consentAt + FRESH.applying[slot], close: consentAt + FRESH.close[slot],
|
|
90
|
+
lanes, trees, bytes: bytesOf(trees), files: filesOf(trees),
|
|
91
|
+
sessions: corpus.sessions.filter((row) => row.runtime_id === runtime.id).length,
|
|
92
|
+
};
|
|
93
|
+
runtimes.push(times);
|
|
94
|
+
const perTree = !whole.has(runtime.id);
|
|
95
|
+
const ready = !perTree ? [] : lanes.flatMap((lane) => lane.spans.filter((span) => !span.tree.bound).map((span) => ({
|
|
96
|
+
tree: span.tree, at: Math.round(lane.start + ((lane.end - lane.start) * span.to) / Math.max(1, lane.bytes)),
|
|
97
|
+
})));
|
|
98
|
+
batches.push(...batchFlips(runtime.id, ready));
|
|
99
|
+
const bound = trees.filter((tree) => tree.bound || !perTree);
|
|
100
|
+
if (bound.length > 0) {
|
|
101
|
+
batches.push({ at: times.close, runtimeId: runtime.id, trees: bound, sessions: bound.flatMap((t) => t.members), kind: "close" });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { runtimes, batches };
|
|
105
|
+
}
|
|
106
|
+
function planResumed(corpus, enrolled, consentAt) {
|
|
107
|
+
const runtimes = [];
|
|
108
|
+
let at = consentAt;
|
|
109
|
+
for (const runtime of enrolled) {
|
|
110
|
+
const slot = corpus.runtimes.indexOf(runtime);
|
|
111
|
+
const stages = RESUMED.runtimes[slot];
|
|
112
|
+
const trees = corpus.trees.filter((tree) => tree.runtimeId === runtime.id);
|
|
113
|
+
// The interrupted build walked newest first: its ledger holds the newer
|
|
114
|
+
// half, which the replay restores; the catch-up reads the rest.
|
|
115
|
+
const byRecency = [...trees].sort((a, b) => b.recency - a.recency || a.id.localeCompare(b.id));
|
|
116
|
+
const restored = byRecency.slice(0, Math.ceil(byRecency.length / 2));
|
|
117
|
+
const unread = byRecency.slice(restored.length);
|
|
118
|
+
const replayEnd = at + stages.replay;
|
|
119
|
+
const metaPublic = replayEnd + stages.skim;
|
|
120
|
+
const readEnd = metaPublic + stages.catchUp;
|
|
121
|
+
const close = readEnd + stages.prepare;
|
|
122
|
+
runtimes.push({
|
|
123
|
+
runtime, register: consentAt, replay: { start: at, end: replayEnd, bytes: bytesOf(restored) },
|
|
124
|
+
skimStart: replayEnd, metaPublic, streamStart: metaPublic, readEnd, applying: null, close,
|
|
125
|
+
lanes: [walkLane(unread, metaPublic, readEnd)], trees, bytes: bytesOf(trees), files: filesOf(trees),
|
|
126
|
+
sessions: corpus.sessions.filter((row) => row.runtime_id === runtime.id).length,
|
|
127
|
+
});
|
|
128
|
+
at = close;
|
|
129
|
+
}
|
|
130
|
+
return { runtimes, lastClose: at };
|
|
131
|
+
}
|
|
132
|
+
export function planSchedule(corpus, enrolled, consentAt, course, whole = new Set()) {
|
|
133
|
+
const phases = new Map([["consent", consentAt]]);
|
|
134
|
+
let runtimes;
|
|
135
|
+
let batches;
|
|
136
|
+
let end;
|
|
137
|
+
let commitAt = null;
|
|
138
|
+
if (course === "fresh") {
|
|
139
|
+
({ runtimes, batches } = planFresh(corpus, enrolled, consentAt, whole));
|
|
140
|
+
const lastClose = Math.max(...runtimes.map((r) => r.close));
|
|
141
|
+
const from = (offset) => consentAt + offset;
|
|
142
|
+
end = {
|
|
143
|
+
finalizing: lastClose + 5, publishing: from(FRESH.publishing), canonical: from(FRESH.canonical),
|
|
144
|
+
reveal: from(FRESH.reveal), live: from(FRESH.live),
|
|
145
|
+
search: {
|
|
146
|
+
indexing: from(FRESH.search.indexing), optimizing: from(FRESH.search.optimizing), validating: from(FRESH.search.validating),
|
|
147
|
+
publishing: from(FRESH.search.publishing), ready: from(FRESH.search.ready),
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const planned = planResumed(corpus, enrolled, consentAt);
|
|
153
|
+
runtimes = planned.runtimes;
|
|
154
|
+
const from = (offset) => planned.lastClose + offset;
|
|
155
|
+
end = {
|
|
156
|
+
finalizing: from(RESUMED.finalizing), publishing: from(RESUMED.publishing), canonical: from(RESUMED.canonical),
|
|
157
|
+
reveal: from(RESUMED.reveal), live: from(RESUMED.live),
|
|
158
|
+
search: {
|
|
159
|
+
indexing: from(RESUMED.search.indexing), optimizing: from(RESUMED.search.optimizing), validating: from(RESUMED.search.validating),
|
|
160
|
+
publishing: from(RESUMED.search.publishing), ready: from(RESUMED.search.ready),
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
// Withheld until publication: one commit, public at the reveal.
|
|
164
|
+
const trees = runtimes.flatMap((r) => r.trees);
|
|
165
|
+
batches = [{ at: end.reveal, runtimeId: "", trees, sessions: trees.flatMap((t) => t.members), kind: "publication" }];
|
|
166
|
+
commitAt = end.publishing;
|
|
167
|
+
phases.set("restoring", consentAt);
|
|
168
|
+
}
|
|
169
|
+
batches.sort((a, b) => a.at - b.at || a.runtimeId.localeCompare(b.runtimeId));
|
|
170
|
+
const flipAt = new Map();
|
|
171
|
+
for (const batch of batches)
|
|
172
|
+
for (const tree of batch.trees)
|
|
173
|
+
if (!flipAt.has(tree.id))
|
|
174
|
+
flipAt.set(tree.id, batch.at);
|
|
175
|
+
phases.set("metadata", Math.max(...runtimes.map((r) => r.metaPublic)));
|
|
176
|
+
if (course === "fresh" && batches[0] !== undefined)
|
|
177
|
+
phases.set("first-flip", batches[0].at);
|
|
178
|
+
const giant = corpus.trees[0];
|
|
179
|
+
if (course === "fresh" && giant !== undefined && flipAt.has(giant.id))
|
|
180
|
+
phases.set("newest-giant", flipAt.get(giant.id));
|
|
181
|
+
phases.set("reading-done", Math.max(...runtimes.map((r) => r.readEnd)));
|
|
182
|
+
phases.set("runtime-close", Math.max(...runtimes.map((r) => r.close)));
|
|
183
|
+
for (const name of ["finalizing", "publishing", "canonical", "reveal", "live"])
|
|
184
|
+
phases.set(name, end[name]);
|
|
185
|
+
phases.set("search-indexing", end.search.indexing);
|
|
186
|
+
phases.set("search-optimizing", end.search.optimizing);
|
|
187
|
+
phases.set("search-validating", end.search.validating);
|
|
188
|
+
phases.set("search-publishing", end.search.publishing);
|
|
189
|
+
phases.set("search-ready", end.search.ready);
|
|
190
|
+
return { course, whole: course === "fresh" ? whole : new Set(), consentAt, runtimes, batches, flipAt, phases, commitAt };
|
|
191
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { IngestPhase, IngestionState, MetaState, MetaSubscriptionHandlers, RosettaClient, SessionRow, StatusResponse } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { CatalogStatus, Closable, RoomPorts } from "../ports.js";
|
|
3
|
+
import type { ColdCorpus, ColdCorpusOptions, ColdTree, SessionKind } from "./cold-import-corpus.js";
|
|
4
|
+
import type { ColdPhase, FlipBatch, RuntimeTimes } from "./cold-import-schedule.js";
|
|
5
|
+
export type { ColdCorpus, ColdCorpusOptions, ColdTree, SessionKind } from "./cold-import-corpus.js";
|
|
6
|
+
export type { ColdPhase, FlipBatch, FlipKind, RuntimeTimes } from "./cold-import-schedule.js";
|
|
7
|
+
export interface ColdImportOptions extends ColdCorpusOptions {
|
|
8
|
+
/** `fresh` (default): a first import. `resumed`: a cross-launch resume. */
|
|
9
|
+
readonly course?: "fresh" | "resumed";
|
|
10
|
+
/** `awaiting` (default for fresh): the app's roll call grants consent.
|
|
11
|
+
* `granted`: consent was given before (a resume always has it). */
|
|
12
|
+
readonly consent?: "awaiting" | "granted";
|
|
13
|
+
/** Agent kinds a fresh build admits whole, as a runtime-admission adapter
|
|
14
|
+
* or the kill switch has it: each of their sessions opens at its runtime's
|
|
15
|
+
* close. Default none: claude-code and codex admit per tree. */
|
|
16
|
+
readonly wholeRuntimes?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
/** One entry of the trail: every status ask and its fate, the grant, every
|
|
19
|
+
* metadata delivery and resync, and what a host marks (a connection change
|
|
20
|
+
* reaching the room), in one order. */
|
|
21
|
+
export interface ColdTrailEntry {
|
|
22
|
+
readonly seq: number;
|
|
23
|
+
/** Simulated ms. */
|
|
24
|
+
readonly at: number;
|
|
25
|
+
readonly what: string;
|
|
26
|
+
readonly detail: string | null;
|
|
27
|
+
}
|
|
28
|
+
/** What the room asked and heard, in order, with the simulated time. */
|
|
29
|
+
export interface ColdImportLog {
|
|
30
|
+
readonly status: number[];
|
|
31
|
+
readonly projectStats: {
|
|
32
|
+
readonly projectId: string;
|
|
33
|
+
readonly at: number;
|
|
34
|
+
}[];
|
|
35
|
+
readonly usage: number[];
|
|
36
|
+
readonly dayUsage: number[];
|
|
37
|
+
readonly search: {
|
|
38
|
+
readonly q: string;
|
|
39
|
+
readonly at: number;
|
|
40
|
+
}[];
|
|
41
|
+
readonly boosts: {
|
|
42
|
+
readonly sessionId: string;
|
|
43
|
+
readonly at: number;
|
|
44
|
+
}[];
|
|
45
|
+
readonly opened: string[];
|
|
46
|
+
readonly closed: string[];
|
|
47
|
+
readonly subscribed: {
|
|
48
|
+
readonly sessionId: string;
|
|
49
|
+
readonly at: number;
|
|
50
|
+
}[];
|
|
51
|
+
readonly enabled: {
|
|
52
|
+
readonly kinds: readonly string[];
|
|
53
|
+
readonly at: number;
|
|
54
|
+
}[];
|
|
55
|
+
/** Every metadata delivery: a snapshot (after a resync) or mutations. */
|
|
56
|
+
readonly meta: {
|
|
57
|
+
readonly seq: number;
|
|
58
|
+
readonly at: number;
|
|
59
|
+
readonly source: "snapshot" | "mutation";
|
|
60
|
+
readonly rows: number;
|
|
61
|
+
readonly why: string;
|
|
62
|
+
}[];
|
|
63
|
+
readonly resyncs: {
|
|
64
|
+
readonly seq: number;
|
|
65
|
+
readonly sessionId: string;
|
|
66
|
+
readonly at: number;
|
|
67
|
+
readonly delivered: boolean;
|
|
68
|
+
}[];
|
|
69
|
+
readonly trail: ColdTrailEntry[];
|
|
70
|
+
}
|
|
71
|
+
/** How a barrier reaches an open transcript. `immediate`: its socket resyncs
|
|
72
|
+
* at once (a flip's resync lands before its metadata,
|
|
73
|
+
* crates/rosettad/src/cold_stream/flips.rs:9-11).
|
|
74
|
+
* `manual`: held until `deliverResyncs()`. `drop`: the subscription raced
|
|
75
|
+
* the barrier and hears nothing. */
|
|
76
|
+
export type ResyncMode = "immediate" | "manual" | "drop";
|
|
77
|
+
export interface ColdImportController {
|
|
78
|
+
readonly corpus: ColdCorpus;
|
|
79
|
+
/** Epoch ms of the import clock's zero (the daemon's start). */
|
|
80
|
+
readonly now: number;
|
|
81
|
+
/** Simulated ms since the daemon started. */
|
|
82
|
+
readonly clock: number;
|
|
83
|
+
readonly course: "fresh" | "resumed";
|
|
84
|
+
readonly log: ColdImportLog;
|
|
85
|
+
resyncMode: ResyncMode;
|
|
86
|
+
/** When a phase happens, in simulated ms; null before consent places it
|
|
87
|
+
* (or for a phase this course has not). */
|
|
88
|
+
phaseAt(phase: ColdPhase): number | null;
|
|
89
|
+
/** A runtime's stages (by runtime id); null before consent. */
|
|
90
|
+
runtimeAt(runtimeId: string): RuntimeTimes | null;
|
|
91
|
+
/** When a tree (by its root id, or any rostered member) leaves Pending in
|
|
92
|
+
* the catalog; null when it never does or consent has not placed it yet. */
|
|
93
|
+
flipAt(sessionId: string): number | null;
|
|
94
|
+
kindOf(sessionId: string): SessionKind | null;
|
|
95
|
+
treeOf(sessionId: string): ColdTree | null;
|
|
96
|
+
/** The flip batches, in order, once consent placed them. */
|
|
97
|
+
batches(): readonly FlipBatch[];
|
|
98
|
+
/** Deliver everything up to `ms`, in order, then rest there. */
|
|
99
|
+
advanceTo(ms: number): void;
|
|
100
|
+
advanceToPhase(phase: ColdPhase): void;
|
|
101
|
+
/** The metadata the hub publishes now. */
|
|
102
|
+
meta(): MetaState;
|
|
103
|
+
/** One session's published stream state; null while it is not public. */
|
|
104
|
+
streamState(sessionId: string): SessionRow["stream_state"] | null;
|
|
105
|
+
/** What `/api/status` answers now, as the room reads it. */
|
|
106
|
+
status(): CatalogStatus;
|
|
107
|
+
/** The same, as the wire says it. */
|
|
108
|
+
statusResponse(): StatusResponse;
|
|
109
|
+
/** Just its phase, cheaply. */
|
|
110
|
+
phase(): IngestPhase;
|
|
111
|
+
/** Hold every status answer until `releaseStatus()` (answered then, at the
|
|
112
|
+
* simulated time of the release), so a test can see whether the room asks. */
|
|
113
|
+
holdStatus(): void;
|
|
114
|
+
releaseStatus(): number;
|
|
115
|
+
/** Status asks waiting on a hold. */
|
|
116
|
+
heldStatus(): number;
|
|
117
|
+
/** Deliver the resyncs `manual` mode held; returns how many. */
|
|
118
|
+
deliverResyncs(): number;
|
|
119
|
+
/** Refuse the next subscription's first snapshot as the shared-cache lock
|
|
120
|
+
* does during the build: the SDK hears the `not_ready` error frame and
|
|
121
|
+
* reconnects, which `retryRefused()` completes. */
|
|
122
|
+
refuseNextSnapshot(): void;
|
|
123
|
+
/** The refused subscriptions' reconnect: their snapshots; returns how many. */
|
|
124
|
+
retryRefused(): number;
|
|
125
|
+
/** The run's control state as the wire says it (`run.state`). Only the
|
|
126
|
+
* wire changes: a test that pauses does not advance until it resumes. */
|
|
127
|
+
setRunState(state: IngestionState): void;
|
|
128
|
+
/** Fire what a host fires when its route to the daemon changes, to every
|
|
129
|
+
* listener of `ports.catalog.onConnectionChange`; returns how many. */
|
|
130
|
+
connectionChange(): number;
|
|
131
|
+
/** Put a host-side event on the trail, in order with the daemon's. */
|
|
132
|
+
mark(what: string, detail?: string): void;
|
|
133
|
+
/** Make one project's figures fail (a 500, as a daemon mid-restart
|
|
134
|
+
* answers) until called with `false`; the ask is still logged. */
|
|
135
|
+
failFigures(projectId: string, failing: boolean): void;
|
|
136
|
+
}
|
|
137
|
+
export interface ColdImport {
|
|
138
|
+
readonly ports: RoomPorts;
|
|
139
|
+
/** The app's roll call client (`RollCallPanel`'s); granting consent
|
|
140
|
+
* places the schedule. */
|
|
141
|
+
readonly consent: Pick<RosettaClient, "discoveries" | "enableRuntimes">;
|
|
142
|
+
/** The same daemon for a host that builds its ports over a RosettaClient:
|
|
143
|
+
* its REST routes as a `fetchFn`, and /ws/meta, which a fixture has no
|
|
144
|
+
* socket for. Every ask goes through the same simulator and its log. */
|
|
145
|
+
readonly daemon: {
|
|
146
|
+
readonly fetch: typeof fetch;
|
|
147
|
+
subscribeMeta(handlers: MetaSubscriptionHandlers): Closable;
|
|
148
|
+
};
|
|
149
|
+
readonly controller: ColdImportController;
|
|
150
|
+
}
|
|
151
|
+
export declare function createColdImport(options: ColdImportOptions): ColdImport;
|