@basementuniverse/kanbn 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/docs/commands/burndown.txt +7 -1
  2. package/docs/commands/gantt.txt +36 -0
  3. package/docs/commands/help.txt +1 -0
  4. package/docs/index-structure.md +20 -1
  5. package/docs/quick-start.md +1 -1
  6. package/docs/task-structure.md +47 -0
  7. package/example/.kanbn/index.md +63 -0
  8. package/example/.kanbn/tasks/add-basic-activity-feed.md +53 -0
  9. package/example/.kanbn/tasks/add-passwordless-login-option.md +34 -0
  10. package/example/.kanbn/tasks/add-usage-alert-email-thresholds.md +35 -0
  11. package/example/.kanbn/tasks/build-email-template-system.md +30 -0
  12. package/example/.kanbn/tasks/build-invoice-download-endpoint.md +43 -0
  13. package/example/.kanbn/tasks/build-tenant-settings-page.md +48 -0
  14. package/example/.kanbn/tasks/create-organization-switcher.md +53 -0
  15. package/example/.kanbn/tasks/create-sandbox-environment-provisioner.md +36 -0
  16. package/example/.kanbn/tasks/create-self-serve-cancellation-flow.md +38 -0
  17. package/example/.kanbn/tasks/define-product-pricing-strategy.md +37 -0
  18. package/example/.kanbn/tasks/design-onboarding-checklist.md +30 -0
  19. package/example/.kanbn/tasks/design-team-invite-expiry-flow.md +33 -0
  20. package/example/.kanbn/tasks/implement-data-retention-policy-jobs.md +30 -0
  21. package/example/.kanbn/tasks/implement-feature-flags-foundation.md +36 -0
  22. package/example/.kanbn/tasks/implement-project-creation-wizard.md +44 -0
  23. package/example/.kanbn/tasks/implement-stripe-webhook-signature-check.md +54 -0
  24. package/example/.kanbn/tasks/implement-team-permissions-ui.md +57 -0
  25. package/example/.kanbn/tasks/implement-user-signup-and-login.md +62 -0
  26. package/example/.kanbn/tasks/integrate-crm-lead-sync.md +35 -0
  27. package/example/.kanbn/tasks/legal-review-terms-and-privacy.md +30 -0
  28. package/example/.kanbn/tasks/migrate-legacy-events-to-new-schema.md +48 -0
  29. package/example/.kanbn/tasks/optimize-dashboard-first-load.md +52 -0
  30. package/example/.kanbn/tasks/prototype-report-export-scheduler.md +34 -0
  31. package/example/.kanbn/tasks/publish-internal-qa-checklist.md +53 -0
  32. package/example/.kanbn/tasks/setup-ci-pipeline.md +53 -0
  33. package/package.json +3 -2
  34. package/routes/gantt.json +27 -0
  35. package/skills/kanbn-plan/SKILL.md +0 -0
  36. package/src/board.js +21 -2
  37. package/src/controller/add.js +33 -1
  38. package/src/controller/burndown.js +72 -5
  39. package/src/controller/edit.js +68 -1
  40. package/src/controller/find.js +5 -0
  41. package/src/controller/gantt.js +375 -0
  42. package/src/controller/init.js +2 -1
  43. package/src/controller/sort.js +8 -0
  44. package/src/main.d.ts +295 -340
  45. package/src/main.js +2591 -2050
  46. package/src/parse-task.js +211 -3
