adispatchd 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +195 -2
- package/dist/api/errors.d.ts +27 -0
- package/dist/api/errors.js +80 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/api/index.js +11 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/logs.d.ts +30 -0
- package/dist/api/logs.js +88 -0
- package/dist/api/logs.js.map +1 -0
- package/dist/api/serialize.d.ts +65 -0
- package/dist/api/serialize.js +135 -0
- package/dist/api/serialize.js.map +1 -0
- package/dist/api/server.d.ts +89 -0
- package/dist/api/server.js +751 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/sse.d.ts +90 -0
- package/dist/api/sse.js +225 -0
- package/dist/api/sse.js.map +1 -0
- package/dist/app.d.ts +173 -0
- package/dist/app.js +488 -0
- package/dist/app.js.map +1 -0
- package/dist/cli/config-validate.d.ts +6 -0
- package/dist/cli/config-validate.js +39 -0
- package/dist/cli/config-validate.js.map +1 -0
- package/dist/cli/control.d.ts +31 -0
- package/dist/cli/control.js +186 -0
- package/dist/cli/control.js.map +1 -0
- package/dist/cli/http-client.d.ts +57 -0
- package/dist/cli/http-client.js +174 -0
- package/dist/cli/http-client.js.map +1 -0
- package/dist/cli/index.d.ts +14 -0
- package/dist/cli/index.js +14 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init-templates.d.ts +20 -0
- package/dist/cli/init-templates.js +275 -0
- package/dist/cli/init-templates.js.map +1 -0
- package/dist/cli/init.d.ts +16 -0
- package/dist/cli/init.js +107 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +25 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/program.d.ts +102 -0
- package/dist/cli/program.js +133 -0
- package/dist/cli/program.js.map +1 -0
- package/dist/cli/service.d.ts +27 -0
- package/dist/cli/service.js +252 -0
- package/dist/cli/service.js.map +1 -0
- package/dist/cli/start.d.ts +22 -0
- package/dist/cli/start.js +133 -0
- package/dist/cli/start.js.map +1 -0
- package/dist/cli/workflow-dry-run.d.ts +13 -0
- package/dist/cli/workflow-dry-run.js +144 -0
- package/dist/cli/workflow-dry-run.js.map +1 -0
- package/dist/config/field-catalog.d.ts +33 -0
- package/dist/config/field-catalog.js +172 -0
- package/dist/config/field-catalog.js.map +1 -0
- package/dist/config/filter-schema.d.ts +15 -0
- package/dist/config/filter-schema.js +110 -0
- package/dist/config/filter-schema.js.map +1 -0
- package/dist/config/index.d.ts +15 -0
- package/dist/config/index.js +16 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/issues.d.ts +27 -0
- package/dist/config/issues.js +37 -0
- package/dist/config/issues.js.map +1 -0
- package/dist/config/loader.d.ts +32 -0
- package/dist/config/loader.js +250 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/manager.d.ts +153 -0
- package/dist/config/manager.js +276 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/model.d.ts +334 -0
- package/dist/config/model.js +2 -0
- package/dist/config/model.js.map +1 -0
- package/dist/config/normalize.d.ts +20 -0
- package/dist/config/normalize.js +200 -0
- package/dist/config/normalize.js.map +1 -0
- package/dist/config/parameters.d.ts +37 -0
- package/dist/config/parameters.js +71 -0
- package/dist/config/parameters.js.map +1 -0
- package/dist/config/public.d.ts +6 -0
- package/dist/config/public.js +18 -0
- package/dist/config/public.js.map +1 -0
- package/dist/config/schemas.d.ts +538 -0
- package/dist/config/schemas.js +321 -0
- package/dist/config/schemas.js.map +1 -0
- package/dist/config/snapshot.d.ts +38 -0
- package/dist/config/snapshot.js +57 -0
- package/dist/config/snapshot.js.map +1 -0
- package/dist/config/validate.d.ts +33 -0
- package/dist/config/validate.js +346 -0
- package/dist/config/validate.js.map +1 -0
- package/dist/core/clock.d.ts +59 -0
- package/dist/core/clock.js +133 -0
- package/dist/core/clock.js.map +1 -0
- package/dist/core/duration.d.ts +19 -0
- package/dist/core/duration.js +93 -0
- package/dist/core/duration.js.map +1 -0
- package/dist/core/errors.d.ts +62 -0
- package/dist/core/errors.js +72 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/ids.d.ts +57 -0
- package/dist/core/ids.js +88 -0
- package/dist/core/ids.js.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +14 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +100 -0
- package/dist/core/logger.js +207 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/paths.d.ts +84 -0
- package/dist/core/paths.js +138 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/template.d.ts +136 -0
- package/dist/core/template.js +261 -0
- package/dist/core/template.js.map +1 -0
- package/dist/core/types.d.ts +544 -0
- package/dist/core/types.js +172 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/worker-protocol.d.ts +102 -0
- package/dist/core/worker-protocol.js +75 -0
- package/dist/core/worker-protocol.js.map +1 -0
- package/dist/executors/classify.d.ts +25 -0
- package/dist/executors/classify.js +54 -0
- package/dist/executors/classify.js.map +1 -0
- package/dist/executors/dispatcher.d.ts +35 -0
- package/dist/executors/dispatcher.js +68 -0
- package/dist/executors/dispatcher.js.map +1 -0
- package/dist/executors/env.d.ts +43 -0
- package/dist/executors/env.js +66 -0
- package/dist/executors/env.js.map +1 -0
- package/dist/executors/event-parser.d.ts +41 -0
- package/dist/executors/event-parser.js +106 -0
- package/dist/executors/event-parser.js.map +1 -0
- package/dist/executors/index.d.ts +12 -0
- package/dist/executors/index.js +13 -0
- package/dist/executors/index.js.map +1 -0
- package/dist/executors/log-capture.d.ts +57 -0
- package/dist/executors/log-capture.js +155 -0
- package/dist/executors/log-capture.js.map +1 -0
- package/dist/executors/process-identity.d.ts +124 -0
- package/dist/executors/process-identity.js +283 -0
- package/dist/executors/process-identity.js.map +1 -0
- package/dist/executors/shell-executor.d.ts +35 -0
- package/dist/executors/shell-executor.js +478 -0
- package/dist/executors/shell-executor.js.map +1 -0
- package/dist/executors/stream-redactor.d.ts +40 -0
- package/dist/executors/stream-redactor.js +89 -0
- package/dist/executors/stream-redactor.js.map +1 -0
- package/dist/executors/workspace.d.ts +10 -0
- package/dist/executors/workspace.js +47 -0
- package/dist/executors/workspace.js.map +1 -0
- package/dist/filters/evaluate.d.ts +77 -0
- package/dist/filters/evaluate.js +187 -0
- package/dist/filters/evaluate.js.map +1 -0
- package/dist/filters/fields.d.ts +35 -0
- package/dist/filters/fields.js +75 -0
- package/dist/filters/fields.js.map +1 -0
- package/dist/filters/index.d.ts +11 -0
- package/dist/filters/index.js +12 -0
- package/dist/filters/index.js.map +1 -0
- package/dist/filters/iso-date.d.ts +10 -0
- package/dist/filters/iso-date.js +42 -0
- package/dist/filters/iso-date.js.map +1 -0
- package/dist/filters/predicate.d.ts +24 -0
- package/dist/filters/predicate.js +178 -0
- package/dist/filters/predicate.js.map +1 -0
- package/dist/filters/priority.d.ts +51 -0
- package/dist/filters/priority.js +91 -0
- package/dist/filters/priority.js.map +1 -0
- package/dist/filters/pushdown.d.ts +12 -0
- package/dist/filters/pushdown.js +52 -0
- package/dist/filters/pushdown.js.map +1 -0
- package/dist/filters/shell-check.d.ts +110 -0
- package/dist/filters/shell-check.js +304 -0
- package/dist/filters/shell-check.js.map +1 -0
- package/dist/identities/github-app.d.ts +55 -0
- package/dist/identities/github-app.js +160 -0
- package/dist/identities/github-app.js.map +1 -0
- package/dist/identities/index.d.ts +6 -0
- package/dist/identities/index.js +7 -0
- package/dist/identities/index.js.map +1 -0
- package/dist/identities/jwt.d.ts +24 -0
- package/dist/identities/jwt.js +56 -0
- package/dist/identities/jwt.js.map +1 -0
- package/dist/lifecycle/context.d.ts +106 -0
- package/dist/lifecycle/context.js +170 -0
- package/dist/lifecycle/context.js.map +1 -0
- package/dist/lifecycle/engine.d.ts +185 -0
- package/dist/lifecycle/engine.js +551 -0
- package/dist/lifecycle/engine.js.map +1 -0
- package/dist/lifecycle/errors.d.ts +48 -0
- package/dist/lifecycle/errors.js +71 -0
- package/dist/lifecycle/errors.js.map +1 -0
- package/dist/lifecycle/index.d.ts +9 -0
- package/dist/lifecycle/index.js +9 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/lifecycle/performers.d.ts +66 -0
- package/dist/lifecycle/performers.js +179 -0
- package/dist/lifecycle/performers.js.map +1 -0
- package/dist/notifications/index.d.ts +6 -0
- package/dist/notifications/index.js +7 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/service.d.ts +115 -0
- package/dist/notifications/service.js +364 -0
- package/dist/notifications/service.js.map +1 -0
- package/dist/persistence/actions.d.ts +101 -0
- package/dist/persistence/actions.js +196 -0
- package/dist/persistence/actions.js.map +1 -0
- package/dist/persistence/blocks.d.ts +85 -0
- package/dist/persistence/blocks.js +140 -0
- package/dist/persistence/blocks.js.map +1 -0
- package/dist/persistence/cron-firings.d.ts +55 -0
- package/dist/persistence/cron-firings.js +70 -0
- package/dist/persistence/cron-firings.js.map +1 -0
- package/dist/persistence/database.d.ts +60 -0
- package/dist/persistence/database.js +124 -0
- package/dist/persistence/database.js.map +1 -0
- package/dist/persistence/errors.d.ts +39 -0
- package/dist/persistence/errors.js +67 -0
- package/dist/persistence/errors.js.map +1 -0
- package/dist/persistence/events.d.ts +72 -0
- package/dist/persistence/events.js +83 -0
- package/dist/persistence/events.js.map +1 -0
- package/dist/persistence/index.d.ts +18 -0
- package/dist/persistence/index.js +19 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/instance-lock.d.ts +26 -0
- package/dist/persistence/instance-lock.js +117 -0
- package/dist/persistence/instance-lock.js.map +1 -0
- package/dist/persistence/lock-keys.d.ts +16 -0
- package/dist/persistence/lock-keys.js +41 -0
- package/dist/persistence/lock-keys.js.map +1 -0
- package/dist/persistence/notifications.d.ts +113 -0
- package/dist/persistence/notifications.js +213 -0
- package/dist/persistence/notifications.js.map +1 -0
- package/dist/persistence/persistence.d.ts +46 -0
- package/dist/persistence/persistence.js +42 -0
- package/dist/persistence/persistence.js.map +1 -0
- package/dist/persistence/retention.d.ts +46 -0
- package/dist/persistence/retention.js +68 -0
- package/dist/persistence/retention.js.map +1 -0
- package/dist/persistence/runs.d.ts +215 -0
- package/dist/persistence/runs.js +417 -0
- package/dist/persistence/runs.js.map +1 -0
- package/dist/persistence/schema.d.ts +16 -0
- package/dist/persistence/schema.js +183 -0
- package/dist/persistence/schema.js.map +1 -0
- package/dist/persistence/sqlite.d.ts +49 -0
- package/dist/persistence/sqlite.js +131 -0
- package/dist/persistence/sqlite.js.map +1 -0
- package/dist/runs/controller.d.ts +307 -0
- package/dist/runs/controller.js +1078 -0
- package/dist/runs/controller.js.map +1 -0
- package/dist/runs/errors.d.ts +20 -0
- package/dist/runs/errors.js +26 -0
- package/dist/runs/errors.js.map +1 -0
- package/dist/runs/event-bus.d.ts +106 -0
- package/dist/runs/event-bus.js +105 -0
- package/dist/runs/event-bus.js.map +1 -0
- package/dist/runs/execution.d.ts +39 -0
- package/dist/runs/execution.js +146 -0
- package/dist/runs/execution.js.map +1 -0
- package/dist/runs/index.d.ts +12 -0
- package/dist/runs/index.js +13 -0
- package/dist/runs/index.js.map +1 -0
- package/dist/runs/retention.d.ts +64 -0
- package/dist/runs/retention.js +232 -0
- package/dist/runs/retention.js.map +1 -0
- package/dist/runs/workspace.d.ts +20 -0
- package/dist/runs/workspace.js +51 -0
- package/dist/runs/workspace.js.map +1 -0
- package/dist/scheduler/checks.d.ts +41 -0
- package/dist/scheduler/checks.js +111 -0
- package/dist/scheduler/checks.js.map +1 -0
- package/dist/scheduler/cron.d.ts +32 -0
- package/dist/scheduler/cron.js +83 -0
- package/dist/scheduler/cron.js.map +1 -0
- package/dist/scheduler/dry-run.d.ts +42 -0
- package/dist/scheduler/dry-run.js +167 -0
- package/dist/scheduler/dry-run.js.map +1 -0
- package/dist/scheduler/errors.d.ts +22 -0
- package/dist/scheduler/errors.js +22 -0
- package/dist/scheduler/errors.js.map +1 -0
- package/dist/scheduler/format.d.ts +3 -0
- package/dist/scheduler/format.js +73 -0
- package/dist/scheduler/format.js.map +1 -0
- package/dist/scheduler/index.d.ts +13 -0
- package/dist/scheduler/index.js +14 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/planner.d.ts +88 -0
- package/dist/scheduler/planner.js +255 -0
- package/dist/scheduler/planner.js.map +1 -0
- package/dist/scheduler/scheduler.d.ts +160 -0
- package/dist/scheduler/scheduler.js +680 -0
- package/dist/scheduler/scheduler.js.map +1 -0
- package/dist/scheduler/state.d.ts +26 -0
- package/dist/scheduler/state.js +25 -0
- package/dist/scheduler/state.js.map +1 -0
- package/dist/scheduler/types.d.ts +197 -0
- package/dist/scheduler/types.js +3 -0
- package/dist/scheduler/types.js.map +1 -0
- package/dist/service/index.d.ts +6 -0
- package/dist/service/index.js +7 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/install.d.ts +93 -0
- package/dist/service/install.js +250 -0
- package/dist/service/install.js.map +1 -0
- package/dist/service/unit.d.ts +50 -0
- package/dist/service/unit.js +171 -0
- package/dist/service/unit.js.map +1 -0
- package/dist/sources/github/adapter.d.ts +99 -0
- package/dist/sources/github/adapter.js +336 -0
- package/dist/sources/github/adapter.js.map +1 -0
- package/dist/sources/github/fields.d.ts +8 -0
- package/dist/sources/github/fields.js +72 -0
- package/dist/sources/github/fields.js.map +1 -0
- package/dist/sources/github/http.d.ts +100 -0
- package/dist/sources/github/http.js +288 -0
- package/dist/sources/github/http.js.map +1 -0
- package/dist/sources/github/index.d.ts +6 -0
- package/dist/sources/github/index.js +7 -0
- package/dist/sources/github/index.js.map +1 -0
- package/dist/sources/github/pushdown.d.ts +14 -0
- package/dist/sources/github/pushdown.js +47 -0
- package/dist/sources/github/pushdown.js.map +1 -0
- package/dist/sources/github/refs.d.ts +17 -0
- package/dist/sources/github/refs.js +61 -0
- package/dist/sources/github/refs.js.map +1 -0
- package/dist/sources/index.d.ts +6 -0
- package/dist/sources/index.js +7 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/index.js +28 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/public/app.css +239 -0
- package/dist/ui/public/favicon.svg +1 -0
- package/dist/ui/public/index.html +27 -0
- package/dist/ui/public/js/client/api.js +68 -0
- package/dist/ui/public/js/client/app.js +146 -0
- package/dist/ui/public/js/client/dom.js +34 -0
- package/dist/ui/public/js/client/page.js +9 -0
- package/dist/ui/public/js/client/pages/actions.js +35 -0
- package/dist/ui/public/js/client/pages/blocked.js +58 -0
- package/dist/ui/public/js/client/pages/config.js +126 -0
- package/dist/ui/public/js/client/pages/dashboard.js +175 -0
- package/dist/ui/public/js/client/pages/run.js +367 -0
- package/dist/ui/public/js/client/pages/runs.js +72 -0
- package/dist/ui/public/js/client/pages/views.js +80 -0
- package/dist/ui/public/js/client/pages/workflows.js +291 -0
- package/dist/ui/public/js/client/types.js +1 -0
- package/dist/ui/public/js/client/ui.js +152 -0
- package/dist/ui/public/js/shared/dom.js +77 -0
- package/dist/ui/public/js/shared/events.js +88 -0
- package/dist/ui/public/js/shared/format.js +213 -0
- package/dist/ui/public/js/shared/logs.js +136 -0
- package/dist/ui/public/js/shared/params.js +90 -0
- package/dist/ui/public/js/shared/route.js +36 -0
- package/dist/ui/public/js/shared/sort.js +70 -0
- package/dist/ui/public/js/shared/sse.js +193 -0
- package/dist/ui/public/js/shared/throttle.js +65 -0
- package/dist/views/index.d.ts +6 -0
- package/dist/views/index.js +7 -0
- package/dist/views/index.js.map +1 -0
- package/dist/views/service.d.ts +131 -0
- package/dist/views/service.js +264 -0
- package/dist/views/service.js.map +1 -0
- package/docs/api.md +239 -0
- package/docs/configuration-reference.md +1785 -0
- package/docs/cron-semantics.md +96 -0
- package/docs/manual-tests/github-fixture/config.yaml +30 -0
- package/docs/manual-tests/github-fixture/helpers.sh +93 -0
- package/docs/manual-tests/github-fixture/identities.yaml +18 -0
- package/docs/manual-tests/github-fixture/scripts/test-worker.sh +100 -0
- package/docs/manual-tests/github-fixture/sources.yaml +13 -0
- package/docs/manual-tests/github-fixture/views/dependencies.yaml +17 -0
- package/docs/manual-tests/github-fixture/views/needs-maintainer.yaml +17 -0
- package/docs/manual-tests/github-fixture/workflows/coder-test.yaml +76 -0
- package/docs/manual-tests/github-fixture/workflows/commenter-test.yaml +63 -0
- package/docs/manual-tests/github-fixture/workflows/reviewer-test.yaml +60 -0
- package/docs/manual-tests/github.md +1308 -0
- package/docs/manual-tests/process-supervision.md +64 -0
- package/docs/manual-tests/systemd.md +68 -0
- package/docs/operations.md +271 -0
- package/docs/worker-protocol.md +145 -0
- package/examples/config/config.yaml +35 -0
- package/examples/config/identities.yaml +18 -0
- package/examples/config/sources.yaml +13 -0
- package/examples/config/views/needs-maintainer.yaml +15 -0
- package/examples/config/workflows/coder-project-a.yaml +86 -0
- package/examples/config/workflows/deploy.yaml +15 -0
- package/examples/config/workflows/nightly-maintenance.yaml +13 -0
- package/package.json +75 -4
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run context for lifecycle actions: the run's configuration snapshot
|
|
3
|
+
* (Spec §12, §19), placeholder values/scope for hook actions (WI-02 table
|
|
4
|
+
* "Platzhalter-Scopes") and the JSON context handed to `shell` actions.
|
|
5
|
+
*/
|
|
6
|
+
import { WORKER_PROTOCOL_VERSION, type HookName, type IdentityRef, type SourceItem, type TemplateScope, type TemplateValues } from '../core/index.js';
|
|
7
|
+
import { type LifecycleActionConfig, type WorkflowSnapshot } from '../config/index.js';
|
|
8
|
+
import type { RunRecord } from '../persistence/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* Validate and return the workflow snapshot stored with a run
|
|
11
|
+
* (`runs.config_snapshot`). Hooks always run against this snapshot, never
|
|
12
|
+
* against the currently active configuration.
|
|
13
|
+
*
|
|
14
|
+
* @throws LifecycleError `lifecycle_invalid_snapshot`
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseRunSnapshot(value: unknown, runId?: string): WorkflowSnapshot;
|
|
17
|
+
/** True for workflows whose runs are bound to a source item (WI-02: `trigger.type: source`). */
|
|
18
|
+
export declare function isSourceWorkflow(snapshot: WorkflowSnapshot): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Write identity of an action: action `identity` (only `source.comment`) →
|
|
21
|
+
* workflow `identity` → source `identity` (WI-02, Spec §5.2).
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveActionIdentity(action: LifecycleActionConfig, snapshot: WorkflowSnapshot): IdentityRef | null;
|
|
24
|
+
/** Placeholder scope of hook actions (WI-02): `result` everywhere except `on_start`. */
|
|
25
|
+
export declare function hookTemplateScope(snapshot: WorkflowSnapshot, hook: HookName): TemplateScope;
|
|
26
|
+
/** Minimal item derived from the run when the source item is not available. */
|
|
27
|
+
export declare function itemFromRun(run: RunRecord): SourceItem | null;
|
|
28
|
+
/** Input for {@link buildHookTemplateValues}. */
|
|
29
|
+
export interface HookValueInput {
|
|
30
|
+
run: RunRecord;
|
|
31
|
+
snapshot: WorkflowSnapshot;
|
|
32
|
+
hook: HookName;
|
|
33
|
+
/** Item (fresh or derived from the run); `null` for sourceless runs. */
|
|
34
|
+
item: SourceItem | null;
|
|
35
|
+
/** `{source.repository}` (adapter's value); defaults to `owner/repository` of the snapshot source. */
|
|
36
|
+
repository?: string;
|
|
37
|
+
now: Date;
|
|
38
|
+
}
|
|
39
|
+
/** Placeholder values for a hook action of `run`. Result values only outside `on_start`. */
|
|
40
|
+
export declare function buildHookTemplateValues(input: HookValueInput): TemplateValues;
|
|
41
|
+
/**
|
|
42
|
+
* Render a hook-action text template. Unknown placeholders and placeholders
|
|
43
|
+
* outside the hook's scope (e.g. `{result.message}` in `on_start`) are
|
|
44
|
+
* rejected with a `TemplateError`, even if config validation was bypassed.
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderHookText(template: string, values: TemplateValues, scope: TemplateScope): string;
|
|
47
|
+
/** JSON context written to `ADISPATCH_CONTEXT_FILE` for `shell` actions. */
|
|
48
|
+
export type ShellActionContext = {
|
|
49
|
+
schema_version: typeof WORKER_PROTOCOL_VERSION;
|
|
50
|
+
kind: 'lifecycle_action';
|
|
51
|
+
run: {
|
|
52
|
+
id: string;
|
|
53
|
+
trigger: string;
|
|
54
|
+
status: string;
|
|
55
|
+
started_at: string | null;
|
|
56
|
+
finished_at: string | null;
|
|
57
|
+
};
|
|
58
|
+
workflow: {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
};
|
|
62
|
+
hook: HookName;
|
|
63
|
+
action: {
|
|
64
|
+
id: number;
|
|
65
|
+
name: string | null;
|
|
66
|
+
ordinal: number;
|
|
67
|
+
type: 'shell';
|
|
68
|
+
attempt: number;
|
|
69
|
+
};
|
|
70
|
+
/** Shape of `WorkerContext.source` (sets `ADISPATCH_SOURCE_*`). */
|
|
71
|
+
source?: {
|
|
72
|
+
id: string;
|
|
73
|
+
type: string;
|
|
74
|
+
item_id: string;
|
|
75
|
+
item_key: string;
|
|
76
|
+
url: string;
|
|
77
|
+
attributes: Record<string, unknown>;
|
|
78
|
+
};
|
|
79
|
+
parameters: Record<string, string | number | boolean>;
|
|
80
|
+
workspace: {
|
|
81
|
+
path: string | null;
|
|
82
|
+
base_dir: string;
|
|
83
|
+
};
|
|
84
|
+
/** Final run outcome and worker result; `null` in `on_start`. */
|
|
85
|
+
result: {
|
|
86
|
+
status: string | null;
|
|
87
|
+
result: string | null;
|
|
88
|
+
reason: string | null;
|
|
89
|
+
message: string | null;
|
|
90
|
+
details: unknown;
|
|
91
|
+
artifacts: unknown;
|
|
92
|
+
} | null;
|
|
93
|
+
};
|
|
94
|
+
/** Build the context of a `shell` action. Contains no secrets. */
|
|
95
|
+
export declare function buildShellActionContext(input: {
|
|
96
|
+
run: RunRecord;
|
|
97
|
+
snapshot: WorkflowSnapshot;
|
|
98
|
+
hook: HookName;
|
|
99
|
+
item: SourceItem | null;
|
|
100
|
+
action: {
|
|
101
|
+
id: number;
|
|
102
|
+
name: string | null;
|
|
103
|
+
ordinal: number;
|
|
104
|
+
attempt: number;
|
|
105
|
+
};
|
|
106
|
+
}): ShellActionContext;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run context for lifecycle actions: the run's configuration snapshot
|
|
3
|
+
* (Spec §12, §19), placeholder values/scope for hook actions (WI-02 table
|
|
4
|
+
* "Platzhalter-Scopes") and the JSON context handed to `shell` actions.
|
|
5
|
+
*/
|
|
6
|
+
import { WORKER_PROTOCOL_VERSION, buildTemplateValues, parseSourceItemKey, renderTemplate, } from '../core/index.js';
|
|
7
|
+
import { WORKFLOW_SNAPSHOT_VERSION } from '../config/index.js';
|
|
8
|
+
import { LifecycleError } from './errors.js';
|
|
9
|
+
/**
|
|
10
|
+
* Validate and return the workflow snapshot stored with a run
|
|
11
|
+
* (`runs.config_snapshot`). Hooks always run against this snapshot, never
|
|
12
|
+
* against the currently active configuration.
|
|
13
|
+
*
|
|
14
|
+
* @throws LifecycleError `lifecycle_invalid_snapshot`
|
|
15
|
+
*/
|
|
16
|
+
export function parseRunSnapshot(value, runId) {
|
|
17
|
+
const s = value;
|
|
18
|
+
const ok = typeof s === 'object' &&
|
|
19
|
+
s !== null &&
|
|
20
|
+
s.schemaVersion === WORKFLOW_SNAPSHOT_VERSION &&
|
|
21
|
+
typeof s.workflow === 'object' &&
|
|
22
|
+
s.workflow !== null &&
|
|
23
|
+
typeof s.workflow.id === 'string' &&
|
|
24
|
+
typeof s.workflow.hooks === 'object' &&
|
|
25
|
+
s.workflow.hooks !== null &&
|
|
26
|
+
typeof s.workspace === 'object' &&
|
|
27
|
+
s.workspace !== null;
|
|
28
|
+
if (!ok) {
|
|
29
|
+
throw new LifecycleError('invalid_snapshot', `${runId !== undefined ? `Run ${runId}` : 'Run'} has no valid workflow configuration snapshot`, {
|
|
30
|
+
details: runId !== undefined ? { runId } : {},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return s;
|
|
34
|
+
}
|
|
35
|
+
/** True for workflows whose runs are bound to a source item (WI-02: `trigger.type: source`). */
|
|
36
|
+
export function isSourceWorkflow(snapshot) {
|
|
37
|
+
return snapshot.workflow.trigger.type === 'source';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Write identity of an action: action `identity` (only `source.comment`) →
|
|
41
|
+
* workflow `identity` → source `identity` (WI-02, Spec §5.2).
|
|
42
|
+
*/
|
|
43
|
+
export function resolveActionIdentity(action, snapshot) {
|
|
44
|
+
if (action.type === 'source.comment' && action.identity)
|
|
45
|
+
return action.identity;
|
|
46
|
+
return snapshot.workflow.identity ?? snapshot.source?.identity ?? null;
|
|
47
|
+
}
|
|
48
|
+
/** Placeholder scope of hook actions (WI-02): `result` everywhere except `on_start`. */
|
|
49
|
+
export function hookTemplateScope(snapshot, hook) {
|
|
50
|
+
return {
|
|
51
|
+
run: true,
|
|
52
|
+
workspace: true,
|
|
53
|
+
source: isSourceWorkflow(snapshot),
|
|
54
|
+
result: hook !== 'on_start',
|
|
55
|
+
parameters: Object.keys(snapshot.workflow.parameters ?? {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Minimal item derived from the run when the source item is not available. */
|
|
59
|
+
export function itemFromRun(run) {
|
|
60
|
+
if (!run.sourceItemKey)
|
|
61
|
+
return null;
|
|
62
|
+
const { sourceId, itemId } = parseSourceItemKey(run.sourceItemKey);
|
|
63
|
+
return { sourceId, itemId, key: run.sourceItemKey, url: run.sourceUrl ?? '', type: 'unknown', fields: {} };
|
|
64
|
+
}
|
|
65
|
+
/** The worker result (`runs.result_json`) as plain object, if any. */
|
|
66
|
+
function runResult(run) {
|
|
67
|
+
return typeof run.result === 'object' && run.result !== null ? run.result : null;
|
|
68
|
+
}
|
|
69
|
+
function scalarParameters(run) {
|
|
70
|
+
const out = {};
|
|
71
|
+
for (const [k, v] of Object.entries(run.parameters ?? {})) {
|
|
72
|
+
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean')
|
|
73
|
+
out[k] = v;
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/** Placeholder values for a hook action of `run`. Result values only outside `on_start`. */
|
|
78
|
+
export function buildHookTemplateValues(input) {
|
|
79
|
+
const { run, snapshot, hook, item } = input;
|
|
80
|
+
const source = isSourceWorkflow(snapshot) ? snapshot.source : null;
|
|
81
|
+
const result = runResult(run);
|
|
82
|
+
const title = item?.fields.title;
|
|
83
|
+
return buildTemplateValues({
|
|
84
|
+
workflow: { id: snapshot.workflow.id, name: snapshot.workflow.name },
|
|
85
|
+
workspace: { baseDir: snapshot.workspace.baseDir, ...(run.workspacePath ? { path: run.workspacePath } : {}) },
|
|
86
|
+
run: {
|
|
87
|
+
id: run.id,
|
|
88
|
+
trigger: run.triggerType,
|
|
89
|
+
...(run.startedAt ? { startedAt: new Date(run.startedAt) } : {}),
|
|
90
|
+
},
|
|
91
|
+
...(source
|
|
92
|
+
? { source: { id: source.id, type: source.type, repository: input.repository ?? `${source.owner}/${source.repository}` } }
|
|
93
|
+
: {}),
|
|
94
|
+
...(source && item
|
|
95
|
+
? {
|
|
96
|
+
item: {
|
|
97
|
+
id: item.itemId,
|
|
98
|
+
key: item.key,
|
|
99
|
+
...(/^\d+$/.test(item.itemId) ? { number: item.itemId } : {}),
|
|
100
|
+
...(item.url ? { url: item.url } : {}),
|
|
101
|
+
...(typeof title === 'string' ? { title } : {}),
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
: {}),
|
|
105
|
+
...(hook !== 'on_start'
|
|
106
|
+
? {
|
|
107
|
+
result: {
|
|
108
|
+
...(run.finalStatus ? { status: run.finalStatus } : {}),
|
|
109
|
+
result: run.businessResult,
|
|
110
|
+
...(typeof result?.message === 'string' ? { message: result.message } : {}),
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
: {}),
|
|
114
|
+
parameters: scalarParameters(run),
|
|
115
|
+
now: input.now,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Render a hook-action text template. Unknown placeholders and placeholders
|
|
120
|
+
* outside the hook's scope (e.g. `{result.message}` in `on_start`) are
|
|
121
|
+
* rejected with a `TemplateError`, even if config validation was bypassed.
|
|
122
|
+
*/
|
|
123
|
+
export function renderHookText(template, values, scope) {
|
|
124
|
+
return renderTemplate(template, values, { mode: 'text', scope });
|
|
125
|
+
}
|
|
126
|
+
/** Build the context of a `shell` action. Contains no secrets. */
|
|
127
|
+
export function buildShellActionContext(input) {
|
|
128
|
+
const { run, snapshot, hook, item } = input;
|
|
129
|
+
const result = runResult(run);
|
|
130
|
+
const source = isSourceWorkflow(snapshot) ? snapshot.source : null;
|
|
131
|
+
return {
|
|
132
|
+
schema_version: WORKER_PROTOCOL_VERSION,
|
|
133
|
+
kind: 'lifecycle_action',
|
|
134
|
+
run: {
|
|
135
|
+
id: run.id,
|
|
136
|
+
trigger: run.triggerType,
|
|
137
|
+
status: run.status,
|
|
138
|
+
started_at: run.startedAt,
|
|
139
|
+
finished_at: run.finishedAt,
|
|
140
|
+
},
|
|
141
|
+
workflow: { id: snapshot.workflow.id, name: snapshot.workflow.name },
|
|
142
|
+
hook,
|
|
143
|
+
action: { ...input.action, type: 'shell' },
|
|
144
|
+
...(source && item
|
|
145
|
+
? {
|
|
146
|
+
source: {
|
|
147
|
+
id: source.id,
|
|
148
|
+
type: source.type,
|
|
149
|
+
item_id: item.itemId,
|
|
150
|
+
item_key: item.key,
|
|
151
|
+
url: item.url,
|
|
152
|
+
attributes: { ...item.fields },
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
: {}),
|
|
156
|
+
parameters: scalarParameters(run),
|
|
157
|
+
workspace: { path: run.workspacePath, base_dir: snapshot.workspace.baseDir },
|
|
158
|
+
result: hook === 'on_start'
|
|
159
|
+
? null
|
|
160
|
+
: {
|
|
161
|
+
status: run.finalStatus,
|
|
162
|
+
result: run.businessResult,
|
|
163
|
+
reason: run.finalReason,
|
|
164
|
+
message: typeof result?.message === 'string' ? result.message : null,
|
|
165
|
+
details: result?.details ?? null,
|
|
166
|
+
artifacts: result?.artifacts ?? null,
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/lifecycle/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,GAMf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,yBAAyB,EAAqD,MAAM,oBAAoB,CAAC;AAElH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,KAAc;IAC7D,MAAM,CAAC,GAAG,KAAyC,CAAC;IACpD,MAAM,EAAE,GACN,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACV,CAAC,CAAC,aAAa,KAAK,yBAAyB;QAC7C,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ;QAC9B,CAAC,CAAC,QAAQ,KAAK,IAAI;QACnB,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,KAAK,QAAQ;QACjC,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,KAAK,QAAQ;QACpC,CAAC,CAAC,QAAQ,CAAC,KAAK,KAAK,IAAI;QACzB,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ;QAC/B,CAAC,CAAC,SAAS,KAAK,IAAI,CAAC;IACvB,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,cAAc,CAAC,kBAAkB,EAAE,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,+CAA+C,EAAE;YAC3I,O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IAAI,IAAI;aACrC;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle engine (Spec §10): journaled, sequential hook chains with
|
|
3
|
+
* per-action retries, manual retry/skip, chain continuation and recovery.
|
|
4
|
+
*
|
|
5
|
+
* Invariants:
|
|
6
|
+
* - Every action state change is persisted before work continues
|
|
7
|
+
* (journal = `run_actions`, every attempt = `action_attempts`).
|
|
8
|
+
* - `succeeded`/`skipped` actions are never executed again.
|
|
9
|
+
* - Hooks always use the run's configuration snapshot (journal
|
|
10
|
+
* `action_config_json` + `runs.config_snapshot`), never the live config.
|
|
11
|
+
* - Notifications and change callbacks are published only after commit.
|
|
12
|
+
*/
|
|
13
|
+
import { type Clock, type Executor, type HookName, type LifecycleStatus, type Logger, type Notifier, type SourceItem, type Timers, type Redactor } from '../core/index.js';
|
|
14
|
+
import type { LifecycleActionConfig, RetryPolicy, WorkflowSnapshot } from '../config/index.js';
|
|
15
|
+
import type { Repositories, RunActionRecord, RunRecord } from '../persistence/index.js';
|
|
16
|
+
import { type ActionErrorInfo } from './errors.js';
|
|
17
|
+
import { type SourceResolver } from './performers.js';
|
|
18
|
+
/** Event type persisted in `run_events` for every action state change. */
|
|
19
|
+
export declare const LIFECYCLE_ACTION_EVENT = "lifecycle.action";
|
|
20
|
+
/** Event type persisted in `run_events` when a hook chain starts/ends. */
|
|
21
|
+
export declare const LIFECYCLE_CHAIN_EVENT = "lifecycle.chain";
|
|
22
|
+
/** Default retry policy if a journaled action carries none (Spec §5.1: 3 × 30 s). */
|
|
23
|
+
export declare const DEFAULT_ACTION_RETRY: RetryPolicy;
|
|
24
|
+
/** Outcome of executing (or continuing) one hook chain. */
|
|
25
|
+
export interface HookResult {
|
|
26
|
+
runId: string;
|
|
27
|
+
hook: HookName;
|
|
28
|
+
/**
|
|
29
|
+
* - `succeeded`: every action is `succeeded`/`skipped` or failed with `continue_on_error`.
|
|
30
|
+
* - `failed`: the chain stopped at {@link HookResult.failedAction}; later actions stay `pending`.
|
|
31
|
+
* - `interrupted`: aborted via signal; the current action was reset to `pending` (resumable).
|
|
32
|
+
*/
|
|
33
|
+
status: 'succeeded' | 'failed' | 'interrupted';
|
|
34
|
+
/** Final journal state of the hook (ordinal order). */
|
|
35
|
+
actions: RunActionRecord[];
|
|
36
|
+
/** Action that stopped the chain (`status === 'failed'`). */
|
|
37
|
+
failedAction: RunActionRecord | null;
|
|
38
|
+
}
|
|
39
|
+
/** Per-call options. */
|
|
40
|
+
export interface HookContext {
|
|
41
|
+
/**
|
|
42
|
+
* Freshly read source item (WI-08 re-reads it before starting, Spec §7).
|
|
43
|
+
* Optional: if missing, source actions read the item via the adapter.
|
|
44
|
+
*/
|
|
45
|
+
item?: SourceItem;
|
|
46
|
+
/** Aborts retry delays and running shell actions (shutdown). */
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
/**
|
|
49
|
+
* If another chain of the same run is executing: `true` = queue behind it
|
|
50
|
+
* (internal callers, e.g. WI-08 `runHook` while a manual retry runs);
|
|
51
|
+
* default `false` = reject immediately with {@link LifecycleBusyError} (API calls).
|
|
52
|
+
*/
|
|
53
|
+
wait?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** Payload of the `lifecycle_action_failed` notification. */
|
|
56
|
+
export interface LifecycleActionFailedPayload extends Record<string, unknown> {
|
|
57
|
+
runId: string;
|
|
58
|
+
workflowId: string;
|
|
59
|
+
hook: HookName;
|
|
60
|
+
actionId: number;
|
|
61
|
+
actionName: string | null;
|
|
62
|
+
actionType: string;
|
|
63
|
+
ordinal: number;
|
|
64
|
+
attempts: number;
|
|
65
|
+
error: ActionErrorInfo | null;
|
|
66
|
+
sourceItemKey: string | null;
|
|
67
|
+
sourceUrl: string | null;
|
|
68
|
+
}
|
|
69
|
+
/** Dependencies of {@link LifecycleEngine}. */
|
|
70
|
+
export interface LifecycleEngineOptions {
|
|
71
|
+
/** Persistence (WI-03). */
|
|
72
|
+
repositories: Pick<Repositories, 'runs' | 'actions' | 'events' | 'transaction' | 'afterCommit'>;
|
|
73
|
+
/** Source adapters by configured source ID. */
|
|
74
|
+
sources: SourceResolver;
|
|
75
|
+
/** Data directory (context/log files of `shell` actions below `runs/<id>/actions`, `logs/<id>/actions`). */
|
|
76
|
+
dataDir: string;
|
|
77
|
+
/** Executor for `shell` actions; default `new ShellExecutor({ clock, logger })` (minimal env, no controller env). */
|
|
78
|
+
executor?: Executor;
|
|
79
|
+
clock?: Clock;
|
|
80
|
+
/** Timers for retry delays (FakeClock in tests). */
|
|
81
|
+
timers?: Timers;
|
|
82
|
+
logger?: Logger;
|
|
83
|
+
/** Receives `lifecycle_action_failed` after commit (delivery: WI-10). Must not throw/block. */
|
|
84
|
+
notifier?: Notifier;
|
|
85
|
+
/** Called after commit for every persisted action change (event bus / SSE in WI-08/WI-10). */
|
|
86
|
+
onActionChange?: (action: RunActionRecord) => void;
|
|
87
|
+
/** Best-effort redaction of persisted error texts (e.g. `SecretRedactor.asRedactor`). */
|
|
88
|
+
redact?: Redactor;
|
|
89
|
+
/** SIGTERM → SIGKILL grace for `shell` actions. Default 5 s. */
|
|
90
|
+
shellCancelGraceMs?: number;
|
|
91
|
+
/** Log limit per `shell` action attempt (stdout + stderr). Default 10 MiB. */
|
|
92
|
+
maxShellLogBytes?: number;
|
|
93
|
+
}
|
|
94
|
+
/** See module docs. One instance per process; chains of one run never execute concurrently. */
|
|
95
|
+
export declare class LifecycleEngine {
|
|
96
|
+
private readonly options;
|
|
97
|
+
private readonly repos;
|
|
98
|
+
private readonly clock;
|
|
99
|
+
private readonly timers;
|
|
100
|
+
private readonly logger;
|
|
101
|
+
private readonly redact;
|
|
102
|
+
private readonly performerDeps;
|
|
103
|
+
/** Tail of the per-run execution queue (present while a chain of the run runs or waits). */
|
|
104
|
+
private readonly tails;
|
|
105
|
+
constructor(options: LifecycleEngineOptions);
|
|
106
|
+
/** True while a chain of `runId` is executing in this process. */
|
|
107
|
+
isBusy(runId: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Run hook `hook` of a run: creates the journal for all actions of the hook
|
|
110
|
+
* from the snapshot (stable IDs, ordinals, `action_config_json`) and
|
|
111
|
+
* executes them sequentially. Idempotent/resumable: an existing journal is
|
|
112
|
+
* reused and only `pending` actions run (a `failed` action without
|
|
113
|
+
* `continue_on_error` keeps the chain stopped — use {@link retryAction}).
|
|
114
|
+
*
|
|
115
|
+
* @param snapshot defaults to `run.configSnapshot` (must be the run's snapshot, never the live config)
|
|
116
|
+
* @throws LifecycleBusyError if a chain of this run is already executing
|
|
117
|
+
*/
|
|
118
|
+
runHook(run: RunRecord | string, hook: HookName, snapshot?: WorkflowSnapshot, context?: HookContext): Promise<HookResult>;
|
|
119
|
+
/**
|
|
120
|
+
* Manual retry (GUI "Retry Action"): the `failed` action gets a fresh round
|
|
121
|
+
* of attempts (its retry policy), then the chain continues from there. The
|
|
122
|
+
* main worker is not involved; `succeeded` actions are never repeated.
|
|
123
|
+
*
|
|
124
|
+
* @throws LifecycleError `lifecycle_not_retryable` if the action is not `failed`
|
|
125
|
+
*/
|
|
126
|
+
retryAction(actionId: number, context?: HookContext): Promise<HookResult>;
|
|
127
|
+
/**
|
|
128
|
+
* Operator skips a `failed` (or `pending`) action; the chain then continues
|
|
129
|
+
* after it (e.g. the operator fixed the item manually).
|
|
130
|
+
*/
|
|
131
|
+
skipAction(actionId: number, context?: HookContext): Promise<HookResult>;
|
|
132
|
+
/**
|
|
133
|
+
* Recovery after a controller restart (WI-08, Spec §14): actions left
|
|
134
|
+
* `running` are brought into a safe state, then every incomplete chain of
|
|
135
|
+
* the run is continued (in journal order). Safe state:
|
|
136
|
+
* - `source.comment`: marker lookup; found → `succeeded` (no duplicate), else `pending`
|
|
137
|
+
* (the next attempt looks up the marker again before posting).
|
|
138
|
+
* - `source.update`: `pending` (re-applied idempotently after re-reading the item).
|
|
139
|
+
* - `shell`: with an unfinished attempt the outcome is unknown and the old process
|
|
140
|
+
* may still run → `failed` (chain stops, manual retry); otherwise `pending`.
|
|
141
|
+
*
|
|
142
|
+
* @param options.hooks only continue these hooks (others are only made safe)
|
|
143
|
+
*/
|
|
144
|
+
resumeIncomplete(run: RunRecord | string, options?: HookContext & {
|
|
145
|
+
hooks?: readonly HookName[];
|
|
146
|
+
}): Promise<HookResult[]>;
|
|
147
|
+
/**
|
|
148
|
+
* Abandon the rest of a hook chain (WI-08 recovery, e.g. an interrupted
|
|
149
|
+
* `on_start` of a run that is now finalized as `crashed`): interrupted
|
|
150
|
+
* actions are made safe (comment marker lookup), all `pending` ones become `skipped`.
|
|
151
|
+
*/
|
|
152
|
+
abandonHook(run: RunRecord | string, hook: HookName, context?: Pick<HookContext, 'item' | 'wait'>): Promise<HookResult>;
|
|
153
|
+
/**
|
|
154
|
+
* Serialize chain executions per run. Without `wait` a busy run is rejected
|
|
155
|
+
* immediately ({@link LifecycleBusyError}, API callers); with `wait` the call
|
|
156
|
+
* is queued behind the running/queued ones (internal callers such as WI-08).
|
|
157
|
+
*/
|
|
158
|
+
private exclusive;
|
|
159
|
+
private executeChain;
|
|
160
|
+
private executeActions;
|
|
161
|
+
private hookResult;
|
|
162
|
+
/** Execute one action with its retry policy. The action is `pending` on entry. */
|
|
163
|
+
private executeAction;
|
|
164
|
+
private perform;
|
|
165
|
+
/** Bring an action left `running` (crash/restart) into a safe state, see {@link resumeIncomplete}. */
|
|
166
|
+
private makeSafe;
|
|
167
|
+
private persistActionStatus;
|
|
168
|
+
private appendActionEvent;
|
|
169
|
+
private publishChange;
|
|
170
|
+
private queueFailureNotification;
|
|
171
|
+
/** Recompute `runs.lifecycle_status` from the whole journal of the run. */
|
|
172
|
+
private refreshLifecycleStatus;
|
|
173
|
+
/** Hooks of a run in journal order. */
|
|
174
|
+
private hooksInOrder;
|
|
175
|
+
}
|
|
176
|
+
/** Action config persisted in the journal (`action_config_json`). */
|
|
177
|
+
export declare function actionConfig(action: RunActionRecord): LifecycleActionConfig;
|
|
178
|
+
/** First `failed` action without `continue_on_error` (the chain stops there), else `null`. */
|
|
179
|
+
export declare function stoppedAt(journal: readonly RunActionRecord[]): RunActionRecord | null;
|
|
180
|
+
/**
|
|
181
|
+
* Aggregate `runs.lifecycle_status` over all hook chains of a run:
|
|
182
|
+
* `running` if an action runs, else `failed` if any chain stopped at a failed
|
|
183
|
+
* action, else `pending` if actions wait, else `succeeded`; `null` without journal.
|
|
184
|
+
*/
|
|
185
|
+
export declare function aggregateLifecycleStatus(actions: readonly RunActionRecord[]): LifecycleStatus | null;
|