switchroom 0.19.41 → 0.19.43

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 (90) hide show
  1. package/dist/agent-scheduler/index.js +23 -3
  2. package/dist/auth-broker/index.js +54 -9
  3. package/dist/cli/notion-write-pretool.mjs +23 -3
  4. package/dist/cli/switchroom.js +1956 -900
  5. package/dist/host-control/main.js +227 -30
  6. package/dist/vault/approvals/kernel-server.js +54 -9
  7. package/dist/vault/broker/server.js +54 -9
  8. package/package.json +3 -3
  9. package/profiles/_base/start.sh.hbs +82 -4
  10. package/telegram-plugin/bridge/bridge.ts +1 -1
  11. package/telegram-plugin/card-layout.ts +63 -1
  12. package/telegram-plugin/dist/bridge/bridge.js +4 -1
  13. package/telegram-plugin/dist/gateway/gateway.js +1318 -693
  14. package/telegram-plugin/dist/server.js +5 -2
  15. package/telegram-plugin/flood-429-ledger.ts +5 -3
  16. package/telegram-plugin/flood-circuit-breaker.ts +11 -3
  17. package/telegram-plugin/format.ts +223 -13
  18. package/telegram-plugin/gateway/approval-callback-consume-record.test.ts +132 -0
  19. package/telegram-plugin/gateway/boot-card.ts +7 -2
  20. package/telegram-plugin/gateway/flood-reply-queue.ts +5 -0
  21. package/telegram-plugin/gateway/gateway.ts +56 -58
  22. package/telegram-plugin/gateway/handback-orphan-recovery.ts +69 -0
  23. package/telegram-plugin/gateway/handback-preturn-signal.ts +170 -32
  24. package/telegram-plugin/gateway/ipc-protocol.ts +31 -3
  25. package/telegram-plugin/gateway/ipc-server.ts +13 -4
  26. package/telegram-plugin/gateway/liveness-wiring.ts +12 -0
  27. package/telegram-plugin/gateway/model-command.ts +21 -109
  28. package/telegram-plugin/gateway/obligation-store.ts +55 -0
  29. package/telegram-plugin/gateway/outbound-send-path.ts +127 -11
  30. package/telegram-plugin/gateway/outbox-sweep.ts +371 -61
  31. package/telegram-plugin/gateway/rollout-status-edit.ts +175 -0
  32. package/telegram-plugin/gateway/stream-render.ts +62 -0
  33. package/telegram-plugin/gateway/update-announce.ts +11 -4
  34. package/telegram-plugin/hooks/audience-classify.d.mts +50 -0
  35. package/telegram-plugin/hooks/audience-classify.mjs +364 -0
  36. package/telegram-plugin/hooks/silent-end-interrupt-stop.mjs +86 -3
  37. package/telegram-plugin/hooks/silent-end-scan.mjs +80 -4
  38. package/telegram-plugin/outbox.ts +103 -2
  39. package/telegram-plugin/render/rich-render.ts +10 -2
  40. package/telegram-plugin/reply-quote.ts +150 -0
  41. package/telegram-plugin/retry-api-call.ts +254 -11
  42. package/telegram-plugin/shared/bot-runtime.ts +69 -34
  43. package/telegram-plugin/shared/gw-trace-gate.ts +14 -2
  44. package/telegram-plugin/silent-end.ts +34 -2
  45. package/telegram-plugin/status-no-truncate.ts +31 -16
  46. package/telegram-plugin/stream-controller.ts +44 -9
  47. package/telegram-plugin/stream-reply-handler.ts +5 -3
  48. package/telegram-plugin/tests/boot-card-render.test.ts +2 -1
  49. package/telegram-plugin/tests/card-budget-never-overflows.test.ts +165 -0
  50. package/telegram-plugin/tests/card-hard-truncate-entity-safe.test.ts +153 -0
  51. package/telegram-plugin/tests/card-variants.golden.txt +9 -9
  52. package/telegram-plugin/tests/flood-reply-queue.test.ts +89 -4
  53. package/telegram-plugin/tests/format-consistency.test.ts +160 -14
  54. package/telegram-plugin/tests/framework-fallback-drains-parked.test.ts +134 -0
  55. package/telegram-plugin/tests/handback-orphan-recovery.test.ts +131 -0
  56. package/telegram-plugin/tests/handback-preturn-signal.test.ts +212 -17
  57. package/telegram-plugin/tests/helpers/liveness-wiring-fixture.ts +3 -0
  58. package/telegram-plugin/tests/nested-indent-idiom.test.ts +162 -0
  59. package/telegram-plugin/tests/nested-prefix-indent.test.ts +115 -0
  60. package/telegram-plugin/tests/no-robust-api-call-factory.test.ts +62 -0
  61. package/telegram-plugin/tests/obligation-store.test.ts +51 -0
  62. package/telegram-plugin/tests/outbox-audience-3865.test.ts +579 -0
  63. package/telegram-plugin/tests/outbox-provenance-4141.test.ts +1126 -0
  64. package/telegram-plugin/tests/outbox-sweep-single-flight.test.ts +138 -0
  65. package/telegram-plugin/tests/pinned-card-collapse.test.ts +12 -10
  66. package/telegram-plugin/tests/plain-fallback-4096-cap.test.ts +509 -0
  67. package/telegram-plugin/tests/reply-quote-wire.test.ts +433 -0
  68. package/telegram-plugin/tests/retry-grammy-http-error.test.ts +404 -0
  69. package/telegram-plugin/tests/rollout-narration-edit-socket.test.ts +170 -0
  70. package/telegram-plugin/tests/rollout-status-edit-retry-policy.test.ts +366 -0
  71. package/telegram-plugin/tests/rollout-status-edit.test.ts +140 -0
  72. package/telegram-plugin/tests/rollout-status-wiring.test.ts +40 -7
  73. package/telegram-plugin/tests/tg-post-logger-error-shape.test.ts +4 -0
  74. package/telegram-plugin/tests/tg-post-retry-attribution.test.ts +196 -0
  75. package/telegram-plugin/tests/tool-activity-summary.test.ts +23 -17
  76. package/telegram-plugin/tool-activity-summary.ts +58 -30
  77. package/telegram-plugin/uat/scenarios/jtbd-foreground-subagent-activity-dm.test.ts +3 -2
  78. package/vendor/hindsight-memory/CHANGELOG.md +28 -0
  79. package/vendor/hindsight-memory/docs/measurements/subagent-volume-gate-3994.md +84 -0
  80. package/vendor/hindsight-memory/scripts/backfill_transcripts.py +254 -40
  81. package/vendor/hindsight-memory/scripts/lib/content.py +11 -2
  82. package/vendor/hindsight-memory/scripts/recall.py +18 -3
  83. package/vendor/hindsight-memory/scripts/subagent_retain.py +59 -38
  84. package/vendor/hindsight-memory/scripts/tests/data/replay_volume_gate_3994.py +295 -0
  85. package/vendor/hindsight-memory/scripts/tests/test_backfill_from_logs.py +109 -0
  86. package/vendor/hindsight-memory/scripts/tests/test_overlap_tokens.py +135 -0
  87. package/vendor/hindsight-memory/scripts/tests/test_recall_no_lexical_gate.py +20 -23
  88. package/vendor/hindsight-memory/scripts/tests/test_recall_query_shaping.py +48 -0
  89. package/vendor/hindsight-memory/scripts/tests/test_subagent_retain.py +94 -1
  90. package/vendor/hindsight-memory/scripts/tests/test_subagent_retain_learnings.py +98 -42
