@triedotdev/mcp 1.0.138 → 1.0.140

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 (74) hide show
  1. package/README.md +184 -38
  2. package/dist/{autonomy-config-TZ6HF4FA.js → autonomy-config-ZCOSTMPD.js} +2 -2
  3. package/dist/{chunk-X3F5QDER.js → chunk-4O2KRHK4.js} +934 -132
  4. package/dist/chunk-4O2KRHK4.js.map +1 -0
  5. package/dist/{chunk-J5EMP4XW.js → chunk-5KJ4UJOY.js} +9 -4
  6. package/dist/chunk-5KJ4UJOY.js.map +1 -0
  7. package/dist/chunk-62POBLFC.js +1925 -0
  8. package/dist/chunk-62POBLFC.js.map +1 -0
  9. package/dist/{chunk-GFFUDJMK.js → chunk-75ADWWUF.js} +13 -13
  10. package/dist/chunk-75ADWWUF.js.map +1 -0
  11. package/dist/{chunk-D3AS5LY7.js → chunk-7OJ6JIPL.js} +39 -604
  12. package/dist/chunk-7OJ6JIPL.js.map +1 -0
  13. package/dist/{chunk-3RRXWX3V.js → chunk-AF2APASP.js} +38 -4
  14. package/dist/{chunk-3RRXWX3V.js.map → chunk-AF2APASP.js.map} +1 -1
  15. package/dist/{chunk-QSWUPSLK.js → chunk-FH335WL5.js} +9 -1
  16. package/dist/chunk-FH335WL5.js.map +1 -0
  17. package/dist/{chunk-Y32FM3MR.js → chunk-FPEMP54L.js} +21 -15
  18. package/dist/chunk-FPEMP54L.js.map +1 -0
  19. package/dist/{chunk-EDDT4ZIH.js → chunk-GXF6JOCN.js} +21 -323
  20. package/dist/chunk-GXF6JOCN.js.map +1 -0
  21. package/dist/chunk-LD7ZEFNY.js +132 -0
  22. package/dist/chunk-LD7ZEFNY.js.map +1 -0
  23. package/dist/chunk-NKHO34UZ.js +467 -0
  24. package/dist/chunk-NKHO34UZ.js.map +1 -0
  25. package/dist/{chunk-YOKQ25IW.js → chunk-OQ4A3RDY.js} +14 -14
  26. package/dist/{chunk-6LLH3TBZ.js → chunk-UOSTOLU7.js} +12 -12
  27. package/dist/{chunk-67GSG2ST.js → chunk-XTTZAQWJ.js} +18 -15
  28. package/dist/chunk-XTTZAQWJ.js.map +1 -0
  29. package/dist/{chunk-FOCXXIXY.js → chunk-YEIJW6X6.js} +2 -2
  30. package/dist/chunk-YOJGSRZK.js +216 -0
  31. package/dist/chunk-YOJGSRZK.js.map +1 -0
  32. package/dist/cli/main.js +573 -59
  33. package/dist/cli/main.js.map +1 -1
  34. package/dist/cli/yolo-daemon.js +15 -13
  35. package/dist/cli/yolo-daemon.js.map +1 -1
  36. package/dist/{client-JTU5TRLB.js → client-INNE2GGZ.js} +2 -2
  37. package/dist/{codebase-index-FNJ4GCBE.js → codebase-index-5SEOESWM.js} +3 -3
  38. package/dist/fast-analyzer-AYLZB5TW.js +216 -0
  39. package/dist/fast-analyzer-AYLZB5TW.js.map +1 -0
  40. package/dist/github-ingester-J2ZFYXVE.js +11 -0
  41. package/dist/{goal-manager-6BJQ36AH.js → goal-manager-ZBWKWEML.js} +3 -3
  42. package/dist/{goal-validator-GISXYANK.js → goal-validator-HNXXUCPW.js} +3 -3
  43. package/dist/{graph-X2FMRQLG.js → graph-J4OGTYCO.js} +2 -2
  44. package/dist/{hypothesis-K3KQJOXJ.js → hypothesis-JCUMZKTG.js} +3 -3
  45. package/dist/index.js +1090 -108
  46. package/dist/index.js.map +1 -1
  47. package/dist/{issue-store-BO5OWLJW.js → issue-store-LZWZIGM7.js} +2 -2
  48. package/dist/linear-ingester-JRDQAIAA.js +11 -0
  49. package/dist/linear-ingester-JRDQAIAA.js.map +1 -0
  50. package/dist/{trie-agent-XMSGMD7E.js → trie-agent-M6PHM6UD.js} +10 -10
  51. package/dist/trie-agent-M6PHM6UD.js.map +1 -0
  52. package/package.json +15 -8
  53. package/dist/chunk-67GSG2ST.js.map +0 -1
  54. package/dist/chunk-D3AS5LY7.js.map +0 -1
  55. package/dist/chunk-EDDT4ZIH.js.map +0 -1
  56. package/dist/chunk-GFFUDJMK.js.map +0 -1
  57. package/dist/chunk-J5EMP4XW.js.map +0 -1
  58. package/dist/chunk-QSWUPSLK.js.map +0 -1
  59. package/dist/chunk-X3F5QDER.js.map +0 -1
  60. package/dist/chunk-Y32FM3MR.js.map +0 -1
  61. package/dist/chunk-Z2P4WST6.js +0 -883
  62. package/dist/chunk-Z2P4WST6.js.map +0 -1
  63. /package/dist/{autonomy-config-TZ6HF4FA.js.map → autonomy-config-ZCOSTMPD.js.map} +0 -0
  64. /package/dist/{chunk-YOKQ25IW.js.map → chunk-OQ4A3RDY.js.map} +0 -0
  65. /package/dist/{chunk-6LLH3TBZ.js.map → chunk-UOSTOLU7.js.map} +0 -0
  66. /package/dist/{chunk-FOCXXIXY.js.map → chunk-YEIJW6X6.js.map} +0 -0
  67. /package/dist/{client-JTU5TRLB.js.map → client-INNE2GGZ.js.map} +0 -0
  68. /package/dist/{codebase-index-FNJ4GCBE.js.map → codebase-index-5SEOESWM.js.map} +0 -0
  69. /package/dist/{goal-manager-6BJQ36AH.js.map → github-ingester-J2ZFYXVE.js.map} +0 -0
  70. /package/dist/{goal-validator-GISXYANK.js.map → goal-manager-ZBWKWEML.js.map} +0 -0
  71. /package/dist/{graph-X2FMRQLG.js.map → goal-validator-HNXXUCPW.js.map} +0 -0
  72. /package/dist/{hypothesis-K3KQJOXJ.js.map → graph-J4OGTYCO.js.map} +0 -0
  73. /package/dist/{issue-store-BO5OWLJW.js.map → hypothesis-JCUMZKTG.js.map} +0 -0
  74. /package/dist/{trie-agent-XMSGMD7E.js.map → issue-store-LZWZIGM7.js.map} +0 -0
