@llm4ts/shell 4.1.0 → 4.3.0
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/dist/Cli.d.ts +1 -1
- package/dist/Cli.d.ts.map +1 -1
- package/dist/Cli.js +11 -2
- package/dist/Cli.js.map +1 -1
- package/dist/Watch.d.ts +8 -0
- package/dist/Watch.d.ts.map +1 -1
- package/dist/Watch.js +6 -4
- package/dist/Watch.js.map +1 -1
- package/dist/WebFrame.d.ts +283 -0
- package/dist/WebFrame.d.ts.map +1 -0
- package/dist/WebFrame.js +124 -0
- package/dist/WebFrame.js.map +1 -0
- package/dist/WebWatch.d.ts +63 -0
- package/dist/WebWatch.d.ts.map +1 -0
- package/dist/WebWatch.js +226 -0
- package/dist/WebWatch.js.map +1 -0
- package/dist/WebWatchView.d.ts +51 -0
- package/dist/WebWatchView.d.ts.map +1 -0
- package/dist/WebWatchView.js +229 -0
- package/dist/WebWatchView.js.map +1 -0
- package/package.json +5 -4
- package/src/Cli.ts +18 -4
- package/src/Watch.ts +8 -4
- package/src/WebFrame.ts +145 -0
- package/src/WebWatch.ts +398 -0
- package/src/WebWatchView.ts +322 -0
- package/web/app.js +25 -0
- package/web/fonts/Geist-Variable.woff2 +0 -0
- package/web/fonts/GeistMono-Variable.woff2 +0 -0
- package/web/fonts/OFL.txt +92 -0
- package/web/index.html +169 -0
- package/web/style.css +1179 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// @internal: the browser's view of a run for `llm4ts watch --web`; the shell's own
|
|
2
|
+
import type { TraceLine } from "@llm4ts/flow/FlowRecorder"
|
|
3
|
+
import {
|
|
4
|
+
chipsOf,
|
|
5
|
+
heldBy,
|
|
6
|
+
initialView,
|
|
7
|
+
leaseCounts,
|
|
8
|
+
reduceTree,
|
|
9
|
+
selectedLane,
|
|
10
|
+
treeInputsOfTrace,
|
|
11
|
+
type ChipStatus,
|
|
12
|
+
type TreeInput,
|
|
13
|
+
type TreeLogEntry,
|
|
14
|
+
type TreeState
|
|
15
|
+
} from "@llm4ts/runner/AgentTree"
|
|
16
|
+
import { presentationOf } from "@llm4ts/runner/EventPresentation"
|
|
17
|
+
import type {
|
|
18
|
+
WebExecutor,
|
|
19
|
+
WebFrame,
|
|
20
|
+
WebStory,
|
|
21
|
+
WebTimelineItem,
|
|
22
|
+
WebTone,
|
|
23
|
+
WebVerdict
|
|
24
|
+
} from "./WebFrame.ts"
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `llm4ts watch --web` (ADR 0051): what the browser draws, folded from the
|
|
28
|
+
* same `TreeInput`s and `reduceTree` as the terminal tree. Pure: the server
|
|
29
|
+
* folds, this module projects a `TreeState` into a `WebFrame` (WebFrame.ts),
|
|
30
|
+
* and the page only lays it out.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** One trace line the tree reads, with the `seq` the trace gave it. */
|
|
34
|
+
export interface WebStep {
|
|
35
|
+
readonly seq: number
|
|
36
|
+
readonly at: number
|
|
37
|
+
readonly input: TreeInput
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A trace's lines as steps; lines the tree skips (raw output, unknown kinds) are not steps. */
|
|
41
|
+
export const stepsOfTrace = (lines: ReadonlyArray<TraceLine>): ReadonlyArray<WebStep> =>
|
|
42
|
+
lines.flatMap((line) =>
|
|
43
|
+
treeInputsOfTrace([line]).map((input) => ({ seq: line.seq, at: input.at, input }))
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
/** What the tree does not keep about a lane, read from the same events. */
|
|
47
|
+
interface LaneNotes {
|
|
48
|
+
readonly stage: string | undefined
|
|
49
|
+
readonly failStage: string | undefined
|
|
50
|
+
readonly failMessage: string | undefined
|
|
51
|
+
readonly endedAt: number | undefined
|
|
52
|
+
readonly merged: boolean
|
|
53
|
+
readonly model: string | undefined
|
|
54
|
+
readonly prompt: number
|
|
55
|
+
readonly completion: number
|
|
56
|
+
readonly note: string | undefined
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const noNotes: LaneNotes = {
|
|
60
|
+
stage: undefined,
|
|
61
|
+
failStage: undefined,
|
|
62
|
+
failMessage: undefined,
|
|
63
|
+
endedAt: undefined,
|
|
64
|
+
merged: false,
|
|
65
|
+
model: undefined,
|
|
66
|
+
prompt: 0,
|
|
67
|
+
completion: 0,
|
|
68
|
+
note: undefined
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A replay in progress: the tree after `count` steps, and what the page adds to it. */
|
|
72
|
+
export interface WebFold {
|
|
73
|
+
readonly count: number
|
|
74
|
+
readonly seq: number | undefined
|
|
75
|
+
readonly state: TreeState
|
|
76
|
+
readonly timeline: ReadonlyArray<WebTimelineItem>
|
|
77
|
+
readonly verdicts: ReadonlyArray<WebVerdict>
|
|
78
|
+
readonly notes: Readonly<Record<string, LaneNotes>>
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const startFold = (start: TreeState): WebFold => ({
|
|
82
|
+
count: 0,
|
|
83
|
+
seq: undefined,
|
|
84
|
+
state: start,
|
|
85
|
+
timeline: [],
|
|
86
|
+
verdicts: [],
|
|
87
|
+
notes: {}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const toneOfLog = (entry: TreeLogEntry): WebTone => {
|
|
91
|
+
if (/^failed\b| out · /u.test(entry.what)) {
|
|
92
|
+
return "failed"
|
|
93
|
+
}
|
|
94
|
+
switch (entry.source) {
|
|
95
|
+
case "run":
|
|
96
|
+
return "orchestrator"
|
|
97
|
+
case "judge":
|
|
98
|
+
return / cleared /u.test(entry.what) ? "judgment" : "issue"
|
|
99
|
+
case "roster":
|
|
100
|
+
return / leaves /u.test(entry.what) ? "issue" : "running"
|
|
101
|
+
case "lane":
|
|
102
|
+
return /^(done|merged\b)/u.test(entry.what) ? "done" : "issue"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A step's items: the session log's new lines, else the event's digest or activity. */
|
|
107
|
+
const itemsOf = (
|
|
108
|
+
step: WebStep,
|
|
109
|
+
before: TreeState,
|
|
110
|
+
after: TreeState
|
|
111
|
+
): ReadonlyArray<WebTimelineItem> => {
|
|
112
|
+
const logged = after.log.slice(before.log.length)
|
|
113
|
+
if (logged.length > 0) {
|
|
114
|
+
return logged.map((entry) => ({
|
|
115
|
+
seq: step.seq,
|
|
116
|
+
at: entry.at,
|
|
117
|
+
who: entry.who,
|
|
118
|
+
what: entry.what,
|
|
119
|
+
tone: toneOfLog(entry)
|
|
120
|
+
}))
|
|
121
|
+
}
|
|
122
|
+
if (step.input._tag !== "Event") {
|
|
123
|
+
return []
|
|
124
|
+
}
|
|
125
|
+
const event = step.input.event
|
|
126
|
+
const item = (who: string, what: string, tone: WebTone): ReadonlyArray<WebTimelineItem> => [
|
|
127
|
+
{ seq: step.seq, at: step.at, who, what, tone }
|
|
128
|
+
]
|
|
129
|
+
const digest = presentationOf(event).digest?.(event)
|
|
130
|
+
if (digest !== undefined) {
|
|
131
|
+
return item(digest.lane ?? "flow", digest.text, event._tag === "StageFailed" ? "failed" : "log")
|
|
132
|
+
}
|
|
133
|
+
switch (event._tag) {
|
|
134
|
+
case "ToolUse":
|
|
135
|
+
return event.lane === undefined ? [] : item(event.lane, `${event.tool} ${event.args}`, "tool")
|
|
136
|
+
case "ExecutorLeased":
|
|
137
|
+
return item(
|
|
138
|
+
"roster",
|
|
139
|
+
`${event.executor} → ${event.role}${event.label === undefined ? "" : ` · ${event.label}`}`,
|
|
140
|
+
event.role === "judge" ? "judge" : "running"
|
|
141
|
+
)
|
|
142
|
+
case "StageStarted":
|
|
143
|
+
return event.lane !== undefined &&
|
|
144
|
+
event.stage !== `story ${event.lane}` &&
|
|
145
|
+
!event.stage.endsWith(": setup")
|
|
146
|
+
? item(event.lane, event.stage, "running")
|
|
147
|
+
: []
|
|
148
|
+
default:
|
|
149
|
+
return []
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const noteLane = (
|
|
154
|
+
notes: Readonly<Record<string, LaneNotes>>,
|
|
155
|
+
lane: string,
|
|
156
|
+
change: (open: LaneNotes) => Partial<LaneNotes>
|
|
157
|
+
): Readonly<Record<string, LaneNotes>> => {
|
|
158
|
+
const open = notes[lane] ?? noNotes
|
|
159
|
+
return { ...notes, [lane]: { ...open, ...change(open) } }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const notesOf = (fold: WebFold, step: WebStep): Readonly<Record<string, LaneNotes>> => {
|
|
163
|
+
if (step.input._tag !== "Event") {
|
|
164
|
+
return fold.notes
|
|
165
|
+
}
|
|
166
|
+
const event = step.input.event
|
|
167
|
+
switch (event._tag) {
|
|
168
|
+
case "StageStarted":
|
|
169
|
+
return event.lane === undefined || event.stage === `story ${event.lane}`
|
|
170
|
+
? fold.notes
|
|
171
|
+
: noteLane(fold.notes, event.lane, () => ({ stage: event.stage }))
|
|
172
|
+
case "StageCompleted":
|
|
173
|
+
return event.lane !== undefined && event.stage === `story ${event.lane}`
|
|
174
|
+
? noteLane(fold.notes, event.lane, () => ({ endedAt: step.at }))
|
|
175
|
+
: fold.notes
|
|
176
|
+
case "StageFailed":
|
|
177
|
+
if (event.lane === undefined) {
|
|
178
|
+
return fold.notes
|
|
179
|
+
}
|
|
180
|
+
return event.stage === `story ${event.lane}`
|
|
181
|
+
? noteLane(fold.notes, event.lane, (open) => ({
|
|
182
|
+
endedAt: step.at,
|
|
183
|
+
failMessage: open.failMessage ?? event.message
|
|
184
|
+
}))
|
|
185
|
+
: noteLane(fold.notes, event.lane, () => ({
|
|
186
|
+
failStage: event.stage,
|
|
187
|
+
failMessage: event.message
|
|
188
|
+
}))
|
|
189
|
+
case "TokensUsed":
|
|
190
|
+
return event.lane === undefined || event.agent !== "coder"
|
|
191
|
+
? fold.notes
|
|
192
|
+
: noteLane(fold.notes, event.lane, (open) => ({
|
|
193
|
+
model: event.model ?? open.model,
|
|
194
|
+
prompt: open.prompt + event.usage.prompt,
|
|
195
|
+
completion: open.completion + event.usage.completion
|
|
196
|
+
}))
|
|
197
|
+
case "Info":
|
|
198
|
+
if (event.lane === undefined) {
|
|
199
|
+
return fold.notes
|
|
200
|
+
}
|
|
201
|
+
return / merged into /u.test(event.message)
|
|
202
|
+
? noteLane(fold.notes, event.lane, () => ({ merged: true }))
|
|
203
|
+
: noteLane(fold.notes, event.lane, () => ({
|
|
204
|
+
note: event.message.replace(`story ${event.lane}: `, "")
|
|
205
|
+
}))
|
|
206
|
+
default:
|
|
207
|
+
return fold.notes
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** One more step: the tree's own fold, and the page's notes beside it. */
|
|
212
|
+
export const advance = (fold: WebFold, step: WebStep): WebFold => {
|
|
213
|
+
const state = reduceTree(fold.state, step.input)
|
|
214
|
+
const verdict = state.verdict
|
|
215
|
+
return {
|
|
216
|
+
count: fold.count + 1,
|
|
217
|
+
seq: step.seq,
|
|
218
|
+
state,
|
|
219
|
+
timeline: [...fold.timeline, ...itemsOf(step, fold.state, state)],
|
|
220
|
+
verdicts:
|
|
221
|
+
verdict !== undefined && verdict !== fold.state.verdict
|
|
222
|
+
? [...fold.verdicts, { ...verdict, seq: step.seq }]
|
|
223
|
+
: fold.verdicts,
|
|
224
|
+
notes: notesOf(fold, step)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export const foldSteps = (start: TreeState, steps: ReadonlyArray<WebStep>): WebFold =>
|
|
229
|
+
steps.reduce(advance, startFold(start))
|
|
230
|
+
|
|
231
|
+
// ── the frame ───────────────────────────────────────────────────────────────
|
|
232
|
+
|
|
233
|
+
const executorOf = (state: TreeState, name: string): WebExecutor => {
|
|
234
|
+
const out = state.exclusions.find((exclusion) => exclusion.executor === name)
|
|
235
|
+
if (out !== undefined) {
|
|
236
|
+
return { name, state: "out", text: `✗ out: ${out.reason}` }
|
|
237
|
+
}
|
|
238
|
+
const held = heldBy(state, name)
|
|
239
|
+
return held.length > 0
|
|
240
|
+
? { name, state: "busy", text: `◐ busy · ${held.join(", ")}` }
|
|
241
|
+
: { name, state: "idle", text: "○ idle · no lease" }
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** At most this many of the latest timeline items travel with each frame. */
|
|
245
|
+
export const frameTimeline = 40
|
|
246
|
+
|
|
247
|
+
export const frameOf = (
|
|
248
|
+
fold: WebFold,
|
|
249
|
+
options: { readonly steps: number; readonly lastSeq: number | undefined; readonly gapMs?: number }
|
|
250
|
+
): WebFrame => {
|
|
251
|
+
const state = fold.state
|
|
252
|
+
const chips = chipsOf(state)
|
|
253
|
+
const count = (status: ChipStatus): number =>
|
|
254
|
+
chips.filter((chip) => chip.status === status).length
|
|
255
|
+
const running = state.lanes.filter((lane) => lane.status === "running")
|
|
256
|
+
const counts = leaseCounts(state)
|
|
257
|
+
const stories = chips.map((chip): WebStory => {
|
|
258
|
+
const lane = state.lanes.find((candidate) => candidate.id === chip.id)
|
|
259
|
+
const notes = fold.notes[chip.id] ?? noNotes
|
|
260
|
+
return {
|
|
261
|
+
id: chip.id,
|
|
262
|
+
status: chip.status,
|
|
263
|
+
executor: lane?.executor,
|
|
264
|
+
stage: lane?.stages.at(-1) ?? notes.stage,
|
|
265
|
+
startedAt: lane?.startedAt,
|
|
266
|
+
endedAt: lane?.status === "running" ? undefined : notes.endedAt,
|
|
267
|
+
tokens: lane?.tokens ?? 0,
|
|
268
|
+
prompt: notes.prompt,
|
|
269
|
+
completion: notes.completion,
|
|
270
|
+
model: notes.model,
|
|
271
|
+
merged: notes.merged,
|
|
272
|
+
failStage: notes.failStage,
|
|
273
|
+
failMessage: chip.status === "failed" ? notes.failMessage : undefined,
|
|
274
|
+
tools: lane?.tools.slice(-2) ?? [],
|
|
275
|
+
activity:
|
|
276
|
+
lane?.activity === undefined
|
|
277
|
+
? undefined
|
|
278
|
+
: { text: lane.activity.text, since: lane.activity.since },
|
|
279
|
+
note: notes.note,
|
|
280
|
+
tasks: lane?.tasks.length ?? 0
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
const judging = state.leases.some((lease) => lease.role === "judge")
|
|
284
|
+
return {
|
|
285
|
+
count: fold.count,
|
|
286
|
+
steps: options.steps,
|
|
287
|
+
seq: fold.seq,
|
|
288
|
+
lastSeq: options.lastSeq,
|
|
289
|
+
startedAt: state.startedAt,
|
|
290
|
+
now: state.now,
|
|
291
|
+
ended: state.ended,
|
|
292
|
+
title: state.title,
|
|
293
|
+
action: state.action,
|
|
294
|
+
stage: state.stages.at(-1) ?? (running.length > 0 ? "implement stories" : "idle"),
|
|
295
|
+
agents: `agents · ${running.length} running${counts.length === 0 ? "" : ` · ${counts}`}`,
|
|
296
|
+
counts: {
|
|
297
|
+
planned: count("planned"),
|
|
298
|
+
running: count("running"),
|
|
299
|
+
waiting: count("waiting"),
|
|
300
|
+
done: count("done"),
|
|
301
|
+
failed: count("failed"),
|
|
302
|
+
total: chips.length
|
|
303
|
+
},
|
|
304
|
+
tokens: state.tokens,
|
|
305
|
+
costUsd: state.costUsd,
|
|
306
|
+
stories,
|
|
307
|
+
focus: selectedLane(state, initialView)?.id ?? stories[0]?.id,
|
|
308
|
+
judge: {
|
|
309
|
+
executor: state.judge.executor,
|
|
310
|
+
state: judging ? "running" : state.judge.executor === undefined ? "idle" : "waiting",
|
|
311
|
+
reviews: state.judge.reviews,
|
|
312
|
+
verdicts: state.judge.verdicts,
|
|
313
|
+
borrowed: state.judge.borrowed
|
|
314
|
+
},
|
|
315
|
+
verdicts: fold.verdicts,
|
|
316
|
+
merged: stories.filter((story) => story.merged).length,
|
|
317
|
+
roster: state.executors.map((name) => executorOf(state, name)),
|
|
318
|
+
timeline: fold.timeline.slice(-frameTimeline),
|
|
319
|
+
timelineCount: fold.timeline.length,
|
|
320
|
+
gapMs: options.gapMs ?? 0
|
|
321
|
+
}
|
|
322
|
+
}
|