@@ -11116,6 +11116,7 @@ var init_schema = __esm(() => {
11116
11116
  auto_recall: exports_external.boolean().default(true).describe("Auto-search memories before each response"),
11117
11117
  file: exports_external.boolean().default(true).describe("Maintain a curated workspace MEMORY.md file (seeded once, " + "auto-loaded every turn). Set false for hindsight-only memory: " + "the file is not seeded or re-created, so once migrated into " + "Hindsight and deleted it stays gone. Recall + directives carry " + "the memory instead. Cascade: override (per-agent wins over default)."),
11118
11118
  isolation: exports_external.enum(["default", "strict"]).default("default").describe("strict = never shared cross-agent, default = eligible for reflect"),
11119
+ profile: exports_external.string().optional().describe("Memory profile bank this agent's curated memory defaults key off — " + "the built-in disposition + observations_mission in PROFILE_MEMORY_DEFAULTS. " + "Decouples the memory profile from `extends` (the filesystem persona " + "profile), so an agent on `extends: default` can opt into the `coding` " + "memory bundle via `memory.profile: coding` without inheriting the coding " + "persona. Resolution: memory.profile → extends → DEFAULT_PROFILE (see " + "resolveMemoryProfile). Unset ⇒ byte-identical to keying off `extends`."),
11119
11120
  bank_mission: exports_external.string().optional().describe("Bank-level mission statement used during recall to contextualize " + "results. NOTE: this is an alias for the Hindsight engine's " + "`reflect_mission` field (verified live: switchroom's bank_mission " + "lands in `config.reflect_mission`). Prefer `reflect_mission` going " + "forward; `bank_mission` is retained for back-compat. If both are " + "set, `reflect_mission` wins. Cascade: override."),
11120
11121
  reflect_mission: exports_external.string().optional().describe("Mission/context steering Hindsight Reflect operations (the bank's " + "'who am I / what matters' framing applied during recall). The " + "engine-accurate name for what `bank_mission` sets. Cascade: override."),
11121
11122
  retain_mission: exports_external.string().optional().describe("Instructions for the fact extraction LLM during retain. Cascade: override."),
@@ -11409,11 +11410,13 @@ var init_schema = __esm(() => {
11409
11410
  provider: exports_external.string().min(1).optional().describe("Hindsight LLM provider (upstream `HINDSIGHT_API_LLM_PROVIDER`). " + "Defaults to `claude-code` (subscription-honest, broker-fed OAuth). " + "Any litellm-routable provider the upstream image supports is valid. " + "Serves as the GLOBAL default for every op absent a per-op override."),
11410
11411
  model: exports_external.string().min(1).optional().describe("Hindsight LLM model (upstream `HINDSIGHT_API_LLM_MODEL`). Defaults " + "to HINDSIGHT_DEFAULT_MODEL. Any model your LiteLLM proxy can route " + "is valid, e.g. `openrouter/z-ai/glm-5.2` when routing through the " + "fleet proxy. With provider=claude-code this value is ALSO exported " + "as `ANTHROPIC_MODEL` to the claude subprocess. Serves as the GLOBAL " + "default for every op absent a per-op override."),
11411
11412
  context_window: exports_external.number().int().positive().optional().describe("GLOBAL context window (tokens) of the backend serving hindsight's " + "LLM ops — the declared size switchroom derives every token budget " + "from. Set this to the real window of whatever you point " + "`hindsight.llm` at (e.g. 32768 for a llama.cpp slot launched with " + "`-c 65536 -np 2`, 131072 for a large-window OpenRouter model). " + "Absent → a per-provider default: 200000 for `claude-code`, a " + "conservative 32768 for everything else. Overflowing a local " + "backend's window does NOT error — llama.cpp context-shift silently " + "drops the system prompt and the model answers conversationally " + "with HTTP 200 — so this value is what makes the failure " + "detectable at setup time instead of never."),
11413
+ base_url: exports_external.string().min(1).optional().describe("GLOBAL LLM base URL (upstream `HINDSIGHT_API_LLM_BASE_URL`). The " + "default endpoint every op inherits absent a per-op " + "`hindsight.llm.<op>.base_url`. Optional passthrough; unset → the " + "engine's provider default. When this points at host loopback the " + "hindsight container is forced onto host networking, same as a " + "per-op base URL, so the endpoint stays reachable (#3687)."),
11414
+ api_key: exports_external.string().min(1).optional().describe("GLOBAL LLM API key (upstream `HINDSIGHT_API_LLM_API_KEY`). Literal " + "or `vault:` reference. The default credential every op inherits " + "absent a per-op `hindsight.llm.<op>.api_key`; the engine reads it as " + "a plain env fallback. Optional passthrough (#3687)."),
11412
11415
  retain: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `retain` LLM op (memory ingestion). Emits " + "`HINDSIGHT_API_RETAIN_LLM_*`. Absent → uses the global model/provider."),
11413
11416
  reflect: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `reflect` LLM op (synthesis / mental-model " + "refresh). Emits `HINDSIGHT_API_REFLECT_LLM_*`. Absent → uses global."),
11414
11417
  consolidation: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `consolidation` LLM op (background memory " + "merge). Emits `HINDSIGHT_API_CONSOLIDATION_LLM_*`. Absent → global.")
11415
11418
  }).optional().describe("LLM knob for the hindsight container. The flat `provider`/`model` set " + "the global default (backward-compatible); optional `retain`/`reflect`/" + "`consolidation` blocks override individual ops. All fields optional; " + "unset fields fall back to the hard-coded defaults."),
11416
- env: exports_external.record(exports_external.union([exports_external.string(), exports_external.number(), exports_external.boolean()])).optional().describe("Operator overrides for switchroom's capability-gated Hindsight " + "performance defaults. Only the keys switchroom actually manages are " + "honoured (`HINDSIGHT_PERF_ENV_KEYS` in " + "src/setup/hindsight-perf-defaults.ts: RERANKER_LOCAL_FP16, " + "RERANKER_LOCAL_BATCH_SIZE, LLM_MAX_CONCURRENT, " + "RETAIN/CONSOLIDATION_LLM_MAX_CONCURRENT, LLM_STRICT_SCHEMA, " + "LLM_MAX_RETRIES, CONSOLIDATION_LLM_PARALLELISM, " + "MAX_OBSERVATIONS_PER_SCOPE, " + "RECALL_MAX_CANDIDATES_PER_SOURCE, LINK_EXPANSION_PER_ENTITY_LIMIT, " + "LINK_EXPANSION_TIMEOUT, LLM_REASONING_EFFORT, " + "RERANKER_LOCAL_BUCKET_BATCHING, RERANKER_MAX_CANDIDATES, " + "RERANKER_LOCAL_MAX_CONCURRENT, RECALL_MAX_CONCURRENT, " + "REFLECT_WALL_TIMEOUT, WORKER_CONSOLIDATION_MAX_SLOTS, " + "WORKER_CONSOLIDATION_SLOT_LIMIT, " + "CONSOLIDATION_MAX_MEMORIES_PER_ROUND, RECENCY_DECAY_FUNCTION, " + "RECENCY_DECAY_HALFLIFE_DAYS — switchroom defaults recall's recency " + "curve to `exponential` with a 30-day half-life so a fact retained " + "today outranks a stale one, instead of upstream's near-flat " + "linear/365-day window), the override-only keys " + "switchroom manages but ships NO default for " + "(`HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS`: " + "HINDSIGHT_API_WORKER_CONSOLIDATION_BANK_PRIORITY — a per-deployment " + "`bank-pattern:priority,...` map; unset means upstream's flat " + "created_at FIFO across banks; and " + "HINDSIGHT_CE_DECISIVE_RELATIVE_GAP — the rollback knob for " + "switchroom's CE-saturation damping patch, a float; >= ~0.65 backs the " + "damping out entirely, unset means the patch's own derived gap; and " + "HINDSIGHT_API_RECENCY_DECAY_LINEAR_WINDOW_DAYS — only read when the " + "decay function is `linear`, so switchroom ships no default for it but " + "still honours an operator who flips the function back; and " + "HINDSIGHT_API_WORKER_MAX_SLOTS — the worker poller's TOTAL in-flight " + "task budget, the pool WORKER_CONSOLIDATION_MAX_SLOTS reserves out of; " + "unset means upstream's own default; and " + "HINDSIGHT_API_WORKER_RETAIN_MAX_SLOTS — the reserved slot FLOOR for the " + "retain (memory write) lane, carved from that same total; unset means " + "upstream's own 0, i.e. no floor and retain competes for the shared " + "pool), plus the " + "embedded-PostgreSQL (pg0) sizing keys switchroom manages in " + "src/setup/hindsight-pg-defaults.ts (`HINDSIGHT_PG_ENV_KEYS`: " + "SWITCHROOM_HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE, " + "SWITCHROOM_HINDSIGHT_PG_SHARED_BUFFERS — a postgres size string such " + "as `4GB`, or the sentinel `off` to leave pg0's own default for that " + "one knob). A value set here " + "REPLACES switchroom's default and is emitted even when the gating " + "capability is absent, so an operator can always force a knob. Other " + "`HINDSIGHT_API_*` keys are deliberately IGNORED — a blanket " + "passthrough would collide with the vars startHindsight() derives " + "itself (HINDSIGHT_API_PORT, the retain token/deadline budget).")
11419
+ env: exports_external.record(exports_external.union([exports_external.string(), exports_external.number(), exports_external.boolean()])).optional().describe("Operator overrides for switchroom's capability-gated Hindsight " + "performance defaults. Only the keys switchroom actually manages are " + "honoured (`HINDSIGHT_PERF_ENV_KEYS` in " + "src/setup/hindsight-perf-defaults.ts: RERANKER_LOCAL_FP16, " + "RERANKER_LOCAL_BATCH_SIZE, LLM_MAX_CONCURRENT, " + "RETAIN/CONSOLIDATION_LLM_MAX_CONCURRENT, LLM_STRICT_SCHEMA, " + "LLM_MAX_RETRIES, CONSOLIDATION_LLM_PARALLELISM, " + "MAX_OBSERVATIONS_PER_SCOPE, " + "RECALL_MAX_CANDIDATES_PER_SOURCE, LINK_EXPANSION_PER_ENTITY_LIMIT, " + "LINK_EXPANSION_TIMEOUT, LLM_REASONING_EFFORT, " + "RERANKER_LOCAL_BUCKET_BATCHING, RERANKER_MAX_CANDIDATES, " + "RERANKER_LOCAL_MAX_CONCURRENT, RECALL_MAX_CONCURRENT, " + "REFLECT_WALL_TIMEOUT, WORKER_CONSOLIDATION_RESERVED_SLOTS, " + "WORKER_CONSOLIDATION_SLOT_LIMIT, " + "CONSOLIDATION_MAX_MEMORIES_PER_ROUND, GRAPH_SEED_MIN_SIMILARITY, " + "LLM_SUPPORTS_MAX_ITEMS, RECENCY_DECAY_FUNCTION, " + "RECENCY_DECAY_HALFLIFE_DAYS — switchroom defaults recall's recency " + "curve to `exponential` with a 30-day half-life so a fact retained " + "today outranks a stale one, instead of upstream's near-flat " + "linear/365-day window), the override-only keys " + "switchroom manages but ships NO default for " + "(`HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS`: " + "HINDSIGHT_API_WORKER_CONSOLIDATION_BANK_PRIORITY — a per-deployment " + "`bank-pattern:priority,...` map; unset means upstream's flat " + "created_at FIFO across banks; and " + "HINDSIGHT_CE_DECISIVE_RELATIVE_GAP — the rollback knob for " + "switchroom's CE-saturation damping patch, a float; >= ~0.65 backs the " + "damping out entirely, unset means the patch's own derived gap; and " + "HINDSIGHT_API_RECENCY_DECAY_LINEAR_WINDOW_DAYS — only read when the " + "decay function is `linear`, so switchroom ships no default for it but " + "still honours an operator who flips the function back; and " + "HINDSIGHT_API_WORKER_MAX_SLOTS — the worker poller's TOTAL in-flight " + "task budget, the pool WORKER_CONSOLIDATION_RESERVED_SLOTS reserves out of; " + "unset means upstream's own default; and " + "HINDSIGHT_API_WORKER_RETAIN_RESERVED_SLOTS — the reserved slot FLOOR for the " + "retain (memory write) lane, carved from that same total; unset means " + "upstream's own 0, i.e. no floor and retain competes for the shared " + "pool; and " + "the pre-0.8.6 name HINDSIGHT_API_WORKER_<TYPE>_MAX_SLOTS is still " + "accepted for every operation type and normalised to " + "..._RESERVED_SLOTS on the way in, because setting both names for " + "one type is a hard boot failure in the engine and switchroom " + "therefore emits only the canonical name; and " + "HINDSIGHT_API_SEMANTIC_MIN_SIMILARITY — the cosine-similarity floor a " + "candidate must reach to be returned by the semantic retrieval arm at " + "all (0..1); unset means upstream's own 0.3, and where it should sit " + "depends on the bank's embedding model and phrasing diversity, so " + "switchroom ships no opinion; and " + "HINDSIGHT_MCP_RECALL_BUDGET_MODE — the rollback knob for switchroom's " + "mcp-recall-token-budget image patch; `legacy` restores upstream's " + "exact pre-patch recall returns, anything else or unset is the " + "honest-envelope mode; and " + "HINDSIGHT_API_LLM_TEMPERATURE_REFLECT — upstream's own per-op reflect " + "temperature knob, made live by switchroom's reflect-temperature image " + "patch; a float, or `none` to omit the kwarg (provider default, " + "upstream's accidental pre-patch behaviour); unset means the image's " + "baked default 0.1), plus the " + "embedded-PostgreSQL (pg0) sizing keys switchroom manages in " + "src/setup/hindsight-pg-defaults.ts (`HINDSIGHT_PG_ENV_KEYS`: " + "SWITCHROOM_HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE, " + "SWITCHROOM_HINDSIGHT_PG_SHARED_BUFFERS — a postgres size string such " + "as `4GB`, or the sentinel `off` to leave pg0's own default for that " + "one knob). A value set here " + "REPLACES switchroom's default and is emitted even when the gating " + "capability is absent, so an operator can always force a knob. Other " + "`HINDSIGHT_API_*` keys are deliberately IGNORED — a blanket " + "passthrough would collide with the vars startHindsight() derives " + "itself (HINDSIGHT_API_PORT, the retain token/deadline budget).")
11417
11420
  });
