@llm4ts/flow 4.13.0 → 4.15.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/BoardSync.d.ts.map +1 -1
- package/dist/BoardSync.js +4 -4
- package/dist/BoardSync.js.map +1 -1
- package/dist/Control.d.ts +126 -0
- package/dist/Control.d.ts.map +1 -0
- package/dist/Control.js +152 -0
- package/dist/Control.js.map +1 -0
- package/dist/FlowContext.d.ts +3 -0
- package/dist/FlowContext.d.ts.map +1 -1
- package/dist/FlowContext.js.map +1 -1
- package/dist/FlowError.d.ts +2 -1
- package/dist/FlowError.d.ts.map +1 -1
- package/dist/FlowError.js +3 -2
- package/dist/FlowError.js.map +1 -1
- package/dist/FlowEvents.d.ts +27 -1
- package/dist/FlowEvents.d.ts.map +1 -1
- package/dist/FlowEvents.js +22 -1
- package/dist/FlowEvents.js.map +1 -1
- package/dist/Stories.d.ts +16 -3
- package/dist/Stories.d.ts.map +1 -1
- package/dist/Stories.js +123 -8
- package/dist/Stories.js.map +1 -1
- package/dist/StoryPlan.d.ts +2 -0
- package/dist/StoryPlan.d.ts.map +1 -1
- package/dist/StoryPlan.js +1 -0
- package/dist/StoryPlan.js.map +1 -1
- package/dist/settings/Registry.d.ts +5 -0
- package/dist/settings/Registry.d.ts.map +1 -1
- package/dist/settings/Registry.js +7 -0
- package/dist/settings/Registry.js.map +1 -1
- package/package.json +3 -2
- package/src/BoardSync.ts +7 -5
- package/src/Control.ts +256 -0
- package/src/FlowContext.ts +3 -0
- package/src/FlowError.ts +5 -2
- package/src/FlowEvents.ts +29 -1
- package/src/Stories.ts +162 -11
- package/src/StoryPlan.ts +3 -0
- package/src/settings/Registry.ts +8 -0
package/src/Stories.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import * as Clock from "effect/Clock"
|
|
8
8
|
import * as Effect from "effect/Effect"
|
|
9
9
|
import * as Exit from "effect/Exit"
|
|
10
|
+
import * as Fiber from "effect/Fiber"
|
|
10
11
|
import * as Option from "effect/Option"
|
|
11
12
|
import * as Queue from "effect/Queue"
|
|
12
13
|
import * as Ref from "effect/Ref"
|
|
@@ -49,6 +50,8 @@ import {
|
|
|
49
50
|
withLane,
|
|
50
51
|
type FlowEventsShape
|
|
51
52
|
} from "./FlowEvents.ts"
|
|
53
|
+
import { ControlApplied, ControlRefused } from "./FlowEvents.ts"
|
|
54
|
+
import { decideControl, waitingFor, type ControlInboxShape } from "./Control.ts"
|
|
52
55
|
import { timeEffect, withTimedRole } from "./Timing.ts"
|
|
53
56
|
import { statusPaths, type GitToolShape } from "./GitTool.ts"
|
|
54
57
|
import {
|
|
@@ -206,8 +209,11 @@ export const frozenTestsGate = (
|
|
|
206
209
|
|
|
207
210
|
export const EpicReportVersion = 1
|
|
208
211
|
|
|
209
|
-
/**
|
|
210
|
-
|
|
212
|
+
/**
|
|
213
|
+
* `waiting`: on hold behind a failed or skipped predecessor, runs once that
|
|
214
|
+
* is done. `skipped`: left out of this run by a control command (ADR 0057).
|
|
215
|
+
*/
|
|
216
|
+
export const OutcomeStatus = Schema.Literals(["done", "failed", "waiting", "skipped"])
|
|
211
217
|
export type OutcomeStatus = typeof OutcomeStatus.Type
|
|
212
218
|
|
|
213
219
|
export class StoryOutcome extends Schema.Class<StoryOutcome>("StoryOutcome")({
|
|
@@ -249,7 +255,9 @@ export const renderEpicReport = (report: EpicReport): string => {
|
|
|
249
255
|
"> the CLI seats report no usage. They are not measurements.",
|
|
250
256
|
"",
|
|
251
257
|
`- Epic branch: \`${report.epicBranch}\``,
|
|
252
|
-
`- Stories: ${report.stories.length} (done ${report.count("done")}, failed ${report.count("failed")}, waiting ${report.count("waiting")}
|
|
258
|
+
`- Stories: ${report.stories.length} (done ${report.count("done")}, failed ${report.count("failed")}, waiting ${report.count("waiting")}${
|
|
259
|
+
report.count("skipped") === 0 ? "" : `, skipped ${report.count("skipped")}`
|
|
260
|
+
})`,
|
|
253
261
|
"",
|
|
254
262
|
"| Story | Status | Branch | Est. tokens | Est. cost | Note |",
|
|
255
263
|
"| --- | --- | --- | --- | --- | --- |"
|
|
@@ -896,6 +904,15 @@ export interface StoriesOptions {
|
|
|
896
904
|
* executor stops launching stories instead of failing each in turn.
|
|
897
905
|
*/
|
|
898
906
|
readonly awaitRecovery?: (reason: string) => Effect.Effect<void, FlowError>
|
|
907
|
+
/**
|
|
908
|
+
* The control inbox (ADR 0057): retry and skip commands for this run's
|
|
909
|
+
* stories, polled while it runs. Absent, the run is not steered.
|
|
910
|
+
*/
|
|
911
|
+
readonly control?: ControlInboxShape
|
|
912
|
+
/** How often the inbox is read; default two seconds. */
|
|
913
|
+
readonly controlPollMs?: number
|
|
914
|
+
/** The epic's name in the inbox: its state folder. Default: the plan's epic id. */
|
|
915
|
+
readonly controlEpic?: string
|
|
899
916
|
}
|
|
900
917
|
|
|
901
918
|
/**
|
|
@@ -2703,6 +2720,7 @@ export const implementStoriesFlow = Effect.fn("@llm4ts/flow/Stories.implement")(
|
|
|
2703
2720
|
done: byStatus("done"),
|
|
2704
2721
|
failed: byStatus("failed"),
|
|
2705
2722
|
waiting: byStatus("waiting"),
|
|
2723
|
+
skipped: byStatus("skipped"),
|
|
2706
2724
|
running: yield* Ref.get(running)
|
|
2707
2725
|
}
|
|
2708
2726
|
})
|
|
@@ -2720,11 +2738,12 @@ export const implementStoriesFlow = Effect.fn("@llm4ts/flow/Stories.implement")(
|
|
|
2720
2738
|
dependent === undefined ||
|
|
2721
2739
|
current.done.has(id) ||
|
|
2722
2740
|
current.failed.has(id) ||
|
|
2741
|
+
current.skipped.has(id) ||
|
|
2723
2742
|
current.waiting.has(id)
|
|
2724
2743
|
) {
|
|
2725
2744
|
continue
|
|
2726
2745
|
}
|
|
2727
|
-
const reason =
|
|
2746
|
+
const reason = waitingFor(story.id)
|
|
2728
2747
|
yield* record(StoryOutcome.make({ id, title: dependent.title, status: "waiting", reason }))
|
|
2729
2748
|
yield* board.wait(id, reason)
|
|
2730
2749
|
}
|
|
@@ -2736,10 +2755,126 @@ export const implementStoriesFlow = Effect.fn("@llm4ts/flow/Stories.implement")(
|
|
|
2736
2755
|
let toldLaunch: string | undefined
|
|
2737
2756
|
/** Stories retried once after the serving engine recovered. */
|
|
2738
2757
|
const recovered = new Set<string>()
|
|
2758
|
+
/** The fiber of each running story, so a skip can interrupt it. */
|
|
2759
|
+
const fibers = new Map<string, Fiber.Fiber<void>>()
|
|
2760
|
+
|
|
2761
|
+
// ---- Control inbox (ADR 0057) ---------------------------------------------
|
|
2762
|
+
const control = options.control
|
|
2763
|
+
const controlRunId = context.trace?.runId ?? "run"
|
|
2764
|
+
const controlEpic = options.controlEpic ?? plan.epicId
|
|
2765
|
+
const forget = (ids: ReadonlySet<string>): Effect.Effect<void> =>
|
|
2766
|
+
Ref.update(outcomes, (current) => current.filter((outcome) => !ids.has(outcome.id)))
|
|
2767
|
+
// A command is for the run live when it was written: what a run finds at
|
|
2768
|
+
// its start, or leaves at its end, expires.
|
|
2769
|
+
const expireControl =
|
|
2770
|
+
control === undefined
|
|
2771
|
+
? Effect.void
|
|
2772
|
+
: Effect.gen(function* () {
|
|
2773
|
+
for (const command of yield* control.pending(controlEpic)) {
|
|
2774
|
+
yield* control.receipt(controlEpic, {
|
|
2775
|
+
id: command.id,
|
|
2776
|
+
runId: controlRunId,
|
|
2777
|
+
outcome: "expired"
|
|
2778
|
+
})
|
|
2779
|
+
}
|
|
2780
|
+
})
|
|
2781
|
+
const applyControl =
|
|
2782
|
+
control === undefined
|
|
2783
|
+
? Effect.void
|
|
2784
|
+
: Effect.gen(function* () {
|
|
2785
|
+
for (const command of yield* control.pending(controlEpic)) {
|
|
2786
|
+
const current = yield* progress
|
|
2787
|
+
const known = yield* Ref.get(outcomes)
|
|
2788
|
+
const decision = decideControl(
|
|
2789
|
+
plan,
|
|
2790
|
+
{
|
|
2791
|
+
done: current.done,
|
|
2792
|
+
failed: current.failed,
|
|
2793
|
+
skipped: current.skipped,
|
|
2794
|
+
running: current.running,
|
|
2795
|
+
waiting: new Map(
|
|
2796
|
+
known.flatMap((outcome) =>
|
|
2797
|
+
outcome.status === "waiting"
|
|
2798
|
+
? [[outcome.id, outcome.reason ?? ""] as const]
|
|
2799
|
+
: []
|
|
2800
|
+
)
|
|
2801
|
+
),
|
|
2802
|
+
...(halted === undefined ? {} : { halted })
|
|
2803
|
+
},
|
|
2804
|
+
command.command
|
|
2805
|
+
)
|
|
2806
|
+
const told = {
|
|
2807
|
+
id: command.id,
|
|
2808
|
+
command: command.command._tag,
|
|
2809
|
+
story: command.command.story,
|
|
2810
|
+
by: command.by
|
|
2811
|
+
}
|
|
2812
|
+
let refusal = decision._tag === "Refused" ? decision.reason : undefined
|
|
2813
|
+
if (decision._tag === "Skip" && decision.interrupt) {
|
|
2814
|
+
const fiber = fibers.get(decision.story)
|
|
2815
|
+
if (fiber !== undefined) {
|
|
2816
|
+
yield* Fiber.interrupt(fiber)
|
|
2817
|
+
// It ended on its own first: its result is in the queue.
|
|
2818
|
+
if (Exit.isSuccess(yield* Fiber.await(fiber))) {
|
|
2819
|
+
refusal = `story ${decision.story} finished before it could be skipped`
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
if (refusal !== undefined) {
|
|
2824
|
+
yield* control.receipt(controlEpic, {
|
|
2825
|
+
id: command.id,
|
|
2826
|
+
runId: controlRunId,
|
|
2827
|
+
outcome: "refused",
|
|
2828
|
+
reason: refusal
|
|
2829
|
+
})
|
|
2830
|
+
yield* events.publish(ControlRefused.make({ ...told, reason: refusal }))
|
|
2831
|
+
continue
|
|
2832
|
+
}
|
|
2833
|
+
if (decision._tag === "Retry") {
|
|
2834
|
+
yield* forget(new Set([decision.story, ...decision.release]))
|
|
2835
|
+
}
|
|
2836
|
+
if (decision._tag === "Skip") {
|
|
2837
|
+
const story = plan.story(decision.story)
|
|
2838
|
+
if (story !== undefined) {
|
|
2839
|
+
fibers.delete(story.id)
|
|
2840
|
+
yield* Ref.update(running, (set) => {
|
|
2841
|
+
const next = new Set(set)
|
|
2842
|
+
next.delete(story.id)
|
|
2843
|
+
return next
|
|
2844
|
+
})
|
|
2845
|
+
yield* forget(new Set([story.id]))
|
|
2846
|
+
yield* record(
|
|
2847
|
+
StoryOutcome.make({
|
|
2848
|
+
id: story.id,
|
|
2849
|
+
title: story.title,
|
|
2850
|
+
status: "skipped",
|
|
2851
|
+
reason: decision.reason
|
|
2852
|
+
})
|
|
2853
|
+
)
|
|
2854
|
+
yield* board.skip(story.id, decision.reason)
|
|
2855
|
+
yield* holdDependents(story)
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
yield* control.receipt(controlEpic, {
|
|
2859
|
+
id: command.id,
|
|
2860
|
+
runId: controlRunId,
|
|
2861
|
+
outcome: "applied"
|
|
2862
|
+
})
|
|
2863
|
+
yield* events.publish(
|
|
2864
|
+
ControlApplied.make({
|
|
2865
|
+
...told,
|
|
2866
|
+
...(decision._tag === "Skip" ? { reason: decision.reason } : {})
|
|
2867
|
+
})
|
|
2868
|
+
)
|
|
2869
|
+
}
|
|
2870
|
+
})
|
|
2871
|
+
|
|
2872
|
+
yield* expireControl
|
|
2739
2873
|
|
|
2740
2874
|
yield* Effect.scoped(
|
|
2741
2875
|
Effect.gen(function* () {
|
|
2742
2876
|
while (true) {
|
|
2877
|
+
yield* applyControl
|
|
2743
2878
|
/** The roster's coder capacity when a ready story was left waiting for it. */
|
|
2744
2879
|
let starvedAt: number | undefined
|
|
2745
2880
|
if (halted === undefined) {
|
|
@@ -2761,9 +2896,13 @@ export const implementStoriesFlow = Effect.fn("@llm4ts/flow/Stories.implement")(
|
|
|
2761
2896
|
const launching = ready.slice(0, Math.max(0, slots))
|
|
2762
2897
|
for (const story of launching) {
|
|
2763
2898
|
yield* Ref.update(running, (set) => new Set([...set, story.id]))
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2899
|
+
fibers.set(
|
|
2900
|
+
story.id,
|
|
2901
|
+
yield* Effect.forkScoped(
|
|
2902
|
+
attempt(story).pipe(
|
|
2903
|
+
Effect.flatMap((completion) => Queue.offer(completions, completion)),
|
|
2904
|
+
Effect.asVoid
|
|
2905
|
+
)
|
|
2767
2906
|
)
|
|
2768
2907
|
)
|
|
2769
2908
|
}
|
|
@@ -2810,17 +2949,27 @@ export const implementStoriesFlow = Effect.fn("@llm4ts/flow/Stories.implement")(
|
|
|
2810
2949
|
// grows (an executor back from a cooldown, a health probe, a resume),
|
|
2811
2950
|
// not when the next running story happens to end.
|
|
2812
2951
|
const roster = context.roster
|
|
2813
|
-
const
|
|
2952
|
+
const completed = Effect.map(Queue.take(completions), Option.some)
|
|
2953
|
+
const grown =
|
|
2814
2954
|
starvedAt === undefined || roster === undefined
|
|
2815
|
-
?
|
|
2816
|
-
:
|
|
2817
|
-
|
|
2955
|
+
? completed
|
|
2956
|
+
: Effect.raceFirst(
|
|
2957
|
+
completed,
|
|
2818
2958
|
Effect.as(roster.capacityChanged("coder", starvedAt), Option.none<Completion>())
|
|
2819
2959
|
)
|
|
2960
|
+
// With an inbox, the wait also ends every poll interval, and the top
|
|
2961
|
+
// of the loop reads the commands.
|
|
2962
|
+
const next: Option.Option<Completion> = yield* control === undefined
|
|
2963
|
+
? grown
|
|
2964
|
+
: Effect.raceFirst(
|
|
2965
|
+
grown,
|
|
2966
|
+
Effect.as(Effect.sleep(options.controlPollMs ?? 2000), Option.none<Completion>())
|
|
2967
|
+
)
|
|
2820
2968
|
if (Option.isNone(next)) {
|
|
2821
2969
|
continue
|
|
2822
2970
|
}
|
|
2823
2971
|
const completion = next.value
|
|
2972
|
+
fibers.delete(completion.story.id)
|
|
2824
2973
|
yield* Ref.update(running, (set) => {
|
|
2825
2974
|
const next = new Set(set)
|
|
2826
2975
|
next.delete(completion.story.id)
|
|
@@ -2884,6 +3033,8 @@ export const implementStoriesFlow = Effect.fn("@llm4ts/flow/Stories.implement")(
|
|
|
2884
3033
|
})
|
|
2885
3034
|
)
|
|
2886
3035
|
|
|
3036
|
+
yield* expireControl
|
|
3037
|
+
|
|
2887
3038
|
if (halted !== undefined) {
|
|
2888
3039
|
const stopped = halted
|
|
2889
3040
|
yield* events.publish(
|
package/src/StoryPlan.ts
CHANGED
|
@@ -267,6 +267,8 @@ export interface StoryProgress {
|
|
|
267
267
|
readonly failed: ReadonlySet<string>
|
|
268
268
|
/** On hold behind a failed predecessor. */
|
|
269
269
|
readonly waiting: ReadonlySet<string>
|
|
270
|
+
/** Left out of this run by a control command (ADR 0057). */
|
|
271
|
+
readonly skipped?: ReadonlySet<string>
|
|
270
272
|
readonly running: ReadonlySet<string>
|
|
271
273
|
}
|
|
272
274
|
|
|
@@ -277,6 +279,7 @@ export const readyStories = (plan: StoryPlan, progress: StoryProgress): Readonly
|
|
|
277
279
|
!progress.done.has(story.id) &&
|
|
278
280
|
!progress.failed.has(story.id) &&
|
|
279
281
|
!progress.waiting.has(story.id) &&
|
|
282
|
+
progress.skipped?.has(story.id) !== true &&
|
|
280
283
|
!progress.running.has(story.id) &&
|
|
281
284
|
story.dependsOn.every((dependency) => progress.done.has(dependency))
|
|
282
285
|
)
|
package/src/settings/Registry.ts
CHANGED
|
@@ -792,6 +792,14 @@ export const settings = {
|
|
|
792
792
|
doc: "One writing run per checkout: a second one is refused while the first, or a process it started, is alive. off lets runs write side by side."
|
|
793
793
|
}),
|
|
794
794
|
|
|
795
|
+
LLM4TS_CHILD_ENV_DROP: setting({
|
|
796
|
+
group: "launch",
|
|
797
|
+
scope: "global",
|
|
798
|
+
value: Value.names,
|
|
799
|
+
fallback: fallback.off("children inherit every variable but LLM4TS_*"),
|
|
800
|
+
doc: "Variables withheld from every process a run starts (coding agents, gates, setup commands): names, with * as a wildcard, e.g. TEMPORAL_*,AWS_*. A variable the run sets for a child itself still reaches it."
|
|
801
|
+
}),
|
|
802
|
+
|
|
795
803
|
// ---- operator ---------------------------------------------------------------
|
|
796
804
|
LLM4TS_MCP_TOKEN: setting({
|
|
797
805
|
group: "operator",
|