@a-company/paradigm 3.0.3 → 3.1.2

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 (32) hide show
  1. package/dist/{triage-RM5KNG5V.js → chunk-4LGLU2LO.js} +1035 -663
  2. package/dist/{chunk-4WR7X3FE.js → chunk-AQZSUGL3.js} +42 -6
  3. package/dist/{chunk-27OSFWHG.js → chunk-MVXJVRFI.js} +98 -1
  4. package/dist/{chunk-S65LENNL.js → chunk-VZ7CXFRZ.js} +248 -3
  5. package/dist/delete-W67IVTLJ.js +45 -0
  6. package/dist/dist-GPQ4LAY3.js +42 -0
  7. package/dist/edit-Y7XPYSMK.js +63 -0
  8. package/dist/habits-FA65W77Y.js +1153 -0
  9. package/dist/{hooks-7TQIRXXS.js → hooks-YXPQV4SP.js} +1 -1
  10. package/dist/index.js +84 -31
  11. package/dist/{list-QMUE7DPK.js → list-R3QWW4SC.js} +3 -1
  12. package/dist/{lore-server-3TAIUZ3Y.js → lore-server-RQH5REZV.js} +166 -41
  13. package/dist/mcp.js +1608 -117
  14. package/dist/{record-5CTCDFUO.js → record-OHQNWOUP.js} +7 -2
  15. package/dist/{review-QEDNQAIO.js → review-RUHX25A5.js} +1 -1
  16. package/dist/{sentinel-RSEXIRXM.js → sentinel-WB7GIK4V.js} +1 -1
  17. package/dist/{serve-WCIRW244.js → serve-H7ZBMODT.js} +1 -1
  18. package/dist/{server-NXG5N7JE.js → server-MV4HNFVF.js} +1 -1
  19. package/dist/{shift-NABNKPGL.js → shift-JDBRTHWO.js} +1 -1
  20. package/dist/{show-S653P3TO.js → show-WTOJXUTN.js} +1 -1
  21. package/dist/timeline-P7BARFLI.js +110 -0
  22. package/dist/triage-TBIWJA6R.js +671 -0
  23. package/dist/university-content/courses/para-401.json +1 -1
  24. package/dist/university-content/courses/para-501.json +486 -0
  25. package/dist/university-content/plsat/v3.0.json +233 -0
  26. package/dist/university-content/reference.json +61 -0
  27. package/lore-ui/dist/assets/index-BB3P4Cok.js +56 -0
  28. package/lore-ui/dist/assets/index-DI0Q6NmX.css +1 -0
  29. package/lore-ui/dist/index.html +2 -2
  30. package/package.json +1 -1
  31. package/lore-ui/dist/assets/index-DcT8TINz.js +0 -56
  32. package/lore-ui/dist/assets/index-DyJhpQ5w.css +0 -1