11418
11421
  MicrosoftWorkspaceConfigSchema = exports_external.object({
11419
11422
  microsoft_client_id: exports_external.string().min(1).optional().describe("Microsoft OAuth application (client) ID from Entra portal " + "(literal string or vault reference e.g. " + "'vault:microsoft-oauth-client-id'). OPTIONAL — omit it to use " + "switchroom's shipped default Microsoft app (zero-config). " + "Set it only to bring your own Entra app (BYO)."),
@@ -11545,6 +11548,7 @@ var init_schema = __esm(() => {
11545
11548
  auto_recall: exports_external.boolean().optional(),
11546
11549
  file: exports_external.boolean().optional(),
11547
11550
  isolation: exports_external.enum(["default", "strict"]).optional(),
11551
+ profile: exports_external.string().optional(),
11548
11552
  directive_capture_nudge: exports_external.boolean().optional(),
11549
11553
  observation_scopes: ObservationScopesSchema,
11550
11554
  observation_scope_strategy: ObservationScopeStrategySchema,
@@ -11586,7 +11590,23 @@ var init_schema = __esm(() => {
11586
11590
  max_query_chars: exports_external.number().int().min(1).optional(),
11587
11591
  parallel: exports_external.boolean().optional(),
11588
11592
  additional_banks: exports_external.array(exports_external.string()).optional(),
11589
- sender_banks: exports_external.record(exports_external.string(), exports_external.string()).optional()
11593
+ sender_banks: exports_external.record(exports_external.string(), exports_external.string()).optional(),
11594
+ types: exports_external.array(exports_external.string()).optional(),
11595
+ skip_trivial: exports_external.boolean().optional(),
11596
+ topic_filter_mode: exports_external.enum(["soft-preamble", "hard-filter"]).optional()
11597
+ }).optional(),
11598
+ retain: exports_external.object({
11599
+ every_n_turns: exports_external.number().int().min(1).optional(),
11600
+ overlap_turns: exports_external.number().int().min(0).optional()
11601
+ }).optional(),
11602
+ bank_mission: exports_external.string().optional(),
11603
+ reflect_mission: exports_external.string().optional(),
11604
+ retain_mission: exports_external.string().optional(),
11605
+ observations_mission: exports_external.string().optional(),
11606
+ disposition: exports_external.object({
11607
+ skepticism: exports_external.number().int().min(1).max(5).optional(),
11608
+ literalism: exports_external.number().int().min(1).max(5).optional(),
11609
+ empathy: exports_external.number().int().min(1).max(5).optional()
11590
11610
  }).optional()
11591
11611
  }).optional(),
11592
11612
  schedule: exports_external.array(ScheduleEntrySchema).optional(),
@@ -18753,11 +18773,11 @@ var init_protocol = __esm(() => {
18753
18773
  OkRevokeGrantResponseSchema,
18754
18774
  OkApprovalRequestResponseSchema,
18755
18775
  OkApprovalLookupResponseSchema,
18776
+ OkApprovalConsumeRecordResponseSchema,
18756
18777
  OkApprovalConsumeResponseSchema,
18757
18778
  OkApprovalRevokeResponseSchema,
18758
18779
  OkApprovalListResponseSchema,
18759
18780
  OkApprovalRecordResponseSchema,
18760
- OkApprovalConsumeRecordResponseSchema,
18761
18781
  ErrorResponseSchema
18762
18782
  ]);
18763
18783
  });
