switchroom 0.18.11 → 0.18.13

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 (150) hide show
  1. package/dist/agent-scheduler/index.js +37 -5
  2. package/dist/auth-broker/index.js +116 -78
  3. package/dist/cli/hindsight-mental-model-pretool.mjs +39 -0
  4. package/dist/cli/ms-365-write-pretool.mjs +31 -8
  5. package/dist/cli/notion-write-pretool.mjs +38 -6
  6. package/dist/cli/skill-validate-pretool.mjs +144 -2847
  7. package/dist/cli/switchroom.js +3529 -4543
  8. package/dist/cli/ui/index.html +163 -17
  9. package/dist/host-control/main.js +605 -2847
  10. package/dist/vault/approvals/kernel-server.js +120 -13
  11. package/dist/vault/broker/server.js +259 -157
  12. package/package.json +3 -4
  13. package/profiles/_base/start.sh.hbs +65 -0
  14. package/profiles/_shared/vault-protocol.md.hbs +3 -1
  15. package/profiles/coding/CLAUDE.md.hbs +1 -1
  16. package/profiles/default/CLAUDE.md.hbs +2 -2
  17. package/profiles/executive-assistant/CLAUDE.md.hbs +1 -1
  18. package/profiles/health-coach/CLAUDE.md.hbs +1 -1
  19. package/telegram-plugin/bridge/bridge.ts +37 -0
  20. package/telegram-plugin/bridge/inbound-dedup.ts +101 -0
  21. package/telegram-plugin/dist/bridge/bridge.js +122 -4
  22. package/telegram-plugin/dist/gateway/gateway.js +4213 -3288
  23. package/telegram-plugin/dist/server.js +139 -5
  24. package/telegram-plugin/flood-circuit-breaker.ts +493 -21
  25. package/telegram-plugin/format.ts +19 -0
  26. package/telegram-plugin/gateway/approval-hold.ts +602 -0
  27. package/telegram-plugin/gateway/auth-command.ts +92 -2
  28. package/telegram-plugin/gateway/auth-loopback-relay.ts +670 -0
  29. package/telegram-plugin/gateway/boot-card.ts +12 -5
  30. package/telegram-plugin/gateway/callback-query-handlers.ts +88 -1
  31. package/telegram-plugin/gateway/config-approval-handler.ts +6 -1
  32. package/telegram-plugin/gateway/disconnect-flush.ts +19 -0
  33. package/telegram-plugin/gateway/dm-pin-sweep.test.ts +251 -0
  34. package/telegram-plugin/gateway/dm-pin-sweep.ts +178 -0
  35. package/telegram-plugin/gateway/gateway.ts +1695 -230
  36. package/telegram-plugin/gateway/hostd-dispatch.ts +23 -0
  37. package/telegram-plugin/gateway/idle-clear.ts +90 -6
  38. package/telegram-plugin/gateway/inbound-delivery-machine-shadow.ts +26 -5
  39. package/telegram-plugin/gateway/inject-handler.ts +8 -0
  40. package/telegram-plugin/gateway/ipc-protocol.ts +46 -3
  41. package/telegram-plugin/gateway/ipc-server.ts +43 -0
  42. package/telegram-plugin/gateway/mental-model-propose-resolve.ts +145 -37
  43. package/telegram-plugin/gateway/model-command.ts +9 -3
  44. package/telegram-plugin/gateway/pending-session-command.ts +13 -1
  45. package/telegram-plugin/gateway/permission-ttl-sweep.ts +66 -0
  46. package/telegram-plugin/gateway/pre-approval-check.ts +74 -0
  47. package/telegram-plugin/gateway/queued-card-store.ts +217 -0
  48. package/telegram-plugin/gateway/session-model-file.ts +26 -1
  49. package/telegram-plugin/gateway/turn-end-gate-backstop.ts +59 -0
  50. package/telegram-plugin/gateway/turn-end-gate.ts +95 -0
  51. package/telegram-plugin/gateway/turn-typing-loop.ts +10 -2
  52. package/telegram-plugin/gateway/unhandled-rejection-policy.ts +13 -0
  53. package/telegram-plugin/history.ts +51 -0
  54. package/telegram-plugin/hooks/dispatch-claim-scan.mjs +259 -0
  55. package/telegram-plugin/hooks/dispatch-claim-stop.mjs +129 -0
  56. package/telegram-plugin/hooks/hooks.json +9 -0
  57. package/telegram-plugin/inline-keyboard-callbacks.ts +303 -2
  58. package/telegram-plugin/model-unavailable.ts +41 -11
  59. package/telegram-plugin/operator-events.ts +23 -0
  60. package/telegram-plugin/outbound-field-redact.ts +69 -0
  61. package/telegram-plugin/package.json +0 -1
  62. package/telegram-plugin/permission-rule.ts +1 -0
  63. package/telegram-plugin/permission-title.ts +1 -0
  64. package/telegram-plugin/render/render.ts +32 -14
  65. package/telegram-plugin/retry-api-call.ts +212 -2
  66. package/telegram-plugin/scoped-approval.ts +11 -2
  67. package/telegram-plugin/secret-detect/chunker.ts +18 -4
  68. package/telegram-plugin/secret-detect/index.ts +12 -56
  69. package/telegram-plugin/send-gate-degraded.test.ts +574 -0
  70. package/telegram-plugin/send-gate-observability.test.ts +470 -0
  71. package/telegram-plugin/send-gate-observability.ts +355 -0
  72. package/telegram-plugin/send-gate.test.ts +717 -0
  73. package/telegram-plugin/send-gate.ts +1056 -0
  74. package/telegram-plugin/session-tail.ts +82 -7
  75. package/telegram-plugin/shared/bot-runtime.ts +17 -5
  76. package/telegram-plugin/shared/gw-trace-gate.ts +105 -0
  77. package/telegram-plugin/status-pin-driver.ts +52 -7
  78. package/telegram-plugin/status-pin.ts +81 -0
  79. package/telegram-plugin/subagent-watcher.ts +173 -18
  80. package/telegram-plugin/tests/activity-card-wiring.test.ts +18 -5
  81. package/telegram-plugin/tests/approval-hold-harness.ts +425 -0
  82. package/telegram-plugin/tests/approval-hold-outcome.test.ts +327 -0
  83. package/telegram-plugin/tests/approval-hold-record.test.ts +531 -0
  84. package/telegram-plugin/tests/approval-hold-redeliver.test.ts +602 -0
  85. package/telegram-plugin/tests/auth-loopback-relay.test.ts +533 -0
  86. package/telegram-plugin/tests/boot-card-flood-suppress.test.ts +53 -7
  87. package/telegram-plugin/tests/busy-key-reaper.test.ts +1 -0
  88. package/telegram-plugin/tests/callback-query-handlers.test.ts +65 -0
  89. package/telegram-plugin/tests/dispatch-claim-scan.test.ts +250 -0
  90. package/telegram-plugin/tests/flood-breaker-blindness.test.ts +213 -0
  91. package/telegram-plugin/tests/flood-windows-persistence.test.ts +224 -0
  92. package/telegram-plugin/tests/gateway-boot-marker-clear.test.ts +3 -3
  93. package/telegram-plugin/tests/gateway-disconnect-flush.test.ts +29 -1
  94. package/telegram-plugin/tests/gateway-loopback-paste-redact.test.ts +66 -0
  95. package/telegram-plugin/tests/gateway-outbound-redact.test.ts +57 -0
  96. package/telegram-plugin/tests/gw-trace-gate.test.ts +105 -0
  97. package/telegram-plugin/tests/history.test.ts +115 -0
  98. package/telegram-plugin/tests/idle-clear.test.ts +233 -3
  99. package/telegram-plugin/tests/inbound-dedup.test.ts +93 -0
  100. package/telegram-plugin/tests/inbound-message-types.test.ts +5 -1
  101. package/telegram-plugin/tests/inline-keyboard-callbacks.test.ts +448 -0
  102. package/telegram-plugin/tests/ipc-server-check-pre-approved.test.ts +194 -0
  103. package/telegram-plugin/tests/mental-model-propose-resolve.test.ts +123 -0
  104. package/telegram-plugin/tests/missed-approvals-wiring.test.ts +1 -1
  105. package/telegram-plugin/tests/model-command.test.ts +14 -0
  106. package/telegram-plugin/tests/operator-events-session-tail.test.ts +74 -0
  107. package/telegram-plugin/tests/outbound-field-redact.test.ts +107 -0
  108. package/telegram-plugin/tests/pending-session-command.test.ts +21 -0
  109. package/telegram-plugin/tests/permission-card-routing.test.ts +30 -5
  110. package/telegram-plugin/tests/permission-no-repeat-wiring.test.ts +8 -7
  111. package/telegram-plugin/tests/permission-rearm-wiring.test.ts +1 -1
  112. package/telegram-plugin/tests/pre-approval-check.test.ts +148 -0
  113. package/telegram-plugin/tests/queued-card-store.test.ts +232 -0
  114. package/telegram-plugin/tests/reaction-flush-turn-gated.test.ts +100 -0
  115. package/telegram-plugin/tests/reaction-gate-routing.test.ts +173 -0
  116. package/telegram-plugin/tests/render/render.test.ts +88 -0
  117. package/telegram-plugin/tests/retry-api-call.test.ts +398 -0
  118. package/telegram-plugin/tests/scoped-approval.test.ts +27 -0
  119. package/telegram-plugin/tests/secret-detect-chunk-overlap.test.ts +65 -0
  120. package/telegram-plugin/tests/secret-detect-oauth-code.test.ts +5 -4
  121. package/telegram-plugin/tests/session-model-file.test.ts +50 -0
  122. package/telegram-plugin/tests/session-tail-sidecar-reap.test.ts +268 -0
  123. package/telegram-plugin/tests/status-pin-boot-recovery.test.ts +35 -14
  124. package/telegram-plugin/tests/status-pin.test.ts +275 -1
  125. package/telegram-plugin/tests/subagent-watcher-deferral-log-ratelimit.test.ts +316 -0
  126. package/telegram-plugin/tests/subagent-watcher-fd-leak.test.ts +275 -0
  127. package/telegram-plugin/tests/turn-end-gate-backstop.test.ts +92 -0
  128. package/telegram-plugin/tests/turn-end-gate.test.ts +137 -0
  129. package/telegram-plugin/tests/typing-emitter.test.ts +586 -0
  130. package/telegram-plugin/tests/unhandled-rejection-policy.test.ts +20 -0
  131. package/telegram-plugin/tests/worktree-watch-cwds.test.ts +215 -1
  132. package/telegram-plugin/typing-emitter.ts +224 -0
  133. package/telegram-plugin/uat/scenarios/jtbd-feel-like-a-colleague-dm.test.ts +136 -0
  134. package/telegram-plugin/welcome-text.ts +42 -0
  135. package/telegram-plugin/worktree-watch-cwds.ts +194 -5
  136. package/vendor/hindsight-memory/scripts/drain_pending.py +22 -6
  137. package/vendor/hindsight-memory/scripts/lib/client.py +12 -5
  138. package/vendor/hindsight-memory/scripts/lib/directives.py +38 -3
  139. package/vendor/hindsight-memory/scripts/lib/pending.py +36 -9
  140. package/vendor/hindsight-memory/scripts/session_end.py +14 -3
  141. package/vendor/hindsight-memory/scripts/session_start.py +21 -0
  142. package/vendor/hindsight-memory/scripts/tests/test_directives.py +38 -0
  143. package/vendor/hindsight-memory/tests/test_drain_pending.py +68 -0
  144. package/vendor/hindsight-memory/tests/test_pending.py +44 -0
  145. package/vendor/hindsight-memory/tests/test_session_end_pending.py +38 -0
  146. package/vendor/hindsight-memory/tests/test_session_start_drain.py +155 -0
  147. package/telegram-plugin/channel-envelope-safety.test.ts +0 -56
  148. package/telegram-plugin/channel-envelope-safety.ts +0 -56
  149. package/telegram-plugin/secret-detect/secretlint-source.ts +0 -95
  150. package/telegram-plugin/tests/secret-detect-secretlint.test.ts +0 -105
