instar 0.23.9 → 0.23.11

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 (52) hide show
  1. package/dist/cli.js +0 -0
  2. package/dist/commands/server.d.ts.map +1 -1
  3. package/dist/commands/server.js +73 -20
  4. package/dist/commands/server.js.map +1 -1
  5. package/dist/commands/setup.d.ts.map +1 -1
  6. package/dist/commands/setup.js +16 -1
  7. package/dist/commands/setup.js.map +1 -1
  8. package/dist/core/ResponseReviewGate.d.ts +182 -0
  9. package/dist/core/ResponseReviewGate.d.ts.map +1 -0
  10. package/dist/core/ResponseReviewGate.js +956 -0
  11. package/dist/core/ResponseReviewGate.js.map +1 -0
  12. package/dist/core/SessionManager.d.ts.map +1 -1
  13. package/dist/core/SessionManager.js +8 -0
  14. package/dist/core/SessionManager.js.map +1 -1
  15. package/dist/knowledge/TreeGenerator.d.ts.map +1 -1
  16. package/dist/knowledge/TreeGenerator.js +13 -0
  17. package/dist/knowledge/TreeGenerator.js.map +1 -1
  18. package/dist/knowledge/TreeTriage.js +1 -1
  19. package/dist/knowledge/TreeTriage.js.map +1 -1
  20. package/dist/lifeline/TelegramLifeline.d.ts +9 -0
  21. package/dist/lifeline/TelegramLifeline.d.ts.map +1 -1
  22. package/dist/lifeline/TelegramLifeline.js +123 -10
  23. package/dist/lifeline/TelegramLifeline.js.map +1 -1
  24. package/dist/memory/MemoryIndex.d.ts.map +1 -1
  25. package/dist/memory/MemoryIndex.js +1 -0
  26. package/dist/memory/MemoryIndex.js.map +1 -1
  27. package/dist/memory/SemanticMemory.d.ts +5 -0
  28. package/dist/memory/SemanticMemory.d.ts.map +1 -1
  29. package/dist/memory/SemanticMemory.js +13 -0
  30. package/dist/memory/SemanticMemory.js.map +1 -1
  31. package/dist/memory/TopicMemory.d.ts +5 -0
  32. package/dist/memory/TopicMemory.d.ts.map +1 -1
  33. package/dist/memory/TopicMemory.js +13 -0
  34. package/dist/memory/TopicMemory.js.map +1 -1
  35. package/dist/messaging/TelegramAdapter.d.ts +7 -0
  36. package/dist/messaging/TelegramAdapter.d.ts.map +1 -1
  37. package/dist/messaging/TelegramAdapter.js +53 -14
  38. package/dist/messaging/TelegramAdapter.js.map +1 -1
  39. package/dist/threadline/relay/RegistryStore.d.ts.map +1 -1
  40. package/dist/threadline/relay/RegistryStore.js +1 -0
  41. package/dist/threadline/relay/RegistryStore.js.map +1 -1
  42. package/dist/tunnel/TunnelManager.d.ts +22 -1
  43. package/dist/tunnel/TunnelManager.d.ts.map +1 -1
  44. package/dist/tunnel/TunnelManager.js +118 -1
  45. package/dist/tunnel/TunnelManager.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/data/builtin-manifest.json +5 -5
  48. package/upgrades/0.23.10.md +19 -0
  49. package/upgrades/0.23.11.md +21 -0
  50. package/upgrades/0.23.8.md +38 -0
  51. package/upgrades/0.23.9.md +21 -24
  52. package/upgrades/NEXT.md +35 -0
