@llm4ts/shell 3.4.0 → 4.0.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.
Files changed (68) hide show
  1. package/dist/Cli.d.ts +4 -4
  2. package/dist/Cli.d.ts.map +1 -1
  3. package/dist/Cli.js +3 -3
  4. package/dist/Cli.js.map +1 -1
  5. package/dist/Config.d.ts +3 -3
  6. package/dist/Config.d.ts.map +1 -1
  7. package/dist/Config.js +8 -6
  8. package/dist/Config.js.map +1 -1
  9. package/dist/Costs.d.ts +52 -0
  10. package/dist/Costs.d.ts.map +1 -0
  11. package/dist/Costs.js +95 -0
  12. package/dist/Costs.js.map +1 -0
  13. package/dist/OperatorActTools.d.ts +1 -1
  14. package/dist/OperatorActTools.d.ts.map +1 -1
  15. package/dist/OperatorActTools.js +1 -1
  16. package/dist/OperatorActTools.js.map +1 -1
  17. package/dist/OperatorNode.js +2 -2
  18. package/dist/OperatorNode.js.map +1 -1
  19. package/dist/OperatorRuns.d.ts +1 -1
  20. package/dist/OperatorRuns.d.ts.map +1 -1
  21. package/dist/OperatorRuns.js +1 -1
  22. package/dist/OperatorRuns.js.map +1 -1
  23. package/dist/OperatorTools.d.ts +2 -2
  24. package/dist/OperatorTools.d.ts.map +1 -1
  25. package/dist/OperatorTools.js +4 -4
  26. package/dist/OperatorTools.js.map +1 -1
  27. package/dist/Profile.d.ts +313 -0
  28. package/dist/Profile.d.ts.map +1 -0
  29. package/dist/Profile.js +937 -0
  30. package/dist/Profile.js.map +1 -0
  31. package/dist/RunReaders.d.ts +70 -0
  32. package/dist/RunReaders.d.ts.map +1 -0
  33. package/dist/RunReaders.js +236 -0
  34. package/dist/RunReaders.js.map +1 -0
  35. package/dist/StoryReaders.d.ts +16 -0
  36. package/dist/StoryReaders.d.ts.map +1 -0
  37. package/dist/StoryReaders.js +107 -0
  38. package/dist/StoryReaders.js.map +1 -0
  39. package/dist/Watch.d.ts +68 -0
  40. package/dist/Watch.d.ts.map +1 -0
  41. package/dist/Watch.js +261 -0
  42. package/dist/Watch.js.map +1 -0
  43. package/flows/lib/epic-design.js +1 -1
  44. package/flows/lib/epic-stories.js +2 -6
  45. package/flows/lib/modernize-extract.js +3 -3
  46. package/flows/modernize-bench.js +7 -2
  47. package/flows/modernize-extract.js +1 -1
  48. package/flows/modernize-implement.js +2 -3
  49. package/flows/modernize-refine.js +1 -1
  50. package/flows/modernize-review.js +3 -4
  51. package/flows/modernize-survey.js +1 -1
  52. package/flows/modernize-verify.js +1 -1
  53. package/flows/pack-fork.js +1 -1
  54. package/flows/port-guide.js +1 -1
  55. package/flows/port-ledger.js +1 -1
  56. package/kits/j2ee-nextjs/flows/lib/convert.js +2 -3
  57. package/package.json +4 -24
  58. package/src/Cli.ts +3 -8
  59. package/src/Config.ts +9 -5
  60. package/src/Costs.ts +148 -0
  61. package/src/OperatorActTools.ts +1 -1
  62. package/src/OperatorNode.ts +2 -2
  63. package/src/OperatorRuns.ts +1 -1
  64. package/src/OperatorTools.ts +4 -4
  65. package/src/Profile.ts +1196 -0
  66. package/src/RunReaders.ts +370 -0
  67. package/src/StoryReaders.ts +157 -0
  68. package/src/Watch.ts +451 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llm4ts/shell",
3
- "version": "3.4.0",
3
+ "version": "4.0.0",
4
4
  "description": "Interactive shell and CLI for llm4ts: flow discovery, run-a-flow, and view",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,26 +18,6 @@
