@lumenflow/cli 3.12.6 → 3.12.8

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 (111) hide show
  1. package/dist/config-set.js +82 -32
  2. package/dist/config-set.js.map +1 -1
  3. package/dist/wu-claim.js +2 -1
  4. package/dist/wu-claim.js.map +1 -1
  5. package/dist/wu-done-policies.js +9 -9
  6. package/dist/wu-done-policies.js.map +1 -1
  7. package/dist/wu-spawn-strategy-resolver.js +14 -6
  8. package/dist/wu-spawn-strategy-resolver.js.map +1 -1
  9. package/package.json +8 -8
  10. package/packs/sidekick/.turbo/turbo-build.log +1 -1
  11. package/packs/sidekick/package.json +1 -1
  12. package/packs/software-delivery/.turbo/turbo-build.log +1 -1
  13. package/packs/software-delivery/package.json +1 -1
  14. package/dist/chunk-2D2VOCA4.js +0 -37
  15. package/dist/chunk-2D5KFYGX.js +0 -284
  16. package/dist/chunk-2GXVIN57.js +0 -14072
  17. package/dist/chunk-2MQ7HZWZ.js +0 -26
  18. package/dist/chunk-2UFQ3A3C.js +0 -643
  19. package/dist/chunk-3RG5ZIWI.js +0 -10
  20. package/dist/chunk-4N74J3UT.js +0 -15
  21. package/dist/chunk-5GTOXFYR.js +0 -392
  22. package/dist/chunk-5VY6MQMC.js +0 -240
  23. package/dist/chunk-67XVPMRY.js +0 -1297
  24. package/dist/chunk-6HO4GWJE.js +0 -164
  25. package/dist/chunk-6W5XHWYV.js +0 -1890
  26. package/dist/chunk-6X4EMYJQ.js +0 -64
  27. package/dist/chunk-6XYXI2NQ.js +0 -772
  28. package/dist/chunk-7ANSOV6Q.js +0 -285
  29. package/dist/chunk-A624LFLB.js +0 -1380
  30. package/dist/chunk-ADN5NHG4.js +0 -126
  31. package/dist/chunk-B7YJYJKG.js +0 -33
  32. package/dist/chunk-CCLHCPKG.js +0 -210
  33. package/dist/chunk-CK36VROC.js +0 -1584
  34. package/dist/chunk-D3UOFRSB.js +0 -81
  35. package/dist/chunk-DFR4DJBM.js +0 -230
  36. package/dist/chunk-DSYBDHYH.js +0 -79
  37. package/dist/chunk-DWMLTXKQ.js +0 -1176
  38. package/dist/chunk-E3REJTAJ.js +0 -28
  39. package/dist/chunk-EA3IVO64.js +0 -633
  40. package/dist/chunk-EK2AKZKD.js +0 -55
  41. package/dist/chunk-ELD7JTTT.js +0 -343
  42. package/dist/chunk-EX6TT2XI.js +0 -195
  43. package/dist/chunk-EXINSFZE.js +0 -82
  44. package/dist/chunk-EZ6ZBYBM.js +0 -510
  45. package/dist/chunk-FBKAPTJ2.js +0 -16
  46. package/dist/chunk-FVLV5RYH.js +0 -1118
  47. package/dist/chunk-GDNSBQVK.js +0 -2485
  48. package/dist/chunk-GPQHMBNN.js +0 -278
  49. package/dist/chunk-GTFJB67L.js +0 -68
  50. package/dist/chunk-HANJXVKW.js +0 -1127
  51. package/dist/chunk-HEVS5YLD.js +0 -269
  52. package/dist/chunk-HMEVZKPQ.js +0 -9
  53. package/dist/chunk-HRGSYNLM.js +0 -3511
  54. package/dist/chunk-ISZR5N4K.js +0 -60
  55. package/dist/chunk-J6SUPR2C.js +0 -226
  56. package/dist/chunk-JERYVEIZ.js +0 -244
  57. package/dist/chunk-JHHWGL2N.js +0 -87
  58. package/dist/chunk-JONWQUB5.js +0 -775
  59. package/dist/chunk-K2DIWWDM.js +0 -1766
  60. package/dist/chunk-KY4PGL5V.js +0 -969
  61. package/dist/chunk-L737LQ4C.js +0 -1285
  62. package/dist/chunk-LFTWYIB2.js +0 -497
  63. package/dist/chunk-LV47RFNJ.js +0 -41
  64. package/dist/chunk-MKSAITI7.js +0 -15
  65. package/dist/chunk-MZ7RKIX4.js +0 -212
  66. package/dist/chunk-NAP6CFSO.js +0 -84
  67. package/dist/chunk-ND6MY37M.js +0 -16
  68. package/dist/chunk-NMG736UR.js +0 -683
  69. package/dist/chunk-NRAXROED.js +0 -32
  70. package/dist/chunk-NRIZR3A7.js +0 -690
  71. package/dist/chunk-NX43BG3M.js +0 -233
  72. package/dist/chunk-O645XLSI.js +0 -297
  73. package/dist/chunk-OMJD6A3S.js +0 -235
  74. package/dist/chunk-QB6SJD4T.js +0 -430
  75. package/dist/chunk-QFSTL4J3.js +0 -276
  76. package/dist/chunk-QLGDFMFX.js +0 -212
  77. package/dist/chunk-RIAAGL2E.js +0 -13
  78. package/dist/chunk-RWO5XMZ6.js +0 -86
  79. package/dist/chunk-RXRKBBSM.js +0 -149
  80. package/dist/chunk-RZOZMML6.js +0 -363
  81. package/dist/chunk-U7I7FS7T.js +0 -113
  82. package/dist/chunk-UI42RODY.js +0 -717
  83. package/dist/chunk-UTVMVSCO.js +0 -519
  84. package/dist/chunk-V6OJGLBA.js +0 -1746
  85. package/dist/chunk-W2JHVH7D.js +0 -152
  86. package/dist/chunk-WD3Y7VQN.js +0 -280
  87. package/dist/chunk-WOCTQ5MS.js +0 -303
  88. package/dist/chunk-WZR3ZUNN.js +0 -696
  89. package/dist/chunk-XGI665H7.js +0 -150
  90. package/dist/chunk-XKY65P2T.js +0 -304
  91. package/dist/chunk-Y4CQZY65.js +0 -57
  92. package/dist/chunk-YFEXKLVE.js +0 -194
  93. package/dist/chunk-YHO3HS5X.js +0 -287
  94. package/dist/chunk-YLS7AZSX.js +0 -738
  95. package/dist/chunk-ZE473AO6.js +0 -49
  96. package/dist/chunk-ZF747T3O.js +0 -644
  97. package/dist/chunk-ZHCZHZH3.js +0 -43
  98. package/dist/chunk-ZZNZX2XY.js +0 -87
  99. package/dist/constants-7QAP3VQ4.js +0 -23
  100. package/dist/dist-IY3UUMWK.js +0 -33
  101. package/dist/invariants-runner-W5RGHCSU.js +0 -27
  102. package/dist/lane-lock-6J36HD5O.js +0 -35
  103. package/dist/mem-checkpoint-core-EANG2GVN.js +0 -14
  104. package/dist/mem-signal-core-2LZ2WYHW.js +0 -19
  105. package/dist/memory-store-OLB5FO7K.js +0 -18
  106. package/dist/service-6BYCOCO5.js +0 -13
  107. package/dist/spawn-policy-resolver-NTSZYQ6R.js +0 -17
  108. package/dist/spawn-task-builder-R4E2BHSW.js +0 -22
  109. package/dist/wu-done-pr-WLFFFEPJ.js +0 -25
  110. package/dist/wu-done-validation-3J5E36FE.js +0 -30
  111. package/dist/wu-duplicate-id-detector-5S7JHELK.js +0 -232