package/dist/cli.js CHANGED
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwPH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA8gCD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAy1EtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwPH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAiiCD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAk3EtE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
@@ -1006,15 +1006,22 @@ async function ensureAgentUpdatesTopic(telegram, state) {
1006
1006
  */
1007
1007
  async function ensureSqliteBindings() {
1008
1008
  try {
1009
- await import('better-sqlite3');
1010
- // Bindings loaded OKnothing to do.
1009
+ const BetterSqlite3 = (await import('better-sqlite3')).default;
1010
+ // Import alone doesn't catch all mismatches some NODE_MODULE_VERSION
1011
+ // conflicts cause runtime crashes (C++ mutex errors) rather than import errors.
1012
+ // Actually opening an in-memory DB exercises the native bindings fully.
1013
+ const testDb = new BetterSqlite3(':memory:');
1014
+ testDb.pragma('journal_mode = WAL');
1015
+ testDb.close();
1011
1016
  return false;
1012
1017
  }
1013
1018
  catch (err) {
1014
1019
  const reason = err instanceof Error ? err.message : String(err);
1015
1020
  const isBindingError = reason.includes('Could not locate the bindings file') ||
1016
1021
  reason.includes('better-sqlite3') ||
1017
- reason.includes('was compiled against a different Node.js version');
1022
+ reason.includes('was compiled against a different Node.js version') ||
1023
+ reason.includes('NODE_MODULE_VERSION') ||
1024
+ reason.includes('mutex lock failed');
1018
1025
  if (!isBindingError)
1019
1026
  return false; // Not a binding issue — let subsystems handle it.
1020
1027
  console.log(pc.yellow(' better-sqlite3: native binding mismatch detected — auto-rebuilding for current Node.js version...'));
@@ -1026,14 +1033,27 @@ async function ensureSqliteBindings() {
1026
1033
  execFileSync(process.execPath, [fixScript], { encoding: 'utf-8', timeout: 60000, stdio: 'pipe' });
1027
1034
  }
1028
1035
  else {
1029
- // Fallback: npm rebuild (may fail in pnpm/asdf environments)
1030
- const globalInstarDir = execSync('npm root -g', { encoding: 'utf-8', timeout: 10000 }).trim() + '/instar';
1031
- execSync('npm rebuild better-sqlite3', {
1032
- cwd: globalInstarDir,
1033
- encoding: 'utf-8',
1034
- timeout: 60000,
1035
- stdio: 'pipe',
1036
- });
1036
+ // Fallback: npm rebuild in the directory containing better-sqlite3.
1037
+ // Shadow installs have their own node_modules try that first, then global.
1038
+ const instarDir = new URL('../../..', import.meta.url).pathname;
1039
+ const shadowBs3 = path.join(instarDir, 'node_modules', 'better-sqlite3');
1040
+ if (fs.existsSync(shadowBs3)) {
1041
+ execSync('npm rebuild better-sqlite3', {
1042
+ cwd: instarDir,
1043
+ encoding: 'utf-8',
1044
+ timeout: 60000,
1045
+ stdio: 'pipe',
1046
+ });
1047
+ }
1048
+ else {
1049
+ const globalInstarDir = execSync('npm root -g', { encoding: 'utf-8', timeout: 10000 }).trim() + '/instar';
1050
+ execSync('npm rebuild better-sqlite3', {
1051
+ cwd: globalInstarDir,
1052
+ encoding: 'utf-8',
1053
+ timeout: 60000,
1054
+ stdio: 'pipe',
1055
+ });
1056
+ }
1037
1057
  }
1038
1058
  console.log(pc.green(' better-sqlite3: rebuilt successfully — restarting to apply (ESM module cache must be cleared).'));
1039
1059
  return true; // Restart needed — ESM cache holds the stale failure
@@ -2511,6 +2531,15 @@ export async function startServer(options) {
2511
2531
  const sleepWakeDetector = new SleepWakeDetector();
2512
2532
  sleepWakeDetector.on('wake', async (event) => {
2513
2533
  console.log(`[SleepWake] Wake detected after ~${event.sleepDurationSeconds}s sleep`);
2534
+ // Checkpoint SQLite WAL files to flush stale locks from pre-sleep connections
2535
+ try {
2536
+ topicMemory?.checkpoint();
2537
+ }
2538
+ catch { /* non-critical */ }
2539
+ try {
2540
+ semanticMemory?.checkpoint();
2541
+ }
2542
+ catch { /* non-critical */ }
2514
2543
  // Re-validate tmux sessions
2515
2544
  try {
2516
2545
  const tmuxPath = detectTmuxPath();
@@ -2523,17 +2552,24 @@ export async function startServer(options) {
2523
2552
  catch {
2524
2553
  console.warn('[SleepWake] tmux check failed after wake');
2525
2554
  }
2526
- // Restart tunnel if configured
2555
+ // Restart tunnel if configured — use forceStop to handle zombie cloudflared
2556
+ // processes that may be hung after sleep. Race with a 15s overall timeout
2557
+ // to prevent the wake handler itself from blocking indefinitely.
2527
2558
  if (tunnel) {
2528
2559
  try {
2529
- await tunnel.stop();
2530
- const tunnelUrl = await tunnel.start();
2531
- console.log(`[SleepWake] Tunnel restarted: ${tunnelUrl}`);
2532
- // Re-broadcast dashboard URL after tunnel restart (quick tunnels get new URL)
2533
- if (telegram && tunnelUrl) {
2534
- const tunnelType = config.tunnel?.type || 'quick';
2535
- await telegram.broadcastDashboardUrl(tunnelUrl, tunnelType).catch(() => { });
2536
- }
2560
+ await Promise.race([
2561
+ (async () => {
2562
+ await tunnel.forceStop(5000);
2563
+ const tunnelUrl = await tunnel.start();
2564
+ console.log(`[SleepWake] Tunnel restarted: ${tunnelUrl}`);
2565
+ // Re-broadcast dashboard URL after tunnel restart (quick tunnels get new URL)
2566
+ if (telegram && tunnelUrl) {
2567
+ const tunnelType = config.tunnel?.type || 'quick';
2568
+ await telegram.broadcastDashboardUrl(tunnelUrl, tunnelType).catch(() => { });
2569
+ }
2570
+ })(),
2571
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Tunnel restart timed out after 15s')), 15_000)),
2572
+ ]);
2537
2573
  }
2538
2574
  catch (err) {
2539
2575
  console.error(`[SleepWake] Tunnel restart failed:`, err);
@@ -3109,6 +3145,7 @@ export async function startServer(options) {
3109
3145
  }
3110
3146
  // Start tunnel AFTER server is listening (with retry on failure)
3111
3147
  if (tunnel) {
3148
+ tunnel.enableAutoReconnect();
3112
3149
  const maxRetries = 5;
3113
3150
  let tunnelStarted = false;
3114
3151
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
@@ -3319,6 +3356,22 @@ export async function startServer(options) {
3319
3356
  };
3320
3357
  process.on('SIGINT', shutdown);
3321
3358
  process.on('SIGTERM', shutdown);
3359
+ // Last-resort SQLite cleanup — if the process crashes from an uncaught exception
3360
+ // (e.g., cloudflared crash cascade during sleep/wake), close databases to prevent
3361
+ // the "mutex lock failed" error on next start. This doesn't prevent the crash,
3362
+ // but ensures the next boot is clean.
3363
+ process.on('uncaughtException', (err) => {
3364
+ console.error('[FATAL] Uncaught exception — closing databases before crash:', err.message);
3365
+ try {
3366
+ topicMemory?.close();
3367
+ }
3368
+ catch { /* best effort */ }
3369
+ try {
3370
+ semanticMemory?.close();
3371
+ }
3372
+ catch { /* best effort */ }
3373
+ process.exit(1);
3374
+ });
3322
3375
  // Wire the ForegroundRestartWatcher to the graceful shutdown function.
3323
3376
  // This ensures auto-update restarts close all resources (especially SQLite
3324
3377
  // databases) before exiting, preventing the "mutex lock failed" crash.