@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,112 @@
|
|
|
1
|
+
import { Attempt, AttemptId, AttemptNumber } from "@usine/core/attempt";
|
|
2
|
+
import { AttemptFailure, InfraFailure } from "@usine/core/attempt/failure";
|
|
3
|
+
import { AttemptCanceled, AttemptFailed, AttemptSucceeded } from "@usine/core/attempt/outcome";
|
|
4
|
+
import { EventId } from "@usine/core/event";
|
|
5
|
+
import { Run, RunId } from "@usine/core/run";
|
|
6
|
+
import * as RunState from "@usine/core/run/state";
|
|
7
|
+
import { StepResult } from "@usine/core/step/result";
|
|
8
|
+
import { Option, Result } from "effect";
|
|
9
|
+
import type { WorkflowCommand } from "../workflow/command.ts";
|
|
10
|
+
/** A Run and its Attempts in ascending attempt-number order, read together. */
|
|
11
|
+
interface RunProgress {
|
|
12
|
+
readonly run: Run;
|
|
13
|
+
readonly attempts: ReadonlyArray<Attempt>;
|
|
14
|
+
}
|
|
15
|
+
type Unchanged = {
|
|
16
|
+
readonly _tag: "Unchanged";
|
|
17
|
+
readonly reason: "RunNotRunning" | "NoOpenAttempt" | "AttemptReplaced";
|
|
18
|
+
};
|
|
19
|
+
type RetryAttempt = {
|
|
20
|
+
readonly _tag: "RetryAttempt";
|
|
21
|
+
readonly attempt: Attempt;
|
|
22
|
+
readonly outcome: AttemptFailed;
|
|
23
|
+
};
|
|
24
|
+
type RunFailed = {
|
|
25
|
+
readonly _tag: "RunFailed";
|
|
26
|
+
readonly attempt: Attempt;
|
|
27
|
+
readonly outcome: AttemptFailed;
|
|
28
|
+
readonly state: RunState.Failed;
|
|
29
|
+
};
|
|
30
|
+
type RunSucceeded = {
|
|
31
|
+
readonly _tag: "RunSucceeded";
|
|
32
|
+
readonly attempt: Attempt;
|
|
33
|
+
readonly outcome: AttemptSucceeded;
|
|
34
|
+
readonly state: RunState.Succeeded;
|
|
35
|
+
readonly result: StepResult;
|
|
36
|
+
};
|
|
37
|
+
/** Changes that must commit together when an Attempt finishes. Only success stores a Step result. */
|
|
38
|
+
export type FinishDecision = RetryAttempt | RunFailed | RunSucceeded | Unchanged;
|
|
39
|
+
/**
|
|
40
|
+
* Settles the current Attempt from its executor result. Infrastructure failure
|
|
41
|
+
* can retry up to three total Attempts; a late or repeated completion changes nothing.
|
|
42
|
+
*/
|
|
43
|
+
export declare const finishAttempt: (current: RunProgress, attemptId: AttemptId, result: Result.Result<StepResult, AttemptFailure>) => FinishDecision;
|
|
44
|
+
/**
|
|
45
|
+
* Repairs an open Attempt from a final durable result. The workflow has already
|
|
46
|
+
* ended, so even an infrastructure failure closes the Run without auto-retry.
|
|
47
|
+
* The runtime must first translate its completion into a typed result; defects
|
|
48
|
+
* and suspension are not Attempt outcomes here (ADRs 0003 and 0010).
|
|
49
|
+
*/
|
|
50
|
+
export declare const reconcileAttempt: (current: RunProgress, result: Result.Result<StepResult, AttemptFailure>) => FinishDecision;
|
|
51
|
+
type StartDecision = {
|
|
52
|
+
readonly _tag: "StartAttempt";
|
|
53
|
+
readonly state: RunState.Running;
|
|
54
|
+
readonly number: AttemptNumber;
|
|
55
|
+
readonly interrupted: Option.Option<RetryAttempt>;
|
|
56
|
+
} | RunFailed | {
|
|
57
|
+
readonly _tag: "RunClosed";
|
|
58
|
+
readonly state: RunState.RunState;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Admits the next Attempt after a Worker reservation. An unfinished previous
|
|
62
|
+
* Attempt indicates a restart and counts against the same retry cap as ordinary
|
|
63
|
+
* infrastructure failure. `interruption` records the runtime's explanation.
|
|
64
|
+
* The caller creates the new Attempt's identity and timestamp only when admitted.
|
|
65
|
+
*/
|
|
66
|
+
export declare const beginAttempt: (current: RunProgress, interruption: InfraFailure) => StartDecision;
|
|
67
|
+
type CancelDecision = {
|
|
68
|
+
readonly _tag: "AlreadyClosed";
|
|
69
|
+
} | {
|
|
70
|
+
readonly _tag: "Canceled";
|
|
71
|
+
readonly state: RunState.Canceled;
|
|
72
|
+
readonly attempt: Option.Option<{
|
|
73
|
+
readonly id: AttemptId;
|
|
74
|
+
readonly outcome: AttemptCanceled;
|
|
75
|
+
}>;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Cancels open work and, if executing, its unfinished Attempt. A Run awaiting
|
|
79
|
+
* capacity may have no Attempt, or only the closed Attempt preceding a retry.
|
|
80
|
+
*/
|
|
81
|
+
export declare const cancelRun: (current: RunProgress) => CancelDecision;
|
|
82
|
+
type RetryDecision = {
|
|
83
|
+
readonly _tag: "Resume";
|
|
84
|
+
readonly state: RunState.Running;
|
|
85
|
+
} | {
|
|
86
|
+
readonly _tag: "ResumePending";
|
|
87
|
+
} | {
|
|
88
|
+
readonly _tag: "RetryRejected";
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Reopens a failed Run for operator retry regardless of its Attempt count.
|
|
92
|
+
* Repeating the request is accepted while its Resume command remains pending;
|
|
93
|
+
* after delivery, retrying a Running Run is rejected.
|
|
94
|
+
*/
|
|
95
|
+
export declare const retryRun: (state: RunState.RunState, pendingCommands: ReadonlyArray<WorkflowCommand>) => RetryDecision;
|
|
96
|
+
type ClaimDecision = {
|
|
97
|
+
readonly _tag: "OpenRun";
|
|
98
|
+
} | {
|
|
99
|
+
readonly _tag: "QueueEvent";
|
|
100
|
+
} | {
|
|
101
|
+
readonly _tag: "SupersedeRun";
|
|
102
|
+
readonly runId: RunId;
|
|
103
|
+
readonly state: RunState.Canceled;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Places a previously unclaimed Event behind its Item's running work, or
|
|
107
|
+
* replaces unstarted work. The ledger must resolve permanent deduplication and
|
|
108
|
+
* ignored Events before this decision; running Attempts always finish (ADR 0007).
|
|
109
|
+
*/
|
|
110
|
+
export declare const claimRun: (blocking: Option.Option<Run>, eventId: EventId) => ClaimDecision;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/engine/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAmB,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,QAAQ,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAK9D,+EAA+E;AAC/E,UAAU,WAAW;IACnB,QAAQ,CAAC,GAAG,EAAE,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eAAe,CAAC,KAC9C,aAMF,CAAC;AAEF,KAAK,aAAa,GACd;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAA;CAAE,CAAC;AAEhG;;;;GAIG;AACH,eAAO,MAAM,QAAQ,aAAc,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,OAAO,KAAG,aAQzE,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Attempt, AttemptId, AttemptNumber, shouldAutoRetry } from "@usine/core/attempt";
|
|
2
|
+
import { AttemptFailure, InfraFailure } from "@usine/core/attempt/failure";
|
|
3
|
+
import { AttemptCanceled, AttemptFailed, AttemptSucceeded } from "@usine/core/attempt/outcome";
|
|
4
|
+
import { EventId } from "@usine/core/event";
|
|
5
|
+
import { Run, RunId } from "@usine/core/run";
|
|
6
|
+
import * as RunState from "@usine/core/run/state";
|
|
7
|
+
import { StepResult } from "@usine/core/step/result";
|
|
8
|
+
import { Option, Result } from "effect";
|
|
9
|
+
// Engine policy, not a limit imposed on consumers of the core Attempt model.
|
|
10
|
+
const MAX_AUTO_ATTEMPTS = AttemptNumber.make(3);
|
|
11
|
+
const openAttempt = (current) => Option.fromNullishOr(current.attempts.at(-1)).pipe(Option.filter((attempt) => Option.isNone(attempt.outcome)));
|
|
12
|
+
const failRunningAttempt = (state, attempt, failure, policy) => {
|
|
13
|
+
const outcome = new AttemptFailed({ failure });
|
|
14
|
+
if (policy === "Execution" &&
|
|
15
|
+
shouldAutoRetry({ failure, number: attempt.number, maxAutoAttempts: MAX_AUTO_ATTEMPTS })) {
|
|
16
|
+
return { _tag: "RetryAttempt", attempt, outcome };
|
|
17
|
+
}
|
|
18
|
+
return { _tag: "RunFailed", attempt, outcome, state: RunState.fail(state) };
|
|
19
|
+
};
|
|
20
|
+
const finish = (current, attemptId, result, policy) => {
|
|
21
|
+
if (current.run.state._tag !== "Running") {
|
|
22
|
+
return { _tag: "Unchanged", reason: "RunNotRunning" };
|
|
23
|
+
}
|
|
24
|
+
const attempt = openAttempt(current);
|
|
25
|
+
if (Option.isNone(attempt))
|
|
26
|
+
return { _tag: "Unchanged", reason: "NoOpenAttempt" };
|
|
27
|
+
// A completion from before restart or operator retry cannot settle the
|
|
28
|
+
// replacement Attempt, even though the Run is Running again.
|
|
29
|
+
if (attempt.value.id !== attemptId)
|
|
30
|
+
return { _tag: "Unchanged", reason: "AttemptReplaced" };
|
|
31
|
+
if (Result.isFailure(result)) {
|
|
32
|
+
return failRunningAttempt(current.run.state, attempt.value, result.failure, policy);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
_tag: "RunSucceeded",
|
|
36
|
+
attempt: attempt.value,
|
|
37
|
+
outcome: new AttemptSucceeded(),
|
|
38
|
+
state: RunState.succeed(current.run.state),
|
|
39
|
+
result: result.success,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Settles the current Attempt from its executor result. Infrastructure failure
|
|
44
|
+
* can retry up to three total Attempts; a late or repeated completion changes nothing.
|
|
45
|
+
*/
|
|
46
|
+
export const finishAttempt = (current, attemptId, result) => finish(current, attemptId, result, "Execution");
|
|
47
|
+
/**
|
|
48
|
+
* Repairs an open Attempt from a final durable result. The workflow has already
|
|
49
|
+
* ended, so even an infrastructure failure closes the Run without auto-retry.
|
|
50
|
+
* The runtime must first translate its completion into a typed result; defects
|
|
51
|
+
* and suspension are not Attempt outcomes here (ADRs 0003 and 0010).
|
|
52
|
+
*/
|
|
53
|
+
export const reconcileAttempt = (current, result) => {
|
|
54
|
+
const attempt = openAttempt(current);
|
|
55
|
+
return Option.isNone(attempt)
|
|
56
|
+
? { _tag: "Unchanged", reason: "NoOpenAttempt" }
|
|
57
|
+
: finish(current, attempt.value.id, result, "FinalReconciliation");
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Admits the next Attempt after a Worker reservation. An unfinished previous
|
|
61
|
+
* Attempt indicates a restart and counts against the same retry cap as ordinary
|
|
62
|
+
* infrastructure failure. `interruption` records the runtime's explanation.
|
|
63
|
+
* The caller creates the new Attempt's identity and timestamp only when admitted.
|
|
64
|
+
*/
|
|
65
|
+
export const beginAttempt = (current, interruption) => {
|
|
66
|
+
const state = current.run.state;
|
|
67
|
+
if (!RunState.isStartable(state) && state._tag !== "Running") {
|
|
68
|
+
return { _tag: "RunClosed", state };
|
|
69
|
+
}
|
|
70
|
+
let interrupted = Option.none();
|
|
71
|
+
const attempt = openAttempt(current);
|
|
72
|
+
if (state._tag === "Running" && Option.isSome(attempt)) {
|
|
73
|
+
const recovery = failRunningAttempt(state, attempt.value, interruption, "Execution");
|
|
74
|
+
if (recovery._tag === "RunFailed")
|
|
75
|
+
return recovery;
|
|
76
|
+
interrupted = Option.some(recovery);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
_tag: "StartAttempt",
|
|
80
|
+
state: state._tag === "Running" ? state : RunState.start(state),
|
|
81
|
+
number: AttemptNumber.make((current.attempts.at(-1)?.number ?? 0) + 1),
|
|
82
|
+
interrupted,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Cancels open work and, if executing, its unfinished Attempt. A Run awaiting
|
|
87
|
+
* capacity may have no Attempt, or only the closed Attempt preceding a retry.
|
|
88
|
+
*/
|
|
89
|
+
export const cancelRun = (current) => {
|
|
90
|
+
if (!RunState.isOpen(current.run.state))
|
|
91
|
+
return { _tag: "AlreadyClosed" };
|
|
92
|
+
return {
|
|
93
|
+
_tag: "Canceled",
|
|
94
|
+
state: RunState.cancelByOperator(current.run.state),
|
|
95
|
+
attempt: current.run.state._tag === "Running"
|
|
96
|
+
? Option.map(openAttempt(current), (attempt) => ({
|
|
97
|
+
id: attempt.id,
|
|
98
|
+
outcome: new AttemptCanceled(),
|
|
99
|
+
}))
|
|
100
|
+
: Option.none(),
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Reopens a failed Run for operator retry regardless of its Attempt count.
|
|
105
|
+
* Repeating the request is accepted while its Resume command remains pending;
|
|
106
|
+
* after delivery, retrying a Running Run is rejected.
|
|
107
|
+
*/
|
|
108
|
+
export const retryRun = (state, pendingCommands) => {
|
|
109
|
+
if (state._tag === "Failed")
|
|
110
|
+
return { _tag: "Resume", state: RunState.retry(state) };
|
|
111
|
+
if (state._tag === "Running" && pendingCommands.includes("Resume")) {
|
|
112
|
+
return { _tag: "ResumePending" };
|
|
113
|
+
}
|
|
114
|
+
return { _tag: "RetryRejected" };
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Places a previously unclaimed Event behind its Item's running work, or
|
|
118
|
+
* replaces unstarted work. The ledger must resolve permanent deduplication and
|
|
119
|
+
* ignored Events before this decision; running Attempts always finish (ADR 0007).
|
|
120
|
+
*/
|
|
121
|
+
export const claimRun = (blocking, eventId) => {
|
|
122
|
+
if (Option.isNone(blocking))
|
|
123
|
+
return { _tag: "OpenRun" };
|
|
124
|
+
const run = blocking.value;
|
|
125
|
+
if (run.state._tag === "Running")
|
|
126
|
+
return { _tag: "QueueEvent" };
|
|
127
|
+
if (RunState.isUnstarted(run.state)) {
|
|
128
|
+
return { _tag: "SupersedeRun", runId: run.id, state: RunState.supersede(run.state, eventId) };
|
|
129
|
+
}
|
|
130
|
+
return { _tag: "OpenRun" };
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/engine/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE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E,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;IACrF,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;IACnC,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AACnC,CAAC,CAAC;AAOF;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,QAA4B,EAAE,OAAgB,EAAiB,EAAE;IACxF,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC3B,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAChE,IAAI,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACpC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;IAChG,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context, Deferred } from "effect";
|
|
2
|
+
declare const RunEngineShutdown_base: Context.ServiceClass<RunEngineShutdown, "@usine/engine/RunEngineShutdown", Deferred.Deferred<void, never>>;
|
|
3
|
+
/**
|
|
4
|
+
* Optional host-owned shutdown latch, provided before building an engine runtime.
|
|
5
|
+
* Completing it closes Attempt admission even while startup recovery is running.
|
|
6
|
+
* After startup, RunEngine.drain waits for admitted Attempts to persist their outcomes.
|
|
7
|
+
* Allocate a fresh latch for each runtime; it cannot be reopened (ADR 0023).
|
|
8
|
+
*/
|
|
9
|
+
export declare class RunEngineShutdown extends RunEngineShutdown_base {
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../src/engine/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;;AAE3C;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,sBAGD;CAAG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, Deferred } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* Optional host-owned shutdown latch, provided before building an engine runtime.
|
|
4
|
+
* Completing it closes Attempt admission even while startup recovery is running.
|
|
5
|
+
* After startup, RunEngine.drain waits for admitted Attempts to persist their outcomes.
|
|
6
|
+
* Allocate a fresh latch for each runtime; it cannot be reopened (ADR 0023).
|
|
7
|
+
*/
|
|
8
|
+
export class RunEngineShutdown extends Context.Service()("@usine/engine/RunEngineShutdown") {
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../src/engine/shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,OAAO,CAAC,OAAO,EAGnD,CAAC,iCAAiC,CAAC;CAAG"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Agent } from "@usine/core/agent";
|
|
2
|
+
import { CycleBudgetAsk } from "@usine/core/cycle-budget";
|
|
3
|
+
import { Event } from "@usine/core/event";
|
|
4
|
+
import { Schema } from "effect";
|
|
5
|
+
declare const Submission_base: Schema.Class<Submission, Schema.Struct<{
|
|
6
|
+
readonly event: typeof Event;
|
|
7
|
+
readonly itemKey: Schema.brand<Schema.NonEmptyString, "ItemKey">;
|
|
8
|
+
readonly loop: Schema.brand<Schema.NonEmptyString, "LoopName">;
|
|
9
|
+
readonly step: Schema.brand<Schema.NonEmptyString, "StepName">;
|
|
10
|
+
readonly approval: Schema.Literals<readonly ["none", "required"]>;
|
|
11
|
+
/** Item Runs default to three rounds; schedule adapters explicitly supply None. */
|
|
12
|
+
readonly cycleLimit: Schema.withConstructorDefault<Schema.withDecodingDefaultTypeKey<Schema.Option<Schema.brand<Schema.Int, "CycleLimit">>, never>>;
|
|
13
|
+
/** Capture before fetching trigger input. A reset supersedes older observations. */
|
|
14
|
+
readonly cycleGeneration: Schema.withConstructorDefault<Schema.withDecodingDefaultKey<Schema.brand<Schema.Int, "CycleGeneration">, never>>;
|
|
15
|
+
readonly repository: Schema.brand<Schema.String, "RepositoryName">;
|
|
16
|
+
readonly revision: Schema.brand<Schema.String, "RepositoryRevision">;
|
|
17
|
+
readonly task: Schema.brand<Schema.String, "AttemptTask">;
|
|
18
|
+
readonly agent: typeof Agent;
|
|
19
|
+
readonly parentModel: Schema.Option<Schema.brand<Schema.String, "ModelId">>;
|
|
20
|
+
}>, {}>;
|
|
21
|
+
/** A matched Event with the Loop, Item, and execution choices that determine the work owed. */
|
|
22
|
+
export declare class Submission extends Submission_base {
|
|
23
|
+
}
|
|
24
|
+
declare const Claimed_base: Schema.Class<Claimed, Schema.TaggedStruct<"Claimed", {
|
|
25
|
+
readonly eventId: Schema.brand<Schema.NonEmptyString, "EventId">;
|
|
26
|
+
readonly runId: Schema.brand<Schema.NonEmptyString, "RunId">;
|
|
27
|
+
}>, {}>;
|
|
28
|
+
/** The Event now owns a Run; submitting it again returns the same run id. */
|
|
29
|
+
export declare class Claimed extends Claimed_base {
|
|
30
|
+
}
|
|
31
|
+
declare const Queued_base: Schema.Class<Queued, Schema.TaggedStruct<"Queued", {
|
|
32
|
+
readonly eventId: Schema.brand<Schema.NonEmptyString, "EventId">;
|
|
33
|
+
}>, {}>;
|
|
34
|
+
/** A running Attempt on the same Item must finish before this Event is reconsidered. */
|
|
35
|
+
export declare class Queued extends Queued_base {
|
|
36
|
+
}
|
|
37
|
+
export declare const IGNORED_REASONS: readonly ["superseded", "revoked"];
|
|
38
|
+
export declare const IgnoreReason: Schema.Literals<readonly ["superseded", "revoked"]>;
|
|
39
|
+
export type IgnoreReason = typeof IgnoreReason.Type;
|
|
40
|
+
declare const Ignored_base: Schema.Class<Ignored, Schema.TaggedStruct<"Ignored", {
|
|
41
|
+
readonly eventId: Schema.brand<Schema.NonEmptyString, "EventId">;
|
|
42
|
+
readonly reason: Schema.Literals<readonly ["superseded", "revoked"]>;
|
|
43
|
+
}>, {}>;
|
|
44
|
+
/** The Event stays in the ledger but can no longer open a Run. */
|
|
45
|
+
export declare class Ignored extends Ignored_base {
|
|
46
|
+
}
|
|
47
|
+
declare const CycleBlocked_base: Schema.Class<CycleBlocked, Schema.TaggedStruct<"CycleBlocked", {
|
|
48
|
+
readonly eventId: Schema.brand<Schema.NonEmptyString, "EventId">;
|
|
49
|
+
readonly ask: typeof CycleBudgetAsk;
|
|
50
|
+
}>, {}>;
|
|
51
|
+
/** No Run opened because this Item requires an explicit cycle-budget reset. */
|
|
52
|
+
export declare class CycleBlocked extends CycleBlocked_base {
|
|
53
|
+
}
|
|
54
|
+
/** Whether a recorded Event owns a Run, waits behind running work, or can no longer open a Run. */
|
|
55
|
+
export declare const SubmissionResult: Schema.Union<readonly [typeof Claimed, typeof Queued, typeof Ignored, typeof CycleBlocked]>;
|
|
56
|
+
export type SubmissionResult = typeof SubmissionResult.Type;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=submission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submission.d.ts","sourceRoot":"","sources":["../../src/engine/submission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EACL,cAAc,EAIf,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,KAAK,EAAW,MAAM,mBAAmB,CAAC;AAMnD,OAAO,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;;IAS9C,mFAAmF;;IAKnF,oFAAoF;;;;;;;;AAZtF,+FAA+F;AAC/F,qBAAa,UAAW,SAAQ,eAqB9B;CAAG;;;;;AAEL,6EAA6E;AAC7E,qBAAa,OAAQ,SAAQ,YAG3B;CAAG;;;;AAEL,wFAAwF;AACxF,qBAAa,MAAO,SAAQ,WAE1B;CAAG;AAEL,eAAO,MAAM,eAAe,YAAI,YAAY,EAAE,SAAS,CAAU,CAAC;AAElE,eAAO,MAAM,YAAY,qDAAmC,CAAC;AAE7D,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;;;;;AAEpD,kEAAkE;AAClE,qBAAa,OAAQ,SAAQ,YAG3B;CAAG;;;;;AAEL,+EAA+E;AAC/E,qBAAa,YAAa,SAAQ,iBAGjC;CAAG;AAEJ,mGAAmG;AACnG,eAAO,MAAM,gBAAgB,6FAAyD,CAAC;AAEvF,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Agent } from "@usine/core/agent";
|
|
2
|
+
import { CycleBudgetAsk, CycleGeneration, CycleLimit, DEFAULT_CYCLE_LIMIT, } from "@usine/core/cycle-budget";
|
|
3
|
+
import { ModelId } from "@usine/core/agent/brain";
|
|
4
|
+
import { AttemptTask } from "@usine/core/attempt";
|
|
5
|
+
import { Event, EventId } from "@usine/core/event";
|
|
6
|
+
import { ItemKey } from "@usine/core/item";
|
|
7
|
+
import { LoopName, ApprovalRequirement } from "@usine/core/loop";
|
|
8
|
+
import { RepositoryName, RepositoryRevision } from "@usine/core/repository";
|
|
9
|
+
import { RunId } from "@usine/core/run";
|
|
10
|
+
import { StepName } from "@usine/core/step";
|
|
11
|
+
import { Effect, Option, Schema } from "effect";
|
|
12
|
+
/** A matched Event with the Loop, Item, and execution choices that determine the work owed. */
|
|
13
|
+
export class Submission extends Schema.Class("@usine/engine/Submission")({
|
|
14
|
+
event: Event,
|
|
15
|
+
itemKey: ItemKey,
|
|
16
|
+
loop: LoopName,
|
|
17
|
+
step: StepName,
|
|
18
|
+
approval: ApprovalRequirement,
|
|
19
|
+
/** Item Runs default to three rounds; schedule adapters explicitly supply None. */
|
|
20
|
+
cycleLimit: Schema.Option(CycleLimit).pipe(Schema.withDecodingDefaultTypeKey(Effect.succeed(Option.some(DEFAULT_CYCLE_LIMIT))), Schema.withConstructorDefault(Effect.succeed(Option.some(DEFAULT_CYCLE_LIMIT)))),
|
|
21
|
+
/** Capture before fetching trigger input. A reset supersedes older observations. */
|
|
22
|
+
cycleGeneration: CycleGeneration.pipe(Schema.withDecodingDefaultKey(Effect.succeed(CycleGeneration.make(0))), Schema.withConstructorDefault(Effect.succeed(CycleGeneration.make(0)))),
|
|
23
|
+
repository: RepositoryName,
|
|
24
|
+
revision: RepositoryRevision,
|
|
25
|
+
task: AttemptTask,
|
|
26
|
+
agent: Agent,
|
|
27
|
+
parentModel: Schema.Option(ModelId),
|
|
28
|
+
}) {
|
|
29
|
+
}
|
|
30
|
+
/** The Event now owns a Run; submitting it again returns the same run id. */
|
|
31
|
+
export class Claimed extends Schema.TaggedClass("@usine/engine/Claimed")("Claimed", {
|
|
32
|
+
eventId: EventId,
|
|
33
|
+
runId: RunId,
|
|
34
|
+
}) {
|
|
35
|
+
}
|
|
36
|
+
/** A running Attempt on the same Item must finish before this Event is reconsidered. */
|
|
37
|
+
export class Queued extends Schema.TaggedClass("@usine/engine/Queued")("Queued", {
|
|
38
|
+
eventId: EventId,
|
|
39
|
+
}) {
|
|
40
|
+
}
|
|
41
|
+
export const IGNORED_REASONS = ["superseded", "revoked"];
|
|
42
|
+
export const IgnoreReason = Schema.Literals(IGNORED_REASONS);
|
|
43
|
+
/** The Event stays in the ledger but can no longer open a Run. */
|
|
44
|
+
export class Ignored extends Schema.TaggedClass("@usine/engine/Ignored")("Ignored", {
|
|
45
|
+
eventId: EventId,
|
|
46
|
+
reason: IgnoreReason,
|
|
47
|
+
}) {
|
|
48
|
+
}
|
|
49
|
+
/** No Run opened because this Item requires an explicit cycle-budget reset. */
|
|
50
|
+
export class CycleBlocked extends Schema.TaggedClass("@usine/engine/CycleBlocked")("CycleBlocked", { eventId: EventId, ask: CycleBudgetAsk }) {
|
|
51
|
+
}
|
|
52
|
+
/** Whether a recorded Event owns a Run, waits behind running work, or can no longer open a Run. */
|
|
53
|
+
export const SubmissionResult = Schema.Union([Claimed, Queued, Ignored, CycleBlocked]);
|
|
54
|
+
//# sourceMappingURL=submission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"submission.js","sourceRoot":"","sources":["../../src/engine/submission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EACL,cAAc,EACd,eAAe,EACf,UAAU,EACV,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;A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AK;CACb,CAAC;CAAG;AAEL,wFAAwF;AACxF,MAAM,OAAO,MAAO,SAAQ,MAAM,CAAC,WAAW,CAAS,sBAAsB,CAAC,CAAC,QAAQ,EAAE;IACvF,OAAO,EAAE,OAAO;CACjB,CAAC;CAAG;AAEL,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,YAAY,EAAE,SAAS,CAAU,CAAC;AAElE,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;AAI7D,kEAAkE;AAClE,MAAM,OAAO,OAAQ,SAAQ,MAAM,CAAC,WAAW,CAAU,uBAAuB,CAAC,CAAC,SAAS,EAAE;IAC3F,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,YAAY;CACrB,CAAC;CAAG;AAEL,+EAA+E;AAC/E,MAAM,OAAO,YAAa,SAAQ,MAAM,CAAC,WAAW,CAAe,4BAA4B,CAAC,CAC9F,cAAc,EACd,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,CAC1C;CAAG;AAEJ,mGAAmG;AACnG,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RepositoryName } from "@usine/core/repository";
|
|
2
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
|
+
import { RunDatabase } from "../database/database.ts";
|
|
4
|
+
import { EnginePersistenceError } from "../engine/error.ts";
|
|
5
|
+
import { ItemProjection } from "./model.ts";
|
|
6
|
+
/** Newest Items first. The bound keeps a long-lived repository's Board response finite. */
|
|
7
|
+
export interface ItemProjectionListOptions {
|
|
8
|
+
readonly limit: number;
|
|
9
|
+
}
|
|
10
|
+
declare const ItemProjectionReader_base: Context.ServiceClass<ItemProjectionReader, "@usine/engine/ItemProjectionReader", {
|
|
11
|
+
/** The newest `limit` Item projections of one repository, highest number first. */
|
|
12
|
+
readonly list: (repository: RepositoryName, options: ItemProjectionListOptions) => Effect.Effect<ReadonlyArray<ItemProjection>, EnginePersistenceError>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare class ItemProjectionReader extends ItemProjectionReader_base {
|
|
15
|
+
static readonly layer: Layer.Layer<ItemProjectionReader, never, RunDatabase>;
|
|
16
|
+
}
|
|
17
|
+
declare const ItemProjectionWriter_base: Context.ServiceClass<ItemProjectionWriter, "@usine/engine/ItemProjectionWriter", {
|
|
18
|
+
/** `true` means the durable projection changed. */
|
|
19
|
+
readonly upsert: (item: ItemProjection) => Effect.Effect<boolean, EnginePersistenceError>;
|
|
20
|
+
}>;
|
|
21
|
+
export declare class ItemProjectionWriter extends ItemProjectionWriter_base {
|
|
22
|
+
static readonly layer: Layer.Layer<ItemProjectionWriter, never, RunDatabase>;
|
|
23
|
+
}
|
|
24
|
+
export { ItemContentHash, ItemProjection, ItemProjectionSource } from "./model.ts";
|
|
25
|
+
//# sourceMappingURL=item-projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-projection.d.ts","sourceRoot":"","sources":["../../src/item-projection/item-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAmB,cAAc,EAAwB,MAAM,YAAY,CAAC;AAmBnF,2FAA2F;AAC3F,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;;IAqFG,mFAAmF;mBACpE,CACb,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,yBAAyB,KAC/B,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,sBAAsB,CAAC;;AAP7E,qBAAa,oBAAqB,SAAQ,yBASD;IACvC,MAAM,CAAC,QAAQ,CAAC,KAAK,wDAAkD;CACxE;;IAKG,mDAAmD;qBAClC,CAAC,IAAI,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,sBAAsB,CAAC;;AAJ7F,qBAAa,oBAAqB,SAAQ,yBAMD;IACvC,MAAM,CAAC,QAAQ,CAAC,KAAK,wDAAkD;CACxE;AAED,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { RepositoryName } from "@usine/core/repository";
|
|
2
|
+
import { desc, eq, ne } from "drizzle-orm";
|
|
3
|
+
import { Context, Effect, Layer, Schema } from "effect";
|
|
4
|
+
import { RunDatabase } from "../database/database.js";
|
|
5
|
+
import { itemProjections } from "../database/schema.js";
|
|
6
|
+
import { EnginePersistenceError } from "../engine/error.js";
|
|
7
|
+
import { ItemNumber } from "@usine/core/item";
|
|
8
|
+
import { ItemContentHash, ItemProjection, ItemProjectionSource } from "./model.js";
|
|
9
|
+
const ItemProjectionRow = Schema.Struct({
|
|
10
|
+
itemKey: ItemProjection.fields.itemKey,
|
|
11
|
+
repository: RepositoryName,
|
|
12
|
+
source: ItemProjectionSource,
|
|
13
|
+
number: ItemNumber,
|
|
14
|
+
contentHash: ItemContentHash,
|
|
15
|
+
payload: Schema.JsonObject,
|
|
16
|
+
});
|
|
17
|
+
const decodeRows = Schema.decodeUnknownEffect(Schema.Array(ItemProjectionRow));
|
|
18
|
+
const encodePayload = Schema.encodeSync(Schema.JsonObject);
|
|
19
|
+
const persistence = (operation) => (effect) => Effect.mapError(effect, (cause) => new EnginePersistenceError({ operation, cause }));
|
|
20
|
+
const makeReader = Effect.gen(function* () {
|
|
21
|
+
const database = yield* RunDatabase;
|
|
22
|
+
return {
|
|
23
|
+
list: Effect.fn("ItemProjectionReader.list")(function* (repository, options) {
|
|
24
|
+
yield* Effect.annotateCurrentSpan({ repository, limit: options.limit });
|
|
25
|
+
const rows = yield* database
|
|
26
|
+
.select({
|
|
27
|
+
itemKey: itemProjections.itemKey,
|
|
28
|
+
repository: itemProjections.repository,
|
|
29
|
+
source: itemProjections.source,
|
|
30
|
+
number: itemProjections.itemNumber,
|
|
31
|
+
contentHash: itemProjections.contentHash,
|
|
32
|
+
payload: itemProjections.payloadJson,
|
|
33
|
+
})
|
|
34
|
+
.from(itemProjections)
|
|
35
|
+
.where(eq(itemProjections.repository, repository))
|
|
36
|
+
.orderBy(desc(itemProjections.itemNumber))
|
|
37
|
+
.limit(options.limit)
|
|
38
|
+
.execute();
|
|
39
|
+
return (yield* decodeRows(rows, { onExcessProperty: "error" })).map((row) => new ItemProjection(row));
|
|
40
|
+
}, persistence("list Item projections")),
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
const makeWriter = Effect.gen(function* () {
|
|
44
|
+
const database = yield* RunDatabase;
|
|
45
|
+
return {
|
|
46
|
+
upsert: Effect.fn("ItemProjectionWriter.upsert")(function* (item) {
|
|
47
|
+
yield* Effect.annotateCurrentSpan({
|
|
48
|
+
repository: item.repository,
|
|
49
|
+
item: item.number,
|
|
50
|
+
itemKey: item.itemKey,
|
|
51
|
+
});
|
|
52
|
+
const changed = yield* database
|
|
53
|
+
.insert(itemProjections)
|
|
54
|
+
.values({
|
|
55
|
+
itemKey: item.itemKey,
|
|
56
|
+
repository: item.repository,
|
|
57
|
+
source: item.source,
|
|
58
|
+
itemNumber: item.number,
|
|
59
|
+
contentHash: item.contentHash,
|
|
60
|
+
payloadJson: encodePayload(item.payload),
|
|
61
|
+
})
|
|
62
|
+
.onConflictDoUpdate({
|
|
63
|
+
target: itemProjections.itemKey,
|
|
64
|
+
set: {
|
|
65
|
+
repository: item.repository,
|
|
66
|
+
source: item.source,
|
|
67
|
+
itemNumber: item.number,
|
|
68
|
+
contentHash: item.contentHash,
|
|
69
|
+
payloadJson: encodePayload(item.payload),
|
|
70
|
+
},
|
|
71
|
+
setWhere: ne(itemProjections.contentHash, item.contentHash),
|
|
72
|
+
})
|
|
73
|
+
.returning({ itemKey: itemProjections.itemKey })
|
|
74
|
+
.execute();
|
|
75
|
+
if (changed.length === 0) {
|
|
76
|
+
yield* Effect.logDebug("Item projection already matched the observed snapshot", {
|
|
77
|
+
repository: item.repository,
|
|
78
|
+
item: item.number,
|
|
79
|
+
contentHash: item.contentHash,
|
|
80
|
+
});
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
yield* Effect.logDebug("Item projection updated from trigger polling", {
|
|
84
|
+
repository: item.repository,
|
|
85
|
+
item: item.number,
|
|
86
|
+
source: item.source,
|
|
87
|
+
contentHash: item.contentHash,
|
|
88
|
+
});
|
|
89
|
+
return true;
|
|
90
|
+
}, persistence("write Item projection")),
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
export class ItemProjectionReader extends Context.Service()("@usine/engine/ItemProjectionReader") {
|
|
94
|
+
static layer = Layer.effect(ItemProjectionReader, makeReader);
|
|
95
|
+
}
|
|
96
|
+
export class ItemProjectionWriter extends Context.Service()("@usine/engine/ItemProjectionWriter") {
|
|
97
|
+
static layer = Layer.effect(ItemProjectionWriter, makeWriter);
|
|
98
|
+
}
|
|
99
|
+
export { ItemContentHash, ItemProjection, ItemProjectionSource } from "./model.js";
|
|
100
|
+
//# sourceMappingURL=item-projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-projection.js","sourceRoot":"","sources":["../../src/item-projection/item-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,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AAC,8CAA8C,EAAE;gBACrE,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,IAAI,EAAE,IAAI,CAAC,MAAM;gBACjB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC,EAAE,WAAW,CAAC,uBAAuB,CAAC,CAAC;KAChC,CAAC;AACb,CAAC,CAAC,CAAC;AAEH,MAAM,OAAO,oBAAqB,SAAQ,OAAO,CAAC,OAAO,EAStD,CAAC,oCAAoC,CAAC;IACvC,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;CACxE;AAED,MAAM,OAAO,oBAAqB,SAAQ,OAAO,CAAC,OAAO,EAMtD,CAAC,oCAAoC,CAAC;IACvC,MAAM,CAAU,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;CACxE;AAED,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const ItemProjectionSource: Schema.brand<Schema.NonEmptyString, "ItemProjectionSource">;
|
|
3
|
+
export type ItemProjectionSource = typeof ItemProjectionSource.Type;
|
|
4
|
+
export declare const ItemContentHash: Schema.brand<Schema.NonEmptyString, "ItemContentHash">;
|
|
5
|
+
export type ItemContentHash = typeof ItemContentHash.Type;
|
|
6
|
+
declare const ItemProjection_base: Schema.Class<ItemProjection, Schema.Struct<{
|
|
7
|
+
readonly itemKey: Schema.brand<Schema.NonEmptyString, "ItemKey">;
|
|
8
|
+
readonly repository: Schema.brand<Schema.String, "RepositoryName">;
|
|
9
|
+
readonly source: Schema.brand<Schema.NonEmptyString, "ItemProjectionSource">;
|
|
10
|
+
readonly number: Schema.brand<Schema.Int, "ItemNumber">;
|
|
11
|
+
readonly contentHash: Schema.brand<Schema.NonEmptyString, "ItemContentHash">;
|
|
12
|
+
readonly payload: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
13
|
+
}>, {}>;
|
|
14
|
+
/** The latest payload a trigger observed for one Item, whatever the source adapter. */
|
|
15
|
+
export declare class ItemProjection extends ItemProjection_base {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/item-projection/model.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,oBAAoB,6DAEhC,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,OAAO,oBAAoB,CAAC,IAAI,CAAC;AAEpE,eAAO,MAAM,eAAe,wDAA8D,CAAC;AAC3F,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,IAAI,CAAC;;;;;;;;;AAE1D,uFAAuF;AACvF,qBAAa,cAAe,SAAQ,mBAOlC;CAAG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ItemKey, ItemNumber } from "@usine/core/item";
|
|
2
|
+
import { RepositoryName } from "@usine/core/repository";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
export const ItemProjectionSource = Schema.NonEmptyString.pipe(Schema.brand("ItemProjectionSource"));
|
|
5
|
+
export const ItemContentHash = Schema.NonEmptyString.pipe(Schema.brand("ItemContentHash"));
|
|
6
|
+
/** The latest payload a trigger observed for one Item, whatever the source adapter. */
|
|
7
|
+
export class ItemProjection extends Schema.Class("@usine/engine/ItemProjection")({
|
|
8
|
+
itemKey: ItemKey,
|
|
9
|
+
repository: RepositoryName,
|
|
10
|
+
source: ItemProjectionSource,
|
|
11
|
+
number: ItemNumber,
|
|
12
|
+
contentHash: ItemContentHash,
|
|
13
|
+
payload: Schema.JsonObject,
|
|
14
|
+
}) {
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/item-projection/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAC5D,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CACrC,CAAC;AAGF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAG3F,uFAAuF;AACvF,MAAM,OAAO,cAAe,SAAQ,MAAM,CAAC,KAAK,CAAiB,8BAA8B,CAAC,CAAC;IAC/F,OAAO,EAAE,OAAO;IAChB,UAAU,EAAE,cAAc;IAC1B,MAAM,EAAE,oBAAoB;IAC5B,MAAM,EAAE,UAAU;IAClB,WAAW,EAAE,eAAe;IAC5B,OAAO,EAAE,MAAM,CAAC,UAAU;CAC3B,CAAC;CAAG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LoopName } from "@usine/core/loop";
|
|
2
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
|
+
import { RunDatabase } from "../database/database.ts";
|
|
4
|
+
import { EnginePersistenceError } from "../engine/error.ts";
|
|
5
|
+
import { LoopRuntimeState } from "./model.ts";
|
|
6
|
+
declare const LoopControl_base: Context.ServiceClass<LoopControl, "@usine/engine/LoopControl", {
|
|
7
|
+
/** Whether new Runs are paused; a Loop with no recorded runtime state is unpaused. */
|
|
8
|
+
readonly isPaused: (loop: LoopName) => Effect.Effect<boolean, EnginePersistenceError>;
|
|
9
|
+
/** Pauses new trigger work for this Loop without stopping its existing Runs. */
|
|
10
|
+
readonly pause: (loop: LoopName) => Effect.Effect<LoopRuntimeState, EnginePersistenceError>;
|
|
11
|
+
/** Recorded runtime states ordered by Loop name; Loops without stored state are omitted. */
|
|
12
|
+
readonly states: Effect.Effect<ReadonlyArray<LoopRuntimeState>, EnginePersistenceError>;
|
|
13
|
+
/** Allows triggers to open new Runs for this Loop again. */
|
|
14
|
+
readonly unpause: (loop: LoopName) => Effect.Effect<LoopRuntimeState, EnginePersistenceError>;
|
|
15
|
+
}>;
|
|
16
|
+
/** Records whether triggers may open new Runs for each Loop; existing Runs and authored files stay unchanged. */
|
|
17
|
+
export declare class LoopControl extends LoopControl_base {
|
|
18
|
+
static readonly layer: Layer.Layer<LoopControl, never, RunDatabase>;
|
|
19
|
+
}
|
|
20
|
+
export { LoopRuntimeState } from "./model.ts";
|
|
21
|
+
//# sourceMappingURL=loop-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-control.d.ts","sourceRoot":"","sources":["../../src/loop-control/loop-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;;IA6E1C,sFAAsF;uBACnE,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,sBAAsB,CAAC;IACrF,gFAAgF;oBAChE,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,sBAAsB,CAAC;IAC3F,4FAA4F;qBAC3E,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IACvF,4DAA4D;sBAC1C,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,sBAAsB,CAAC;;AAXjG,iHAAiH;AACjH,qBAAa,WAAY,SAAQ,gBAYD;IAC9B,MAAM,CAAC,QAAQ,CAAC,KAAK,+CAA8C;CACpE;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
|