@lumenflow/core 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/LICENSE +190 -0
- package/README.md +119 -0
- package/dist/active-wu-detector.d.ts +33 -0
- package/dist/active-wu-detector.js +106 -0
- package/dist/adapters/filesystem-metrics.adapter.d.ts +108 -0
- package/dist/adapters/filesystem-metrics.adapter.js +519 -0
- package/dist/adapters/terminal-renderer.adapter.d.ts +106 -0
- package/dist/adapters/terminal-renderer.adapter.js +337 -0
- package/dist/arg-parser.d.ts +63 -0
- package/dist/arg-parser.js +560 -0
- package/dist/backlog-editor.d.ts +98 -0
- package/dist/backlog-editor.js +179 -0
- package/dist/backlog-generator.d.ts +111 -0
- package/dist/backlog-generator.js +381 -0
- package/dist/backlog-parser.d.ts +45 -0
- package/dist/backlog-parser.js +102 -0
- package/dist/backlog-sync-validator.d.ts +78 -0
- package/dist/backlog-sync-validator.js +294 -0
- package/dist/branch-drift.d.ts +34 -0
- package/dist/branch-drift.js +51 -0
- package/dist/cleanup-install-config.d.ts +33 -0
- package/dist/cleanup-install-config.js +37 -0
- package/dist/cleanup-lock.d.ts +139 -0
- package/dist/cleanup-lock.js +313 -0
- package/dist/code-path-validator.d.ts +146 -0
- package/dist/code-path-validator.js +537 -0
- package/dist/code-paths-overlap.d.ts +55 -0
- package/dist/code-paths-overlap.js +245 -0
- package/dist/commands-logger.d.ts +77 -0
- package/dist/commands-logger.js +254 -0
- package/dist/commit-message-utils.d.ts +25 -0
- package/dist/commit-message-utils.js +41 -0
- package/dist/compliance-parser.d.ts +150 -0
- package/dist/compliance-parser.js +507 -0
- package/dist/constants/backlog-patterns.d.ts +20 -0
- package/dist/constants/backlog-patterns.js +23 -0
- package/dist/constants/dora-constants.d.ts +49 -0
- package/dist/constants/dora-constants.js +53 -0
- package/dist/constants/gate-constants.d.ts +15 -0
- package/dist/constants/gate-constants.js +15 -0
- package/dist/constants/linter-constants.d.ts +16 -0
- package/dist/constants/linter-constants.js +16 -0
- package/dist/constants/tokenizer-constants.d.ts +15 -0
- package/dist/constants/tokenizer-constants.js +15 -0
- package/dist/core/scope-checker.d.ts +97 -0
- package/dist/core/scope-checker.js +163 -0
- package/dist/core/tool-runner.d.ts +161 -0
- package/dist/core/tool-runner.js +393 -0
- package/dist/core/tool.constants.d.ts +105 -0
- package/dist/core/tool.constants.js +101 -0
- package/dist/core/tool.schemas.d.ts +226 -0
- package/dist/core/tool.schemas.js +226 -0
- package/dist/core/worktree-guard.d.ts +130 -0
- package/dist/core/worktree-guard.js +242 -0
- package/dist/coverage-gate.d.ts +108 -0
- package/dist/coverage-gate.js +196 -0
- package/dist/date-utils.d.ts +75 -0
- package/dist/date-utils.js +140 -0
- package/dist/dependency-graph.d.ts +142 -0
- package/dist/dependency-graph.js +550 -0
- package/dist/dependency-guard.d.ts +54 -0
- package/dist/dependency-guard.js +142 -0
- package/dist/dependency-validator.d.ts +105 -0
- package/dist/dependency-validator.js +154 -0
- package/dist/docs-path-validator.d.ts +36 -0
- package/dist/docs-path-validator.js +95 -0
- package/dist/domain/orchestration.constants.d.ts +99 -0
- package/dist/domain/orchestration.constants.js +97 -0
- package/dist/domain/orchestration.schemas.d.ts +280 -0
- package/dist/domain/orchestration.schemas.js +211 -0
- package/dist/domain/orchestration.types.d.ts +133 -0
- package/dist/domain/orchestration.types.js +12 -0
- package/dist/error-handler.d.ts +116 -0
- package/dist/error-handler.js +136 -0
- package/dist/file-classifiers.d.ts +62 -0
- package/dist/file-classifiers.js +108 -0
- package/dist/gates-agent-mode.d.ts +81 -0
- package/dist/gates-agent-mode.js +94 -0
- package/dist/generate-traceability.d.ts +107 -0
- package/dist/generate-traceability.js +411 -0
- package/dist/git-adapter.d.ts +395 -0
- package/dist/git-adapter.js +649 -0
- package/dist/git-staged-validator.d.ts +32 -0
- package/dist/git-staged-validator.js +48 -0
- package/dist/hardcoded-strings.d.ts +61 -0
- package/dist/hardcoded-strings.js +270 -0
- package/dist/incremental-lint.d.ts +78 -0
- package/dist/incremental-lint.js +129 -0
- package/dist/incremental-test.d.ts +39 -0
- package/dist/incremental-test.js +61 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +61 -0
- package/dist/invariants/check-automated-tests.d.ts +50 -0
- package/dist/invariants/check-automated-tests.js +166 -0
- package/dist/invariants-runner.d.ts +103 -0
- package/dist/invariants-runner.js +527 -0
- package/dist/lane-checker.d.ts +50 -0
- package/dist/lane-checker.js +319 -0
- package/dist/lane-inference.d.ts +39 -0
- package/dist/lane-inference.js +195 -0
- package/dist/lane-lock.d.ts +211 -0
- package/dist/lane-lock.js +474 -0
- package/dist/lane-validator.d.ts +48 -0
- package/dist/lane-validator.js +114 -0
- package/dist/logs-lib.d.ts +104 -0
- package/dist/logs-lib.js +207 -0
- package/dist/lumenflow-config-schema.d.ts +272 -0
- package/dist/lumenflow-config-schema.js +207 -0
- package/dist/lumenflow-config.d.ts +95 -0
- package/dist/lumenflow-config.js +236 -0
- package/dist/manual-test-validator.d.ts +80 -0
- package/dist/manual-test-validator.js +200 -0
- package/dist/merge-lock.d.ts +115 -0
- package/dist/merge-lock.js +251 -0
- package/dist/micro-worktree.d.ts +159 -0
- package/dist/micro-worktree.js +427 -0
- package/dist/migration-deployer.d.ts +69 -0
- package/dist/migration-deployer.js +151 -0
- package/dist/orchestration-advisory-loader.d.ts +28 -0
- package/dist/orchestration-advisory-loader.js +87 -0
- package/dist/orchestration-advisory.d.ts +58 -0
- package/dist/orchestration-advisory.js +94 -0
- package/dist/orchestration-di.d.ts +48 -0
- package/dist/orchestration-di.js +57 -0
- package/dist/orchestration-rules.d.ts +57 -0
- package/dist/orchestration-rules.js +201 -0
- package/dist/orphan-detector.d.ts +131 -0
- package/dist/orphan-detector.js +226 -0
- package/dist/path-classifiers.d.ts +57 -0
- package/dist/path-classifiers.js +93 -0
- package/dist/piped-command-detector.d.ts +34 -0
- package/dist/piped-command-detector.js +64 -0
- package/dist/ports/dashboard-renderer.port.d.ts +112 -0
- package/dist/ports/dashboard-renderer.port.js +25 -0
- package/dist/ports/metrics-collector.port.d.ts +132 -0
- package/dist/ports/metrics-collector.port.js +26 -0
- package/dist/process-detector.d.ts +84 -0
- package/dist/process-detector.js +172 -0
- package/dist/prompt-linter.d.ts +72 -0
- package/dist/prompt-linter.js +312 -0
- package/dist/prompt-monitor.d.ts +15 -0
- package/dist/prompt-monitor.js +205 -0
- package/dist/rebase-artifact-cleanup.d.ts +145 -0
- package/dist/rebase-artifact-cleanup.js +433 -0
- package/dist/retry-strategy.d.ts +189 -0
- package/dist/retry-strategy.js +283 -0
- package/dist/risk-detector.d.ts +108 -0
- package/dist/risk-detector.js +252 -0
- package/dist/rollback-utils.d.ts +76 -0
- package/dist/rollback-utils.js +104 -0
- package/dist/section-headings.d.ts +43 -0
- package/dist/section-headings.js +49 -0
- package/dist/spawn-escalation.d.ts +90 -0
- package/dist/spawn-escalation.js +253 -0
- package/dist/spawn-monitor.d.ts +229 -0
- package/dist/spawn-monitor.js +672 -0
- package/dist/spawn-recovery.d.ts +82 -0
- package/dist/spawn-recovery.js +298 -0
- package/dist/spawn-registry-schema.d.ts +98 -0
- package/dist/spawn-registry-schema.js +108 -0
- package/dist/spawn-registry-store.d.ts +146 -0
- package/dist/spawn-registry-store.js +273 -0
- package/dist/spawn-tree.d.ts +121 -0
- package/dist/spawn-tree.js +285 -0
- package/dist/stamp-status-validator.d.ts +84 -0
- package/dist/stamp-status-validator.js +134 -0
- package/dist/stamp-utils.d.ts +100 -0
- package/dist/stamp-utils.js +229 -0
- package/dist/state-machine.d.ts +26 -0
- package/dist/state-machine.js +83 -0
- package/dist/system-map-validator.d.ts +80 -0
- package/dist/system-map-validator.js +272 -0
- package/dist/telemetry.d.ts +80 -0
- package/dist/telemetry.js +213 -0
- package/dist/token-counter.d.ts +51 -0
- package/dist/token-counter.js +145 -0
- package/dist/usecases/get-dashboard-data.usecase.d.ts +52 -0
- package/dist/usecases/get-dashboard-data.usecase.js +61 -0
- package/dist/usecases/get-suggestions.usecase.d.ts +100 -0
- package/dist/usecases/get-suggestions.usecase.js +153 -0
- package/dist/user-normalizer.d.ts +41 -0
- package/dist/user-normalizer.js +141 -0
- package/dist/validators/phi-constants.d.ts +97 -0
- package/dist/validators/phi-constants.js +152 -0
- package/dist/validators/phi-scanner.d.ts +58 -0
- package/dist/validators/phi-scanner.js +215 -0
- package/dist/worktree-ownership.d.ts +50 -0
- package/dist/worktree-ownership.js +74 -0
- package/dist/worktree-scanner.d.ts +103 -0
- package/dist/worktree-scanner.js +168 -0
- package/dist/worktree-symlink.d.ts +99 -0
- package/dist/worktree-symlink.js +359 -0
- package/dist/wu-backlog-updater.d.ts +17 -0
- package/dist/wu-backlog-updater.js +37 -0
- package/dist/wu-checkpoint.d.ts +124 -0
- package/dist/wu-checkpoint.js +233 -0
- package/dist/wu-claim-helpers.d.ts +26 -0
- package/dist/wu-claim-helpers.js +63 -0
- package/dist/wu-claim-resume.d.ts +106 -0
- package/dist/wu-claim-resume.js +276 -0
- package/dist/wu-consistency-checker.d.ts +95 -0
- package/dist/wu-consistency-checker.js +567 -0
- package/dist/wu-constants.d.ts +1275 -0
- package/dist/wu-constants.js +1382 -0
- package/dist/wu-create-validators.d.ts +42 -0
- package/dist/wu-create-validators.js +93 -0
- package/dist/wu-done-branch-only.d.ts +63 -0
- package/dist/wu-done-branch-only.js +191 -0
- package/dist/wu-done-messages.d.ts +119 -0
- package/dist/wu-done-messages.js +185 -0
- package/dist/wu-done-pr.d.ts +72 -0
- package/dist/wu-done-pr.js +174 -0
- package/dist/wu-done-retry-helpers.d.ts +85 -0
- package/dist/wu-done-retry-helpers.js +172 -0
- package/dist/wu-done-ui.d.ts +37 -0
- package/dist/wu-done-ui.js +69 -0
- package/dist/wu-done-validators.d.ts +411 -0
- package/dist/wu-done-validators.js +1229 -0
- package/dist/wu-done-worktree.d.ts +182 -0
- package/dist/wu-done-worktree.js +1097 -0
- package/dist/wu-helpers.d.ts +128 -0
- package/dist/wu-helpers.js +248 -0
- package/dist/wu-lint.d.ts +70 -0
- package/dist/wu-lint.js +234 -0
- package/dist/wu-paths.d.ts +171 -0
- package/dist/wu-paths.js +178 -0
- package/dist/wu-preflight-validators.d.ts +86 -0
- package/dist/wu-preflight-validators.js +251 -0
- package/dist/wu-recovery.d.ts +138 -0
- package/dist/wu-recovery.js +341 -0
- package/dist/wu-repair-core.d.ts +131 -0
- package/dist/wu-repair-core.js +669 -0
- package/dist/wu-schema-normalization.d.ts +17 -0
- package/dist/wu-schema-normalization.js +82 -0
- package/dist/wu-schema.d.ts +793 -0
- package/dist/wu-schema.js +881 -0
- package/dist/wu-spawn-helpers.d.ts +121 -0
- package/dist/wu-spawn-helpers.js +271 -0
- package/dist/wu-spawn.d.ts +158 -0
- package/dist/wu-spawn.js +1306 -0
- package/dist/wu-state-schema.d.ts +213 -0
- package/dist/wu-state-schema.js +156 -0
- package/dist/wu-state-store.d.ts +264 -0
- package/dist/wu-state-store.js +691 -0
- package/dist/wu-status-transition.d.ts +63 -0
- package/dist/wu-status-transition.js +382 -0
- package/dist/wu-status-updater.d.ts +25 -0
- package/dist/wu-status-updater.js +116 -0
- package/dist/wu-transaction-collectors.d.ts +116 -0
- package/dist/wu-transaction-collectors.js +272 -0
- package/dist/wu-transaction.d.ts +170 -0
- package/dist/wu-transaction.js +273 -0
- package/dist/wu-validation-constants.d.ts +60 -0
- package/dist/wu-validation-constants.js +66 -0
- package/dist/wu-validation.d.ts +118 -0
- package/dist/wu-validation.js +243 -0
- package/dist/wu-validator.d.ts +62 -0
- package/dist/wu-validator.js +325 -0
- package/dist/wu-yaml-fixer.d.ts +97 -0
- package/dist/wu-yaml-fixer.js +264 -0
- package/dist/wu-yaml.d.ts +86 -0
- package/dist/wu-yaml.js +222 -0
- package/package.json +114 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU State Schema (WU-1570)
|
|
3
|
+
*
|
|
4
|
+
* Zod schemas for WU state event validation.
|
|
5
|
+
* Defines event types for WU lifecycle: create, claim, block, unblock, complete.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link tools/lib/__tests__/wu-state-store.test.mjs} - Tests
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
/**
|
|
11
|
+
* WU event types
|
|
12
|
+
*
|
|
13
|
+
* - create: WU created (transitions to ready)
|
|
14
|
+
* - claim: WU claimed (transitions to in_progress)
|
|
15
|
+
* - block: WU blocked (transitions to blocked)
|
|
16
|
+
* - unblock: WU unblocked (transitions back to in_progress)
|
|
17
|
+
* - complete: WU completed (transitions to done)
|
|
18
|
+
* - checkpoint: Progress checkpoint (WU-1748: cross-agent visibility)
|
|
19
|
+
* - spawn: WU spawned from parent (WU-1947: parent-child relationships)
|
|
20
|
+
*/
|
|
21
|
+
export declare const WU_EVENT_TYPES: readonly ["create", "claim", "block", "unblock", "complete", "checkpoint", "spawn"];
|
|
22
|
+
/** Type for WU event types */
|
|
23
|
+
export type WUEventType = (typeof WU_EVENT_TYPES)[number];
|
|
24
|
+
/**
|
|
25
|
+
* WU status values (matches LumenFlow state machine)
|
|
26
|
+
*/
|
|
27
|
+
export declare const WU_STATUSES: readonly ["ready", "in_progress", "blocked", "waiting", "done"];
|
|
28
|
+
/** Type for WU status values */
|
|
29
|
+
export type WUStatus = (typeof WU_STATUSES)[number];
|
|
30
|
+
/**
|
|
31
|
+
* Regex patterns for WU validation
|
|
32
|
+
*/
|
|
33
|
+
export declare const WU_PATTERNS: {
|
|
34
|
+
/** WU ID format: WU-{digits} */
|
|
35
|
+
WU_ID: RegExp;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Create event schema
|
|
39
|
+
*/
|
|
40
|
+
export declare const CreateEventSchema: z.ZodObject<{
|
|
41
|
+
wuId: z.ZodString;
|
|
42
|
+
timestamp: z.ZodString;
|
|
43
|
+
type: z.ZodLiteral<"create">;
|
|
44
|
+
lane: z.ZodString;
|
|
45
|
+
title: z.ZodString;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
/**
|
|
48
|
+
* Claim event schema
|
|
49
|
+
*/
|
|
50
|
+
export declare const ClaimEventSchema: z.ZodObject<{
|
|
51
|
+
wuId: z.ZodString;
|
|
52
|
+
timestamp: z.ZodString;
|
|
53
|
+
type: z.ZodLiteral<"claim">;
|
|
54
|
+
lane: z.ZodString;
|
|
55
|
+
title: z.ZodString;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
/**
|
|
58
|
+
* Block event schema
|
|
59
|
+
*/
|
|
60
|
+
export declare const BlockEventSchema: z.ZodObject<{
|
|
61
|
+
wuId: z.ZodString;
|
|
62
|
+
timestamp: z.ZodString;
|
|
63
|
+
type: z.ZodLiteral<"block">;
|
|
64
|
+
reason: z.ZodString;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
/**
|
|
67
|
+
* Unblock event schema
|
|
68
|
+
*/
|
|
69
|
+
export declare const UnblockEventSchema: z.ZodObject<{
|
|
70
|
+
wuId: z.ZodString;
|
|
71
|
+
timestamp: z.ZodString;
|
|
72
|
+
type: z.ZodLiteral<"unblock">;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
/**
|
|
75
|
+
* Complete event schema
|
|
76
|
+
*/
|
|
77
|
+
export declare const CompleteEventSchema: z.ZodObject<{
|
|
78
|
+
wuId: z.ZodString;
|
|
79
|
+
timestamp: z.ZodString;
|
|
80
|
+
type: z.ZodLiteral<"complete">;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
/**
|
|
83
|
+
* Checkpoint event schema (WU-1748: cross-agent visibility)
|
|
84
|
+
* Records progress checkpoints for abandoned WU detection
|
|
85
|
+
*/
|
|
86
|
+
export declare const CheckpointEventSchema: z.ZodObject<{
|
|
87
|
+
wuId: z.ZodString;
|
|
88
|
+
timestamp: z.ZodString;
|
|
89
|
+
type: z.ZodLiteral<"checkpoint">;
|
|
90
|
+
note: z.ZodString;
|
|
91
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
92
|
+
progress: z.ZodOptional<z.ZodString>;
|
|
93
|
+
nextSteps: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
/**
|
|
96
|
+
* Spawn event schema (WU-1947: parent-child relationships)
|
|
97
|
+
* Records WU spawn relationships for tracking parent-child WUs
|
|
98
|
+
*/
|
|
99
|
+
export declare const SpawnEventSchema: z.ZodObject<{
|
|
100
|
+
wuId: z.ZodString;
|
|
101
|
+
timestamp: z.ZodString;
|
|
102
|
+
type: z.ZodLiteral<"spawn">;
|
|
103
|
+
parentWuId: z.ZodString;
|
|
104
|
+
spawnId: z.ZodString;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
/**
|
|
107
|
+
* Union schema for all event types
|
|
108
|
+
*/
|
|
109
|
+
export declare const WUEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
110
|
+
wuId: z.ZodString;
|
|
111
|
+
timestamp: z.ZodString;
|
|
112
|
+
type: z.ZodLiteral<"create">;
|
|
113
|
+
lane: z.ZodString;
|
|
114
|
+
title: z.ZodString;
|
|
115
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
116
|
+
wuId: z.ZodString;
|
|
117
|
+
timestamp: z.ZodString;
|
|
118
|
+
type: z.ZodLiteral<"claim">;
|
|
119
|
+
lane: z.ZodString;
|
|
120
|
+
title: z.ZodString;
|
|
121
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
122
|
+
wuId: z.ZodString;
|
|
123
|
+
timestamp: z.ZodString;
|
|
124
|
+
type: z.ZodLiteral<"block">;
|
|
125
|
+
reason: z.ZodString;
|
|
126
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
127
|
+
wuId: z.ZodString;
|
|
128
|
+
timestamp: z.ZodString;
|
|
129
|
+
type: z.ZodLiteral<"unblock">;
|
|
130
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
131
|
+
wuId: z.ZodString;
|
|
132
|
+
timestamp: z.ZodString;
|
|
133
|
+
type: z.ZodLiteral<"complete">;
|
|
134
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
135
|
+
wuId: z.ZodString;
|
|
136
|
+
timestamp: z.ZodString;
|
|
137
|
+
type: z.ZodLiteral<"checkpoint">;
|
|
138
|
+
note: z.ZodString;
|
|
139
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
140
|
+
progress: z.ZodOptional<z.ZodString>;
|
|
141
|
+
nextSteps: z.ZodOptional<z.ZodString>;
|
|
142
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
143
|
+
wuId: z.ZodString;
|
|
144
|
+
timestamp: z.ZodString;
|
|
145
|
+
type: z.ZodLiteral<"spawn">;
|
|
146
|
+
parentWuId: z.ZodString;
|
|
147
|
+
spawnId: z.ZodString;
|
|
148
|
+
}, z.core.$strip>], "type">;
|
|
149
|
+
/**
|
|
150
|
+
* TypeScript types inferred from schemas
|
|
151
|
+
*/
|
|
152
|
+
export type CreateEvent = z.infer<typeof CreateEventSchema>;
|
|
153
|
+
export type ClaimEvent = z.infer<typeof ClaimEventSchema>;
|
|
154
|
+
export type BlockEvent = z.infer<typeof BlockEventSchema>;
|
|
155
|
+
export type UnblockEvent = z.infer<typeof UnblockEventSchema>;
|
|
156
|
+
export type CompleteEvent = z.infer<typeof CompleteEventSchema>;
|
|
157
|
+
export type CheckpointEvent = z.infer<typeof CheckpointEventSchema>;
|
|
158
|
+
export type SpawnEvent = z.infer<typeof SpawnEventSchema>;
|
|
159
|
+
export type WUEvent = z.infer<typeof WUEventSchema>;
|
|
160
|
+
/**
|
|
161
|
+
* Validates WU event data against schema
|
|
162
|
+
*
|
|
163
|
+
* @param {unknown} data - Data to validate
|
|
164
|
+
* @returns {z.SafeParseReturnType<WUEvent, WUEvent>} Validation result
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* const result = validateWUEvent(eventData);
|
|
168
|
+
* if (!result.success) {
|
|
169
|
+
* result.error.issues.forEach(issue => {
|
|
170
|
+
* console.error(`${issue.path.join('.')}: ${issue.message}`);
|
|
171
|
+
* });
|
|
172
|
+
* }
|
|
173
|
+
*/
|
|
174
|
+
export declare function validateWUEvent(data: any): z.ZodSafeParseResult<{
|
|
175
|
+
wuId: string;
|
|
176
|
+
timestamp: string;
|
|
177
|
+
type: "create";
|
|
178
|
+
lane: string;
|
|
179
|
+
title: string;
|
|
180
|
+
} | {
|
|
181
|
+
wuId: string;
|
|
182
|
+
timestamp: string;
|
|
183
|
+
type: "claim";
|
|
184
|
+
lane: string;
|
|
185
|
+
title: string;
|
|
186
|
+
} | {
|
|
187
|
+
wuId: string;
|
|
188
|
+
timestamp: string;
|
|
189
|
+
type: "block";
|
|
190
|
+
reason: string;
|
|
191
|
+
} | {
|
|
192
|
+
wuId: string;
|
|
193
|
+
timestamp: string;
|
|
194
|
+
type: "unblock";
|
|
195
|
+
} | {
|
|
196
|
+
wuId: string;
|
|
197
|
+
timestamp: string;
|
|
198
|
+
type: "complete";
|
|
199
|
+
} | {
|
|
200
|
+
wuId: string;
|
|
201
|
+
timestamp: string;
|
|
202
|
+
type: "checkpoint";
|
|
203
|
+
note: string;
|
|
204
|
+
sessionId?: string;
|
|
205
|
+
progress?: string;
|
|
206
|
+
nextSteps?: string;
|
|
207
|
+
} | {
|
|
208
|
+
wuId: string;
|
|
209
|
+
timestamp: string;
|
|
210
|
+
type: "spawn";
|
|
211
|
+
parentWuId: string;
|
|
212
|
+
spawnId: string;
|
|
213
|
+
}>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU State Schema (WU-1570)
|
|
3
|
+
*
|
|
4
|
+
* Zod schemas for WU state event validation.
|
|
5
|
+
* Defines event types for WU lifecycle: create, claim, block, unblock, complete.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link tools/lib/__tests__/wu-state-store.test.mjs} - Tests
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
/**
|
|
11
|
+
* WU event types
|
|
12
|
+
*
|
|
13
|
+
* - create: WU created (transitions to ready)
|
|
14
|
+
* - claim: WU claimed (transitions to in_progress)
|
|
15
|
+
* - block: WU blocked (transitions to blocked)
|
|
16
|
+
* - unblock: WU unblocked (transitions back to in_progress)
|
|
17
|
+
* - complete: WU completed (transitions to done)
|
|
18
|
+
* - checkpoint: Progress checkpoint (WU-1748: cross-agent visibility)
|
|
19
|
+
* - spawn: WU spawned from parent (WU-1947: parent-child relationships)
|
|
20
|
+
*/
|
|
21
|
+
export const WU_EVENT_TYPES = [
|
|
22
|
+
'create',
|
|
23
|
+
'claim',
|
|
24
|
+
'block',
|
|
25
|
+
'unblock',
|
|
26
|
+
'complete',
|
|
27
|
+
'checkpoint',
|
|
28
|
+
'spawn',
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* WU status values (matches LumenFlow state machine)
|
|
32
|
+
*/
|
|
33
|
+
export const WU_STATUSES = ['ready', 'in_progress', 'blocked', 'waiting', 'done'];
|
|
34
|
+
/**
|
|
35
|
+
* Regex patterns for WU validation
|
|
36
|
+
*/
|
|
37
|
+
export const WU_PATTERNS = {
|
|
38
|
+
/** WU ID format: WU-{digits} */
|
|
39
|
+
WU_ID: /^WU-\d+$/,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Error messages for schema validation
|
|
43
|
+
*/
|
|
44
|
+
const ERROR_MESSAGES = {
|
|
45
|
+
EVENT_TYPE: `Event type must be one of: ${WU_EVENT_TYPES.join(', ')}`,
|
|
46
|
+
WU_ID: 'WU ID must match pattern WU-XXX (e.g., WU-1570)',
|
|
47
|
+
LANE_REQUIRED: 'Lane is required',
|
|
48
|
+
TITLE_REQUIRED: 'Title is required',
|
|
49
|
+
REASON_REQUIRED: 'Reason is required',
|
|
50
|
+
TIMESTAMP_REQUIRED: 'Timestamp is required',
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Base event schema (common fields for all events)
|
|
54
|
+
*/
|
|
55
|
+
const BaseEventSchema = z.object({
|
|
56
|
+
/** Event type */
|
|
57
|
+
type: z.enum(WU_EVENT_TYPES, {
|
|
58
|
+
error: ERROR_MESSAGES.EVENT_TYPE,
|
|
59
|
+
}),
|
|
60
|
+
/** WU ID */
|
|
61
|
+
wuId: z.string().regex(WU_PATTERNS.WU_ID, { message: ERROR_MESSAGES.WU_ID }),
|
|
62
|
+
/** Event timestamp (ISO 8601 datetime) */
|
|
63
|
+
timestamp: z.string().datetime({ message: ERROR_MESSAGES.TIMESTAMP_REQUIRED }),
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Create event schema
|
|
67
|
+
*/
|
|
68
|
+
export const CreateEventSchema = BaseEventSchema.extend({
|
|
69
|
+
type: z.literal('create'),
|
|
70
|
+
lane: z.string().min(1, { message: ERROR_MESSAGES.LANE_REQUIRED }),
|
|
71
|
+
title: z.string().min(1, { message: ERROR_MESSAGES.TITLE_REQUIRED }),
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Claim event schema
|
|
75
|
+
*/
|
|
76
|
+
export const ClaimEventSchema = BaseEventSchema.extend({
|
|
77
|
+
type: z.literal('claim'),
|
|
78
|
+
lane: z.string().min(1, { message: ERROR_MESSAGES.LANE_REQUIRED }),
|
|
79
|
+
title: z.string().min(1, { message: ERROR_MESSAGES.TITLE_REQUIRED }),
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* Block event schema
|
|
83
|
+
*/
|
|
84
|
+
export const BlockEventSchema = BaseEventSchema.extend({
|
|
85
|
+
type: z.literal('block'),
|
|
86
|
+
reason: z.string().min(1, { message: ERROR_MESSAGES.REASON_REQUIRED }),
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* Unblock event schema
|
|
90
|
+
*/
|
|
91
|
+
export const UnblockEventSchema = BaseEventSchema.extend({
|
|
92
|
+
type: z.literal('unblock'),
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Complete event schema
|
|
96
|
+
*/
|
|
97
|
+
export const CompleteEventSchema = BaseEventSchema.extend({
|
|
98
|
+
type: z.literal('complete'),
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Checkpoint event schema (WU-1748: cross-agent visibility)
|
|
102
|
+
* Records progress checkpoints for abandoned WU detection
|
|
103
|
+
*/
|
|
104
|
+
export const CheckpointEventSchema = BaseEventSchema.extend({
|
|
105
|
+
type: z.literal('checkpoint'),
|
|
106
|
+
/** Checkpoint note/description */
|
|
107
|
+
note: z.string().min(1, { message: 'Checkpoint note is required' }),
|
|
108
|
+
/** Optional session ID */
|
|
109
|
+
sessionId: z.string().optional(),
|
|
110
|
+
/** Optional progress summary */
|
|
111
|
+
progress: z.string().optional(),
|
|
112
|
+
/** Optional next steps */
|
|
113
|
+
nextSteps: z.string().optional(),
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* Spawn event schema (WU-1947: parent-child relationships)
|
|
117
|
+
* Records WU spawn relationships for tracking parent-child WUs
|
|
118
|
+
*/
|
|
119
|
+
export const SpawnEventSchema = BaseEventSchema.extend({
|
|
120
|
+
type: z.literal('spawn'),
|
|
121
|
+
/** Parent WU ID that spawned this WU */
|
|
122
|
+
parentWuId: z
|
|
123
|
+
.string()
|
|
124
|
+
.regex(WU_PATTERNS.WU_ID, { message: 'Parent WU ID must match pattern WU-XXX' }),
|
|
125
|
+
/** Unique spawn identifier */
|
|
126
|
+
spawnId: z.string().min(1, { message: 'Spawn ID is required' }),
|
|
127
|
+
});
|
|
128
|
+
/**
|
|
129
|
+
* Union schema for all event types
|
|
130
|
+
*/
|
|
131
|
+
export const WUEventSchema = z.discriminatedUnion('type', [
|
|
132
|
+
CreateEventSchema,
|
|
133
|
+
ClaimEventSchema,
|
|
134
|
+
BlockEventSchema,
|
|
135
|
+
UnblockEventSchema,
|
|
136
|
+
CompleteEventSchema,
|
|
137
|
+
CheckpointEventSchema,
|
|
138
|
+
SpawnEventSchema,
|
|
139
|
+
]);
|
|
140
|
+
/**
|
|
141
|
+
* Validates WU event data against schema
|
|
142
|
+
*
|
|
143
|
+
* @param {unknown} data - Data to validate
|
|
144
|
+
* @returns {z.SafeParseReturnType<WUEvent, WUEvent>} Validation result
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const result = validateWUEvent(eventData);
|
|
148
|
+
* if (!result.success) {
|
|
149
|
+
* result.error.issues.forEach(issue => {
|
|
150
|
+
* console.error(`${issue.path.join('.')}: ${issue.message}`);
|
|
151
|
+
* });
|
|
152
|
+
* }
|
|
153
|
+
*/
|
|
154
|
+
export function validateWUEvent(data) {
|
|
155
|
+
return WUEventSchema.safeParse(data);
|
|
156
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WU State Store (WU-1570, WU-2240)
|
|
3
|
+
*
|
|
4
|
+
* Event-sourced state store for WU lifecycle following INIT-007 pattern.
|
|
5
|
+
* Stores events in .beacon/state/wu-events.jsonl (append-only, git-friendly).
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Event sourcing with replay for current state
|
|
9
|
+
* - Atomic append operations (WU-2240: temp file + fsync + rename)
|
|
10
|
+
* - O(1) queries by status and lane via in-memory indexes
|
|
11
|
+
* - State machine validation for legal transitions
|
|
12
|
+
* - File locking with stale detection (WU-2240)
|
|
13
|
+
* - Corruption recovery via repairStateFile (WU-2240)
|
|
14
|
+
*
|
|
15
|
+
* @see {@link tools/__tests__/state-store-concurrent.test.mjs} - Concurrent access tests
|
|
16
|
+
* @see {@link tools/lib/wu-state-schema.mjs} - Schema definitions
|
|
17
|
+
*/
|
|
18
|
+
import { type WUEvent } from './wu-state-schema.js';
|
|
19
|
+
/**
|
|
20
|
+
* WU events file name constant
|
|
21
|
+
*/
|
|
22
|
+
export declare const WU_EVENTS_FILE_NAME = "wu-events.jsonl";
|
|
23
|
+
/**
|
|
24
|
+
* WU state entry in the in-memory store
|
|
25
|
+
*/
|
|
26
|
+
export interface WUStateEntry {
|
|
27
|
+
status: string;
|
|
28
|
+
lane: string;
|
|
29
|
+
title: string;
|
|
30
|
+
completedAt?: string;
|
|
31
|
+
lastCheckpoint?: string;
|
|
32
|
+
lastCheckpointNote?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Lock file data structure
|
|
36
|
+
*/
|
|
37
|
+
export interface LockData {
|
|
38
|
+
pid: number;
|
|
39
|
+
timestamp: number;
|
|
40
|
+
hostname: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checkpoint options
|
|
44
|
+
*/
|
|
45
|
+
export interface CheckpointOptions {
|
|
46
|
+
sessionId?: string;
|
|
47
|
+
progress?: string;
|
|
48
|
+
nextSteps?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Repair result
|
|
52
|
+
*/
|
|
53
|
+
export interface RepairResult {
|
|
54
|
+
success: boolean;
|
|
55
|
+
linesKept: number;
|
|
56
|
+
linesRemoved: number;
|
|
57
|
+
backupPath: string | null;
|
|
58
|
+
warnings: string[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* WU State Store class
|
|
62
|
+
*
|
|
63
|
+
* Manages WU lifecycle state via event sourcing pattern.
|
|
64
|
+
* Events are appended to JSONL file, state is rebuilt by replaying events.
|
|
65
|
+
*/
|
|
66
|
+
export declare class WUStateStore {
|
|
67
|
+
private readonly baseDir;
|
|
68
|
+
private readonly eventsFilePath;
|
|
69
|
+
private wuState;
|
|
70
|
+
private byStatus;
|
|
71
|
+
private byLane;
|
|
72
|
+
private byParent;
|
|
73
|
+
constructor(baseDir: string);
|
|
74
|
+
/**
|
|
75
|
+
* Loads and replays events from JSONL file into current state.
|
|
76
|
+
*
|
|
77
|
+
* Handles:
|
|
78
|
+
* - Missing file: returns empty state
|
|
79
|
+
* - Empty file: returns empty state
|
|
80
|
+
* - Empty lines: skipped gracefully
|
|
81
|
+
* - Malformed JSON: throws error with line info
|
|
82
|
+
* - Invalid events: throws validation error
|
|
83
|
+
*
|
|
84
|
+
* @throws Error If file contains malformed JSON or invalid events
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const store = new WUStateStore('/path/to/project');
|
|
88
|
+
* await store.load();
|
|
89
|
+
* const inProgress = store.getByStatus('in_progress');
|
|
90
|
+
*/
|
|
91
|
+
load(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Transition WU to a new status if it exists.
|
|
94
|
+
*/
|
|
95
|
+
private _transitionToStatus;
|
|
96
|
+
/**
|
|
97
|
+
* Applies an event to the in-memory state.
|
|
98
|
+
*/
|
|
99
|
+
private _applyEvent;
|
|
100
|
+
/**
|
|
101
|
+
* Sets WU state and updates indexes.
|
|
102
|
+
*/
|
|
103
|
+
private _setState;
|
|
104
|
+
/**
|
|
105
|
+
* Appends an event to the events file.
|
|
106
|
+
*
|
|
107
|
+
* Uses append mode to avoid full file rewrite.
|
|
108
|
+
* Creates file and parent directories if they don't exist.
|
|
109
|
+
* Validates event before appending.
|
|
110
|
+
*
|
|
111
|
+
* @throws Error If event fails validation
|
|
112
|
+
*/
|
|
113
|
+
private _appendEvent;
|
|
114
|
+
/**
|
|
115
|
+
* Claims a WU (transitions to in_progress).
|
|
116
|
+
*
|
|
117
|
+
* @throws Error If WU is already in_progress
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* await store.claim('WU-1570', 'Operations: Tooling', 'Test WU');
|
|
121
|
+
*/
|
|
122
|
+
claim(wuId: string, lane: string, title: string): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Completes a WU (transitions to done).
|
|
125
|
+
*
|
|
126
|
+
* @throws Error If WU is not in_progress
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* await store.complete('WU-1570');
|
|
130
|
+
*/
|
|
131
|
+
complete(wuId: string): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Get current in-memory state for a WU.
|
|
134
|
+
*/
|
|
135
|
+
getWUState(wuId: string): WUStateEntry | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Create a complete event without writing to disk.
|
|
138
|
+
*
|
|
139
|
+
* Used by transactional flows where event log writes are staged and committed atomically.
|
|
140
|
+
*
|
|
141
|
+
* @throws Error If WU is not in_progress or event fails validation
|
|
142
|
+
*/
|
|
143
|
+
createCompleteEvent(wuId: string, timestamp?: string): WUEvent;
|
|
144
|
+
/**
|
|
145
|
+
* Apply a validated event to in-memory state without writing to disk.
|
|
146
|
+
*
|
|
147
|
+
* @throws Error If event fails validation
|
|
148
|
+
*/
|
|
149
|
+
applyEvent(event: WUEvent): void;
|
|
150
|
+
/**
|
|
151
|
+
* Blocks a WU (transitions to blocked).
|
|
152
|
+
*
|
|
153
|
+
* @throws Error If WU is not in_progress
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* await store.block('WU-1570', 'Blocked by dependency');
|
|
157
|
+
*/
|
|
158
|
+
block(wuId: string, reason: string): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Unblocks a WU (transitions back to in_progress).
|
|
161
|
+
*
|
|
162
|
+
* @throws Error If WU is not blocked
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* await store.unblock('WU-1570');
|
|
166
|
+
*/
|
|
167
|
+
unblock(wuId: string): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Records a checkpoint for a WU (WU-1748: cross-agent visibility).
|
|
170
|
+
*
|
|
171
|
+
* Checkpoints are recorded for visibility but don't change WU state.
|
|
172
|
+
* Used to track progress and detect abandoned WUs.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* await store.checkpoint('WU-1748', 'Completed worktree scanner', {
|
|
176
|
+
* progress: 'Scanner implemented and tests passing',
|
|
177
|
+
* nextSteps: 'Integrate into orchestrate:status'
|
|
178
|
+
* });
|
|
179
|
+
*/
|
|
180
|
+
checkpoint(wuId: string, note: string, options?: CheckpointOptions): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Gets WU IDs by status (O(1) lookup).
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* const inProgress = store.getByStatus('in_progress');
|
|
186
|
+
* for (const wuId of inProgress) {
|
|
187
|
+
* console.log(wuId);
|
|
188
|
+
* }
|
|
189
|
+
*/
|
|
190
|
+
getByStatus(status: string): Set<string>;
|
|
191
|
+
/**
|
|
192
|
+
* Gets WU IDs by lane (O(1) lookup).
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* const tooling = store.getByLane('Operations: Tooling');
|
|
196
|
+
* for (const wuId of tooling) {
|
|
197
|
+
* console.log(wuId);
|
|
198
|
+
* }
|
|
199
|
+
*/
|
|
200
|
+
getByLane(lane: string): Set<string>;
|
|
201
|
+
/**
|
|
202
|
+
* Gets child WU IDs spawned from a parent WU (O(1) lookup).
|
|
203
|
+
* WU-1947: Parent-child relationship tracking.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* const children = store.getChildWUs('WU-100');
|
|
207
|
+
* for (const childId of children) {
|
|
208
|
+
* console.log(`Child WU: ${childId}`);
|
|
209
|
+
* }
|
|
210
|
+
*/
|
|
211
|
+
getChildWUs(parentWuId: string): Set<string>;
|
|
212
|
+
/**
|
|
213
|
+
* Records a spawn relationship between parent and child WUs.
|
|
214
|
+
* WU-1947: Parent-child relationship tracking.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* await store.spawn('WU-200', 'WU-100', 'spawn-abc123');
|
|
218
|
+
*/
|
|
219
|
+
spawn(childWuId: string, parentWuId: string, spawnId: string): Promise<void>;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Check if a lock is stale (expired or dead process)
|
|
223
|
+
*
|
|
224
|
+
* WU-2240: Prepared for proper-lockfile integration
|
|
225
|
+
*/
|
|
226
|
+
export declare function isLockStale(lockData: LockData): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Acquire a file lock for the events file
|
|
229
|
+
*
|
|
230
|
+
* Uses a JSON lock file containing PID, timestamp, and hostname.
|
|
231
|
+
* Implements stale lock detection via:
|
|
232
|
+
* - PID check (on same host)
|
|
233
|
+
* - 5-minute timeout (across hosts)
|
|
234
|
+
*
|
|
235
|
+
* WU-2240: Prepared for proper-lockfile integration
|
|
236
|
+
*
|
|
237
|
+
* @throws Error If lock cannot be acquired after retries
|
|
238
|
+
*/
|
|
239
|
+
export declare function acquireLock(lockPath: string): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Release a file lock
|
|
242
|
+
*
|
|
243
|
+
* WU-2240: Prepared for proper-lockfile integration
|
|
244
|
+
*/
|
|
245
|
+
export declare function releaseLock(lockPath: string): void;
|
|
246
|
+
/**
|
|
247
|
+
* Repair a corrupted state file by removing invalid lines.
|
|
248
|
+
*
|
|
249
|
+
* WU-2240: Corruption recovery for wu-events.jsonl
|
|
250
|
+
*
|
|
251
|
+
* Features:
|
|
252
|
+
* - Creates backup before repair
|
|
253
|
+
* - Removes malformed JSON lines
|
|
254
|
+
* - Removes lines that fail schema validation
|
|
255
|
+
* - Returns detailed repair statistics
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* const stateFilePath = path.join(process.cwd(), '.beacon', 'state', 'wu-events.jsonl');
|
|
259
|
+
* const result = await repairStateFile(stateFilePath);
|
|
260
|
+
* if (result.success) {
|
|
261
|
+
* console.log(`Repaired: kept ${result.linesKept}, removed ${result.linesRemoved}`);
|
|
262
|
+
* }
|
|
263
|
+
*/
|
|
264
|
+
export declare function repairStateFile(filePath: string): Promise<RepairResult>;
|