@llm4ts/shell 4.4.0 → 4.6.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/src/WebFrame.ts CHANGED
@@ -63,6 +63,8 @@ export const WebStory = Schema.Struct({
63
63
  /** Who codes it, `codex#2`, once it has a lane. */
64
64
  clone: Schema.optional(Schema.String),
65
65
  stage: Schema.optional(Schema.String),
66
+ /** Every open stage of its lane, innermost last, for the expanded detail. */
67
+ stages: Schema.Array(Schema.String),
66
68
  startedAt: Schema.optional(Schema.Number),
67
69
  endedAt: Schema.optional(Schema.Number),
68
70
  tokens: Schema.Number,
@@ -72,6 +74,7 @@ export const WebStory = Schema.Struct({
72
74
  merged: Schema.Boolean,
73
75
  failStage: Schema.optional(Schema.String),
74
76
  failMessage: Schema.optional(Schema.String),
77
+ /** Its lane's latest tool calls, oldest first, as many as the tree keeps (20). */
75
78
  tools: Schema.Array(Schema.String),
76
79
  activity: Schema.optional(Schema.Struct({ text: Schema.String, since: Schema.Number })),
77
80
  note: Schema.optional(Schema.String),
@@ -150,6 +153,29 @@ export const WebRun = Schema.Struct({
150
153
  })
151
154
  export type WebRun = typeof WebRun.Type
152
155
 
156
+ /** Whose transcript a tail shows: a story's, or everything an executor served. */
157
+ export const WebTailOf = Schema.Literals(["story", "executor"])
158
+ export type WebTailOf = typeof WebTailOf.Type
159
+
160
+ /** The roles a tail can keep to; none keeps every call. */
161
+ export const WebTailRole = Schema.Literals(["coder", "reviewer", "judge"])
162
+ export type WebTailRole = typeof WebTailRole.Type
163
+
164
+ /**
165
+ * `GET /api/transcript`: the tail's lines as `watch --tail` formats them,
166
+ * or `None` with the terminal's words when the run kept no transcript.
167
+ */
168
+ export const WebTranscript = Schema.Union([
169
+ Schema.TaggedStruct("Lines", {
170
+ target: Schema.String,
171
+ of: WebTailOf,
172
+ role: Schema.optional(WebTailRole),
173
+ lines: Schema.Array(Schema.String)
174
+ }),
175
+ Schema.TaggedStruct("None", { message: Schema.String })
176
+ ])
177
+ export type WebTranscript = typeof WebTranscript.Type
178
+
153
179
  /**
154
180
  * The bodies on the wire: JSON text, an absent value written as `null`. The
155
181
  * server's `schemaJson` responses and its server-sent frames use this
@@ -157,3 +183,4 @@ export type WebRun = typeof WebRun.Type
157
183
  */
158
184
  export const WebFrameJson = Schema.fromJsonString(Schema.toCodecJson(WebFrame))
159
185
  export const WebRunJson = Schema.fromJsonString(Schema.toCodecJson(WebRun))
186
+ export const WebTranscriptJson = Schema.fromJsonString(Schema.toCodecJson(WebTranscript))
package/src/WebWatch.ts CHANGED
@@ -20,16 +20,32 @@ import type { FlowError } from "@llm4ts/flow/FlowError"
20
20
  import { readTrace } from "@llm4ts/flow/Replay"
21
21
  import { reduceTree } from "@llm4ts/runner/AgentTree"
22
22
  import {
23
+ loadTranscript,
24
+ nodeTranscriptFiles,
25
+ tailLinesOf,
26
+ type TailTarget,
27
+ type TranscriptFiles
28
+ } from "@llm4ts/runner/Transcripts"
29
+ import {
30
+ noTranscriptMessage,
23
31
  pollInterval,
24
32
  replayGap,
25
33
  resolveTraceTarget,
26
34
  startingTree,
35
+ transcriptDirOf,
27
36
  type TraceSources,
28
37
  type WatchOptions,
29
38
  type WatchTarget,
30
39
  type WatchTargetMissing
31
40
  } from "./Watch.ts"
32
- import { WebFrame, WebFrameJson, WebRun } from "./WebFrame.ts"
41
+ import {
42
+ WebFrame,
43
+ WebFrameJson,
44
+ WebRun,
45
+ WebTailOf,
46
+ WebTailRole,
47
+ WebTranscript
48
+ } from "./WebFrame.ts"
33
49
  import {
34
50
  advance,
35
51
  foldSteps,
@@ -93,6 +109,8 @@ export interface WebWatchDependencies extends TraceSources {
93
109
  readonly asset: (file: string) => Uint8Array | undefined
94
110
  /** Completes when the reader detaches (Ctrl-C). */
95
111
  readonly detach: Effect.Effect<void>
112
+ /** A run's transcript files (`--transcript`); the disk by default. */
113
+ readonly transcripts?: TranscriptFiles
96
114
  }
97
115
 
98
116
  const defaultSpeed = 10
@@ -103,6 +121,21 @@ const FrameQuery = Schema.Struct({
103
121
  speed: Schema.optional(Schema.FiniteFromString)
104
122
  })
105
123
 
124
+ /**
125
+ * What a tail asks for: a story or an executor of the run, a role, and for a
126
+ * replay the steps on screen, whose last step's time cuts the transcript.
127
+ */
128
+ const TranscriptQuery = Schema.Struct({
129
+ target: Schema.String.check(Schema.isNonEmpty()),
130
+ of: WebTailOf,
131
+ role: Schema.optional(WebTailRole),
132
+ count: Schema.optional(Schema.FiniteFromString)
133
+ })
134
+
135
+ /** The tail's width in characters, as the detail card fits it, and how many of its last lines travel. */
136
+ const tailWidth = 52
137
+ const tailRows = 400
138
+
106
139
  interface Loaded {
107
140
  readonly runId: string | undefined
108
141
  readonly lastSeq: number | undefined
@@ -244,6 +277,10 @@ export const webWatchApp = Effect.fn("@llm4ts/shell/WebWatch.app")(function* (
244
277
  )
245
278
  )
246
279
 
280
+ const transcripts = dependencies.transcripts ?? nodeTranscriptFiles
281
+ const transcriptDir = yield* transcriptDirOf(options.repo, target, dependencies.files)
282
+ const transcriptQuery = HttpServerRequest.schemaSearchParams(TranscriptQuery)
283
+
247
284
  const pages = webAssets.map((asset) =>
248
285
  HttpRouter.route("GET", asset.path, () => {
249
286
  const bytes = dependencies.asset(asset.file)
@@ -317,7 +354,55 @@ export const webWatchApp = Effect.fn("@llm4ts/shell/WebWatch.app")(function* (
317
354
  }).pipe(Effect.catch(failed))
318
355
  )
319
356
 
320
- return Layer.mergeAll(HttpRouter.addAll([...pages, favicon, run, frame, stream]), guard)
357
+ // The target only ever names a story or an executor the fold knows; a
358
+ // story's file name is `transcriptFileOf` of it, which keeps no separator.
359
+ const transcript = HttpRouter.route(
360
+ "GET",
361
+ "/api/transcript",
362
+ Effect.gen(function* () {
363
+ const asked = yield* transcriptQuery
364
+ const loaded = yield* load
365
+ const count =
366
+ replay || asked.count !== undefined
367
+ ? Math.min(loaded.steps.length, Math.max(1, asked.count ?? loaded.steps.length))
368
+ : loaded.steps.length
369
+ const shown = frameOf(foldSteps(start, loaded.steps.slice(0, count)), {
370
+ steps: loaded.steps.length,
371
+ lastSeq: loaded.lastSeq
372
+ })
373
+ const known =
374
+ asked.of === "story"
375
+ ? shown.stories.some((story) => story.id === asked.target)
376
+ : shown.roster.some((executor) => executor.name === asked.target)
377
+ if (!known) {
378
+ return HttpServerResponse.text(`no ${asked.of} of this run is named so`, { status: 404 })
379
+ }
380
+ const tailTarget: TailTarget =
381
+ asked.of === "story" ? { lane: asked.target } : { executor: asked.target }
382
+ const entries =
383
+ transcriptDir === undefined
384
+ ? undefined
385
+ : yield* loadTranscript(transcripts, transcriptDir, tailTarget)
386
+ const until = count < loaded.steps.length ? loaded.steps[count - 1]?.at : undefined
387
+ const lines = tailLinesOf(
388
+ until === undefined ? entries : entries?.filter((entry) => entry.at <= until),
389
+ tailTarget,
390
+ asked.role,
391
+ tailWidth,
392
+ tailRows
393
+ )
394
+ return yield* HttpServerResponse.schemaJson(WebTranscript)(
395
+ lines === undefined
396
+ ? { _tag: "None", message: noTranscriptMessage }
397
+ : { _tag: "Lines", target: asked.target, of: asked.of, role: asked.role, lines }
398
+ )
399
+ }).pipe(Effect.catch(failed))
400
+ )
401
+
402
+ return Layer.mergeAll(
403
+ HttpRouter.addAll([...pages, favicon, run, frame, stream, transcript]),
404
+ guard
405
+ )
321
406
  })
322
407
 
323
408
  /** Serves the page until the reader detaches; prints where to open it. */
@@ -265,6 +265,7 @@ export const frameOf = (
265
265
  executor: lane?.executor,
266
266
  clone: lane === undefined ? undefined : cloneLabel(lane),
267
267
  stage: lane?.stages.at(-1) ?? notes.stage,
268
+ stages: lane?.stages ?? [],
268
269
  startedAt: lane?.startedAt,
269
270
  endedAt: lane?.status === "running" ? undefined : notes.endedAt,
270
271
  tokens: lane?.tokens ?? 0,
@@ -274,7 +275,7 @@ export const frameOf = (
274
275
  merged: notes.merged,
275
276
  failStage: notes.failStage,
276
277
  failMessage: chip.status === "failed" ? notes.failMessage : undefined,
277
- tools: lane?.tools.slice(-2) ?? [],
278
+ tools: lane?.tools ?? [],
278
279
  activity:
279
280
  lane?.activity === undefined
280
281
  ? undefined