@@ -46,6 +46,17 @@ export type ParsedAuthCommand =
46
46
  | { kind: 'rotate' }
47
47
  | { kind: 'add'; label: string }
48
48
  | { kind: 'cancel' }
49
+ | {
50
+ kind: 'provider-add'
51
+ provider: 'google' | 'microsoft'
52
+ email: string
53
+ replace: boolean
54
+ /** Google `--write` (Drive write scope). */
55
+ write: boolean
56
+ /** Microsoft `--org-mode`. */
57
+ orgMode: boolean
58
+ }
59
+ | { kind: 'provider-cancel'; provider: 'google' | 'microsoft' }
49
60
  | { kind: 'rm-prompt'; label: string }
50
61
  | { kind: 'rm-confirmed'; label: string }
51
62
  | { kind: 'refresh'; label?: string }
@@ -147,6 +158,9 @@ export function parseAuthCommand(text: string): ParsedAuthCommand | null {
147
158
  }
148
159
  case 'cancel':
149
160
  return { kind: 'cancel' }
161
+ case 'google':
162
+ case 'microsoft':
163
+ return parseProviderVerb(verb, parts.slice(1))
150
164
  case 'rm': {
151
165
  const label = parts[1]
152
166
  if (!label) return { kind: 'help', reason: 'Usage: /auth rm <label> [confirm]' }
@@ -206,6 +220,69 @@ export function parseAuthCommand(text: string): ParsedAuthCommand | null {
206
220
  }
207
221
  }
