instar 0.28.87 → 0.28.89

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.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiQH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAg4CD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAu4JtE;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;AAiQH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAw4CD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAw6JtE;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"}
@@ -270,6 +270,11 @@ let _projectDir = process.cwd();
270
270
  let _sharedIntelligence = null;
271
271
  let _selfKnowledgeTree = null;
272
272
  let _slackAdapter = null;
273
+ // SessionRefresh — agent-initiated respawn. Module-scope so onRestartSession
274
+ // (defined outside startServer) can delegate to it once startServer wires it.
275
+ // Null until startServer constructs it; the Telegram /restart handler falls
276
+ // back to the inline kill+respawn path when null (e.g. early in boot).
277
+ let _sessionRefresh = null;
273
278
  async function spawnSessionForTopic(sessionManager, telegram, sessionName, topicId, latestMessage, topicMemory, userProfile) {
274
279
  const msg = latestMessage || 'Session started — send a message to continue.';
275
280
  // If memory is elevated/critical and we have the reaper, try to free memory
@@ -538,25 +543,28 @@ function wireTelegramCallbacks(telegram, sessionManager, state, quotaTracker, ac
538
543
  return false;
539
544
  }
540
545
  };
541
- // /restart — kill session and respawn
546
+ // /restart — kill session and respawn. Delegates to SessionRefresh, the
547
+ // consolidated lifecycle owner: it routes the kill through
548
+ // sessionManager.killSession (which fires the kill hook so the UUID
549
+ // listener persists session.claudeSessionId), then spawns a fresh tmux
550
+ // running `claude --resume <uuid>`. Includes the rate guard against
551
+ // infinite-respawn loops.
552
+ //
553
+ // If SessionRefresh isn't wired yet (very narrow early-boot window
554
+ // before startServer reaches the construction point), we no-op with a
555
+ // warning instead of falling back to a broken inline path — the
556
+ // pre-PR inline kill bypassed sessionManager.killSession and so the
557
+ // kill hook never fired, meaning resume UUIDs were silently dropped.
558
+ // Routing exclusively through SessionRefresh fixes that latent issue.
542
559
  telegram.onRestartSession = async (sessionName, topicId) => {
543
- // Save resume UUID before killing so the new session can --resume
544
- if (_topicResumeMap) {
545
- try {
546
- const uuid = _topicResumeMap.findUuidForSession(sessionName);
547
- if (uuid) {
548
- _topicResumeMap.save(topicId, uuid, sessionName);
549
- }
550
- }
551
- catch { /* best effort */ }
560
+ if (!_sessionRefresh) {
561
+ console.warn(`[telegram /restart] SessionRefresh not yet wired; deferring restart for sessionName=${sessionName} topicId=${topicId}`);
562
+ return;
552
563
  }
553
- // Kill existing session
554
- try {
555
- execFileSync(detectTmuxPath(), ['kill-session', '-t', `=${sessionName}`], { stdio: 'ignore' });
564
+ const result = await _sessionRefresh.refreshSession({ sessionName, reason: 'telegram-/restart' });
565
+ if (!result.ok) {
566
+ console.warn(`[telegram /restart] SessionRefresh refused sessionName=${sessionName} code=${result.code}`);
556
567
  }
557
- catch { /* may already be dead */ }
558
- // Respawn with thread history
559
- await respawnSessionForTopic(sessionManager, telegram, sessionName, topicId, undefined, topicMemory);
560
568
  };
561
569
  // /sessions — list running sessions
562
570
  telegram.onListSessions = () => {
@@ -5718,6 +5726,15 @@ export async function startServer(options) {
5718
5726
  }
5719
5727
  const { InitiativeTracker } = await import('../core/InitiativeTracker.js');
5720
5728
  const initiativeTracker = new InitiativeTracker(config.stateDir);
5729
+ // Project-scope Phase 1.9 — wire the digest cache writer so every
5730
+ // project mutation re-renders `.instar/projects-digest.cache`. The
5731
+ // session-start + compaction-recovery hooks read this file directly
5732
+ // (≤50ms budget, no HTTP). First-start writes the file unconditionally
5733
+ // so the hooks always have something to read on a fresh install.
5734
+ const { ProjectDigestCache } = await import('../core/ProjectDigestCache.js');
5735
+ const projectDigestCache = new ProjectDigestCache(config.stateDir, initiativeTracker);
5736
+ initiativeTracker.setDigestCacheInvalidator(() => projectDigestCache.writeDigestCache());
5737
+ projectDigestCache.writeDigestCache();
5721
5738
  // TaskFlow registry — opt-in via config.taskFlow.enabled (default: off in v1).
5722
5739
  // Owns its own SQLite file under .instar/task-flows.db. The maintenance
5723
5740
  // sweeper and due-waker start with the registry; both .unref() their timers
@@ -5800,7 +5817,29 @@ export async function startServer(options) {
5800
5817
  divergenceChecker = undefined;
5801
5818
  }
5802
5819
  }
5803
- const server = new AgentServer({ config, sessionManager, state, scheduler, telegram, relationships, feedback, feedbackAnomalyDetector, dispatches, updateChecker, autoUpdater, autoDispatcher, quotaTracker, quotaManager, publisher, viewer, tunnel, evolution, watchdog, topicMemory, triageNurse, projectMapper, coherenceGate: scopeVerifier, contextHierarchy, canonicalState, operationGate, sentinel, adaptiveTrust, memoryMonitor, orphanReaper, coherenceMonitor, commitmentTracker, semanticMemory, activitySentinel, messageRouter, summarySentinel, spawnManager, systemReviewer, capabilityMapper, selfKnowledgeTree, coverageAuditor, topicResumeMap: _topicResumeMap ?? undefined, autonomyManager, trustElevationTracker, autonomousEvolution, coordinator: coordinator.enabled ? coordinator : undefined, localSigningKeyPem, whatsapp: whatsappAdapter, slack: slackAdapter, imessage: imessageAdapter, whatsappBusinessBackend, messageBridge, hookEventReceiver, worktreeMonitor, subagentTracker, instructionsVerifier, handshakeManager: threadlineHandshake, threadlineRouter, threadlineRelayClient, threadlineReplyWaiters, listenerManager: listenerManager ?? undefined, responseReviewGate, messagingToneGate, outboundDedupGate, telemetryHeartbeat, pasteManager, featureRegistry, discoveryEvaluator, unifiedTrust, liveConfig, sharedStateLedger, ledgerSessionRegistry, worktreeManager, oidcEnrolledRepos: parallelDevConfig?.oidcEnrolledRepos, initiativeTracker, proxyCoordinator, telegramBridgeConfig, telegramBridge: telegramBridge ?? undefined, threadlineObservability, workingMemory, taskFlowRegistry, threadlineFlowBridge });
5820
+ // SessionRefresh — agent-initiated session respawn. Requires a Telegram
5821
+ // adapter (v1 scope: Telegram-bound sessions only). The respawner closure
5822
+ // captures `topicMemory` by reference, so even if topicMemory is wired up
5823
+ // after this point it will be resolved at refresh-time.
5824
+ if (telegram) {
5825
+ const { SessionRefresh } = await import('../core/SessionRefresh.js');
5826
+ const telegramRef = telegram; // narrow for closure
5827
+ _sessionRefresh = new SessionRefresh({
5828
+ sessionManager,
5829
+ state,
5830
+ telegram: telegramRef,
5831
+ topicResumeMap: _topicResumeMap,
5832
+ respawner: async (sessionName, topicId, followUpPrompt) => {
5833
+ // killSession (called inside SessionRefresh) has already fired
5834
+ // beforeSessionKill (UUID persisted) and destroyed the tmux
5835
+ // session. respawnSessionForTopic spawns the new tmux running
5836
+ // `claude --resume <uuid>` and registers the topic mapping.
5837
+ await respawnSessionForTopic(sessionManager, telegramRef, sessionName, topicId, followUpPrompt, topicMemory);
5838
+ return telegramRef.getSessionForTopic(topicId) ?? sessionName;
5839
+ },
5840
+ });
5841
+ }
5842
+ const server = new AgentServer({ config, sessionManager, state, scheduler, telegram, relationships, feedback, feedbackAnomalyDetector, dispatches, updateChecker, autoUpdater, autoDispatcher, quotaTracker, quotaManager, publisher, viewer, tunnel, evolution, watchdog, topicMemory, triageNurse, projectMapper, coherenceGate: scopeVerifier, contextHierarchy, canonicalState, operationGate, sentinel, adaptiveTrust, memoryMonitor, orphanReaper, coherenceMonitor, commitmentTracker, semanticMemory, activitySentinel, messageRouter, summarySentinel, spawnManager, systemReviewer, capabilityMapper, selfKnowledgeTree, coverageAuditor, topicResumeMap: _topicResumeMap ?? undefined, sessionRefresh: _sessionRefresh ?? undefined, autonomyManager, trustElevationTracker, autonomousEvolution, coordinator: coordinator.enabled ? coordinator : undefined, localSigningKeyPem, whatsapp: whatsappAdapter, slack: slackAdapter, imessage: imessageAdapter, whatsappBusinessBackend, messageBridge, hookEventReceiver, worktreeMonitor, subagentTracker, instructionsVerifier, handshakeManager: threadlineHandshake, threadlineRouter, threadlineRelayClient, threadlineReplyWaiters, listenerManager: listenerManager ?? undefined, responseReviewGate, messagingToneGate, outboundDedupGate, telemetryHeartbeat, pasteManager, featureRegistry, discoveryEvaluator, unifiedTrust, liveConfig, sharedStateLedger, ledgerSessionRegistry, worktreeManager, oidcEnrolledRepos: parallelDevConfig?.oidcEnrolledRepos, initiativeTracker, proxyCoordinator, telegramBridgeConfig, telegramBridge: telegramBridge ?? undefined, threadlineObservability, workingMemory, taskFlowRegistry, threadlineFlowBridge });
5804
5843
  await server.start();
5805
5844
  void taskFlowSweeper;
5806
5845
  void taskFlowDueWaker;