package/dist/cli/main.js CHANGED
@@ -1,40 +1,31 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- LinearIngester,
4
3
  completeBootstrap,
5
4
  getSkillCategories,
6
5
  initProjectInfo,
7
6
  initializeBootstrapFiles,
8
- loadConfig,
9
7
  loadContextState,
10
8
  loadProjectInfo,
11
9
  needsBootstrap,
12
- projectInfoExists,
13
- saveConfig
14
- } from "../chunk-D3AS5LY7.js";
10
+ projectInfoExists
11
+ } from "../chunk-7OJ6JIPL.js";
15
12
  import {
16
- getAutonomyConfig,
17
- recordBypass,
18
- shouldAutoFix,
19
- shouldBlockPush,
20
- trackIssueOccurrence
21
- } from "../chunk-J5EMP4XW.js";
13
+ LinearIngester
14
+ } from "../chunk-LD7ZEFNY.js";
22
15
  import {
23
16
  LearningEngine,
24
17
  exportToJson,
25
- formatAuditLog,
26
18
  formatFriendlyError,
27
- getAuditStatistics,
28
- getRecentAuditLogs,
29
- getSkillAuditLogs,
30
- getStagedChanges,
31
- getUncommittedChanges,
32
19
  handleCheckpointCommand,
33
20
  importFromJson,
34
21
  isTrieInitialized,
35
22
  perceiveCurrentChanges,
36
23
  reasonAboutChangesHumanReadable
37
- } from "../chunk-EDDT4ZIH.js";
24
+ } from "../chunk-GXF6JOCN.js";
25
+ import {
26
+ loadConfig,
27
+ saveConfig
28
+ } from "../chunk-NKHO34UZ.js";
38
29
  import {
39
30
  IncidentIndex
40
31
  } from "../chunk-4C67GV3O.js";
@@ -46,33 +37,60 @@ import {
46
37
  listTrackedProjects,
47
38
  searchGlobalPatterns,
48
39
  updateGlobalMemoryMd
49
- } from "../chunk-6LLH3TBZ.js";
40
+ } from "../chunk-UOSTOLU7.js";
41
+ import {
42
+ ContextGraph
43
+ } from "../chunk-FH335WL5.js";
50
44
  import {
51
45
  measureInitialGoalValue
52
- } from "../chunk-GFFUDJMK.js";
53
- import "../chunk-Y32FM3MR.js";
46
+ } from "../chunk-75ADWWUF.js";
47
+ import "../chunk-FPEMP54L.js";
54
48
  import {
55
49
  getProjectState
56
50
  } from "../chunk-LT6VUZG2.js";
57
- import "../chunk-F4NJ4CBP.js";
58
- import "../chunk-IXO4G4D3.js";
59
- import "../chunk-6NLHFIYA.js";
60
- import {
61
- getStorage
62
- } from "../chunk-FG467PDD.js";
63
- import {
64
- ContextGraph
65
- } from "../chunk-QSWUPSLK.js";
66
51
  import {
52
+ compressOldBlocks,
53
+ deleteAllBlocks,
54
+ deleteBlocks,
55
+ detectLegacyLedger,
56
+ formatAuditLog,
57
+ getAuditStatistics,
67
58
  getDailyLogs,
59
+ getLedgerBlocks,
60
+ getLedgerSyncStatus,
68
61
  getMemoryStats,
62
+ getRecentAuditLogs,
69
63
  getRecentIssues,
64
+ getSkillAuditLogs,
65
+ getStagedChanges,
66
+ getStorageStats,
67
+ getUncommittedChanges,
68
+ initializeSharedLedger,
69
+ isGitRepo,
70
70
  markIssueResolved,
71
+ migrateLegacyLedger,
71
72
  purgeIssues,
72
- searchIssues
73
- } from "../chunk-Z2P4WST6.js";
73
+ pushLedgerToShared,
74
+ searchIssues,
75
+ shouldCompress,
76
+ syncLedgerFromShared,
77
+ verifyLedger
78
+ } from "../chunk-62POBLFC.js";
74
79
  import "../chunk-4MJ52WBH.js";
75
80
  import "../chunk-43X6JBEM.js";
