prjct-cli 0.8.6 → 0.9.1

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 (47) hide show
  1. package/CHANGELOG.md +216 -0
  2. package/CLAUDE.md +34 -0
  3. package/core/agentic/agent-router.js +482 -0
  4. package/core/agentic/command-executor.js +70 -15
  5. package/core/agentic/context-builder.js +4 -3
  6. package/core/agentic/context-filter.js +545 -0
  7. package/core/agentic/prompt-builder.js +48 -38
  8. package/core/agentic/tool-registry.js +35 -0
  9. package/core/command-registry.js +104 -164
  10. package/core/commands.js +84 -0
  11. package/core/domain/agent-generator.js +55 -44
  12. package/core/domain/architecture-generator.js +561 -0
  13. package/core/domain/task-stack.js +496 -0
  14. package/core/infrastructure/legacy-installer-detector.js +546 -0
  15. package/core/infrastructure/session-manager.js +14 -2
  16. package/core/infrastructure/setup.js +29 -11
  17. package/core/utils/jsonl-helper.js +137 -0
  18. package/package.json +1 -1
  19. package/scripts/install.sh +45 -8
  20. package/scripts/postinstall.js +5 -5
  21. package/templates/agents/AGENTS.md +3 -3
  22. package/templates/commands/analyze.md +10 -53
  23. package/templates/commands/ask.md +25 -338
  24. package/templates/commands/bug.md +11 -70
  25. package/templates/commands/build.md +8 -35
  26. package/templates/commands/cleanup.md +9 -32
  27. package/templates/commands/dash.md +241 -0
  28. package/templates/commands/design.md +5 -28
  29. package/templates/commands/done.md +6 -20
  30. package/templates/commands/feature.md +12 -225
  31. package/templates/commands/help.md +26 -313
  32. package/templates/commands/idea.md +7 -25
  33. package/templates/commands/init.md +15 -191
  34. package/templates/commands/migrate-all.md +25 -84
  35. package/templates/commands/next.md +6 -26
  36. package/templates/commands/now.md +6 -25
  37. package/templates/commands/pause.md +18 -0
  38. package/templates/commands/progress.md +5 -50
  39. package/templates/commands/recap.md +5 -54
  40. package/templates/commands/resume.md +97 -0
  41. package/templates/commands/ship.md +14 -135
  42. package/templates/commands/status.md +7 -32
  43. package/templates/commands/suggest.md +36 -495
  44. package/templates/commands/sync.md +7 -24
  45. package/templates/commands/work.md +44 -0
  46. package/templates/commands/workflow.md +3 -25
  47. package/templates/planning-methodology.md +195 -0
