instar 1.3.1121 → 1.3.1122

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 (36) hide show
  1. package/dist/commands/server.d.ts.map +1 -1
  2. package/dist/commands/server.js +60 -44
  3. package/dist/commands/server.js.map +1 -1
  4. package/dist/data/standards-guard-index.json +1 -1
  5. package/dist/data/standards-guard-index.meta.json +2 -2
  6. package/dist/data/standards-registry.meta.json +1 -1
  7. package/dist/messaging/DeliverySinkFailure.d.ts +14 -0
  8. package/dist/messaging/DeliverySinkFailure.d.ts.map +1 -0
  9. package/dist/messaging/DeliverySinkFailure.js +23 -0
  10. package/dist/messaging/DeliverySinkFailure.js.map +1 -0
  11. package/dist/messaging/NotificationBatcher.d.ts.map +1 -1
  12. package/dist/messaging/NotificationBatcher.js +14 -4
  13. package/dist/messaging/NotificationBatcher.js.map +1 -1
  14. package/dist/messaging/telegramSendSideComposition.d.ts +40 -0
  15. package/dist/messaging/telegramSendSideComposition.d.ts.map +1 -0
  16. package/dist/messaging/telegramSendSideComposition.js +36 -0
  17. package/dist/messaging/telegramSendSideComposition.js.map +1 -0
  18. package/dist/scheduler/JobScheduler.d.ts +23 -8
  19. package/dist/scheduler/JobScheduler.d.ts.map +1 -1
  20. package/dist/scheduler/JobScheduler.js +189 -29
  21. package/dist/scheduler/JobScheduler.js.map +1 -1
  22. package/dist/testing/selfActionRegistry.d.ts.map +1 -1
  23. package/dist/testing/selfActionRegistry.js +53 -0
  24. package/dist/testing/selfActionRegistry.js.map +1 -1
  25. package/dist/threadline/TelegramBridge.d.ts +4 -0
  26. package/dist/threadline/TelegramBridge.d.ts.map +1 -1
  27. package/dist/threadline/TelegramBridge.js +24 -0
  28. package/dist/threadline/TelegramBridge.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/data/builtin-manifest.json +3 -3
  31. package/src/data/standards-guard-index.json +1 -1
  32. package/src/data/standards-guard-index.meta.json +2 -2
  33. package/src/data/standards-registry.meta.json +1 -1
  34. package/upgrades/1.3.1122.md +64 -0
  35. package/upgrades/scheduler-alert-delivery.eli16.md +46 -0
  36. package/upgrades/side-effects/scheduler-alert-delivery.md +168 -0
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA8EH,OAAO,EAAE,cAAc,EAAkC,MAAM,2BAA2B,CAAC;AAU3F,OAAO,EAAE,eAAe,EAAiC,MAAM,iCAAiC,CAAC;AA0BjG,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AA+H7D,OAAO,KAAK,EAAW,oBAAoB,EAAe,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAgFtD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC1C,OAAO,CAUT;AAuID,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA+rDD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,oBAAoB,GAAG,IAAI,GACxC;IACD,YAAY,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,SAA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ForegroundRestartWatcher.js';
199
199
  import { NotificationBatcher } from '../messaging/NotificationBatcher.js';
200
200
  import { formatLocalTimestamp } from '../utils/localTime.js';
201
+ import { resolveTelegramStartupTopology, wireTelegramSendSide } from '../messaging/telegramSendSideComposition.js';
201
202
  import { MessageStore } from '../messaging/MessageStore.js';
202
203
  import { MessageFormatter } from '../messaging/MessageFormatter.js';
203
204
  import { MessageDelivery } from '../messaging/MessageDelivery.js';
