@llm4ts/flow 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.
Files changed (161) hide show
  1. package/dist/Bench.d.ts.map +1 -1
  2. package/dist/Bench.js +3 -7
  3. package/dist/Bench.js.map +1 -1
  4. package/dist/CapabilityGuard.d.ts.map +1 -1
  5. package/dist/CapabilityGuard.js +1 -0
  6. package/dist/CapabilityGuard.js.map +1 -1
  7. package/dist/CarriedNotes.d.ts.map +1 -1
  8. package/dist/CarriedNotes.js.map +1 -1
  9. package/dist/Context.d.ts.map +1 -1
  10. package/dist/Context.js +2 -8
  11. package/dist/Context.js.map +1 -1
  12. package/dist/CostTracker.d.ts +1 -1
  13. package/dist/CostTracker.d.ts.map +1 -1
  14. package/dist/CostTracker.js +2 -8
  15. package/dist/CostTracker.js.map +1 -1
  16. package/dist/EstimatedUsage.d.ts.map +1 -1
  17. package/dist/EstimatedUsage.js +4 -3
  18. package/dist/EstimatedUsage.js.map +1 -1
  19. package/dist/Evidence.d.ts.map +1 -1
  20. package/dist/Evidence.js +1 -0
  21. package/dist/Evidence.js.map +1 -1
  22. package/dist/Flow.d.ts +0 -1
  23. package/dist/Flow.d.ts.map +1 -1
  24. package/dist/Flow.js +0 -1
  25. package/dist/Flow.js.map +1 -1
  26. package/dist/FlowEvents.d.ts +98 -20
  27. package/dist/FlowEvents.d.ts.map +1 -1
  28. package/dist/FlowEvents.js +185 -131
  29. package/dist/FlowEvents.js.map +1 -1
  30. package/dist/FlowRecorder.d.ts +1 -1
  31. package/dist/FlowRecorder.d.ts.map +1 -1
  32. package/dist/FlowRecorder.js +4 -10
  33. package/dist/FlowRecorder.js.map +1 -1
  34. package/dist/GateTriage.d.ts +1 -1
  35. package/dist/GateTriage.d.ts.map +1 -1
  36. package/dist/GateTriage.js +1 -1
  37. package/dist/GateTriage.js.map +1 -1
  38. package/dist/Gates.d.ts +0 -1
  39. package/dist/Gates.d.ts.map +1 -1
  40. package/dist/Gates.js +1 -2
  41. package/dist/Gates.js.map +1 -1
  42. package/dist/GraphRules.d.ts +3 -1
  43. package/dist/GraphRules.d.ts.map +1 -1
  44. package/dist/GraphRules.js +2 -0
  45. package/dist/GraphRules.js.map +1 -1
  46. package/dist/JudgmentDataset.d.ts.map +1 -1
  47. package/dist/JudgmentDataset.js +1 -0
  48. package/dist/JudgmentDataset.js.map +1 -1
  49. package/dist/JudgmentEval.d.ts.map +1 -1
  50. package/dist/JudgmentEval.js +1 -0
  51. package/dist/JudgmentEval.js.map +1 -1
  52. package/dist/JudgmentLog.d.ts.map +1 -1
  53. package/dist/JudgmentLog.js +7 -13
  54. package/dist/JudgmentLog.js.map +1 -1
  55. package/dist/JudgmentTypes.d.ts.map +1 -1
  56. package/dist/JudgmentTypes.js +1 -0
  57. package/dist/JudgmentTypes.js.map +1 -1
  58. package/dist/NodePreflight.d.ts.map +1 -1
  59. package/dist/NodePreflight.js +2 -2
  60. package/dist/NodePreflight.js.map +1 -1
  61. package/dist/OracleGuard.d.ts +1 -1
  62. package/dist/OracleGuard.d.ts.map +1 -1
  63. package/dist/OracleGuard.js +2 -1
  64. package/dist/OracleGuard.js.map +1 -1
  65. package/dist/Orientation.d.ts.map +1 -1
  66. package/dist/Orientation.js +3 -5
  67. package/dist/Orientation.js.map +1 -1
  68. package/dist/Pack.d.ts +1 -1
  69. package/dist/Pack.d.ts.map +1 -1
  70. package/dist/Pack.js +0 -1
  71. package/dist/Pack.js.map +1 -1
  72. package/dist/ProgramJudge.d.ts +1 -4
  73. package/dist/ProgramJudge.d.ts.map +1 -1
  74. package/dist/ProgramJudge.js +2 -2
  75. package/dist/ProgramJudge.js.map +1 -1
  76. package/dist/Recheck.d.ts.map +1 -1
  77. package/dist/Recheck.js +1 -0
  78. package/dist/Recheck.js.map +1 -1
  79. package/dist/Retro.d.ts.map +1 -1
  80. package/dist/Retro.js +2 -3
  81. package/dist/Retro.js.map +1 -1
  82. package/dist/ReviewModel.d.ts.map +1 -1
  83. package/dist/ReviewModel.js +1 -0
  84. package/dist/ReviewModel.js.map +1 -1
  85. package/dist/Settings.d.ts +40 -1
  86. package/dist/Settings.d.ts.map +1 -1
  87. package/dist/Settings.js +45 -7
  88. package/dist/Settings.js.map +1 -1
  89. package/dist/Spans.d.ts.map +1 -1
  90. package/dist/Spans.js +2 -4
  91. package/dist/Spans.js.map +1 -1
  92. package/dist/Stories.d.ts.map +1 -1
  93. package/dist/Stories.js +2 -1
  94. package/dist/Stories.js.map +1 -1
  95. package/dist/Survey.d.ts +0 -2
  96. package/dist/Survey.d.ts.map +1 -1
  97. package/dist/Survey.js +1 -2
  98. package/dist/Survey.js.map +1 -1
  99. package/dist/Taskforce.d.ts +1 -1
  100. package/dist/Taskforce.d.ts.map +1 -1
  101. package/dist/Taskforce.js +0 -1
  102. package/dist/Taskforce.js.map +1 -1
  103. package/dist/TestEvidence.d.ts.map +1 -1
  104. package/dist/TestEvidence.js +4 -3
  105. package/dist/TestEvidence.js.map +1 -1
  106. package/dist/Workspace.d.ts.map +1 -1
  107. package/dist/Workspace.js +5 -22
  108. package/dist/Workspace.js.map +1 -1
  109. package/dist/settings/Registry.d.ts +5 -5
  110. package/dist/settings/Registry.d.ts.map +1 -1
  111. package/dist/settings/Registry.js +9 -7
  112. package/dist/settings/Registry.js.map +1 -1
  113. package/dist/settings/Value.d.ts +6 -1
  114. package/dist/settings/Value.d.ts.map +1 -1
  115. package/dist/settings/Value.js +9 -3
  116. package/dist/settings/Value.js.map +1 -1
  117. package/package.json +28 -38
  118. package/src/Bench.ts +6 -19
  119. package/src/CapabilityGuard.ts +1 -0
  120. package/src/CarriedNotes.ts +1 -0
  121. package/src/Context.ts +2 -8
  122. package/src/CostTracker.ts +3 -15
  123. package/src/EstimatedUsage.ts +4 -3
  124. package/src/Evidence.ts +1 -0
  125. package/src/Flow.ts +0 -2
  126. package/src/FlowEvents.ts +380 -153
  127. package/src/FlowRecorder.ts +7 -16
  128. package/src/GateTriage.ts +1 -1
  129. package/src/Gates.ts +1 -3
  130. package/src/GraphRules.ts +4 -1
  131. package/src/JudgmentDataset.ts +1 -0
  132. package/src/JudgmentEval.ts +1 -0
  133. package/src/JudgmentLog.ts +7 -18
  134. package/src/JudgmentTypes.ts +1 -0
  135. package/src/NodePreflight.ts +2 -4
  136. package/src/OracleGuard.ts +2 -1
  137. package/src/Orientation.ts +3 -5
  138. package/src/Pack.ts +0 -2
  139. package/src/ProgramJudge.ts +4 -6
  140. package/src/Recheck.ts +1 -0
  141. package/src/Retro.ts +2 -5
  142. package/src/ReviewModel.ts +1 -0
  143. package/src/Settings.ts +66 -8
  144. package/src/Spans.ts +2 -4
  145. package/src/Stories.ts +3 -5
  146. package/src/Survey.ts +1 -2
  147. package/src/Taskforce.ts +0 -2
  148. package/src/TestEvidence.ts +4 -3
  149. package/src/Workspace.ts +7 -24
  150. package/src/settings/Registry.ts +14 -7
  151. package/src/settings/Value.ts +13 -5
  152. package/dist/Classified.d.ts +0 -16
  153. package/dist/Classified.d.ts.map +0 -1
  154. package/dist/Classified.js +0 -52
  155. package/dist/Classified.js.map +0 -1
  156. package/dist/Mermaid.d.ts +0 -7
  157. package/dist/Mermaid.d.ts.map +0 -1
  158. package/dist/Mermaid.js +0 -98
  159. package/dist/Mermaid.js.map +0 -1
  160. package/src/Classified.ts +0 -72
  161. package/src/Mermaid.ts +0 -112