@@ -0,0 +1,1153 @@
1
+ #!/usr/bin/env node
2
+ import "./chunk-MO4EEYFW.js";
3
+
4
+ // src/commands/habits/index.ts
5
+ import * as fs2 from "fs";
6
+ import * as path3 from "path";
7
+ import { execSync } from "child_process";
8
+ import chalk from "chalk";
9
+ import * as yaml2 from "js-yaml";
10
+
11
+ // src/core/habits/loader.ts
12
+ import * as fs from "fs";
13
+ import * as path from "path";
14
+ import * as yaml from "js-yaml";
15
+
16
+ // src/core/habits/seed-habits.json
17
+ var seed_habits_default = [
18
+ {
19
+ id: "explore-before-implement",
20
+ name: "Explore Before Implementing",
21
+ description: "Call ripple/navigate/search before modifying existing symbols to understand impact",
22
+ category: "discovery",
23
+ trigger: "preflight",
24
+ severity: "advisory",
25
+ check: {
26
+ type: "tool-called",
27
+ params: {
28
+ tools: ["paradigm_ripple", "paradigm_navigate", "paradigm_search", "paradigm_related"]
29
+ }
30
+ },
31
+ enabled: true
32
+ },
33
+ {
34
+ id: "ripple-before-modify",
35
+ name: "Ripple Before Modifying",
36
+ description: "Run ripple analysis before modifying symbols with dependents",
37
+ category: "discovery",
38
+ trigger: "preflight",
39
+ severity: "advisory",
40
+ check: {
41
+ type: "tool-called",
42
+ params: {
43
+ tools: ["paradigm_ripple"]
44
+ }
45
+ },
46
+ enabled: true
47
+ },
48
+ {
49
+ id: "check-fragility",
50
+ name: "Check Fragility",
51
+ description: "Check history fragility for symbols before modifying frequently-broken code",
52
+ category: "discovery",
53
+ trigger: "preflight",
54
+ severity: "advisory",
55
+ check: {
56
+ type: "tool-called",
57
+ params: {
58
+ tools: ["paradigm_history_fragility"]
59
+ }
60
+ },
61
+ enabled: true
62
+ },
63
+ {
64
+ id: "wisdom-before-implement",
65
+ name: "Check Team Wisdom",
66
+ description: "Check team wisdom (preferences, antipatterns, decisions) before implementing",
67
+ category: "collaboration",
68
+ trigger: "preflight",
69
+ severity: "advisory",
70
+ check: {
71
+ type: "tool-called",
72
+ params: {
73
+ tools: ["paradigm_wisdom_context", "paradigm_wisdom_expert"]
74
+ }
75
+ },
76
+ enabled: true
77
+ },
78
+ {
79
+ id: "verify-before-done",
80
+ name: "Verify Before Done",
81
+ description: "Run postflight compliance checks before finishing a session",
82
+ category: "verification",
83
+ trigger: "on-stop",
84
+ severity: "warn",
85
+ check: {
86
+ type: "tool-called",
87
+ params: {
88
+ tools: ["paradigm_pm_postflight"]
89
+ }
90
+ },
91
+ enabled: true
92
+ },
93
+ {
94
+ id: "postflight-compliance",
95
+ name: "Postflight Compliance",
96
+ description: "Ensure postflight checks pass without errors before finishing",
97
+ category: "verification",
98
+ trigger: "on-stop",
99
+ severity: "advisory",
100
+ check: {
101
+ type: "tool-called",
102
+ params: {
103
+ tools: ["paradigm_pm_postflight", "paradigm_reindex"]
104
+ }
105
+ },
106
+ enabled: true
107
+ },
108
+ {
109
+ id: "test-new-components",
110
+ name: "Test New Components",
111
+ description: "New components should have associated tests or test plan documented",
112
+ category: "testing",
113
+ trigger: "postflight",
114
+ severity: "advisory",
115
+ check: {
116
+ type: "tests-exist",
117
+ params: {
118
+ patterns: ["**/*.test.*", "**/*.spec.*", "**/tests/**"]
119
+ }
120
+ },
121
+ enabled: true
122
+ },
123
+ {
124
+ id: "purpose-coverage",
125
+ name: "Purpose File Coverage",
126
+ description: "All modified source directories should have .purpose file coverage",
127
+ category: "documentation",
128
+ trigger: "postflight",
129
+ severity: "warn",
130
+ check: {
131
+ type: "file-exists",
132
+ params: {
133
+ patterns: ["**/.purpose"]
134
+ }
135
+ },
136
+ enabled: true
137
+ },
138
+ {
139
+ id: "record-lore-for-significant",
140
+ name: "Record Lore for Significant Changes",
141
+ description: "Sessions modifying 3+ files should record a lore entry",
142
+ category: "documentation",
143
+ trigger: "on-stop",
144
+ severity: "warn",
145
+ check: {
146
+ type: "lore-recorded",
147
+ params: {}
148
+ },
149
+ enabled: true
150
+ },
151
+ {
152
+ id: "gates-for-routes",
153
+ name: "Gates for Routes",
154
+ description: "API routes should have corresponding gate declarations in portal.yaml",
155
+ category: "security",
156
+ trigger: "postflight",
157
+ severity: "warn",
158
+ check: {
159
+ type: "gates-declared",
160
+ params: {
161
+ requireRoutes: true
162
+ }
163
+ },
164
+ enabled: true
165
+ }
166
+ ];
167
+
168
+ // src/core/habits/loader.ts
169
+ var SEED_HABITS = seed_habits_default;
170
+ var HABITS_CACHE_TTL_MS = 30 * 1e3;
171
+ var habitsCache = /* @__PURE__ */ new Map();
172
+ function loadHabits(rootDir) {
173
+ const absoluteRoot = path.resolve(rootDir);
174
+ const cached = habitsCache.get(absoluteRoot);
175
+ if (cached && Date.now() - cached.loadedAt < HABITS_CACHE_TTL_MS) {
176
+ return cached.habits;
177
+ }
178
+ const habits = loadHabitsFresh(absoluteRoot);
179
+ habitsCache.set(absoluteRoot, {
180
+ habits,
181
+ loadedAt: Date.now()
182
+ });
183
+ return habits;
184
+ }
185
+ function loadHabitsFresh(rootDir) {
186
+ const habitsById = /* @__PURE__ */ new Map();
187
+ for (const seed of SEED_HABITS) {
188
+ habitsById.set(seed.id, { ...seed });
189
+ }
190
+ const globalHabitsPath = path.join(
191
+ process.env.HOME || process.env.USERPROFILE || "~",
192
+ ".paradigm",
193
+ "habits.yaml"
194
+ );
195
+ const globalConfig = loadHabitsYaml(globalHabitsPath);
196
+ if (globalConfig) {
197
+ mergeHabits(habitsById, globalConfig);
198
+ }
199
+ const projectHabitsPath = path.join(rootDir, ".paradigm", "habits.yaml");
200
+ const projectConfig = loadHabitsYaml(projectHabitsPath);
201
+ if (projectConfig) {
202
+ mergeHabits(habitsById, projectConfig);
203
+ }
204
+ return Array.from(habitsById.values());
205
+ }
206
+ function loadHabitsYaml(filePath) {
207
+ if (!fs.existsSync(filePath)) {
208
+ return null;
209
+ }
210
+ try {
211
+ const content = fs.readFileSync(filePath, "utf8");
212
+ return yaml.load(content);
213
+ } catch {
214
+ return null;
215
+ }
216
+ }
217
+ function mergeHabits(habitsById, config) {
218
+ if (config.habits) {
219
+ for (const habit of config.habits) {
220
+ habitsById.set(habit.id, { ...habit });
221
+ }
222
+ }
223
+ if (config.overrides) {
224
+ for (const [habitId, override] of Object.entries(config.overrides)) {
225
+ const existing = habitsById.get(habitId);
226
+ if (existing) {
227
+ applyOverride(existing, override);
228
+ }
229
+ }
230
+ }
231
+ }
232
+ function applyOverride(habit, override) {
233
+ if (override.severity !== void 0) {
234
+ habit.severity = override.severity;
235
+ }
236
+ if (override.enabled !== void 0) {
237
+ habit.enabled = override.enabled;
238
+ }
239
+ }
240
+ function getHabitsByTrigger(habits, trigger) {
241
+ return habits.filter((h) => h.enabled && h.trigger === trigger);
242
+ }
243
+ function getEnabledHabits(habits) {
244
+ return habits.filter((h) => h.enabled);
245
+ }
246
+ function invalidateHabitsCache(rootDir) {
247
+ const absoluteRoot = path.resolve(rootDir);
248
+ habitsCache.delete(absoluteRoot);
249
+ }
250
+
251
+ // src/core/habits/evaluator.ts
252
+ import * as path2 from "path";
253
+ function evaluateHabits(habits, trigger, context) {
254
+ const activeHabits = getHabitsByTrigger(habits, trigger);
255
+ const evaluations = [];
256
+ for (const habit of activeHabits) {
257
+ const evaluation = evaluateHabit(habit, context);
258
+ evaluations.push(evaluation);
259
+ }
260
+ const followed = evaluations.filter((e) => e.result === "followed").length;
261
+ const skipped = evaluations.filter((e) => e.result === "skipped").length;
262
+ const partial = evaluations.filter((e) => e.result === "partial").length;
263
+ const blockingViolations = evaluations.filter(
264
+ (e) => e.result === "skipped" && e.habit.severity === "block"
265
+ ).length;
266
+ return {
267
+ trigger,
268
+ evaluations,
269
+ summary: {
270
+ total: evaluations.length,
271
+ followed,
272
+ skipped,
273
+ partial,
274
+ blockingViolations
275
+ },
276
+ blocksCompletion: blockingViolations > 0
277
+ };
278
+ }
279
+ function evaluateHabit(habit, context) {
280
+ switch (habit.check.type) {
281
+ case "tool-called":
282
+ return evaluateToolCalled(habit, context);
283
+ case "file-exists":
284
+ return evaluateFileExists(habit, context);
285
+ case "lore-recorded":
286
+ return evaluateLoreRecorded(habit, context);
287
+ case "symbols-registered":
288
+ return evaluateSymbolsRegistered(habit, context);
289
+ case "gates-declared":
290
+ return evaluateGatesDeclared(habit, context);
291
+ case "tests-exist":
292
+ return evaluateTestsExist(habit, context);
293
+ case "file-modified":
294
+ return evaluateFileModified(habit, context);
295
+ case "git-clean":
296
+ return evaluateGitClean(habit, context);
297
+ default:
298
+ return {
299
+ habit,
300
+ result: "partial",
301
+ reason: `Unknown check type: ${habit.check.type}`
302
+ };
303
+ }
304
+ }
305
+ function evaluateToolCalled(habit, context) {
306
+ const requiredTools = habit.check.params.tools || [];
307
+ if (requiredTools.length === 0) {
308
+ return { habit, result: "followed", reason: "No tools required" };
309
+ }
310
+ const calledTools = requiredTools.filter(
311
+ (tool) => context.toolsCalled.includes(tool)
312
+ );
313
+ if (calledTools.length > 0) {
314
+ return {
315
+ habit,
316
+ result: "followed",
317
+ reason: `Called: ${calledTools.join(", ")}`,
318
+ evidence: calledTools
319
+ };
320
+ }
321
+ if (context.filesModified.length === 0 && context.symbolsTouched.length === 0) {
322
+ return {
323
+ habit,
324
+ result: "followed",
325
+ reason: "No modifications made, habit not applicable"
326
+ };
327
+ }
328
+ return {
329
+ habit,
330
+ result: "skipped",
331
+ reason: `None of [${requiredTools.join(", ")}] were called before modifying code`
332
+ };
333
+ }
334
+ function evaluateFileExists(habit, context) {
335
+ if (context.filesModified.length === 0) {
336
+ return {
337
+ habit,
338
+ result: "followed",
339
+ reason: "No files modified, check not applicable"
340
+ };
341
+ }
342
+ const hasPurposeUpdates = context.filesModified.some(
343
+ (f) => f.endsWith(".purpose") || f.includes(".paradigm/")
344
+ );
345
+ if (hasPurposeUpdates) {
346
+ return {
347
+ habit,
348
+ result: "followed",
349
+ reason: "Purpose files were updated alongside source changes"
350
+ };
351
+ }
352
+ const sourceFiles = context.filesModified.filter(
353
+ (f) => !f.endsWith(".md") && !f.endsWith(".json") && !f.endsWith(".yaml") && !f.endsWith(".yml") && !f.endsWith(".lock") && !f.endsWith(".purpose") && !f.includes(".paradigm/")
354
+ );
355
+ if (sourceFiles.length === 0) {
356
+ return {
357
+ habit,
358
+ result: "followed",
359
+ reason: "Only non-source files modified"
360
+ };
361
+ }
362
+ return {
363
+ habit,
364
+ result: "skipped",
365
+ reason: `${sourceFiles.length} source file(s) modified without .purpose updates`,
366
+ evidence: sourceFiles.slice(0, 5)
367
+ };
368
+ }
369
+ function evaluateLoreRecorded(habit, context) {
370
+ const sourceFiles = context.filesModified.filter(
371
+ (f) => !f.endsWith(".md") && !f.endsWith(".json") && !f.endsWith(".yaml") && !f.endsWith(".yml") && !f.endsWith(".lock") && !f.endsWith(".purpose") && !f.includes(".paradigm/")
372
+ );
373
+ if (sourceFiles.length < 3) {
374
+ return {
375
+ habit,
376
+ result: "followed",
377
+ reason: "Session not significant enough to require lore (< 3 source files)"
378
+ };
379
+ }
380
+ if (context.loreRecorded) {
381
+ return {
382
+ habit,
383
+ result: "followed",
384
+ reason: "Lore entry was recorded for this session"
385
+ };
386
+ }
387
+ if (context.toolsCalled.includes("paradigm_lore_record")) {
388
+ return {
389
+ habit,
390
+ result: "followed",
391
+ reason: "paradigm_lore_record was called during session"
392
+ };
393
+ }
394
+ return {
395
+ habit,
396
+ result: "skipped",
397
+ reason: `${sourceFiles.length} source files modified but no lore entry recorded`,
398
+ evidence: sourceFiles.slice(0, 5)
399
+ };
400
+ }
401
+ function evaluateSymbolsRegistered(habit, context) {
402
+ if (context.symbolsTouched.length === 0) {
403
+ return {
404
+ habit,
405
+ result: "followed",
406
+ reason: "No symbols touched"
407
+ };
408
+ }
409
+ const purposeTools = [
410
+ "paradigm_purpose_add_component",
411
+ "paradigm_purpose_add_signal",
412
+ "paradigm_purpose_add_flow",
413
+ "paradigm_purpose_add_gate",
414
+ "paradigm_purpose_add_aspect",
415
+ "paradigm_purpose_add_state",
416
+ "paradigm_purpose_init"
417
+ ];
418
+ const calledPurposeTools = purposeTools.filter(
419
+ (t) => context.toolsCalled.includes(t)
420
+ );
421
+ if (calledPurposeTools.length > 0) {
422
+ return {
423
+ habit,
424
+ result: "followed",
425
+ reason: `Purpose tools called: ${calledPurposeTools.join(", ")}`,
426
+ evidence: calledPurposeTools
427
+ };
428
+ }
429
+ return {
430
+ habit,
431
+ result: "partial",
432
+ reason: `${context.symbolsTouched.length} symbol(s) touched but no purpose registration tools called`
433
+ };
434
+ }
435
+ function evaluateGatesDeclared(habit, context) {
436
+ if (!context.taskAddsRoutes) {
437
+ return {
438
+ habit,
439
+ result: "followed",
440
+ reason: "Task does not add routes"
441
+ };
442
+ }
443
+ if (context.hasPortalRoutes) {
444
+ return {
445
+ habit,
446
+ result: "followed",
447
+ reason: "Portal.yaml has route declarations"
448
+ };
449
+ }
450
+ const gateTools = [
451
+ "paradigm_gates_for_route",
452
+ "paradigm_portal_add_route",
453
+ "paradigm_portal_add_gate"
454
+ ];
455
+ const calledGateTools = gateTools.filter(
456
+ (t) => context.toolsCalled.includes(t)
457
+ );
458
+ if (calledGateTools.length > 0) {
459
+ return {
460
+ habit,
461
+ result: "followed",
462
+ reason: `Gate tools called: ${calledGateTools.join(", ")}`,
463
+ evidence: calledGateTools
464
+ };
465
+ }
466
+ return {
467
+ habit,
468
+ result: "skipped",
469
+ reason: "Task adds routes but no gate declarations or portal tools called"
470
+ };
471
+ }
472
+ function evaluateTestsExist(habit, context) {
473
+ if (context.filesModified.length === 0) {
474
+ return {
475
+ habit,
476
+ result: "followed",
477
+ reason: "No files modified"
478
+ };
479
+ }
480
+ const testFiles = context.filesModified.filter(
481
+ (f) => f.includes(".test.") || f.includes(".spec.") || f.includes("/tests/") || f.includes("/test/") || f.includes("__tests__")
482
+ );
483
+ if (testFiles.length > 0) {
484
+ return {
485
+ habit,
486
+ result: "followed",
487
+ reason: `Test files modified: ${testFiles.length}`,
488
+ evidence: testFiles.slice(0, 5)
489
+ };
490
+ }
491
+ const newSourceFiles = context.filesModified.filter(
492
+ (f) => !f.endsWith(".md") && !f.endsWith(".json") && !f.endsWith(".yaml") && !f.endsWith(".lock") && !f.endsWith(".purpose") && !f.includes(".paradigm/") && !f.includes("node_modules/")
493
+ );
494
+ if (newSourceFiles.length === 0) {
495
+ return {
496
+ habit,
497
+ result: "followed",
498
+ reason: "No new source files to test"
499
+ };
500
+ }
501
+ return {
502
+ habit,
503
+ result: "partial",
504
+ reason: `${newSourceFiles.length} source file(s) modified but no test files updated`,
505
+ evidence: newSourceFiles.slice(0, 5)
506
+ };
507
+ }
508
+ function evaluateFileModified(habit, context) {
509
+ if (context.filesModified.length === 0) {
510
+ return { habit, result: "followed", reason: "No files modified" };
511
+ }
512
+ const patterns = habit.check.params.patterns || [];
513
+ if (patterns.length === 0) {
514
+ return { habit, result: "followed", reason: "No patterns specified" };
515
+ }
516
+ const matched = context.filesModified.filter(
517
+ (f) => patterns.some((p) => f.includes(p) || path2.basename(f) === p)
518
+ );
519
+ if (matched.length > 0) {
520
+ return {
521
+ habit,
522
+ result: "followed",
523
+ reason: `Matching files: ${matched.join(", ")}`,
524
+ evidence: matched
525
+ };
526
+ }
527
+ return {
528
+ habit,
529
+ result: "skipped",
530
+ reason: `None of [${patterns.join(", ")}] found in modified files`
531
+ };
532
+ }
533
+ function evaluateGitClean(habit, context) {
534
+ if (context.filesModified.length === 0) {
535
+ return { habit, result: "followed", reason: "No files modified" };
536
+ }
537
+ if (context.gitClean === void 0) {
538
+ return { habit, result: "partial", reason: "Git status not available" };
539
+ }
540
+ if (context.gitClean) {
541
+ return {
542
+ habit,
543
+ result: "followed",
544
+ reason: "Working tree is clean \u2014 changes committed"
545
+ };
546
+ }
547
+ return {
548
+ habit,
549
+ result: "skipped",
550
+ reason: "Uncommitted changes in working tree"
551
+ };
552
+ }
553
+ function buildEvaluationContext(params) {
554
+ return {
555
+ toolsCalled: params.toolsCalled || [],
556
+ filesModified: params.filesModified || [],
557
+ symbolsTouched: params.symbolsTouched || [],
558
+ loreRecorded: params.loreRecorded || false,
559
+ hasPortalRoutes: params.hasPortalRoutes || false,
560
+ taskAddsRoutes: params.taskAddsRoutes || false,
561
+ taskDescription: params.taskDescription,
562
+ gitClean: params.gitClean
563
+ };
564
+ }
565
+
566
+ // src/commands/habits/index.ts
567
+ var HABITS_FILE = ".paradigm/habits.yaml";
568
+ var SEED_HABIT_IDS = /* @__PURE__ */ new Set([
569
+ "explore-before-implement",
570
+ "ripple-before-modify",
571
+ "check-fragility",
572
+ "wisdom-before-implement",
573
+ "verify-before-done",
574
+ "postflight-compliance",
575
+ "test-new-components",
576
+ "purpose-coverage",
577
+ "record-lore-for-significant",
578
+ "gates-for-routes"
579
+ ]);
580
+ var VALID_CATEGORIES = ["discovery", "verification", "testing", "documentation", "collaboration", "security"];
581
+ var VALID_TRIGGERS = ["preflight", "postflight", "on-stop", "on-commit"];
582
+ var VALID_SEVERITIES = ["advisory", "warn", "block"];
583
+ var VALID_CHECK_TYPES = ["tool-called", "file-exists", "file-modified", "lore-recorded", "symbols-registered", "gates-declared", "tests-exist", "git-clean"];
584
+ function resolveHabitLocation(rootDir, habitId) {
585
+ const projectPath = path3.join(rootDir, HABITS_FILE);
586
+ const projectLocation = findInConfig(projectPath, habitId);
587
+ if (projectLocation) return { source: "project", ...projectLocation };
588
+ const home = process.env.HOME || process.env.USERPROFILE || "~";
589
+ const globalPath = path3.join(home, ".paradigm", "habits.yaml");
590
+ const globalLocation = findInConfig(globalPath, habitId);
591
+ if (globalLocation) return { source: "global", ...globalLocation };
592
+ if (SEED_HABIT_IDS.has(habitId)) return { source: "seed", filePath: "", index: -1 };
593
+ return null;
594
+ }
595
+ function findInConfig(filePath, habitId) {
596
+ if (!fs2.existsSync(filePath)) return null;
597
+ try {
598
+ const content = fs2.readFileSync(filePath, "utf8");
599
+ const config = yaml2.load(content);
600
+ if (!config?.habits) return null;
601
+ const idx = config.habits.findIndex((h) => h.id === habitId);
602
+ if (idx === -1) return null;
603
+ return { filePath, index: idx };
604
+ } catch {
605
+ return null;
606
+ }
607
+ }
608
+ function loadConfigFile(filePath) {
609
+ const content = fs2.readFileSync(filePath, "utf8");
610
+ const config = yaml2.load(content);
611
+ if (!config.habits) config.habits = [];
612
+ if (!config.overrides) config.overrides = {};
613
+ return config;
614
+ }
615
+ function writeConfigFile(filePath, config) {
616
+ fs2.writeFileSync(filePath, yaml2.dump(config, { lineWidth: 80, noRefs: true }), "utf8");
617
+ }
618
+ function ensureProjectConfig(rootDir) {
619
+ const configPath = path3.join(rootDir, HABITS_FILE);
620
+ if (!fs2.existsSync(configPath)) {
621
+ const dir = path3.dirname(configPath);
622
+ if (!fs2.existsSync(dir)) fs2.mkdirSync(dir, { recursive: true });
623
+ const initial = { version: "1.0", habits: [], overrides: {} };
624
+ writeConfigFile(configPath, initial);
625
+ }
626
+ return configPath;
627
+ }
628
+ async function habitsListCommand(options) {
629
+ const rootDir = process.cwd();
630
+ let habits;
631
+ try {
632
+ habits = loadHabits(rootDir);
633
+ } catch (err) {
634
+ console.log(chalk.red("Failed to load habits:"), err.message);
635
+ return;
636
+ }
637
+ if (options.trigger) {
638
+ habits = habits.filter((h) => h.trigger === options.trigger);
639
+ }
640
+ if (options.category) {
641
+ habits = habits.filter((h) => h.category === options.category);
642
+ }
643
+ if (options.json) {
644
+ console.log(JSON.stringify(habits, null, 2));
645
+ return;
646
+ }
647
+ const enabled = habits.filter((h) => h.enabled);
648
+ const disabled = habits.filter((h) => !h.enabled);
649
+ console.log(chalk.magenta(`
650
+ Habits (${enabled.length} active, ${disabled.length} disabled)
651
+ `));
652
+ const triggers = ["preflight", "postflight", "on-stop", "on-commit"];
653
+ for (const trigger of triggers) {
654
+ const group = habits.filter((h) => h.trigger === trigger);
655
+ if (group.length === 0) continue;
656
+ console.log(chalk.cyan(` ${trigger}:`));
657
+ for (const h of group) {
658
+ const status = h.enabled ? chalk.green("ON") : chalk.gray("OFF");
659
+ const severity = h.severity === "block" ? chalk.red(h.severity) : h.severity === "warn" ? chalk.yellow(h.severity) : chalk.gray(h.severity);
660
+ console.log(` ${status} ${chalk.white(h.id)} [${severity}] - ${h.name}`);
661
+ console.log(chalk.gray(` ${h.description}`));
662
+ }
663
+ console.log();
664
+ }
665
+ const projectConfig = path3.join(rootDir, HABITS_FILE);
666
+ if (fs2.existsSync(projectConfig)) {
667
+ console.log(chalk.gray(` Config: ${HABITS_FILE}`));
668
+ } else {
669
+ console.log(chalk.gray(` Config: using seed habits only (run 'paradigm habits init' to customize)`));
670
+ }
671
+ console.log();
672
+ }
673
+ async function habitsStatusCommand(options) {
674
+ const rootDir = process.cwd();
675
+ let habits;
676
+ try {
677
+ habits = loadHabits(rootDir);
678
+ } catch (err) {
679
+ console.log(chalk.red("Failed to load habits:"), err.message);
680
+ return;
681
+ }
682
+ const enabled = getEnabledHabits(habits);
683
+ let practiceData = null;
684
+ try {
685
+ const { SentinelStorage } = await import("./dist-GPQ4LAY3.js");
686
+ const sentinelDir = path3.join(rootDir, ".paradigm", "sentinel");
687
+ if (fs2.existsSync(sentinelDir)) {
688
+ const storage = new SentinelStorage(sentinelDir);
689
+ const period = options.period || "30d";
690
+ const days = parseInt(period.replace("d", ""), 10) || 30;
691
+ const dateFrom = period === "all" ? void 0 : new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString();
692
+ const compliance = storage.getComplianceRate({ dateFrom });
693
+ const events = storage.getPracticeEvents({ dateFrom, limit: 500 });
694
+ const catStats = /* @__PURE__ */ new Map();
695
+ for (const event of events) {
696
+ const cat = event.habitCategory;
697
+ const existing = catStats.get(cat) || { followed: 0, skipped: 0, partial: 0 };
698
+ existing[event.result]++;
699
+ catStats.set(cat, existing);
700
+ }
701
+ const byCategory = Array.from(catStats.entries()).map(([category, stats]) => {
702
+ const total = stats.followed + stats.skipped + stats.partial;
703
+ const rate = total > 0 ? Math.round((stats.followed + stats.partial * 0.5) / total * 100) : 100;
704
+ return { category, rate, total };
705
+ }).sort((a, b) => a.rate - b.rate);
706
+ practiceData = {
707
+ total: compliance.total,
708
+ followed: compliance.followed,
709
+ skipped: compliance.skipped,
710
+ partial: compliance.partial,
711
+ rate: compliance.rate,
712
+ byCategory
713
+ };
714
+ }
715
+ } catch {
716
+ }
717
+ if (options.json) {
718
+ console.log(JSON.stringify({
719
+ habits: { total: habits.length, enabled: enabled.length },
720
+ practice: practiceData
721
+ }, null, 2));
722
+ return;
723
+ }
724
+ console.log(chalk.magenta("\n Habits Practice Profile\n"));
725
+ console.log(chalk.white(` Total habits: ${habits.length} (${enabled.length} active)`));
726
+ const byTrigger = /* @__PURE__ */ new Map();
727
+ for (const h of enabled) {
728
+ byTrigger.set(h.trigger, (byTrigger.get(h.trigger) || 0) + 1);
729
+ }
730
+ for (const [trigger, count] of byTrigger) {
731
+ console.log(chalk.gray(` ${trigger}: ${count} habit(s)`));
732
+ }
733
+ console.log();
734
+ if (practiceData && practiceData.total > 0) {
735
+ const rateColor = practiceData.rate >= 80 ? chalk.green : practiceData.rate >= 60 ? chalk.yellow : chalk.red;
736
+ console.log(chalk.white(` Compliance Rate: ${rateColor(`${practiceData.rate}%`)}`));
737
+ console.log(chalk.gray(` Followed: ${practiceData.followed} | Skipped: ${practiceData.skipped} | Partial: ${practiceData.partial}`));
738
+ console.log(chalk.gray(` Total events: ${practiceData.total}
739
+ `));
740
+ if (practiceData.byCategory.length > 0) {
741
+ console.log(chalk.white(" By Category:"));
742
+ for (const cat of practiceData.byCategory) {
743
+ const catColor = cat.rate >= 80 ? chalk.green : cat.rate >= 60 ? chalk.yellow : chalk.red;
744
+ const bar = "\u2588".repeat(Math.round(cat.rate / 5)) + "\u2591".repeat(20 - Math.round(cat.rate / 5));
745
+ console.log(` ${cat.category.padEnd(15)} ${catColor(bar)} ${catColor(`${cat.rate}%`)} (${cat.total})`);
746
+ }
747
+ }
748
+ } else {
749
+ console.log(chalk.gray(" No practice events recorded yet."));
750
+ console.log(chalk.gray(" Call paradigm_habits_check via MCP to start recording.\n"));
751
+ }
752
+ console.log();
753
+ }
754
+ async function habitsInitCommand(options) {
755
+ const rootDir = process.cwd();
756
+ const configPath = path3.join(rootDir, HABITS_FILE);
757
+ if (fs2.existsSync(configPath) && !options.force) {
758
+ console.log(chalk.yellow(`${HABITS_FILE} already exists. Use --force to overwrite.`));
759
+ return;
760
+ }
761
+ const dir = path3.dirname(configPath);
762
+ if (!fs2.existsSync(dir)) {
763
+ fs2.mkdirSync(dir, { recursive: true });
764
+ }
765
+ const defaultConfig = {
766
+ version: "1.0",
767
+ habits: [],
768
+ overrides: {
769
+ "verify-before-done": {
770
+ severity: "warn"
771
+ }
772
+ }
773
+ };
774
+ const content = `# Paradigm Habits Configuration
775
+ # See: paradigm habits list (for all seed habits)
776
+ #
777
+ # Seed habits are built-in and active by default.
778
+ # Use 'overrides' to tune severity or disable specific habits.
779
+ # Add custom habits in the 'habits' section.
780
+
781
+ ${yaml2.dump(defaultConfig, { lineWidth: 80, noRefs: true })}
782
+ # Example custom habit:
783
+ # habits:
784
+ # - id: my-custom-check
785
+ # name: "Custom Check"
786
+ # description: "Describe what this habit enforces"
787
+ # category: verification
788
+ # trigger: postflight
789
+ # severity: advisory
790
+ # check:
791
+ # type: tool-called
792
+ # params:
793
+ # tools: [paradigm_pm_postflight]
794
+ # enabled: true
795
+ #
796
+ # Override seed habits:
797
+ # overrides:
798
+ # verify-before-done:
799
+ # severity: block # Upgrade to blocking
800
+ # check-fragility:
801
+ # enabled: false # Disable this habit
802
+ `;
803
+ fs2.writeFileSync(configPath, content, "utf8");
804
+ invalidateHabitsCache(rootDir);
805
+ console.log(chalk.green(`Created ${HABITS_FILE}`));
806
+ console.log(chalk.gray(" 10 seed habits are active by default."));
807
+ console.log(chalk.gray(" Use overrides section to tune severity or disable habits."));
808
+ console.log(chalk.gray(" Run `paradigm habits list` to see all habits.\n"));
809
+ }
810
+ async function habitsAddCommand(options) {
811
+ const rootDir = process.cwd();
812
+ const configPath = path3.join(rootDir, HABITS_FILE);
813
+ if (!fs2.existsSync(configPath)) {
814
+ console.log(chalk.yellow(`No ${HABITS_FILE} found. Run 'paradigm habits init' first.`));
815
+ return;
816
+ }
817
+ if (!VALID_CATEGORIES.includes(options.category)) {
818
+ console.log(chalk.red(`Invalid category: ${options.category}. Valid: ${VALID_CATEGORIES.join(", ")}`));
819
+ return;
820
+ }
821
+ if (!VALID_TRIGGERS.includes(options.trigger)) {
822
+ console.log(chalk.red(`Invalid trigger: ${options.trigger}. Valid: ${VALID_TRIGGERS.join(", ")}`));
823
+ return;
824
+ }
825
+ if (options.severity && !VALID_SEVERITIES.includes(options.severity)) {
826
+ console.log(chalk.red(`Invalid severity: ${options.severity}. Valid: ${VALID_SEVERITIES.join(", ")}`));
827
+ return;
828
+ }
829
+ const checkType = options.checkType || "tool-called";
830
+ if (!VALID_CHECK_TYPES.includes(checkType)) {
831
+ console.log(chalk.red(`Invalid check-type: ${checkType}. Valid: ${VALID_CHECK_TYPES.join(", ")}`));
832
+ return;
833
+ }
834
+ let config;
835
+ try {
836
+ const content = fs2.readFileSync(configPath, "utf8");
837
+ config = yaml2.load(content);
838
+ if (!config.habits) config.habits = [];
839
+ } catch (err) {
840
+ console.log(chalk.red("Failed to parse habits.yaml:"), err.message);
841
+ return;
842
+ }
843
+ const existingIds = /* @__PURE__ */ new Set([
844
+ ...config.habits.map((h) => h.id),
845
+ ...loadHabits(rootDir).map((h) => h.id)
846
+ ]);
847
+ if (existingIds.has(options.id)) {
848
+ console.log(chalk.yellow(`Habit "${options.id}" already exists.`));
849
+ return;
850
+ }
851
+ const tools = options.tools ? options.tools.split(",").map((t) => t.trim()) : [];
852
+ const patterns = options.patterns ? options.patterns.split(",").map((p) => p.trim()) : [];
853
+ const checkParams = {};
854
+ if (checkType === "tool-called" && tools.length > 0) checkParams.tools = tools;
855
+ if ((checkType === "file-exists" || checkType === "file-modified" || checkType === "tests-exist") && patterns.length > 0) {
856
+ checkParams.patterns = patterns;
857
+ }
858
+ const newHabit = {
859
+ id: options.id,
860
+ name: options.name,
861
+ description: options.description,
862
+ category: options.category,
863
+ trigger: options.trigger,
864
+ severity: options.severity || "advisory",
865
+ check: {
866
+ type: checkType,
867
+ params: checkParams
868
+ },
869
+ enabled: true
870
+ };
871
+ config.habits.push(newHabit);
872
+ writeConfigFile(configPath, config);
873
+ invalidateHabitsCache(rootDir);
874
+ console.log(chalk.green(`Added habit: ${options.id}`));
875
+ console.log(chalk.gray(` Name: ${options.name}`));
876
+ console.log(chalk.gray(` Category: ${options.category} | Trigger: ${options.trigger} | Severity: ${options.severity || "advisory"}`));
877
+ console.log(chalk.gray(` Check: ${checkType}`));
878
+ if (tools.length > 0) console.log(chalk.gray(` Tools: ${tools.join(", ")}`));
879
+ if (patterns.length > 0) console.log(chalk.gray(` Patterns: ${patterns.join(", ")}`));
880
+ console.log();
881
+ }
882
+ async function habitsEditCommand(id, options) {
883
+ const rootDir = process.cwd();
884
+ if (options.category && !VALID_CATEGORIES.includes(options.category)) {
885
+ console.log(chalk.red(`Invalid category: ${options.category}. Valid: ${VALID_CATEGORIES.join(", ")}`));
886
+ return;
887
+ }
888
+ if (options.trigger && !VALID_TRIGGERS.includes(options.trigger)) {
889
+ console.log(chalk.red(`Invalid trigger: ${options.trigger}. Valid: ${VALID_TRIGGERS.join(", ")}`));
890
+ return;
891
+ }
892
+ if (options.severity && !VALID_SEVERITIES.includes(options.severity)) {
893
+ console.log(chalk.red(`Invalid severity: ${options.severity}. Valid: ${VALID_SEVERITIES.join(", ")}`));
894
+ return;
895
+ }
896
+ if (options.checkType && !VALID_CHECK_TYPES.includes(options.checkType)) {
897
+ console.log(chalk.red(`Invalid check-type: ${options.checkType}. Valid: ${VALID_CHECK_TYPES.join(", ")}`));
898
+ return;
899
+ }
900
+ const location = resolveHabitLocation(rootDir, id);
901
+ if (!location) {
902
+ console.log(chalk.red(`Habit not found: ${id}`));
903
+ return;
904
+ }
905
+ if (location.source === "seed") {
906
+ const nonOverrideFields = ["name", "description", "category", "trigger", "checkType", "patterns", "tools"];
907
+ const hasNonOverride = nonOverrideFields.some((f) => options[f] !== void 0);
908
+ if (hasNonOverride) {
909
+ console.log(chalk.yellow(`"${id}" is a seed habit. Only --severity and --enabled can be changed.`));
910
+ console.log(chalk.gray(" Other fields require creating a custom habit with the same functionality."));
911
+ return;
912
+ }
913
+ if (!options.severity && options.enabled === void 0) {
914
+ console.log(chalk.yellow("No changes specified. Use --severity or --enabled for seed habits."));
915
+ return;
916
+ }
917
+ const configPath = ensureProjectConfig(rootDir);
918
+ const config2 = loadConfigFile(configPath);
919
+ if (!config2.overrides) config2.overrides = {};
920
+ if (!config2.overrides[id]) config2.overrides[id] = {};
921
+ if (options.severity) config2.overrides[id].severity = options.severity;
922
+ if (options.enabled !== void 0) config2.overrides[id].enabled = options.enabled === "true";
923
+ writeConfigFile(configPath, config2);
924
+ invalidateHabitsCache(rootDir);
925
+ console.log(chalk.green(`Updated seed habit override: ${id}`));
926
+ if (options.severity) console.log(chalk.gray(` Severity: ${options.severity}`));
927
+ if (options.enabled !== void 0) console.log(chalk.gray(` Enabled: ${options.enabled}`));
928
+ console.log();
929
+ return;
930
+ }
931
+ const config = loadConfigFile(location.filePath);
932
+ const habit = config.habits[location.index];
933
+ if (options.name) habit.name = options.name;
934
+ if (options.description) habit.description = options.description;
935
+ if (options.category) habit.category = options.category;
936
+ if (options.trigger) habit.trigger = options.trigger;
937
+ if (options.severity) habit.severity = options.severity;
938
+ if (options.enabled !== void 0) habit.enabled = options.enabled === "true";
939
+ if (options.checkType) habit.check.type = options.checkType;
940
+ if (options.tools) habit.check.params.tools = options.tools.split(",").map((t) => t.trim());
941
+ if (options.patterns) habit.check.params.patterns = options.patterns.split(",").map((p) => p.trim());
942
+ config.habits[location.index] = habit;
943
+ writeConfigFile(location.filePath, config);
944
+ invalidateHabitsCache(rootDir);
945
+ const source = location.source === "global" ? "(global)" : "(project)";
946
+ console.log(chalk.green(`Updated habit: ${id} ${chalk.gray(source)}`));
947
+ console.log();
948
+ }
949
+ async function habitsRemoveCommand(id, options) {
950
+ const rootDir = process.cwd();
951
+ const location = resolveHabitLocation(rootDir, id);
952
+ if (!location) {
953
+ console.log(chalk.red(`Habit not found: ${id}`));
954
+ return;
955
+ }
956
+ if (location.source === "seed") {
957
+ console.log(chalk.yellow(`"${id}" is a seed habit and cannot be removed.`));
958
+ console.log(chalk.gray(` Use: paradigm habits edit ${id} --enabled false`));
959
+ return;
960
+ }
961
+ const config = loadConfigFile(location.filePath);
962
+ const habit = config.habits[location.index];
963
+ if (!options.yes) {
964
+ console.log(chalk.yellow(`
965
+ Will remove habit: ${habit.name} (${id})`));
966
+ console.log(chalk.gray(` Source: ${location.source} (${location.filePath})`));
967
+ console.log(chalk.gray(` Use --yes to confirm.
968
+ `));
969
+ return;
970
+ }
971
+ config.habits.splice(location.index, 1);
972
+ writeConfigFile(location.filePath, config);
973
+ invalidateHabitsCache(rootDir);
974
+ console.log(chalk.green(`Removed habit: ${id}`));
975
+ console.log();
976
+ }
977
+ async function habitsToggleCommand(id, action) {
978
+ const rootDir = process.cwd();
979
+ const enabled = action === "enable";
980
+ const location = resolveHabitLocation(rootDir, id);
981
+ if (!location) {
982
+ console.log(chalk.red(`Habit not found: ${id}`));
983
+ return;
984
+ }
985
+ if (location.source === "seed") {
986
+ const configPath = ensureProjectConfig(rootDir);
987
+ const config2 = loadConfigFile(configPath);
988
+ if (!config2.overrides) config2.overrides = {};
989
+ if (!config2.overrides[id]) config2.overrides[id] = {};
990
+ config2.overrides[id].enabled = enabled;
991
+ writeConfigFile(configPath, config2);
992
+ invalidateHabitsCache(rootDir);
993
+ console.log(chalk.green(`${enabled ? "Enabled" : "Disabled"} seed habit: ${id}`));
994
+ console.log();
995
+ return;
996
+ }
997
+ const config = loadConfigFile(location.filePath);
998
+ config.habits[location.index].enabled = enabled;
999
+ writeConfigFile(location.filePath, config);
1000
+ invalidateHabitsCache(rootDir);
1001
+ console.log(chalk.green(`${enabled ? "Enabled" : "Disabled"} habit: ${id}`));
1002
+ console.log();
1003
+ }
1004
+ async function habitsCheckCommand(options) {
1005
+ const rootDir = process.cwd();
1006
+ const trigger = options.trigger;
1007
+ let habits;
1008
+ try {
1009
+ habits = loadHabits(rootDir);
1010
+ } catch (err) {
1011
+ console.log(chalk.red("Failed to load habits:"), err.message);
1012
+ process.exitCode = 1;
1013
+ return;
1014
+ }
1015
+ const filesModified = options.files ? options.files.split(",").map((f) => f.trim()).filter(Boolean) : getGitModifiedFiles(rootDir);
1016
+ const symbolsTouched = options.symbols ? options.symbols.split(",").map((s) => s.trim()).filter(Boolean) : [];
1017
+ let gitClean;
1018
+ try {
1019
+ const status = execSync("git status --porcelain", {
1020
+ cwd: rootDir,
1021
+ encoding: "utf8",
1022
+ timeout: 5e3
1023
+ });
1024
+ gitClean = status.trim() === "";
1025
+ } catch {
1026
+ }
1027
+ const portalPath = path3.join(rootDir, "portal.yaml");
1028
+ let hasPortalRoutes = false;
1029
+ if (fs2.existsSync(portalPath)) {
1030
+ try {
1031
+ const portalContent = fs2.readFileSync(portalPath, "utf8");
1032
+ const portal = yaml2.load(portalContent);
1033
+ hasPortalRoutes = portal?.routes != null && Object.keys(portal.routes).length > 0;
1034
+ } catch {
1035
+ }
1036
+ }
1037
+ const evalContext = buildEvaluationContext({
1038
+ toolsCalled: [],
1039
+ // CLI has no session breadcrumbs
1040
+ filesModified,
1041
+ symbolsTouched,
1042
+ loreRecorded: false,
1043
+ hasPortalRoutes,
1044
+ taskAddsRoutes: false,
1045
+ gitClean
1046
+ });
1047
+ const evaluation = evaluateHabits(habits, trigger, evalContext);
1048
+ let recordedCount = 0;
1049
+ if (options.record && evaluation.evaluations.length > 0) {
1050
+ try {
1051
+ const sentinelDir = path3.join(rootDir, ".paradigm", "sentinel");
1052
+ if (fs2.existsSync(sentinelDir)) {
1053
+ const { SentinelStorage } = await import("./dist-GPQ4LAY3.js");
1054
+ const storage = new SentinelStorage(sentinelDir);
1055
+ for (const e of evaluation.evaluations) {
1056
+ storage.recordPracticeEvent({
1057
+ habitId: e.habit.id,
1058
+ habitCategory: e.habit.category,
1059
+ result: e.result,
1060
+ engineer: "agent",
1061
+ sessionId: `cli-${Date.now().toString(36)}`,
1062
+ symbolsTouched,
1063
+ filesModified,
1064
+ notes: e.reason
1065
+ });
1066
+ recordedCount++;
1067
+ }
1068
+ }
1069
+ } catch {
1070
+ }
1071
+ }
1072
+ const markerPath = path3.join(rootDir, ".paradigm", ".habits-blocking");
1073
+ try {
1074
+ if (trigger === "on-stop" && evaluation.blocksCompletion) {
1075
+ const blocking = evaluation.evaluations.filter((e) => e.result === "skipped" && e.habit.severity === "block").map((e) => `${e.habit.name}: ${e.reason}`);
1076
+ fs2.writeFileSync(markerPath, blocking.join("\n"), "utf8");
1077
+ } else if (trigger === "on-stop") {
1078
+ if (fs2.existsSync(markerPath)) fs2.unlinkSync(markerPath);
1079
+ }
1080
+ } catch {
1081
+ }
1082
+ if (options.json) {
1083
+ console.log(JSON.stringify({
1084
+ trigger,
1085
+ evaluation: {
1086
+ total: evaluation.summary.total,
1087
+ followed: evaluation.summary.followed,
1088
+ skipped: evaluation.summary.skipped,
1089
+ partial: evaluation.summary.partial,
1090
+ blockingViolations: evaluation.summary.blockingViolations,
1091
+ blocksCompletion: evaluation.blocksCompletion
1092
+ },
1093
+ habits: evaluation.evaluations.map((e) => ({
1094
+ id: e.habit.id,
1095
+ name: e.habit.name,
1096
+ category: e.habit.category,
1097
+ severity: e.habit.severity,
1098
+ result: e.result,
1099
+ reason: e.reason,
1100
+ evidence: e.evidence
1101
+ })),
1102
+ recorded: recordedCount
1103
+ }, null, 2));
1104
+ } else {
1105
+ printHumanReadableResults(evaluation, recordedCount);
1106
+ }
1107
+ if (evaluation.blocksCompletion) {
1108
+ process.exitCode = 1;
1109
+ }
1110
+ }
1111
+ function getGitModifiedFiles(rootDir) {
1112
+ try {
1113
+ const output = execSync("git diff --name-only HEAD", {
1114
+ cwd: rootDir,
1115
+ encoding: "utf8",
1116
+ timeout: 5e3
1117
+ });
1118
+ return output.trim().split("\n").filter(Boolean);
1119
+ } catch {
1120
+ return [];
1121
+ }
1122
+ }
1123
+ function printHumanReadableResults(evaluation, recordedCount) {
1124
+ const { summary } = evaluation;
1125
+ console.log(chalk.magenta(`
1126
+ Habits Check (${evaluation.trigger})
1127
+ `));
1128
+ for (const e of evaluation.evaluations) {
1129
+ const icon = e.result === "followed" ? chalk.green("PASS") : e.result === "skipped" ? e.habit.severity === "block" ? chalk.red("BLOCK") : chalk.yellow("SKIP") : chalk.gray("PART");
1130
+ const severity = e.habit.severity === "block" ? chalk.red(e.habit.severity) : e.habit.severity === "warn" ? chalk.yellow(e.habit.severity) : chalk.gray(e.habit.severity);
1131
+ console.log(` ${icon} ${chalk.white(e.habit.id)} [${severity}]`);
1132
+ console.log(chalk.gray(` ${e.reason}`));
1133
+ }
1134
+ console.log();
1135
+ console.log(chalk.white(` Summary: ${summary.followed} followed, ${summary.skipped} skipped, ${summary.partial} partial`));
1136
+ if (summary.blockingViolations > 0) {
1137
+ console.log(chalk.red(` ${summary.blockingViolations} blocking violation(s) \u2014 exit code 1`));
1138
+ }
1139
+ if (recordedCount > 0) {
1140
+ console.log(chalk.gray(` Recorded ${recordedCount} practice event(s) to Sentinel`));
1141
+ }
1142
+ console.log();
1143
+ }
1144
+ export {
1145
+ habitsAddCommand,
1146
+ habitsCheckCommand,
1147
+ habitsEditCommand,
1148
+ habitsInitCommand,
1149
+ habitsListCommand,
1150
+ habitsRemoveCommand,
1151
+ habitsStatusCommand,
1152
+ habitsToggleCommand
1153
+ };