@@ -21322,7 +21342,7 @@ function allocateAgentUid(name) {
21322
21342
  }
21323
21343
 
21324
21344
  // src/build-info.ts
21325
- var VERSION = "0.19.41";
21345
+ var VERSION = "0.19.43";
21326
21346
 
21327
21347
  // src/setup/hindsight-recall-tunables.ts
21328
21348
  var RECALL_DEADLINE_HEADROOM_SECONDS = 2;
@@ -21498,7 +21518,9 @@ var HINDSIGHT_DEFAULT_RECALL_MAX_CONCURRENT = 8;
21498
21518
  var HINDSIGHT_DEFAULT_REFLECT_WALL_TIMEOUT_S = 600;
21499
21519
  var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_MEMORIES_PER_ROUND = 250;
21500
21520
  var HINDSIGHT_DEFAULT_CONSOLIDATION_SLOT_LIMIT = 6;
21501
- var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_SLOTS = 1;
21521
+ var HINDSIGHT_DEFAULT_CONSOLIDATION_RESERVED_SLOTS = 1;
21522
+ var HINDSIGHT_DEFAULT_GRAPH_SEED_MIN_SIMILARITY = 0.3;
21523
+ var HINDSIGHT_DEFAULT_LLM_SUPPORTS_MAX_ITEMS = "false";
21502
21524
  var HINDSIGHT_DEFAULT_RECENCY_DECAY_FUNCTION = "exponential";
