@usine/engine 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -2
- package/dist/cursor/cursor.d.ts +20 -0
- package/dist/cursor/cursor.d.ts.map +1 -0
- package/dist/cursor/cursor.js +55 -0
- package/dist/cursor/cursor.js.map +1 -0
- package/dist/cycle-budget/cycle-budget.d.ts +25 -0
- package/dist/cycle-budget/cycle-budget.d.ts.map +1 -0
- package/dist/cycle-budget/cycle-budget.js +117 -0
- package/dist/cycle-budget/cycle-budget.js.map +1 -0
- package/dist/cycle-budget/model.d.ts +26 -0
- package/dist/cycle-budget/model.d.ts.map +1 -0
- package/dist/cycle-budget/model.js +20 -0
- package/dist/cycle-budget/model.js.map +1 -0
- package/dist/cycle-budget/queries.d.ts +27 -0
- package/dist/cycle-budget/queries.d.ts.map +1 -0
- package/dist/cycle-budget/queries.js +175 -0
- package/dist/cycle-budget/queries.js.map +1 -0
- package/dist/database/database.d.ts +15 -0
- package/dist/database/database.d.ts.map +1 -0
- package/dist/database/database.js +5 -0
- package/dist/database/database.js.map +1 -0
- package/dist/database/local-sqlite.d.ts +37 -0
- package/dist/database/local-sqlite.d.ts.map +1 -0
- package/dist/database/local-sqlite.js +144 -0
- package/dist/database/local-sqlite.js.map +1 -0
- package/dist/database/schema.d.ts +1341 -0
- package/dist/database/schema.d.ts.map +1 -0
- package/dist/database/schema.js +224 -0
- package/dist/database/schema.js.map +1 -0
- package/dist/engine/engine.d.ts +55 -0
- package/dist/engine/engine.d.ts.map +1 -0
- package/dist/engine/engine.js +193 -0
- package/dist/engine/engine.js.map +1 -0
- package/dist/engine/error.d.ts +37 -0
- package/dist/engine/error.d.ts.map +1 -0
- package/dist/engine/error.js +41 -0
- package/dist/engine/error.js.map +1 -0
- package/dist/engine/lifecycle.d.ts +112 -0
- package/dist/engine/lifecycle.d.ts.map +1 -0
- package/dist/engine/lifecycle.js +132 -0
- package/dist/engine/lifecycle.js.map +1 -0
- package/dist/engine/shutdown.d.ts +12 -0
- package/dist/engine/shutdown.d.ts.map +1 -0
- package/dist/engine/shutdown.js +10 -0
- package/dist/engine/shutdown.js.map +1 -0
- package/dist/engine/submission.d.ts +58 -0
- package/dist/engine/submission.d.ts.map +1 -0
- package/dist/engine/submission.js +54 -0
- package/dist/engine/submission.js.map +1 -0
- package/dist/item-projection/item-projection.d.ts +25 -0
- package/dist/item-projection/item-projection.d.ts.map +1 -0
- package/dist/item-projection/item-projection.js +100 -0
- package/dist/item-projection/item-projection.js.map +1 -0
- package/dist/item-projection/model.d.ts +18 -0
- package/dist/item-projection/model.d.ts.map +1 -0
- package/dist/item-projection/model.js +16 -0
- package/dist/item-projection/model.js.map +1 -0
- package/dist/loop-control/loop-control.d.ts +21 -0
- package/dist/loop-control/loop-control.d.ts.map +1 -0
- package/dist/loop-control/loop-control.js +71 -0
- package/dist/loop-control/loop-control.js.map +1 -0
- package/dist/loop-control/model.d.ts +10 -0
- package/dist/loop-control/model.d.ts.map +1 -0
- package/dist/loop-control/model.js +9 -0
- package/dist/loop-control/model.js.map +1 -0
- package/dist/repository-label-projection/model.d.ts +19 -0
- package/dist/repository-label-projection/model.d.ts.map +1 -0
- package/dist/repository-label-projection/model.js +20 -0
- package/dist/repository-label-projection/model.js.map +1 -0
- package/dist/repository-label-projection/repository-label-projection.d.ts +20 -0
- package/dist/repository-label-projection/repository-label-projection.d.ts.map +1 -0
- package/dist/repository-label-projection/repository-label-projection.js +83 -0
- package/dist/repository-label-projection/repository-label-projection.js.map +1 -0
- package/dist/run-reader/model.d.ts +46 -0
- package/dist/run-reader/model.d.ts.map +1 -0
- package/dist/run-reader/model.js +44 -0
- package/dist/run-reader/model.js.map +1 -0
- package/dist/run-reader/run-reader.d.ts +29 -0
- package/dist/run-reader/run-reader.d.ts.map +1 -0
- package/dist/run-reader/run-reader.js +44 -0
- package/dist/run-reader/run-reader.js.map +1 -0
- package/dist/step-executor.d.ts +43 -0
- package/dist/step-executor.d.ts.map +1 -0
- package/dist/step-executor.js +25 -0
- package/dist/step-executor.js.map +1 -0
- package/dist/store/codec.d.ts +495 -0
- package/dist/store/codec.d.ts.map +1 -0
- package/dist/store/codec.js +162 -0
- package/dist/store/codec.js.map +1 -0
- package/dist/store/queries.d.ts +107 -0
- package/dist/store/queries.d.ts.map +1 -0
- package/dist/store/queries.js +543 -0
- package/dist/store/queries.js.map +1 -0
- package/dist/store/store.d.ts +101 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +432 -0
- package/dist/store/store.js.map +1 -0
- package/dist/transcript.d.ts +64 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +59 -0
- package/dist/transcript.js.map +1 -0
- package/dist/workflow/admission.d.ts +13 -0
- package/dist/workflow/admission.d.ts.map +1 -0
- package/dist/workflow/admission.js +55 -0
- package/dist/workflow/admission.js.map +1 -0
- package/dist/workflow/command.d.ts +13 -0
- package/dist/workflow/command.d.ts.map +1 -0
- package/dist/workflow/command.js +17 -0
- package/dist/workflow/command.js.map +1 -0
- package/dist/workflow/workflow.d.ts +18 -0
- package/dist/workflow/workflow.d.ts.map +1 -0
- package/dist/workflow/workflow.js +108 -0
- package/dist/workflow/workflow.js.map +1 -0
- package/drizzle/20260825055549_initial_runtime/migration.sql +73 -0
- package/drizzle/20260825055549_initial_runtime/snapshot.json +592 -0
- package/drizzle/20260830191125_polling_cursors/migration.sql +5 -0
- package/drizzle/20260830191125_polling_cursors/snapshot.json +629 -0
- package/drizzle/20260831073158_attempt_channel/migration.sql +36 -0
- package/drizzle/20260831073158_attempt_channel/snapshot.json +845 -0
- package/drizzle/20260831133534_agent_context/migration.sql +49 -0
- package/drizzle/20260831133534_agent_context/snapshot.json +897 -0
- package/drizzle/20260831134612_attempt_brain/migration.sql +26 -0
- package/drizzle/20260831134612_attempt_brain/snapshot.json +923 -0
- package/drizzle/20260831194605_loop_runtime/migration.sql +4 -0
- package/drizzle/20260831194605_loop_runtime/snapshot.json +954 -0
- package/drizzle/20260901073233_projection_revision/migration.sql +55 -0
- package/drizzle/20260901073233_projection_revision/snapshot.json +991 -0
- package/drizzle/20260901180433_item_projections/migration.sql +22 -0
- package/drizzle/20260901180433_item_projections/snapshot.json +1110 -0
- package/drizzle/20260901185146_repository_label_projections/migration.sql +17 -0
- package/drizzle/20260901185146_repository_label_projections/snapshot.json +1147 -0
- package/drizzle/20260903091940_queued_approved_runs/migration.sql +3 -0
- package/drizzle/20260903091940_queued_approved_runs/snapshot.json +1147 -0
- package/drizzle/20260905150403_item_cycle_budgets/migration.sql +58 -0
- package/drizzle/20260905150403_item_cycle_budgets/snapshot.json +1417 -0
- package/drizzle/20260905174009_item_run_history/migration.sql +1 -0
- package/drizzle/20260905174009_item_run_history/snapshot.json +1431 -0
- package/package.json +60 -6
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as AttemptChannel from "@usine/core/attempt/channel";
|
|
2
|
+
import { AttemptId } from "@usine/core/attempt";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
/**
|
|
5
|
+
* Global append order of the persisted transcript. Distinct from
|
|
6
|
+
* `AttemptChannel.Sequence`, which orders messages within one Attempt's channel
|
|
7
|
+
* direction.
|
|
8
|
+
*/
|
|
9
|
+
export const TranscriptSequence = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)).pipe(Schema.brand("TranscriptSequence"));
|
|
10
|
+
const LEGACY_TRANSCRIPT_PROTOCOL_VERSION = 3;
|
|
11
|
+
const LegacyTranscriptEnvelope = Schema.Union([
|
|
12
|
+
Schema.Struct({
|
|
13
|
+
...AttemptChannel.OutboundEnvelope.fields,
|
|
14
|
+
version: Schema.Literal(LEGACY_TRANSCRIPT_PROTOCOL_VERSION),
|
|
15
|
+
}),
|
|
16
|
+
Schema.Struct({
|
|
17
|
+
...AttemptChannel.InboundEnvelope.fields,
|
|
18
|
+
version: Schema.Literal(LEGACY_TRANSCRIPT_PROTOCOL_VERSION),
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
/** Stored v3 envelopes stay readable; the live channel is v4 only. */
|
|
22
|
+
const TranscriptEnvelope = Schema.Union([AttemptChannel.Envelope, LegacyTranscriptEnvelope]);
|
|
23
|
+
/** One append-only row of an Attempt transcript. */
|
|
24
|
+
export class TranscriptEntry extends Schema.Class("@usine/engine/TranscriptEntry")({
|
|
25
|
+
sequence: TranscriptSequence,
|
|
26
|
+
attemptId: AttemptId,
|
|
27
|
+
direction: AttemptChannel.Direction,
|
|
28
|
+
envelope: TranscriptEnvelope,
|
|
29
|
+
receivedAt: Schema.DateTimeUtc,
|
|
30
|
+
}) {
|
|
31
|
+
}
|
|
32
|
+
/** All persisted rows for one Attempt, in append order. */
|
|
33
|
+
export class TranscriptAllQuery extends Schema.TaggedClass("@usine/engine/TranscriptAllQuery")("TranscriptAllQuery", { attemptId: AttemptId }) {
|
|
34
|
+
}
|
|
35
|
+
/** The next bounded set of rows after a cursor, in append order, for following an Attempt's activity. */
|
|
36
|
+
export class TranscriptTailQuery extends Schema.TaggedClass("@usine/engine/TranscriptTailQuery")("TranscriptTailQuery", {
|
|
37
|
+
attemptId: AttemptId,
|
|
38
|
+
/** Last row already received; the response excludes this row. */
|
|
39
|
+
after: TranscriptSequence,
|
|
40
|
+
/** Maximum number of newer rows to return. */
|
|
41
|
+
limit: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
|
|
42
|
+
}) {
|
|
43
|
+
}
|
|
44
|
+
/** The newest bounded page before a cursor, returned in append order for loading earlier activity. */
|
|
45
|
+
export class TranscriptPageQuery extends Schema.TaggedClass("@usine/engine/TranscriptPageQuery")("TranscriptPageQuery", {
|
|
46
|
+
attemptId: AttemptId,
|
|
47
|
+
/** Earliest row already loaded, excluded from the response; `None` starts at the current tail. */
|
|
48
|
+
before: Schema.Option(TranscriptSequence),
|
|
49
|
+
/** Maximum number of earlier rows to return. */
|
|
50
|
+
limit: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
|
|
51
|
+
}) {
|
|
52
|
+
}
|
|
53
|
+
/** Selects a complete Attempt transcript, newer activity, or an earlier page. */
|
|
54
|
+
export const TranscriptQuery = Schema.Union([
|
|
55
|
+
TranscriptAllQuery,
|
|
56
|
+
TranscriptTailQuery,
|
|
57
|
+
TranscriptPageQuery,
|
|
58
|
+
]);
|
|
59
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../src/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CACvF,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CACnC,CAAC;AAIF,MAAM,kCAAkC,GAAG,CAAU,CAAC;AAEtD,MAAM,wBAAwB,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC;QACZ,GAAG,cAAc,CAAC,gBAAgB,CAAC,MAAM;QACzC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,kCAAkC,CAAC;KAC5D,CAAC;IACF,MAAM,CAAC,MAAM,CAAC;QACZ,GAAG,cAAc,CAAC,eAAe,CAAC,MAAM;QACxC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,kCAAkC,CAAC;KAC5D,CAAC;CACH,CAAC,CAAC;AAEH,sEAAsE;AACtE,MAAM,kBAAkB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,c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,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RunId } from "@usine/core/run";
|
|
2
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
|
+
declare const AttemptAdmission_base: Context.ServiceClass<AttemptAdmission, "@usine/engine/AttemptAdmission", {
|
|
4
|
+
/** Admits and brackets one Attempt through outcome persistence; denied work waits for runtime teardown. */
|
|
5
|
+
readonly withAttempt: <A, E, R>(runId: RunId, attempt: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
6
|
+
readonly drain: () => Effect.Effect<void>;
|
|
7
|
+
}>;
|
|
8
|
+
/** Process-local Attempt admission. Durable Runs stay recoverable when admission closes (ADR 0023). */
|
|
9
|
+
export declare class AttemptAdmission extends AttemptAdmission_base {
|
|
10
|
+
static readonly layer: Layer.Layer<AttemptAdmission, never, never>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.d.ts","sourceRoot":"","sources":["../../src/workflow/admission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAY,MAAM,EAAE,KAAK,EAAe,MAAM,QAAQ,CAAC;;IAOnE,2GAA2G;0BACrF,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC5B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC5B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;oBACX,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;AAT7C,uGAAuG;AACvG,qBAAa,gBAAiB,SAAQ,qBAUD;IACnC,MAAM,CAAC,QAAQ,CAAC,KAAK,8CAkEnB;CACH"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Context, Deferred, Effect, Layer, Option, Ref } from "effect";
|
|
2
|
+
import { RunEngineShutdown } from "../engine/shutdown.js";
|
|
3
|
+
/** Process-local Attempt admission. Durable Runs stay recoverable when admission closes (ADR 0023). */
|
|
4
|
+
export class AttemptAdmission extends Context.Service()("@usine/engine/AttemptAdmission") {
|
|
5
|
+
static layer = Layer.effect(AttemptAdmission, Effect.gen(function* () {
|
|
6
|
+
const hostShutdown = yield* Effect.serviceOption(RunEngineShutdown);
|
|
7
|
+
const shutdown = Option.isSome(hostShutdown)
|
|
8
|
+
? hostShutdown.value
|
|
9
|
+
: yield* Deferred.make();
|
|
10
|
+
const active = yield* Ref.make(new Set());
|
|
11
|
+
const empty = yield* Deferred.make();
|
|
12
|
+
const enter = Effect.fn("AttemptAdmission.enter")(function* (runId) {
|
|
13
|
+
yield* Effect.annotateCurrentSpan({ runId });
|
|
14
|
+
// The host completes the same latch synchronously on a signal. This
|
|
15
|
+
// read and the active-set update are one atomic Ref.modify callback.
|
|
16
|
+
const admitted = yield* Ref.modify(active, (current) => Deferred.isDoneUnsafe(shutdown)
|
|
17
|
+
? [false, current]
|
|
18
|
+
: [true, new Set([...current, runId])]);
|
|
19
|
+
if (!admitted)
|
|
20
|
+
yield* Effect.logInfo("Attempt deferred until restart; the engine is draining", {
|
|
21
|
+
runId,
|
|
22
|
+
});
|
|
23
|
+
return admitted;
|
|
24
|
+
});
|
|
25
|
+
const leave = Effect.fn("AttemptAdmission.leave")(function* (runId) {
|
|
26
|
+
yield* Effect.annotateCurrentSpan({ runId });
|
|
27
|
+
const remaining = yield* Ref.updateAndGet(active, (current) => new Set([...current].filter((id) => id !== runId)));
|
|
28
|
+
if (yield* Deferred.isDone(shutdown)) {
|
|
29
|
+
yield* Effect.logInfo("Attempt settled during drain", {
|
|
30
|
+
runId,
|
|
31
|
+
remainingRunIds: [...remaining],
|
|
32
|
+
});
|
|
33
|
+
if (remaining.size === 0)
|
|
34
|
+
yield* Deferred.succeed(empty, undefined);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const withAttempt = Effect.fn("AttemptAdmission.withAttempt")(function* (runId, attempt) {
|
|
38
|
+
yield* Effect.annotateCurrentSpan({ runId });
|
|
39
|
+
return yield* Effect.acquireUseRelease(enter(runId), (admitted) => (admitted ? attempt : Effect.never), (admitted) => (admitted ? leave(runId) : Effect.void));
|
|
40
|
+
});
|
|
41
|
+
const drain = Effect.fn("AttemptAdmission.drain")(function* () {
|
|
42
|
+
yield* Deferred.succeed(shutdown, undefined);
|
|
43
|
+
const current = yield* Ref.get(active);
|
|
44
|
+
yield* Effect.logInfo("Engine drain started; no further Attempts will be admitted", {
|
|
45
|
+
activeRunIds: [...current],
|
|
46
|
+
});
|
|
47
|
+
if (current.size === 0)
|
|
48
|
+
yield* Deferred.succeed(empty, undefined);
|
|
49
|
+
yield* Deferred.await(empty);
|
|
50
|
+
yield* Effect.logInfo("Engine drain completed; all admitted Attempts settled");
|
|
51
|
+
});
|
|
52
|
+
return { withAttempt, drain };
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admission.js","sourceRoot":"","sources":["../../src/workflow/admission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,uGAAuG;AACvG,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,OAAO,EAUlD,CAAC,gCAAgC,CAAC;IACnC,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,MAAM,CAClC,gBAAgB,EAChB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,MAAM,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wBAAwB,CAAC,CAAC,QAAQ,CAAC;YACzD,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;YAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACvC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,4DAA4D,EAAE;gBAClF,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC;aAC3B,CAAC,CAAC;YACH,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC;gBAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAClE,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC7B,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,uDAAuD,CAAC,CAAC;QACjF,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC,CAAC,CACH,CAAC;CACH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
/** One-shot requests the store hands to the workflow runtime. */
|
|
3
|
+
export declare const WORKFLOW_COMMANDS: readonly ["Approve", "Continue", "Interrupt", "Resume"];
|
|
4
|
+
export declare const WorkflowCommand: Schema.Literals<readonly ["Approve", "Continue", "Interrupt", "Resume"]>;
|
|
5
|
+
export type WorkflowCommand = typeof WorkflowCommand.Type;
|
|
6
|
+
/**
|
|
7
|
+
* Replay order after a restart, first delivered first. Interrupt precedes
|
|
8
|
+
* Continue so a canceled workflow stops before the next queued Event opens,
|
|
9
|
+
* keeping one open Run per Item; the length constraint makes the list name
|
|
10
|
+
* every command exactly once.
|
|
11
|
+
*/
|
|
12
|
+
export declare const WORKFLOW_COMMAND_PRIORITY: readonly ["Resume", "Interrupt", "Continue", "Approve"];
|
|
13
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/workflow/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,YAAI,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC;AAEzF,eAAO,MAAM,eAAe,0EAAqC,CAAC;AAElE,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,yDAOrC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
/** One-shot requests the store hands to the workflow runtime. */
|
|
3
|
+
export const WORKFLOW_COMMANDS = ["Approve", "Continue", "Interrupt", "Resume"];
|
|
4
|
+
export const WorkflowCommand = Schema.Literals(WORKFLOW_COMMANDS);
|
|
5
|
+
/**
|
|
6
|
+
* Replay order after a restart, first delivered first. Interrupt precedes
|
|
7
|
+
* Continue so a canceled workflow stops before the next queued Event opens,
|
|
8
|
+
* keeping one open Run per Item; the length constraint makes the list name
|
|
9
|
+
* every command exactly once.
|
|
10
|
+
*/
|
|
11
|
+
export const WORKFLOW_COMMAND_PRIORITY = [
|
|
12
|
+
"Resume",
|
|
13
|
+
"Interrupt",
|
|
14
|
+
"Continue",
|
|
15
|
+
"Approve",
|
|
16
|
+
];
|
|
17
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/workflow/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,iEAAiE;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAC;AAEzF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAIlE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,QAAQ;IACR,WAAW;IACX,UAAU;IACV,SAAS;CAGV,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AgentFailure, DefectFailure, InfraFailure } from "@usine/core/attempt/failure";
|
|
2
|
+
import { RunId } from "@usine/core/run";
|
|
3
|
+
import { StepResult } from "@usine/core/step/result";
|
|
4
|
+
import { Effect, Schema } from "effect";
|
|
5
|
+
import { DurableDeferred, Workflow, WorkflowEngine } from "effect/unstable/workflow";
|
|
6
|
+
import { StepExecutor } from "../step-executor.ts";
|
|
7
|
+
import { AttemptAdmission } from "./admission.ts";
|
|
8
|
+
import { RunStore } from "../store/store.ts";
|
|
9
|
+
import { type RunStoreError } from "../engine/error.ts";
|
|
10
|
+
import { Submission } from "../engine/submission.ts";
|
|
11
|
+
export declare const DurableRun: Workflow.Workflow<"@usine/engine/DurableRun", Schema.Struct<{
|
|
12
|
+
readonly submission: typeof Submission;
|
|
13
|
+
}>, typeof StepResult, Schema.Union<readonly [typeof InfraFailure, typeof DefectFailure, typeof AgentFailure, typeof import("@usine/core/attempt/failure").RunawayFailure, typeof import("@usine/core/attempt/failure").ChildSessionBudgetFailure]>>;
|
|
14
|
+
export declare const ApprovalGate: DurableDeferred.DurableDeferred<Schema.Void, Schema.Never>;
|
|
15
|
+
export declare const continueWithNewest: (store: RunStore["Service"], completedRunId: RunId) => Effect.Effect<void, RunStoreError, WorkflowEngine.WorkflowEngine>;
|
|
16
|
+
export declare const durableRunLayer: import("effect/Layer").Layer<never, never, AttemptAdmission | RunStore | StepExecutor | WorkflowEngine.WorkflowEngine>;
|
|
17
|
+
export declare const runIdFor: (submission: Submission) => Effect.Effect<string & import("effect/Brand").Brand<"RunId">, never, never>;
|
|
18
|
+
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/workflow/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,aAAa,EACb,YAAY,EACb,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAyB,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAOrD,eAAO,MAAM,UAAU;;oPAKqB,CAAC;AAE7C,eAAO,MAAM,YAAY,4DAAqD,CAAC;AAiB/E,eAAO,MAAM,kBAAkB,EAAE,CAC/B,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,EAC1B,cAAc,EAAE,KAAK,KAClB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,cAAc,CAAC,cAAc,CAanE,CAAC;AA6FH,eAAO,MAAM,eAAe,wHAAwC,CAAC;AAErE,eAAO,MAAM,QAAQ,yGAEnB,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { AgentFailure, AttemptFailure, DefectFailure, InfraFailure, } from "@usine/core/attempt/failure";
|
|
2
|
+
import { RunId } from "@usine/core/run";
|
|
3
|
+
import { StepResult } from "@usine/core/step/result";
|
|
4
|
+
import { Effect, Option, Result, Schema } from "effect";
|
|
5
|
+
import { DurableDeferred, Workflow, WorkflowEngine } from "effect/unstable/workflow";
|
|
6
|
+
import { StepExecutor } from "../step-executor.js";
|
|
7
|
+
import { AttemptAdmission } from "./admission.js";
|
|
8
|
+
import { AttemptRecoveryFailed, RunStore } from "../store/store.js";
|
|
9
|
+
import { EnginePersistenceError, RunNotFoundError, RunOperationRejectedError, } from "../engine/error.js";
|
|
10
|
+
import { Submission } from "../engine/submission.js";
|
|
11
|
+
const WorkflowPayload = Schema.Struct({
|
|
12
|
+
submission: Submission,
|
|
13
|
+
});
|
|
14
|
+
export const DurableRun = Workflow.make("@usine/engine/DurableRun", {
|
|
15
|
+
payload: WorkflowPayload,
|
|
16
|
+
success: StepResult,
|
|
17
|
+
error: AttemptFailure,
|
|
18
|
+
idempotencyKey: ({ submission }) => submission.event.dedupKey,
|
|
19
|
+
}).annotate(Workflow.SuspendOnFailure, true);
|
|
20
|
+
export const ApprovalGate = DurableDeferred.make("@usine/engine/ApprovalGate");
|
|
21
|
+
const asAttemptFailure = (effect) => Effect.catchTags(effect, {
|
|
22
|
+
EnginePersistenceError: (error) => new InfraFailure({
|
|
23
|
+
message: `Engine persistence failed during ${error.operation}`,
|
|
24
|
+
cause: error,
|
|
25
|
+
}),
|
|
26
|
+
RunNotFoundError: (error) => Effect.die(error),
|
|
27
|
+
RunOperationRejectedError: (error) => Effect.die(error),
|
|
28
|
+
});
|
|
29
|
+
const executionId = (submission) => DurableRun.executionId({ submission });
|
|
30
|
+
export const continueWithNewest = Effect.fn("DurableRun.continueWithNewest")(function* (store, completedRunId) {
|
|
31
|
+
const queued = yield* store.nextQueued(completedRunId);
|
|
32
|
+
if (Option.isSome(queued)) {
|
|
33
|
+
const nextExecutionId = yield* executionId(queued.value);
|
|
34
|
+
const runId = RunId.make(nextExecutionId);
|
|
35
|
+
const claimed = yield* store.claimQueued(queued.value, runId);
|
|
36
|
+
if (Option.isSome(claimed)) {
|
|
37
|
+
yield* DurableRun.execute({ submission: claimed.value.submission }, { discard: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
yield* store.completeWorkflowCommand(completedRunId, "Continue");
|
|
41
|
+
});
|
|
42
|
+
const executeAttempt = Effect.fn("DurableRun.attempt")(function* (runId, worker) {
|
|
43
|
+
yield* Effect.annotateCurrentSpan({ runId, worker });
|
|
44
|
+
const store = yield* RunStore;
|
|
45
|
+
const executor = yield* StepExecutor;
|
|
46
|
+
const started = yield* store.beginAttempt(runId, worker).pipe(asAttemptFailure);
|
|
47
|
+
if (started instanceof AttemptRecoveryFailed || started._tag === "RunClosed") {
|
|
48
|
+
return started;
|
|
49
|
+
}
|
|
50
|
+
// Durable workflows need a serializable terminal outcome. Preserve an
|
|
51
|
+
// executor defect without turning a programming bug into an automatic retry.
|
|
52
|
+
const result = yield* executor
|
|
53
|
+
.execute(started.execution, {
|
|
54
|
+
append: (direction, envelope) => store.appendTranscript(direction, envelope).pipe(asAttemptFailure),
|
|
55
|
+
})
|
|
56
|
+
.pipe(Effect.catchDefect((defect) => Effect.logError("Step executor defect; operator intervention required", { runId }).pipe(Effect.andThen(new DefectFailure({
|
|
57
|
+
message: "The step executor crashed outside its typed failure channel",
|
|
58
|
+
cause: defect,
|
|
59
|
+
})))), Effect.result);
|
|
60
|
+
const decision = yield* store
|
|
61
|
+
.finishAttempt(started.execution.attempt, result)
|
|
62
|
+
.pipe(asAttemptFailure);
|
|
63
|
+
return { _tag: "AttemptExecuted", result, decision };
|
|
64
|
+
});
|
|
65
|
+
const executeDurableRun = Effect.fn("DurableRun.execute")(function* ({ submission }, executionId) {
|
|
66
|
+
const runId = RunId.make(executionId);
|
|
67
|
+
const store = yield* RunStore;
|
|
68
|
+
const executor = yield* StepExecutor;
|
|
69
|
+
const admission = yield* AttemptAdmission;
|
|
70
|
+
if (submission.approval === "required") {
|
|
71
|
+
yield* store.parkForApproval(runId).pipe(asAttemptFailure);
|
|
72
|
+
yield* DurableDeferred.await(ApprovalGate);
|
|
73
|
+
}
|
|
74
|
+
while (true) {
|
|
75
|
+
// The wait for a worker slot stays interruptible so a cancel can reach a run
|
|
76
|
+
// parked in `reserve`; the scheduler releases or reoffers the slot in its own
|
|
77
|
+
// onInterrupt. The release obligation begins only once the lease exists.
|
|
78
|
+
const attempted = yield* Effect.uninterruptibleMask((restore) => restore(executor.reserve(submission)).pipe(Effect.flatMap((lease) => restore(admission.withAttempt(runId, executeAttempt(runId, lease.worker))).pipe(Effect.ensuring(lease.release)))));
|
|
79
|
+
if (attempted._tag === "RunClosed") {
|
|
80
|
+
// Canceled, superseded, or revoked while queued: release was the only
|
|
81
|
+
// obligation, and the closing operation already delivered the interrupt.
|
|
82
|
+
yield* Effect.logInfo("Run closed while it waited for a worker", {
|
|
83
|
+
runId,
|
|
84
|
+
state: attempted.state,
|
|
85
|
+
});
|
|
86
|
+
yield* continueWithNewest(store, runId).pipe(asAttemptFailure);
|
|
87
|
+
return yield* new AgentFailure({
|
|
88
|
+
message: `The run closed (${attempted.state}) before an attempt started`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (attempted instanceof AttemptRecoveryFailed) {
|
|
92
|
+
yield* continueWithNewest(store, runId).pipe(asAttemptFailure);
|
|
93
|
+
return yield* attempted.failure;
|
|
94
|
+
}
|
|
95
|
+
const { result, decision } = attempted;
|
|
96
|
+
if (decision._tag !== "RetryAttempt") {
|
|
97
|
+
yield* continueWithNewest(store, runId).pipe(asAttemptFailure);
|
|
98
|
+
if (Result.isSuccess(result))
|
|
99
|
+
return result.success;
|
|
100
|
+
return yield* result.failure;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
export const durableRunLayer = DurableRun.toLayer(executeDurableRun);
|
|
105
|
+
export const runIdFor = Effect.fn("DurableRun.runIdFor")(function* (submission) {
|
|
106
|
+
return RunId.make(yield* executionId(submission));
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=workflow.js.map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,MAAM,CAAC,OAAO,CAAC;QAC/B,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,EAAE,UAAsB;IACxF,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;AACpD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
CREATE TABLE `usine_approvals` (
|
|
2
|
+
`run_id` text PRIMARY KEY,
|
|
3
|
+
`event_id` text NOT NULL UNIQUE,
|
|
4
|
+
CONSTRAINT `fk_usine_approvals_run_id_usine_runs_run_id_fk` FOREIGN KEY (`run_id`) REFERENCES `usine_runs`(`run_id`),
|
|
5
|
+
CONSTRAINT `fk_usine_approvals_event_id_usine_events_event_id_fk` FOREIGN KEY (`event_id`) REFERENCES `usine_events`(`event_id`)
|
|
6
|
+
);
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
CREATE TABLE `usine_attempts` (
|
|
9
|
+
`attempt_id` text PRIMARY KEY,
|
|
10
|
+
`run_id` text NOT NULL,
|
|
11
|
+
`step_name` text NOT NULL,
|
|
12
|
+
`attempt_number` integer NOT NULL,
|
|
13
|
+
`started_at` text NOT NULL,
|
|
14
|
+
`outcome_json` text,
|
|
15
|
+
CONSTRAINT `fk_usine_attempts_run_id_step_name_usine_steps_run_id_step_name_fk` FOREIGN KEY (`run_id`,`step_name`) REFERENCES `usine_steps`(`run_id`,`step_name`),
|
|
16
|
+
CONSTRAINT "usine_attempts_number" CHECK("attempt_number" >= 1),
|
|
17
|
+
CONSTRAINT "usine_attempts_outcome_json_valid" CHECK("outcome_json" is null or json_valid("outcome_json"))
|
|
18
|
+
);
|
|
19
|
+
--> statement-breakpoint
|
|
20
|
+
CREATE TABLE `usine_events` (
|
|
21
|
+
`event_id` text PRIMARY KEY,
|
|
22
|
+
`dedup_key` text NOT NULL UNIQUE,
|
|
23
|
+
`payload_json` text NOT NULL,
|
|
24
|
+
`received_at` text NOT NULL,
|
|
25
|
+
CONSTRAINT "usine_events_payload_json_valid" CHECK(json_valid("payload_json"))
|
|
26
|
+
);
|
|
27
|
+
--> statement-breakpoint
|
|
28
|
+
CREATE TABLE `usine_ignored_events` (
|
|
29
|
+
`event_id` text PRIMARY KEY,
|
|
30
|
+
`reason` text NOT NULL,
|
|
31
|
+
CONSTRAINT `fk_usine_ignored_events_event_id_usine_trigger_events_event_id_fk` FOREIGN KEY (`event_id`) REFERENCES `usine_trigger_events`(`event_id`),
|
|
32
|
+
CONSTRAINT "usine_ignored_events_reason" CHECK("reason" in ('superseded', 'revoked'))
|
|
33
|
+
);
|
|
34
|
+
--> statement-breakpoint
|
|
35
|
+
CREATE TABLE `usine_runs` (
|
|
36
|
+
`run_id` text PRIMARY KEY,
|
|
37
|
+
`event_id` text NOT NULL UNIQUE,
|
|
38
|
+
`loop_name` text NOT NULL,
|
|
39
|
+
`state_json` text NOT NULL,
|
|
40
|
+
`opened_at` text NOT NULL,
|
|
41
|
+
CONSTRAINT `fk_usine_runs_event_id_usine_trigger_events_event_id_fk` FOREIGN KEY (`event_id`) REFERENCES `usine_trigger_events`(`event_id`),
|
|
42
|
+
CONSTRAINT "usine_runs_state_json_valid" CHECK(json_valid("state_json"))
|
|
43
|
+
);
|
|
44
|
+
--> statement-breakpoint
|
|
45
|
+
CREATE TABLE `usine_steps` (
|
|
46
|
+
`run_id` text NOT NULL,
|
|
47
|
+
`step_name` text NOT NULL,
|
|
48
|
+
`result` text,
|
|
49
|
+
CONSTRAINT `usine_steps_pk` PRIMARY KEY(`run_id`, `step_name`),
|
|
50
|
+
CONSTRAINT `fk_usine_steps_run_id_usine_runs_run_id_fk` FOREIGN KEY (`run_id`) REFERENCES `usine_runs`(`run_id`)
|
|
51
|
+
);
|
|
52
|
+
--> statement-breakpoint
|
|
53
|
+
CREATE TABLE `usine_trigger_events` (
|
|
54
|
+
`event_id` text PRIMARY KEY,
|
|
55
|
+
`item_key` text NOT NULL,
|
|
56
|
+
`loop_name` text NOT NULL,
|
|
57
|
+
`step_name` text NOT NULL,
|
|
58
|
+
`approval` text NOT NULL,
|
|
59
|
+
CONSTRAINT `fk_usine_trigger_events_event_id_usine_events_event_id_fk` FOREIGN KEY (`event_id`) REFERENCES `usine_events`(`event_id`),
|
|
60
|
+
CONSTRAINT "usine_trigger_events_approval" CHECK("approval" in ('none', 'required'))
|
|
61
|
+
);
|
|
62
|
+
--> statement-breakpoint
|
|
63
|
+
CREATE TABLE `usine_workflow_commands` (
|
|
64
|
+
`run_id` text NOT NULL,
|
|
65
|
+
`command` text NOT NULL,
|
|
66
|
+
CONSTRAINT `usine_workflow_commands_pk` PRIMARY KEY(`run_id`, `command`),
|
|
67
|
+
CONSTRAINT `fk_usine_workflow_commands_run_id_usine_runs_run_id_fk` FOREIGN KEY (`run_id`) REFERENCES `usine_runs`(`run_id`),
|
|
68
|
+
CONSTRAINT "usine_workflow_commands_command" CHECK("command" in ('Approve', 'Continue', 'Interrupt', 'Resume'))
|
|
69
|
+
);
|
|
70
|
+
--> statement-breakpoint
|
|
71
|
+
CREATE UNIQUE INDEX `usine_attempt_number` ON `usine_attempts` (`run_id`,`step_name`,`attempt_number`);--> statement-breakpoint
|
|
72
|
+
CREATE UNIQUE INDEX `usine_one_in_flight_attempt` ON `usine_attempts` (`run_id`) WHERE "usine_attempts"."outcome_json" is null;--> statement-breakpoint
|
|
73
|
+
CREATE INDEX `usine_trigger_events_item` ON `usine_trigger_events` (`loop_name`,`item_key`);
|