208
222
 
223
+ /**
224
+ * Parse `/auth google …` and `/auth microsoft …` — the Telegram-native OAuth
225
+ * loopback relay verbs (issue #2582). Only `add <email>` and `cancel` are
226
+ * wired; anything else is a help-with-reason so the operator sees the shape.
227
+ *
228
+ * Flags mirror the CLI:
229
+ * google: `add <email> [--replace] [--write]`
230
+ * microsoft: `add <email> [--replace] [--org-mode]`
231
+ */
232
+ export function parseProviderVerb(
233
+ provider: 'google' | 'microsoft',
234
+ rest: string[],
235
+ ): ParsedAuthCommand {
236
+ const sub = (rest[0] ?? '').toLowerCase()
237
+ if (sub === 'cancel') {
238
+ return { kind: 'provider-cancel', provider }
239
+ }
240
+ if (sub !== 'add') {
241
+ const usage =
242
+ provider === 'google'
243
+ ? 'Usage: /auth google add <email> [--replace] [--write]'
244
+ : 'Usage: /auth microsoft add <email> [--replace] [--org-mode]'
245
+ return {
246
+ kind: 'help',
247
+ reason: `Unknown \`${provider}\` subcommand: \`${codeSpanSafe(sub || '(none)')}\`. ${usage}`,
248
+ }
249
+ }
250
+ // Split positional email from `--flag` tokens.
251
+ const args = rest.slice(1)
252
+ const flags = new Set(args.filter((a) => a.startsWith('--')).map((a) => a.toLowerCase()))
253
+ const positional = args.filter((a) => !a.startsWith('--'))
254
+ const email = positional[0]
255
+ if (!email) {
256
+ const usage =
257
+ provider === 'google'
258
+ ? 'Usage: /auth google add <email> [--replace] [--write]'
259
+ : 'Usage: /auth microsoft add <email> [--replace] [--org-mode]'
260
+ return { kind: 'help', reason: usage }
261
+ }
262
+ const emailErr = validateAuthAddLabel(email)
263
+ if (emailErr) return { kind: 'help', reason: emailErr }
264
+ // Reject unknown flags so a typo (`--replaced`) isn't silently dropped.
265
+ const allowed = provider === 'google'
266
+ ? new Set(['--replace', '--write'])
267
+ : new Set(['--replace', '--org-mode'])
268
+ for (const f of flags) {
269
+ if (!allowed.has(f)) {
270
+ return {
271
+ kind: 'help',
272
+ reason: `Unknown flag \`${codeSpanSafe(f)}\` for \`/auth ${provider} add\`.`,
273
+ }
274
+ }
275
+ }
276
+ return {
277
+ kind: 'provider-add',
278
+ provider,
279
+ email,
280
+ replace: flags.has('--replace'),
281
+ write: provider === 'google' && flags.has('--write'),
282
+ orgMode: provider === 'microsoft' && flags.has('--org-mode'),
283
+ }
284
+ }
285
+
209
286
  // ─── Handler ───────────────────────────────────────────────────────────────