package/src/Gates.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // The target's gates as a module (ADR 0027): run them in a directory with a
2
2
  // timeout and a log per gate, remember what they said on a base, and keep
3
3
  // only what matters when an epic lands. The pure half lives in
4
- // GateTriage.ts and is re-exported here.
4
+ // GateTriage.ts.
5
5
  import { join } from "node:path"
6
6
  import type * as Duration from "effect/Duration"
7
7
  import * as Effect from "effect/Effect"
@@ -12,8 +12,6 @@ import { baselinesPath, normalizeGateOutput } from "./GateTriage.ts"
12
12
  import type { PlainFileStoreShape } from "./Persistence.ts"
13
13
  import { lintCommand, mergeReviewResults, type ReviewResult } from "./Review.ts"
14
14
 
15
- export * from "./GateTriage.ts"
16
-
17
15
  export interface GateLogDir {
18
16
  readonly files: PlainFileStoreShape
19
17
  readonly dir: string
package/src/GraphRules.ts CHANGED
@@ -3,7 +3,6 @@ import * as Schema from "effect/Schema"
3
3
  import { PlanParseError } from "./FlowError.ts"
4
4
  import { fingerprintOf } from "./ReviewCache.ts"
5
5
  import type { CoverageRule } from "./SpecChecks.ts"
6
- import type { JoinMatch } from "./Survey.ts"
7
6
 
8
7
  /**
9
8
  * The pack's graph vocabulary (ADR 0030). A `## Node:` rule names a sub-file
@@ -39,6 +38,10 @@ export class EdgeRule extends Schema.Class<EdgeRule>("EdgeRule")({
39
38
  unknown: Schema.optionalKey(Schema.Literals(["keep", "drop"]))
40
39
  }) {}
41
40
 
41
+ /** How a survey edge's target was reached from what the source names. */
42
+ export const JoinMatch = Schema.Literals(["exact", "prefix", "extension"])
43
+ export type JoinMatch = typeof JoinMatch.Type
44
+
42
45
  /**
43
46
  * `exact`: trimmed string equality. `exact-ci`: the same ignoring case (an EL
44
47
  * `${invoiceBean}` against a class `InvoiceBean`). `url`: servlet-spec
@@ -1,3 +1,4 @@
1
+ // @internal: dataset reader for JudgmentEval and tools/judgment
1
2
  import * as Effect from "effect/Effect"
2
3
  import * as Schema from "effect/Schema"
3
4
  import { State, ScoreQuestion, TruthQuestion, truth } from "@llm4ts/core/judgment/Schemas"
@@ -1,3 +1,4 @@
1
+ // @internal: offline judgment evaluation for tools/judgment
1
2
  import * as Schema from "effect/Schema"
2
3
  import { expectedScore, truth, type Answer } from "@llm4ts/core/judgment/Schemas"
3
4
  import { decide, type Decision } from "./Judgment.ts"
@@ -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 * as Stream from "effect/Stream"
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> =>
@@ -52,11 +50,8 @@ export const makeJudgmentLog = Effect.fn("@llm4ts/flow/JudgmentLog.make")(functi
52
50
  Effect.gen(function* () {
53
51
  if (yield* Ref.get(degraded)) return
54
52
  const at = yield* Clock.currentTimeMillis
55
- // Classified remains sealed until an explicit, audited declassify.
56
- // Text uses its toString; JSON uses its toJSON. Serialize before
57
- // schema traversal so even nested sealed values use that redaction,
58
- // never their private payload. Already declassified plain text has
59
- // no taint metadata; callers must retain the wrapper for secrets.
53
+ // Serialize before schema traversal, so a value's own toJSON
54
+ // decides what is written, never the fields behind it.
60
55
  const observation = yield* Schema.decodeUnknownEffect(codec)(
61
56
  JSON.stringify({ ...event, runId: options.runId, at })
62
57
  )
@@ -66,23 +61,17 @@ export const makeJudgmentLog = Effect.fn("@llm4ts/flow/JudgmentLog.make")(functi
66
61
  )
67
62
 
68
63
  const awaitDrained = (hub: FlowEventHub, timeout?: Duration.Input): Effect.Effect<boolean> =>
69
- awaitConsumed(hub, consumed, timeout)
64
+ Effect.map(hub.drained(timeout), (report) => report.complete)
70
65
 
71
66
  return {
72
67
  record,
73
68
  awaitDrained,
74
69
  consume: (hub) =>
75
70
  Effect.gen(function* () {
76
- yield* Ref.set(consumed, yield* hub.publishedCount)
77
- const subscription = yield* hub.subscribe
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
- )
71
+ // A judgment log may be attached to a run already under way.
72
+ const consumer = yield* hub.consume("judgment log", record, { from: "now" })
84
73
  // Registered after the consumer fiber: drain before scope interrupts it.
85
- yield* Effect.addFinalizer(() => awaitDrained(hub))
74
+ yield* Effect.addFinalizer(() => consumer.caughtUp())
86
75
  })
87
76
  }
88
77
  })
@@ -1,3 +1,4 @@
1
+ // @internal: judgment literals; Judgment re-exports them
1
2
  import * as Schema from "effect/Schema"
2
3
 
3
4
  /**
@@ -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 (switchedOff(environment.LLM4TS_NODE_CHECK)) {
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)
@@ -1,9 +1,10 @@
1
+ // @internal: oracle protection for the review and story loops
1
2
  // The oracle guard (ADR 0027, decision 4): a change may not delete a test
2
3
  // file, add a skip or focus marker, or lower the passed-test count unless
3
4
  // its plan entry says it may. Deterministic, from the diff and the gate
4
5
  // output; a violation is a gate failure the fix round can undo.
5
6
  import * as Schema from "effect/Schema"
6
- import { ReviewIssue } from "./Review.ts"
7
+ import { ReviewIssue } from "./ReviewModel.ts"
7
8
 
8
9
  export class OracleRules extends Schema.Class<OracleRules>("OracleRules")({
9
10
  /** Regex source: a path matching it is a test file. */
@@ -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 raw = environment.LLM4TS_ORIENTATION_CHARS?.trim()
188
- const value = Number(raw ?? "")
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/Pack.ts CHANGED
@@ -10,8 +10,6 @@ import { Reviewer, parseReviewer } from "./Reviewer.ts"
10
10
  import { CoverageRule } from "./SpecChecks.ts"
11
11
  import type { WorkspaceError, WorkspaceShape } from "./Workspace.ts"
12
12
 
13
- export { Reviewer, parseReviewer } from "./Reviewer.ts"
14
-
15
13
  export const ComparisonOrdering = Schema.Literals(["Ordered", "Unordered", "PerKey"])
16
14
  export type ComparisonOrdering = typeof ComparisonOrdering.Type
17
15
 
@@ -1,7 +1,7 @@
1
1
  import { reviewRulesPreamble } from "./Review.ts"
2
2
  import * as Effect from "effect/Effect"
3
- import { Sample, type Dimension, type EvalResult } from "@llm4ts/core/eval/Eval"
4
- import { makeEvaluator, type Evaluator } from "@llm4ts/core/eval/Evaluator"
3
+ import { Sample, type Dimension, type EvalResult, type Evaluator } from "@llm4ts/core/eval/Eval"
4
+ import { makeEvaluator } from "@llm4ts/core/eval/Evaluator"
5
5
  import { judgeWithJudgment } from "@llm4ts/core/eval/Judge"
6
6
  import type { JudgmentShape } from "@llm4ts/core/judgment/Judgment"
7
7
  import { capped, withShrink } from "./Context.ts"
@@ -18,7 +18,7 @@ import type { GitToolShape } from "./GitTool.ts"
18
18
  import type { Pack } from "./Pack.ts"
19
19
  import type { PlainFileStoreShape } from "./Persistence.ts"
20
20
  import { ReviewIssue, ReviewResult, mergeReviewResults } from "./Review.ts"
21
- import { cachedReview } from "./ReviewCache.ts"
21
+ import { cachedReview, fingerprintOf } from "./ReviewCache.ts"
22
22
 
23
23
  // Per-program spec-compliance judging, shared by the implement and review
24
24
  // phases. A whole-branch judge call carries every spec and every diff hunk in
@@ -71,8 +71,6 @@ export interface ProgramJudgeOptions {
71
71
  /** A program's spec text; the caller owns where specs live. */
72
72
  readonly specFor: (program: string) => Effect.Effect<string, FlowError>
73
73
  readonly query: string
74
- /** Content fingerprint for the verdict cache (hashing lives outside flow). */
75
- readonly fingerprint: (...parts: ReadonlyArray<string>) => string
76
74
  }
77
75
 
78
76
  /**
@@ -219,7 +217,7 @@ const judgeSlice = Effect.fn("@llm4ts/flow/ProgramJudge.judgeSlice")(function* (
219
217
  return yield* cachedReview(
220
218
  options.files,
221
219
  join(options.gateDir, `${label}.json`),
222
- options.fingerprint(spec, diff, rubric, ...judgmentKey),
220
+ fingerprintOf([spec, diff, rubric, ...judgmentKey]),
223
221
  events.publish(Info.make({ message: `judging ${label}` })).pipe(
224
222
  Effect.andThen(
225
223
  withShrink(`judge[${label}]`, (cap) =>
package/src/Recheck.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // @internal: incremental re-checks for Review and Stories
1
2
  /**
2
3
  * Incremental re-review (ADR 0044): what each reviewer found last time, which
3
4
  * files a fix touched, and so which reviewers a round asks again — in full,
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) {
@@ -1,3 +1,4 @@
1
+ // @internal: review values; Review re-exports them
1
2
  /**
2
3
  * What a review answers: findings and their result. Kept apart from
3
4
  * `Review.ts` so modules that `Review.ts` imports can build schemas over them
package/src/Settings.ts CHANGED
@@ -113,22 +113,80 @@ export const readSetting = <N extends SettingName>(
113
113
  return Option.isSome(decoded) ? Result.succeed(decoded.value) : Result.fail(value.grammar)
114
114
  }
115
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
+
116
123
  /**
117
- * The setting's value in `environment`. Unset: the default when the setting
118
- * has one, else `undefined`. A value the grammar does not read counts as
119
- * unset, as it did for every reader before the registry.
124
+ * `settingValue` without the default, for a reader that keeps its own default
125
+ * or tells an unreadable value from an unset one.
120
126
  */
121
- export const settingValue = <N extends SettingName>(
127
+ export const settingGiven = <N extends SettingName>(
122
128
  name: N,
123
129
  environment: Environment
124
- ): Reading<N> => {
125
- const unset = entries[name].fallback.value
130
+ ): Given<N> => {
126
131
  const raw = environment[name]
127
132
  if (raw === undefined) {
128
- return unset
133
+ return { _tag: "Unset" }
129
134
  }
130
135
  const read = readSetting(name, raw)
131
- return Result.isSuccess(read) && read.success !== undefined ? read.success : unset
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 here; a launch through the shell or the runner has already refused
146
+ * it (`unreadableEnvironment`).
147
+ */
148
+ export const settingValue = <N extends SettingName>(
149
+ name: N,
150
+ environment: Environment
151
+ ): Reading<N> => {
152
+ const given = settingGiven(name, environment)
153
+ return given._tag === "Read" ? given.value : entries[name].fallback.value
154
+ }
155
+
156
+ /**
157
+ * Why an environment value the grammar does not read stops a run: the name
158
+ * and the grammar, never the value, so a secret cannot leak through it.
159
+ */
160
+ export const unreadableInEnvironment = (name: SettingName): string =>
161
+ `the environment: ${name} must be ${entries[name].value.grammar}; fix or unset it`
162
+
163
+ /**
164
+ * One line per setting `environment` holds a value for that its grammar does
165
+ * not read, in registry order; empty when every value reads. The shell and
166
+ * the runner refuse a launch on any, so `settingValue`'s lenience never
167
+ * decides a run.
168
+ */
169
+ export const unreadableEnvironment = (environment: Environment): ReadonlyArray<string> =>
170
+ settingNames
171
+ .filter((name) => settingGiven(name, environment)._tag === "Unreadable")
172
+ .map(unreadableInEnvironment)
173
+
174
+ type Spelled = {
175
+ readonly [N in SettingName]: Values[N] extends string | number ? N : never
176
+ }[SettingName]
177
+
178
+ /**
179
+ * The setting as the text to look up or quote: the value read, else the text
180
+ * the grammar refused, else `undefined`. For a reader that names what it was
181
+ * given in its own refusal.
182
+ */
183
+ export const settingText = (name: Spelled, environment: Environment): string | undefined => {
184
+ const given = settingGiven(name, environment)
185
+ return given._tag === "Read"
186
+ ? String(given.value)
187
+ : given._tag === "Unreadable"
188
+ ? given.text
189
+ : undefined
132
190
  }
133
191
 
134
192
  const belongsIn: Readonly<Record<SettingScope, string>> = {
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/Stories.ts CHANGED
@@ -21,16 +21,14 @@ import type { LlmError } from "@llm4ts/core/Errors"
21
21
  import { BoardItem, eventedBoard, type BoardSyncShape } from "./BoardSync.ts"
22
22
  import { makeChat } from "./Chat.ts"
23
23
  import { flowReviewer, implementPlanFlow, type TaskOverrides } from "./Flow.ts"
24
+ import { storyGateLogDir, mergeGateLogDir, type GateLogDir } from "./Gates.ts"
24
25
  import {
25
26
  GateBaseline,
26
27
  baselineKey,
27
28
  ensureBaseline as ensureStoredBaseline,
28
29
  failingLinesOf,
29
- storyGateLogDir,
30
- mergeGateLogDir,
31
- writeBaseline,
32
- type GateLogDir
33
- } from "./Gates.ts"
30
+ writeBaseline
31
+ } from "./GateTriage.ts"
34
32
  import type { ContextOptions, FlowContextShape } from "./FlowContext.ts"
35
33
  import {
36
34
  describeFlowError,
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,6 @@ export const GraphMechanism = Schema.Literals([
29
30
  "codegraph"
30
31
  ])
31
32
  export type GraphMechanism = typeof GraphMechanism.Type
32
- export const JoinMatch = Schema.Literals(["exact", "prefix", "extension"])
33
- export type JoinMatch = typeof JoinMatch.Type
34
33
 
35
34
  export class GraphEvidence extends Schema.Class<GraphEvidence>("GraphEvidence")({
36
35
  file: Schema.String,
package/src/Taskforce.ts CHANGED
@@ -12,8 +12,6 @@ import { makeOpenPointsCollector, OpenPoint } from "./Decisions.ts"
12
12
  import { PlanInvalid, ReportInvalid } from "./FlowError.ts"
13
13
  import type { Persona } from "./Roundtable.ts"
14
14
 
15
- export { ToolGrade } from "./Roundtable.ts"
16
-
17
15
  const dash = " — "
18
16
  const headerLine = /^([A-Za-z][A-Za-z ]*):\s*(.*)$/
19
17
  const oneLine = (text: string): string => text.replace(/\s+/g, " ").trim()
@@ -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.LLM4TS_TEST_REPORT?.trim()
110
- if (report !== undefined && report.length > 0) {
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.LLM4TS_TEST_ONE?.trim()
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 = positiveInteger(environment.LLM4TS_MAX_READ_BYTES)
105
- const maxResults = positiveInteger(environment.LLM4TS_MAX_DISCOVER_RESULTS)
106
- const excludeDirs = directoryList(environment.LLM4TS_EXCLUDE_DIRS)
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
  }
@@ -1,4 +1,11 @@
1
+ // @internal: the settings table; Settings is the public face
1
2
  import * as Duration from "effect/Duration"
3
+ import {
4
+ apiProviderNames,
5
+ coderNames,
6
+ offeredApiProviderNames,
7
+ offeredCoderNames
8
+ } from "@llm4ts/core/Models"
2
9
  import * as Value from "./Value.ts"
3
10
 
4
11
  /** @internal */
@@ -78,14 +85,14 @@ export const settings = {
78
85
  LLM4TS_CODER: setting({
79
86
  group: "seats",
80
87
  scope: "global",
81
- value: Value.text,
88
+ value: Value.oneOf(coderNames),
82
89
  fallback: fallback.perFlow("claude; pi in the epic flows"),
83
- doc: "The coding agent that edits files: claude, codex, gemini, pi, agy, grok, cursor or opencode."
90
+ doc: `The coding agent that edits files: ${Value.listed(offeredCoderNames)}.`
84
91
  }),
85
92
  LLM4TS_REASONER: setting({
86
93
  group: "seats",
87
94
  scope: "global",
88
- value: Value.text,
95
+ value: Value.oneOf(coderNames),
89
96
  fallback: fallback.perFlow("claude"),
90
97
  doc: "The agent that plans, reviews and judges in the epic, soap, roundtable and taskforce flows; any coder name."
91
98
  }),
@@ -127,9 +134,9 @@ export const settings = {
127
134
  LLM4TS_PROVIDER: setting({
128
135
  group: "seats",
129
136
  scope: "global",
130
- value: Value.text,
137
+ value: Value.oneOf(apiProviderNames),
131
138
  fallback: fallback.value("mock", "mock"),
132
- doc: "The API provider of provider-driven flows such as hello: mock, openai, anthropic, gemini, lm-studio, ollama or mlx-lm. Any provider but mock needs LLM4TS_MODEL."
139
+ doc: `The API provider of provider-driven flows such as hello: ${Value.listed(offeredApiProviderNames)}. Any provider but mock needs LLM4TS_MODEL.`
133
140
  }),
134
141
  LLM4TS_MODEL: setting({
135
142
  group: "seats",
@@ -141,7 +148,7 @@ export const settings = {
141
148
  LLM4TS_JUDGMENT_PROVIDER: setting({
142
149
  group: "seats",
143
150
  scope: "global",
144
- value: Value.text,
151
+ value: Value.oneOf(apiProviderNames),
145
152
  fallback: fallback.off("the reasoning seat answers typed judgments"),
146
153
  doc: "The API provider of the judgment seat, named the way LLM4TS_PROVIDER is."
147
154
  }),
@@ -276,7 +283,7 @@ export const settings = {
276
283
  scope: "project",
277
284
  value: Value.positive,
278
285
  fallback: fallback.value(4000, "4000"),
279
- doc: "How many characters of a red gate's output the fix prompt carries."
286
+ doc: "How many characters of a red gate's output the fix prompt carries; at least 500 in port-tests."
280
287
  }),
281
288
  LLM4TS_TEST_REPORT: setting({
282
289
  group: "gates",
@@ -1,3 +1,4 @@
1
+ // @internal: setting value grammars; Settings is the public face
1
2
  import * as Duration from "effect/Duration"
2
3
  import * as Effect from "effect/Effect"
3
4
  import * as Schema from "effect/Schema"
@@ -195,12 +196,15 @@ export const commandOrNone: SettingValue<string> = make(
195
196
  { runs: true, empty: "value" }
196
197
  )
197
198
 
198
- /** `cmd; cmd`. */
199
+ /**
200
+ * `cmd; cmd`. A lone `;` is the empty list: the way to say "run none" where
201
+ * an empty value means "not set" and the default commands would run.
202
+ */
199
203
  export const commands: SettingValue<ReadonlyArray<string>> = make(
200
- "command lines separated by ;",
204
+ "command lines separated by ; (a lone ; for none)",
201
205
  Schema.Array(Schema.String),
202
- listOf(";"),
203
- (value) => value.join("; "),
206
+ (text) => listOf(";")(text) ?? (text.includes(";") ? [] : undefined),
207
+ (value) => (value.length === 0 ? ";" : value.join("; ")),
204
208
  { runs: true }
205
209
  )
206
210
 
@@ -232,10 +236,14 @@ export const cliFlags: SettingValue<Readonly<Record<string, string>>> = make(
232
236
  .join(";")
233
237
  )
234
238
 
239
+ /** `a, b or c`. */
240
+ export const listed = (words: ReadonlyArray<string>): string =>
241
+ words.join(", ").replace(/, ([^,]*)$/u, " or $1")
242
+
235
243
  /** One of `choices`, any case; choices are written in lower case. */
236
244
  export const oneOf = <const L extends ReadonlyArray<string>>(choices: L): SettingValue<L[number]> =>
237
245
  make<L[number]>(
238
- choices.join(", ").replace(/, ([^,]*)$/u, " or $1"),
246
+ listed(choices),
239
247
  Schema.Literals(choices),
240
248
  (value) => choices.find((choice) => choice === value.toLowerCase()),
241
249
  (value) => value,
@@ -1,16 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import { type Capability } from "@llm4ts/core/Capability";
3
- import { FlowCapabilityDenied } from "./FlowError.ts";
4
- import { FlowEvents } from "./FlowEvents.ts";
5
- export declare const guarded: <A, E, R>(capability: Capability, operation: string, body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | FlowCapabilityDenied, R | FlowEvents>;
6
- export declare class Classified<A> {
7
- private readonly value;
8
- private constructor();
9
- static of<A>(value: A): Classified<A>;
10
- map<B>(transform: (value: A) => B): Classified<B>;
11
- declassify(label: string): Effect.Effect<A, FlowCapabilityDenied, FlowEvents>;
12
- /** JSON boundaries must use the same sealed representation as text boundaries. */
13
- toJSON(): string;
14
- toString(): string;
15
- }
16
- //# sourceMappingURL=Classified.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Classified.d.ts","sourceRoot":"","sources":["../src/Classified.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAgB,KAAK,UAAU,EAAyB,MAAM,yBAAyB,CAAA;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,UAAU,EAA0C,MAAM,iBAAiB,CAAA;AAiBpF,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAC7B,YAAY,UAAU,EACtB,WAAW,MAAM,EACjB,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC3B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,oBAAoB,EAAE,CAAC,GAAG,UAAU,CAgBxD,CAAA;AAEJ,qBAAa,UAAU,CAAC,CAAC;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK;IAA1C,OAAO;IAEP,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAIrC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAIjD,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,oBAAoB,EAAE,UAAU,CAAC;IAU7E,kFAAkF;IAClF,MAAM,IAAI,MAAM;IAIhB,QAAQ,IAAI,MAAM;CAGnB"}