21503
21525
  var HINDSIGHT_DEFAULT_RECENCY_DECAY_HALFLIFE_DAYS = 30;
21504
21526
  var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
@@ -21544,8 +21566,8 @@ var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
21544
21566
  String(HINDSIGHT_DEFAULT_REFLECT_WALL_TIMEOUT_S)
21545
21567
  ],
21546
21568
  [
21547
- "HINDSIGHT_API_WORKER_CONSOLIDATION_MAX_SLOTS",
21548
- String(HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_SLOTS)
21569
+ "HINDSIGHT_API_WORKER_CONSOLIDATION_RESERVED_SLOTS",
21570
+ String(HINDSIGHT_DEFAULT_CONSOLIDATION_RESERVED_SLOTS)
21549
21571
  ],
21550
21572
  [
21551
21573
  "HINDSIGHT_API_WORKER_CONSOLIDATION_SLOT_LIMIT",
@@ -21562,6 +21584,10 @@ var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
21562
21584
  [
21563
21585
  "HINDSIGHT_API_RECENCY_DECAY_HALFLIFE_DAYS",
21564
21586
  String(HINDSIGHT_DEFAULT_RECENCY_DECAY_HALFLIFE_DAYS)
21587
+ ],
21588
+ [
21589
+ "HINDSIGHT_API_GRAPH_SEED_MIN_SIMILARITY",
21590
+ String(HINDSIGHT_DEFAULT_GRAPH_SEED_MIN_SIMILARITY)
21565
21591
  ]
21566
21592
  ];
21567
21593
  var HINDSIGHT_PERF_DEFAULTS_GPU = [
@@ -21582,22 +21608,41 @@ var HINDSIGHT_PERF_DEFAULTS_LOCAL_LLM = [
21582
21608
  String(HINDSIGHT_DEFAULT_CONSOLIDATION_LLM_MAX_CONCURRENT)
21583
21609
  ],
21584
21610
  ["HINDSIGHT_API_LLM_STRICT_SCHEMA", HINDSIGHT_DEFAULT_LLM_STRICT_SCHEMA],
21585
- ["HINDSIGHT_API_LLM_MAX_RETRIES", String(HINDSIGHT_DEFAULT_LLM_MAX_RETRIES)]
21611
+ ["HINDSIGHT_API_LLM_MAX_RETRIES", String(HINDSIGHT_DEFAULT_LLM_MAX_RETRIES)],
21612
+ ["HINDSIGHT_API_LLM_SUPPORTS_MAX_ITEMS", HINDSIGHT_DEFAULT_LLM_SUPPORTS_MAX_ITEMS]
21586
21613
  ];
21587
21614
  var HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS = new Set([
21588
21615
  "HINDSIGHT_API_WORKER_CONSOLIDATION_BANK_PRIORITY",
21589
21616
  "HINDSIGHT_CE_DECISIVE_RELATIVE_GAP",
21590
21617
  "HINDSIGHT_API_RECENCY_DECAY_LINEAR_WINDOW_DAYS",
21591
21618
  "HINDSIGHT_API_WORKER_MAX_SLOTS",
21592
- "HINDSIGHT_API_WORKER_RETAIN_MAX_SLOTS"
21619
+ "HINDSIGHT_API_WORKER_RETAIN_RESERVED_SLOTS",
21620
+ "HINDSIGHT_API_SEMANTIC_MIN_SIMILARITY",
21621
+ "HINDSIGHT_MCP_RECALL_BUDGET_MODE",
21622
+ "HINDSIGHT_API_LLM_TEMPERATURE_REFLECT",
21623
+ "HINDSIGHT_API_RETAIN_WALL_TIMEOUT"
21593
21624
  ]);
