@llm4ts/shell 3.3.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.
- package/README.md +36 -0
- package/dist/Cli.d.ts +4 -4
- package/dist/Cli.d.ts.map +1 -1
- package/dist/Cli.js +5 -4
- package/dist/Cli.js.map +1 -1
- package/dist/CoderChoice.d.ts +2 -4
- package/dist/CoderChoice.d.ts.map +1 -1
- package/dist/CoderChoice.js +8 -12
- package/dist/CoderChoice.js.map +1 -1
- package/dist/Config.d.ts +3 -3
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +8 -6
- package/dist/Config.js.map +1 -1
- package/dist/ConfigEdit.js +4 -4
- package/dist/ConfigEdit.js.map +1 -1
- package/dist/Costs.d.ts +52 -0
- package/dist/Costs.d.ts.map +1 -0
- package/dist/Costs.js +95 -0
- package/dist/Costs.js.map +1 -0
- package/dist/OperatorActTools.d.ts +1 -1
- package/dist/OperatorActTools.d.ts.map +1 -1
- package/dist/OperatorActTools.js +1 -1
- package/dist/OperatorActTools.js.map +1 -1
- package/dist/OperatorConfig.d.ts.map +1 -1
- package/dist/OperatorConfig.js +2 -1
- package/dist/OperatorConfig.js.map +1 -1
- package/dist/OperatorNode.js +2 -2
- package/dist/OperatorNode.js.map +1 -1
- package/dist/OperatorRuns.d.ts +1 -1
- package/dist/OperatorRuns.d.ts.map +1 -1
- package/dist/OperatorRuns.js +1 -1
- package/dist/OperatorRuns.js.map +1 -1
- package/dist/OperatorTools.d.ts +4 -2
- package/dist/OperatorTools.d.ts.map +1 -1
- package/dist/OperatorTools.js +4 -4
- package/dist/OperatorTools.js.map +1 -1
- package/dist/Profile.d.ts +313 -0
- package/dist/Profile.d.ts.map +1 -0
- package/dist/Profile.js +937 -0
- package/dist/Profile.js.map +1 -0
- package/dist/Refine.d.ts.map +1 -1
- package/dist/Refine.js +3 -2
- package/dist/Refine.js.map +1 -1
- package/dist/RunReaders.d.ts +70 -0
- package/dist/RunReaders.d.ts.map +1 -0
- package/dist/RunReaders.js +236 -0
- package/dist/RunReaders.js.map +1 -0
- package/dist/StoryReaders.d.ts +16 -0
- package/dist/StoryReaders.d.ts.map +1 -0
- package/dist/StoryReaders.js +107 -0
- package/dist/StoryReaders.js.map +1 -0
- package/dist/Watch.d.ts +68 -0
- package/dist/Watch.d.ts.map +1 -0
- package/dist/Watch.js +261 -0
- package/dist/Watch.js.map +1 -0
- package/flows/epic-design.js +7 -5
- package/flows/epic-retro.js +3 -2
- package/flows/implement.js +3 -2
- package/flows/issue-pr.js +3 -2
- package/flows/judge-suite.js +2 -2
- package/flows/lib/debt.js +2 -2
- package/flows/lib/epic-design.js +1 -1
- package/flows/lib/epic-retro.js +3 -6
- package/flows/lib/epic-stories.js +53 -118
- package/flows/lib/modernize-extract.js +6 -9
- package/flows/lib/pack-fork.js +8 -10
- package/flows/lib/port.js +8 -10
- package/flows/local.js +3 -2
- package/flows/modernize-bench.js +11 -6
- package/flows/modernize-extract.js +9 -8
- package/flows/modernize-implement.js +5 -8
- package/flows/modernize-pack-check.js +2 -1
- package/flows/modernize-pack-upgrade.js +2 -1
- package/flows/modernize-refine.js +7 -6
- package/flows/modernize-review.js +4 -5
- package/flows/modernize-seed.js +8 -8
- package/flows/modernize-survey.js +5 -8
- package/flows/modernize-verify.js +3 -3
- package/flows/pack-fork.js +5 -4
- package/flows/port-compile.js +4 -3
- package/flows/port-files.js +2 -2
- package/flows/port-guide.js +6 -5
- package/flows/port-ledger.js +3 -3
- package/flows/port-tests.js +5 -4
- package/flows/roundtable.js +2 -2
- package/flows/sdd.js +8 -13
- package/flows/taskforce.js +5 -4
- package/kits/j2ee-nextjs/flows/convert-all.js +8 -7
- package/kits/j2ee-nextjs/flows/convert-feature.js +2 -2
- package/kits/j2ee-nextjs/flows/convert-page.js +2 -2
- package/kits/j2ee-nextjs/flows/lib/convert.js +9 -13
- package/kits/soap-ace/flows/soap-design.js +5 -8
- package/kits/soap-ace/flows/soap-discover.js +4 -3
- package/kits/soap-ace/flows/soap-epic.js +4 -7
- package/kits/soap-ace/flows/soap-explore.js +8 -7
- package/kits/soap-ace/flows/soap-sample.js +10 -10
- package/kits/soap-ace/tools/soap-call.js +3 -2
- package/package.json +4 -24
- package/src/Cli.ts +6 -9
- package/src/CoderChoice.ts +10 -16
- package/src/Config.ts +9 -5
- package/src/ConfigEdit.ts +4 -4
- package/src/Costs.ts +148 -0
- package/src/OperatorActTools.ts +1 -1
- package/src/OperatorConfig.ts +2 -1
- package/src/OperatorNode.ts +2 -2
- package/src/OperatorRuns.ts +1 -1
- package/src/OperatorTools.ts +4 -4
- package/src/Profile.ts +1196 -0
- package/src/Refine.ts +3 -2
- package/src/RunReaders.ts +370 -0
- package/src/StoryReaders.ts +157 -0
- package/src/Watch.ts +451 -0
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
|
+
}
|
package/src/OperatorActTools.ts
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
meaningfulEventsAfter,
|
|
28
28
|
runStatusOf,
|
|
29
29
|
type TraceFold
|
|
30
|
-
} from "
|
|
30
|
+
} from "./RunReaders.ts"
|
|
31
31
|
import { FlowLaunchError } from "./FlowProcess.ts"
|
|
32
32
|
import { resolveRepo, type OperatorDeps } from "./OperatorTools.ts"
|
|
33
33
|
import {
|
package/src/OperatorConfig.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { basename, join, resolve } from "node:path"
|
|
|
3
3
|
import * as Effect from "effect/Effect"
|
|
4
4
|
import * as Option from "effect/Option"
|
|
5
5
|
import * as Schema from "effect/Schema"
|
|
6
|
+
import { settingValue } from "@llm4ts/flow/Settings"
|
|
6
7
|
import { ShellUsageError } from "./ShellErrors.ts"
|
|
7
8
|
|
|
8
9
|
export interface McpFlags {
|
|
@@ -89,7 +90,7 @@ const httpTransport = (
|
|
|
89
90
|
readFile: (path: string) => Effect.Effect<string | undefined>
|
|
90
91
|
): Effect.Effect<OperatorConfig["transport"], ShellUsageError> =>
|
|
91
92
|
Effect.gen(function* () {
|
|
92
|
-
const fromEnvironment = environment
|
|
93
|
+
const fromEnvironment = settingValue("LLM4TS_MCP_TOKEN", environment) ?? ""
|
|
93
94
|
const fromFile =
|
|
94
95
|
fromEnvironment.length === 0 && Option.isSome(flags.tokenFile)
|
|
95
96
|
? ((yield* readFile(resolve(cwd, flags.tokenFile.value)))?.trim() ?? "")
|
package/src/OperatorNode.ts
CHANGED
|
@@ -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 "
|
|
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 "
|
|
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"
|
package/src/OperatorRuns.ts
CHANGED
|
@@ -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 "
|
|
17
|
+
import { TraceUnreadable } from "./RunReaders.ts"
|
|
18
18
|
import type { OperatorConfig } from "./OperatorConfig.ts"
|
|
19
19
|
import type { RunSupervisorShape } from "./RunSupervisor.ts"
|
|
20
20
|
|
package/src/OperatorTools.ts
CHANGED
|
@@ -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 "
|
|
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 "
|
|
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 "
|
|
46
|
-
import { storyDetailOf, storyDiagnosisOf } from "
|
|
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"
|