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.
Files changed (58) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/README.md +255 -2
  4. package/README.zh.md +179 -0
  5. package/cordis.patch.yml +20 -0
  6. package/dist/config.d.ts +86 -0
  7. package/dist/config.js +106 -0
  8. package/dist/domain/records.d.ts +543 -0
  9. package/dist/domain/records.js +135 -0
  10. package/dist/domain/state.d.ts +61 -0
  11. package/dist/domain/state.js +128 -0
  12. package/dist/errors.d.ts +38 -0
  13. package/dist/errors.js +99 -0
  14. package/dist/host.d.ts +165 -0
  15. package/dist/host.js +56 -0
  16. package/dist/index.d.ts +60 -0
  17. package/dist/index.js +78 -0
  18. package/dist/prompt/guidance.d.ts +30 -0
  19. package/dist/prompt/guidance.js +62 -0
  20. package/dist/services/audit.d.ts +39 -0
  21. package/dist/services/audit.js +48 -0
  22. package/dist/services/engine.d.ts +435 -0
  23. package/dist/services/engine.js +150 -0
  24. package/dist/services/run-service.d.ts +145 -0
  25. package/dist/services/run-service.js +569 -0
  26. package/dist/services/schedule-adapter.d.ts +92 -0
  27. package/dist/services/schedule-adapter.js +220 -0
  28. package/dist/services/task-service.d.ts +146 -0
  29. package/dist/services/task-service.js +490 -0
  30. package/dist/storage/repository.d.ts +65 -0
  31. package/dist/storage/repository.js +194 -0
  32. package/dist/storage/spec.d.ts +97 -0
  33. package/dist/storage/spec.js +149 -0
  34. package/dist/tools/run-tools.d.ts +14 -0
  35. package/dist/tools/run-tools.js +402 -0
  36. package/dist/tools/schedule-tool.d.ts +11 -0
  37. package/dist/tools/schedule-tool.js +238 -0
  38. package/dist/tools/shared.d.ts +108 -0
  39. package/dist/tools/shared.js +278 -0
  40. package/dist/tools/task-tools.d.ts +7 -0
  41. package/dist/tools/task-tools.js +321 -0
  42. package/dist/utils/id.d.ts +8 -0
  43. package/dist/utils/id.js +29 -0
  44. package/dist/utils/page.d.ts +36 -0
  45. package/dist/utils/page.js +71 -0
  46. package/dist/utils/text.d.ts +20 -0
  47. package/dist/utils/text.js +46 -0
  48. package/dist/utils/time.d.ts +7 -0
  49. package/dist/utils/time.js +38 -0
  50. package/docs/API-COMPATIBILITY-AUDIT.md +203 -0
  51. package/docs/DETAIL.md +1 -0
  52. package/docs/DETAIL.zh.md +1 -0
  53. package/docs/TEST-REPORT.md +200 -0
  54. package/docs/preview.svg +68 -0
  55. package/icon.svg +23 -0
  56. package/locale/en.json +7 -0
  57. package/locale/zh.json +7 -0
  58. package/package.json +71 -4