21625
+ var HINDSIGHT_WORKER_SLOT_TYPES = [
21626
+ "consolidation",
21627
+ "file_convert_retain",
21628
+ "graph_maintenance",
21629
+ "import_documents",
21630
+ "refresh_mental_model",
21631
+ "retain"
21632
+ ];
21633
+ var HINDSIGHT_WORKER_RESERVED_SLOT_ALIASES = new Map(HINDSIGHT_WORKER_SLOT_TYPES.map((type) => [
21634
+ `HINDSIGHT_API_WORKER_${type.toUpperCase()}_MAX_SLOTS`,
21635
+ `HINDSIGHT_API_WORKER_${type.toUpperCase()}_RESERVED_SLOTS`
21636
+ ]));
21594
21637
  var HINDSIGHT_PERF_ENV_KEYS = new Set([
21595
21638
  ...[
21596
21639
  ...HINDSIGHT_PERF_DEFAULTS_UNGATED,
21597
21640
  ...HINDSIGHT_PERF_DEFAULTS_GPU,
21598
21641
  ...HINDSIGHT_PERF_DEFAULTS_LOCAL_LLM
21599
21642
  ].map(([k]) => k),
21600
- ...HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS
21643
+ ...HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS,
21644
+ ...HINDSIGHT_WORKER_RESERVED_SLOT_ALIASES.keys(),
21645
+ ...HINDSIGHT_WORKER_RESERVED_SLOT_ALIASES.values()
21601
21646
  ]);
21602
21647
 
21603
21648
  // src/setup/hindsight-context-budget.ts
@@ -29523,6 +29568,17 @@ function deferredLines(target) {
29523
29568
  `- hostd template regen (only if the release changed hostd mounts/env) — \`switchroom hostd install --tag ${target}\``
29524
29569
  ];
29525
29570
  }
29571
+ function warningLines(warnings) {
29572
+ if (!warnings || warnings.length === 0)
29573
+ return [];
29574
+ const MAX_SHOWN = 8;
29575
+ const shown = warnings.slice(0, MAX_SHOWN);
29576
+ const lines = ["**Warnings:**", ...shown.map((w) => `- ⚠️ ${w}`)];
29577
+ if (warnings.length > MAX_SHOWN) {
29578
+ lines.push(`- …and ${warnings.length - MAX_SHOWN} more (see \`get_status\`).`);
29579
+ }
29580
+ return lines;
29581
+ }
29526
29582
  var MAX_RENDER_CHARS = 3800;
