@vibefield/rosetta-room 0.1.1 → 0.1.3
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 +84 -27
- 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 +40 -3
- package/dist/components/IngestionControls.d.ts +6 -0
- package/dist/components/IngestionControls.js +75 -0
- 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 +82 -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/index.d.ts +1 -1
- package/dist/index.js +5 -0
- 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 +122 -55
- 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 +52 -0
- package/dist/lib/ingest-activity.js +127 -12
- package/dist/lib/ingest.d.ts +3 -0
- package/dist/lib/ingest.js +10 -0
- 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/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 +56 -20
- package/dist/ports.d.ts +21 -2
- package/dist/room-context.d.ts +1 -0
- package/dist/room-context.js +3 -2
- package/dist/styles/artifacts.css +66 -0
- package/dist/styles/history-room.css +1 -0
- package/dist/styles/ingest.css +32 -3
- package/dist/styles/room.css +15 -0
- package/dist/styles/search.css +17 -0
- package/package.json +2 -2
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
const MINUTE = 60_000;
|
|
2
|
+
const HOUR = 60 * MINUTE;
|
|
3
|
+
const DAY = 24 * HOUR;
|
|
4
|
+
const MB = 1_000_000;
|
|
5
|
+
const MIB = 1024 * 1024;
|
|
6
|
+
/** A tree whose largest source is over this walks the big lane
|
|
7
|
+
* (crates/pipeline/src/closed/walk_order.rs:38). */
|
|
8
|
+
export const BIG_SOURCE_BYTES = 64 * MIB;
|
|
9
|
+
/* ── seeded helpers ─────────────────────────────────────────────────────── */
|
|
10
|
+
/** mulberry32: a small, fast, seeded PRNG. Nothing here reads a clock. */
|
|
11
|
+
function random(seed) {
|
|
12
|
+
let state = seed >>> 0;
|
|
13
|
+
return () => {
|
|
14
|
+
state = (state + 0x6d2b79f5) >>> 0;
|
|
15
|
+
let t = state;
|
|
16
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
17
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
18
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4_294_967_296;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** A 64-hex id, the shape of a rosetta id (a blake3 digest): four rounds of
|
|
22
|
+
* a well-mixed 64-bit string hash (cyrb53's mixing). Like the daemon's
|
|
23
|
+
* digests, ordering by it is unrelated to recency or creation order. */
|
|
24
|
+
export function hexId(seed) {
|
|
25
|
+
let hex = "";
|
|
26
|
+
for (let round = 0; round < 4; round += 1) {
|
|
27
|
+
let h1 = 0xdeadbeef ^ Math.imul(round + 1, 0x9e3779b1);
|
|
28
|
+
let h2 = 0x41c6ce57 ^ Math.imul(round + 1, 0x85ebca6b);
|
|
29
|
+
for (let i = 0; i < seed.length; i += 1) {
|
|
30
|
+
const ch = seed.charCodeAt(i);
|
|
31
|
+
h1 = Math.imul(h1 ^ ch, 2_654_435_761);
|
|
32
|
+
h2 = Math.imul(h2 ^ ch, 1_597_334_677);
|
|
33
|
+
}
|
|
34
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2_246_822_507) ^ Math.imul(h2 ^ (h2 >>> 13), 3_266_489_909);
|
|
35
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2_246_822_507) ^ Math.imul(h1 ^ (h1 >>> 13), 3_266_489_909);
|
|
36
|
+
hex += (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
|
37
|
+
}
|
|
38
|
+
return hex;
|
|
39
|
+
}
|
|
40
|
+
function uuidOf(seed) {
|
|
41
|
+
const h = hexId(`native:${seed}`);
|
|
42
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20, 32)}`;
|
|
43
|
+
}
|
|
44
|
+
/** A standard normal draw (Box–Muller). */
|
|
45
|
+
function normal(rnd) {
|
|
46
|
+
return Math.sqrt(-2 * Math.log(1 - rnd())) * Math.cos(2 * Math.PI * rnd());
|
|
47
|
+
}
|
|
48
|
+
/** Split `total` over `weights` exactly (largest remainder). */
|
|
49
|
+
function apportion(total, weights) {
|
|
50
|
+
const sum = weights.reduce((a, b) => a + b, 0) || 1;
|
|
51
|
+
const raw = weights.map((w) => (total * w) / sum);
|
|
52
|
+
const out = raw.map(Math.floor);
|
|
53
|
+
let left = total - out.reduce((a, b) => a + b, 0);
|
|
54
|
+
const order = raw.map((r, i) => [r - Math.floor(r), i]).sort((a, b) => b[0] - a[0] || a[1] - b[1]);
|
|
55
|
+
for (let k = 0; left > 0; k = (k + 1) % order.length, left -= 1)
|
|
56
|
+
out[order[k][1]] += 1;
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
const TOPICS = [
|
|
60
|
+
"parser", "ledger", "walker", "sidebar", "charts", "search", "renderer", "importer",
|
|
61
|
+
"schema", "deploy", "billing", "theme", "auth", "cache", "worker", "router",
|
|
62
|
+
"fixtures", "metrics", "layout", "sync", "queue", "export", "budget", "lanes",
|
|
63
|
+
];
|
|
64
|
+
const ACTS = [
|
|
65
|
+
"tidy the walk", "fix the flaky test", "review the diff", "split the module", "trace the stall",
|
|
66
|
+
"draft the plan", "port the screen", "measure the cost", "rename the seam", "check the copy",
|
|
67
|
+
];
|
|
68
|
+
const PROJECT_WORDS = [
|
|
69
|
+
"rosetta", "vibe-field", "puppeteer", "canvas", "ghosttea", "truffle", "atlas", "mille",
|
|
70
|
+
"harbor", "quill", "lantern", "orbit", "pebble", "meadow", "forge", "signal",
|
|
71
|
+
];
|
|
72
|
+
/** Build the archive. Deterministic in (now, scale, seed); `now` only
|
|
73
|
+
* anchors the times, so every id, count and order is the same in any
|
|
74
|
+
* timezone and on any day. */
|
|
75
|
+
export function createColdCorpus(options) {
|
|
76
|
+
const scale = Math.min(1, Math.max(0.01, options.scale ?? 1));
|
|
77
|
+
const seed = options.seed ?? 1;
|
|
78
|
+
const now = options.now;
|
|
79
|
+
const rnd = random(seed * 2_654_435_761);
|
|
80
|
+
const n = (count, least) => Math.max(least, Math.round(count * scale));
|
|
81
|
+
// The trace's counts, scaled (its census line: roots=1139 sessions=8062
|
|
82
|
+
// big=40; its metadata line: sessions=8612 projects=119).
|
|
83
|
+
const treeCount = n(1139, 12);
|
|
84
|
+
const projectCount = n(119, 4);
|
|
85
|
+
const bigCount = n(40, 2);
|
|
86
|
+
const placeholderTrees = n(25, 1);
|
|
87
|
+
const neverRosteredRoots = n(60, 2);
|
|
88
|
+
const boundTrees = n(8, 1);
|
|
89
|
+
const dirtyTrees = n(5, 1);
|
|
90
|
+
const rostered = Math.max(treeCount + 4, n(8062, 0));
|
|
91
|
+
const metadata = Math.max(rostered + placeholderTrees + neverRosteredRoots, n(8612, 0));
|
|
92
|
+
const neverRosteredChildren = metadata - rostered - placeholderTrees - neverRosteredRoots;
|
|
93
|
+
const codexTrees = Math.max(1, Math.round(treeCount * 0.06));
|
|
94
|
+
const runtimes = ["claude-code", "codex"].map((kind) => ({
|
|
95
|
+
id: hexId(`runtime:${seed}:${kind}`), kind, data_root: kind === "codex" ? "~/.codex" : "~/.claude",
|
|
96
|
+
enabled: true, account: null, config: null, skills: null, versions_seen: null, discovered_at: now - 2 * HOUR,
|
|
97
|
+
}));
|
|
98
|
+
// Tree ages: a few trees within a day of the newest, a few more within a
|
|
99
|
+
// week, then a long tail over the year (the trace's census ages).
|
|
100
|
+
const recent = n(13, 3);
|
|
101
|
+
const week = n(14, 2);
|
|
102
|
+
const ages = [];
|
|
103
|
+
for (let i = 0; i < recent; i += 1)
|
|
104
|
+
ages.push(2 * MINUTE + (i / recent) ** 1.6 * 20 * HOUR + rnd() * 10 * MINUTE);
|
|
105
|
+
for (let i = 0; i < week; i += 1)
|
|
106
|
+
ages.push(DAY + ((i + rnd()) / week) * 6 * DAY);
|
|
107
|
+
for (let i = recent + week; i < treeCount; i += 1)
|
|
108
|
+
ages.push(7 * DAY * Math.exp(rnd() * Math.log(60)));
|
|
109
|
+
ages.sort((a, b) => a - b);
|
|
110
|
+
const drafts = ages.map((age, i) => ({
|
|
111
|
+
id: hexId(`tree:${seed}:${i}`), runtime: 0, age, big: false, bytes: 0, project: null,
|
|
112
|
+
children: 0, bound: false, dirty: false, placeholderRoot: false,
|
|
113
|
+
}));
|
|
114
|
+
const pick = (from, to, ok) => {
|
|
115
|
+
for (let tries = 0; tries < 400; tries += 1) {
|
|
116
|
+
const d = drafts[from + Math.floor(rnd() * Math.max(1, to - from))];
|
|
117
|
+
if (d !== undefined && ok(d))
|
|
118
|
+
return d;
|
|
119
|
+
}
|
|
120
|
+
return drafts.slice(from, to).find(ok) ?? null;
|
|
121
|
+
};
|
|
122
|
+
// Big trees: the newest is the giant; the recent ones are mostly big
|
|
123
|
+
// (le1h holds 2.5 GB in 23 files); the rest scatter over the tail.
|
|
124
|
+
drafts[0].big = true;
|
|
125
|
+
const recentBig = Math.min(recent - 2, n(4, 1));
|
|
126
|
+
const weekBig = Math.min(week - 1, n(6, 1));
|
|
127
|
+
for (let k = 0; k < recentBig; k += 1)
|
|
128
|
+
pick(1, recent, (d) => !d.big).big = true;
|
|
129
|
+
for (let k = 0; k < weekBig; k += 1)
|
|
130
|
+
pick(recent, recent + week, (d) => !d.big).big = true;
|
|
131
|
+
for (let k = 1 + recentBig + weekBig; k < bigCount; k += 1)
|
|
132
|
+
pick(recent + week, treeCount, (d) => !d.big).big = true;
|
|
133
|
+
// Codex trees: a few small ones among claude-code's, never the newest.
|
|
134
|
+
for (let k = 0; k < codexTrees; k += 1)
|
|
135
|
+
pick(1, treeCount, (d) => d.runtime === 0 && !d.big).runtime = 1;
|
|
136
|
+
// Bytes: the giant is the trace's 668 MB newest giant; big trees run
|
|
137
|
+
// 70 MB to 1.7 GB; small trees are log-normal around 45 KB (root_p50).
|
|
138
|
+
for (const d of drafts) {
|
|
139
|
+
d.bytes = d.big
|
|
140
|
+
? Math.round(70 * MB * Math.exp(rnd() ** 1.8 * Math.log(24)))
|
|
141
|
+
: Math.round(Math.min(60 * MB, Math.max(1_500, 45_000 * Math.exp(2.4 * normal(rnd)))));
|
|
142
|
+
}
|
|
143
|
+
drafts[0].bytes = 668_350_304;
|
|
144
|
+
// Projects: the newest work concentrates in a few projects; every
|
|
145
|
+
// project owns at least one tree; ~2% of trees have no proven owner.
|
|
146
|
+
const projectWeight = (p) => 1 / (p + 1) ** 0.9;
|
|
147
|
+
const zipf = (limit) => {
|
|
148
|
+
const total = Array.from({ length: limit }, (_, p) => projectWeight(p)).reduce((a, b) => a + b, 0);
|
|
149
|
+
let x = rnd() * total;
|
|
150
|
+
for (let p = 0; p < limit; p += 1) {
|
|
151
|
+
x -= projectWeight(p);
|
|
152
|
+
if (x <= 0)
|
|
153
|
+
return p;
|
|
154
|
+
}
|
|
155
|
+
return limit - 1;
|
|
156
|
+
};
|
|
157
|
+
drafts.forEach((d, i) => {
|
|
158
|
+
d.project = i === 0 ? 0 : i < recent ? zipf(Math.min(3, projectCount)) : i < recent + week ? zipf(Math.min(10, projectCount)) : zipf(projectCount);
|
|
159
|
+
});
|
|
160
|
+
// The newest project keeps a readable morning beside its giant: its small
|
|
161
|
+
// trees today and this week, whatever the draw gave.
|
|
162
|
+
for (const at of [1, 2, recent]) {
|
|
163
|
+
const d = drafts[at];
|
|
164
|
+
if (d !== undefined && !d.big && d.runtime === 0)
|
|
165
|
+
d.project = 0;
|
|
166
|
+
}
|
|
167
|
+
const owned = (p) => drafts.reduce((count, d) => count + (d.project === p ? 1 : 0), 0);
|
|
168
|
+
const tail = drafts.slice(recent + week);
|
|
169
|
+
for (let p = 0; p < projectCount; p += 1) {
|
|
170
|
+
if (owned(p) > 0)
|
|
171
|
+
continue;
|
|
172
|
+
const d = tail.find((t) => t.project !== 0 && owned(t.project) > 2) ?? tail[p % tail.length];
|
|
173
|
+
d.project = p;
|
|
174
|
+
}
|
|
175
|
+
for (let k = 0; k < Math.max(1, Math.round(treeCount * 0.02)); k += 1) {
|
|
176
|
+
const d = pick(recent + week, treeCount, (t) => t.project !== null && owned(t.project) > 2);
|
|
177
|
+
if (d !== null)
|
|
178
|
+
d.project = null;
|
|
179
|
+
}
|
|
180
|
+
// Bound trees: admitted only at the producer's close. One sits in the
|
|
181
|
+
// newest project, so a reader can open a not-imported row whose tree
|
|
182
|
+
// waits for the close.
|
|
183
|
+
const ownBound = drafts.find((d, i) => i > 2 && d.project === 0 && !d.big && d.runtime === 0);
|
|
184
|
+
if (ownBound !== undefined)
|
|
185
|
+
ownBound.bound = true;
|
|
186
|
+
for (let k = ownBound === undefined ? 0 : 1; k < boundTrees; k += 1) {
|
|
187
|
+
const d = pick(recent + week, treeCount, (t) => !t.big && !t.bound && t.runtime === 0);
|
|
188
|
+
if (d !== null)
|
|
189
|
+
d.bound = true;
|
|
190
|
+
}
|
|
191
|
+
// Placeholder roots: claude-code trees whose root transcript is gone. The
|
|
192
|
+
// first is the newest such tree outside the newest project: its family's
|
|
193
|
+
// activity is newer than any unassigned tree's, so publication's reveal
|
|
194
|
+
// (which shows it) moves the unassigned bucket at every scale. The rest
|
|
195
|
+
// are older.
|
|
196
|
+
const placeholderOk = (t) => !t.big && !t.bound && !t.placeholderRoot && t.runtime === 0 && t.project !== null && t.project !== 0;
|
|
197
|
+
for (let k = 0; k < placeholderTrees; k += 1) {
|
|
198
|
+
const d = (k === 0 ? drafts.slice(1).find(placeholderOk) ?? null : null) ?? pick(recent + week, treeCount, placeholderOk);
|
|
199
|
+
if (d !== null)
|
|
200
|
+
d.placeholderRoot = true;
|
|
201
|
+
}
|
|
202
|
+
// Dirty trees: the newest project's second-newest small tree (it flips
|
|
203
|
+
// long before the giant, so its Streaming row sits beside the
|
|
204
|
+
// not-imported ones), the rest scattered over the tail.
|
|
205
|
+
const ownDirty = [drafts[2], drafts[1]].find((d) => d !== undefined && !d.big && !d.bound && d.runtime === 0 && d.project === 0);
|
|
206
|
+
if (ownDirty !== undefined)
|
|
207
|
+
ownDirty.dirty = true;
|
|
208
|
+
for (let k = ownDirty === undefined ? 0 : 1; k < dirtyTrees; k += 1) {
|
|
209
|
+
const d = pick(recent + week, treeCount, (t) => !t.big && !t.bound && !t.dirty && !t.placeholderRoot);
|
|
210
|
+
if (d !== null)
|
|
211
|
+
d.dirty = true;
|
|
212
|
+
}
|
|
213
|
+
// Children: big trees carry the subagent swarms (one flip of 201 sessions
|
|
214
|
+
// in the trace), small trees a few or none; a placeholder needs one.
|
|
215
|
+
const childTotal = rostered - drafts.filter((d) => !d.placeholderRoot).length;
|
|
216
|
+
const weights = drafts.map((d) => d.big ? 40 + rnd() * 160 : d.runtime === 1 ? 0 : rnd() < 0.5 ? 0 : rnd() < 0.9 ? 1 + rnd() * 3 : 8 + rnd() * 30);
|
|
217
|
+
const counts = apportion(childTotal - placeholderTrees, weights);
|
|
218
|
+
drafts.forEach((d, i) => {
|
|
219
|
+
d.children = Math.min(500, counts[i] + (d.placeholderRoot ? 1 : 0));
|
|
220
|
+
});
|
|
221
|
+
// What the cap clipped goes to the oldest claude-code trees with room.
|
|
222
|
+
let spill = childTotal - drafts.reduce((a, d) => a + d.children, 0);
|
|
223
|
+
for (let pass = 0; spill > 0 && pass < 500; pass += 1) {
|
|
224
|
+
for (let i = drafts.length - 1; i >= 0 && spill > 0; i -= 1) {
|
|
225
|
+
const d = drafts[i];
|
|
226
|
+
if (d.children < 500 && d.runtime === 0) {
|
|
227
|
+
d.children += 1;
|
|
228
|
+
spill -= 1;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const projectRows = Array.from({ length: projectCount }, (_, p) => {
|
|
233
|
+
const name = `${PROJECT_WORDS[p % PROJECT_WORDS.length]}${p < PROJECT_WORDS.length ? "" : `-${Math.floor(p / PROJECT_WORDS.length) + 1}`}`;
|
|
234
|
+
return { id: hexId(`project:${seed}:${p}`), name, root_paths: [`/Users/demo/Projects/${name}`], git_repo: p % 3 === 0 ? null : `github.com/demo/${name}` };
|
|
235
|
+
});
|
|
236
|
+
const sessions = [];
|
|
237
|
+
const kind = new Map();
|
|
238
|
+
const own = new Map();
|
|
239
|
+
const children = new Map();
|
|
240
|
+
const trees = [];
|
|
241
|
+
const treeOf = new Map();
|
|
242
|
+
const bytesOf = new Map();
|
|
243
|
+
const adopt = (parent, child) => {
|
|
244
|
+
const list = children.get(parent);
|
|
245
|
+
if (list === undefined)
|
|
246
|
+
children.set(parent, [child]);
|
|
247
|
+
else
|
|
248
|
+
list.push(child);
|
|
249
|
+
};
|
|
250
|
+
/** Recorded bounds a little before the source's mtime. */
|
|
251
|
+
const bounds = (mtime) => {
|
|
252
|
+
const last = mtime - Math.round(rnd() * 50_000) - 1_000;
|
|
253
|
+
return { first_at: last - Math.round(MINUTE + rnd() ** 2 * 6 * HOUR), last_at: last };
|
|
254
|
+
};
|
|
255
|
+
const projectOf = (p) => (p === null ? null : projectRows[p]);
|
|
256
|
+
const cwdOf = (p, i) => projectOf(p)?.root_paths[0] ?? `/Users/demo/scratch/run-${i % 40}`;
|
|
257
|
+
drafts.forEach((d, i) => {
|
|
258
|
+
const runtime = runtimes[d.runtime];
|
|
259
|
+
const recency = now - Math.round(d.age);
|
|
260
|
+
const project = projectOf(d.project);
|
|
261
|
+
const cwd = cwdOf(d.project, i);
|
|
262
|
+
const topic = TOPICS[Math.floor(rnd() * TOPICS.length)];
|
|
263
|
+
const members = [];
|
|
264
|
+
const memberBytes = [];
|
|
265
|
+
if (d.placeholderRoot) {
|
|
266
|
+
// The parent row the child's skim made: unassigned, unnamed, Pending.
|
|
267
|
+
sessions.push({
|
|
268
|
+
id: d.id, native_session_id: uuidOf(d.id), runtime_id: runtime.id, project_id: null, cwd: null,
|
|
269
|
+
parent_session_id: null, delegation: null, root_session_id: d.id, role: "main", title: null, summary: null,
|
|
270
|
+
started_at: recency - HOUR, updated_at: recency, activity: null, stream_state: "pending",
|
|
271
|
+
});
|
|
272
|
+
kind.set(d.id, "placeholder");
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
const activity = bounds(recency);
|
|
276
|
+
sessions.push({
|
|
277
|
+
id: d.id, native_session_id: uuidOf(d.id), runtime_id: runtime.id, project_id: project?.id ?? null, cwd,
|
|
278
|
+
parent_session_id: null, delegation: null, root_session_id: d.id, role: "main",
|
|
279
|
+
title: `${topic}: ${ACTS[Math.floor(rnd() * ACTS.length)]} #${i}`, summary: null,
|
|
280
|
+
started_at: activity.first_at, updated_at: recency, activity: null, stream_state: "pending",
|
|
281
|
+
});
|
|
282
|
+
kind.set(d.id, "root");
|
|
283
|
+
own.set(d.id, activity);
|
|
284
|
+
members.push(d.id);
|
|
285
|
+
memberBytes.push(1 + rnd());
|
|
286
|
+
}
|
|
287
|
+
// Subagents: most under the root, some one level deeper; each wrote a
|
|
288
|
+
// little before the tree's newest file.
|
|
289
|
+
const made = [];
|
|
290
|
+
for (let c = 0; c < d.children; c += 1) {
|
|
291
|
+
const id = hexId(`child:${seed}:${i}:${c}`);
|
|
292
|
+
const parent = made.length > 0 && rnd() < 0.15 ? made[Math.floor(rnd() * made.length)] : d.id;
|
|
293
|
+
const mtime = recency - Math.round(rnd() * Math.min(d.age / 3, 6 * HOUR));
|
|
294
|
+
const activity = bounds(mtime);
|
|
295
|
+
sessions.push({
|
|
296
|
+
id, native_session_id: uuidOf(id), runtime_id: runtime.id, project_id: project?.id ?? null, cwd,
|
|
297
|
+
parent_session_id: parent, delegation: null, root_session_id: d.id, role: "subagent",
|
|
298
|
+
title: rnd() < 0.7 ? `${topic} subtask ${c + 1}` : null, summary: null,
|
|
299
|
+
started_at: activity.first_at, updated_at: mtime, activity: null, stream_state: "pending",
|
|
300
|
+
});
|
|
301
|
+
kind.set(id, "child");
|
|
302
|
+
own.set(id, activity);
|
|
303
|
+
adopt(parent, id);
|
|
304
|
+
made.push(id);
|
|
305
|
+
members.push(id);
|
|
306
|
+
memberBytes.push(rnd());
|
|
307
|
+
}
|
|
308
|
+
const tree = {
|
|
309
|
+
id: d.id, runtimeId: runtime.id, members, bytes: d.bytes, big: d.big, recency, bound: d.bound,
|
|
310
|
+
dirty: d.dirty && !d.placeholderRoot, placeholderRoot: d.placeholderRoot,
|
|
311
|
+
};
|
|
312
|
+
apportion(d.bytes, memberBytes).forEach((bytes, m) => {
|
|
313
|
+
bytesOf.set(members[m], bytes);
|
|
314
|
+
treeOf.set(members[m], tree);
|
|
315
|
+
});
|
|
316
|
+
trees.push(tree);
|
|
317
|
+
});
|
|
318
|
+
// Rows no source rosters: roots spread over the year (one of them in the
|
|
319
|
+
// newest project, this morning) and leaf children under flipping trees.
|
|
320
|
+
for (let k = 0; k < neverRosteredRoots; k += 1) {
|
|
321
|
+
const id = hexId(`unrostered:${seed}:${k}`);
|
|
322
|
+
const p = k === 0 ? 0 : zipf(projectCount);
|
|
323
|
+
const updated = now - Math.round(k === 0 ? 3 * HOUR : 2 * DAY * Math.exp(rnd() * Math.log(150)));
|
|
324
|
+
sessions.push({
|
|
325
|
+
id, native_session_id: uuidOf(id), runtime_id: runtimes[0].id, project_id: projectOf(p).id, cwd: cwdOf(p, k),
|
|
326
|
+
parent_session_id: null, delegation: null, root_session_id: id, role: "main",
|
|
327
|
+
title: `${TOPICS[k % TOPICS.length]}: an unrostered thread #${k}`, summary: null,
|
|
328
|
+
started_at: updated - HOUR, updated_at: updated, activity: null, stream_state: "pending",
|
|
329
|
+
});
|
|
330
|
+
kind.set(id, "never-rostered-root");
|
|
331
|
+
}
|
|
332
|
+
const hosts = trees.filter((t) => !t.placeholderRoot && t.runtimeId === runtimes[0].id);
|
|
333
|
+
const rootRow = new Map(sessions.map((row) => [row.id, row]));
|
|
334
|
+
for (let k = 0; k < neverRosteredChildren; k += 1) {
|
|
335
|
+
const host = hosts[Math.floor(rnd() * hosts.length)];
|
|
336
|
+
const id = hexId(`unrostered-child:${seed}:${k}`);
|
|
337
|
+
const root = rootRow.get(host.id);
|
|
338
|
+
sessions.push({
|
|
339
|
+
...root, id, native_session_id: uuidOf(id), parent_session_id: host.id, role: "subagent",
|
|
340
|
+
title: null, summary: null, updated_at: host.recency - HOUR, started_at: host.recency - 2 * HOUR,
|
|
341
|
+
});
|
|
342
|
+
kind.set(id, "never-rostered-child");
|
|
343
|
+
adopt(host.id, id);
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
now, scale, seed, runtimes, projects: projectRows, sessions, kind, own, children, trees, treeOf, bytesOf,
|
|
347
|
+
topics: TOPICS,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ArtifactPage, BoostResponse, ContributionResponse, DayUsageResponse, DiscoveriesResponse, EnableResponse, ErrorCode, HeatmapResponse, SearchResponse, StatusResponse, UsageResponse } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { CatalogSearch } from "../ports.js";
|
|
3
|
+
/** A refusal, as the daemon words it (`ApiError`). */
|
|
4
|
+
export declare class ColdWireError extends Error {
|
|
5
|
+
readonly status: number;
|
|
6
|
+
readonly code: ErrorCode;
|
|
7
|
+
constructor(status: number, code: ErrorCode, message: string);
|
|
8
|
+
}
|
|
9
|
+
/** What the simulated daemon answers, route by route. */
|
|
10
|
+
export interface ColdWire {
|
|
11
|
+
/** May be held by the controller; rejects with an AbortError on abort. */
|
|
12
|
+
status(signal?: AbortSignal): Promise<StatusResponse>;
|
|
13
|
+
discoveries(): DiscoveriesResponse;
|
|
14
|
+
enableRuntimes(kinds: readonly string[]): EnableResponse;
|
|
15
|
+
heatmap(projectId: string): HeatmapResponse;
|
|
16
|
+
contribution(projectId: string): ContributionResponse;
|
|
17
|
+
usage(projectId: string): UsageResponse;
|
|
18
|
+
dayUsage(projectId: string, day: string): DayUsageResponse;
|
|
19
|
+
search(request: CatalogSearch, signal?: AbortSignal): SearchResponse;
|
|
20
|
+
boost(sessionId: string): BoostResponse;
|
|
21
|
+
artifacts(): ArtifactPage;
|
|
22
|
+
}
|
|
23
|
+
export declare const aborted: () => DOMException;
|
|
24
|
+
/** The routes the SDK asks (clients/ts/client.ts), answered over `wire`. */
|
|
25
|
+
export declare function fetchOver(wire: ColdWire): typeof fetch;
|
|
@@ -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;
|