81
+ import "../chunk-F4NJ4CBP.js";
82
+ import "../chunk-IXO4G4D3.js";
83
+ import "../chunk-6NLHFIYA.js";
84
+ import {
85
+ getStorage
86
+ } from "../chunk-FG467PDD.js";
87
+ import {
88
+ getAutonomyConfig,
89
+ recordBypass,
90
+ shouldAutoFix,
91
+ shouldBlockPush,
92
+ trackIssueOccurrence
93
+ } from "../chunk-5KJ4UJOY.js";
76
94
  import {
77
95
  getTrieDirectory,
78
96
  getWorkingDirectory
@@ -83,10 +101,10 @@ import {
83
101
  } from "../chunk-DGUM43GV.js";
84
102
 
85
103
  // src/cli/main.ts
86
- import { resolve, join as join3, dirname } from "path";
104
+ import { resolve, join as join4, dirname } from "path";
87
105
  import { readFileSync, realpathSync } from "fs";
88
106
  import { fileURLToPath } from "url";
89
- import pc5 from "picocolors";
107
+ import pc8 from "picocolors";
90
108
 
91
109
  // src/hooks/install.ts
92
110
  import fs from "fs";
@@ -2095,9 +2113,9 @@ async function loadSavedPatterns(workDir) {
2095
2113
  return [];
2096
2114
  }
2097
2115
  async function savePatternsToProject(patterns, workDir) {
2098
- const { mkdir } = await import("fs/promises");
2116
+ const { mkdir: mkdir2 } = await import("fs/promises");
2099
2117
  const patternsPath = join2(getTrieDirectory(workDir), "saved-patterns.json");
2100
- await mkdir(getTrieDirectory(workDir), { recursive: true });
2118
+ await mkdir2(getTrieDirectory(workDir), { recursive: true });
2101
2119
  await writeFile2(patternsPath, JSON.stringify(patterns, null, 2));
2102
2120
  }
2103
2121
  async function savePatternToProject(pattern, workDir) {
@@ -2398,6 +2416,490 @@ ${picocolors3.dim("Patterns are saved in .trie/saved-patterns.json")}
2398
2416
  `);
2399
2417
  }
2400
2418
 
2419
+ // src/cli/sync.ts
2420
+ import pc6 from "picocolors";
2421
+ import { Command } from "commander";
2422
+
2423
+ // src/cli/hooks.ts
2424
+ import { writeFile as writeFile4, mkdir, chmod } from "fs/promises";
2425
+ import { join as join3 } from "path";
2426
+ import { existsSync as existsSync6 } from "fs";
2427
+ import pc5 from "picocolors";
2428
+ async function installGitHooks2() {
2429
+ const workDir = getWorkingDirectory(void 0, true);
2430
+ const isRepo = await isGitRepo(workDir);
2431
+ if (!isRepo) {
2432
+ console.log(pc5.yellow("\u26A0 Not a git repository. Git hooks not installed."));
2433
+ return;
2434
+ }
2435
+ const hooksDir = join3(workDir, ".git", "hooks");
2436
+ if (!existsSync6(hooksDir)) {
2437
+ await mkdir(hooksDir, { recursive: true });
2438
+ }
2439
+ const prePushHook = `#!/bin/sh
2440
+ # Auto-sync ledger to shared storage before push
2441
+
2442
+ # Only run if trie is initialized
2443
+ if [ ! -d ".trie" ]; then
2444
+ exit 0
2445
+ fi
2446
+
2447
+ # Check if trie command is available
2448
+ if ! command -v trie >/dev/null 2>&1; then
2449
+ echo "Warning: trie command not found, skipping ledger sync"
2450
+ exit 0
2451
+ fi
2452
+
2453
+ # Sync ledger to shared storage
2454
+ echo "Syncing ledger to shared storage..."
2455
+ trie sync push 2>/dev/null || true
2456
+
2457
+ exit 0
2458
+ `;
2459
+ const postMergeHook = `#!/bin/sh
2460
+ # Auto-sync ledger from shared storage after merge
2461
+
2462
+ # Only run if trie is initialized
2463
+ if [ ! -d ".trie" ]; then
2464
+ exit 0
2465
+ fi
2466
+
2467
+ # Check if trie command is available
2468
+ if ! command -v trie >/dev/null 2>&1; then
2469
+ exit 0
2470
+ fi
2471
+
2472
+ # Sync ledger from shared storage
2473
+ echo "Syncing ledger from shared storage..."
2474
+ trie sync pull 2>/dev/null || true
2475
+
2476
+ exit 0
2477
+ `;
2478
+ const prePushPath = join3(hooksDir, "pre-push");
2479
+ const postMergePath = join3(hooksDir, "post-merge");
2480
+ await writeFile4(prePushPath, prePushHook);
2481
+ await writeFile4(postMergePath, postMergeHook);
2482
+ await chmod(prePushPath, 493);
2483
+ await chmod(postMergePath, 493);
2484
+ console.log(pc5.green("\u2713 Git hooks installed successfully"));
2485
+ console.log(pc5.dim(" pre-push: Syncs ledger to shared storage"));
2486
+ console.log(pc5.dim(" post-merge: Syncs ledger from shared storage"));
2487
+ }
2488
+ async function checkGitHooks() {
2489
+ const workDir = getWorkingDirectory(void 0, true);
2490
+ const isRepo = await isGitRepo(workDir);
2491
+ if (!isRepo) {
2492
+ return {
2493
+ isGitRepo: false,
2494
+ prePushInstalled: false,
2495
+ postMergeInstalled: false
2496
+ };
2497
+ }
2498
+ const hooksDir = join3(workDir, ".git", "hooks");
2499
+ const prePushPath = join3(hooksDir, "pre-push");
2500
+ const postMergePath = join3(hooksDir, "post-merge");
2501
+ return {
2502
+ isGitRepo: true,
2503
+ prePushInstalled: existsSync6(prePushPath),
2504
+ postMergeInstalled: existsSync6(postMergePath)
2505
+ };
2506
+ }
2507
+
2508
+ // src/cli/sync.ts
2509
+ function createSyncCommand() {
2510
+ const sync = new Command("sync").description("Sync ledger with shared storage");
2511
+ sync.command("init").description("Initialize shared ledger storage").action(async () => {
2512
+ try {
2513
+ const workDir = getWorkingDirectory(void 0, true);
2514
+ console.log(`Initializing shared ledger in ${workDir}...`);
2515
+ await initializeSharedLedger();
2516
+ console.log(pc6.green("\u2713 Shared ledger initialized successfully"));
2517
+ } catch (error) {
2518
+ console.error(pc6.red("Failed to initialize shared ledger:"), error);
2519
+ process.exit(1);
2520
+ }
2521
+ });
2522
+ sync.command("pull").description("Pull updates from shared ledger").action(async () => {
2523
+ try {
2524
+ console.log("Syncing from shared ledger...");
2525
+ const hasLegacy = await detectLegacyLedger();
2526
+ if (hasLegacy) {
2527
+ console.log("Detected legacy ledger, migrating...");
2528
+ await migrateLegacyLedger();
2529
+ }
2530
+ const result = await syncLedgerFromShared();
2531
+ console.log(pc6.green("\u2713 Sync completed"));
2532
+ console.log(`Merged ${result.stats.mergedBlocks} blocks`);
2533
+ if (result.conflicts.length > 0) {
2534
+ console.log(pc6.yellow(`\u26A0 ${result.conflicts.length} conflicts detected`));
2535
+ console.log('Run "trie sync status" to see details');
2536
+ }
2537
+ if (result.stats.duplicatesRemoved > 0) {
2538
+ console.log(`Removed ${result.stats.duplicatesRemoved} duplicate entries`);
2539
+ }
2540
+ } catch (error) {
2541
+ console.error(pc6.red("Failed to sync from shared ledger:"), error);
2542
+ process.exit(1);
2543
+ }
2544
+ });
2545
+ sync.command("push").description("Push local changes to shared ledger").action(async () => {
2546
+ try {
2547
+ console.log("Pushing to shared ledger...");
2548
+ const hasLegacy = await detectLegacyLedger();
2549
+ if (hasLegacy) {
2550
+ console.log("Detected legacy ledger, migrating...");
2551
+ await migrateLegacyLedger();
2552
+ }
2553
+ await pushLedgerToShared();
2554
+ console.log(pc6.green("\u2713 Push completed"));
2555
+ } catch (error) {
2556
+ console.error(pc6.red("Failed to push to shared ledger:"), error);
2557
+ process.exit(1);
2558
+ }
2559
+ });
2560
+ sync.command("status").description("Show ledger sync status").action(async () => {
2561
+ try {
2562
+ const status = await getLedgerSyncStatus();
2563
+ console.log(pc6.bold("Ledger Sync Status\n"));
2564
+ if (!status.isInitialized) {
2565
+ console.log(pc6.yellow('\u26A0 Shared ledger not initialized. Run "trie sync init" first.'));
2566
+ return;
2567
+ }
2568
+ if (status.hasLegacyLedger) {
2569
+ console.log(pc6.yellow('\u26A0 Legacy ledger detected. Run "trie sync pull" to migrate.'));
2570
+ }
2571
+ console.log(`Local blocks: ${pc6.cyan(status.localBlocks.toString())}`);
2572
+ console.log(`Shared blocks: ${pc6.cyan(status.sharedBlocks.toString())}`);
2573
+ if (status.syncState) {
2574
+ const lastSync = new Date(status.syncState.lastSyncTimestamp);
2575
+ console.log(`Last sync: ${pc6.dim(lastSync.toLocaleString())}`);
2576
+ if (status.conflicts > 0) {
2577
+ console.log(pc6.yellow(`Conflicts: ${status.conflicts}`));
2578
+ console.log("\nConflicts:");
2579
+ for (const conflict of status.syncState.conflicts) {
2580
+ console.log(` \u2022 ${conflict.type}: ${conflict.description}`);
2581
+ }
2582
+ } else {
2583
+ console.log(pc6.green("\u2713 No conflicts"));
2584
+ }
2585
+ }
2586
+ if (status.manifest) {
2587
+ console.log(`
2588
+ Total entries: ${pc6.cyan(status.manifest.totalEntries.toString())}`);
2589
+ console.log(`Compression: ${status.manifest.compressionConfig.enabled ? pc6.green("enabled") : pc6.red("disabled")}`);
2590
+ }
2591
+ } catch (error) {
2592
+ console.error(pc6.red("Failed to get sync status:"), error);
2593
+ process.exit(1);
2594
+ }
2595
+ });
2596
+ sync.command("migrate").description("Migrate legacy ledger to new format").action(async () => {
2597
+ try {
2598
+ const hasLegacy = await detectLegacyLedger();
2599
+ if (!hasLegacy) {
2600
+ console.log(pc6.yellow("No legacy ledger found to migrate"));
2601
+ return;
2602
+ }
2603
+ console.log("Migrating legacy ledger...");
2604
+ const success = await migrateLegacyLedger();
2605
+ if (success) {
2606
+ console.log(pc6.green("\u2713 Migration completed successfully"));
2607
+ } else {
2608
+ console.log(pc6.red("Migration failed"));
2609
+ process.exit(1);
2610
+ }
2611
+ } catch (error) {
2612
+ console.error(pc6.red("Failed to migrate legacy ledger:"), error);
2613
+ process.exit(1);
2614
+ }
2615
+ });
2616
+ sync.command("hooks").description("Manage git hooks for automatic sync").option("--install", "Install git hooks").option("--status", "Check git hooks status").action(async (options) => {
2617
+ try {
2618
+ if (options.install) {
2619
+ await installGitHooks2();
2620
+ return;
2621
+ }
2622
+ const status = await checkGitHooks();
2623
+ if (!status.isGitRepo) {
2624
+ console.log(pc6.yellow("Not a git repository"));
2625
+ return;
2626
+ }
2627
+ console.log(pc6.bold("Git Hooks Status\n"));
2628
+ console.log(`Pre-push hook: ${status.prePushInstalled ? pc6.green("\u2713 installed") : pc6.red("\u2717 not installed")}`);
2629
+ console.log(`Post-merge hook: ${status.postMergeInstalled ? pc6.green("\u2713 installed") : pc6.red("\u2717 not installed")}`);
2630
+ if (!status.prePushInstalled || !status.postMergeInstalled) {
2631
+ console.log(`
2632
+ ${pc6.yellow("\u{1F4A1} Tip:")} Run ${pc6.bold("trie sync hooks --install")} to install missing hooks`);
2633
+ }
2634
+ } catch (error) {
2635
+ console.error(pc6.red("Failed to manage git hooks:"), error);
2636
+ process.exit(1);
2637
+ }
2638
+ });
2639
+ return sync;
2640
+ }
2641
+
2642
+ // src/cli/ledger.ts
2643
+ import pc7 from "picocolors";
2644
+ import { Command as Command2 } from "commander";
2645
+ function createLedgerCommand() {
2646
+ const ledger = new Command2("ledger").description("Manage and inspect the ledger");
2647
+ ledger.command("verify").description("Verify ledger chain integrity").action(async () => {
2648
+ try {
2649
+ console.log("Verifying ledger chain...");
2650
+ const result = await verifyLedger();
2651
+ if (result.valid) {
2652
+ console.log(pc7.green("\u2713 Ledger chain is valid"));
2653
+ } else {
2654
+ console.log(pc7.red(`\u2717 Ledger chain is invalid: ${result.error}`));
2655
+ process.exit(1);
2656
+ }
2657
+ } catch (error) {
2658
+ console.error(pc7.red("Failed to verify ledger:"), error);
2659
+ process.exit(1);
2660
+ }
2661
+ });
2662
+ ledger.command("history").description("Show ledger history with author attribution").option("-l, --limit <number>", "Number of blocks to show", "10").action(async (options) => {
2663
+ try {
2664
+ const limit = parseInt(options.limit, 10);
2665
+ const blocks = await getLedgerBlocks();
2666
+ if (blocks.length === 0) {
2667
+ console.log("No ledger blocks found");
2668
+ return;
2669
+ }
2670
+ console.log(pc7.bold(`Ledger History (last ${Math.min(limit, blocks.length)} blocks)
2671
+ `));
2672
+ const recentBlocks = blocks.slice(-limit).reverse();
2673
+ for (const block of recentBlocks) {
2674
+ const syncableBlock = block;
2675
+ console.log(pc7.bold(pc7.cyan(`Block ${block.date}`)));
2676
+ if (syncableBlock.author) {
2677
+ console.log(`Author: ${pc7.dim(syncableBlock.author)}`);
2678
+ }
2679
+ if (syncableBlock.gitCommit) {
2680
+ console.log(`Git: ${pc7.dim(syncableBlock.gitCommit.slice(0, 8))}`);
2681
+ }
2682
+ console.log(`Entries: ${block.entries.length}`);
2683
+ console.log(`Hash: ${pc7.dim(block.blockHash.slice(0, 16))}...`);
2684
+ if (block.entries.length > 0) {
2685
+ console.log("Issues:");
2686
+ for (const entry of block.entries) {
2687
+ console.log(` \u2022 ${entry.severity} - ${entry.file} (${entry.agent})`);
2688
+ }
2689
+ }
2690
+ console.log("");
2691
+ }
2692
+ } catch (error) {
2693
+ console.error(pc7.red("Failed to show ledger history:"), error);
2694
+ process.exit(1);
2695
+ }
2696
+ });
2697
+ ledger.command("stats").description("Show ledger statistics").action(async () => {
2698
+ try {
2699
+ const status = await getLedgerSyncStatus();
2700
+ const blocks = await getLedgerBlocks();
2701
+ console.log(pc7.bold("Ledger Statistics\n"));
2702
+ console.log(`Total blocks: ${pc7.cyan(blocks.length.toString())}`);
2703
+ if (status.manifest) {
2704
+ console.log(`Total entries: ${pc7.cyan(status.manifest.totalEntries.toString())}`);
2705
+ console.log(`Active blocks: ${pc7.cyan(status.manifest.activeBlocks.length.toString())}`);
2706
+ console.log(`Archived blocks: ${pc7.cyan(status.manifest.archivedBlocks.length.toString())}`);
2707
+ if (status.manifest.compressionConfig.enabled) {
2708
+ const hotSize = Math.round(status.manifest.compressionConfig.maxHotStorageSize / 1024 / 1024);
2709
+ console.log(`Hot storage limit: ${pc7.cyan(`${hotSize}MB`)}`);
2710
+ console.log(`Archive after: ${pc7.cyan(`${status.manifest.compressionConfig.archiveAfterDays} days`)}`);
2711
+ }
2712
+ }
2713
+ if (blocks.length > 0) {
2714
+ const firstBlock = blocks[0];
2715
+ const lastBlock = blocks[blocks.length - 1];
2716
+ console.log(`Date range: ${pc7.dim(`${firstBlock.date} to ${lastBlock.date}`)}`);
2717
+ }
2718
+ const authorCounts = /* @__PURE__ */ new Map();
2719
+ for (const block of blocks) {
2720
+ const syncableBlock = block;
2721
+ if (syncableBlock.author) {
2722
+ authorCounts.set(syncableBlock.author, (authorCounts.get(syncableBlock.author) || 0) + 1);
2723
+ }
2724
+ }
2725
+ if (authorCounts.size > 0) {
2726
+ console.log("\nBlocks by author:");
2727
+ const sortedAuthors = Array.from(authorCounts.entries()).sort((a, b) => b[1] - a[1]);
2728
+ for (const [author, count] of sortedAuthors.slice(0, 10)) {
2729
+ console.log(` ${author}: ${pc7.cyan(count.toString())}`);
2730
+ }
2731
+ }
2732
+ const severityCounts = /* @__PURE__ */ new Map();
2733
+ for (const block of blocks) {
2734
+ for (const entry of block.entries) {
2735
+ severityCounts.set(entry.severity, (severityCounts.get(entry.severity) || 0) + 1);
2736
+ }
2737
+ }
2738
+ if (severityCounts.size > 0) {
2739
+ console.log("\nIssues by severity:");
2740
+ const severityOrder = ["critical", "high", "medium", "low", "info"];
2741
+ for (const severity of severityOrder) {
2742
+ const count = severityCounts.get(severity);
2743
+ if (count) {
2744
+ const color = severity === "critical" ? pc7.red : severity === "high" ? pc7.yellow : severity === "medium" ? pc7.blue : pc7.gray;
2745
+ console.log(` ${color(severity)}: ${pc7.cyan(count.toString())}`);
2746
+ }
2747
+ }
2748
+ }
2749
+ } catch (error) {
2750
+ console.error(pc7.red("Failed to show ledger stats:"), error);
2751
+ process.exit(1);
2752
+ }
2753
+ });
2754
+ ledger.command("diff").description("Compare local and shared ledger state").action(async () => {
2755
+ try {
2756
+ const status = await getLedgerSyncStatus();
2757
+ console.log(pc7.bold("Ledger Diff\n"));
2758
+ if (!status.isInitialized) {
2759
+ console.log(pc7.yellow("Shared ledger not initialized"));
2760
+ return;
2761
+ }
2762
+ console.log(`Local blocks: ${pc7.cyan(status.localBlocks.toString())}`);
2763
+ console.log(`Shared blocks: ${pc7.cyan(status.sharedBlocks.toString())}`);
2764
+ const diff = status.sharedBlocks - status.localBlocks;
2765
+ if (diff > 0) {
2766
+ console.log(pc7.green(`\u2193 ${diff} blocks available to pull`));
2767
+ } else if (diff < 0) {
2768
+ console.log(pc7.blue(`\u2191 ${-diff} local blocks not yet pushed`));
2769
+ } else {
2770
+ console.log(pc7.green("\u2713 Local and shared ledgers are in sync"));
2771
+ }
2772
+ if (status.conflicts > 0) {
2773
+ console.log(pc7.red(`\u26A0 ${status.conflicts} conflicts detected`));
2774
+ }
2775
+ } catch (error) {
2776
+ console.error(pc7.red("Failed to diff ledgers:"), error);
2777
+ process.exit(1);
2778
+ }
2779
+ });
2780
+ ledger.command("compress").description("Manually compress and archive old blocks").action(async () => {
2781
+ try {
2782
+ const shouldRun = await shouldCompress();
2783
+ if (!shouldRun) {
2784
+ console.log("No compression needed at this time");
2785
+ return;
2786
+ }
2787
+ console.log("Compressing old ledger blocks...");
2788
+ const result = await compressOldBlocks();
2789
+ if (result.archived > 0) {
2790
+ console.log(pc7.green(`\u2713 Compressed ${result.archived} blocks`));
2791
+ console.log(`Space saved: ${result.sizeReduction}%`);
2792
+ } else {
2793
+ console.log("No blocks were archived");
2794
+ }
2795
+ } catch (error) {
2796
+ console.error(pc7.red("Failed to compress blocks:"), error);
2797
+ process.exit(1);
2798
+ }
2799
+ });
2800
+ ledger.command("storage").description("Show detailed storage statistics").action(async () => {
2801
+ try {
2802
+ const stats = await getStorageStats();
2803
+ console.log(pc7.bold("Ledger Storage Statistics\n"));
2804
+ console.log(pc7.bold("Block Storage:"));
2805
+ console.log(` Active blocks: ${pc7.cyan(stats.activeBlocks.toString())}`);
2806
+ console.log(` Archived blocks: ${pc7.cyan(stats.archivedBlocks.toString())}`);
2807
+ console.log(pc7.bold("\nStorage Usage:"));
2808
+ const activeMB = (stats.activeSize / 1024 / 1024).toFixed(2);
2809
+ const archivedMB = (stats.archivedSize / 1024 / 1024).toFixed(2);
2810
+ const totalMB = (Number(activeMB) + Number(archivedMB)).toFixed(2);
2811
+ console.log(` Active storage: ${pc7.cyan(`${activeMB} MB`)}`);
2812
+ console.log(` Archived storage: ${pc7.cyan(`${archivedMB} MB`)}`);
2813
+ console.log(` Total storage: ${pc7.bold(pc7.cyan(`${totalMB} MB`))}`);
2814
+ if (stats.compressionRatio > 0) {
2815
+ console.log(` Compression ratio: ${pc7.green(`${stats.compressionRatio}%`)}`);
2816
+ }
2817
+ console.log(pc7.bold("\nData:"));
2818
+ console.log(` Total entries: ${pc7.cyan(stats.totalEntries.toString())}`);
2819
+ const needsCompression = await shouldCompress();
2820
+ if (needsCompression) {
2821
+ console.log(`
2822
+ ${pc7.yellow("\u{1F4A1} Tip:")} Run ${pc7.bold("trie ledger compress")} to archive old blocks`);
2823
+ }
2824
+ } catch (error) {
2825
+ console.error(pc7.red("Failed to get storage stats:"), error);
2826
+ process.exit(1);
2827
+ }
2828
+ });
2829
+ ledger.command("delete").description("Delete specific blocks from the ledger (PERMANENT)").argument("<dates...>", "Block dates to delete (YYYY-MM-DD format)").option("--confirm", "Confirm the permanent deletion").action(async (dates, options) => {
2830
+ try {
2831
+ const datePattern = /^\d{4}-\d{2}-\d{2}$/;
2832
+ const invalidDates = dates.filter((date) => !datePattern.test(date));
2833
+ if (invalidDates.length > 0) {
2834
+ console.error(pc7.red("Invalid date format(s):"), invalidDates.join(", "));
2835
+ console.error("Please use YYYY-MM-DD format");
2836
+ process.exit(1);
2837
+ }
2838
+ if (!options.confirm) {
2839
+ console.log(pc7.bold(pc7.red("\u26A0\uFE0F DANGER: PERMANENT DELETION")));
2840
+ console.log("");
2841
+ console.log(`You are about to permanently delete ${dates.length} block(s):`);
2842
+ for (const date of dates) {
2843
+ console.log(` \u2022 ${pc7.cyan(date)}`);
2844
+ }
2845
+ console.log("");
2846
+ console.log(pc7.red("This operation cannot be undone and will permanently remove"));
2847
+ console.log(pc7.red("all issues and data from these blocks."));
2848
+ console.log("");
2849
+ console.log(`To proceed, add the ${pc7.bold("--confirm")} flag:`);
2850
+ console.log(` ${pc7.dim("trie ledger delete " + dates.join(" ") + " --confirm")}`);
2851
+ return;
2852
+ }
2853
+ console.log(pc7.yellow("\u{1F5D1}\uFE0F Deleting blocks..."));
2854
+ const result = await deleteBlocks(dates, void 0, true);
2855
+ if (result.success) {
2856
+ console.log(pc7.green(`\u2713 Successfully deleted ${result.deletedBlocks} block(s)`));
2857
+ if (result.warning) {
2858
+ console.log(pc7.yellow(`\u26A0\uFE0F ${result.warning}`));
2859
+ }
2860
+ } else {
2861
+ console.error(pc7.red("\u2717 Deletion failed:"), result.error);
2862
+ process.exit(1);
2863
+ }
2864
+ } catch (error) {
2865
+ console.error(pc7.red("Failed to delete blocks:"), error);
2866
+ process.exit(1);
2867
+ }
2868
+ });
2869
+ ledger.command("clear").description("Delete ALL blocks from the ledger (PERMANENT)").option("--confirm", "Confirm the permanent deletion of all blocks").action(async (options) => {
2870
+ try {
2871
+ if (!options.confirm) {
2872
+ console.log(pc7.bold(pc7.red("\u{1F6A8} DANGER: COMPLETE LEDGER DELETION")));
2873
+ console.log("");
2874
+ console.log(pc7.red("You are about to permanently delete ALL blocks in the ledger."));
2875
+ console.log(pc7.red("This will completely erase the entire ledger history."));
2876
+ console.log("");
2877
+ console.log(pc7.red("This operation cannot be undone and will permanently remove"));
2878
+ console.log(pc7.red("ALL issues and historical data."));
2879
+ console.log("");
2880
+ console.log(`To proceed, add the ${pc7.bold("--confirm")} flag:`);
2881
+ console.log(` ${pc7.dim("trie ledger clear --confirm")}`);
2882
+ return;
2883
+ }
2884
+ console.log(pc7.yellow("\u{1F5D1}\uFE0F Clearing entire ledger..."));
2885
+ const result = await deleteAllBlocks(void 0, true);
2886
+ if (result.success) {
2887
+ console.log(pc7.green(`\u2713 Successfully deleted ${result.deletedBlocks} block(s)`));
2888
+ if (result.warning) {
2889
+ console.log(pc7.yellow(`\u26A0\uFE0F ${result.warning}`));
2890
+ }
2891
+ } else {
2892
+ console.error(pc7.red("\u2717 Clear operation failed:"), result.error);
2893
+ process.exit(1);
2894
+ }
2895
+ } catch (error) {
2896
+ console.error(pc7.red("Failed to clear ledger:"), error);
2897
+ process.exit(1);
2898
+ }
2899
+ });
2900
+ return ledger;
2901
+ }
2902
+
2401
2903
  // src/cli/main.ts
2402
2904
  var __filename2 = fileURLToPath(import.meta.url);
2403
2905
  var __dirname2 = dirname(__filename2);
@@ -2557,47 +3059,47 @@ async function handleStatusCommand() {
2557
3059
  const lastScanDate = new Date(state.lastScan.timestamp);
2558
3060
  const daysAgo = Math.floor((Date.now() - lastScanDate.getTime()) / (1e3 * 60 * 60 * 24));
2559
3061
  console.log(`
2560
- ${pc5.bold("Last Scan:")} ${lastScanDate.toLocaleDateString()} (${daysAgo === 0 ? "today" : daysAgo === 1 ? "yesterday" : `${daysAgo} days ago`})`);
2561
- console.log(pc5.dim(` Files scanned: ${state.lastScan.filesScanned}`));
2562
- console.log(pc5.dim(` Issues found: ${state.lastScan.issues.total} (${state.lastScan.issues.critical} critical, ${state.lastScan.issues.serious} serious)`));
3062
+ ${pc8.bold("Last Scan:")} ${lastScanDate.toLocaleDateString()} (${daysAgo === 0 ? "today" : daysAgo === 1 ? "yesterday" : `${daysAgo} days ago`})`);
3063
+ console.log(pc8.dim(` Files scanned: ${state.lastScan.filesScanned}`));
3064
+ console.log(pc8.dim(` Issues found: ${state.lastScan.issues.total} (${state.lastScan.issues.critical} critical, ${state.lastScan.issues.serious} serious)`));
2563
3065
  } else {
2564
3066
  console.log(`
2565
- ${pc5.bold("Last Scan:")} Never ${pc5.dim("(run `trie scan` to get started)")}`);
3067
+ ${pc8.bold("Last Scan:")} Never ${pc8.dim("(run `trie scan` to get started)")}`);
2566
3068
  }
2567
3069
  console.log(`
2568
- ${pc5.bold("Memory Stats:")}`);
2569
- console.log(pc5.dim(` Active Issues: ${memoryStats.activeIssues}`));
2570
- console.log(pc5.dim(` Resolved: ${memoryStats.resolvedCount}`));
2571
- console.log(pc5.dim(` Total (all-time): ${memoryStats.totalIssues}`));
3070
+ ${pc8.bold("Memory Stats:")}`);
3071
+ console.log(pc8.dim(` Active Issues: ${memoryStats.activeIssues}`));
3072
+ console.log(pc8.dim(` Resolved: ${memoryStats.resolvedCount}`));
3073
+ console.log(pc8.dim(` Total (all-time): ${memoryStats.totalIssues}`));
2572
3074
  const cap = memoryStats.capacityInfo;
