@llm4ts/flow 3.2.6 → 3.4.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/Bench.d.ts.map +1 -1
- package/dist/Bench.js +3 -7
- package/dist/Bench.js.map +1 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +2 -8
- package/dist/Context.js.map +1 -1
- package/dist/CostTracker.d.ts +1 -1
- package/dist/CostTracker.d.ts.map +1 -1
- package/dist/CostTracker.js +2 -8
- package/dist/CostTracker.js.map +1 -1
- package/dist/EstimatedUsage.d.ts.map +1 -1
- package/dist/EstimatedUsage.js +4 -3
- package/dist/EstimatedUsage.js.map +1 -1
- package/dist/FlowEvents.d.ts +100 -0
- package/dist/FlowEvents.d.ts.map +1 -1
- package/dist/FlowEvents.js +188 -107
- package/dist/FlowEvents.js.map +1 -1
- package/dist/FlowRecorder.d.ts +1 -1
- package/dist/FlowRecorder.d.ts.map +1 -1
- package/dist/FlowRecorder.js +4 -10
- package/dist/FlowRecorder.js.map +1 -1
- package/dist/GateTriage.d.ts +1 -1
- package/dist/GateTriage.d.ts.map +1 -1
- package/dist/GateTriage.js +1 -1
- package/dist/GateTriage.js.map +1 -1
- package/dist/GraphRules.d.ts +3 -1
- package/dist/GraphRules.d.ts.map +1 -1
- package/dist/GraphRules.js +2 -0
- package/dist/GraphRules.js.map +1 -1
- package/dist/JudgmentLog.d.ts.map +1 -1
- package/dist/JudgmentLog.js +5 -8
- package/dist/JudgmentLog.js.map +1 -1
- package/dist/NodePreflight.d.ts.map +1 -1
- package/dist/NodePreflight.js +2 -2
- package/dist/NodePreflight.js.map +1 -1
- package/dist/OracleGuard.d.ts +1 -1
- package/dist/OracleGuard.d.ts.map +1 -1
- package/dist/OracleGuard.js +1 -1
- package/dist/OracleGuard.js.map +1 -1
- package/dist/Orientation.d.ts.map +1 -1
- package/dist/Orientation.js +3 -5
- package/dist/Orientation.js.map +1 -1
- package/dist/Retro.d.ts.map +1 -1
- package/dist/Retro.js +2 -3
- package/dist/Retro.js.map +1 -1
- package/dist/Settings.d.ts +105 -0
- package/dist/Settings.d.ts.map +1 -0
- package/dist/Settings.js +198 -0
- package/dist/Settings.js.map +1 -0
- package/dist/Spans.d.ts.map +1 -1
- package/dist/Spans.js +2 -4
- package/dist/Spans.js.map +1 -1
- package/dist/Survey.d.ts +2 -4
- package/dist/Survey.d.ts.map +1 -1
- package/dist/Survey.js +2 -2
- package/dist/Survey.js.map +1 -1
- package/dist/TestEvidence.d.ts.map +1 -1
- package/dist/TestEvidence.js +4 -3
- package/dist/TestEvidence.js.map +1 -1
- package/dist/Workspace.d.ts.map +1 -1
- package/dist/Workspace.js +5 -22
- package/dist/Workspace.js.map +1 -1
- package/dist/settings/Registry.d.ts +625 -0
- package/dist/settings/Registry.d.ts.map +1 -0
- package/dist/settings/Registry.js +742 -0
- package/dist/settings/Registry.js.map +1 -0
- package/dist/settings/Value.d.ts +56 -0
- package/dist/settings/Value.d.ts.map +1 -0
- package/dist/settings/Value.js +107 -0
- package/dist/settings/Value.js.map +1 -0
- package/package.json +3 -2
- package/src/Bench.ts +6 -19
- package/src/Context.ts +2 -8
- package/src/CostTracker.ts +3 -15
- package/src/EstimatedUsage.ts +4 -3
- package/src/FlowEvents.ts +383 -117
- package/src/FlowRecorder.ts +7 -16
- package/src/GateTriage.ts +1 -1
- package/src/GraphRules.ts +4 -1
- package/src/JudgmentLog.ts +5 -13
- package/src/NodePreflight.ts +2 -4
- package/src/OracleGuard.ts +1 -1
- package/src/Orientation.ts +3 -5
- package/src/Retro.ts +2 -5
- package/src/Settings.ts +309 -0
- package/src/Spans.ts +2 -4
- package/src/Survey.ts +2 -2
- package/src/TestEvidence.ts +4 -3
- package/src/Workspace.ts +7 -24
- package/src/settings/Registry.ts +802 -0
- package/src/settings/Value.ts +250 -0
package/src/JudgmentLog.ts
CHANGED
|
@@ -5,8 +5,7 @@ import * as Ref from "effect/Ref"
|
|
|
5
5
|
import * as Schema from "effect/Schema"
|
|
6
6
|
import * as Semaphore from "effect/Semaphore"
|
|
7
7
|
import type * as Scope from "effect/Scope"
|
|
8
|
-
import
|
|
9
|
-
import { awaitConsumed, JudgmentObserved, type FlowEvent, type FlowEventHub } from "./FlowEvents.ts"
|
|
8
|
+
import { JudgmentObserved, type FlowEvent, type FlowEventHub } from "./FlowEvents.ts"
|
|
10
9
|
import type { PlainFileStoreShape } from "./Persistence.ts"
|
|
11
10
|
|
|
12
11
|
export class JudgmentObservation extends Schema.Class<JudgmentObservation>("JudgmentObservation")({
|
|
@@ -42,7 +41,6 @@ export const makeJudgmentLog = Effect.fn("@llm4ts/flow/JudgmentLog.make")(functi
|
|
|
42
41
|
readonly root: string
|
|
43
42
|
readonly runId: string
|
|
44
43
|
}): Effect.fn.Return<JudgmentLogShape> {
|
|
45
|
-
const consumed = yield* Ref.make(0)
|
|
46
44
|
const degraded = yield* Ref.make(false)
|
|
47
45
|
const lock = yield* Semaphore.make(1)
|
|
48
46
|
const record = (event: FlowEvent): Effect.Effect<void> =>
|
|
@@ -66,23 +64,17 @@ export const makeJudgmentLog = Effect.fn("@llm4ts/flow/JudgmentLog.make")(functi
|
|
|
66
64
|
)
|
|
67
65
|
|
|
68
66
|
const awaitDrained = (hub: FlowEventHub, timeout?: Duration.Input): Effect.Effect<boolean> =>
|
|
69
|
-
|
|
67
|
+
Effect.map(hub.drained(timeout), (report) => report.complete)
|
|
70
68
|
|
|
71
69
|
return {
|
|
72
70
|
record,
|
|
73
71
|
awaitDrained,
|
|
74
72
|
consume: (hub) =>
|
|
75
73
|
Effect.gen(function* () {
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
yield* Stream.fromSubscription(subscription).pipe(
|
|
79
|
-
Stream.runForEach((event) =>
|
|
80
|
-
record(event).pipe(Effect.andThen(Ref.update(consumed, (count) => count + 1)))
|
|
81
|
-
),
|
|
82
|
-
Effect.forkScoped
|
|
83
|
-
)
|
|
74
|
+
// A judgment log may be attached to a run already under way.
|
|
75
|
+
const consumer = yield* hub.consume("judgment log", record, { from: "now" })
|
|
84
76
|
// Registered after the consumer fiber: drain before scope interrupts it.
|
|
85
|
-
yield* Effect.addFinalizer(() =>
|
|
77
|
+
yield* Effect.addFinalizer(() => consumer.caughtUp())
|
|
86
78
|
})
|
|
87
79
|
}
|
|
88
80
|
})
|
package/src/NodePreflight.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { ProcessExecutorShape } from "@llm4ts/core/ProcessExecutor"
|
|
|
18
18
|
import { FlowAborted, type FlowError } from "./FlowError.ts"
|
|
19
19
|
import { Info, type FlowEventsShape } from "./FlowEvents.ts"
|
|
20
20
|
import type { PlainFileStoreShape } from "./Persistence.ts"
|
|
21
|
+
import { settingValue } from "./Settings.ts"
|
|
21
22
|
|
|
22
23
|
/** A Node pin as the application wrote it, and where. */
|
|
23
24
|
export class NodePin extends Schema.Class<NodePin>("NodePin")({
|
|
@@ -226,9 +227,6 @@ export type NodePreflightReport =
|
|
|
226
227
|
}
|
|
227
228
|
| { readonly _tag: "Ok"; readonly node: string; readonly summary: string }
|
|
228
229
|
|
|
229
|
-
const switchedOff = (value: string | undefined): boolean =>
|
|
230
|
-
value !== undefined && ["off", "0", "false", "no"].includes(value.trim().toLowerCase())
|
|
231
|
-
|
|
232
230
|
const describePin = (pin: NodePin): string => `${pin.spec} (${pin.source})`
|
|
233
231
|
|
|
234
232
|
/**
|
|
@@ -242,7 +240,7 @@ export const nodePreflightReport = Effect.fn("@llm4ts/flow/NodePreflight.report"
|
|
|
242
240
|
appDir: string,
|
|
243
241
|
environment: Readonly<Record<string, string | undefined>>
|
|
244
242
|
): Effect.fn.Return<NodePreflightReport> {
|
|
245
|
-
if (
|
|
243
|
+
if (!settingValue("LLM4TS_NODE_CHECK", environment)) {
|
|
246
244
|
return { _tag: "Off", summary: "node: check off (LLM4TS_NODE_CHECK)" }
|
|
247
245
|
}
|
|
248
246
|
const pins = yield* nodePinsOf(files, appDir)
|
package/src/OracleGuard.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// its plan entry says it may. Deterministic, from the diff and the gate
|
|
4
4
|
// output; a violation is a gate failure the fix round can undo.
|
|
5
5
|
import * as Schema from "effect/Schema"
|
|
6
|
-
import { ReviewIssue } from "./
|
|
6
|
+
import { ReviewIssue } from "./ReviewModel.ts"
|
|
7
7
|
|
|
8
8
|
export class OracleRules extends Schema.Class<OracleRules>("OracleRules")({
|
|
9
9
|
/** Regex source: a path matching it is a test file. */
|
package/src/Orientation.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// call, computed once per epic, so every story stops rediscovering the
|
|
5
5
|
// layout with `ls`, `find` and `grep` round trips.
|
|
6
6
|
import { cap } from "./Context.ts"
|
|
7
|
+
import { settingGiven } from "./Settings.ts"
|
|
7
8
|
|
|
8
9
|
export interface OrientationInput {
|
|
9
10
|
/** Tracked files, repo-relative, as `git ls-files` prints them. */
|
|
@@ -184,9 +185,6 @@ export const orientationOf = (input: OrientationInput): string | undefined => {
|
|
|
184
185
|
export const orientationChars = (
|
|
185
186
|
environment: Readonly<Record<string, string | undefined>>
|
|
186
187
|
): { readonly orientationChars?: number } => {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
return raw === undefined || raw.length === 0 || !Number.isInteger(value) || value < 0
|
|
190
|
-
? {}
|
|
191
|
-
: { orientationChars: value }
|
|
188
|
+
const chars = settingGiven("LLM4TS_ORIENTATION_CHARS", environment)
|
|
189
|
+
return chars._tag === "Read" ? { orientationChars: chars.value } : {}
|
|
192
190
|
}
|
package/src/Retro.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { ApprovedMarker, DraftApprovalMarker } from "./Approval.ts"
|
|
|
18
18
|
import { Board, BoardVersion } from "./BoardSync.ts"
|
|
19
19
|
import { cap } from "./Context.ts"
|
|
20
20
|
import { PersistenceError, type FlowError, type StoryPlanInvalid } from "./FlowError.ts"
|
|
21
|
-
import { FlowEvent, Info, type FlowEventsShape } from "./FlowEvents.ts"
|
|
21
|
+
import { FlowEvent, Info, laneOf, type FlowEventsShape } from "./FlowEvents.ts"
|
|
22
22
|
import type { TraceLine } from "./FlowRecorder.ts"
|
|
23
23
|
import { Plan, Task, parsePlan } from "./Plan.ts"
|
|
24
24
|
import { loadVersioned, makePlanStore, type PlainFileStoreShape } from "./Persistence.ts"
|
|
@@ -186,9 +186,6 @@ const traceView = (lines: ReadonlyArray<TraceLine>): TraceView => {
|
|
|
186
186
|
return { outcome, events }
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
const laneOf = (event: FlowEvent): string | undefined =>
|
|
190
|
-
"lane" in event && typeof event.lane === "string" ? event.lane : undefined
|
|
191
|
-
|
|
192
189
|
const retryLine = /^⟳ (.+?) — retry (\d+)\/(\d+): (.*)$/u
|
|
193
190
|
|
|
194
191
|
const retryKind = (what: string): string =>
|
|
@@ -317,7 +314,7 @@ const storySection = (
|
|
|
317
314
|
)
|
|
318
315
|
}
|
|
319
316
|
|
|
320
|
-
const laneEvents = trace.events.filter((event) => laneOf(event) === story.id)
|
|
317
|
+
const laneEvents = trace.events.filter((event) => laneOf(event)?.lane === story.id)
|
|
321
318
|
const traceLines: Array<string> = []
|
|
322
319
|
const retries: Array<string> = []
|
|
323
320
|
for (const event of laneEvents) {
|
package/src/Settings.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import * as Option from "effect/Option"
|
|
2
|
+
import * as Result from "effect/Result"
|
|
3
|
+
import * as Schema from "effect/Schema"
|
|
4
|
+
import {
|
|
5
|
+
settingGroups,
|
|
6
|
+
settings,
|
|
7
|
+
type Fallback,
|
|
8
|
+
type Setting,
|
|
9
|
+
type SettingGroup,
|
|
10
|
+
type SettingScope
|
|
11
|
+
} from "./settings/Registry.ts"
|
|
12
|
+
import * as Value from "./settings/Value.ts"
|
|
13
|
+
|
|
14
|
+
export type { SettingGroup, SettingScope }
|
|
15
|
+
|
|
16
|
+
/** Each group's id and title, in the order docs and `config show --all` print them. */
|
|
17
|
+
export const groupTitles: ReadonlyArray<readonly [SettingGroup, string]> = settingGroups
|
|
18
|
+
export type Environment = Readonly<Record<string, string | undefined>>
|
|
19
|
+
|
|
20
|
+
/** The registry's keys: a misspelled name does not compile. */
|
|
21
|
+
export type SettingName = keyof typeof settings
|
|
22
|
+
|
|
23
|
+
type Values = {
|
|
24
|
+
readonly [N in SettingName]: (typeof settings)[N]["value"] extends Value.SettingValue<infer A>
|
|
25
|
+
? A
|
|
26
|
+
: never
|
|
27
|
+
}
|
|
28
|
+
type Unset = { readonly [N in SettingName]: (typeof settings)[N]["fallback"]["value"] }
|
|
29
|
+
|
|
30
|
+
/** What a setting's grammar decodes to. */
|
|
31
|
+
export type ValueOf<N extends SettingName> = Values[N]
|
|
32
|
+
/** What `settingValue` returns: the value, or `undefined` when unset with no single default. */
|
|
33
|
+
export type Reading<N extends SettingName> = Values[N] | Unset[N]
|
|
34
|
+
|
|
35
|
+
// The registry seen through its own key: indexing by a generic name keeps the
|
|
36
|
+
// value type and the fallback type of that one setting together.
|
|
37
|
+
const entries: {
|
|
38
|
+
readonly [N in SettingName]: Setting<
|
|
39
|
+
Values[N],
|
|
40
|
+
Fallback<Values[N]> & { readonly value: Unset[N] }
|
|
41
|
+
>
|
|
42
|
+
} = settings
|
|
43
|
+
|
|
44
|
+
/** What the shell, the docs and `config show` read about a setting; never its schema. */
|
|
45
|
+
export interface SettingFacts {
|
|
46
|
+
readonly name: SettingName
|
|
47
|
+
readonly group: SettingGroup
|
|
48
|
+
readonly scope: SettingScope
|
|
49
|
+
/** "on or off", "a positive integer": what docs and errors print. */
|
|
50
|
+
readonly grammar: string
|
|
51
|
+
/** The grammar is the shared on/off one. */
|
|
52
|
+
readonly toggle: boolean
|
|
53
|
+
/** Every value the grammar reads, as it is written; empty when the grammar is open. */
|
|
54
|
+
readonly choices: ReadonlyArray<string>
|
|
55
|
+
/** A filesystem path, made absolute when it comes from a file. */
|
|
56
|
+
readonly path: boolean
|
|
57
|
+
/** llm4ts runs the value as a command. */
|
|
58
|
+
readonly runs: boolean
|
|
59
|
+
/** An empty value means something, so it does not count as unset. */
|
|
60
|
+
readonly emptyIsValue: boolean
|
|
61
|
+
readonly fallback: { readonly kind: "default" | "per-flow" | "off"; readonly text: string }
|
|
62
|
+
readonly doc: string
|
|
63
|
+
/** The `llm4ts run` flag that also sets it. */
|
|
64
|
+
readonly flag?: string
|
|
65
|
+
/** Flows that stop without it whatever their arguments. */
|
|
66
|
+
readonly requiredBy: ReadonlyArray<string>
|
|
67
|
+
/** Read by the shell only; never handed to a flow. */
|
|
68
|
+
readonly shellOnly: boolean
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const isSettingName = (name: string): name is SettingName => Object.hasOwn(settings, name)
|
|
72
|
+
|
|
73
|
+
/** Every setting, in registry order: grouped as the docs are. */
|
|
74
|
+
export const settingNames: ReadonlyArray<SettingName> = Object.keys(settings).filter(isSettingName)
|
|
75
|
+
|
|
76
|
+
const fallbackKinds = { Default: "default", PerFlow: "per-flow", Off: "off" } as const
|
|
77
|
+
|
|
78
|
+
export const settingFacts = (name: SettingName): SettingFacts => {
|
|
79
|
+
const entry: Setting<unknown, Fallback<unknown>> = settings[name]
|
|
80
|
+
return {
|
|
81
|
+
name,
|
|
82
|
+
group: entry.group,
|
|
83
|
+
scope: entry.scope,
|
|
84
|
+
grammar: entry.value.grammar,
|
|
85
|
+
toggle: entry.value === Value.toggle,
|
|
86
|
+
choices: entry.value.choices,
|
|
87
|
+
path: entry.value.path,
|
|
88
|
+
runs: entry.value.runs,
|
|
89
|
+
emptyIsValue: entry.value.empty === "value",
|
|
90
|
+
fallback: { kind: fallbackKinds[entry.fallback._tag], text: entry.fallback.text },
|
|
91
|
+
doc: entry.doc,
|
|
92
|
+
...(entry.flag === undefined ? {} : { flag: entry.flag }),
|
|
93
|
+
requiredBy: entry.requiredBy ?? [],
|
|
94
|
+
shellOnly: entry.shellOnly === true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* One raw string read by the setting's grammar. An empty string succeeds with
|
|
100
|
+
* `undefined` (unset) unless the grammar gives empty a meaning. The failure is
|
|
101
|
+
* the grammar phrase; it never carries the raw value, so a secret cannot leak
|
|
102
|
+
* through it.
|
|
103
|
+
*/
|
|
104
|
+
export const readSetting = <N extends SettingName>(
|
|
105
|
+
name: N,
|
|
106
|
+
raw: string
|
|
107
|
+
): Result.Result<ValueOf<N> | undefined, string> => {
|
|
108
|
+
const value = entries[name].value
|
|
109
|
+
if (raw.trim().length === 0 && value.empty === "unset") {
|
|
110
|
+
return Result.succeed(undefined)
|
|
111
|
+
}
|
|
112
|
+
const decoded = Schema.decodeUnknownOption(value.schema)(raw)
|
|
113
|
+
return Option.isSome(decoded) ? Result.succeed(decoded.value) : Result.fail(value.grammar)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** What the environment holds for a setting, before any default. */
|
|
117
|
+
export type Given<N extends SettingName> =
|
|
118
|
+
| { readonly _tag: "Unset" }
|
|
119
|
+
| { readonly _tag: "Read"; readonly value: ValueOf<N> }
|
|
120
|
+
/** `text` is the trimmed value the grammar did not read: to report or refuse, never to parse. */
|
|
121
|
+
| { readonly _tag: "Unreadable"; readonly text: string }
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* `settingValue` without the default, for a reader that keeps its own default
|
|
125
|
+
* or tells an unreadable value from an unset one.
|
|
126
|
+
*/
|
|
127
|
+
export const settingGiven = <N extends SettingName>(
|
|
128
|
+
name: N,
|
|
129
|
+
environment: Environment
|
|
130
|
+
): Given<N> => {
|
|
131
|
+
const raw = environment[name]
|
|
132
|
+
if (raw === undefined) {
|
|
133
|
+
return { _tag: "Unset" }
|
|
134
|
+
}
|
|
135
|
+
const read = readSetting(name, raw)
|
|
136
|
+
if (Result.isFailure(read)) {
|
|
137
|
+
return { _tag: "Unreadable", text: raw.trim() }
|
|
138
|
+
}
|
|
139
|
+
return read.success === undefined ? { _tag: "Unset" } : { _tag: "Read", value: read.success }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The setting's value in `environment`. Unset: the default when the setting
|
|
144
|
+
* has one, else `undefined`. A value the grammar does not read counts as
|
|
145
|
+
* unset, as it did for every reader before the registry.
|
|
146
|
+
*/
|
|
147
|
+
export const settingValue = <N extends SettingName>(
|
|
148
|
+
name: N,
|
|
149
|
+
environment: Environment
|
|
150
|
+
): Reading<N> => {
|
|
151
|
+
const given = settingGiven(name, environment)
|
|
152
|
+
return given._tag === "Read" ? given.value : entries[name].fallback.value
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type Spelled = {
|
|
156
|
+
readonly [N in SettingName]: Values[N] extends string | number ? N : never
|
|
157
|
+
}[SettingName]
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The setting as the text to look up or quote: the value read, else the text
|
|
161
|
+
* the grammar refused, else `undefined`. For a reader that names what it was
|
|
162
|
+
* given in its own refusal.
|
|
163
|
+
*/
|
|
164
|
+
export const settingText = (name: Spelled, environment: Environment): string | undefined => {
|
|
165
|
+
const given = settingGiven(name, environment)
|
|
166
|
+
return given._tag === "Read"
|
|
167
|
+
? String(given.value)
|
|
168
|
+
: given._tag === "Unreadable"
|
|
169
|
+
? given.text
|
|
170
|
+
: undefined
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const belongsIn: Readonly<Record<SettingScope, string>> = {
|
|
174
|
+
global: "global file",
|
|
175
|
+
project: "project file",
|
|
176
|
+
run: "per run",
|
|
177
|
+
secret: "environment only",
|
|
178
|
+
internal: "set by llm4ts"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Outside code spans, a variable name or a `<placeholder>` word becomes a code
|
|
182
|
+
// span: Markdown would otherwise read `<repo>` as an HTML tag.
|
|
183
|
+
const codeWord = /[^\s`]*<[a-z-]+>[^\s`,;:)]*|\b[A-Z][A-Z0-9]*_(?:[A-Z0-9_]*[A-Z0-9]\b|\*)/gu
|
|
184
|
+
|
|
185
|
+
const cell = (text: string): string =>
|
|
186
|
+
text
|
|
187
|
+
.split("`")
|
|
188
|
+
.map((part, index) => (index % 2 === 0 ? part.replace(codeWord, "`$&`") : part))
|
|
189
|
+
.join("`")
|
|
190
|
+
.replaceAll("|", "\\|")
|
|
191
|
+
|
|
192
|
+
const table = (rows: ReadonlyArray<ReadonlyArray<string>>): ReadonlyArray<string> => {
|
|
193
|
+
const widths = (rows[0] ?? []).map((_, column) =>
|
|
194
|
+
Math.max(3, ...rows.map((row) => (row[column] ?? "").length))
|
|
195
|
+
)
|
|
196
|
+
const line = (row: ReadonlyArray<string>): string =>
|
|
197
|
+
`| ${row.map((text, column) => text.padEnd(widths[column] ?? 0)).join(" | ")} |`
|
|
198
|
+
const [head = [], ...body] = rows
|
|
199
|
+
return [
|
|
200
|
+
line(head),
|
|
201
|
+
`| ${widths.map((width) => "-".repeat(width)).join(" | ")} |`,
|
|
202
|
+
...body.map(line)
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The settings reference of `docs/configuration.md`: one table per group, in
|
|
208
|
+
* registry order, already laid out the way Prettier lays out a Markdown
|
|
209
|
+
* table. `scripts/settings-docs.mjs` writes it into the document.
|
|
210
|
+
*/
|
|
211
|
+
export const settingsReference = (): string =>
|
|
212
|
+
groupTitles
|
|
213
|
+
.flatMap(([group, title]) => {
|
|
214
|
+
const rows = settingNames
|
|
215
|
+
.map(settingFacts)
|
|
216
|
+
.filter((facts) => facts.group === group)
|
|
217
|
+
.map((facts) => [
|
|
218
|
+
`\`${facts.name}\``,
|
|
219
|
+
cell(facts.grammar) + (facts.runs ? " (run as a command)" : ""),
|
|
220
|
+
cell(facts.fallback.text),
|
|
221
|
+
belongsIn[facts.scope],
|
|
222
|
+
facts.requiredBy.map((flow) => `\`${flow}\``).join(", "),
|
|
223
|
+
cell(facts.doc) + (facts.flag === undefined ? "" : ` Flag: \`${facts.flag}\`.`)
|
|
224
|
+
])
|
|
225
|
+
// A column no row of the group fills is left out.
|
|
226
|
+
const columns = [
|
|
227
|
+
"Setting",
|
|
228
|
+
"Value",
|
|
229
|
+
"Default",
|
|
230
|
+
"Belongs in",
|
|
231
|
+
"Required by",
|
|
232
|
+
"Meaning"
|
|
233
|
+
].flatMap((heading, column) =>
|
|
234
|
+
rows.some((row) => row[column] !== "") ? [[heading, column] as const] : []
|
|
235
|
+
)
|
|
236
|
+
return rows.length === 0
|
|
237
|
+
? []
|
|
238
|
+
: [
|
|
239
|
+
`### ${title}`,
|
|
240
|
+
"",
|
|
241
|
+
...table([
|
|
242
|
+
columns.map(([heading]) => heading),
|
|
243
|
+
...rows.map((row) => columns.map(([, column]) => row[column] ?? ""))
|
|
244
|
+
]),
|
|
245
|
+
""
|
|
246
|
+
]
|
|
247
|
+
})
|
|
248
|
+
.join("\n")
|
|
249
|
+
.trimEnd()
|
|
250
|
+
|
|
251
|
+
const prefix = "LLM4TS_"
|
|
252
|
+
|
|
253
|
+
/** Damerau-Levenshtein in its optimal-string-alignment form: a swap of two neighbours costs 1. */
|
|
254
|
+
const editDistance = (left: string, right: string): number => {
|
|
255
|
+
let twoBack: ReadonlyArray<number> = []
|
|
256
|
+
let previous: ReadonlyArray<number> = Array.from({ length: right.length + 1 }, (_, j) => j)
|
|
257
|
+
for (let i = 1; i <= left.length; i++) {
|
|
258
|
+
const current = [i]
|
|
259
|
+
for (let j = 1; j <= right.length; j++) {
|
|
260
|
+
const same = left[i - 1] === right[j - 1]
|
|
261
|
+
const swapped = i > 1 && j > 1 && left[i - 1] === right[j - 2] && left[i - 2] === right[j - 1]
|
|
262
|
+
current.push(
|
|
263
|
+
Math.min(
|
|
264
|
+
(previous[j] ?? 0) + 1,
|
|
265
|
+
(current[j - 1] ?? 0) + 1,
|
|
266
|
+
(previous[j - 1] ?? 0) + (same ? 0 : 1),
|
|
267
|
+
swapped ? (twoBack[j - 2] ?? 0) + 1 : Number.POSITIVE_INFINITY
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
twoBack = previous
|
|
272
|
+
previous = current
|
|
273
|
+
}
|
|
274
|
+
return previous[right.length] ?? 0
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const wordsOf = (suffix: string): string => suffix.split("_").sort().join("_")
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* The setting a misspelled `LLM4TS_*` name most likely meant: the one at the
|
|
281
|
+
* smallest edit distance over the part after the prefix, when that is at most
|
|
282
|
+
* 2 or a quarter of the length, else the one made of the same `_`-separated
|
|
283
|
+
* words in another order. `undefined` when nothing is close.
|
|
284
|
+
*/
|
|
285
|
+
export const closestSettingName = (name: string): SettingName | undefined => {
|
|
286
|
+
const given = name.trim().toUpperCase()
|
|
287
|
+
if (!given.startsWith(prefix)) {
|
|
288
|
+
return undefined
|
|
289
|
+
}
|
|
290
|
+
if (isSettingName(given)) {
|
|
291
|
+
return given
|
|
292
|
+
}
|
|
293
|
+
const suffix = given.slice(prefix.length)
|
|
294
|
+
let closest: { readonly name: SettingName; readonly distance: number } | undefined
|
|
295
|
+
for (const candidate of settingNames) {
|
|
296
|
+
const known = candidate.slice(prefix.length)
|
|
297
|
+
const distance = editDistance(suffix, known)
|
|
298
|
+
const limit = Math.max(2, Math.floor(Math.max(suffix.length, known.length) / 4))
|
|
299
|
+
// A distance as long as the shorter name is a different name, not a typo of it.
|
|
300
|
+
const typo = distance <= limit && distance < Math.min(suffix.length, known.length)
|
|
301
|
+
if (typo && (closest === undefined || distance < closest.distance)) {
|
|
302
|
+
closest = { name: candidate, distance }
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return (
|
|
306
|
+
closest?.name ??
|
|
307
|
+
settingNames.find((candidate) => wordsOf(candidate.slice(prefix.length)) === wordsOf(suffix))
|
|
308
|
+
)
|
|
309
|
+
}
|
package/src/Spans.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as Option from "effect/Option"
|
|
|
9
9
|
import type * as Tracer from "effect/Tracer"
|
|
10
10
|
import type { TokenUsage } from "@llm4ts/core/Models"
|
|
11
11
|
import { isEstimatedModel } from "./EstimatedUsage.ts"
|
|
12
|
+
import { settingValue } from "./Settings.ts"
|
|
12
13
|
|
|
13
14
|
export type SpanKind = "CHAIN" | "AGENT" | "LLM" | "TOOL" | "EVALUATOR"
|
|
14
15
|
|
|
@@ -49,10 +50,7 @@ export type OtelContent = "off" | "on" | "full"
|
|
|
49
50
|
/** LLM4TS_OTEL_CONTENT: `on` or `full`; anything else is off. */
|
|
50
51
|
export const otelContent = (
|
|
51
52
|
environment: Readonly<Record<string, string | undefined>>
|
|
52
|
-
): OtelContent =>
|
|
53
|
-
const value = environment.LLM4TS_OTEL_CONTENT?.trim().toLowerCase()
|
|
54
|
-
return value === "on" ? "on" : value === "full" ? "full" : "off"
|
|
55
|
-
}
|
|
53
|
+
): OtelContent => settingValue("LLM4TS_OTEL_CONTENT", environment)
|
|
56
54
|
|
|
57
55
|
export interface SpanOptions {
|
|
58
56
|
readonly kind: SpanKind
|
package/src/Survey.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { PlanParseError } from "./FlowError.ts"
|
|
|
5
5
|
import {
|
|
6
6
|
edgeRuleOfSurvey,
|
|
7
7
|
emptyGraphRules,
|
|
8
|
+
JoinMatch,
|
|
8
9
|
matchUrl,
|
|
9
10
|
matchUrlPath,
|
|
10
11
|
normalizeUrl,
|
|
@@ -29,8 +30,7 @@ export const GraphMechanism = Schema.Literals([
|
|
|
29
30
|
"codegraph"
|
|
30
31
|
])
|
|
31
32
|
export type GraphMechanism = typeof GraphMechanism.Type
|
|
32
|
-
export
|
|
33
|
-
export type JoinMatch = typeof JoinMatch.Type
|
|
33
|
+
export { JoinMatch }
|
|
34
34
|
|
|
35
35
|
export class GraphEvidence extends Schema.Class<GraphEvidence>("GraphEvidence")({
|
|
36
36
|
file: Schema.String,
|
package/src/TestEvidence.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import * as Schema from "effect/Schema"
|
|
7
7
|
import type { OracleRules } from "./OracleGuard.ts"
|
|
8
8
|
import { defaultOracleRules } from "./OracleGuard.ts"
|
|
9
|
+
import { settingValue } from "./Settings.ts"
|
|
9
10
|
|
|
10
11
|
/** The tag tests of a criterion carry in their name: `[story-id#2]` for its second criterion. */
|
|
11
12
|
export const criterionTag = (storyId: string, index: number): string => `[${storyId}#${index}]`
|
|
@@ -106,11 +107,11 @@ export type EvidenceSource =
|
|
|
106
107
|
export const evidenceSourceFromEnvironment = (
|
|
107
108
|
environment: Readonly<Record<string, string | undefined>>
|
|
108
109
|
): EvidenceSource | undefined => {
|
|
109
|
-
const report = environment
|
|
110
|
-
if (report !== undefined
|
|
110
|
+
const report = settingValue("LLM4TS_TEST_REPORT", environment)
|
|
111
|
+
if (report !== undefined) {
|
|
111
112
|
return { _tag: "Report", path: report }
|
|
112
113
|
}
|
|
113
|
-
const command = environment
|
|
114
|
+
const command = settingValue("LLM4TS_TEST_ONE", environment)
|
|
114
115
|
if (command !== undefined && (command.includes("{tag}") || command.includes("{tagRegex}"))) {
|
|
115
116
|
return { _tag: "Command", argv: command.split(/\s+/u) }
|
|
116
117
|
}
|
package/src/Workspace.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as Effect from "effect/Effect"
|
|
|
3
3
|
import * as Ref from "effect/Ref"
|
|
4
4
|
import * as Schema from "effect/Schema"
|
|
5
5
|
import { WorkspaceIoError, WorkspaceLimitError, WorkspacePathError } from "./FlowError.ts"
|
|
6
|
+
import { settingValue } from "./Settings.ts"
|
|
6
7
|
|
|
7
8
|
export type WorkspaceError = WorkspacePathError | WorkspaceLimitError | WorkspaceIoError
|
|
8
9
|
|
|
@@ -63,27 +64,6 @@ export const legacySourceWorkspaceLimits: WorkspaceLimits = Object.freeze({
|
|
|
63
64
|
maxResults: 20_000
|
|
64
65
|
})
|
|
65
66
|
|
|
66
|
-
const positiveInteger = (raw: string | undefined): number | undefined => {
|
|
67
|
-
const text = raw?.trim()
|
|
68
|
-
if (text === undefined || text.length === 0 || !/^\d+$/.test(text)) {
|
|
69
|
-
return undefined
|
|
70
|
-
}
|
|
71
|
-
const parsed = Number.parseInt(text, 10)
|
|
72
|
-
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const directoryList = (raw: string | undefined): ReadonlyArray<string> | undefined => {
|
|
76
|
-
const text = raw?.trim()
|
|
77
|
-
if (text === undefined || text.length === 0) {
|
|
78
|
-
return undefined
|
|
79
|
-
}
|
|
80
|
-
const names = text
|
|
81
|
-
.split(",")
|
|
82
|
-
.map((name) => name.trim())
|
|
83
|
-
.filter((name) => name.length > 0 && !name.includes("/") && !name.includes("\\"))
|
|
84
|
-
return names.length === 0 ? undefined : names
|
|
85
|
-
}
|
|
86
|
-
|
|
87
67
|
/**
|
|
88
68
|
* `defaults` with the caps overridden from the environment when the values
|
|
89
69
|
* are well-formed; anything else leaves that default untouched:
|
|
@@ -101,9 +81,12 @@ export const workspaceLimitsFromEnv = (
|
|
|
101
81
|
environment: Readonly<Record<string, string | undefined>>,
|
|
102
82
|
defaults: WorkspaceLimits = defaultWorkspaceLimits
|
|
103
83
|
): WorkspaceLimits => {
|
|
104
|
-
const maxReadBytes =
|
|
105
|
-
const maxResults =
|
|
106
|
-
const
|
|
84
|
+
const maxReadBytes = settingValue("LLM4TS_MAX_READ_BYTES", environment)
|
|
85
|
+
const maxResults = settingValue("LLM4TS_MAX_DISCOVER_RESULTS", environment)
|
|
86
|
+
const names = (settingValue("LLM4TS_EXCLUDE_DIRS", environment) ?? []).filter(
|
|
87
|
+
(name) => !name.includes("/") && !name.includes("\\")
|
|
88
|
+
)
|
|
89
|
+
const excludeDirs = names.length === 0 ? undefined : names
|
|
107
90
|
if (maxReadBytes === undefined && maxResults === undefined && excludeDirs === undefined) {
|
|
108
91
|
return defaults
|
|
109
92
|
}
|