package/dist/config.js ADDED
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Configuration schema (PRD 4.4 / FR-012).
3
+ *
4
+ * Exported as `Config` so the DSH loader validates profile config before the
5
+ * plugin is applied. `resolveConfig` re-validates and fills defaults so the
6
+ * engine never runs with out-of-range numbers even when it is constructed
7
+ * directly (tests, embedded use).
8
+ */
9
+ import Schema from '@deepseek-ai/schemastery';
10
+ export const CONFIG_LIMITS = {
11
+ maxTasksPerOwner: { min: 1, max: 1000, default: 100 },
12
+ maxStepsPerTask: { min: 1, max: 10, default: 10 },
13
+ maxActiveRunsPerOwner: { min: 1, max: 20, default: 3 },
14
+ maxParallelRunsPerTask: { min: 1, max: 1, default: 1 },
15
+ defaultTimeoutMinutes: { min: 1, max: 1440, default: 60 },
16
+ staleRunAfterMinutes: { min: 1, max: 1440, default: 30 },
17
+ historyRetentionDays: { min: 1, max: 3650, default: 90 },
18
+ maxSummaryChars: { min: 100, max: 10000, default: 2000 },
19
+ };
20
+ export const Config = Schema.object({
21
+ maxTasksPerOwner: Schema.number()
22
+ .min(1)
23
+ .max(1000)
24
+ .default(100)
25
+ .description('每个 Session 允许保留的未归档任务上限(1–1000)。'),
26
+ maxStepsPerTask: Schema.number()
27
+ .min(1)
28
+ .max(10)
29
+ .default(10)
30
+ .description('单个任务的步骤上限,V1.0 固定为线性 1–10 步。'),
31
+ maxActiveRunsPerOwner: Schema.number()
32
+ .min(1)
33
+ .max(20)
34
+ .default(3)
35
+ .description('每个 Session 同时处于 queued/running 的 TaskRun 上限(1–20)。'),
36
+ maxParallelRunsPerTask: Schema.number()
37
+ .min(1)
38
+ .max(1)
39
+ .default(1)
40
+ .description('同一任务允许的并行运行数,V1.0 固定为 1。'),
41
+ defaultTimeoutMinutes: Schema.number()
42
+ .min(1)
43
+ .max(1440)
44
+ .default(60)
45
+ .description('运行默认超时(分钟);超时只标记待核验,不自动重启。'),
46
+ staleRunAfterMinutes: Schema.number()
47
+ .min(1)
48
+ .max(1440)
49
+ .default(30)
50
+ .description('启动扫描时,多久没有心跳的 queued/running 运行判定为 interrupted(分钟)。'),
51
+ historyRetentionDays: Schema.number()
52
+ .min(1)
53
+ .max(3650)
54
+ .default(90)
55
+ .description('终态运行记录保留天数(默认 90)。清理永不删除活动运行与任务模板。'),
56
+ maxSummaryChars: Schema.number()
57
+ .min(100)
58
+ .max(10000)
59
+ .default(2000)
60
+ .description('运行/步骤摘要最大字符数(默认 2000),超长截断。'),
61
+ }).description('dsh-background-task-engine 配置(所有数值均有下界/上界校验)。');
62
+ export const DEFAULT_CONFIG = {
63
+ maxTasksPerOwner: CONFIG_LIMITS.maxTasksPerOwner.default,
64
+ maxStepsPerTask: CONFIG_LIMITS.maxStepsPerTask.default,
65
+ maxActiveRunsPerOwner: CONFIG_LIMITS.maxActiveRunsPerOwner.default,
66
+ maxParallelRunsPerTask: CONFIG_LIMITS.maxParallelRunsPerTask.default,
67
+ defaultTimeoutMinutes: CONFIG_LIMITS.defaultTimeoutMinutes.default,
68
+ staleRunAfterMinutes: CONFIG_LIMITS.staleRunAfterMinutes.default,
69
+ historyRetentionDays: CONFIG_LIMITS.historyRetentionDays.default,
70
+ maxSummaryChars: CONFIG_LIMITS.maxSummaryChars.default,
71
+ };
72
+ function readNumber(source, key) {
73
+ const limits = CONFIG_LIMITS[key];
74
+ const raw = source[key];
75
+ if (raw === undefined || raw === null)
76
+ return limits.default;
77
+ const value = typeof raw === 'string' ? Number(raw) : raw;
78
+ if (typeof value !== 'number' || !Number.isFinite(value) || !Number.isInteger(value)) {
79
+ throw new Error(`配置项 ${key} 必须是整数,收到 ${JSON.stringify(raw)}`);
80
+ }
81
+ if (value < limits.min || value > limits.max) {
82
+ throw new Error(`配置项 ${key} 超出允许范围 ${limits.min}–${limits.max},收到 ${value}`);
83
+ }
84
+ return value;
85
+ }
86
+ /**
87
+ * Validate a raw config object. Throws (with a message naming the key and the
88
+ * allowed range) instead of clamping, so a misconfigured profile fails loudly.
89
+ */
90
+ export function resolveConfig(raw) {
91
+ if (raw === undefined || raw === null)
92
+ return { ...DEFAULT_CONFIG };
93
+ if (typeof raw !== 'object')
94
+ throw new Error('配置必须是对象');
95
+ const source = raw;
96
+ return {
97
+ maxTasksPerOwner: readNumber(source, 'maxTasksPerOwner'),
98
+ maxStepsPerTask: readNumber(source, 'maxStepsPerTask'),
99
+ maxActiveRunsPerOwner: readNumber(source, 'maxActiveRunsPerOwner'),
100
+ maxParallelRunsPerTask: readNumber(source, 'maxParallelRunsPerTask'),
101
+ defaultTimeoutMinutes: readNumber(source, 'defaultTimeoutMinutes'),
102
+ staleRunAfterMinutes: readNumber(source, 'staleRunAfterMinutes'),
103
+ historyRetentionDays: readNumber(source, 'historyRetentionDays'),
104
+ maxSummaryChars: readNumber(source, 'maxSummaryChars'),
105
+ };
106
+ }
@@ -0,0 +1,543 @@
1
+ /**
2
+ * Persisted record schemas (PRD 5.x, 7.3).
3
+ *
4
+ * Everything written to the StorageDomain is validated by these zod schemas
5
+ * before it is stored and again when the domain is opened, so a corrupted or
6
+ * hand-edited record fails loudly instead of silently degrading behaviour.
7
+ */
8
+ import { z } from 'zod';
9
+ /** Bumped only when the persisted shape changes; drives the migration runner. */
10
+ export declare const SCHEMA_VERSION = 1;
11
+ /**
12
+ * StorageDomain unit name.
13
+ *
14
+ * The host's `UNIT_NAME_RE` is `/^[a-z][a-z0-9_]*$/` (verified against the
15
+ * installed @deepseek-ai/dsh-storage), so the domain id uses underscores even
16
+ * though the npm package name uses hyphens. The two are deliberately different
17
+ * values: the package name is the npm identity, this is the storage unit.
18
+ */
19
+ export declare const DOMAIN_NAME = "dsh_background_task_engine";
20
+ export declare const TASK_STATUSES: readonly ["active", "paused", "archived"];
21
+ export declare const RUN_STATUSES: readonly ["queued", "running", "blocked", "succeeded", "failed", "interrupted", "skipped"];
22
+ export declare const STEP_STATUSES: readonly ["pending", "running", "completed", "failed", "skipped"];
23
+ export declare const TRIGGER_TYPES: readonly ["manual", "schedule"];
24
+ export type TaskStatus = (typeof TASK_STATUSES)[number];
25
+ export type RunStatus = (typeof RUN_STATUSES)[number];
26
+ export type StepStatus = (typeof STEP_STATUSES)[number];
27
+ export type TriggerType = (typeof TRIGGER_TYPES)[number];
28
+ export declare const stepErrorSchema: z.ZodObject<{
29
+ code: z.ZodString;
30
+ message: z.ZodString;
31
+ }, "strip", z.ZodTypeAny, {
32
+ code: string;
33
+ message: string;
34
+ }, {
35
+ code: string;
36
+ message: string;
37
+ }>;
38
+ export declare const stepDefinitionSchema: z.ZodObject<{
39
+ stepId: z.ZodString;
40
+ title: z.ZodString;
41
+ instruction: z.ZodString;
42
+ completionCriteria: z.ZodOptional<z.ZodString>;
43
+ order: z.ZodNumber;
44
+ required: z.ZodBoolean;
45
+ }, "strip", z.ZodTypeAny, {
46
+ title: string;
47
+ stepId: string;
48
+ instruction: string;
49
+ order: number;
50
+ required: boolean;
51
+ completionCriteria?: string | undefined;
52
+ }, {
53
+ title: string;
54
+ stepId: string;
55
+ instruction: string;
56
+ order: number;
57
+ required: boolean;
58
+ completionCriteria?: string | undefined;
59
+ }>;
60
+ export type StepDefinition = z.infer<typeof stepDefinitionSchema>;
61
+ export declare const scheduleRefSchema: z.ZodObject<{
62
+ scheduleId: z.ZodString;
63
+ /** Original timing kind requested by the user (at / every / rrule). */
64
+ timingKind: z.ZodString;
65
+ timing: z.ZodRecord<z.ZodString, z.ZodUnknown>;
66
+ state: z.ZodEnum<["active", "paused", "unlinked"]>;
67
+ title: z.ZodString;
68
+ createdAt: z.ZodString;
69
+ updatedAt: z.ZodString;
70
+ lastError: z.ZodOptional<z.ZodObject<{
71
+ code: z.ZodString;
72
+ message: z.ZodString;
73
+ }, "strip", z.ZodTypeAny, {
74
+ code: string;
75
+ message: string;
76
+ }, {
77
+ code: string;
78
+ message: string;
79
+ }>>;
80
+ }, "strip", z.ZodTypeAny, {
81
+ title: string;
82
+ createdAt: string;
83
+ updatedAt: string;
84
+ scheduleId: string;
85
+ timingKind: string;
86
+ timing: Record<string, unknown>;
87
+ state: "active" | "paused" | "unlinked";
88
+ lastError?: {
89
+ code: string;
90
+ message: string;
91
+ } | undefined;
92
+ }, {
93
+ title: string;
94
+ createdAt: string;
95
+ updatedAt: string;
96
+ scheduleId: string;
97
+ timingKind: string;
98
+ timing: Record<string, unknown>;
99
+ state: "active" | "paused" | "unlinked";
100
+ lastError?: {
101
+ code: string;
102
+ message: string;
103
+ } | undefined;
104
+ }>;
105
+ export type ScheduleRef = z.infer<typeof scheduleRefSchema>;
106
+ export declare const taskRecordSchema: z.ZodObject<{
107
+ taskId: z.ZodString;
108
+ title: z.ZodString;
109
+ description: z.ZodOptional<z.ZodString>;
110
+ status: z.ZodEnum<["active", "paused", "archived"]>;
111
+ revision: z.ZodNumber;
112
+ ownerSessionId: z.ZodString;
113
+ steps: z.ZodArray<z.ZodObject<{
114
+ stepId: z.ZodString;
115
+ title: z.ZodString;
116
+ instruction: z.ZodString;
117
+ completionCriteria: z.ZodOptional<z.ZodString>;
118
+ order: z.ZodNumber;
119
+ required: z.ZodBoolean;
120
+ }, "strip", z.ZodTypeAny, {
121
+ title: string;
122
+ stepId: string;
123
+ instruction: string;
124
+ order: number;
125
+ required: boolean;
126
+ completionCriteria?: string | undefined;
127
+ }, {
128
+ title: string;
129
+ stepId: string;
130
+ instruction: string;
131
+ order: number;
132
+ required: boolean;
133
+ completionCriteria?: string | undefined;
134
+ }>, "many">;
135
+ scheduleRef: z.ZodOptional<z.ZodObject<{
136
+ scheduleId: z.ZodString;
137
+ /** Original timing kind requested by the user (at / every / rrule). */
138
+ timingKind: z.ZodString;
139
+ timing: z.ZodRecord<z.ZodString, z.ZodUnknown>;
140
+ state: z.ZodEnum<["active", "paused", "unlinked"]>;
141
+ title: z.ZodString;
142
+ createdAt: z.ZodString;
143
+ updatedAt: z.ZodString;
144
+ lastError: z.ZodOptional<z.ZodObject<{
145
+ code: z.ZodString;
146
+ message: z.ZodString;
147
+ }, "strip", z.ZodTypeAny, {
148
+ code: string;
149
+ message: string;
150
+ }, {
151
+ code: string;
152
+ message: string;
153
+ }>>;
154
+ }, "strip", z.ZodTypeAny, {
155
+ title: string;
156
+ createdAt: string;
157
+ updatedAt: string;
158
+ scheduleId: string;
159
+ timingKind: string;
160
+ timing: Record<string, unknown>;
161
+ state: "active" | "paused" | "unlinked";
162
+ lastError?: {
163
+ code: string;
164
+ message: string;
165
+ } | undefined;
166
+ }, {
167
+ title: string;
168
+ createdAt: string;
169
+ updatedAt: string;
170
+ scheduleId: string;
171
+ timingKind: string;
172
+ timing: Record<string, unknown>;
173
+ state: "active" | "paused" | "unlinked";
174
+ lastError?: {
175
+ code: string;
176
+ message: string;
177
+ } | undefined;
178
+ }>>;
179
+ createdAt: z.ZodString;
180
+ updatedAt: z.ZodString;
181
+ schemaVersion: z.ZodNumber;
182
+ }, "strip", z.ZodTypeAny, {
183
+ title: string;
184
+ status: "active" | "paused" | "archived";
185
+ createdAt: string;
186
+ updatedAt: string;
187
+ taskId: string;
188
+ revision: number;
189
+ ownerSessionId: string;
190
+ steps: {
191
+ title: string;
192
+ stepId: string;
193
+ instruction: string;
194
+ order: number;
195
+ required: boolean;
196
+ completionCriteria?: string | undefined;
197
+ }[];
198
+ schemaVersion: number;
199
+ description?: string | undefined;
200
+ scheduleRef?: {
201
+ title: string;
202
+ createdAt: string;
203
+ updatedAt: string;
204
+ scheduleId: string;
205
+ timingKind: string;
206
+ timing: Record<string, unknown>;
207
+ state: "active" | "paused" | "unlinked";
208
+ lastError?: {
209
+ code: string;
210
+ message: string;
211
+ } | undefined;
212
+ } | undefined;
213
+ }, {
214
+ title: string;
215
+ status: "active" | "paused" | "archived";
216
+ createdAt: string;
217
+ updatedAt: string;
218
+ taskId: string;
219
+ revision: number;
220
+ ownerSessionId: string;
221
+ steps: {
222
+ title: string;
223
+ stepId: string;
224
+ instruction: string;
225
+ order: number;
226
+ required: boolean;
227
+ completionCriteria?: string | undefined;
228
+ }[];
229
+ schemaVersion: number;
230
+ description?: string | undefined;
231
+ scheduleRef?: {
232
+ title: string;
233
+ createdAt: string;
234
+ updatedAt: string;
235
+ scheduleId: string;
236
+ timingKind: string;
237
+ timing: Record<string, unknown>;
238
+ state: "active" | "paused" | "unlinked";
239
+ lastError?: {
240
+ code: string;
241
+ message: string;
242
+ } | undefined;
243
+ } | undefined;
244
+ }>;
245
+ export type TaskRecord = z.infer<typeof taskRecordSchema>;
246
+ export declare const templateSnapshotSchema: z.ZodObject<{
247
+ revision: z.ZodNumber;
248
+ title: z.ZodString;
249
+ steps: z.ZodArray<z.ZodObject<{
250
+ stepId: z.ZodString;
251
+ title: z.ZodString;
252
+ instruction: z.ZodString;
253
+ completionCriteria: z.ZodOptional<z.ZodString>;
254
+ order: z.ZodNumber;
255
+ required: z.ZodBoolean;
256
+ }, "strip", z.ZodTypeAny, {
257
+ title: string;
258
+ stepId: string;
259
+ instruction: string;
260
+ order: number;
261
+ required: boolean;
262
+ completionCriteria?: string | undefined;
263
+ }, {
264
+ title: string;
265
+ stepId: string;
266
+ instruction: string;
267
+ order: number;
268
+ required: boolean;
269
+ completionCriteria?: string | undefined;
270
+ }>, "many">;
271
+ }, "strip", z.ZodTypeAny, {
272
+ title: string;
273
+ revision: number;
274
+ steps: {
275
+ title: string;
276
+ stepId: string;
277
+ instruction: string;
278
+ order: number;
279
+ required: boolean;
280
+ completionCriteria?: string | undefined;
281
+ }[];
282
+ }, {
283
+ title: string;
284
+ revision: number;
285
+ steps: {
286
+ title: string;
287
+ stepId: string;
288
+ instruction: string;
289
+ order: number;
290
+ required: boolean;
291
+ completionCriteria?: string | undefined;
292
+ }[];
293
+ }>;
294
+ export type TemplateSnapshot = z.infer<typeof templateSnapshotSchema>;
295
+ export declare const runRecordSchema: z.ZodObject<{
296
+ runId: z.ZodString;
297
+ taskId: z.ZodString;
298
+ taskRevision: z.ZodNumber;
299
+ /** Owner of the task; every tool entry point compares this with the caller. */
300
+ taskOwnerSessionId: z.ZodString;
301
+ /** Session that started the run (equals owner in V1.0). */
302
+ sessionId: z.ZodString;
303
+ status: z.ZodEnum<["queued", "running", "blocked", "succeeded", "failed", "interrupted", "skipped"]>;
304
+ triggerType: z.ZodEnum<["manual", "schedule"]>;
305
+ scheduleId: z.ZodOptional<z.ZodString>;
306
+ occurrenceKey: z.ZodOptional<z.ZodString>;
307
+ idempotencyKey: z.ZodOptional<z.ZodString>;
308
+ currentStepId: z.ZodOptional<z.ZodString>;
309
+ progress: z.ZodNumber;
310
+ requiredTotal: z.ZodNumber;
311
+ requiredCompleted: z.ZodNumber;
312
+ totalSteps: z.ZodNumber;
313
+ startedAt: z.ZodString;
314
+ updatedAt: z.ZodString;
315
+ finishedAt: z.ZodOptional<z.ZodString>;
316
+ summary: z.ZodOptional<z.ZodString>;
317
+ error: z.ZodOptional<z.ZodObject<{
318
+ code: z.ZodString;
319
+ message: z.ZodString;
320
+ }, "strip", z.ZodTypeAny, {
321
+ code: string;
322
+ message: string;
323
+ }, {
324
+ code: string;
325
+ message: string;
326
+ }>>;
327
+ resumesRunId: z.ZodOptional<z.ZodString>;
328
+ templateSnapshot: z.ZodObject<{
329
+ revision: z.ZodNumber;
330
+ title: z.ZodString;
331
+ steps: z.ZodArray<z.ZodObject<{
332
+ stepId: z.ZodString;
333
+ title: z.ZodString;
334
+ instruction: z.ZodString;
335
+ completionCriteria: z.ZodOptional<z.ZodString>;
336
+ order: z.ZodNumber;
337
+ required: z.ZodBoolean;
338
+ }, "strip", z.ZodTypeAny, {
339
+ title: string;
340
+ stepId: string;
341
+ instruction: string;
342
+ order: number;
343
+ required: boolean;
344
+ completionCriteria?: string | undefined;
345
+ }, {
346
+ title: string;
347
+ stepId: string;
348
+ instruction: string;
349
+ order: number;
350
+ required: boolean;
351
+ completionCriteria?: string | undefined;
352
+ }>, "many">;
353
+ }, "strip", z.ZodTypeAny, {
354
+ title: string;
355
+ revision: number;
356
+ steps: {
357
+ title: string;
358
+ stepId: string;
359
+ instruction: string;
360
+ order: number;
361
+ required: boolean;
362
+ completionCriteria?: string | undefined;
363
+ }[];
364
+ }, {
365
+ title: string;
366
+ revision: number;
367
+ steps: {
368
+ title: string;
369
+ stepId: string;
370
+ instruction: string;
371
+ order: number;
372
+ required: boolean;
373
+ completionCriteria?: string | undefined;
374
+ }[];
375
+ }>;
376
+ schemaVersion: z.ZodNumber;
377
+ }, "strip", z.ZodTypeAny, {
378
+ status: "queued" | "running" | "blocked" | "succeeded" | "failed" | "interrupted" | "skipped";
379
+ updatedAt: string;
380
+ taskId: string;
381
+ schemaVersion: number;
382
+ runId: string;
383
+ taskRevision: number;
384
+ taskOwnerSessionId: string;
385
+ sessionId: string;
386
+ triggerType: "manual" | "schedule";
387
+ progress: number;
388
+ requiredTotal: number;
389
+ requiredCompleted: number;
390
+ totalSteps: number;
391
+ startedAt: string;
392
+ templateSnapshot: {
393
+ title: string;
394
+ revision: number;
395
+ steps: {
396
+ title: string;
397
+ stepId: string;
398
+ instruction: string;
399
+ order: number;
400
+ required: boolean;
401
+ completionCriteria?: string | undefined;
402
+ }[];
403
+ };
404
+ scheduleId?: string | undefined;
405
+ occurrenceKey?: string | undefined;
406
+ idempotencyKey?: string | undefined;
407
+ currentStepId?: string | undefined;
408
+ finishedAt?: string | undefined;
409
+ summary?: string | undefined;
410
+ error?: {
411
+ code: string;
412
+ message: string;
413
+ } | undefined;
414
+ resumesRunId?: string | undefined;
415
+ }, {
416
+ status: "queued" | "running" | "blocked" | "succeeded" | "failed" | "interrupted" | "skipped";
417
+ updatedAt: string;
418
+ taskId: string;
419
+ schemaVersion: number;
420
+ runId: string;
421
+ taskRevision: number;
422
+ taskOwnerSessionId: string;
423
+ sessionId: string;
424
+ triggerType: "manual" | "schedule";
425
+ progress: number;
426
+ requiredTotal: number;
427
+ requiredCompleted: number;
428
+ totalSteps: number;
429
+ startedAt: string;
430
+ templateSnapshot: {
431
+ title: string;
432
+ revision: number;
433
+ steps: {
434
+ title: string;
435
+ stepId: string;
436
+ instruction: string;
437
+ order: number;
438
+ required: boolean;
439
+ completionCriteria?: string | undefined;
440
+ }[];
441
+ };
442
+ scheduleId?: string | undefined;
443
+ occurrenceKey?: string | undefined;
444
+ idempotencyKey?: string | undefined;
445
+ currentStepId?: string | undefined;
446
+ finishedAt?: string | undefined;
447
+ summary?: string | undefined;
448
+ error?: {
449
+ code: string;
450
+ message: string;
451
+ } | undefined;
452
+ resumesRunId?: string | undefined;
453
+ }>;
454
+ export type RunRecord = z.infer<typeof runRecordSchema>;
455
+ export declare const runStepRecordSchema: z.ZodObject<{
456
+ runId: z.ZodString;
457
+ stepId: z.ZodString;
458
+ taskId: z.ZodString;
459
+ order: z.ZodNumber;
460
+ title: z.ZodString;
461
+ required: z.ZodBoolean;
462
+ status: z.ZodEnum<["pending", "running", "completed", "failed", "skipped"]>;
463
+ attempt: z.ZodNumber;
464
+ startedAt: z.ZodOptional<z.ZodString>;
465
+ finishedAt: z.ZodOptional<z.ZodString>;
466
+ summary: z.ZodOptional<z.ZodString>;
467
+ error: z.ZodOptional<z.ZodObject<{
468
+ code: z.ZodString;
469
+ message: z.ZodString;
470
+ }, "strip", z.ZodTypeAny, {
471
+ code: string;
472
+ message: string;
473
+ }, {
474
+ code: string;
475
+ message: string;
476
+ }>>;
477
+ /** Set when a resume carries a completed step over into the new run. */
478
+ carryOverFromRunId: z.ZodOptional<z.ZodString>;
479
+ updatedAt: z.ZodString;
480
+ }, "strip", z.ZodTypeAny, {
481
+ title: string;
482
+ status: "running" | "failed" | "skipped" | "pending" | "completed";
483
+ updatedAt: string;
484
+ stepId: string;
485
+ order: number;
486
+ required: boolean;
487
+ taskId: string;
488
+ runId: string;
489
+ attempt: number;
490
+ startedAt?: string | undefined;
491
+ finishedAt?: string | undefined;
492
+ summary?: string | undefined;
493
+ error?: {
494
+ code: string;
495
+ message: string;
496
+ } | undefined;
497
+ carryOverFromRunId?: string | undefined;
498
+ }, {
499
+ title: string;
500
+ status: "running" | "failed" | "skipped" | "pending" | "completed";
501
+ updatedAt: string;
502
+ stepId: string;
503
+ order: number;
504
+ required: boolean;
505
+ taskId: string;
506
+ runId: string;
507
+ attempt: number;
508
+ startedAt?: string | undefined;
509
+ finishedAt?: string | undefined;
510
+ summary?: string | undefined;
511
+ error?: {
512
+ code: string;
513
+ message: string;
514
+ } | undefined;
515
+ carryOverFromRunId?: string | undefined;
516
+ }>;
517
+ export type RunStepRecord = z.infer<typeof runStepRecordSchema>;
518
+ export declare const globalStateSchema: z.ZodObject<{
519
+ schemaVersion: z.ZodNumber;
520
+ /** migrationId -> ISO timestamp; presence means "already applied". */
521
+ appliedMigrations: z.ZodRecord<z.ZodString, z.ZodString>;
522
+ lastRecoveryScanAt: z.ZodOptional<z.ZodString>;
523
+ lastPruneAt: z.ZodOptional<z.ZodString>;
524
+ }, "strip", z.ZodTypeAny, {
525
+ schemaVersion: number;
526
+ appliedMigrations: Record<string, string>;
527
+ lastRecoveryScanAt?: string | undefined;
528
+ lastPruneAt?: string | undefined;
529
+ }, {
530
+ schemaVersion: number;
531
+ appliedMigrations: Record<string, string>;
532
+ lastRecoveryScanAt?: string | undefined;
533
+ lastPruneAt?: string | undefined;
534
+ }>;
535
+ export type GlobalState = z.infer<typeof globalStateSchema>;
536
+ /** Table names, kept in one place so spec and repository cannot drift. */
537
+ export declare const TABLES: {
538
+ readonly tasks: "tasks";
539
+ readonly runs: "task_runs";
540
+ readonly steps: "task_run_steps";
541
+ };
542
+ /** Composite key for one step record: one row per (runId, stepId). */
543
+ export declare function stepKey(runId: string, stepId: string): string;