@@ -0,0 +1,496 @@
1
+ /**
2
+ * Task Stack Manager - Handles multiple concurrent tasks with pause/resume capability
3
+ * Enables natural workflow with interruptions and context switching
4
+ */
5
+
6
+ const path = require('path');
7
+ const fs = require('fs').promises;
8
+
9
+ class TaskStack {
10
+ constructor(projectPath) {
11
+ this.projectPath = projectPath;
12
+ this.stackPath = path.join(projectPath, 'core', 'stack.jsonl');
13
+ this.nowPath = path.join(projectPath, 'core', 'now.md');
14
+ }
15
+
16
+ /**
17
+ * Initialize stack system - migrate from legacy now.md if needed
18
+ */
19
+ async initialize() {
20
+ try {
21
+ // Check if stack already exists
22
+ await fs.access(this.stackPath);
23
+ return { migrated: false };
24
+ } catch {
25
+ // Stack doesn't exist, check for legacy now.md
26
+ return await this.migrateFromLegacy();
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Migrate from legacy now.md to stack system
32
+ */
33
+ async migrateFromLegacy() {
34
+ try {
35
+ const nowContent = await fs.readFile(this.nowPath, 'utf8');
36
+
37
+ if (!nowContent.trim() || nowContent.includes('No active task')) {
38
+ // Empty or no task, just create empty stack
39
+ await this.ensureStackFile();
40
+ return { migrated: true, hadTask: false };
41
+ }
42
+
43
+ // Parse task from now.md
44
+ const task = this.parseNowFile(nowContent);
45
+
46
+ // Create initial stack entry
47
+ const entry = {
48
+ id: `task-${Date.now()}`,
49
+ task: task.description || 'Migrated task',
50
+ agent: task.agent || 'unknown',
51
+ status: 'active',
52
+ started: task.started || new Date().toISOString(),
53
+ paused: null,
54
+ resumed: null,
55
+ completed: null,
56
+ duration: null,
57
+ complexity: task.complexity || 'moderate',
58
+ dev: task.dev || 'unknown'
59
+ };
60
+
61
+ // Write to stack
62
+ await this.appendToStack(entry);
63
+
64
+ return { migrated: true, hadTask: true, task: entry };
65
+ } catch (error) {
66
+ // No now.md or error reading, just create empty stack
67
+ await this.ensureStackFile();
68
+ return { migrated: true, hadTask: false, error: error.message };
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Parse legacy now.md format
74
+ */
75
+ parseNowFile(content) {
76
+ const result = {
77
+ description: '',
78
+ started: null,
79
+ agent: null,
80
+ complexity: null,
81
+ dev: null
82
+ };
83
+
84
+ // Check for frontmatter
85
+ if (content.startsWith('---')) {
86
+ const frontmatterEnd = content.indexOf('---', 3);
87
+ if (frontmatterEnd > 0) {
88
+ const frontmatter = content.substring(3, frontmatterEnd);
89
+ const lines = frontmatter.split('\n');
90
+
91
+ for (const line of lines) {
92
+ if (line.includes('task:')) {
93
+ result.description = line.split('task:')[1].trim().replace(/['"]/g, '');
94
+ }
95
+ if (line.includes('started:')) {
96
+ result.started = line.split('started:')[1].trim();
97
+ }
98
+ if (line.includes('agent:')) {
99
+ result.agent = line.split('agent:')[1].trim();
100
+ }
101
+ if (line.includes('complexity:')) {
102
+ result.complexity = line.split('complexity:')[1].trim();
103
+ }
104
+ if (line.includes('dev:')) {
105
+ result.dev = line.split('dev:')[1].trim();
106
+ }
107
+ }
108
+
109
+ // Get description from content if not in frontmatter
110
+ if (!result.description) {
111
+ const contentBody = content.substring(frontmatterEnd + 3).trim();
112
+ const firstLine = contentBody.split('\n')[0];
113
+ if (firstLine && !firstLine.startsWith('#')) {
114
+ result.description = firstLine.replace(/^[*-]\s*/, '').trim();
115
+ }
116
+ }
117
+ }
118
+ } else {
119
+ // No frontmatter, try to extract task from content
120
+ const lines = content.split('\n');
121
+ for (const line of lines) {
122
+ if (line.trim() && !line.startsWith('#') && !line.startsWith('---')) {
123
+ result.description = line.replace(/^[*-]\s*/, '').trim();
124
+ break;
125
+ }
126
+ }
127
+ }
128
+
129
+ return result;
130
+ }
131
+
132
+ /**
133
+ * Ensure stack file exists
134
+ */
135
+ async ensureStackFile() {
136
+ try {
137
+ await fs.access(this.stackPath);
138
+ } catch {
139
+ // Create empty file
140
+ await fs.writeFile(this.stackPath, '');
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Append entry to stack
146
+ */
147
+ async appendToStack(entry) {
148
+ await this.ensureStackFile();
149
+ const line = JSON.stringify(entry) + '\n';
150
+ await fs.appendFile(this.stackPath, line);
151
+ }
152
+
153
+ /**
154
+ * Read all stack entries
155
+ */
156
+ async readStack() {
157
+ await this.ensureStackFile();
158
+ const content = await fs.readFile(this.stackPath, 'utf8');
159
+
160
+ if (!content.trim()) {
161
+ return [];
162
+ }
163
+
164
+ const entries = [];
165
+ const lines = content.split('\n').filter(line => line.trim());
166
+
167
+ for (const line of lines) {
168
+ try {
169
+ entries.push(JSON.parse(line));
170
+ } catch (error) {
171
+ console.error('Error parsing stack line:', error);
172
+ }
173
+ }
174
+
175
+ return entries;
176
+ }
177
+
178
+ /**
179
+ * Get active task
180
+ */
181
+ async getActiveTask() {
182
+ const stack = await this.readStack();
183
+ return stack.find(task => task.status === 'active') || null;
184
+ }
185
+
186
+ /**
187
+ * Get paused tasks
188
+ */
189
+ async getPausedTasks() {
190
+ const stack = await this.readStack();
191
+ return stack.filter(task => task.status === 'paused')
192
+ .sort((a, b) => new Date(b.paused) - new Date(a.paused)); // Most recently paused first
193
+ }
194
+
195
+ /**
196
+ * Get all incomplete tasks
197
+ */
198
+ async getIncompleteTasks() {
199
+ const stack = await this.readStack();
200
+ return stack.filter(task => task.status !== 'completed');
201
+ }
202
+
203
+ /**
204
+ * Start a new task
205
+ */
206
+ async startTask(description, agent = 'general', complexity = 'moderate') {
207
+ // Check if there's already an active task
208
+ const active = await this.getActiveTask();
209
+ if (active) {
210
+ throw new Error(`Already working on: ${active.task}. Use /p:pause to pause it first.`);
211
+ }
212
+
213
+ const entry = {
214
+ id: `task-${Date.now()}`,
215
+ task: description,
216
+ agent,
217
+ status: 'active',
218
+ started: new Date().toISOString(),
219
+ paused: null,
220
+ resumed: null,
221
+ completed: null,
222
+ duration: null,
223
+ complexity,
224
+ dev: await this.getCurrentDev()
225
+ };
226
+
227
+ await this.appendToStack(entry);
228
+ await this.updateNowFile(entry);
229
+
230
+ return entry;
231
+ }
232
+
233
+ /**
234
+ * Pause the active task
235
+ */
236
+ async pauseTask(reason = '') {
237
+ const active = await this.getActiveTask();
238
+ if (!active) {
239
+ throw new Error('No active task to pause');
240
+ }
241
+
242
+ // Update the task
243
+ active.status = 'paused';
244
+ active.paused = new Date().toISOString();
245
+ if (reason) {
246
+ active.pauseReason = reason;
247
+ }
248
+
249
+ // Rewrite stack with updated task
250
+ await this.updateTask(active);
251
+
252
+ // Update now.md to show paused state
253
+ await this.updateNowFile(null, `Paused: ${active.task}`);
254
+
255
+ return active;
256
+ }
257
+
258
+ /**
259
+ * Resume a paused task
260
+ */
261
+ async resumeTask(taskId = null) {
262
+ // Check if there's an active task
263
+ const active = await this.getActiveTask();
264
+ if (active) {
265
+ throw new Error(`Already working on: ${active.task}. Complete or pause it first.`);
266
+ }
267
+
268
+ const paused = await this.getPausedTasks();
269
+ if (paused.length === 0) {
270
+ throw new Error('No paused tasks to resume');
271
+ }
272
+
273
+ let taskToResume;
274
+ if (taskId) {
275
+ taskToResume = paused.find(t => t.id === taskId);
276
+ if (!taskToResume) {
277
+ throw new Error(`Task ${taskId} not found or not paused`);
278
+ }
279
+ } else {
280
+ // Resume most recently paused
281
+ taskToResume = paused[0];
282
+ }
283
+
284
+ // Update the task
285
+ taskToResume.status = 'active';
286
+ taskToResume.resumed = new Date().toISOString();
287
+
288
+ // Calculate paused duration
289
+ if (taskToResume.paused) {
290
+ const pausedMs = new Date() - new Date(taskToResume.paused);
291
+ taskToResume.pausedDuration = (taskToResume.pausedDuration || 0) + pausedMs;
292
+ }
293
+
294
+ // Rewrite stack with updated task
295
+ await this.updateTask(taskToResume);
296
+
297
+ // Update now.md
298
+ await this.updateNowFile(taskToResume);
299
+
300
+ return taskToResume;
301
+ }
302
+
303
+ /**
304
+ * Complete the active task
305
+ */
306
+ async completeTask() {
307
+ const active = await this.getActiveTask();
308
+ if (!active) {
309
+ throw new Error('No active task to complete');
310
+ }
311
+
312
+ // Update the task
313
+ active.status = 'completed';
314
+ active.completed = new Date().toISOString();
315
+
316
+ // Calculate duration (excluding paused time)
317
+ const totalMs = new Date() - new Date(active.started);
318
+ const pausedMs = active.pausedDuration || 0;
319
+ active.duration = totalMs - pausedMs;
320
+ active.durationFormatted = this.formatDuration(active.duration);
321
+
322
+ // Rewrite stack with updated task
323
+ await this.updateTask(active);
324
+
325
+ // Clear now.md
326
+ await this.updateNowFile(null, '');
327
+
328
+ return active;
329
+ }
330
+
331
+ /**
332
+ * Switch tasks (atomic pause + resume/start)
333
+ */
334
+ async switchTask(targetTaskOrDescription) {
335
+ const active = await this.getActiveTask();
336
+ let pausedTask = null;
337
+
338
+ // Pause current if exists
339
+ if (active) {
340
+ pausedTask = await this.pauseTask('Switched to another task');
341
+ }
342
+
343
+ try {
344
+ // Check if target is a task ID or description
345
+ const paused = await this.getPausedTasks();
346
+ const existingTask = paused.find(t => t.id === targetTaskOrDescription);
347
+
348
+ if (existingTask) {
349
+ // Resume existing task
350
+ return {
351
+ paused: pausedTask,
352
+ resumed: await this.resumeTask(targetTaskOrDescription),
353
+ type: 'resumed'
354
+ };
355
+ } else {
356
+ // Start new task
357
+ return {
358
+ paused: pausedTask,
359
+ started: await this.startTask(targetTaskOrDescription),
360
+ type: 'started'
361
+ };
362
+ }
363
+ } catch (error) {
364
+ // If switch fails, resume the original task
365
+ if (pausedTask) {
366
+ await this.resumeTask(pausedTask.id);
367
+ }
368
+ throw error;
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Update a task in the stack
374
+ */
375
+ async updateTask(updatedTask) {
376
+ const stack = await this.readStack();
377
+ const index = stack.findIndex(t => t.id === updatedTask.id);
378
+
379
+ if (index === -1) {
380
+ throw new Error(`Task ${updatedTask.id} not found`);
381
+ }
382
+
383
+ stack[index] = updatedTask;
384
+
385
+ // Rewrite entire file (JSONL format)
386
+ const content = stack.map(task => JSON.stringify(task)).join('\n') + '\n';
387
+ await fs.writeFile(this.stackPath, content);
388
+ }
389
+
390
+ /**
391
+ * Update now.md to reflect current state
392
+ */
393
+ async updateNowFile(task, customContent = null) {
394
+ let content;
395
+
396
+ if (customContent !== undefined && customContent !== null) {
397
+ content = customContent;
398
+ } else if (!task) {
399
+ content = `# Current Task
400
+
401
+ **No active task**
402
+
403
+ Use \`/p:work\` or \`/p:resume\` to start working.
404
+
405
+ ---
406
+
407
+ _Track your focus with \`/p:work [task]\`_
408
+ `;
409
+ } else {
410
+ const started = new Date(task.started);
411
+ const now = new Date();
412
+ const elapsed = this.formatDuration(now - started - (task.pausedDuration || 0));
413
+
414
+ content = `---
415
+ task: "${task.task}"
416
+ started: ${task.started}
417
+ agent: ${task.agent}
418
+ complexity: ${task.complexity}
419
+ dev: ${task.dev}
420
+ ---
421
+
422
+ # Current Task
423
+
424
+ **${task.task}**
425
+
426
+ - Started: ${started.toLocaleTimeString()} (${elapsed} ago)
427
+ - Agent: ${task.agent}
428
+ - Complexity: ${task.complexity}
429
+
430
+ ---
431
+
432
+ When done: \`/p:done\`
433
+ Need to pause: \`/p:pause\`
434
+ `;
435
+ }
436
+
437
+ await fs.writeFile(this.nowPath, content);
438
+ }
439
+
440
+ /**
441
+ * Get current developer from git or system
442
+ */
443
+ async getCurrentDev() {
444
+ try {
445
+ const { exec } = require('child_process');
446
+ const { promisify } = require('util');
447
+ const execAsync = promisify(exec);
448
+
449
+ const { stdout } = await execAsync('git config user.name');
450
+ return stdout.trim();
451
+ } catch {
452
+ return 'unknown';
453
+ }
454
+ }
455
+
456
+ /**
457
+ * Format duration in human-readable format
458
+ */
459
+ formatDuration(ms) {
460
+ const seconds = Math.floor(ms / 1000);
461
+ const minutes = Math.floor(seconds / 60);
462
+ const hours = Math.floor(minutes / 60);
463
+ const days = Math.floor(hours / 24);
464
+
465
+ if (days > 0) {
466
+ return `${days}d ${hours % 24}h`;
467
+ } else if (hours > 0) {
468
+ return `${hours}h ${minutes % 60}m`;
469
+ } else if (minutes > 0) {
470
+ return `${minutes}m`;
471
+ } else {
472
+ return `${seconds}s`;
473
+ }
474
+ }
475
+
476
+ /**
477
+ * Get stack summary for display
478
+ */
479
+ async getStackSummary() {
480
+ const active = await this.getActiveTask();
481
+ const paused = await this.getPausedTasks();
482
+ const stack = await this.readStack();
483
+ const completed = stack.filter(t => t.status === 'completed');
484
+
485
+ return {
486
+ active,
487
+ paused,
488
+ pausedCount: paused.length,
489
+ completed,
490
+ completedCount: completed.length,
491
+ totalTasks: stack.length
492
+ };
493
+ }
494
+ }
495
+
496
+ module.exports = TaskStack;