@@ -6765,7 +6766,7 @@ export async function startServer(options) {
6765
6766
  const telegramConfig = config.messaging.find(m => m.type === 'telegram' && m.enabled);
6766
6767
  const skipTelegram = options.telegram === false; // --no-telegram sets telegram: false
6767
6768
  // Standby machines use send-only Telegram — they don't poll for messages
6768
- const isStandbyTelegram = !coordinator.isAwake && telegramConfig;
6769
+ const isStandbyTelegram = !coordinator.isAwake && telegramConfig != null;
6769
6770
  // Poll-ownership lease (Task 4 / 2026-05-27 silent-stalls postmortem,
6770
6771
  // SELF-PROPAGATION-HARNESS-SPEC.md Part 1): if a lifeline is already polling
6771
6772
  // this bot token (lease present + fresh + token-hash match), the server
@@ -6781,7 +6782,13 @@ export async function startServer(options) {
6781
6782
  const lifelineOwnsPolling = telegramConfig && telegramBotToken
6782
6783
  ? lifelineOwnsTelegramPoll(config.stateDir, telegramBotToken)
6783
6784
  : false;
6784
- if ((skipTelegram || isStandbyTelegram || lifelineOwnsPolling) && telegramConfig) {
6785
+ const telegramTopology = resolveTelegramStartupTopology({
6786
+ telegramConfigured: telegramConfig != null,
6787
+ skipTelegram,
6788
+ coordinatorAwake: coordinator.isAwake,
6789
+ lifelineOwnsPolling: Boolean(lifelineOwnsPolling),
6790
+ });
6791
+ if (telegramTopology?.mode === 'send-only' && telegramConfig) {
6785
6792
  // Send-only mode: no polling, but sendToTopic() works for session replies
6786
6793
  telegram = new TelegramAdapter({
6787
6794
  ...telegramConfig.config,
@@ -6864,7 +6871,7 @@ export async function startServer(options) {
6864
6871
  wireTelegramCallbacks(telegram, sessionManager, state, quotaTracker, undefined, config.sessions.claudePath, topicMemory);
6865
6872
  console.log(pc.green(' Telegram routing + command callbacks wired (send-only)'));
6866
6873
  }
6867
- if (telegramConfig && !skipTelegram && !isStandbyTelegram && !lifelineOwnsPolling) {
6874
+ if (telegramTopology?.mode === 'server-polling' && telegramConfig) {
6868
6875
  telegram = new TelegramAdapter({
6869
6876
  ...telegramConfig.config,
6870
6877
  // PR2: hot-reloadable accessors. Sending-side authoritative —
@@ -6892,23 +6899,6 @@ export async function startServer(options) {
6892
6899
  console.log(`[session-rename] Updated bound session "${tmuxSession}" display name → "${newName}" (topic ${topicId})`);
6893
6900
  }
6894
6901
  });
6895
- // Threadline → Telegram bridge — mirrors inbound/outbound threadline
6896
- // messages into per-thread Telegram topics. Default-OFF; the relay
6897
- // handler below and the threadline_send tool consult bridge.mirror*
6898
- // unconditionally — TelegramBridgeConfig owns the gate.
6899
- try {
6900
- const { TelegramBridge } = await import('../threadline/TelegramBridge.js');
6901
- telegramBridge = new TelegramBridge({
6902
- stateDir: config.stateDir,
6903
- localAgentName: config.projectName,
6904
- config: telegramBridgeConfig,
6905
- telegram,
6906
- });
6907
- console.log(pc.dim(` Threadline → Telegram bridge: armed (default ${telegramBridgeConfig.getSettings().enabled ? 'ENABLED' : 'OFF'})`));
6908
- }
6909
- catch (err) {
6910
- console.warn(pc.yellow(` Threadline → Telegram bridge init failed (non-fatal): ${err instanceof Error ? err.message : err}`));
6911
- }
6912
6902
  // Wire Prompt Gate callbacks — connect Telegram relay responses to sessions
6913
6903
  if (promptGateConfig?.enabled) {
6914
6904
  telegram.onPromptResponse = (sessionName, key) => {
@@ -6963,16 +6953,6 @@ export async function startServer(options) {
6963
6953
  relayPruneTimer.unref();
6964
6954
  console.log(pc.green(' Prompt Gate: Telegram relay wired'));
6965
6955
  }
6966
- // Wire NotificationBatcher to Telegram and start batching
6967
- notificationBatcher.setSendFunction(async (topicId, text) => {
6968
- await telegram.sendToTopic(topicId, text);
6969
- // NOTE: Batched notifications (SUMMARY/DIGEST) are NOT mirrored to Slack.
6970
- // Only IMMEDIATE notifications reach Slack (via the notify() gateway).
6971
- // This prevents notification spam in the attention channel.
6972
- return { messageId: 0 };
6973
- });
6974
- notificationBatcher.start();
6975
- console.log(pc.green(' Notification batcher enabled (SUMMARY: 30m, DIGEST: 2h)'));
6976
6956
  // accountSwitcher + the QuotaManager/collector pipeline were hoisted OUT
6977
6957
  // of this Telegram-polling block to top scope (finding A1) so the quota
6978
6958
  // collector runs even when the lifeline owns Telegram polling. See the
@@ -7045,12 +7025,46 @@ export async function startServer(options) {
7045
7025
  console.log(`[telegram] Mini-onboarding complete for ${firstName} (${telegramUserId})`);
7046
7026
  };
7047
7027
  console.log(pc.green(' Telegram message routing active'));
7028
+ // Ensure Agent Attention topic exists (the agent's direct line to the user)
7029
+ ensureAgentAttentionTopic(telegram, state).catch(err => {
7030
+ console.error(`[server] Failed to ensure Agent Attention topic: ${err}`);
7031
+ });
7032
+ // Ensure Agent Updates topic exists (informational updates, not critical)
7033
+ ensureAgentUpdatesTopic(telegram, state).catch(err => {
7034
+ console.error(`[server] Failed to ensure Agent Updates topic: ${err}`);
7035
+ });
7036
+ }
7037
+ // Poll ownership changes only inbound getUpdates. Every constructed adapter
7038
+ // remains a usable outbound sink, so polling-independent dependencies must
7039
+ // converge after both topology branches.
7040
+ if (telegram && telegramTopology) {
7041
+ const sendSide = wireTelegramSendSide({
7042
+ mode: telegramTopology.mode,
7043
+ telegram,
7044
+ scheduler,
7045
+ notificationBatcher,
7046
+ });
7047
+ console.log(pc.green(` Telegram send side wired (${sendSide.mode}; scheduler: ${sendSide.schedulerAttached ? 'attached' : 'not configured'}; batcher: attached)`));
7048
+ // Threadline mirroring writes durable thread→topic bindings. Every
7049
+ // send-capable process may construct the observer so a promoted standby
7050
+ // becomes ready without restart, but EACH mirror consults this live
7051
+ // lease/role predicate immediately before its effects. Demotion therefore
7052
+ // silences the old owner instead of leaving two mirroring voices alive.
7053
+ try {
7054
+ const { TelegramBridge } = await import('../threadline/TelegramBridge.js');
7055
+ telegramBridge = new TelegramBridge({
7056
+ stateDir: config.stateDir,
7057
+ localAgentName: config.projectName,
7058
+ config: telegramBridgeConfig,
7059
+ telegram,
7060
+ isOwner: () => coordinator.isAwake && coordinator.holdsLease(),
7061
+ });
7062
+ console.log(pc.dim(` Threadline → Telegram bridge: ${telegramTopology.bridgeOwner ? 'owner-ready' : 'standby-ready'} (default ${telegramBridgeConfig.getSettings().enabled ? 'ENABLED' : 'OFF'})`));
7063
+ }
7064
+ catch (err) {
7065
+ console.warn(pc.yellow(` Threadline → Telegram bridge init failed (non-fatal): ${err instanceof Error ? err.message : err}`));
7066
+ }
7048
7067
  if (scheduler) {
7049
- scheduler.setMessenger(telegram);
7050
- scheduler.setTelegram(telegram);
7051
- if (topicMemory?.isReady()) {
7052
- scheduler.setTopicMemory(topicMemory);
7053
- }
7054
7068
  // WS4.3 role-guard-at-spawn (MULTI-MACHINE-SEAMLESSNESS-SPEC §WS4.3,
7055
7069
  // CMT-1416). The provider is read LIVE at each spawn boundary: `enabled`
7056
7070
  // from multiMachine.seamlessness.ws43RoleGuard (DARK default), `holdsLease`
@@ -7059,7 +7073,7 @@ export async function startServer(options) {
7059
7073
  // deduped item (createAttentionItem dedups on id) so the operator learns a
7060
7074
  // state-writing job could not run on this read-only standby; it is
7061
7075
  // best-effort (the refusal itself is the load-bearing safety).
7062
- const telegramForRoleGuard = telegram; // const-narrow for the closure
7076
+ const telegramForRoleGuard = telegram;
7063
7077
  scheduler.setRoleGuard(() => ({
7064
7078
  // DEV-AGENT DARK GATE (operator directive 2026-06-13, topic 13481):
7065
7079
  // read ws43RoleGuard through resolveDevAgentGate so it resolves LIVE on
@@ -7082,15 +7096,12 @@ export async function startServer(options) {
7082
7096
  }).catch(() => { });
7083
7097
  });
7084
7098
  }
7085
- // Ensure Agent Attention topic exists (the agent's direct line to the user)
7086
- ensureAgentAttentionTopic(telegram, state).catch(err => {
7087
- console.error(`[server] Failed to ensure Agent Attention topic: ${err}`);
7088
- });
7089
- // Ensure Agent Updates topic exists (informational updates, not critical)
7090
- ensureAgentUpdatesTopic(telegram, state).catch(err => {
7091
- console.error(`[server] Failed to ensure Agent Updates topic: ${err}`);
7092
- });
7093
7099
  }
7100
+ // Finalize scheduler alert delivery after Telegram composition, including
7101
+ // the intentional "no Telegram configured" result. Availability and
7102
+ // composition completion are distinct: an absent sink must remain a loud,
7103
+ // durable retry episode across pause and restart rather than being dropped.
7104
+ scheduler?.activateFailureAlertDelivery();
7094
7105
  // ── Coherence Journal × Telegram emergency-stop seam (COHERENCE-JOURNAL §3.3)
7095
7106
  // The adapter's sentinel emergency-stop path clears a topic's autonomous job
7096
7107
  // via stopAutonomousTopic but holds no StateManager, so it cannot reach the
@@ -7299,6 +7310,11 @@ export async function startServer(options) {
7299
7310
  });
7300
7311
  }
7301
7312
  }
7313
+ // TopicMemory becomes usable only after open() completes. Hand it to the
7314
+ // scheduler here instead of attempting the handoff during adapter startup.
7315
+ if (scheduler && topicMemory?.isReady()) {
7316
+ scheduler.setTopicMemory(topicMemory);
7317
+ }
7302
7318
  // ── WhatsApp adapter initialization ──────────────────────────────
7303
7319
  let whatsappAdapter;
7304
7320
  let whatsappBusinessBackend;