@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.
- package/dist/Bench.d.ts.map +1 -1
- package/dist/Bench.js +3 -7
- package/dist/Bench.js.map +1 -1
- package/dist/CapabilityGuard.d.ts.map +1 -1
- package/dist/CapabilityGuard.js +1 -0
- package/dist/CapabilityGuard.js.map +1 -1
- package/dist/CarriedNotes.d.ts.map +1 -1
- package/dist/CarriedNotes.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/Evidence.d.ts.map +1 -1
- package/dist/Evidence.js +1 -0
- package/dist/Evidence.js.map +1 -1
- package/dist/Flow.d.ts +0 -1
- package/dist/Flow.d.ts.map +1 -1
- package/dist/Flow.js +0 -1
- package/dist/Flow.js.map +1 -1
- package/dist/FlowEvents.d.ts +98 -20
- package/dist/FlowEvents.d.ts.map +1 -1
- package/dist/FlowEvents.js +185 -131
- 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/Gates.d.ts +0 -1
- package/dist/Gates.d.ts.map +1 -1
- package/dist/Gates.js +1 -2
- package/dist/Gates.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/JudgmentDataset.d.ts.map +1 -1
- package/dist/JudgmentDataset.js +1 -0
- package/dist/JudgmentDataset.js.map +1 -1
- package/dist/JudgmentEval.d.ts.map +1 -1
- package/dist/JudgmentEval.js +1 -0
- package/dist/JudgmentEval.js.map +1 -1
- package/dist/JudgmentLog.d.ts.map +1 -1
- package/dist/JudgmentLog.js +7 -13
- package/dist/JudgmentLog.js.map +1 -1
- package/dist/JudgmentTypes.d.ts.map +1 -1
- package/dist/JudgmentTypes.js +1 -0
- package/dist/JudgmentTypes.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 +2 -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/Pack.d.ts +1 -1
- package/dist/Pack.d.ts.map +1 -1
- package/dist/Pack.js +0 -1
- package/dist/Pack.js.map +1 -1
- package/dist/ProgramJudge.d.ts +1 -4
- package/dist/ProgramJudge.d.ts.map +1 -1
- package/dist/ProgramJudge.js +2 -2
- package/dist/ProgramJudge.js.map +1 -1
- package/dist/Recheck.d.ts.map +1 -1
- package/dist/Recheck.js +1 -0
- package/dist/Recheck.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/ReviewModel.d.ts.map +1 -1
- package/dist/ReviewModel.js +1 -0
- package/dist/ReviewModel.js.map +1 -1
- package/dist/Settings.d.ts +40 -1
- package/dist/Settings.d.ts.map +1 -1
- package/dist/Settings.js +45 -7
- package/dist/Settings.js.map +1 -1
- package/dist/Spans.d.ts.map +1 -1
- package/dist/Spans.js +2 -4
- package/dist/Spans.js.map +1 -1
- package/dist/Stories.d.ts.map +1 -1
- package/dist/Stories.js +2 -1
- package/dist/Stories.js.map +1 -1
- package/dist/Survey.d.ts +0 -2
- package/dist/Survey.d.ts.map +1 -1
- package/dist/Survey.js +1 -2
- package/dist/Survey.js.map +1 -1
- package/dist/Taskforce.d.ts +1 -1
- package/dist/Taskforce.d.ts.map +1 -1
- package/dist/Taskforce.js +0 -1
- package/dist/Taskforce.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 +5 -5
- package/dist/settings/Registry.d.ts.map +1 -1
- package/dist/settings/Registry.js +9 -7
- package/dist/settings/Registry.js.map +1 -1
- package/dist/settings/Value.d.ts +6 -1
- package/dist/settings/Value.d.ts.map +1 -1
- package/dist/settings/Value.js +9 -3
- package/dist/settings/Value.js.map +1 -1
- package/package.json +28 -38
- package/src/Bench.ts +6 -19
- package/src/CapabilityGuard.ts +1 -0
- package/src/CarriedNotes.ts +1 -0
- package/src/Context.ts +2 -8
- package/src/CostTracker.ts +3 -15
- package/src/EstimatedUsage.ts +4 -3
- package/src/Evidence.ts +1 -0
- package/src/Flow.ts +0 -2
- package/src/FlowEvents.ts +380 -153
- package/src/FlowRecorder.ts +7 -16
- package/src/GateTriage.ts +1 -1
- package/src/Gates.ts +1 -3
- package/src/GraphRules.ts +4 -1
- package/src/JudgmentDataset.ts +1 -0
- package/src/JudgmentEval.ts +1 -0
- package/src/JudgmentLog.ts +7 -18
- package/src/JudgmentTypes.ts +1 -0
- package/src/NodePreflight.ts +2 -4
- package/src/OracleGuard.ts +2 -1
- package/src/Orientation.ts +3 -5
- package/src/Pack.ts +0 -2
- package/src/ProgramJudge.ts +4 -6
- package/src/Recheck.ts +1 -0
- package/src/Retro.ts +2 -5
- package/src/ReviewModel.ts +1 -0
- package/src/Settings.ts +66 -8
- package/src/Spans.ts +2 -4
- package/src/Stories.ts +3 -5
- package/src/Survey.ts +1 -2
- package/src/Taskforce.ts +0 -2
- package/src/TestEvidence.ts +4 -3
- package/src/Workspace.ts +7 -24
- package/src/settings/Registry.ts +14 -7
- package/src/settings/Value.ts +13 -5
- package/dist/Classified.d.ts +0 -16
- package/dist/Classified.d.ts.map +0 -1
- package/dist/Classified.js +0 -52
- package/dist/Classified.js.map +0 -1
- package/dist/Mermaid.d.ts +0 -7
- package/dist/Mermaid.d.ts.map +0 -1
- package/dist/Mermaid.js +0 -98
- package/dist/Mermaid.js.map +0 -1
- package/src/Classified.ts +0 -72
- package/src/Mermaid.ts +0 -112
package/dist/FlowEvents.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type * as Duration from "effect/Duration";
|
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Layer from "effect/Layer";
|
|
5
5
|
import * as PubSub from "effect/PubSub";
|
|
6
|
-
import * as Ref from "effect/Ref";
|
|
7
6
|
import * as Schema from "effect/Schema";
|
|
8
7
|
import type * as Scope from "effect/Scope";
|
|
9
8
|
import * as Stream from "effect/Stream";
|
|
@@ -216,11 +215,6 @@ declare const EvidenceChecked_base: Schema.Class<EvidenceChecked, Schema.TaggedS
|
|
|
216
215
|
/** A task's `verified:` claims against the tool calls its transcript shows (ADR 0027). */
|
|
217
216
|
export declare class EvidenceChecked extends EvidenceChecked_base {
|
|
218
217
|
}
|
|
219
|
-
declare const Declassified_base: Schema.Class<Declassified, Schema.TaggedStruct<"Declassified", {
|
|
220
|
-
readonly label: Schema.String;
|
|
221
|
-
}>, {}>;
|
|
222
|
-
export declare class Declassified extends Declassified_base {
|
|
223
|
-
}
|
|
224
218
|
declare const BlackboardRun_base: Schema.Class<BlackboardRun, Schema.TaggedStruct<"BlackboardRun", {
|
|
225
219
|
readonly ruleset: Schema.String;
|
|
226
220
|
readonly result: typeof RunResult;
|
|
@@ -477,13 +471,12 @@ export type RosterEvent = ExecutorLeased | ExecutorReleased | ExecutorExcluded |
|
|
|
477
471
|
/** `codex#2` for a numbered clone, the bare executor otherwise (ADR 0033). */
|
|
478
472
|
export declare const cloneName: (executor: string, clone: number | undefined) => string;
|
|
479
473
|
export declare const rosterEventMessage: (event: FlowEvent) => string | undefined;
|
|
480
|
-
export declare const FlowEvent: Schema.Union<readonly [typeof JudgmentObserved, typeof BlackboardRun, typeof StageStarted, typeof StageCompleted, typeof StageFailed, typeof Aborted, typeof Info, typeof ToolUse, typeof AssistantMessage, typeof TokensUsed, typeof UsageProgress, typeof ReviewFindings, typeof CapabilityUsedEvent, typeof CapabilityDeniedEvent, typeof CapabilityUnenforceable, typeof EvidenceChecked, typeof ReviewFindingDemoted, typeof
|
|
474
|
+
export declare const FlowEvent: Schema.Union<readonly [typeof JudgmentObserved, typeof BlackboardRun, typeof StageStarted, typeof StageCompleted, typeof StageFailed, typeof Aborted, typeof Info, typeof ToolUse, typeof AssistantMessage, typeof TokensUsed, typeof UsageProgress, typeof ReviewFindings, typeof CapabilityUsedEvent, typeof CapabilityDeniedEvent, typeof CapabilityUnenforceable, typeof EvidenceChecked, typeof ReviewFindingDemoted, typeof ExecutorLeased, typeof ExecutorReleased, typeof ExecutorExcluded, typeof ExecutorResumed, typeof ExecutorHandedOver, typeof StoryJudged, typeof RoundtableTurn, typeof BriefReported, typeof Timed, typeof Began, typeof TasksPlanned, typeof TaskStarted, typeof TaskCompleted, typeof StoryStatusChanged, typeof CriterionChecked, typeof Parked]>;
|
|
481
475
|
export type FlowEvent = typeof FlowEvent.Type;
|
|
482
476
|
export declare const FlowEventsValues: Readonly<{
|
|
483
477
|
CapabilityUsed: (capability: string, operation: string) => CapabilityUsedEvent;
|
|
484
478
|
CapabilityDenied: (capability: string, operation: string) => CapabilityDeniedEvent;
|
|
485
479
|
CapabilityUnenforceable: (detail: string) => CapabilityUnenforceable;
|
|
486
|
-
Declassified: (label: string) => Declassified;
|
|
487
480
|
}>;
|
|
488
481
|
export interface FlowEventsShape {
|
|
489
482
|
readonly publish: (event: FlowEvent) => Effect.Effect<void>;
|
|
@@ -501,6 +494,60 @@ export interface Lane {
|
|
|
501
494
|
}
|
|
502
495
|
/** Tool arguments without the lane's own directory: `cd <dir> && x` → `x`, `<dir>/src/a` → `src/a`. */
|
|
503
496
|
export declare const shortenLaneArgs: (args: string, workDir: string | undefined) => string;
|
|
497
|
+
export type FlowEventTag = FlowEvent["_tag"];
|
|
498
|
+
/** Each event class by its tag: what a table keyed by tag is typed over. */
|
|
499
|
+
export type FlowEventByTag = {
|
|
500
|
+
readonly [K in FlowEventTag]: Extract<FlowEvent, {
|
|
501
|
+
readonly _tag: K;
|
|
502
|
+
}>;
|
|
503
|
+
};
|
|
504
|
+
type Tag = FlowEventTag;
|
|
505
|
+
type EventOf = FlowEventByTag;
|
|
506
|
+
/** The lane an event is in, and the executor working it when the event names one. */
|
|
507
|
+
export interface LaneRef {
|
|
508
|
+
readonly lane: string;
|
|
509
|
+
readonly executor?: string;
|
|
510
|
+
}
|
|
511
|
+
/** What `withLane` knows of its lane when an event passes through it. */
|
|
512
|
+
export interface LaneTags {
|
|
513
|
+
readonly lane: string;
|
|
514
|
+
readonly executor: string | undefined;
|
|
515
|
+
readonly clone: number | undefined;
|
|
516
|
+
readonly workDir: string | undefined;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* How an event stands to lanes. `none`: it has no lane. `carried`: its
|
|
520
|
+
* producer names the lane, and `withLane` leaves it alone. `stamped`:
|
|
521
|
+
* `withLane` names the lane on one published without, through `stamp`.
|
|
522
|
+
*/
|
|
523
|
+
export interface LaneRule<E> {
|
|
524
|
+
readonly lane: "none" | "carried" | "stamped";
|
|
525
|
+
readonly read?: (event: E) => LaneRef | undefined;
|
|
526
|
+
readonly stamp?: (event: E, tags: LaneTags) => E;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Every event's standing to lanes. Exhaustive by type: adding an event class
|
|
530
|
+
* without an entry here fails `pnpm typecheck`.
|
|
531
|
+
*/
|
|
532
|
+
export declare const eventLanes: {
|
|
533
|
+
readonly [K in Tag]: LaneRule<EventOf[K]>;
|
|
534
|
+
};
|
|
535
|
+
/** The lane of any event that is in one, and its executor when the event names it. */
|
|
536
|
+
export declare const laneOf: (event: FlowEvent) => LaneRef | undefined;
|
|
537
|
+
export declare const LaneKind: Schema.Literals<readonly ["story", "attendee", "specialist"]>;
|
|
538
|
+
/** What a lane stands for: a story's coder (ADR 0022), a roundtable attendee (ADR 0046), or a taskforce specialist (ADR 0047). */
|
|
539
|
+
export type LaneKind = typeof LaneKind.Type;
|
|
540
|
+
/** A lane as its opening stage names it. */
|
|
541
|
+
export interface LaneName {
|
|
542
|
+
readonly kind: LaneKind;
|
|
543
|
+
readonly id: string;
|
|
544
|
+
}
|
|
545
|
+
/** The lane this event opens, when it is the `StageStarted` that opens one. */
|
|
546
|
+
export declare const laneOpened: (event: FlowEvent) => LaneName | undefined;
|
|
547
|
+
/** The lane this event closes, when it is the end of the stage that opened one. */
|
|
548
|
+
export declare const laneClosed: (event: FlowEvent) => (LaneName & {
|
|
549
|
+
readonly failed: boolean;
|
|
550
|
+
}) | undefined;
|
|
504
551
|
/**
|
|
505
552
|
* The same events, stamped with a lane: every stage, message, tool call and
|
|
506
553
|
* token report says which story it belongs to and which executor works it.
|
|
@@ -517,25 +564,56 @@ export interface CollectingFlowEvents extends FlowEventsShape {
|
|
|
517
564
|
readonly recorded: Effect.Effect<ReadonlyArray<FlowEvent>>;
|
|
518
565
|
}
|
|
519
566
|
export declare const makeCollectingFlowEvents: Effect.Effect<CollectingFlowEvents>;
|
|
567
|
+
/** How a consumer stands against what the hub published; see `FlowEventHub.drained`. */
|
|
568
|
+
export interface DrainReport {
|
|
569
|
+
/** Every consumer handled every event it was owed, and none joined late. */
|
|
570
|
+
readonly complete: boolean;
|
|
571
|
+
/** Consumers still short when the wait ended, and by how many events. */
|
|
572
|
+
readonly behind: ReadonlyArray<{
|
|
573
|
+
readonly name: string;
|
|
574
|
+
readonly missing: number;
|
|
575
|
+
}>;
|
|
576
|
+
/**
|
|
577
|
+
* Consumers meant to see the whole run that subscribed after events were
|
|
578
|
+
* published: those events never reached them, however long anyone waits.
|
|
579
|
+
*/
|
|
580
|
+
readonly late: ReadonlyArray<{
|
|
581
|
+
readonly name: string;
|
|
582
|
+
readonly missed: number;
|
|
583
|
+
}>;
|
|
584
|
+
}
|
|
585
|
+
export interface FlowEventConsumer {
|
|
586
|
+
readonly name: string;
|
|
587
|
+
/** Whether this consumer alone handled everything it was owed, within `timeout`. */
|
|
588
|
+
readonly caughtUp: (timeout?: Duration.Input) => Effect.Effect<boolean>;
|
|
589
|
+
}
|
|
590
|
+
export interface ConsumeOptions {
|
|
591
|
+
/**
|
|
592
|
+
* `start` (the default): the consumer accounts for the whole run, so
|
|
593
|
+
* joining after an event was published is reported by `drained`. `now`:
|
|
594
|
+
* it is owed only what is published from here on.
|
|
595
|
+
*/
|
|
596
|
+
readonly from?: "start" | "now";
|
|
597
|
+
}
|
|
520
598
|
export interface FlowEventHub extends FlowEventsShape {
|
|
521
599
|
readonly subscribe: Effect.Effect<PubSub.Subscription<FlowEvent>, never, Scope.Scope>;
|
|
522
600
|
readonly stream: Stream.Stream<FlowEvent>;
|
|
523
601
|
readonly publishedCount: Effect.Effect<number>;
|
|
602
|
+
/**
|
|
603
|
+
* Runs `handle` on every event published from here on, in order, on a fiber
|
|
604
|
+
* of the scope. The one consumer loop: the hub counts what each consumer
|
|
605
|
+
* handled, so nobody keeps a counter of their own.
|
|
606
|
+
*/
|
|
607
|
+
readonly consume: (name: string, handle: (event: FlowEvent) => Effect.Effect<void>, options?: ConsumeOptions) => Effect.Effect<FlowEventConsumer, never, Scope.Scope>;
|
|
608
|
+
/**
|
|
609
|
+
* Waits, at most `timeout`, for every live consumer to handle what it was
|
|
610
|
+
* owed, then says who fell short. A late subscriber ends the wait at once:
|
|
611
|
+
* no wait can bring back what it missed.
|
|
612
|
+
*/
|
|
613
|
+
readonly drained: (timeout?: Duration.Input) => Effect.Effect<DrainReport>;
|
|
524
614
|
}
|
|
525
615
|
export declare const makeFlowEventHub: (capacity?: any) => Effect.Effect<FlowEventHub, never, never>;
|
|
526
616
|
/** How long a consumer waits to catch up before the run moves on regardless. */
|
|
527
617
|
export declare const defaultDrainTimeout = "3 seconds";
|
|
528
|
-
/**
|
|
529
|
-
* The shared drain: wait until `consumed` has caught up with everything the
|
|
530
|
-
* hub published, and report whether it did.
|
|
531
|
-
*
|
|
532
|
-
* Bounded on purpose, and the single copy of this loop. A consumer can fall
|
|
533
|
-
* permanently short of the count — a subscription torn down early, an
|
|
534
|
-
* event the PubSub refused — and an unbounded wait then pegs a core forever.
|
|
535
|
-
* In the runner that swallowed the end of a run: every stage printed and
|
|
536
|
-
* ticked green, and no cost summary ever following, because the summary is
|
|
537
|
-
* written only once every consumer reports drained.
|
|
538
|
-
*/
|
|
539
|
-
export declare const awaitConsumed: (hub: FlowEventHub, consumed: Ref.Ref<number>, timeout?: Duration.Input) => Effect.Effect<boolean>;
|
|
540
618
|
export {};
|
|
541
619
|
//# sourceMappingURL=FlowEvents.d.ts.map
|
package/dist/FlowEvents.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowEvents.d.ts","sourceRoot":"","sources":["../src/FlowEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"FlowEvents.d.ts","sourceRoot":"","sources":["../src/FlowEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC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
import * as Context from "effect/Context";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Option from "effect/Option";
|
|
4
3
|
import * as Layer from "effect/Layer";
|
|
5
4
|
import * as PubSub from "effect/PubSub";
|
|
6
5
|
import * as Ref from "effect/Ref";
|
|
7
6
|
import * as Schema from "effect/Schema";
|
|
7
|
+
import * as Semaphore from "effect/Semaphore";
|
|
8
8
|
import * as Stream from "effect/Stream";
|
|
9
9
|
import { TokenUsage } from "@llm4ts/core/Models";
|
|
10
10
|
import { RunResult } from "@llm4ts/core/blackboard/Run";
|
|
@@ -185,10 +185,6 @@ export class EvidenceChecked extends Schema.TaggedClass()("EvidenceChecked", {
|
|
|
185
185
|
lane: Schema.optionalKey(Schema.String)
|
|
186
186
|
}) {
|
|
187
187
|
}
|
|
188
|
-
export class Declassified extends Schema.TaggedClass()("Declassified", {
|
|
189
|
-
label: Schema.String
|
|
190
|
-
}) {
|
|
191
|
-
}
|
|
192
188
|
/** A blackboard ruleset ran (ADR 0020): its board, trace and failures, for the trace file. */
|
|
193
189
|
export class BlackboardRun extends Schema.TaggedClass()("BlackboardRun", {
|
|
194
190
|
ruleset: Schema.String,
|
|
@@ -472,7 +468,6 @@ export const FlowEvent = Schema.Union([
|
|
|
472
468
|
CapabilityUnenforceable,
|
|
473
469
|
EvidenceChecked,
|
|
474
470
|
ReviewFindingDemoted,
|
|
475
|
-
Declassified,
|
|
476
471
|
ExecutorLeased,
|
|
477
472
|
ExecutorReleased,
|
|
478
473
|
ExecutorExcluded,
|
|
@@ -493,8 +488,7 @@ export const FlowEvent = Schema.Union([
|
|
|
493
488
|
export const FlowEventsValues = Object.freeze({
|
|
494
489
|
CapabilityUsed: (capability, operation) => new CapabilityUsedEvent({ capability, operation }),
|
|
495
490
|
CapabilityDenied: (capability, operation) => new CapabilityDeniedEvent({ capability, operation }),
|
|
496
|
-
CapabilityUnenforceable: (detail) => new CapabilityUnenforceable({ detail })
|
|
497
|
-
Declassified: (label) => new Declassified({ label })
|
|
491
|
+
CapabilityUnenforceable: (detail) => new CapabilityUnenforceable({ detail })
|
|
498
492
|
});
|
|
499
493
|
/** Tool arguments without the lane's own directory: `cd <dir> && x` → `x`, `<dir>/src/a` → `src/a`. */
|
|
500
494
|
export const shortenLaneArgs = (args, workDir) => {
|
|
@@ -504,111 +498,146 @@ export const shortenLaneArgs = (args, workDir) => {
|
|
|
504
498
|
const root = workDir.replace(/\/+$/, "");
|
|
505
499
|
return args.split(`cd ${root} && `).join("").split(`${root}/`).join("");
|
|
506
500
|
};
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
501
|
+
const readLane = (event) => event.lane === undefined
|
|
502
|
+
? undefined
|
|
503
|
+
: { lane: event.lane, ...(event.executor === undefined ? {} : { executor: event.executor }) };
|
|
504
|
+
const unlaned = { lane: "none" };
|
|
505
|
+
const carried = { lane: "carried", read: readLane };
|
|
506
|
+
const stamped = (stamp) => ({ lane: "stamped", read: readLane, stamp });
|
|
507
|
+
/** The lane and, when it has one, the executor working it. */
|
|
508
|
+
const seat = (tags) => ({
|
|
509
|
+
lane: tags.lane,
|
|
510
|
+
...(tags.executor === undefined ? {} : { executor: tags.executor })
|
|
511
|
+
});
|
|
512
|
+
const laneRules = {
|
|
513
|
+
JudgmentObserved: unlaned,
|
|
514
|
+
BlackboardRun: unlaned,
|
|
515
|
+
StageStarted: stamped((event, tags) => StageStarted.make({ stage: event.stage, ...seat(tags) })),
|
|
516
|
+
StageCompleted: stamped((event, tags) => StageCompleted.make({ stage: event.stage, ...seat(tags) })),
|
|
517
|
+
StageFailed: stamped((event, tags) => StageFailed.make({ stage: event.stage, message: event.message, ...seat(tags) })),
|
|
518
|
+
Aborted: unlaned,
|
|
519
|
+
Info: stamped((event, tags) => Info.make({ message: event.message, ...seat(tags) })),
|
|
520
|
+
ToolUse: stamped((event, tags) => ToolUse.make({
|
|
521
|
+
tool: event.tool,
|
|
522
|
+
args: shortenLaneArgs(event.args, tags.workDir),
|
|
523
|
+
...(event.parent === undefined ? {} : { parent: event.parent }),
|
|
524
|
+
...seat(tags)
|
|
525
|
+
})),
|
|
526
|
+
AssistantMessage: stamped((event, tags) => AssistantMessage.make({ text: event.text, ...seat(tags) })),
|
|
527
|
+
TokensUsed: stamped((event, tags) => TokensUsed.make({
|
|
528
|
+
agent: event.agent,
|
|
529
|
+
usage: event.usage,
|
|
530
|
+
...(event.model === undefined ? {} : { model: event.model }),
|
|
531
|
+
...seat(tags),
|
|
532
|
+
// The lane's clone is its coder's: a reviewer or judge on the
|
|
533
|
+
// lane's events ran on another executor (ADR 0033).
|
|
534
|
+
...(event.agent === "coder" && tags.clone !== undefined ? { clone: tags.clone } : {})
|
|
535
|
+
})),
|
|
536
|
+
UsageProgress: stamped((event, tags) => UsageProgress.make({
|
|
537
|
+
call: event.call,
|
|
538
|
+
...(event.usage === undefined ? {} : { usage: event.usage }),
|
|
539
|
+
...(event.done === undefined ? {} : { done: event.done }),
|
|
540
|
+
...seat(tags)
|
|
541
|
+
})),
|
|
542
|
+
ReviewFindings: stamped((event, tags) => ReviewFindings.make({
|
|
543
|
+
round: event.round,
|
|
544
|
+
settled: event.settled,
|
|
545
|
+
issues: event.issues,
|
|
546
|
+
...(event.diffLines === undefined ? {} : { diffLines: event.diffLines }),
|
|
547
|
+
...seat(tags)
|
|
548
|
+
})),
|
|
549
|
+
CapabilityUsed: unlaned,
|
|
550
|
+
CapabilityDenied: unlaned,
|
|
551
|
+
CapabilityUnenforceable: unlaned,
|
|
552
|
+
EvidenceChecked: carried,
|
|
553
|
+
ReviewFindingDemoted: carried,
|
|
554
|
+
ExecutorLeased: unlaned,
|
|
555
|
+
ExecutorReleased: unlaned,
|
|
556
|
+
ExecutorExcluded: unlaned,
|
|
557
|
+
ExecutorResumed: unlaned,
|
|
558
|
+
ExecutorHandedOver: unlaned,
|
|
559
|
+
StoryJudged: carried,
|
|
560
|
+
RoundtableTurn: carried,
|
|
561
|
+
BriefReported: carried,
|
|
562
|
+
// The lane's executor is its coder's: it names a coder call or tool, not
|
|
563
|
+
// a reviewer's or judge's call made on another executor.
|
|
564
|
+
Timed: stamped((event, tags) => Timed.make({
|
|
565
|
+
...event,
|
|
566
|
+
lane: tags.lane,
|
|
567
|
+
...(tags.executor !== undefined &&
|
|
568
|
+
((event.kind === "model" && event.label === "coder") || event.kind === "tool")
|
|
569
|
+
? { executor: tags.executor }
|
|
570
|
+
: {})
|
|
571
|
+
})),
|
|
572
|
+
Began: stamped((event, tags) => Began.make({
|
|
573
|
+
...event,
|
|
574
|
+
lane: tags.lane,
|
|
575
|
+
...(tags.executor !== undefined && event.kind === "model" && event.label === "coder"
|
|
576
|
+
? { executor: tags.executor }
|
|
577
|
+
: {})
|
|
578
|
+
})),
|
|
579
|
+
TasksPlanned: stamped((event, tags) => TasksPlanned.make({ tasks: event.tasks, ...seat(tags) })),
|
|
580
|
+
TaskStarted: stamped((event, tags) => TaskStarted.make({
|
|
581
|
+
index: event.index,
|
|
582
|
+
count: event.count,
|
|
583
|
+
title: event.title,
|
|
584
|
+
...(event.satisfies === undefined ? {} : { satisfies: event.satisfies }),
|
|
585
|
+
...seat(tags),
|
|
586
|
+
// A parallel task names its own coder, not the lane's (ADR 0034).
|
|
587
|
+
...(event.parallel === undefined ? {} : { parallel: event.parallel }),
|
|
588
|
+
...(event.executor === undefined ? {} : { executor: event.executor }),
|
|
589
|
+
...(event.clone === undefined ? {} : { clone: event.clone })
|
|
590
|
+
})),
|
|
591
|
+
TaskCompleted: stamped((event, tags) => TaskCompleted.make({
|
|
592
|
+
index: event.index,
|
|
593
|
+
count: event.count,
|
|
594
|
+
title: event.title,
|
|
595
|
+
...seat(tags)
|
|
596
|
+
})),
|
|
597
|
+
StoryStatusChanged: unlaned,
|
|
598
|
+
CriterionChecked: carried,
|
|
599
|
+
Parked: carried
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* Every event's standing to lanes. Exhaustive by type: adding an event class
|
|
603
|
+
* without an entry here fails `pnpm typecheck`.
|
|
604
|
+
*/
|
|
605
|
+
export const eventLanes = laneRules;
|
|
606
|
+
// A tag and its event are one value's, so the rule found by the tag takes the
|
|
607
|
+
// event. TypeScript does not correlate the two across the union; reading the
|
|
608
|
+
// rule through a generic key is the step that lets it.
|
|
609
|
+
const ruleOf = (tag) => eventLanes[tag];
|
|
610
|
+
/** The lane of any event that is in one, and its executor when the event names it. */
|
|
611
|
+
export const laneOf = (event) => ruleOf(event._tag).read?.(event);
|
|
612
|
+
const stampedWith = (event, tags) => {
|
|
613
|
+
const rule = ruleOf(event._tag);
|
|
614
|
+
return rule.stamp === undefined || rule.read?.(event) !== undefined
|
|
615
|
+
? event
|
|
616
|
+
: rule.stamp(event, tags);
|
|
617
|
+
};
|
|
618
|
+
export const LaneKind = Schema.Literals(["story", "attendee", "specialist"]);
|
|
619
|
+
const isLaneKind = Schema.is(LaneKind);
|
|
620
|
+
const laneStagePattern = /^(\S+) (.+)$/u;
|
|
621
|
+
/**
|
|
622
|
+
* The lane protocol, read side: a lane opens with a `StageStarted` whose stage
|
|
623
|
+
* is `<kind> <id>` and whose lane is that id (names may hold spaces), and
|
|
624
|
+
* closes when the same stage completes or fails.
|
|
625
|
+
*/
|
|
626
|
+
const laneNamed = (stage, lane) => {
|
|
627
|
+
const [, kind, id] = laneStagePattern.exec(stage) ?? [];
|
|
628
|
+
return kind !== undefined && isLaneKind(kind) && id !== undefined && id === lane
|
|
629
|
+
? { kind, id }
|
|
630
|
+
: undefined;
|
|
631
|
+
};
|
|
632
|
+
/** The lane this event opens, when it is the `StageStarted` that opens one. */
|
|
633
|
+
export const laneOpened = (event) => event._tag === "StageStarted" ? laneNamed(event.stage, event.lane) : undefined;
|
|
634
|
+
/** The lane this event closes, when it is the end of the stage that opened one. */
|
|
635
|
+
export const laneClosed = (event) => {
|
|
636
|
+
if (event._tag !== "StageCompleted" && event._tag !== "StageFailed") {
|
|
637
|
+
return undefined;
|
|
611
638
|
}
|
|
639
|
+
const named = laneNamed(event.stage, event.lane);
|
|
640
|
+
return named === undefined ? undefined : { ...named, failed: event._tag === "StageFailed" };
|
|
612
641
|
};
|
|
613
642
|
/**
|
|
614
643
|
* The same events, stamped with a lane: every stage, message, tool call and
|
|
@@ -616,7 +645,7 @@ const stamped = (event, lane, executor, workDir, clone) => {
|
|
|
616
645
|
* An event already stamped (a nested context) keeps its own lane.
|
|
617
646
|
*/
|
|
618
647
|
export const withLane = (events, lane) => ({
|
|
619
|
-
publish: (event) => Effect.flatMap(lane.executor ?? Effect.succeed(undefined), (executor) => Effect.flatMap(lane.clone ?? Effect.succeed(undefined), (clone) => events.publish(
|
|
648
|
+
publish: (event) => Effect.flatMap(lane.executor ?? Effect.succeed(undefined), (executor) => Effect.flatMap(lane.clone ?? Effect.succeed(undefined), (clone) => events.publish(stampedWith(event, { lane: lane.lane, executor, clone, workDir: lane.workDir }))))
|
|
620
649
|
});
|
|
621
650
|
/** Publish an observation, rendering the same decision and outcome in advise mode. */
|
|
622
651
|
export const publishJudgmentObserved = Effect.fn("@llm4ts/flow/FlowEvents.publishJudgmentObserved")(function* (events, observation) {
|
|
@@ -640,34 +669,59 @@ export const makeCollectingFlowEvents = Effect.map(Ref.make([]), (events) => ({
|
|
|
640
669
|
export const makeFlowEventHub = Effect.fn("@llm4ts/flow/FlowEvents.makeHub")(function* (capacity = 64) {
|
|
641
670
|
const events = yield* PubSub.bounded(capacity);
|
|
642
671
|
const published = yield* Ref.make(0);
|
|
672
|
+
const consumers = yield* Ref.make([]);
|
|
673
|
+
// Held across a publish and its count, and across a subscription and the
|
|
674
|
+
// count it reads, so a consumer's baseline is exact: every event counted in
|
|
675
|
+
// it was published before the subscription, every later one reaches it.
|
|
676
|
+
const order = yield* Semaphore.make(1);
|
|
677
|
+
const missingOf = (consumer, target) => Effect.map(Ref.get(consumer.handled), (handled) => Math.max(0, target - consumer.baseline - handled));
|
|
678
|
+
const waitFor = (who, timeout) => Effect.gen(function* () {
|
|
679
|
+
const target = yield* Ref.get(published);
|
|
680
|
+
const behind = Effect.flatMap(who, (all) => Effect.forEach(all, (consumer) => Effect.map(missingOf(consumer, target), (missing) => ({ name: consumer.name, missing }))).pipe(Effect.map((rows) => rows.filter((row) => row.missing > 0))));
|
|
681
|
+
const poll = Effect.suspend(() => Effect.flatMap(behind, (rows) => rows.length === 0 ? Effect.void : Effect.yieldNow.pipe(Effect.andThen(poll))));
|
|
682
|
+
// Bounded on purpose. A consumer can fall permanently short, a handler
|
|
683
|
+
// that never returns among the ways, and an unbounded wait then pegs a
|
|
684
|
+
// core forever and swallows the end of the run.
|
|
685
|
+
yield* Effect.timeoutOption(poll, timeout);
|
|
686
|
+
return yield* behind;
|
|
687
|
+
});
|
|
643
688
|
return {
|
|
644
689
|
// Counted AFTER delivery, and only when the PubSub accepted the event.
|
|
645
690
|
// Tallying first meant a publish interrupted while backpressured (a
|
|
646
691
|
// bounded PubSub suspends when a subscriber is behind) left `published`
|
|
647
692
|
// permanently above anything a consumer could ever reach, and every
|
|
648
693
|
// drain waiting on it never finished.
|
|
649
|
-
publish: (event) => PubSub.publish(events, event).pipe(Effect.flatMap((accepted) => accepted ? Ref.update(published, (count) => count + 1) : Effect.void), Effect.asVoid),
|
|
694
|
+
publish: (event) => order.withPermit(PubSub.publish(events, event).pipe(Effect.flatMap((accepted) => accepted ? Ref.update(published, (count) => count + 1) : Effect.void), Effect.asVoid)),
|
|
650
695
|
subscribe: PubSub.subscribe(events),
|
|
651
696
|
stream: Stream.fromPubSub(events),
|
|
652
|
-
publishedCount: Ref.get(published)
|
|
697
|
+
publishedCount: Ref.get(published),
|
|
698
|
+
consume: (name, handle, options) => Effect.gen(function* () {
|
|
699
|
+
const handled = yield* Ref.make(0);
|
|
700
|
+
const [subscription, baseline] = yield* order.withPermit(Effect.all([PubSub.subscribe(events), Ref.get(published)]));
|
|
701
|
+
const state = {
|
|
702
|
+
name,
|
|
703
|
+
baseline,
|
|
704
|
+
wholeRun: options?.from !== "now",
|
|
705
|
+
handled
|
|
706
|
+
};
|
|
707
|
+
yield* Ref.update(consumers, (all) => [...all, state]);
|
|
708
|
+
yield* Stream.fromSubscription(subscription).pipe(Stream.runForEach((event) => handle(event).pipe(Effect.andThen(Ref.update(handled, (count) => count + 1)))), Effect.forkScoped);
|
|
709
|
+
// A consumer whose scope closed handles nothing more: nobody waits on it.
|
|
710
|
+
yield* Effect.addFinalizer(() => Ref.update(consumers, (all) => all.filter((other) => other !== state)));
|
|
711
|
+
return {
|
|
712
|
+
name,
|
|
713
|
+
caughtUp: (timeout = defaultDrainTimeout) => Effect.map(waitFor(Effect.succeed([state]), timeout), (rows) => rows.length === 0)
|
|
714
|
+
};
|
|
715
|
+
}),
|
|
716
|
+
drained: (timeout = defaultDrainTimeout) => Effect.gen(function* () {
|
|
717
|
+
const late = (yield* Ref.get(consumers))
|
|
718
|
+
.filter((consumer) => consumer.wholeRun && consumer.baseline > 0)
|
|
719
|
+
.map((consumer) => ({ name: consumer.name, missed: consumer.baseline }));
|
|
720
|
+
const behind = yield* waitFor(Ref.get(consumers), late.length === 0 ? timeout : 0);
|
|
721
|
+
return { complete: behind.length === 0 && late.length === 0, behind, late };
|
|
722
|
+
})
|
|
653
723
|
};
|
|
654
724
|
});
|
|
655
725
|
/** How long a consumer waits to catch up before the run moves on regardless. */
|
|
656
726
|
export const defaultDrainTimeout = "3 seconds";
|
|
657
|
-
/**
|
|
658
|
-
* The shared drain: wait until `consumed` has caught up with everything the
|
|
659
|
-
* hub published, and report whether it did.
|
|
660
|
-
*
|
|
661
|
-
* Bounded on purpose, and the single copy of this loop. A consumer can fall
|
|
662
|
-
* permanently short of the count — a subscription torn down early, an
|
|
663
|
-
* event the PubSub refused — and an unbounded wait then pegs a core forever.
|
|
664
|
-
* In the runner that swallowed the end of a run: every stage printed and
|
|
665
|
-
* ticked green, and no cost summary ever following, because the summary is
|
|
666
|
-
* written only once every consumer reports drained.
|
|
667
|
-
*/
|
|
668
|
-
export const awaitConsumed = (hub, consumed, timeout = defaultDrainTimeout) => Effect.gen(function* () {
|
|
669
|
-
const target = yield* hub.publishedCount;
|
|
670
|
-
const drain = Effect.suspend(() => Ref.get(consumed).pipe(Effect.flatMap((count) => count >= target ? Effect.void : Effect.yieldNow.pipe(Effect.andThen(drain)))));
|
|
671
|
-
return Option.isSome(yield* Effect.timeoutOption(drain, timeout));
|
|
672
|
-
});
|
|
673
727
|
//# sourceMappingURL=FlowEvents.js.map
|