2573
- const capIndicator = cap.isAtCap ? pc5.red("\u25CB") : cap.percentFull >= 80 ? pc5.yellow("\u25C9") : pc5.green("\u25CF");
2574
- console.log(` ${capIndicator} Memory Usage: ${pc5.bold(cap.percentFull + "%")} ${pc5.dim(`(${cap.current}/${cap.max})`)}`);
3075
+ const capIndicator = cap.isAtCap ? pc8.red("\u25CB") : cap.percentFull >= 80 ? pc8.yellow("\u25C9") : pc8.green("\u25CF");
3076
+ console.log(` ${capIndicator} Memory Usage: ${pc8.bold(cap.percentFull + "%")} ${pc8.dim(`(${cap.current}/${cap.max})`)}`);
2575
3077
  if (memoryStats.activeIssues > 0) {
2576
3078
  console.log(`
2577
- ${pc5.bold("Active Issues by Severity:")}`);
3079
+ ${pc8.bold("Active Issues by Severity:")}`);
2578
3080
  const severityOrder = ["critical", "serious", "moderate", "low", "info"];
2579
3081
  for (const severity of severityOrder) {
2580
3082
  const count = memoryStats.activeIssuesBySeverity[severity] || 0;
2581
3083
  if (count > 0) {
2582
- console.log(pc5.dim(` ${severity}: ${count}`));
3084
+ console.log(pc8.dim(` ${severity}: ${count}`));
2583
3085
  }
2584
3086
  }
2585
3087
  } else if (memoryStats.totalIssues > 0) {
2586
3088
  console.log(`
2587
- ${pc5.green("\u25CF")} All issues have been resolved`);
3089
+ ${pc8.green("\u25CF")} All issues have been resolved`);
2588
3090
  }