210
287
 
211
288
  /**
@@ -359,8 +436,10 @@ export async function handleAuthCommand(
359
436
  ` \`/auth list\` — alias of \`/auth show\`\n` +
360
437
  ` \`/auth use <label>\` — admin: swap the fleet to <label>\n` +
361
438
  ` \`/auth rotate\` — admin: cycle to next non-exhausted fallback\n` +
362
- ` \`/auth add <label>\` — admin: OAuth-add a new account from chat\n` +
363
- ` \`/auth cancel\`abort an \`/auth add\` in progress\n` +
439
+ ` \`/auth add <label>\` — admin: OAuth-add a new Anthropic account from chat\n` +
440
+ ` \`/auth google add <email>\` admin: Telegram-native Google account add/re-auth\n` +
441
+ ` \`/auth microsoft add <email>\` — admin: Telegram-native Microsoft account add/re-auth\n` +
442
+ ` \`/auth cancel\` — abort an \`/auth add\` or provider add in progress\n` +
364
443
  ` \`/auth rm <label>\` — admin: remove an account (two-step confirm)\n` +
365
444
  ` \`/auth refresh [<label>]\` — admin: force a refresh tick\n` +
366
445
  ` \`/auth agent override <agent> <label|clear>\` — admin: per-agent account override\n` +
@@ -472,6 +551,17 @@ export async function handleAuthCommand(
472
551
  }
473
552
  }
474
553
 
554
+ // `/auth google|microsoft add|cancel` are likewise gateway-routed (they
555
+ // drive the loopback-relay child-process lifecycle — see
556
+ // auth-loopback-relay.ts). Defensive: never reach here in production.
557
+ if (parsed.kind === 'provider-add' || parsed.kind === 'provider-cancel') {
558
+ return {
559
+ text:
560
+ `**/auth ${parsed.provider} not routed.** Internal error — gateway should dispatch this verb directly. Report this.`,
561
+ html: true,
562
+ }
563
+ }
564
+
475
565
  if (parsed.kind === 'use') {
476
566
  try {
477
567
  const result = await ctx.client.setActive(parsed.label)