18
18
  "kits"
19
19
  ],
20
20
  "exports": {
21
- "./Cli": "./dist/Cli.js",
22
- "./CoderChoice": "./dist/CoderChoice.js",
23
- "./Config": "./dist/Config.js",
24
- "./ConfigCommand": "./dist/ConfigCommand.js",
25
- "./ConfigEdit": "./dist/ConfigEdit.js",
26
- "./ConfigTrust": "./dist/ConfigTrust.js",
27
- "./FlowCatalog": "./dist/FlowCatalog.js",
28
- "./FlowLaunch": "./dist/FlowLaunch.js",
29
- "./FlowProcess": "./dist/FlowProcess.js",
30
- "./Menu": "./dist/Menu.js",
31
- "./OperatorActTools": "./dist/OperatorActTools.js",
32
- "./OperatorConfig": "./dist/OperatorConfig.js",
33
- "./OperatorNode": "./dist/OperatorNode.js",
34
- "./OperatorRuns": "./dist/OperatorRuns.js",
35
- "./OperatorServer": "./dist/OperatorServer.js",
36
- "./OperatorTools": "./dist/OperatorTools.js",
37
- "./Refine": "./dist/Refine.js",
38
- "./RunSupervisor": "./dist/RunSupervisor.js",
39
- "./Package": "./dist/Package.js",
40
- "./ShellErrors": "./dist/ShellErrors.js",
41
21
  "./package.json": "./package.json"
42
22
  },