2589
3091
  if (cap.isAtCap) {
2590
3092
  console.log(`
2591
- ${pc5.yellow("\u2B22 Warning:")} Memory at capacity - consider running: ${pc5.bold("trie memory purge smart")}`);
3093
+ ${pc8.yellow("\u2B22 Warning:")} Memory at capacity - consider running: ${pc8.bold("trie memory purge smart")}`);
2592
3094
  } else if (cap.percentFull >= 80) {
2593
3095
  console.log(`
2594
- ${pc5.yellow("\u2B22 Notice:")} Memory usage high - consider running: ${pc5.bold("trie memory purge smart")}`);
3096
+ ${pc8.yellow("\u2B22 Notice:")} Memory usage high - consider running: ${pc8.bold("trie memory purge smart")}`);
2595
3097
  }
2596
3098
  console.log(`
2597
- ${pc5.bold("Quick Commands:")}`);
2598
- console.log(pc5.dim(" trie scan - Scan codebase now"));
2599
- console.log(pc5.dim(" trie memory stats - Detailed memory statistics"));
2600
- console.log(pc5.dim(" trie project - View project information"));
3099
+ ${pc8.bold("Quick Commands:")}`);
3100
+ console.log(pc8.dim(" trie scan - Scan codebase now"));
3101
+ console.log(pc8.dim(" trie memory stats - Detailed memory statistics"));
3102
+ console.log(pc8.dim(" trie project - View project information"));
2601
3103
  console.log("");
2602
3104
  } catch (error) {
2603
3105
  console.error("Error loading status:", error);
@@ -2615,7 +3117,7 @@ async function handleProject(args) {
2615
3117
  \u2551 PROJECT.md Created \u2551
2616
3118
  \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
2617
3119
 
2618
- ${pc5.bold("Path:")} ${result.path}
3120
+ ${pc8.bold("Path:")} ${result.path}
2619
3121
 
2620
3122
  A template has been created with sections for:
2621
3123
  \u2022 Project Overview
@@ -2640,7 +3142,7 @@ Next steps:
2640
3142
  }
2641
3143
  if (subcommand === "edit") {
2642
3144
  const editor = process.env.EDITOR || process.env.VISUAL || "nano";
2643
- const projectPath = join3(getTrieDirectory(workDir), "PROJECT.md");
3145
+ const projectPath = join4(getTrieDirectory(workDir), "PROJECT.md");
2644
3146
  if (!projectInfoExists(workDir)) {
2645
3147
  console.log("No PROJECT.md found. Creating one first...");
2646
3148
  await initProjectInfo(workDir);
@@ -2658,7 +3160,7 @@ Next steps:
2658
3160
  \u2551 Project Information \u2551
2659
3161
  \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
2660
3162
 
2661
- ${pc5.bold("No PROJECT.md found in this project.")}
3163
+ ${pc8.bold("No PROJECT.md found in this project.")}
2662
3164
 
2663
3165
  COMMANDS:
2664
3166
  trie project init Create PROJECT.md from template
@@ -2686,7 +3188,7 @@ This info is available via trie://project MCP resource.
2686
3188
  \u2551 Project Information \u2551
2687
3189
  \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
2688
3190
 
2689
- ${pc5.bold("Path:")} ${join3(getTrieDirectory(workDir), "PROJECT.md")}
3191
+ ${pc8.bold("Path:")} ${join4(getTrieDirectory(workDir), "PROJECT.md")}
2690
3192
 
2691
3193
  ${"-".repeat(68)}
2692
3194
  `);
@@ -2845,6 +3347,18 @@ async function main() {
2845
3347
  case "pattern":
2846
3348
  handlePatternsCommand(restArgs);
2847
3349
  break;
3350
+ case "sync":
3351
+ {
3352
+ const syncCommand = createSyncCommand();
3353
+ syncCommand.parse(["node", "trie", "sync", ...restArgs], { from: "user" });
3354
+ }
3355
+ break;
3356
+ case "ledger":
3357
+ {
3358
+ const ledgerCommand = createLedgerCommand();
3359
+ ledgerCommand.parse(["node", "trie", "ledger", ...restArgs], { from: "user" });
3360
+ }
3361
+ break;
2848
3362
  default:
2849
3363
  if (command.startsWith("-")) {
2850
3364
  const { spawn } = __require("child_process");