29527
29583
  function rolledList(rolled, compact) {
29528
29584
  if (rolled.length === 0)
@@ -29536,6 +29592,7 @@ function renderWith(s, compact) {
29536
29592
  const rolledCount = rolled.length;
29537
29593
  const checklist = checklistLines(s, compact);
29538
29594
  const singletons = singletonLines(s);
29595
+ const warnings = warningLines(s.warnings);
29539
29596
  const elapsedMs = s.elapsedMs ?? (s.startedAtMs !== undefined && s.nowMs !== undefined ? s.nowMs - s.startedAtMs : undefined);
29540
29597
  if (s.terminal === "completed") {
29541
29598
  const parts2 = [headerLine(s, "✅")];
@@ -29548,6 +29605,8 @@ function renderWith(s, compact) {
29548
29605
  parts2.push("", ...checklist);
29549
29606
  if (singletons.length > 0)
29550
29607
  parts2.push("", ...singletons);
29608
+ if (warnings.length > 0)
29609
+ parts2.push("", ...warnings);
29551
29610
  if (s.deferred !== false)
29552
29611
  parts2.push("", ...deferredLines(s.target));
29553
29612
  return parts2.join(`
@@ -29567,6 +29626,8 @@ function renderWith(s, compact) {
29567
29626
  parts2.push("", ...checklist);
29568
29627
  if (singletons.length > 0)
29569
29628
  parts2.push("", ...singletons);
29629
+ if (warnings.length > 0)
29630
+ parts2.push("", ...warnings);
29570
29631
  return parts2.join(`
29571
29632
  `);
29572
29633
  }
@@ -29582,6 +29643,8 @@ function renderWith(s, compact) {
29582
29643
  parts2.push("", ...checklist);
29583
29644
  if (singletons.length > 0)
29584
29645
  parts2.push("", ...singletons);
29646
+ if (warnings.length > 0)
29647
+ parts2.push("", ...warnings);
29585
29648
  return parts2.join(`
29586
29649
  `);
29587
29650
  }
@@ -31467,6 +31530,9 @@ ${output.recovery.stderr}` : "";
31467
31530
  if (parsed.drifted && parsed.drifted.length > 0) {
31468
31531
  entry.drifted = parsed.drifted;
31469
31532
  }
31533
+ if (parsed.warnings && parsed.warnings.length > 0) {
31534
+ entry.warnings = parsed.warnings;
31535
+ }
31470
31536
  if (parsed.got !== undefined)
31471
31537
  entry.got = parsed.got;
31472
31538
  if (parsed.timedOut)
@@ -31609,7 +31675,8 @@ ${pinNote}`.trim();
31609
31675
  ...entry.failed_step ? { failedStep: entry.failed_step } : {},
31610
31676
  ...entry.failed_agent ? { failedAgent: entry.failed_agent } : {},
31611
31677
  ...entry.got !== undefined ? { got: entry.got } : {},
31612
- ...entry.drifted && entry.drifted.length > 0 ? { drifted: entry.drifted } : {}
31678
+ ...entry.drifted && entry.drifted.length > 0 ? { drifted: entry.drifted } : {},
31679
+ ...entry.warnings && entry.warnings.length > 0 ? { warnings: entry.warnings } : {}
31613
31680
  });
31614
31681
  this.opts.rolloutRelay.postTerminal({
31615
31682
  requestId: entry.request_id,
@@ -31692,7 +31759,7 @@ ${pinNote}`.trim();
31692
31759
  };
31693
31760
  }
31694
31761
  statusEntryToResponse(request_id, entry) {
31695
- const rolloutPayload = entry.op === "rollout" && (entry.rolled !== undefined || entry.failed_step !== undefined || entry.failed_agent !== undefined || entry.current_phase !== undefined) ? JSON.stringify({
31762
+ const rolloutPayload = entry.op === "rollout" && (entry.rolled !== undefined || entry.failed_step !== undefined || entry.failed_agent !== undefined || entry.warnings !== undefined && entry.warnings.length > 0 || entry.current_phase !== undefined) ? JSON.stringify({
31696
31763
  rolled: entry.rolled ?? [],
31697
31764
  ...entry.current_phase ? { phase: entry.current_phase } : {},
31698
31765
  ...entry.phase_n !== undefined ? { n: entry.phase_n } : {},
@@ -31702,6 +31769,7 @@ ${pinNote}`.trim();
31702
31769
  ...entry.failed_agent ? { failedAgent: entry.failed_agent } : {},
31703
31770
  ...entry.got !== undefined ? { got: entry.got } : {},
31704
31771
  ...entry.drifted && entry.drifted.length > 0 ? { drifted: entry.drifted } : {},
31772
+ ...entry.warnings && entry.warnings.length > 0 ? { warnings: entry.warnings } : {},
31705
31773
  ...entry.pin ? { pin: entry.pin } : {},
31706
31774
  ...entry.prior_pin ? { prior_pin: entry.prior_pin } : {}
31707
31775
  }) : undefined;
@@ -32265,6 +32333,7 @@ class SocketRolloutRelay {
32265
32333
  // src/host-control/rollout-narration-relay.ts
32266
32334
  import { connect as connect4 } from "node:net";
32267
32335
  var DEFAULT_POST_REPLY_TIMEOUT_MS = 5000;
32336
+ var DEFAULT_EDIT_REPLY_TIMEOUT_MS = 5000;
32268
32337
 
32269
32338
  class SocketRolloutNarrationRelay {
32270
32339
  opts;
@@ -32362,18 +32431,40 @@ class SocketRolloutNarrationRelay {
32362
32431
  sockPath = this.opts.resolveGatewaySocket(args.agentName);
32363
32432
  } catch (e) {
32364
32433
  log(`narration edit resolveGatewaySocket threw: ${e.message}`);
32365
- return;
32434
+ return Promise.resolve({
32435
+ ok: false,
32436
+ gone: false,
32437
+ reason: `resolveGatewaySocket threw: ${e.message}`
32438
+ });
32366
32439
  }
32367
- if (sockPath === null)
32368
- return;
32369
- try {
32370
- const client2 = connect4({ path: sockPath });
32371
- client2.setTimeout(5000);
32372
- const done = () => {
32440
+ if (sockPath === null) {
32441
+ return Promise.resolve({
32442
+ ok: false,
32443
+ gone: false,
32444
+ reason: "no reachable gateway"
32445
+ });
32446
+ }
32447
+ return new Promise((resolve10) => {
32448
+ let settled = false;
32449
+ let client2;
32450
+ const finish = (outcome) => {
32451
+ if (settled)
32452
+ return;
32453
+ settled = true;
32373
32454
  try {
32374
32455
  client2.destroy();
32375
32456
  } catch {}
32457
+ resolve10(outcome);
32376
32458
  };
32459
+ try {
32460
+ client2 = connect4({ path: sockPath });
32461
+ } catch (e) {
32462
+ log(`narration edit connect threw: ${e.message}`);
32463
+ resolve10({ ok: false, gone: false, reason: e.message });
32464
+ return;
32465
+ }
32466
+ client2.setTimeout(this.opts.editReplyTimeoutMs ?? DEFAULT_EDIT_REPLY_TIMEOUT_MS);
32467
+ let buffer = "";
32377
32468
  client2.on("connect", () => {
32378
32469
  try {
32379
32470
  client2.write(JSON.stringify({
@@ -32384,21 +32475,46 @@ class SocketRolloutNarrationRelay {
32384
32475
  text: args.text
32385
32476
  }) + `
32386
32477
  `);
32387
- client2.end();
32388
32478
  } catch (e) {
32389
32479
  log(`narration edit write failed: ${e.message}`);
32390
- done();
32480
+ finish({ ok: false, gone: false, reason: e.message });
32481
+ }
32482
+ });
32483
+ client2.on("data", (chunk2) => {
32484
+ buffer += chunk2.toString("utf8");
32485
+ const lines = buffer.split(`
32486
+ `);
32487
+ buffer = lines.pop() ?? "";
32488
+ for (const line of lines) {
32489
+ if (!line.trim())
32490
+ continue;
32491
+ let obj;
32492
+ try {
32493
+ obj = JSON.parse(line);
32494
+ } catch {
32495
+ continue;
32496
+ }
32497
+ if (obj.type === "rollout_status_edited" && obj.requestId === args.requestId) {
32498
+ if (obj.ok === true) {
32499
+ finish({ ok: true });
32500
+ } else {
32501
+ finish({
32502
+ ok: false,
32503
+ gone: obj.gone === true,
32504
+ ...typeof obj.reason === "string" ? { reason: obj.reason } : {}
32505
+ });
32506
+ }
32507
+ return;
32508
+ }
32391
32509
  }
32392
32510
  });
32393
- client2.on("timeout", done);
32511
+ client2.on("timeout", () => finish({ ok: false, gone: false, reason: "edit reply timed out" }));
32394
32512
  client2.on("error", (e) => {
32395
32513
  log(`narration edit socket error: ${e.message}`);
32396
- done();
32514
+ finish({ ok: false, gone: false, reason: e.message });
32397
32515
  });
32398
- client2.on("close", () => {});
32399
- } catch (e) {
32400
- log(`narration edit connect threw: ${e.message}`);
32401
- }
32516
+ client2.on("close", () => finish({ ok: false, gone: false, reason: "no edit reply" }));
32517
+ });
32402
32518
  }
32403
32519
  }
32404
32520
 
@@ -32711,9 +32827,62 @@ class LogTailRolloutNarrator {
32711
32827
  singletons: initialSingletons(),
32712
32828
  frozen: false,
32713
32829
  timer: null,
32714
- pendingEditAfterPost: false
32830
+ pendingEditAfterPost: false,
32831
+ goneRepostUsed: false,
32832
+ goneRepostForMessageId: null
32715
32833
  };
32716
32834
  }
32835
+ escalateCard(esc) {
32836
+ try {
32837
+ if (this.opts.escalate) {
32838
+ this.opts.escalate(esc);
32839
+ return;
32840
+ }
32841
+ this.opts.log?.(`rollout card escalation request=${esc.requestId} agent=${esc.agentName} ` + `staleMessageId=${esc.staleMessageId} reason=${esc.reason}` + `${esc.detail !== undefined ? ` detail=${esc.detail}` : ""} ` + `— card could not be restored, no operator card issued (get_status remains the record)`);
32842
+ } catch {}
32843
+ }
32844
+ onEditOutcome(requestId, editedMessageId, outcome) {
32845
+ if (outcome.ok)
32846
+ return;
32847
+ const st = this.states.get(requestId);
32848
+ if (!st)
32849
+ return;
32850
+ if (!outcome.gone) {
32851
+ this.opts.log?.(`rollout narration edit failed (transient, requestId=${requestId}): ${outcome.reason ?? "unknown"}`);
32852
+ return;
32853
+ }
32854
+ if (st.messageId !== editedMessageId)
32855
+ return;
32856
+ if (st.goneRepostUsed) {
32857
+ this.escalateCard({
32858
+ requestId,
32859
+ agentName: st.agentName,
32860
+ staleMessageId: editedMessageId,
32861
+ reason: "gone-again",
32862
+ detail: outcome.reason
32863
+ });
32864
+ return;
32865
+ }
32866
+ st.goneRepostUsed = true;
32867
+ st.messageId = null;
32868
+ st.postFailed = false;
32869
+ st.goneRepostForMessageId = editedMessageId;
32870
+ if (st.timer) {
32871
+ clearTimeout(st.timer);
32872
+ st.timer = null;
32873
+ }
32874
+ this.opts.log?.(`rollout narration card ${editedMessageId} is gone (requestId=${requestId}); re-posting once`);
32875
+ if (!this.tryPost(requestId, true)) {
32876
+ st.goneRepostForMessageId = null;
32877
+ this.escalateCard({
32878
+ requestId,
32879
+ agentName: st.agentName,
32880
+ staleMessageId: editedMessageId,
32881
+ reason: "repost-unavailable",
32882
+ detail: "post-attempt cap reached"
32883
+ });
32884
+ }
32885
+ }
32717
32886
  ensureState(entry) {
32718
32887
  let st = this.states.get(entry.request_id);
32719
32888
  if (!st) {
@@ -32777,10 +32946,22 @@ class LogTailRolloutNarrator {
32777
32946
  if (mid === null) {
32778
32947
  st.postFailed = true;
32779
32948
  this.opts.log?.(`rollout narration post returned no message_id (requestId=${requestId}); backing off re-posts`);
32949
+ if (st.goneRepostForMessageId !== null) {
32950
+ const stale = st.goneRepostForMessageId;
32951
+ st.goneRepostForMessageId = null;
32952
+ this.escalateCard({
32953
+ requestId,
32954
+ agentName: st.agentName,
32955
+ staleMessageId: stale,
32956
+ reason: "repost-failed",
32957
+ detail: "post returned no message_id"
32958
+ });
32959
+ }
32780
32960
  return;
32781
32961
  }
32782
32962
  st.messageId = mid;
32783
32963
  st.postFailed = false;
32964
+ st.goneRepostForMessageId = null;
32784
32965
  try {
32785
32966
  this.opts.onMessageId?.(requestId, mid);
32786
32967
  } catch (e) {
@@ -32794,6 +32975,17 @@ class LogTailRolloutNarrator {
32794
32975
  st.posting = false;
32795
32976
  st.postFailed = true;
32796
32977
  this.opts.log?.(`rollout narration post failed (non-fatal): ${e.message}`);
32978
+ if (st.goneRepostForMessageId !== null) {
32979
+ const stale = st.goneRepostForMessageId;
32980
+ st.goneRepostForMessageId = null;
32981
+ this.escalateCard({
32982
+ requestId,
32983
+ agentName: st.agentName,
32984
+ staleMessageId: stale,
32985
+ reason: "repost-failed",
32986
+ detail: e.message
32987
+ });
32988
+ }
32797
32989
  });
32798
32990
  return true;
32799
32991
  }
@@ -32829,11 +33021,14 @@ class LogTailRolloutNarrator {
32829
33021
  return;
32830
33022
  }
32831
33023
  const text = renderRolloutStatus({ ...st.render, nowMs: this.now() });
33024
+ const editedMessageId = st.messageId;
32832
33025
  this.relay.edit({
32833
33026
  requestId,
32834
33027
  agentName: st.agentName,
32835
- messageId: st.messageId,
33028
+ messageId: editedMessageId,
32836
33029
  text
33030
+ }).then((outcome) => this.onEditOutcome(requestId, editedMessageId, outcome)).catch((e) => {
33031
+ this.opts.log?.(`rollout narration edit relay rejected (non-fatal): ${e.message}`);
32837
33032
  });
32838
33033
  }
32839
33034
  }
@@ -33433,7 +33628,9 @@ async function main() {
33433
33628
  }), {
33434
33629
  log: (m) => process.stderr.write(`hostd: rollout-narration — ${m}
33435
33630
  `),
33436
- onMessageId: (rid, mid) => server?.persistNarrationMessageId(rid, mid)
33631
+ onMessageId: (rid, mid) => server?.persistNarrationMessageId(rid, mid),
33632
+ escalate: (esc) => process.stderr.write(`hostd: rollout card escalation request=${esc.requestId} agent=${esc.agentName} ` + `staleMessageId=${esc.staleMessageId} reason=${esc.reason}` + `${esc.detail !== undefined ? ` detail=${esc.detail}` : ""} ` + `— card could not be restored, no operator card issued
33633
+ `)
33437
33634
  });
33438
33635
  const server = new HostdServer({
33439
33636
  homeDir: homedir8(),