@lumenflow/cli 1.6.0 → 2.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/dist/__tests__/backlog-prune.test.js +478 -0
- package/dist/__tests__/deps-operations.test.js +206 -0
- package/dist/__tests__/file-operations.test.js +906 -0
- package/dist/__tests__/git-operations.test.js +668 -0
- package/dist/__tests__/guards-validation.test.js +416 -0
- package/dist/__tests__/init-plan.test.js +340 -0
- package/dist/__tests__/lumenflow-upgrade.test.js +107 -0
- package/dist/__tests__/metrics-cli.test.js +619 -0
- package/dist/__tests__/rotate-progress.test.js +127 -0
- package/dist/__tests__/session-coordinator.test.js +109 -0
- package/dist/__tests__/state-bootstrap.test.js +432 -0
- package/dist/__tests__/trace-gen.test.js +115 -0
- package/dist/backlog-prune.js +299 -0
- package/dist/deps-add.js +215 -0
- package/dist/deps-remove.js +94 -0
- package/dist/file-delete.js +236 -0
- package/dist/file-edit.js +247 -0
- package/dist/file-read.js +197 -0
- package/dist/file-write.js +220 -0
- package/dist/git-branch.js +187 -0
- package/dist/git-diff.js +177 -0
- package/dist/git-log.js +230 -0
- package/dist/git-status.js +208 -0
- package/dist/guard-locked.js +169 -0
- package/dist/guard-main-branch.js +202 -0
- package/dist/guard-worktree-commit.js +160 -0
- package/dist/init-plan.js +337 -0
- package/dist/lumenflow-upgrade.js +178 -0
- package/dist/metrics-cli.js +433 -0
- package/dist/rotate-progress.js +247 -0
- package/dist/session-coordinator.js +300 -0
- package/dist/state-bootstrap.js +307 -0
- package/dist/trace-gen.js +331 -0
- package/dist/validate-agent-skills.js +218 -0
- package/dist/validate-agent-sync.js +148 -0
- package/dist/validate-backlog-sync.js +152 -0
- package/dist/validate-skills-spec.js +206 -0
- package/dist/validate.js +230 -0
- package/package.json +34 -6
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
3
|
+
/**
|
|
4
|
+
* Init Plan Command (WU-1105)
|
|
5
|
+
*
|
|
6
|
+
* Links plan files to initiatives by setting the `related_plan` field
|
|
7
|
+
* in the initiative YAML.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* pnpm init:plan --initiative INIT-001 --plan docs/04-operations/plans/my-plan.md
|
|
11
|
+
* pnpm init:plan --initiative INIT-001 --create # Create new plan template
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Validates initiative exists before modifying
|
|
15
|
+
* - Formats plan path as lumenflow:// URI
|
|
16
|
+
* - Idempotent: no error if same plan already linked
|
|
17
|
+
* - Warns if replacing existing plan link
|
|
18
|
+
* - Can create plan templates with --create
|
|
19
|
+
*
|
|
20
|
+
* Context: WU-1105 (INIT-003 Phase 3a: Migrate init:plan command)
|
|
21
|
+
*/
|
|
22
|
+
import { getGitForCwd } from '@lumenflow/core/dist/git-adapter.js';
|
|
23
|
+
import { die } from '@lumenflow/core/dist/error-handler.js';
|
|
24
|
+
import { existsSync, writeFileSync, mkdirSync, readFileSync } from 'node:fs';
|
|
25
|
+
import { join, basename } from 'node:path';
|
|
26
|
+
import { createWUParser, WU_OPTIONS } from '@lumenflow/core/dist/arg-parser.js';
|
|
27
|
+
import { INIT_PATHS } from '@lumenflow/initiatives/dist/initiative-paths.js';
|
|
28
|
+
import { INIT_PATTERNS } from '@lumenflow/initiatives/dist/initiative-constants.js';
|
|
29
|
+
import { ensureOnMain } from '@lumenflow/core/dist/wu-helpers.js';
|
|
30
|
+
import { withMicroWorktree } from '@lumenflow/core/dist/micro-worktree.js';
|
|
31
|
+
import { readInitiative } from '@lumenflow/initiatives/dist/initiative-yaml.js';
|
|
32
|
+
import { parseYAML, stringifyYAML } from '@lumenflow/core/dist/wu-yaml.js';
|
|
33
|
+
import { LOG_PREFIX as CORE_LOG_PREFIX } from '@lumenflow/core/dist/wu-constants.js';
|
|
34
|
+
/** Log prefix for console output */
|
|
35
|
+
export const LOG_PREFIX = CORE_LOG_PREFIX.INIT_PLAN;
|
|
36
|
+
/** Micro-worktree operation name */
|
|
37
|
+
const OPERATION_NAME = 'init-plan';
|
|
38
|
+
/** Standard plans directory relative to repo root */
|
|
39
|
+
const PLANS_DIR = 'docs/04-operations/plans';
|
|
40
|
+
/** LumenFlow URI scheme for plan references */
|
|
41
|
+
const PLAN_URI_SCHEME = 'lumenflow://plans/';
|
|
42
|
+
/**
|
|
43
|
+
* Custom option for plan file path
|
|
44
|
+
*/
|
|
45
|
+
const PLAN_OPTION = {
|
|
46
|
+
name: 'plan',
|
|
47
|
+
flags: '--plan <path>',
|
|
48
|
+
description: 'Path to plan file (markdown)',
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Custom option for creating new plan template
|
|
52
|
+
*/
|
|
53
|
+
const CREATE_OPTION = {
|
|
54
|
+
name: 'create',
|
|
55
|
+
flags: '--create',
|
|
56
|
+
description: 'Create a new plan template instead of linking existing file',
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Validate Initiative ID format
|
|
60
|
+
* @param id - Initiative ID to validate
|
|
61
|
+
* @throws Error if format is invalid
|
|
62
|
+
*/
|
|
63
|
+
export function validateInitIdFormat(id) {
|
|
64
|
+
if (!INIT_PATTERNS.INIT_ID.test(id)) {
|
|
65
|
+
die(`Invalid Initiative ID format: "${id}"\n\n` +
|
|
66
|
+
`Expected format: INIT-<number> or INIT-NAME (e.g., INIT-001, INIT-TOOLING)`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Validate plan file path
|
|
71
|
+
* @param planPath - Path to plan file
|
|
72
|
+
* @throws Error if path is invalid or file doesn't exist
|
|
73
|
+
*/
|
|
74
|
+
export function validatePlanPath(planPath) {
|
|
75
|
+
if (!planPath.endsWith('.md')) {
|
|
76
|
+
die(`Invalid plan file format: "${planPath}"\n\nPlan files must be markdown (.md)`);
|
|
77
|
+
}
|
|
78
|
+
if (!existsSync(planPath)) {
|
|
79
|
+
die(`Plan file not found: "${planPath}"\n\nUse --create to create a new plan template`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Format plan path as lumenflow:// URI
|
|
84
|
+
*
|
|
85
|
+
* Extracts the filename (and any subdirectory within plans/) and creates
|
|
86
|
+
* a standardized URI for the plan reference.
|
|
87
|
+
*
|
|
88
|
+
* @param planPath - Path to plan file (can be relative or absolute)
|
|
89
|
+
* @returns lumenflow://plans/<filename> URI
|
|
90
|
+
*/
|
|
91
|
+
export function formatPlanUri(planPath) {
|
|
92
|
+
// Try to extract path relative to plans directory
|
|
93
|
+
const plansMarker = '/plans/';
|
|
94
|
+
const plansIndex = planPath.indexOf(plansMarker);
|
|
95
|
+
if (plansIndex !== -1) {
|
|
96
|
+
// Extract everything after /plans/
|
|
97
|
+
const relativePath = planPath.substring(plansIndex + plansMarker.length);
|
|
98
|
+
return `${PLAN_URI_SCHEME}${relativePath}`;
|
|
99
|
+
}
|
|
100
|
+
// Fallback: just use the filename
|
|
101
|
+
const filename = basename(planPath);
|
|
102
|
+
return `${PLAN_URI_SCHEME}${filename}`;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if initiative exists and return the document
|
|
106
|
+
* @param initId - Initiative ID to check
|
|
107
|
+
* @returns Initiative document
|
|
108
|
+
* @throws Error if initiative not found
|
|
109
|
+
*/
|
|
110
|
+
export function checkInitiativeExists(initId) {
|
|
111
|
+
const initPath = INIT_PATHS.INITIATIVE(initId);
|
|
112
|
+
if (!existsSync(initPath)) {
|
|
113
|
+
die(`Initiative not found: ${initId}\n\nFile does not exist: ${initPath}`);
|
|
114
|
+
}
|
|
115
|
+
return readInitiative(initPath, initId);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Update initiative with plan reference in micro-worktree
|
|
119
|
+
*
|
|
120
|
+
* Uses raw YAML parsing to preserve unknown fields like related_plan
|
|
121
|
+
* that are not in the strict initiative schema.
|
|
122
|
+
*
|
|
123
|
+
* @param worktreePath - Path to micro-worktree
|
|
124
|
+
* @param initId - Initiative ID
|
|
125
|
+
* @param planUri - Plan URI to set
|
|
126
|
+
* @returns True if changes were made, false if already linked
|
|
127
|
+
*/
|
|
128
|
+
export function updateInitiativeWithPlan(worktreePath, initId, planUri) {
|
|
129
|
+
const initRelPath = INIT_PATHS.INITIATIVE(initId);
|
|
130
|
+
const initAbsPath = join(worktreePath, initRelPath);
|
|
131
|
+
// Read raw YAML to preserve unknown fields like related_plan
|
|
132
|
+
// (readInitiative strips them via zod schema validation)
|
|
133
|
+
const rawText = readFileSync(initAbsPath, { encoding: 'utf-8' });
|
|
134
|
+
const doc = parseYAML(rawText);
|
|
135
|
+
// Validate ID matches
|
|
136
|
+
if (doc.id !== initId) {
|
|
137
|
+
die(`Initiative YAML id mismatch. Expected ${initId}, found ${doc.id}`);
|
|
138
|
+
}
|
|
139
|
+
// Check for existing plan link
|
|
140
|
+
const existingPlan = doc.related_plan;
|
|
141
|
+
if (existingPlan === planUri) {
|
|
142
|
+
// Already linked to same plan - idempotent
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
if (existingPlan && existingPlan !== planUri) {
|
|
146
|
+
// Different plan already linked - warn but proceed
|
|
147
|
+
console.warn(`${LOG_PREFIX} Replacing existing related_plan: ${existingPlan} -> ${planUri}`);
|
|
148
|
+
}
|
|
149
|
+
// Update related_plan field
|
|
150
|
+
doc.related_plan = planUri;
|
|
151
|
+
const out = stringifyYAML(doc);
|
|
152
|
+
writeFileSync(initAbsPath, out, { encoding: 'utf-8' });
|
|
153
|
+
console.log(`${LOG_PREFIX} Updated ${initId} with related_plan: ${planUri}`);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create a plan template file
|
|
158
|
+
*
|
|
159
|
+
* @param worktreePath - Path to repo root or worktree
|
|
160
|
+
* @param initId - Initiative ID
|
|
161
|
+
* @param title - Initiative title
|
|
162
|
+
* @returns Path to created file
|
|
163
|
+
* @throws Error if file already exists
|
|
164
|
+
*/
|
|
165
|
+
export function createPlanTemplate(worktreePath, initId, title) {
|
|
166
|
+
const slug = title
|
|
167
|
+
.toLowerCase()
|
|
168
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
169
|
+
.replace(/^-|-$/g, '')
|
|
170
|
+
.substring(0, 30);
|
|
171
|
+
const filename = `${initId}-${slug}.md`;
|
|
172
|
+
const plansDir = join(worktreePath, PLANS_DIR);
|
|
173
|
+
const planPath = join(plansDir, filename);
|
|
174
|
+
if (existsSync(planPath)) {
|
|
175
|
+
die(`Plan file already exists: ${planPath}\n\nUse --plan to link an existing file`);
|
|
176
|
+
}
|
|
177
|
+
// Ensure plans directory exists
|
|
178
|
+
if (!existsSync(plansDir)) {
|
|
179
|
+
mkdirSync(plansDir, { recursive: true });
|
|
180
|
+
}
|
|
181
|
+
const template = `# ${initId} Plan - ${title}
|
|
182
|
+
|
|
183
|
+
## Goal
|
|
184
|
+
|
|
185
|
+
<!-- What is the primary objective of this initiative? -->
|
|
186
|
+
|
|
187
|
+
## Scope
|
|
188
|
+
|
|
189
|
+
<!-- What is in scope and out of scope? -->
|
|
190
|
+
|
|
191
|
+
## Approach
|
|
192
|
+
|
|
193
|
+
<!-- How will you achieve the goal? Key phases or milestones? -->
|
|
194
|
+
|
|
195
|
+
## Success Criteria
|
|
196
|
+
|
|
197
|
+
<!-- How will you know when this is complete? Measurable outcomes? -->
|
|
198
|
+
|
|
199
|
+
## Risks
|
|
200
|
+
|
|
201
|
+
<!-- What could go wrong? How will you mitigate? -->
|
|
202
|
+
|
|
203
|
+
## References
|
|
204
|
+
|
|
205
|
+
- Initiative: ${initId}
|
|
206
|
+
- Created: ${new Date().toISOString().split('T')[0]}
|
|
207
|
+
`;
|
|
208
|
+
writeFileSync(planPath, template, { encoding: 'utf-8' });
|
|
209
|
+
console.log(`${LOG_PREFIX} Created plan template: ${planPath}`);
|
|
210
|
+
return planPath;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Generate commit message for plan link operation
|
|
214
|
+
*/
|
|
215
|
+
export function getCommitMessage(initId, planUri) {
|
|
216
|
+
const filename = planUri.replace(PLAN_URI_SCHEME, '');
|
|
217
|
+
return `docs: link plan ${filename} to ${initId.toLowerCase()}`;
|
|
218
|
+
}
|
|
219
|
+
async function main() {
|
|
220
|
+
const args = createWUParser({
|
|
221
|
+
name: 'init-plan',
|
|
222
|
+
description: 'Link a plan file to an initiative',
|
|
223
|
+
options: [WU_OPTIONS.initiative, PLAN_OPTION, CREATE_OPTION],
|
|
224
|
+
required: ['initiative'],
|
|
225
|
+
allowPositionalId: false,
|
|
226
|
+
});
|
|
227
|
+
const initId = args.initiative;
|
|
228
|
+
const planPath = args.plan;
|
|
229
|
+
const shouldCreate = args.create;
|
|
230
|
+
// Validate inputs
|
|
231
|
+
validateInitIdFormat(initId);
|
|
232
|
+
// Check initiative exists first (before any mutations)
|
|
233
|
+
const initDoc = checkInitiativeExists(initId);
|
|
234
|
+
const initTitle = initDoc.title;
|
|
235
|
+
// Determine plan path and URI
|
|
236
|
+
let targetPlanPath;
|
|
237
|
+
let planUri;
|
|
238
|
+
if (shouldCreate) {
|
|
239
|
+
// Create mode - will create template and link it
|
|
240
|
+
console.log(`${LOG_PREFIX} Creating plan template for ${initId}...`);
|
|
241
|
+
// Ensure on main for micro-worktree operations
|
|
242
|
+
await ensureOnMain(getGitForCwd());
|
|
243
|
+
try {
|
|
244
|
+
await withMicroWorktree({
|
|
245
|
+
operation: OPERATION_NAME,
|
|
246
|
+
id: initId,
|
|
247
|
+
logPrefix: LOG_PREFIX,
|
|
248
|
+
pushOnly: true,
|
|
249
|
+
execute: async ({ worktreePath }) => {
|
|
250
|
+
// Create plan template
|
|
251
|
+
targetPlanPath = createPlanTemplate(worktreePath, initId, initTitle);
|
|
252
|
+
planUri = formatPlanUri(targetPlanPath);
|
|
253
|
+
// Update initiative with plan link
|
|
254
|
+
updateInitiativeWithPlan(worktreePath, initId, planUri);
|
|
255
|
+
// Return files to commit
|
|
256
|
+
const planRelPath = targetPlanPath.replace(worktreePath + '/', '');
|
|
257
|
+
return {
|
|
258
|
+
commitMessage: getCommitMessage(initId, planUri),
|
|
259
|
+
files: [planRelPath, INIT_PATHS.INITIATIVE(initId)],
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
console.log(`\n${LOG_PREFIX} Transaction complete!`);
|
|
264
|
+
console.log(`\nPlan Linked:`);
|
|
265
|
+
console.log(` Initiative: ${initId}`);
|
|
266
|
+
console.log(` Plan URI: ${planUri}`);
|
|
267
|
+
console.log(` File: ${targetPlanPath}`);
|
|
268
|
+
console.log(`\nNext steps:`);
|
|
269
|
+
console.log(` 1. Edit the plan file with your goals and approach`);
|
|
270
|
+
console.log(` 2. View initiative: pnpm initiative:status ${initId}`);
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
die(`Transaction failed: ${error.message}\n\n` +
|
|
274
|
+
`Micro-worktree cleanup was attempted automatically.\n` +
|
|
275
|
+
`If issue persists, check for orphaned branches: git branch | grep tmp/${OPERATION_NAME}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else if (planPath) {
|
|
279
|
+
// Link existing file mode
|
|
280
|
+
validatePlanPath(planPath);
|
|
281
|
+
planUri = formatPlanUri(planPath);
|
|
282
|
+
console.log(`${LOG_PREFIX} Linking plan to ${initId}...`);
|
|
283
|
+
// Check for idempotent case before micro-worktree
|
|
284
|
+
const existingPlan = initDoc.related_plan;
|
|
285
|
+
if (existingPlan === planUri) {
|
|
286
|
+
console.log(`${LOG_PREFIX} Plan already linked (idempotent - no changes needed)`);
|
|
287
|
+
console.log(`\n${LOG_PREFIX} ${initId} already has related_plan: ${planUri}`);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
// Ensure on main for micro-worktree operations
|
|
291
|
+
await ensureOnMain(getGitForCwd());
|
|
292
|
+
try {
|
|
293
|
+
await withMicroWorktree({
|
|
294
|
+
operation: OPERATION_NAME,
|
|
295
|
+
id: initId,
|
|
296
|
+
logPrefix: LOG_PREFIX,
|
|
297
|
+
pushOnly: true,
|
|
298
|
+
execute: async ({ worktreePath }) => {
|
|
299
|
+
// Update initiative with plan link
|
|
300
|
+
const changed = updateInitiativeWithPlan(worktreePath, initId, planUri);
|
|
301
|
+
if (!changed) {
|
|
302
|
+
console.log(`${LOG_PREFIX} No changes detected (concurrent link operation)`);
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
commitMessage: getCommitMessage(initId, planUri),
|
|
306
|
+
files: [INIT_PATHS.INITIATIVE(initId)],
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
console.log(`\n${LOG_PREFIX} Transaction complete!`);
|
|
311
|
+
console.log(`\nPlan Linked:`);
|
|
312
|
+
console.log(` Initiative: ${initId}`);
|
|
313
|
+
console.log(` Plan URI: ${planUri}`);
|
|
314
|
+
console.log(` File: ${planPath}`);
|
|
315
|
+
console.log(`\nNext steps:`);
|
|
316
|
+
console.log(` - View initiative: pnpm initiative:status ${initId}`);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
die(`Transaction failed: ${error.message}\n\n` +
|
|
320
|
+
`Micro-worktree cleanup was attempted automatically.\n` +
|
|
321
|
+
`If issue persists, check for orphaned branches: git branch | grep tmp/${OPERATION_NAME}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
die('Either --plan or --create is required\n\n' +
|
|
326
|
+
'Usage:\n' +
|
|
327
|
+
' pnpm init:plan --initiative INIT-001 --plan docs/04-operations/plans/my-plan.md\n' +
|
|
328
|
+
' pnpm init:plan --initiative INIT-001 --create');
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// Guard main() for testability - use import.meta.main (WU-1071)
|
|
332
|
+
import { runCLI } from './cli-entry-point.js';
|
|
333
|
+
if (import.meta.main) {
|
|
334
|
+
runCLI(main);
|
|
335
|
+
}
|
|
336
|
+
// Export for testing
|
|
337
|
+
export { main };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* LumenFlow Upgrade CLI Command
|
|
4
|
+
*
|
|
5
|
+
* Updates all @lumenflow/* packages to a specified version or latest.
|
|
6
|
+
* Uses worktree pattern to ensure pnpm install runs in worktree, not main.
|
|
7
|
+
*
|
|
8
|
+
* WU-1112: INIT-003 Phase 6 - Migrate remaining Tier 1 tools
|
|
9
|
+
*
|
|
10
|
+
* Key requirements (from WU acceptance criteria):
|
|
11
|
+
* - Uses worktree pattern (install runs in worktree, not main)
|
|
12
|
+
* - Checks all 7 @lumenflow/* packages (not just 4)
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* pnpm lumenflow:upgrade --version 1.5.0
|
|
16
|
+
* pnpm lumenflow:upgrade --latest
|
|
17
|
+
* pnpm lumenflow:upgrade --latest --dry-run
|
|
18
|
+
*/
|
|
19
|
+
import { execSync } from 'node:child_process';
|
|
20
|
+
import { STDIO_MODES, EXIT_CODES, PKG_MANAGER, } from '@lumenflow/core/dist/wu-constants.js';
|
|
21
|
+
import { runCLI } from './cli-entry-point.js';
|
|
22
|
+
import { validateWorktreeContext } from './deps-add.js';
|
|
23
|
+
/** Log prefix for console output */
|
|
24
|
+
const LOG_PREFIX = '[lumenflow:upgrade]';
|
|
25
|
+
/**
|
|
26
|
+
* All @lumenflow/* packages that should be upgraded together
|
|
27
|
+
*
|
|
28
|
+
* WU-1112: Must include all 7 packages (not just 4 as before)
|
|
29
|
+
* Kept in alphabetical order for consistency
|
|
30
|
+
*/
|
|
31
|
+
export const LUMENFLOW_PACKAGES = [
|
|
32
|
+
'@lumenflow/agent',
|
|
33
|
+
'@lumenflow/cli',
|
|
34
|
+
'@lumenflow/core',
|
|
35
|
+
'@lumenflow/initiatives',
|
|
36
|
+
'@lumenflow/memory',
|
|
37
|
+
'@lumenflow/metrics',
|
|
38
|
+
'@lumenflow/shims',
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Parse command line arguments for lumenflow-upgrade
|
|
42
|
+
*
|
|
43
|
+
* @param argv - Process argv array
|
|
44
|
+
* @returns Parsed arguments
|
|
45
|
+
*/
|
|
46
|
+
export function parseUpgradeArgs(argv) {
|
|
47
|
+
const args = {};
|
|
48
|
+
// Skip node and script name
|
|
49
|
+
const cliArgs = argv.slice(2);
|
|
50
|
+
for (let i = 0; i < cliArgs.length; i++) {
|
|
51
|
+
const arg = cliArgs[i];
|
|
52
|
+
if (arg === '--help' || arg === '-h') {
|
|
53
|
+
args.help = true;
|
|
54
|
+
}
|
|
55
|
+
else if (arg === '--version' || arg === '-v') {
|
|
56
|
+
args.version = cliArgs[++i];
|
|
57
|
+
}
|
|
58
|
+
else if (arg === '--latest' || arg === '-l') {
|
|
59
|
+
args.latest = true;
|
|
60
|
+
}
|
|
61
|
+
else if (arg === '--dry-run' || arg === '-n') {
|
|
62
|
+
args.dryRun = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return args;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build the upgrade commands based on arguments
|
|
69
|
+
*
|
|
70
|
+
* Creates pnpm add command for all @lumenflow/* packages.
|
|
71
|
+
* Uses --save-dev since these are development dependencies.
|
|
72
|
+
*
|
|
73
|
+
* @param args - Parsed upgrade arguments
|
|
74
|
+
* @returns Object containing the commands to run
|
|
75
|
+
*/
|
|
76
|
+
export function buildUpgradeCommands(args) {
|
|
77
|
+
// Determine version specifier
|
|
78
|
+
const versionSpec = args.latest ? 'latest' : args.version || 'latest';
|
|
79
|
+
// Build package list with version
|
|
80
|
+
const packages = LUMENFLOW_PACKAGES.map((pkg) => `${pkg}@${versionSpec}`);
|
|
81
|
+
// Build pnpm add command
|
|
82
|
+
const addCommand = `${PKG_MANAGER} add --save-dev ${packages.join(' ')}`;
|
|
83
|
+
return {
|
|
84
|
+
addCommand,
|
|
85
|
+
versionSpec,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Print help message for lumenflow-upgrade
|
|
90
|
+
*/
|
|
91
|
+
/* istanbul ignore next -- CLI entry point */
|
|
92
|
+
function printHelp() {
|
|
93
|
+
console.log(`
|
|
94
|
+
Usage: lumenflow-upgrade [options]
|
|
95
|
+
|
|
96
|
+
Upgrade all @lumenflow/* packages to a specified version.
|
|
97
|
+
Must be run from inside a worktree to enforce worktree discipline.
|
|
98
|
+
|
|
99
|
+
Options:
|
|
100
|
+
-v, --version <ver> Upgrade to specific version (e.g., 1.5.0)
|
|
101
|
+
-l, --latest Upgrade to latest version
|
|
102
|
+
-n, --dry-run Show commands without executing
|
|
103
|
+
-h, --help Show this help message
|
|
104
|
+
|
|
105
|
+
Packages upgraded (all 7):
|
|
106
|
+
${LUMENFLOW_PACKAGES.map((p) => ` - ${p}`).join('\n')}
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
lumenflow:upgrade --version 1.5.0 # Upgrade to specific version
|
|
110
|
+
lumenflow:upgrade --latest # Upgrade to latest
|
|
111
|
+
lumenflow:upgrade --latest --dry-run # Preview upgrade commands
|
|
112
|
+
|
|
113
|
+
Worktree Discipline:
|
|
114
|
+
This command only works inside a worktree to prevent lockfile
|
|
115
|
+
conflicts on main checkout. Claim a WU first:
|
|
116
|
+
|
|
117
|
+
pnpm wu:claim --id WU-XXXX --lane "Your Lane"
|
|
118
|
+
cd worktrees/<lane>-wu-<id>/
|
|
119
|
+
lumenflow:upgrade --latest
|
|
120
|
+
`);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Main entry point for lumenflow-upgrade command
|
|
124
|
+
*/
|
|
125
|
+
/* istanbul ignore next -- CLI entry point */
|
|
126
|
+
async function main() {
|
|
127
|
+
const args = parseUpgradeArgs(process.argv);
|
|
128
|
+
if (args.help) {
|
|
129
|
+
printHelp();
|
|
130
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
131
|
+
}
|
|
132
|
+
// Require either --version or --latest
|
|
133
|
+
if (!args.version && !args.latest) {
|
|
134
|
+
console.error(`${LOG_PREFIX} Error: Must specify --version <ver> or --latest`);
|
|
135
|
+
printHelp();
|
|
136
|
+
process.exit(EXIT_CODES.ERROR);
|
|
137
|
+
}
|
|
138
|
+
// Validate worktree context (WU-1112 requirement: must run in worktree)
|
|
139
|
+
const validation = validateWorktreeContext(process.cwd());
|
|
140
|
+
if (!validation.valid) {
|
|
141
|
+
console.error(`${LOG_PREFIX} ${validation.error}`);
|
|
142
|
+
console.error(`\nTo fix:\n${validation.fixCommand}`);
|
|
143
|
+
process.exit(EXIT_CODES.ERROR);
|
|
144
|
+
}
|
|
145
|
+
// Build upgrade commands
|
|
146
|
+
const { addCommand, versionSpec } = buildUpgradeCommands(args);
|
|
147
|
+
console.log(`${LOG_PREFIX} Upgrading @lumenflow/* packages to ${versionSpec}`);
|
|
148
|
+
console.log(`${LOG_PREFIX} Packages: ${LUMENFLOW_PACKAGES.length} packages`);
|
|
149
|
+
if (args.dryRun) {
|
|
150
|
+
console.log(`\n${LOG_PREFIX} DRY RUN - Commands that would be executed:`);
|
|
151
|
+
console.log(` ${addCommand}`);
|
|
152
|
+
console.log(`\n${LOG_PREFIX} No changes made.`);
|
|
153
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
154
|
+
}
|
|
155
|
+
// Execute upgrade
|
|
156
|
+
console.log(`${LOG_PREFIX} Running: ${addCommand}`);
|
|
157
|
+
try {
|
|
158
|
+
execSync(addCommand, {
|
|
159
|
+
stdio: STDIO_MODES.INHERIT,
|
|
160
|
+
cwd: process.cwd(),
|
|
161
|
+
});
|
|
162
|
+
console.log(`\n${LOG_PREFIX} ✅ Upgrade complete!`);
|
|
163
|
+
console.log(`${LOG_PREFIX} Upgraded to ${versionSpec}`);
|
|
164
|
+
console.log(`\n${LOG_PREFIX} Next steps:`);
|
|
165
|
+
console.log(` 1. Run 'pnpm build' to rebuild with new versions`);
|
|
166
|
+
console.log(` 2. Run 'pnpm gates' to verify everything works`);
|
|
167
|
+
console.log(` 3. Commit the changes`);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.error(`\n${LOG_PREFIX} ❌ Upgrade failed`);
|
|
171
|
+
console.error(`${LOG_PREFIX} Check the error above and try again.`);
|
|
172
|
+
process.exit(EXIT_CODES.ERROR);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Run main if executed directly
|
|
176
|
+
if (import.meta.main) {
|
|
177
|
+
runCLI(main);
|
|
178
|
+
}
|