43
23
  "publishConfig": {
@@ -65,9 +45,9 @@
65
45
  "dependencies": {
66
46
  "@effect/platform-node": "4.0.0",
67
47
  "@effect/platform-node-shared": "4.0.0",
68
- "@llm4ts/flow": "3.4.0",
69
- "@llm4ts/runner": "3.4.0",
70
- "@llm4ts/core": "3.4.0"
48
+ "@llm4ts/runner": "4.0.0",
49
+ "@llm4ts/core": "4.0.0",
50
+ "@llm4ts/flow": "4.0.0"
71
51
  },
72
52
  "peerDependencies": {
73
53
  "effect": "4.0.0"
package/src/Cli.ts CHANGED
@@ -10,12 +10,7 @@ import { FileSystem } from "effect/FileSystem"
10
10
  import * as Schema from "effect/Schema"
11
11
  import { Argument, Command, Flag } from "effect/cli"
12
12
  import { makeCliProgram } from "@llm4ts/runner/Cli"
13
- import {
14
- CostsResult,
15
- makeCostsProgram,
16
- renderCostsResult,
17
- type CostsOptions
18
- } from "@llm4ts/runner/Costs"
13
+ import { CostsResult, makeCostsProgram, renderCostsResult, type CostsOptions } from "./Costs.ts"
19
14
  import { makeDoctorProgram } from "@llm4ts/runner/Doctor"
20
15
  import { makeGeminiBridgeProgram, type GeminiBridgeOptions } from "@llm4ts/runner/GeminiBridgeServe"
21
16
  import { nodeProcessExecutor } from "@llm4ts/runner/NodeProcessExecutor"
@@ -33,8 +28,8 @@ import {
33
28
  nodeTraceSources,
34
29
  nodeWatchDependencies,
35
30
  type WatchOptions
36
- } from "@llm4ts/runner/Watch"
37
- import { makeProfileProgram, type ProfileOptions } from "@llm4ts/runner/Profile"
31
+ } from "./Watch.ts"
32
+ import { makeProfileProgram, type ProfileOptions } from "./Profile.ts"
38
33
  import {
39
34
  makeGraphProgram,
40
35
  nodeGraphDependencies,
package/src/Config.ts CHANGED
@@ -16,6 +16,7 @@ import {
16
16
  readSetting,
17
17
  settingFacts,
18
18
  settingNames,
19
+ unreadableInEnvironment,
19
20
  type Environment,
20
21
  type SettingFacts,
21
22
  type SettingName
@@ -259,9 +260,9 @@ export interface ResolveInput {
259
260
  * Pure: flag > environment > project file > global file. Judges each
260
261
  * assignment against the registry and keeps what each winner shadows. An
261
262
  * empty value counts as unset unless the grammar gives empty a meaning. A
262
- * value the grammar does not read is dropped from a flag or a file (an
263
- * error) and kept from the environment (a warning): an export keeps the
264
- * meaning it has today.
263
+ * value the grammar does not read is an error from every layer: dropped from
264
+ * a flag or a file, kept from the environment so `config show` can print
265
+ * where it comes from. A launch refuses on either.
265
266
  */
266
267
  export const resolveConfig = (input: ResolveInput): Resolution => {
267
268
  const known = new Map<string, SettingFacts>(input.facts.map((fact) => [fact.name, fact]))
@@ -324,9 +325,12 @@ export const resolveConfig = (input: ResolveInput): Resolution => {
324
325
  const read = readSetting(fact.name, value)
325
326
  if (Result.isFailure(read)) {
326
327
  problems.push({
327
- severity: source.layer === "environment" ? "warning" : "error",
328
+ severity: "error",
328
329
  kind: "unreadable",
329
- message: `${where}: ${name} must be ${read.failure}`,
330
+ message:
331
+ source.layer === "environment"
332
+ ? unreadableInEnvironment(fact.name)
333
+ : `${where}: ${name} must be ${read.failure}`,
330
334
  name,
331
335
  source
332
336
  })
package/src/Costs.ts ADDED
@@ -0,0 +1,148 @@
1
+ import { existsSync, readdirSync } from "node:fs"
2
+ import { join } from "node:path"
3
+ import type * as DateTime from "effect/DateTime"
4
+ import * as Effect from "effect/Effect"
5
+ import * as Schema from "effect/Schema"
6
+ import { CostLedgerFileName, loadCostLedger, type CostRecord } from "@llm4ts/flow/CostLedger"
7
+ import {
8
+ CostReport,
9
+ buildCostReport,
10
+ reconcileWithLedger,
11
+ renderCostReport,
12
+ usageSamplesFromTrace,
13
+ type UsageSample
14
+ } from "@llm4ts/flow/CostReport"
15
+ import { describeFlowError } from "@llm4ts/flow/FlowError"
16
+ import type { PlainFileStoreShape } from "@llm4ts/flow/Persistence"
17
+ import { readTrace } from "@llm4ts/flow/Replay"
18
+ import { nodePlainFileStore } from "@llm4ts/runner/NodePlainFileStore"
19
+
20
+ /**
21
+ * `llm4ts costs`: the budgeting view over every trace the runner wrote.
22
+ *
23
+ * Traces are the source for timing: a run can span hours and only the trace
24
+ * carries a timestamp per token report, which the hourly buckets need. The
25
+ * cost ledger is the source for each run's total: its line is the run's own
26
+ * summary, and a trace can be short (`CostReport.reconcileWithLedger`). One
27
+ * unreadable trace is reported and skipped rather than failing the whole
28
+ * report — the other runs still answer the question.
29
+ */
30
+
31
+ export const TraceDirectoryName = ".llm4ts"
32
+
33
+ /** `trace-<timestamp>.jsonl` as the runner writes it, or a prefixed variant like `loop-trace-…`. */
34
+ export const isTraceFileName = (name: string): boolean => /(?:^|-)trace-\d+\.jsonl$/u.test(name)
35
+
36
+ export const nodeListTraces = (directory: string): ReadonlyArray<string> =>
37
+ existsSync(directory)
38
+ ? readdirSync(directory)
39
+ .filter(isTraceFileName)
40
+ .sort()
41
+ .map((name) => join(directory, name))
42
+ : []
43
+
44
+ export interface CostsOptions {
45
+ /** Repositories whose `.llm4ts/` traces are read. */
46
+ readonly repos: ReadonlyArray<string>
47
+ /** Drop token reports before this epoch millisecond. */
48
+ readonly since?: number
49
+ readonly timeZone?: DateTime.TimeZone
50
+ readonly runsPerDay?: number
51
+ }
52
+
53
+ export interface CostsDependencies {
54
+ readonly files: PlainFileStoreShape
55
+ /** Absolute trace paths under one `.llm4ts/` directory. */
56
+ readonly listTraces: (directory: string) => ReadonlyArray<string>
57
+ }
58
+
59
+ export const nodeCostsDependencies = (): CostsDependencies => ({
60
+ files: nodePlainFileStore,
61
+ listTraces: nodeListTraces
62
+ })
63
+
64
+ export class SkippedTrace extends Schema.Class<SkippedTrace>("SkippedTrace")({
65
+ path: Schema.String,
66
+ reason: Schema.String
67
+ }) {}
68
+
69
+ export class CostsResult extends Schema.Class<CostsResult>("CostsResult")({
70
+ report: CostReport,
71
+ traces: Schema.Int,
72
+ skipped: Schema.Array(SkippedTrace),
73
+ /** Runs whose trace was short or missing, completed from their cost ledger line. */
74
+ ledgerRuns: Schema.Array(Schema.String).pipe(
75
+ Schema.withConstructorDefault(Effect.succeed<ReadonlyArray<string>>([])),
76
+ Schema.withDecodingDefaultKey(Effect.succeed<ReadonlyArray<string>>([]))
77
+ )
78
+ }) {}
79
+
80
+ export const makeCostsProgram = Effect.fn("@llm4ts/shell/Costs.make")(function* (
81
+ options: CostsOptions,
82
+ dependencies: CostsDependencies = nodeCostsDependencies()
83
+ ): Effect.fn.Return<CostsResult> {
84
+ const paths = options.repos.flatMap((repo) =>
85
+ dependencies.listTraces(join(repo, TraceDirectoryName))
86
+ )
87
+ const skipped: Array<SkippedTrace> = []
88
+ const traced: Array<UsageSample> = []
89
+ for (const path of paths) {
90
+ const lines = yield* readTrace(dependencies.files, path).pipe(
91
+ Effect.catch((error) =>
92
+ Effect.sync(() => {
93
+ skipped.push(SkippedTrace.make({ path, reason: describeFlowError(error) }))
94
+ return []
95
+ })
96
+ )
97
+ )
98
+ traced.push(...usageSamplesFromTrace(lines))
99
+ }
100
+ // An unreadable ledger is no ledger: the traces still answer, uncorrected.
101
+ const records: Array<CostRecord> = []
102
+ for (const repo of options.repos) {
103
+ const path = join(repo, TraceDirectoryName, CostLedgerFileName)
104
+ records.push(
105
+ ...(yield* loadCostLedger(dependencies.files, path).pipe(
106
+ Effect.catch((error) =>
107
+ Effect.sync(() => {
108
+ skipped.push(SkippedTrace.make({ path, reason: describeFlowError(error) }))
109
+ return []
110
+ })
111
+ )
112
+ ))
113
+ )
114
+ }
115
+ const reconciled = reconcileWithLedger(traced, records)
116
+ const samples = reconciled.samples.filter(
117
+ (sample) => options.since === undefined || sample.at >= options.since
118
+ )
119
+ return CostsResult.make({
120
+ report: buildCostReport(samples, {
121
+ ...(options.timeZone === undefined ? {} : { timeZone: options.timeZone }),
122
+ ...(options.runsPerDay === undefined ? {} : { runsPerDay: options.runsPerDay })
123
+ }),
124
+ traces: paths.length,
125
+ skipped,
126
+ ledgerRuns: reconciled.filledRuns
127
+ })
128
+ })
129
+
130
+ export const renderCostsResult = (result: CostsResult): string => {
131
+ const skipped =
132
+ result.skipped.length === 0
133
+ ? []
134
+ : ["", ...result.skipped.map((entry) => `skipped ${entry.path}: ${entry.reason}`)]
135
+ const ledger =
136
+ result.ledgerRuns.length === 0
137
+ ? []
138
+ : [
139
+ `${result.ledgerRuns.length} run${result.ledgerRuns.length === 1 ? "" : "s"} completed from the cost ledger (trace short or missing, remainder at the run's start): ${result.ledgerRuns.join(", ")}`
140
+ ]
141
+ return [
142
+ renderCostReport(result.report),
143
+ "",
144
+ `traces read: ${result.traces - result.skipped.length} of ${result.traces}`,
145
+ ...ledger,
146
+ ...skipped
147
+ ].join("\n")
148
+ }
@@ -27,7 +27,7 @@ import {
27
27
  meaningfulEventsAfter,
28
28
  runStatusOf,
29
29
  type TraceFold
30
- } from "@llm4ts/runner/RunReaders"
30
+ } from "./RunReaders.ts"
31
31
  import { FlowLaunchError } from "./FlowProcess.ts"
32
32
  import { resolveRepo, type OperatorDeps } from "./OperatorTools.ts"
33
33
  import {
@@ -7,13 +7,13 @@ import * as Effect from "effect/Effect"
7
7
  import * as Fiber from "effect/Fiber"
8
8
  import type { ServeError } from "effect/http/HttpServerError"
9
9
  import type { PersistenceError } from "@llm4ts/flow/FlowError"
10
- import { nodeListTraces } from "@llm4ts/runner/Costs"
10
+ import { nodeListTraces } from "./Costs.ts"
11
11
  import { collectDoctorReport } from "@llm4ts/runner/Doctor"
12
12
  import { httpProbe, rosterReport } from "@llm4ts/runner/ExecutorRoster"
13
13
  import { interruptOnSignal, type SignalSource } from "@llm4ts/runner/FlowRunner"
14
14
  import { nodePlainFileStore } from "@llm4ts/runner/NodePlainFileStore"
15
15
  import { nodeTranscriptFiles } from "@llm4ts/runner/Transcripts"
16
- import { nodeListEpics } from "@llm4ts/runner/Watch"
16
+ import { nodeListEpics } from "./Watch.ts"
17
17
  import { discoverFlows, type FlowTierPaths } from "./FlowCatalog.ts"
18
18
  import { nodeFlowProcess, type FlowProcessShape } from "./FlowProcess.ts"
19
19
  import type { OperatorConfig } from "./OperatorConfig.ts"
@@ -14,7 +14,7 @@ import {
14
14
  } from "@llm4ts/flow/OperatorSchemas"
15
15
  import type { PlainFileStoreShape } from "@llm4ts/flow/Persistence"
16
16
  import { readTrace } from "@llm4ts/flow/Replay"
17
- import { TraceUnreadable } from "@llm4ts/runner/RunReaders"
17
+ import { TraceUnreadable } from "./RunReaders.ts"
18
18
  import type { OperatorConfig } from "./OperatorConfig.ts"
19
19
  import type { RunSupervisorShape } from "./RunSupervisor.ts"
20
20
 
@@ -30,10 +30,10 @@ import { readRetroIndex, retroApprovalOf, retroPaths } from "@llm4ts/flow/Retro"
30
30
  import { rolesOf } from "@llm4ts/flow/Roster"
31
31
  import { makeStoryPlanStore } from "@llm4ts/flow/StoryPlan"
32
32
  import { emptyTree, treeInputsOfTrace } from "@llm4ts/runner/AgentTree"
33
- import { CostsResult, makeCostsProgram } from "@llm4ts/runner/Costs"
33
+ import { CostsResult, makeCostsProgram } from "./Costs.ts"
34
34
  import type { DoctorReport } from "@llm4ts/runner/Doctor"
35
35
  import type { RosterReport } from "@llm4ts/runner/ExecutorRoster"
36
- import { ProfileReport, profileOf } from "@llm4ts/runner/Profile"
36
+ import { ProfileReport, profileOf } from "./Profile.ts"
37
37
  import {
38
38
  TraceUnreadable,
39
39
  costsOfRun,
@@ -42,8 +42,8 @@ import {
42
42
  runDiagnosisOf,
43
43
  runStatusOf,
44
44
  type RunSources
45
- } from "@llm4ts/runner/RunReaders"
46
- import { storyDetailOf, storyDiagnosisOf } from "@llm4ts/runner/StoryReaders"
45
+ } from "./RunReaders.ts"
46
+ import { storyDetailOf, storyDiagnosisOf } from "./StoryReaders.ts"
47
47
  import { loadTranscript, tailLinesOf, type TranscriptFiles } from "@llm4ts/runner/Transcripts"
48
48
  import type { DiscoveredFlow } from "./FlowCatalog.ts"
49
49
  import type { OperatorConfig } from "./OperatorConfig.ts"