@@ -1,233 +0,0 @@
1
- import {
2
- normalizeValidationIssue
3
- } from "./chunk-2GXVIN57.js";
4
- import {
5
- REGISTRATION_SURFACES,
6
- RULE_CODES,
7
- validateWURulesSync
8
- } from "./chunk-L737LQ4C.js";
9
- import {
10
- INVARIANT_TYPES,
11
- loadInvariants
12
- } from "./chunk-EZ6ZBYBM.js";
13
- import {
14
- WU_STATUS
15
- } from "./chunk-V6OJGLBA.js";
16
-
17
- // ../core/dist/wu-lint.js
18
- import { existsSync } from "fs";
19
- import { minimatch } from "minimatch";
20
- var WU_LINT_ERROR_TYPES = {
21
- ACCEPTANCE_PATH_NOT_IN_CODE_PATHS: "acceptance_path_not_in_code_paths",
22
- CODE_PATH_CONFLICTS_INVARIANT: "code_path_conflicts_invariant",
23
- ACCEPTANCE_CONFLICTS_INVARIANT: "acceptance_conflicts_invariant",
24
- /** CLI registration parity surface missing */
25
- REGISTRATION_PARITY_MISSING: "registration_parity_missing",
26
- /** Backward-compatible key for minimum test intent */
27
- UNIT_TESTS_REQUIRED: "unit_tests_required",
28
- /** Canonical minimum test intent key */
29
- MINIMUM_TEST_INTENT_REQUIRED: "minimum_test_intent_required"
30
- };
31
- var REGISTRATION_SURFACES2 = {
32
- PUBLIC_MANIFEST: REGISTRATION_SURFACES.PUBLIC_MANIFEST,
33
- MCP_TOOLS: REGISTRATION_SURFACES.MCP_TOOLS
34
- };
35
- var CLI_COMMAND_EXCLUDE_PATTERNS = [
36
- "__tests__/",
37
- "/lib/",
38
- "/shared/",
39
- "/commands/",
40
- "/init.ts",
41
- REGISTRATION_SURFACES2.PUBLIC_MANIFEST,
42
- REGISTRATION_SURFACES2.MCP_TOOLS
43
- ];
44
- var FILE_PATH_PATTERN = /(?:^|[\s'"`])([a-zA-Z0-9_-]+\/[a-zA-Z0-9_./-]+\.[a-zA-Z0-9]+)/g;
45
- function extractFilePaths(text) {
46
- const paths = [];
47
- let match;
48
- while ((match = FILE_PATH_PATTERN.exec(text)) !== null) {
49
- const captured = match[1];
50
- if (captured) {
51
- paths.push(captured);
52
- }
53
- }
54
- FILE_PATH_PATTERN.lastIndex = 0;
55
- return paths;
56
- }
57
- function pathMatchesCodePaths(filePath, codePaths) {
58
- for (const pattern of codePaths) {
59
- if (filePath === pattern) {
60
- return true;
61
- }
62
- if (minimatch(filePath, pattern)) {
63
- return true;
64
- }
65
- }
66
- return false;
67
- }
68
- function validateAcceptanceCodePaths(wu) {
69
- const { id, code_paths = [] } = wu;
70
- const acceptance = Array.isArray(wu.acceptance) ? wu.acceptance : [];
71
- const errors = [];
72
- for (const criterion of acceptance) {
73
- const referencedPaths = extractFilePaths(criterion);
74
- for (const referencedPath of referencedPaths) {
75
- if (!pathMatchesCodePaths(referencedPath, code_paths)) {
76
- errors.push({
77
- type: WU_LINT_ERROR_TYPES.ACCEPTANCE_PATH_NOT_IN_CODE_PATHS,
78
- wuId: id,
79
- path: referencedPath,
80
- criterion,
81
- message: `Acceptance criterion references '${referencedPath}' which is not in code_paths`,
82
- suggestion: `Add '${referencedPath}' to code_paths or remove the reference from acceptance criteria`
83
- });
84
- }
85
- }
86
- }
87
- return {
88
- valid: errors.length === 0,
89
- errors
90
- };
91
- }
92
- function checkForbiddenFileInvariant(invariant, wu) {
93
- const { id, code_paths = [] } = wu;
94
- const acceptance = Array.isArray(wu.acceptance) ? wu.acceptance : [];
95
- const errors = [];
96
- if (code_paths.includes(invariant.path)) {
97
- errors.push({
98
- type: WU_LINT_ERROR_TYPES.CODE_PATH_CONFLICTS_INVARIANT,
99
- wuId: id,
100
- invariantId: invariant.id,
101
- path: invariant.path,
102
- message: `code_paths includes '${invariant.path}' which conflicts with invariant ${invariant.id}: ${invariant.description}`,
103
- suggestion: invariant.message || `Remove '${invariant.path}' from code_paths`
104
- });
105
- }
106
- for (const criterion of acceptance) {
107
- if (criterion.includes(invariant.path)) {
108
- errors.push({
109
- type: WU_LINT_ERROR_TYPES.ACCEPTANCE_CONFLICTS_INVARIANT,
110
- wuId: id,
111
- invariantId: invariant.id,
112
- path: invariant.path,
113
- criterion,
114
- message: `Acceptance criterion references forbidden file '${invariant.path}' (${invariant.id}: ${invariant.description})`,
115
- suggestion: invariant.message
116
- });
117
- }
118
- }
119
- return errors;
120
- }
121
- function checkMutualExclusivityInvariant(invariant, wu) {
122
- const { id, code_paths = [] } = wu;
123
- const errors = [];
124
- const conflictingPaths = invariant.paths.filter((p) => code_paths.includes(p));
125
- if (conflictingPaths.length > 1) {
126
- errors.push({
127
- type: WU_LINT_ERROR_TYPES.CODE_PATH_CONFLICTS_INVARIANT,
128
- wuId: id,
129
- invariantId: invariant.id,
130
- paths: conflictingPaths,
131
- message: `code_paths includes multiple mutually exclusive files (${invariant.id}): ${conflictingPaths.join(", ")}`,
132
- suggestion: invariant.message || `Only one of these files should exist: ${invariant.paths.join(", ")}`
133
- });
134
- }
135
- return errors;
136
- }
137
- function validateInvariantsCompliance(wu, invariants) {
138
- const errors = [];
139
- for (const invariant of invariants) {
140
- if (invariant.type === INVARIANT_TYPES.FORBIDDEN_FILE) {
141
- errors.push(...checkForbiddenFileInvariant(invariant, wu));
142
- } else if (invariant.type === INVARIANT_TYPES.MUTUAL_EXCLUSIVITY) {
143
- errors.push(...checkMutualExclusivityInvariant(invariant, wu));
144
- }
145
- }
146
- return {
147
- valid: errors.length === 0,
148
- errors
149
- };
150
- }
151
- var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
152
- WU_STATUS.DONE,
153
- WU_STATUS.CANCELLED,
154
- WU_STATUS.COMPLETED,
155
- WU_STATUS.ABANDONED,
156
- WU_STATUS.SUPERSEDED
157
- ]);
158
- var LINT_TYPE_BY_RULE_CODE = {
159
- [RULE_CODES.MINIMUM_TEST_INTENT]: WU_LINT_ERROR_TYPES.MINIMUM_TEST_INTENT_REQUIRED,
160
- [RULE_CODES.PARITY_MISSING_SURFACE]: WU_LINT_ERROR_TYPES.REGISTRATION_PARITY_MISSING
161
- };
162
- function toLintIssue(wuId, issue) {
163
- const normalized = normalizeValidationIssue(issue, {
164
- wuId,
165
- typeByCode: LINT_TYPE_BY_RULE_CODE
166
- });
167
- return {
168
- type: normalized.type,
169
- wuId,
170
- message: normalized.message,
171
- suggestion: normalized.suggestion
172
- };
173
- }
174
- function lintWUSpec(wu, options = {}) {
175
- const allErrors = [];
176
- const allWarnings = [];
177
- const phase = options.phase || "structural";
178
- const acceptanceResult = validateAcceptanceCodePaths(wu);
179
- allErrors.push(...acceptanceResult.errors);
180
- let invariants = options.invariants || [];
181
- if (!options.invariants && options.invariantsPath) {
182
- try {
183
- if (existsSync(options.invariantsPath)) {
184
- invariants = loadInvariants(options.invariantsPath);
185
- }
186
- } catch {
187
- }
188
- }
189
- if (invariants.length > 0) {
190
- const invariantsResult = validateInvariantsCompliance(wu, invariants);
191
- allErrors.push(...invariantsResult.errors);
192
- }
193
- const rulesResult = validateWURulesSync({
194
- id: wu.id,
195
- type: wu.type,
196
- status: wu.status,
197
- code_paths: wu.code_paths,
198
- tests: wu.tests || wu.test_paths,
199
- cwd: options.context?.cwd,
200
- baseRef: options.context?.baseRef,
201
- headRef: options.context?.headRef
202
- }, { phase });
203
- for (const issue of rulesResult.errors) {
204
- allErrors.push(toLintIssue(wu.id, issue));
205
- }
206
- for (const issue of rulesResult.warnings) {
207
- allWarnings.push(toLintIssue(wu.id, issue));
208
- }
209
- return {
210
- valid: allErrors.length === 0,
211
- errors: allErrors,
212
- warnings: allWarnings
213
- };
214
- }
215
- function formatLintErrors(errors) {
216
- if (errors.length === 0) {
217
- return "";
218
- }
219
- const lines = ["WU SPEC LINT ERRORS:", ""];
220
- for (const error of errors) {
221
- lines.push(`- ${error.message}`);
222
- if (error.suggestion) {
223
- lines.push(` Fix: ${error.suggestion}`);
224
- }
225
- lines.push("");
226
- }
227
- return lines.join("\n");
228
- }
229
-
230
- export {
231
- lintWUSpec,
232
- formatLintErrors
233
- };
@@ -1,297 +0,0 @@
1
- import {
2
- BLOCKED_EDIT_MODE,
3
- BRANCH_PR_EDIT_MODE,
4
- resolveInProgressEditMode
5
- } from "./chunk-B7YJYJKG.js";
6
- import {
7
- INIT_PATTERNS
8
- } from "./chunk-NAP6CFSO.js";
9
- import {
10
- INIT_PATHS
11
- } from "./chunk-ZHCZHZH3.js";
12
- import {
13
- createGitForPath
14
- } from "./chunk-2UFQ3A3C.js";
15
- import {
16
- parseYAML
17
- } from "./chunk-NRIZR3A7.js";
18
- import {
19
- WU_PATHS,
20
- defaultWorktreeFrom
21
- } from "./chunk-6HO4GWJE.js";
22
- import {
23
- FILE_SYSTEM
24
- } from "./chunk-DWMLTXKQ.js";
25
- import {
26
- WU_EXPOSURE_VALUES,
27
- WU_STATUS,
28
- getConfig
29
- } from "./chunk-V6OJGLBA.js";
30
- import {
31
- die
32
- } from "./chunk-RXRKBBSM.js";
33
-
34
- // src/wu-edit-validators.ts
35
- import { existsSync, readFileSync } from "fs";
36
- import { resolve, join, relative, isAbsolute } from "path";
37
- var EDIT_MODE = {
38
- /** Ready WUs: Use micro-worktree on main (existing behavior) */
39
- MICRO_WORKTREE: "micro_worktree",
40
- /** In-progress worktree WUs: Apply edits directly in active worktree (WU-1365) */
41
- WORKTREE: "worktree",
42
- /** In-progress branch-pr WUs: apply edits directly on the claimed branch */
43
- BRANCH_PR: BRANCH_PR_EDIT_MODE
44
- };
45
- function validateDoneWUEdits(opts) {
46
- const disallowedEdits = [];
47
- if (opts.specFile) disallowedEdits.push("--spec-file");
48
- if (opts.description) disallowedEdits.push("--description");
49
- if (opts.acceptance && Array.isArray(opts.acceptance) && opts.acceptance.length > 0) {
50
- disallowedEdits.push("--acceptance");
51
- }
52
- if (opts.notes) disallowedEdits.push("--notes");
53
- if (opts.codePaths && Array.isArray(opts.codePaths) && opts.codePaths.length > 0) {
54
- disallowedEdits.push("--code-paths");
55
- }
56
- if (opts.risks && Array.isArray(opts.risks) && opts.risks.length > 0) {
57
- disallowedEdits.push("--risks");
58
- }
59
- if (opts.lane) disallowedEdits.push("--lane");
60
- if (opts.type) disallowedEdits.push("--type");
61
- if (opts.priority) disallowedEdits.push("--priority");
62
- if (opts.testPathsManual && Array.isArray(opts.testPathsManual) && opts.testPathsManual.length > 0) {
63
- disallowedEdits.push("--test-paths-manual");
64
- }
65
- if (opts.testPathsUnit && Array.isArray(opts.testPathsUnit) && opts.testPathsUnit.length > 0) {
66
- disallowedEdits.push("--test-paths-unit");
67
- }
68
- if (opts.testPathsE2e && Array.isArray(opts.testPathsE2e) && opts.testPathsE2e.length > 0) {
69
- disallowedEdits.push("--test-paths-e2e");
70
- }
71
- return {
72
- valid: disallowedEdits.length === 0,
73
- disallowedEdits
74
- };
75
- }
76
- function validateExposureValue(exposure) {
77
- const validValues = WU_EXPOSURE_VALUES;
78
- if (!validValues.includes(exposure)) {
79
- return {
80
- valid: false,
81
- error: `Invalid exposure value: "${exposure}"
82
-
83
- Valid values: ${WU_EXPOSURE_VALUES.join(", ")}`
84
- };
85
- }
86
- return { valid: true };
87
- }
88
- function validateInitiativeFormat(initId) {
89
- if (!INIT_PATTERNS.INIT_ID.test(initId)) {
90
- die(
91
- `Invalid Initiative ID format: "${initId}"
92
-
93
- Expected format: INIT-<number> or INIT-<NAME> (e.g., INIT-001, INIT-TOOLING)`
94
- );
95
- }
96
- }
97
- function validateInitiativeExists(initId) {
98
- const initPath = INIT_PATHS.INITIATIVE(initId);
99
- if (!existsSync(initPath)) {
100
- die(`Initiative not found: ${initId}
101
-
102
- File does not exist: ${initPath}`);
103
- }
104
- return initPath;
105
- }
106
- function validateWUEditable(id) {
107
- const wuPath = WU_PATHS.WU(id);
108
- if (!existsSync(wuPath)) {
109
- die(`WU ${id} not found at ${wuPath}
110
-
111
- Ensure the WU exists and you're in the repo root.`);
112
- }
113
- const content = readFileSync(wuPath, { encoding: FILE_SYSTEM.ENCODING });
114
- const wu = parseYAML(content);
115
- if (wu.status === WU_STATUS.DONE) {
116
- return { wu, editMode: EDIT_MODE.MICRO_WORKTREE, isDone: true };
117
- }
118
- if (wu.status === WU_STATUS.IN_PROGRESS) {
119
- const editMode = resolveInProgressEditMode(
120
- typeof wu.claimed_mode === "string" ? wu.claimed_mode : void 0
121
- );
122
- if (editMode === BLOCKED_EDIT_MODE) {
123
- die(
124
- `Cannot edit branch-only WU ${id} via wu:edit.
125
-
126
- WUs claimed with claimed_mode='branch-only' cannot be edited via wu:edit.
127
- To modify the spec, edit the file directly on the lane branch and commit.`
128
- );
129
- }
130
- if (editMode === EDIT_MODE.BRANCH_PR) {
131
- return { wu, editMode: EDIT_MODE.BRANCH_PR, isDone: false };
132
- }
133
- const worktreeRelPath = defaultWorktreeFrom(wu);
134
- if (worktreeRelPath) {
135
- const worktreeWuPath = join(resolve(worktreeRelPath), WU_PATHS.WU(id));
136
- if (existsSync(worktreeWuPath)) {
137
- const worktreeContent = readFileSync(worktreeWuPath, {
138
- encoding: FILE_SYSTEM.ENCODING
139
- });
140
- const worktreeWu = parseYAML(worktreeContent);
141
- return { wu: worktreeWu, editMode: EDIT_MODE.WORKTREE, isDone: false };
142
- }
143
- }
144
- return { wu, editMode: EDIT_MODE.WORKTREE, isDone: false };
145
- }
146
- if (wu.status === WU_STATUS.READY) {
147
- return { wu, editMode: EDIT_MODE.MICRO_WORKTREE, isDone: false };
148
- }
149
- die(
150
- `Cannot edit WU ${id}: status is '${wu.status}'.
151
-
152
- Only WUs in '${WU_STATUS.READY}' or '${WU_STATUS.IN_PROGRESS}' (worktree mode) can be edited.`
153
- );
154
- }
155
- function validateWorktreeExists(worktreePath, id) {
156
- if (!existsSync(worktreePath)) {
157
- die(
158
- `Cannot edit WU ${id}: worktree path missing from disk.
159
-
160
- Expected worktree at: ${worktreePath}
161
-
162
- The worktree may have been removed or the path is incorrect.
163
- If the worktree was accidentally deleted, you may need to re-claim the WU.`
164
- );
165
- }
166
- }
167
- async function validateWorktreeClean(worktreePath, id) {
168
- try {
169
- const gitAdapter = createGitForPath(worktreePath);
170
- const status = (await gitAdapter.raw(["status", "--porcelain"])).trim();
171
- if (status !== "") {
172
- die(
173
- `Cannot edit WU ${id}: worktree has uncommitted changes.
174
-
175
- Uncommitted changes in ${worktreePath}:
176
- ${status}
177
-
178
- Commit or discard your changes before editing the WU spec:
179
- cd ${worktreePath}
180
- git add . && git commit -m "wip: save progress"
181
-
182
- Then retry wu:edit.`
183
- );
184
- }
185
- } catch (err) {
186
- die(
187
- `Cannot edit WU ${id}: failed to check worktree status.
188
-
189
- Error: ${err.message}
190
-
191
- Worktree path: ${worktreePath}`
192
- );
193
- }
194
- }
195
- async function validateWorktreeBranch(worktreePath, expectedBranch, id) {
196
- try {
197
- const gitAdapter = createGitForPath(worktreePath);
198
- const actualBranch = (await gitAdapter.raw(["rev-parse", "--abbrev-ref", "HEAD"])).trim();
199
- if (actualBranch !== expectedBranch) {
200
- die(
201
- `Cannot edit WU ${id}: worktree branch does not match expected lane branch.
202
-
203
- Expected branch: ${expectedBranch}
204
- Actual branch: ${actualBranch}
205
-
206
- This may indicate a corrupted worktree state.
207
- Verify the worktree is correctly set up for this WU.`
208
- );
209
- }
210
- } catch (err) {
211
- die(
212
- `Cannot edit WU ${id}: failed to check worktree branch.
213
-
214
- Error: ${err.message}
215
-
216
- Worktree path: ${worktreePath}`
217
- );
218
- }
219
- }
220
- function isPathWithin(rootPath, candidatePath) {
221
- const relativePath = relative(rootPath, candidatePath);
222
- return relativePath === "" || !relativePath.startsWith("..") && !isAbsolute(relativePath);
223
- }
224
- function validateWorktreeExecutionContext(currentCwd, worktreePath, id, retryCommand) {
225
- const resolvedCwd = resolve(currentCwd);
226
- const resolvedWorktreePath = resolve(worktreePath);
227
- if (isPathWithin(resolvedWorktreePath, resolvedCwd)) {
228
- return;
229
- }
230
- const safeRetryCommand = typeof retryCommand === "string" && retryCommand.trim().length > 0 ? retryCommand.trim() : `pnpm wu:edit --id ${id} <edit-flags>`;
231
- die(
232
- `Cannot edit in_progress WU ${id} from this checkout.
233
-
234
- Current directory: ${resolvedCwd}
235
- Claimed worktree: ${resolvedWorktreePath}
236
-
237
- Run from the claimed worktree and retry:
238
- cd ${resolvedWorktreePath}
239
- ${safeRetryCommand}`
240
- );
241
- }
242
- function toPosixPath(filePath) {
243
- return filePath.replace(/\\/g, "/");
244
- }
245
- function getRuntimePathClassification(projectRoot) {
246
- const config = getConfig({ projectRoot });
247
- const stateEventsPath = toPosixPath(`${config.state.stateDir}/wu-events.jsonl`);
248
- const backlogPath = toPosixPath(config.directories.backlogPath);
249
- const statusPath = toPosixPath(config.directories.statusPath);
250
- const wuDirPrefix = toPosixPath(config.directories.wuDir).replace(/\/?$/, "/");
251
- return {
252
- nonScopeRelevantPaths: /* @__PURE__ */ new Set([stateEventsPath, backlogPath, statusPath]),
253
- wuDirPrefix
254
- };
255
- }
256
- function hasScopeRelevantBranchChanges(changedFiles) {
257
- const { nonScopeRelevantPaths, wuDirPrefix } = getRuntimePathClassification(process.cwd());
258
- return changedFiles.some((filePath) => {
259
- const normalized = toPosixPath(filePath.trim());
260
- if (!normalized) {
261
- return false;
262
- }
263
- if (nonScopeRelevantPaths.has(normalized)) {
264
- return false;
265
- }
266
- return !normalized.startsWith(wuDirPrefix);
267
- });
268
- }
269
- function normalizeReplaceCodePathsArgv(argv) {
270
- const normalized = [...argv];
271
- for (let i = 0; i < normalized.length; i += 1) {
272
- if (normalized[i] !== "--replace-code-paths") {
273
- continue;
274
- }
275
- const next = normalized[i + 1];
276
- if (next && !next.startsWith("-")) {
277
- normalized.splice(i + 1, 0, "--code-paths");
278
- i += 1;
279
- }
280
- }
281
- return normalized;
282
- }
283
-
284
- export {
285
- EDIT_MODE,
286
- validateDoneWUEdits,
287
- validateExposureValue,
288
- validateInitiativeFormat,
289
- validateInitiativeExists,
290
- validateWUEditable,
291
- validateWorktreeExists,
292
- validateWorktreeClean,
293
- validateWorktreeBranch,
294
- validateWorktreeExecutionContext,
295
- hasScopeRelevantBranchChanges,
296
- normalizeReplaceCodePathsArgv
297
- };