@@ -0,0 +1,375 @@
1
+ const kanbn = require('../main');
2
+ const utility = require('../utility');
3
+ const formatDate = require('dateformat');
4
+ const chrono = require('chrono-node');
5
+
6
+ const NOW_MARKER = '┆';
7
+ const ANSI_RESET = '\x1b[0m';
8
+ const ANSI_FG_LINE = '\x1b[97m';
9
+ const ANSI_FG_NOW = '\x1b[90m';
10
+ const ANSI_BG_NOT_STARTED = '\x1b[100m';
11
+ const ANSI_BG_STARTED = '\x1b[44m';
12
+ const ANSI_BG_COMPLETED = '\x1b[42m';
13
+
14
+ const DIR_UP = 1;
15
+ const DIR_DOWN = 2;
16
+ const DIR_LEFT = 4;
17
+ const DIR_RIGHT = 8;
18
+
19
+ const LINE_CHARS = {
20
+ [DIR_UP]: '│',
21
+ [DIR_DOWN]: '│',
22
+ [DIR_LEFT]: '─',
23
+ [DIR_RIGHT]: '─',
24
+ [DIR_UP | DIR_DOWN]: '│',
25
+ [DIR_LEFT | DIR_RIGHT]: '─',
26
+ [DIR_DOWN | DIR_RIGHT]: '┌',
27
+ [DIR_DOWN | DIR_LEFT]: '┐',
28
+ [DIR_UP | DIR_RIGHT]: '└',
29
+ [DIR_UP | DIR_LEFT]: '┘',
30
+ [DIR_UP | DIR_DOWN | DIR_RIGHT]: '├',
31
+ [DIR_UP | DIR_DOWN | DIR_LEFT]: '┤',
32
+ [DIR_UP | DIR_LEFT | DIR_RIGHT]: '┴',
33
+ [DIR_DOWN | DIR_LEFT | DIR_RIGHT]: '┬',
34
+ [DIR_UP | DIR_DOWN | DIR_LEFT | DIR_RIGHT]: '┼'
35
+ };
36
+
37
+ function getBarGeometry(task, from, to, width) {
38
+ if (width <= 1 || from.getTime() === to.getTime()) {
39
+ return { start: 0, end: 0 };
40
+ }
41
+
42
+ // Calculate the position in the chart
43
+ const totalSpan = to.getTime() - from.getTime();
44
+ const taskStartPos = Math.max(0, Math.round((task.start.getTime() - from.getTime()) / totalSpan * (width - 1)));
45
+ const taskEndPos = Math.min(width - 1, Math.round((task.end.getTime() - from.getTime()) / totalSpan * (width - 1)));
46
+
47
+ return {
48
+ start: taskStartPos,
49
+ end: taskEndPos
50
+ };
51
+ }
52
+
53
+ function getBarBackground(task) {
54
+ if (task.completed instanceof Date) {
55
+ return ANSI_BG_COMPLETED;
56
+ }
57
+ if (task.started instanceof Date) {
58
+ return ANSI_BG_STARTED;
59
+ }
60
+ return ANSI_BG_NOT_STARTED;
61
+ }
62
+
63
+ function createChartCell() {
64
+ return {
65
+ bg: null,
66
+ lineMask: 0,
67
+ arrowChar: null
68
+ };
69
+ }
70
+
71
+ function createChartGrid(height, width) {
72
+ return Array.from({ length: height }, () => Array.from({ length: width }, createChartCell));
73
+ }
74
+
75
+ function addMask(cell, mask) {
76
+ cell.lineMask |= mask;
77
+ }
78
+
79
+ function addHorizontalConnection(grid, row, fromCol, toCol) {
80
+ if (fromCol === toCol) {
81
+ return;
82
+ }
83
+
84
+ const step = fromCol < toCol ? 1 : -1;
85
+ for (let col = fromCol; col !== toCol; col += step) {
86
+ addMask(grid[row][col], step > 0 ? DIR_RIGHT : DIR_LEFT);
87
+ addMask(grid[row][col + step], step > 0 ? DIR_LEFT : DIR_RIGHT);
88
+ }
89
+ }
90
+
91
+ function addVerticalConnection(grid, col, fromRow, toRow) {
92
+ if (fromRow === toRow) {
93
+ return;
94
+ }
95
+
96
+ const step = fromRow < toRow ? 1 : -1;
97
+ for (let row = fromRow; row !== toRow; row += step) {
98
+ addMask(grid[row][col], step > 0 ? DIR_DOWN : DIR_UP);
99
+ addMask(grid[row + step][col], step > 0 ? DIR_UP : DIR_DOWN);
100
+ }
101
+ }
102
+
103
+ function routeDependency(grid, sourceRow, sourceCol, targetRow, targetCol) {
104
+ if (sourceRow === null || targetRow === null) {
105
+ return;
106
+ }
107
+
108
+ if (sourceRow === targetRow) {
109
+ addHorizontalConnection(grid, sourceRow, sourceCol, targetCol);
110
+ grid[targetRow][targetCol].arrowChar = targetCol >= sourceCol ? '→' : '←';
111
+ return;
112
+ }
113
+
114
+ const moveRight = targetCol >= sourceCol;
115
+ let routeCol = moveRight ? Math.max(sourceCol + 1, targetCol - 1) : Math.min(sourceCol - 1, targetCol + 1);
116
+ routeCol = Math.max(0, Math.min(grid[0].length - 1, routeCol));
117
+
118
+ addHorizontalConnection(grid, sourceRow, sourceCol, routeCol);
119
+ addVerticalConnection(grid, routeCol, sourceRow, targetRow);
120
+ addHorizontalConnection(grid, targetRow, routeCol, targetCol);
121
+ grid[targetRow][targetCol].arrowChar = targetCol >= routeCol ? '→' : '←';
122
+ }
123
+
124
+ function buildDependencyOverlay(tasks, barGeometries, width) {
125
+ const grid = createChartGrid(tasks.length, width);
126
+ const taskRowMap = new Map(tasks.map((task, index) => [task.id, index]));
127
+
128
+ tasks.forEach((task, targetRow) => {
129
+ (task.dependencies || []).forEach((dependencyId) => {
130
+ const sourceRow = taskRowMap.get(dependencyId);
131
+ if (sourceRow === undefined) {
132
+ return;
133
+ }
134
+
135
+ routeDependency(
136
+ grid,
137
+ sourceRow,
138
+ barGeometries[sourceRow].end,
139
+ targetRow,
140
+ barGeometries[targetRow].start
141
+ );
142
+ });
143
+ });
144
+
145
+ return grid;
146
+ }
147
+
148
+ function styleCell(char, fg = null, bg = null) {
149
+ if (!fg && !bg) {
150
+ return char;
151
+ }
152
+
153
+ return `${fg || ''}${bg || ''}${char}${ANSI_RESET}`;
154
+ }
155
+
156
+ function renderChartRow(gridRow, barGeometry, barBackground, nowPosition) {
157
+ return gridRow.map((cell, column) => {
158
+ const bg = column >= barGeometry.start && column <= barGeometry.end ? barBackground : null;
159
+ if (cell.arrowChar) {
160
+ return styleCell(cell.arrowChar, ANSI_FG_LINE, bg);
161
+ }
162
+
163
+ const lineChar = LINE_CHARS[cell.lineMask] || null;
164
+ if (lineChar) {
165
+ return styleCell(lineChar, ANSI_FG_LINE, bg);
166
+ }
167
+
168
+ if (nowPosition === column) {
169
+ return styleCell(NOW_MARKER, ANSI_FG_NOW, bg);
170
+ }
171
+
172
+ return styleCell(' ', null, bg);
173
+ }).join('');
174
+ }
175
+
176
+ function renderTickRow(ticks, nowPosition) {
177
+ return ticks.split('').map((char, column) => {
178
+ if (char !== ' ') {
179
+ return styleCell(char, ANSI_FG_LINE, null);
180
+ }
181
+ if (nowPosition === column) {
182
+ return styleCell(NOW_MARKER, ANSI_FG_NOW, null);
183
+ }
184
+ return char;
185
+ }).join('');
186
+ }
187
+
188
+ function getLabelPlacements(from, to, width, dateFormat, maxLabels) {
189
+ for (let count = maxLabels; count >= 1; count--) {
190
+ const placements = [];
191
+ let previousEnd = -1;
192
+
193
+ for (let i = 0; i < count; i++) {
194
+ const ratio = count === 1 ? 0 : i / (count - 1);
195
+ const position = Math.round(ratio * (width - 1));
196
+ const value = new Date(from.getTime() + Math.round((to.getTime() - from.getTime()) * ratio));
197
+ const label = formatDate(value, dateFormat);
198
+
199
+ let start = position - Math.floor(label.length / 2);
200
+ if (start < 0) {
201
+ start = 0;
202
+ }
203
+ if (start + label.length > width) {
204
+ start = Math.max(0, width - label.length);
205
+ }
206
+
207
+ const end = start + label.length - 1;
208
+ if (i > 0 && start <= previousEnd + 1) {
209
+ placements.length = 0;
210
+ break;
211
+ }
212
+
213
+ placements.push({ position, start, label, end });
214
+ previousEnd = end;
215
+ }
216
+
217
+ if (placements.length) {
218
+ return placements;
219
+ }
220
+ }
221
+
222
+ return [];
223
+ }
224
+
225
+ function renderXAxisLabels(from, to, width, dateFormat) {
226
+ const sampleLabel = formatDate(from, dateFormat);
227
+ const maxLabels = Math.max(1, Math.floor((width + 2) / (sampleLabel.length + 2)));
228
+ const placements = getLabelPlacements(from, to, width, dateFormat, maxLabels);
229
+
230
+ const ticks = Array(width).fill(' ');
231
+ const labels = Array(width).fill(' ');
232
+
233
+ for (const placement of placements) {
234
+ ticks[placement.position] = '│';
235
+ for (let i = 0; i < placement.label.length; i++) {
236
+ labels[placement.start + i] = placement.label[i];
237
+ }
238
+ }
239
+
240
+ return [ticks.join(''), labels.join('')];
241
+ }
242
+
243
+ function getNowPosition(from, to, width, now = new Date()) {
244
+ if (now < from || now > to) {
245
+ return null;
246
+ }
247
+
248
+ const totalSpan = to.getTime() - from.getTime();
249
+ return Math.round((now.getTime() - from.getTime()) / totalSpan * (width - 1));
250
+ }
251
+
252
+ function renderNowOverlay(line, nowPosition) {
253
+ if (nowPosition === null || nowPosition < 0 || nowPosition >= line.length) {
254
+ return line;
255
+ }
256
+
257
+ const result = line.split('');
258
+ result[nowPosition] = NOW_MARKER;
259
+ return result.join('');
260
+ }
261
+
262
+ function truncateName(name, maxWidth) {
263
+ if (name.length <= maxWidth) {
264
+ return name;
265
+ }
266
+ return name.substring(0, maxWidth - 1) + '…';
267
+ }
268
+
269
+ module.exports = async args => {
270
+
271
+ // Make sure kanbn has been initialised
272
+ if (!await kanbn.initialised()) {
273
+ utility.error('Kanbn has not been initialised in this folder\nTry running: {b}kanbn init{b}');
274
+ return;
275
+ }
276
+ const index = await kanbn.getIndex();
277
+
278
+ // Get assigned
279
+ let assigned = null;
280
+ if (args.assigned) {
281
+ assigned = utility.strArg(args.assigned);
282
+ }
283
+
284
+ // Get columns
285
+ let columns = null;
286
+ if (args.column) {
287
+ columns = utility.arrayArg(args.column);
288
+ }
289
+
290
+ // Get dates
291
+ let dates = null;
292
+ if (args.date) {
293
+ dates = utility.arrayArg(args.date);
294
+ if (dates.length) {
295
+ for (let i = 0; i < dates.length; i++) {
296
+ const dateValue = chrono.parseDate(dates[i]);
297
+ if (dateValue === null) {
298
+ utility.error('Unable to parse date');
299
+ return;
300
+ }
301
+ dates[i] = dateValue;
302
+ }
303
+ }
304
+ }
305
+
306
+ // Get mocked now date
307
+ let now = null;
308
+ if (args.now) {
309
+ now = chrono.parseDate(utility.strArg(args.now));
310
+ if (now === null) {
311
+ utility.error('Unable to parse now date');
312
+ return;
313
+ }
314
+ }
315
+
316
+ // Show gantt chart data
317
+ kanbn
318
+ .gantt(assigned, columns, dates, now)
319
+ .then(data => {
320
+ if (args.json) {
321
+
322
+ // Output raw data
323
+ console.log(JSON.stringify(data, null, 2));
324
+ } else {
325
+
326
+ // Render chart
327
+ const dateFormat = kanbn.getDateFormat(index);
328
+ const maxNameWidth = 16;
329
+ const nowDate = now || new Date();
330
+
331
+ // Keep each rendered task line within terminal width where possible.
332
+ // Line shape: "<prefix> <name> │<bar>│" => maxNameWidth + barWidth + 5 columns.
333
+ const terminalWidth = Number.isFinite(process.stdout.columns) && process.stdout.columns > 0
334
+ ? process.stdout.columns
335
+ : 120;
336
+ const barWidth = Math.max(1, terminalWidth - maxNameWidth - 5);
337
+ const nowPosition = getNowPosition(data.from, data.to, barWidth, nowDate);
338
+ const barGeometries = data.tasks.map((task) => getBarGeometry(task, data.from, data.to, barWidth));
339
+ const dependencyOverlay = buildDependencyOverlay(data.tasks, barGeometries, barWidth);
340
+
341
+ // Render header
342
+ console.log(`Gantt chart: ${formatDate(data.from, dateFormat)} to ${formatDate(data.to, dateFormat)}`);
343
+ if (data.dependencyCycleDetected) {
344
+ const cycleDescription = Array.isArray(data.dependencyCycleTaskIds) && data.dependencyCycleTaskIds.length
345
+ ? ` Cycle: ${data.dependencyCycleTaskIds.join(' -> ')}.`
346
+ : '';
347
+ console.error(`Warning: dependency cycle detected; using fallback ordering for ${data.cycleFallbackTaskIds.length} task(s).${cycleDescription}`);
348
+ }
349
+ console.log('');
350
+
351
+ // Render tasks with bars
352
+ data.tasks.forEach((task, taskIndex) => {
353
+ const prefix = task.blocked ? '⧗' : ' ';
354
+ const truncatedName = truncateName(task.name, maxNameWidth);
355
+ const bar = renderChartRow(
356
+ dependencyOverlay[taskIndex],
357
+ barGeometries[taskIndex],
358
+ getBarBackground(task),
359
+ nowPosition
360
+ );
361
+
362
+ console.log(`${prefix} ${truncatedName.padEnd(maxNameWidth)} │${bar}│`);
363
+ });
364
+
365
+ // Render x-axis
366
+ console.log('');
367
+ const [ticks, labels] = renderXAxisLabels(data.from, data.to, barWidth, dateFormat);
368
+ console.log(` ${''.padEnd(maxNameWidth)} │${renderTickRow(ticks, nowPosition)}│`);
369
+ console.log(` ${''.padEnd(maxNameWidth)} │${labels}│`);
370
+ }
371
+ })
372
+ .catch(error => {
373
+ utility.error(error);
374
+ });
375
+ };
@@ -1,4 +1,5 @@
1
- const kanbn = require('../main');
1
+ const kanbn_module = require('../main');
2
+ const kanbn = new kanbn_module.Kanbn();
2
3
  const utility = require('../utility');
3
4
  const inquirer = require('inquirer');
4
5
 
@@ -122,6 +122,14 @@ const sorterFields = [
122
122
  ],
123
123
  filterable: false
124
124
  },
125
+ {
126
+ name: 'Postponed date',
127
+ field: 'postponed',
128
+ options: [
129
+ '--postponed'
130
+ ],
131
+ filterable: false
132
+ },
125
133
  {
126
134
  name: 'Completed date',
127
135
  field: 'completed',