dsh-background-task-engine 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/README.md +255 -2
- package/README.zh.md +179 -0
- package/cordis.patch.yml +20 -0
- package/dist/config.d.ts +86 -0
- package/dist/config.js +106 -0
- package/dist/domain/records.d.ts +543 -0
- package/dist/domain/records.js +135 -0
- package/dist/domain/state.d.ts +61 -0
- package/dist/domain/state.js +128 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.js +99 -0
- package/dist/host.d.ts +165 -0
- package/dist/host.js +56 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +78 -0
- package/dist/prompt/guidance.d.ts +30 -0
- package/dist/prompt/guidance.js +62 -0
- package/dist/services/audit.d.ts +39 -0
- package/dist/services/audit.js +48 -0
- package/dist/services/engine.d.ts +435 -0
- package/dist/services/engine.js +150 -0
- package/dist/services/run-service.d.ts +145 -0
- package/dist/services/run-service.js +569 -0
- package/dist/services/schedule-adapter.d.ts +92 -0
- package/dist/services/schedule-adapter.js +220 -0
- package/dist/services/task-service.d.ts +146 -0
- package/dist/services/task-service.js +490 -0
- package/dist/storage/repository.d.ts +65 -0
- package/dist/storage/repository.js +194 -0
- package/dist/storage/spec.d.ts +97 -0
- package/dist/storage/spec.js +149 -0
- package/dist/tools/run-tools.d.ts +14 -0
- package/dist/tools/run-tools.js +402 -0
- package/dist/tools/schedule-tool.d.ts +11 -0
- package/dist/tools/schedule-tool.js +238 -0
- package/dist/tools/shared.d.ts +108 -0
- package/dist/tools/shared.js +278 -0
- package/dist/tools/task-tools.d.ts +7 -0
- package/dist/tools/task-tools.js +321 -0
- package/dist/utils/id.d.ts +8 -0
- package/dist/utils/id.js +29 -0
- package/dist/utils/page.d.ts +36 -0
- package/dist/utils/page.js +71 -0
- package/dist/utils/text.d.ts +20 -0
- package/dist/utils/text.js +46 -0
- package/dist/utils/time.d.ts +7 -0
- package/dist/utils/time.js +38 -0
- package/docs/API-COMPATIBILITY-AUDIT.md +203 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/TEST-REPORT.md +200 -0
- package/docs/preview.svg +68 -0
- package/icon.svg +23 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +71 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run service: manual/schedule execution lifecycle (PRD 5.2, 5.3, FR-005..FR-008,
|
|
3
|
+
* chapter 9.1, acceptance 14.2 / 14.4).
|
|
4
|
+
*
|
|
5
|
+
* Invariants enforced here:
|
|
6
|
+
* - a TaskRun is created only after ownership, task status, concurrency and
|
|
7
|
+
* idempotency checks pass;
|
|
8
|
+
* - the step template is snapshotted into the run, so later task edits cannot
|
|
9
|
+
* change an in-flight run;
|
|
10
|
+
* - steps advance strictly by `order`; a step cannot be reported before its
|
|
11
|
+
* predecessors settled;
|
|
12
|
+
* - `succeeded` requires every required step to be completed;
|
|
13
|
+
* - a failed step is never replayed silently: recovery needs a confirmation.
|
|
14
|
+
*/
|
|
15
|
+
import type { EngineConfig } from '../config.js';
|
|
16
|
+
import { type RunRecord, type RunStatus, type RunStepRecord, type TriggerType } from '../domain/records.js';
|
|
17
|
+
import { compareDesc } from '../utils/page.js';
|
|
18
|
+
import type { Repository } from '../storage/repository.js';
|
|
19
|
+
import type { AuditTrail } from './audit.js';
|
|
20
|
+
export type StepReportAction = 'started' | 'completed' | 'failed' | 'skipped';
|
|
21
|
+
export type FinishStatus = 'succeeded' | 'failed' | 'interrupted' | 'skipped' | 'blocked';
|
|
22
|
+
export interface StartRunInput {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
taskId?: string;
|
|
25
|
+
triggerPayload?: string;
|
|
26
|
+
triggerType?: TriggerType;
|
|
27
|
+
scheduleId?: string;
|
|
28
|
+
occurrenceKey?: string;
|
|
29
|
+
idempotencyKey?: string;
|
|
30
|
+
manualRunId?: string;
|
|
31
|
+
/** Create the run as `queued` instead of `running` (explicit two-phase start). */
|
|
32
|
+
defer?: boolean;
|
|
33
|
+
source: string;
|
|
34
|
+
}
|
|
35
|
+
export interface StartRunResult {
|
|
36
|
+
run: RunRecord;
|
|
37
|
+
steps: RunStepRecord[];
|
|
38
|
+
deduplicated: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface StepReportInput {
|
|
41
|
+
sessionId: string;
|
|
42
|
+
runId: string;
|
|
43
|
+
stepId: string;
|
|
44
|
+
action: StepReportAction;
|
|
45
|
+
summary?: string;
|
|
46
|
+
error?: {
|
|
47
|
+
code?: string;
|
|
48
|
+
message: string;
|
|
49
|
+
} | string;
|
|
50
|
+
}
|
|
51
|
+
export interface FinishRunInput {
|
|
52
|
+
sessionId: string;
|
|
53
|
+
runId: string;
|
|
54
|
+
status: FinishStatus;
|
|
55
|
+
summary?: string;
|
|
56
|
+
error?: {
|
|
57
|
+
code?: string;
|
|
58
|
+
message: string;
|
|
59
|
+
} | string;
|
|
60
|
+
}
|
|
61
|
+
export interface ResumeRunInput {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
runId: string;
|
|
64
|
+
confirmation?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface HistoryInput {
|
|
67
|
+
sessionId: string;
|
|
68
|
+
taskId: string;
|
|
69
|
+
status?: RunStatus;
|
|
70
|
+
limit?: number;
|
|
71
|
+
cursor?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface RunHistoryRow {
|
|
74
|
+
runId: string;
|
|
75
|
+
status: RunStatus;
|
|
76
|
+
triggerType: TriggerType;
|
|
77
|
+
taskRevision: number;
|
|
78
|
+
progress: number;
|
|
79
|
+
requiredCompleted: number;
|
|
80
|
+
requiredTotal: number;
|
|
81
|
+
startedAt: string;
|
|
82
|
+
finishedAt?: string;
|
|
83
|
+
currentStepId?: string;
|
|
84
|
+
resumesRunId?: string;
|
|
85
|
+
summary?: string;
|
|
86
|
+
error?: {
|
|
87
|
+
code: string;
|
|
88
|
+
message: string;
|
|
89
|
+
};
|
|
90
|
+
steps: Array<{
|
|
91
|
+
stepId: string;
|
|
92
|
+
order: number;
|
|
93
|
+
title: string;
|
|
94
|
+
status: string;
|
|
95
|
+
}>;
|
|
96
|
+
}
|
|
97
|
+
export declare class RunService {
|
|
98
|
+
private readonly repo;
|
|
99
|
+
private readonly config;
|
|
100
|
+
private readonly audit;
|
|
101
|
+
private readonly now;
|
|
102
|
+
constructor(repo: Repository, config: EngineConfig, audit: AuditTrail, now?: () => string);
|
|
103
|
+
start(input: StartRunInput): Promise<StartRunResult>;
|
|
104
|
+
/** Two-phase start: transition an existing `queued` run to `running`. */
|
|
105
|
+
begin(input: {
|
|
106
|
+
sessionId: string;
|
|
107
|
+
runId: string;
|
|
108
|
+
source: string;
|
|
109
|
+
}): Promise<StartRunResult>;
|
|
110
|
+
private buildFreshSteps;
|
|
111
|
+
reportStep(input: StepReportInput): Promise<{
|
|
112
|
+
run: RunRecord;
|
|
113
|
+
step: RunStepRecord;
|
|
114
|
+
deduplicated: boolean;
|
|
115
|
+
}>;
|
|
116
|
+
finish(input: FinishRunInput): Promise<RunRecord>;
|
|
117
|
+
resume(input: ResumeRunInput): Promise<StartRunResult>;
|
|
118
|
+
history(input: HistoryInput): {
|
|
119
|
+
items: RunHistoryRow[];
|
|
120
|
+
nextCursor?: string;
|
|
121
|
+
};
|
|
122
|
+
private toHistoryRow;
|
|
123
|
+
/**
|
|
124
|
+
* Startup scan (PRD FR-007, 14.4): a run that was `queued`/`running` and has
|
|
125
|
+
* not been touched for `staleRunAfterMinutes` cannot be verified, so it is
|
|
126
|
+
* marked `interrupted`. Nothing is restarted automatically.
|
|
127
|
+
*/
|
|
128
|
+
recoverStale(): Promise<{
|
|
129
|
+
scanned: number;
|
|
130
|
+
interrupted: string[];
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Retention pruning (PRD 7.4 / FR-010): only terminal runs older than
|
|
134
|
+
* `historyRetentionDays` and their step rows are removed. Templates, audit
|
|
135
|
+
* information and every active run are preserved.
|
|
136
|
+
*/
|
|
137
|
+
prune(): Promise<{
|
|
138
|
+
runs: number;
|
|
139
|
+
steps: number;
|
|
140
|
+
}>;
|
|
141
|
+
/** Persisted step rows of one run, ordered. */
|
|
142
|
+
stepsOf(runId: string): RunStepRecord[];
|
|
143
|
+
countActiveRuns(ownerSessionId: string): number;
|
|
144
|
+
}
|
|
145
|
+
export declare const RUN_HISTORY_ORDER: typeof compareDesc;
|