switchroom 0.19.27 → 0.19.29

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 (44) hide show
  1. package/dist/agent-scheduler/index.js +16 -2
  2. package/dist/auth-broker/index.js +141 -8
  3. package/dist/cli/autoaccept-poll.js +225 -17
  4. package/dist/cli/notion-write-pretool.mjs +18 -2
  5. package/dist/cli/switchroom.js +864 -43
  6. package/dist/host-control/main.js +144 -9
  7. package/dist/vault/approvals/kernel-server.js +146 -9
  8. package/dist/vault/broker/server.js +146 -9
  9. package/package.json +3 -2
  10. package/profiles/_base/start.sh.hbs +79 -15
  11. package/telegram-plugin/dist/bridge/bridge.js +1 -0
  12. package/telegram-plugin/dist/gateway/gateway.js +585 -50
  13. package/telegram-plugin/dist/server.js +1 -0
  14. package/telegram-plugin/edit-flood-fuse.ts +230 -27
  15. package/telegram-plugin/gateway/callback-query-handlers.ts +6 -0
  16. package/telegram-plugin/gateway/gateway.ts +9 -2
  17. package/telegram-plugin/gateway/mcp-failure-hook.ts +74 -0
  18. package/telegram-plugin/inline-keyboard-callbacks.ts +202 -21
  19. package/telegram-plugin/mcp-credential-failure.ts +459 -0
  20. package/telegram-plugin/operator-events.ts +38 -0
  21. package/telegram-plugin/tests/edit-flood-fuse-ban-awareness.test.ts +58 -1
  22. package/telegram-plugin/tests/edit-flood-fuse-reply-reserve.test.ts +340 -0
  23. package/telegram-plugin/tests/finalize-callback-flood-policy.test.ts +298 -0
  24. package/telegram-plugin/tests/finalize-callback.test.ts +41 -8
  25. package/telegram-plugin/tests/mcp-credential-failure.test.ts +310 -0
  26. package/vendor/hindsight-memory/CHANGELOG.md +50 -0
  27. package/vendor/hindsight-memory/scripts/backfill_transcripts.py +1 -0
  28. package/vendor/hindsight-memory/scripts/drain_pending.py +437 -11
  29. package/vendor/hindsight-memory/scripts/lib/client.py +14 -0
  30. package/vendor/hindsight-memory/scripts/lib/config.py +91 -0
  31. package/vendor/hindsight-memory/scripts/lib/pending.py +199 -28
  32. package/vendor/hindsight-memory/scripts/reconcile_tail.py +1 -0
  33. package/vendor/hindsight-memory/scripts/retain.py +41 -1
  34. package/vendor/hindsight-memory/scripts/subagent_retain.py +1 -0
  35. package/vendor/hindsight-memory/scripts/tests/test_backfill.py +23 -1
  36. package/vendor/hindsight-memory/scripts/tests/test_backfill_from_logs.py +5 -1
  37. package/vendor/hindsight-memory/scripts/tests/test_drain_circuit_breaker.py +401 -0
  38. package/vendor/hindsight-memory/scripts/tests/test_drain_serialisation.py +286 -0
  39. package/vendor/hindsight-memory/scripts/tests/test_observation_scopes.py +325 -0
  40. package/vendor/hindsight-memory/scripts/tests/test_pending_drops.py +817 -8
  41. package/vendor/hindsight-memory/scripts/tests/test_reconcile_durability.py +160 -1
  42. package/vendor/hindsight-memory/scripts/tests/test_subagent_retain.py +40 -2
  43. package/vendor/hindsight-memory/settings.json +1 -1
  44. package/vendor/hindsight-memory/tests/test_hooks.py +11 -2
@@ -19073,6 +19073,16 @@ import { resolve as resolve3 } from "node:path";
19073
19073
 
19074
19074
  // src/config/schema.ts
19075
19075
  init_zod();
19076
+
19077
+ // src/memory/observation-scopes.ts
19078
+ var OBSERVATION_SCOPES = [
19079
+ "per_tag",
19080
+ "combined",
19081
+ "all_combinations",
19082
+ "shared"
19083
+ ];
19084
+
19085
+ // src/config/schema.ts
19076
19086
  var CodeRepoEntrySchema = exports_external.object({
19077
19087
  name: exports_external.string().describe("Short alias used when claiming (e.g. 'switchroom')"),
19078
19088
  source: exports_external.string().describe("Absolute or home-relative path to the repo (e.g. ~/code/switchroom)"),
@@ -19184,6 +19194,7 @@ var AgentToolsSchema = exports_external.object({
19184
19194
  allow: exports_external.array(exports_external.string()).default([]).describe("Allowed tools (use ['all'] for unrestricted)"),
19185
19195
  deny: exports_external.array(exports_external.string()).default([]).describe("Denied tools (overrides allow)")
19186
19196
  }).optional();
19197
+ var ObservationScopesSchema = exports_external.enum(OBSERVATION_SCOPES).optional().describe("Per-row observation scope stamped on every memory this agent " + `retains. "shared" makes Hindsight's consolidation write the ` + "resulting observations into ONE global untagged scope instead of a " + "scope per tag — what several agents pooling one bank need so their " + "observations actually merge rather than sitting in parallel " + "per-tag silos. OMITTED BY DEFAULT: unset means the field never goes " + "on the wire and the engine's own default stands, which is the " + "shipped behaviour. Applies to every retain path (Stop hook, " + "sidechain, boot reconcile, queue drain, backfill, session-handoff " + "mirror) and is carried on the queued payload, so a retain that fails " + "now and drains later still lands in this scope. Accepted values: " + `${OBSERVATION_SCOPES.join(", ")}. ` + "Cascade: override (per-agent wins over default).");
19187
19198
  var AgentMemorySchema = exports_external.object({
19188
19199
  collection: exports_external.string().describe("Hindsight collection name for this agent"),
19189
19200
  auto_recall: exports_external.boolean().default(true).describe("Auto-search memories before each response"),
@@ -19218,6 +19229,7 @@ var AgentMemorySchema = exports_external.object({
19218
19229
  empathy: exports_external.number().int().min(1).max(5).optional().describe("How much the bank weights emotional/relational context (1-5; engine default 3).")
19219
19230
  }).optional().describe("Personality traits (1-5 each) steering how this bank frames recall, " + "reflect, and observation synthesis — a coach leans empathy-high, a " + "lawyer/analyst leans skepticism/literalism-high. Maps to the engine's " + "flat `disposition_skepticism`/`_literalism`/`_empathy` fields. " + "Cascade: per-key merge (an agent overrides individual traits and " + "inherits the rest, matching `recall`)."),
19220
19231
  directive_capture_nudge: exports_external.boolean().optional().describe("Deterministic directive-capture nudge (issue #2848 Stage B). When " + "on (switchroom default true — Stage A measured a ~55% miss rate on " + "durable corrections), the auto-recall hook regex-detects correction " + '/ standing-rule-shaped inbound ("always/never …", "from now on …", ' + `"stop doing …", a stated preference, "that's wrong, it's …") and ` + "appends a terse advisory to the turn's context telling the model to " + "persist the rule with mcp__hindsight__create_directive if it IS " + "durable. Detection is pure regex — the model does the judgment " + "in-session and calls create_directive itself (no model callsite, no " + "silent hook-side write). Set false to disable per-agent. " + "Cascade: override (per-agent wins over default)."),
19232
+ observation_scopes: ObservationScopesSchema,
19221
19233
  recall: exports_external.object({
19222
19234
  max_memories: exports_external.number().int().min(0).optional().describe("Cap on the number of memories injected into the prompt by " + "auto-recall, regardless of token budget. Plugin default is 12. " + "0 disables the cap (all memories Hindsight returns are injected)."),
19223
19235
  cache_ttl_secs: exports_external.number().int().min(0).optional().describe("Per-session recall cache TTL in seconds. When > 0, identical " + "(prompt, bank) within the same session reuse the cached recall " + "result instead of round-tripping to Hindsight. 0 disables. " + "Default is 600 (10 min) for switchroom-managed agents."),
@@ -19461,7 +19473,10 @@ var LiteLLMConfigSchema = exports_external.object({
19461
19473
  admin_key: exports_external.string().optional().describe("LiteLLM master/admin key used at apply time to provision the team + " + "virtual key. Supports a vault reference (e.g. " + "'vault:litellm/master-key') — resolution happens at apply time via " + "the vault-broker. Never injected into the agent container."),
19462
19474
  team: exports_external.string().optional().describe("LiteLLM team alias the per-agent key is created under. Defaults to " + "'switchroom' (applied in code, not as a schema default)."),
19463
19475
  small_fast_model: exports_external.string().optional().describe("Model id exported as ANTHROPIC_SMALL_FAST_MODEL for the claude CLI's " + "background/fast lane, e.g. 'claude-haiku-4-5-20251001'."),
19464
- tags: exports_external.record(exports_external.string(), exports_external.string()).optional().describe("Extra key/value metadata tags attached to the provisioned LiteLLM " + "virtual key. Merged per-key across cascade layers (agent wins).")
19476
+ tags: exports_external.record(exports_external.string(), exports_external.string()).optional().describe("Extra key/value metadata tags attached to the provisioned LiteLLM " + "virtual key. Merged per-key across cascade layers (agent wins)."),
19477
+ max_budget: exports_external.number().positive().optional().describe("HARD spend cap in USD for this agent's virtual key over one " + "`budget_duration` window. LiteLLM refuses the request once the key's " + "tracked spend exceeds it, so a runaway loop costs at most this much " + "before it is stopped. Defaults to " + "DEFAULT_KEY_MAX_BUDGET_USD (see src/litellm/budget.ts) — deliberately " + "conservative; raise it per-agent rather than removing it. Set 0 or " + "omit `budget_duration` at your own risk: an uncapped key is only as " + "bounded as the upstream account balance."),
19478
+ soft_budget: exports_external.number().positive().optional().describe("ADVISORY spend threshold in USD. LiteLLM keeps serving past it and " + "raises a budget alert instead. Must be < max_budget. NOTE: LiteLLM " + "accepts soft_budget only on POST /key/generate (GenerateKeyRequest); " + "UpdateKeyRequest does NOT carry it, so changing this value only takes " + "effect on a key that is (re)generated, not on an existing one."),
19479
+ budget_duration: exports_external.string().regex(/^\d+(s|m|h|d|mo)$/, "budget_duration must be a LiteLLM duration like '30d', '24h', '1mo'").optional().describe("Rolling window the budget resets on, in LiteLLM duration syntax " + "('30d', '24h', '1mo'). Defaults to DEFAULT_KEY_BUDGET_DURATION. " + "WITHOUT a duration LiteLLM treats max_budget as a LIFETIME cap that " + "never resets — the key silently dies for good once it is hit.")
19465
19480
  }).optional().describe("LiteLLM routing config — opt-in per-agent virtual-key auto-provisioning " + "+ routing env. Default OFF. See LiteLLMConfigSchema doc for the full flow.");
19466
19481
  var HindsightPerOpLlmSchema = exports_external.object({
19467
19482
  model: exports_external.string().min(1).optional().describe("Per-op model (upstream `HINDSIGHT_API_<OP>_LLM_MODEL`). Absent → " + "inherit the global `hindsight.llm.model`."),
@@ -19480,7 +19495,7 @@ var HindsightConfigSchema = exports_external.object({
19480
19495
  reflect: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `reflect` LLM op (synthesis / mental-model " + "refresh). Emits `HINDSIGHT_API_REFLECT_LLM_*`. Absent → uses global."),
19481
19496
  consolidation: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `consolidation` LLM op (background memory " + "merge). Emits `HINDSIGHT_API_CONSOLIDATION_LLM_*`. Absent → global.")
19482
19497
  }).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."),
19483
- 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), 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), 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).")
19498
+ 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).")
19484
19499
  });
19485
19500
  var MicrosoftWorkspaceConfigSchema = exports_external.object({
19486
19501
  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)."),
@@ -19613,6 +19628,7 @@ var profileFields = {
19613
19628
  file: exports_external.boolean().optional(),
19614
19629
  isolation: exports_external.enum(["default", "strict"]).optional(),
19615
19630
  directive_capture_nudge: exports_external.boolean().optional(),
19631
+ observation_scopes: ObservationScopesSchema,
19616
19632
  recall: exports_external.object({
19617
19633
  max_memories: exports_external.number().int().min(0).optional(),
19618
19634
  cache_ttl_secs: exports_external.number().int().min(0).optional(),
@@ -21192,7 +21208,7 @@ function allocateAgentUid(name) {
21192
21208
  }
21193
21209
 
21194
21210
  // src/build-info.ts
21195
- var VERSION = "0.19.27";
21211
+ var VERSION = "0.19.29";
21196
21212
 
21197
21213
  // src/setup/hindsight-recall-tunables.ts
21198
21214
  var RECALL_DEADLINE_HEADROOM_SECONDS = 2;
@@ -21320,7 +21336,13 @@ var HINDSIGHT_DEFAULT_LINK_EXPANSION_TIMEOUT_S = 2;
21320
21336
  var HINDSIGHT_DEFAULT_LLM_REASONING_EFFORT = "low";
21321
21337
  var HINDSIGHT_DEFAULT_LLM_MAX_CONCURRENT = 4;
21322
21338
  var HINDSIGHT_DEFAULT_RETAIN_LLM_MAX_CONCURRENT = 1;
21323
- var HINDSIGHT_DEFAULT_CONSOLIDATION_LLM_MAX_CONCURRENT = 1;
21339
+ function hindsightConsolidationLlmMaxConcurrentDefault(globalMaxConcurrent = HINDSIGHT_DEFAULT_LLM_MAX_CONCURRENT, retainMaxConcurrent = HINDSIGHT_DEFAULT_RETAIN_LLM_MAX_CONCURRENT) {
21340
+ const globalCap = Number.isFinite(globalMaxConcurrent) && globalMaxConcurrent >= 1 ? Math.floor(globalMaxConcurrent) : HINDSIGHT_DEFAULT_LLM_MAX_CONCURRENT;
21341
+ const retainCap = Number.isFinite(retainMaxConcurrent) && retainMaxConcurrent >= 0 ? Math.floor(retainMaxConcurrent) : HINDSIGHT_DEFAULT_RETAIN_LLM_MAX_CONCURRENT;
21342
+ const headroomBound = Math.max(1, globalCap - 1);
21343
+ return Math.min(headroomBound, Math.max(1, globalCap - retainCap - 1));
21344
+ }
21345
+ var HINDSIGHT_DEFAULT_CONSOLIDATION_LLM_MAX_CONCURRENT = hindsightConsolidationLlmMaxConcurrentDefault();
21324
21346
  var HINDSIGHT_DEFAULT_RERANKER_LOCAL_FP16 = "true";
21325
21347
  var HINDSIGHT_DEFAULT_RERANKER_LOCAL_BATCH_SIZE = 128;
21326
21348
  var HINDSIGHT_DEFAULT_LLM_STRICT_SCHEMA = "true";
@@ -21335,6 +21357,8 @@ var HINDSIGHT_DEFAULT_REFLECT_WALL_TIMEOUT_S = 600;
21335
21357
  var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_MEMORIES_PER_ROUND = 500;
21336
21358
  var HINDSIGHT_DEFAULT_CONSOLIDATION_SLOT_LIMIT = 6;
21337
21359
  var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_SLOTS = 1;
21360
+ var HINDSIGHT_DEFAULT_RECENCY_DECAY_FUNCTION = "exponential";
21361
+ var HINDSIGHT_DEFAULT_RECENCY_DECAY_HALFLIFE_DAYS = 30;
21338
21362
  var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
21339
21363
  [
21340
21364
  "HINDSIGHT_API_RECALL_MAX_CANDIDATES_PER_SOURCE",
@@ -21388,6 +21412,14 @@ var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
21388
21412
  [
21389
21413
  "HINDSIGHT_API_CONSOLIDATION_MAX_MEMORIES_PER_ROUND",
21390
21414
  String(HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_MEMORIES_PER_ROUND)
21415
+ ],
21416
+ [
21417
+ "HINDSIGHT_API_RECENCY_DECAY_FUNCTION",
21418
+ HINDSIGHT_DEFAULT_RECENCY_DECAY_FUNCTION
21419
+ ],
21420
+ [
21421
+ "HINDSIGHT_API_RECENCY_DECAY_HALFLIFE_DAYS",
21422
+ String(HINDSIGHT_DEFAULT_RECENCY_DECAY_HALFLIFE_DAYS)
21391
21423
  ]
21392
21424
  ];
21393
21425
  var HINDSIGHT_PERF_DEFAULTS_GPU = [
@@ -21412,7 +21444,10 @@ var HINDSIGHT_PERF_DEFAULTS_LOCAL_LLM = [
21412
21444
  ];
21413
21445
  var HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS = new Set([
21414
21446
  "HINDSIGHT_API_WORKER_CONSOLIDATION_BANK_PRIORITY",
21415
- "HINDSIGHT_CE_DECISIVE_RELATIVE_GAP"
21447
+ "HINDSIGHT_CE_DECISIVE_RELATIVE_GAP",
21448
+ "HINDSIGHT_API_RECENCY_DECAY_LINEAR_WINDOW_DAYS",
21449
+ "HINDSIGHT_API_WORKER_MAX_SLOTS",
21450
+ "HINDSIGHT_API_WORKER_RETAIN_MAX_SLOTS"
21416
21451
  ]);
21417
21452
  var HINDSIGHT_PERF_ENV_KEYS = new Set([
21418
21453
  ...[
@@ -21478,6 +21513,16 @@ var DEFAULT_RETAIN_MISSION = `Extract durable facts that will still be true and
21478
21513
  ` + `- Hindsight's own errors, retries, backlogs, or internal state — the memory
21479
21514
  ` + ` system's self-reports are not memories.
21480
21515
  ` + `- Restatements of the user's current request or the task in progress.
21516
+ ` + `- Volatile state written as a timeless assertion. A version, count, size,
21517
+ ` + ` backlog, status, or any "X is running Y" / "X is at Y" / "X is currently Y"
21518
+ ` + ` claim is true only at the instant it was said. Concretely, never produce a
21519
+ ` + ` fact whose text resembles any of these: "Switchroom fleet is running image
21520
+ ` + ` version v0.18.19", "The switchroom repo is at /path/to/fleet, version
21521
+ ` + ` v0.19.5", "Bank overlord has 43155 pending consolidations", "The build is
21522
+ ` + ` currently green". If the claim is worth keeping, put the date INSIDE the
21523
+ ` + ` fact text ("As of 2026-07-19 the fleet was running v0.18.19"); if you
21524
+ ` + ` cannot date it, drop it. An undated one is recalled forever as though it
21525
+ ` + ` were still true, which is worse than not remembering it at all.
21481
21526
  ` + `- Transient state (unread counts, build status, what is running right now) unless
21482
21527
  ` + ` the fact is explicitly dated, in which case record it as a dated observation.
21483
21528
  ` + `- Greetings, acknowledgements, and routine operational chatter.
@@ -21499,18 +21544,108 @@ var SUPERSEDED_RETAIN_MISSIONS = [
21499
21544
  ` + "- Transient state (unread counts, build status, what is running right now) " + "unless the fact is explicitly dated, in which case record it as a dated " + `observation.
21500
21545
  ` + `- Greetings, acknowledgements, and routine operational chatter.
21501
21546
 
21502
- ` + "If a candidate fact matches an exclusion, drop it rather than rewording " + "it. If nothing durable remains, return an empty facts list."
21547
+ ` + "If a candidate fact matches an exclusion, drop it rather than rewording " + "it. If nothing durable remains, return an empty facts list.",
21548
+ `Extract durable facts that will still be true and useful weeks from now: user preferences and standing rules, ongoing projects and recurring commitments, technical and architectural decisions with their rationale, and people/tool relationships. A preference revealed by a request is durable — record the preference (what the user likes, wants, or always does), not the request itself.
21549
+ ` + `
21550
+ ` + `A TOOL RESULT IS NOT A FACT. Before extracting, ask: is the subject of this
21551
+ ` + `candidate a file path, a command/process/agent/session id, a temp directory, or
21552
+ ` + `the location where some output was written? If yes, drop it — it is transcript
21553
+ ` + `exhaust, not memory.
21554
+ ` + `
21555
+ ` + `NEVER extract:
21556
+ ` + `- Tool results verbatim or paraphrased. Concretely, never produce a fact whose
21557
+ ` + ` text resembles any of these: "File created successfully at /path/to/file",
21558
+ ` + ` "A background command with ID bctz4yskm is running, and its output will be
21559
+ ` + ` written to /tmp/...", "Async agent a745598ba84e71df1 was launched successfully
21560
+ ` + ` and is running in the background", "User executed a Bash command to sleep for
21561
+ ` + ` 200 seconds", "The assistant used grep to locate 'truncateSync' in src/foo.ts".
21562
+ ` + `- Anything mentioning a path under /tmp, a scratchpad directory, or a .tmp file.
21563
+ ` + `- Agent tool-use traces or narration of what the assistant did (e.g. "the
21564
+ ` + ` assistant used X to query Y", "ran a search", "sent the message").
21565
+ ` + `- In-flight workflow/process narration (a sub-task started, paused, or is still
21566
+ ` + ` running) — retain the outcome only once the task completes or a decision is made.
21567
+ ` + `- Operation, request, batch, agent, command or session IDs, UUIDs, hashes, or error codes.
21568
+ ` + `- Slash commands the user typed and their effects (e.g. "User issued /clear to
21569
+ ` + ` reset assistant state").
21570
+ ` + `- Hindsight's own errors, retries, backlogs, or internal state — the memory
21571
+ ` + ` system's self-reports are not memories.
21572
+ ` + `- Restatements of the user's current request or the task in progress.
21573
+ ` + `- Transient state (unread counts, build status, what is running right now) unless
21574
+ ` + ` the fact is explicitly dated, in which case record it as a dated observation.
21575
+ ` + `- Greetings, acknowledgements, and routine operational chatter.
21576
+ ` + `
21577
+ ` + `If a candidate fact matches an exclusion, drop it rather than rewording it. If
21578
+ ` + "nothing durable remains, return an empty facts list."
21579
+ ];
21580
+ var DEFAULT_OBSERVATIONS_MISSION = `Synthesise durable, standing knowledge about the people, projects, and systems this agent works with: preferences and standing rules, roles and relationships, skills and recurring patterns, technical and operational decisions with their rationale, and the state of long-running work once it lands.
21581
+ ` + `
21582
+ ` + `The test is durability, not notability: an observation must still be worth reading weeks from now. A single dated event belongs in an observation only when it establishes or changes a standing fact.
21583
+ ` + `
21584
+ ` + `Do NOT synthesise observations from:
21585
+ ` + `- Transcript exhaust — tool calls and their results, file paths, temp or scratchpad directories, where some output was written, or narration of what an assistant did.
21586
+ ` + `- Identifiers with no standing meaning: session, agent, request, batch or command IDs, UUIDs, hashes, error codes.
21587
+ ` + `- In-flight process narration — a task started, paused, or still running. Record the outcome once it lands, not the running state.
21588
+ ` + `- The memory system's own errors, retries, backlogs, or internal state.
21589
+ ` + `- Transient state (what is running right now, unread counts, build status) unless the fact is explicitly dated, in which case record it as dated.
21590
+ ` + `
21591
+ ` + "If the new facts contain nothing durable, record nothing rather than synthesising a weak observation.";
21592
+ var SUPERSEDED_OBSERVATIONS_MISSIONS = [
21593
+ "Synthesise the person's wellbeing patterns, motivations, and emotional " + "context — how habits, setbacks, and encouragement connect over time."
21503
21594
  ];
21504
21595
  var PROFILE_MEMORY_DEFAULTS = {
21505
21596
  "health-coach": {
21506
21597
  disposition: { skepticism: 2, literalism: 2, empathy: 5 },
21507
- observations_mission: "Synthesise the person's wellbeing patterns, motivations, and emotional " + "context how habits, setbacks, and encouragement connect over time."
21598
+ observations_mission: `You consolidate the memory of a health and fitness coach working with one person. This bank records how that person actually lives and trains.
21599
+ ` + `
21600
+ ` + `Synthesise into durable observations:
21601
+ ` + `- Goals, targets, and the plan currently in force, with the reasoning behind each.
21602
+ ` + `- Training, nutrition, sleep, and alcohol patterns as they hold over weeks — what the person reliably does, not what they did once.
21603
+ ` + `- Constraints that shape the plan: injuries, medical guidance, schedule, equipment, foods and sessions they refuse.
21604
+ ` + `- Motivations, and what actually helps or backfires when they slip.
21605
+ ` + `- Trends in the numbers: direction and range over time, not any single reading.
21606
+ ` + `- Corrections to earlier beliefs, recorded explicitly as corrections.
21607
+ ` + `
21608
+ ` + `A single day's log, weight reading, or session is evidence, not an observation. Record one only when it establishes or changes a standing pattern, target, or constraint — then fold it into the observation for that pattern and say what changed and roughly when.
21609
+ ` + `
21610
+ ` + `Granularity: one observation per habit, target, constraint, or trend. Aggregate repeated daily evidence into the observation for that pattern rather than creating one per day, and keep training, nutrition, and sleep as separate observations.
21611
+ ` + `
21612
+ ` + "Word observations as the person's own pattern and framing, never as a verdict on them."
21508
21613
  },
21509
21614
  "executive-assistant": {
21510
- disposition: { skepticism: 4, literalism: 4, empathy: 3 }
21615
+ disposition: { skepticism: 4, literalism: 4, empathy: 3 },
21616
+ observations_mission: `You consolidate the memory of an executive assistant working for one person. This bank records that person's commitments, people, and standing arrangements.
21617
+ ` + `
21618
+ ` + `Synthesise into durable observations:
21619
+ ` + `- Standing rules and preferences: how they want things scheduled, written, and filed, and when they want to be interrupted.
21620
+ ` + `- People and organisations, and the relationship: who they are, what they are involved in, how to reach them.
21621
+ ` + `- Recurring commitments and routines, and the constraints around them.
21622
+ ` + `- Obligations and their state: what was promised to whom, the deadline, and what is still outstanding.
21623
+ ` + `- Decisions made and decisions deferred, with the reasoning and the trade accepted.
21624
+ ` + `- Corrections to earlier beliefs, recorded explicitly as corrections.
21625
+ ` + `
21626
+ ` + `Live commitment state IS durable knowledge here, not ephemeral chatter. An outstanding obligation, a travel window, an unanswered request, a "currently X" arrangement — these are precisely what this agent must recall later. Keep them, and embed the date inside the observation text so a later reader can judge staleness. Do not drop them as ephemeral.
21627
+ ` + `
21628
+ ` + `Granularity: one observation per person, arrangement, or obligation. Aggregate repeated mentions into that observation rather than creating siblings; never merge two different people or two different commitments into one.
21629
+ ` + `
21630
+ ` + "Do not synthesise from transcript exhaust: tool calls and their results, message or event identifiers, or narration of what the assistant did."
21511
21631
  },
21512
21632
  coding: {
21513
- disposition: { skepticism: 4, literalism: 5, empathy: 2 }
21633
+ disposition: { skepticism: 4, literalism: 5, empathy: 2 },
21634
+ observations_mission: `You consolidate the memory of a software-engineering agent. This bank records real work on real codebases.
21635
+ ` + `
21636
+ ` + `Synthesise into durable observations:
21637
+ ` + `- Architecture and design decisions, each with its rationale and the trade accepted.
21638
+ ` + `- Root causes, with the evidence chain, and negative results — what was ruled out matters as much as what was found.
21639
+ ` + `- How the repository works: build, test, and lint commands, conventions, CI gates, and where things live.
21640
+ ` + `- Outcomes of code work: issue and PR numbers, what changed, whether it merged, what review found.
21641
+ ` + `- The user's standing rules, preferences, and corrections to this agent's behaviour.
21642
+ ` + `- Corrections to earlier beliefs, recorded explicitly as corrections.
21643
+ ` + `
21644
+ ` + `Repository and service state IS durable knowledge here, not ephemeral chatter. Versions, a failing gate, an open PR, a measured number, a "currently X" claim — these are precisely what this agent must recall later. Keep them, and embed the date inside the observation text so a later reader can judge staleness. Do not drop them as ephemeral.
21645
+ ` + `
21646
+ ` + `Granularity: one observation per distinct decision, cause, convention, or work item. Aggregate repeated evidence about the same one into that observation rather than creating siblings; never merge two separate decisions into a single summary.
21647
+ ` + `
21648
+ ` + "Do not synthesise from transcript exhaust: tool calls and their results, scratch paths, session or request identifiers, or narration of what the agent did. Prefer specific and falsifiable — naming the file, the number, the commit, or the decision beats summarising the topic."
21514
21649
  }
21515
21650
  };
21516
21651
 
@@ -4012,10 +4012,22 @@ var init_zod = __esm(() => {
4012
4012
  init_external();
4013
4013
  });
4014
4014
 
4015
+ // src/memory/observation-scopes.ts
4016
+ var OBSERVATION_SCOPES;
4017
+ var init_observation_scopes = __esm(() => {
4018
+ OBSERVATION_SCOPES = [
4019
+ "per_tag",
4020
+ "combined",
4021
+ "all_combinations",
4022
+ "shared"
4023
+ ];
4024
+ });
4025
+
4015
4026
  // src/config/schema.ts
4016
- var CodeRepoEntrySchema, AgentBindMountSchema, HttpDiffPollSchema, PollSpecSchema, TelegramMessageActionSchema, WebhookActionSchema, ActionSpecSchema, ScheduleEntrySchema, AgentSoulSchema, AgentToolsSchema, AgentMemorySchema, HookEntrySchema, AgentHooksSchema, SubagentSchema, SessionSchema, SessionContinuitySchema, webhookDispatchRule, TelegramChannelSchema, ChannelsSchema, TIMEZONE_REGEX, ApproverIdSchema, GoogleWorkspaceTierSchema, GoogleWorkspaceConfigSchema, LiteLLMConfigSchema, HindsightPerOpLlmSchema, HindsightConfigSchema, MicrosoftWorkspaceConfigSchema, NotionWorkspaceConfigSchema, AgentGoogleWorkspaceConfigSchema, MicrosoftAccountEmailSchema, MicrosoftToolTokenSchema, MicrosoftAccountBindingSchema, AgentMicrosoftWorkspaceConfigSchema, AgentNotionWorkspaceConfigSchema, ReactionsSchema, ReactionDispatchSchema, releaseBlockFields, ReleaseBlock, RootReleaseBlock, NetworkIsolationSchema, servesField, knowsField, profileFields, ProfileSchema, _omitExtends, defaultsFields, AgentDefaultsSchema, AgentSchema, TelegramConfigSchema, MemoryBackendConfigSchema, VaultConfigSchema, QuotaConfigSchema, AutoReleaseCheckSchema, HostControlConfigSchema, WebServiceConfigSchema, FleetHealthConfigSchema, HostdConfigSchema, CronEgressSchema, CronConfigSchema, UserSchema, SwitchroomConfigSchema;
4027
+ var CodeRepoEntrySchema, AgentBindMountSchema, HttpDiffPollSchema, PollSpecSchema, TelegramMessageActionSchema, WebhookActionSchema, ActionSpecSchema, ScheduleEntrySchema, AgentSoulSchema, AgentToolsSchema, ObservationScopesSchema, AgentMemorySchema, HookEntrySchema, AgentHooksSchema, SubagentSchema, SessionSchema, SessionContinuitySchema, webhookDispatchRule, TelegramChannelSchema, ChannelsSchema, TIMEZONE_REGEX, ApproverIdSchema, GoogleWorkspaceTierSchema, GoogleWorkspaceConfigSchema, LiteLLMConfigSchema, HindsightPerOpLlmSchema, HindsightConfigSchema, MicrosoftWorkspaceConfigSchema, NotionWorkspaceConfigSchema, AgentGoogleWorkspaceConfigSchema, MicrosoftAccountEmailSchema, MicrosoftToolTokenSchema, MicrosoftAccountBindingSchema, AgentMicrosoftWorkspaceConfigSchema, AgentNotionWorkspaceConfigSchema, ReactionsSchema, ReactionDispatchSchema, releaseBlockFields, ReleaseBlock, RootReleaseBlock, NetworkIsolationSchema, servesField, knowsField, profileFields, ProfileSchema, _omitExtends, defaultsFields, AgentDefaultsSchema, AgentSchema, TelegramConfigSchema, MemoryBackendConfigSchema, VaultConfigSchema, QuotaConfigSchema, AutoReleaseCheckSchema, HostControlConfigSchema, WebServiceConfigSchema, FleetHealthConfigSchema, HostdConfigSchema, CronEgressSchema, CronConfigSchema, UserSchema, SwitchroomConfigSchema;
4017
4028
  var init_schema = __esm(() => {
4018
4029
  init_zod();
4030
+ init_observation_scopes();
4019
4031
  CodeRepoEntrySchema = exports_external.object({
4020
4032
  name: exports_external.string().describe("Short alias used when claiming (e.g. 'switchroom')"),
4021
4033
  source: exports_external.string().describe("Absolute or home-relative path to the repo (e.g. ~/code/switchroom)"),
@@ -4127,6 +4139,7 @@ var init_schema = __esm(() => {
4127
4139
  allow: exports_external.array(exports_external.string()).default([]).describe("Allowed tools (use ['all'] for unrestricted)"),
4128
4140
  deny: exports_external.array(exports_external.string()).default([]).describe("Denied tools (overrides allow)")
4129
4141
  }).optional();
4142
+ ObservationScopesSchema = exports_external.enum(OBSERVATION_SCOPES).optional().describe("Per-row observation scope stamped on every memory this agent " + `retains. "shared" makes Hindsight's consolidation write the ` + "resulting observations into ONE global untagged scope instead of a " + "scope per tag — what several agents pooling one bank need so their " + "observations actually merge rather than sitting in parallel " + "per-tag silos. OMITTED BY DEFAULT: unset means the field never goes " + "on the wire and the engine's own default stands, which is the " + "shipped behaviour. Applies to every retain path (Stop hook, " + "sidechain, boot reconcile, queue drain, backfill, session-handoff " + "mirror) and is carried on the queued payload, so a retain that fails " + "now and drains later still lands in this scope. Accepted values: " + `${OBSERVATION_SCOPES.join(", ")}. ` + "Cascade: override (per-agent wins over default).");
4130
4143
  AgentMemorySchema = exports_external.object({
4131
4144
  collection: exports_external.string().describe("Hindsight collection name for this agent"),
4132
4145
  auto_recall: exports_external.boolean().default(true).describe("Auto-search memories before each response"),
@@ -4161,6 +4174,7 @@ var init_schema = __esm(() => {
4161
4174
  empathy: exports_external.number().int().min(1).max(5).optional().describe("How much the bank weights emotional/relational context (1-5; engine default 3).")
4162
4175
  }).optional().describe("Personality traits (1-5 each) steering how this bank frames recall, " + "reflect, and observation synthesis — a coach leans empathy-high, a " + "lawyer/analyst leans skepticism/literalism-high. Maps to the engine's " + "flat `disposition_skepticism`/`_literalism`/`_empathy` fields. " + "Cascade: per-key merge (an agent overrides individual traits and " + "inherits the rest, matching `recall`)."),
4163
4176
  directive_capture_nudge: exports_external.boolean().optional().describe("Deterministic directive-capture nudge (issue #2848 Stage B). When " + "on (switchroom default true — Stage A measured a ~55% miss rate on " + "durable corrections), the auto-recall hook regex-detects correction " + '/ standing-rule-shaped inbound ("always/never …", "from now on …", ' + `"stop doing …", a stated preference, "that's wrong, it's …") and ` + "appends a terse advisory to the turn's context telling the model to " + "persist the rule with mcp__hindsight__create_directive if it IS " + "durable. Detection is pure regex — the model does the judgment " + "in-session and calls create_directive itself (no model callsite, no " + "silent hook-side write). Set false to disable per-agent. " + "Cascade: override (per-agent wins over default)."),
4177
+ observation_scopes: ObservationScopesSchema,
4164
4178
  recall: exports_external.object({
4165
4179
  max_memories: exports_external.number().int().min(0).optional().describe("Cap on the number of memories injected into the prompt by " + "auto-recall, regardless of token budget. Plugin default is 12. " + "0 disables the cap (all memories Hindsight returns are injected)."),
4166
4180
  cache_ttl_secs: exports_external.number().int().min(0).optional().describe("Per-session recall cache TTL in seconds. When > 0, identical " + "(prompt, bank) within the same session reuse the cached recall " + "result instead of round-tripping to Hindsight. 0 disables. " + "Default is 600 (10 min) for switchroom-managed agents."),
@@ -4404,7 +4418,10 @@ var init_schema = __esm(() => {
4404
4418
  admin_key: exports_external.string().optional().describe("LiteLLM master/admin key used at apply time to provision the team + " + "virtual key. Supports a vault reference (e.g. " + "'vault:litellm/master-key') — resolution happens at apply time via " + "the vault-broker. Never injected into the agent container."),
4405
4419
  team: exports_external.string().optional().describe("LiteLLM team alias the per-agent key is created under. Defaults to " + "'switchroom' (applied in code, not as a schema default)."),
4406
4420
  small_fast_model: exports_external.string().optional().describe("Model id exported as ANTHROPIC_SMALL_FAST_MODEL for the claude CLI's " + "background/fast lane, e.g. 'claude-haiku-4-5-20251001'."),
4407
- tags: exports_external.record(exports_external.string(), exports_external.string()).optional().describe("Extra key/value metadata tags attached to the provisioned LiteLLM " + "virtual key. Merged per-key across cascade layers (agent wins).")
4421
+ tags: exports_external.record(exports_external.string(), exports_external.string()).optional().describe("Extra key/value metadata tags attached to the provisioned LiteLLM " + "virtual key. Merged per-key across cascade layers (agent wins)."),
4422
+ max_budget: exports_external.number().positive().optional().describe("HARD spend cap in USD for this agent's virtual key over one " + "`budget_duration` window. LiteLLM refuses the request once the key's " + "tracked spend exceeds it, so a runaway loop costs at most this much " + "before it is stopped. Defaults to " + "DEFAULT_KEY_MAX_BUDGET_USD (see src/litellm/budget.ts) — deliberately " + "conservative; raise it per-agent rather than removing it. Set 0 or " + "omit `budget_duration` at your own risk: an uncapped key is only as " + "bounded as the upstream account balance."),
4423
+ soft_budget: exports_external.number().positive().optional().describe("ADVISORY spend threshold in USD. LiteLLM keeps serving past it and " + "raises a budget alert instead. Must be < max_budget. NOTE: LiteLLM " + "accepts soft_budget only on POST /key/generate (GenerateKeyRequest); " + "UpdateKeyRequest does NOT carry it, so changing this value only takes " + "effect on a key that is (re)generated, not on an existing one."),
4424
+ budget_duration: exports_external.string().regex(/^\d+(s|m|h|d|mo)$/, "budget_duration must be a LiteLLM duration like '30d', '24h', '1mo'").optional().describe("Rolling window the budget resets on, in LiteLLM duration syntax " + "('30d', '24h', '1mo'). Defaults to DEFAULT_KEY_BUDGET_DURATION. " + "WITHOUT a duration LiteLLM treats max_budget as a LIFETIME cap that " + "never resets — the key silently dies for good once it is hit.")
4408
4425
  }).optional().describe("LiteLLM routing config — opt-in per-agent virtual-key auto-provisioning " + "+ routing env. Default OFF. See LiteLLMConfigSchema doc for the full flow.");
4409
4426
  HindsightPerOpLlmSchema = exports_external.object({
4410
4427
  model: exports_external.string().min(1).optional().describe("Per-op model (upstream `HINDSIGHT_API_<OP>_LLM_MODEL`). Absent → " + "inherit the global `hindsight.llm.model`."),
@@ -4423,7 +4440,7 @@ var init_schema = __esm(() => {
4423
4440
  reflect: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `reflect` LLM op (synthesis / mental-model " + "refresh). Emits `HINDSIGHT_API_REFLECT_LLM_*`. Absent → uses global."),
4424
4441
  consolidation: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `consolidation` LLM op (background memory " + "merge). Emits `HINDSIGHT_API_CONSOLIDATION_LLM_*`. Absent → global.")
4425
4442
  }).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."),
4426
- 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), 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), 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).")
4443
+ 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).")
4427
4444
  });
4428
4445
  MicrosoftWorkspaceConfigSchema = exports_external.object({
4429
4446
  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)."),
@@ -4556,6 +4573,7 @@ var init_schema = __esm(() => {
4556
4573
  file: exports_external.boolean().optional(),
4557
4574
  isolation: exports_external.enum(["default", "strict"]).optional(),
4558
4575
  directive_capture_nudge: exports_external.boolean().optional(),
4576
+ observation_scopes: ObservationScopesSchema,
4559
4577
  recall: exports_external.object({
4560
4578
  max_memories: exports_external.number().int().min(0).optional(),
4561
4579
  cache_ttl_secs: exports_external.number().int().min(0).optional(),
@@ -19297,7 +19315,13 @@ var HINDSIGHT_DEFAULT_LINK_EXPANSION_TIMEOUT_S = 2;
19297
19315
  var HINDSIGHT_DEFAULT_LLM_REASONING_EFFORT = "low";
19298
19316
  var HINDSIGHT_DEFAULT_LLM_MAX_CONCURRENT = 4;
19299
19317
  var HINDSIGHT_DEFAULT_RETAIN_LLM_MAX_CONCURRENT = 1;
19300
- var HINDSIGHT_DEFAULT_CONSOLIDATION_LLM_MAX_CONCURRENT = 1;
19318
+ function hindsightConsolidationLlmMaxConcurrentDefault(globalMaxConcurrent = HINDSIGHT_DEFAULT_LLM_MAX_CONCURRENT, retainMaxConcurrent = HINDSIGHT_DEFAULT_RETAIN_LLM_MAX_CONCURRENT) {
19319
+ const globalCap = Number.isFinite(globalMaxConcurrent) && globalMaxConcurrent >= 1 ? Math.floor(globalMaxConcurrent) : HINDSIGHT_DEFAULT_LLM_MAX_CONCURRENT;
19320
+ const retainCap = Number.isFinite(retainMaxConcurrent) && retainMaxConcurrent >= 0 ? Math.floor(retainMaxConcurrent) : HINDSIGHT_DEFAULT_RETAIN_LLM_MAX_CONCURRENT;
19321
+ const headroomBound = Math.max(1, globalCap - 1);
19322
+ return Math.min(headroomBound, Math.max(1, globalCap - retainCap - 1));
19323
+ }
19324
+ var HINDSIGHT_DEFAULT_CONSOLIDATION_LLM_MAX_CONCURRENT = hindsightConsolidationLlmMaxConcurrentDefault();
19301
19325
  var HINDSIGHT_DEFAULT_RERANKER_LOCAL_FP16 = "true";
19302
19326
  var HINDSIGHT_DEFAULT_RERANKER_LOCAL_BATCH_SIZE = 128;
19303
19327
  var HINDSIGHT_DEFAULT_LLM_STRICT_SCHEMA = "true";
@@ -19312,6 +19336,8 @@ var HINDSIGHT_DEFAULT_REFLECT_WALL_TIMEOUT_S = 600;
19312
19336
  var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_MEMORIES_PER_ROUND = 500;
19313
19337
  var HINDSIGHT_DEFAULT_CONSOLIDATION_SLOT_LIMIT = 6;
19314
19338
  var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_SLOTS = 1;
19339
+ var HINDSIGHT_DEFAULT_RECENCY_DECAY_FUNCTION = "exponential";
19340
+ var HINDSIGHT_DEFAULT_RECENCY_DECAY_HALFLIFE_DAYS = 30;
19315
19341
  var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
19316
19342
  [
19317
19343
  "HINDSIGHT_API_RECALL_MAX_CANDIDATES_PER_SOURCE",
@@ -19365,6 +19391,14 @@ var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
19365
19391
  [
19366
19392
  "HINDSIGHT_API_CONSOLIDATION_MAX_MEMORIES_PER_ROUND",
19367
19393
  String(HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_MEMORIES_PER_ROUND)
19394
+ ],
19395
+ [
19396
+ "HINDSIGHT_API_RECENCY_DECAY_FUNCTION",
19397
+ HINDSIGHT_DEFAULT_RECENCY_DECAY_FUNCTION
19398
+ ],
19399
+ [
19400
+ "HINDSIGHT_API_RECENCY_DECAY_HALFLIFE_DAYS",
19401
+ String(HINDSIGHT_DEFAULT_RECENCY_DECAY_HALFLIFE_DAYS)
19368
19402
  ]
19369
19403
  ];
19370
19404
  var HINDSIGHT_PERF_DEFAULTS_GPU = [
@@ -19389,7 +19423,10 @@ var HINDSIGHT_PERF_DEFAULTS_LOCAL_LLM = [
19389
19423
  ];
19390
19424
  var HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS = new Set([
19391
19425
  "HINDSIGHT_API_WORKER_CONSOLIDATION_BANK_PRIORITY",
19392
- "HINDSIGHT_CE_DECISIVE_RELATIVE_GAP"
19426
+ "HINDSIGHT_CE_DECISIVE_RELATIVE_GAP",
19427
+ "HINDSIGHT_API_RECENCY_DECAY_LINEAR_WINDOW_DAYS",
19428
+ "HINDSIGHT_API_WORKER_MAX_SLOTS",
19429
+ "HINDSIGHT_API_WORKER_RETAIN_MAX_SLOTS"
19393
19430
  ]);
19394
19431
  var HINDSIGHT_PERF_ENV_KEYS = new Set([
19395
19432
  ...[
@@ -19455,6 +19492,16 @@ var DEFAULT_RETAIN_MISSION = `Extract durable facts that will still be true and
19455
19492
  ` + `- Hindsight's own errors, retries, backlogs, or internal state — the memory
19456
19493
  ` + ` system's self-reports are not memories.
19457
19494
  ` + `- Restatements of the user's current request or the task in progress.
19495
+ ` + `- Volatile state written as a timeless assertion. A version, count, size,
19496
+ ` + ` backlog, status, or any "X is running Y" / "X is at Y" / "X is currently Y"
19497
+ ` + ` claim is true only at the instant it was said. Concretely, never produce a
19498
+ ` + ` fact whose text resembles any of these: "Switchroom fleet is running image
19499
+ ` + ` version v0.18.19", "The switchroom repo is at /path/to/fleet, version
19500
+ ` + ` v0.19.5", "Bank overlord has 43155 pending consolidations", "The build is
19501
+ ` + ` currently green". If the claim is worth keeping, put the date INSIDE the
19502
+ ` + ` fact text ("As of 2026-07-19 the fleet was running v0.18.19"); if you
19503
+ ` + ` cannot date it, drop it. An undated one is recalled forever as though it
19504
+ ` + ` were still true, which is worse than not remembering it at all.
19458
19505
  ` + `- Transient state (unread counts, build status, what is running right now) unless
19459
19506
  ` + ` the fact is explicitly dated, in which case record it as a dated observation.
19460
19507
  ` + `- Greetings, acknowledgements, and routine operational chatter.
@@ -19476,18 +19523,108 @@ var SUPERSEDED_RETAIN_MISSIONS = [
19476
19523
  ` + "- Transient state (unread counts, build status, what is running right now) " + "unless the fact is explicitly dated, in which case record it as a dated " + `observation.
19477
19524
  ` + `- Greetings, acknowledgements, and routine operational chatter.
19478
19525
 
19479
- ` + "If a candidate fact matches an exclusion, drop it rather than rewording " + "it. If nothing durable remains, return an empty facts list."
19526
+ ` + "If a candidate fact matches an exclusion, drop it rather than rewording " + "it. If nothing durable remains, return an empty facts list.",
19527
+ `Extract durable facts that will still be true and useful weeks from now: user preferences and standing rules, ongoing projects and recurring commitments, technical and architectural decisions with their rationale, and people/tool relationships. A preference revealed by a request is durable — record the preference (what the user likes, wants, or always does), not the request itself.
19528
+ ` + `
19529
+ ` + `A TOOL RESULT IS NOT A FACT. Before extracting, ask: is the subject of this
19530
+ ` + `candidate a file path, a command/process/agent/session id, a temp directory, or
19531
+ ` + `the location where some output was written? If yes, drop it — it is transcript
19532
+ ` + `exhaust, not memory.
19533
+ ` + `
19534
+ ` + `NEVER extract:
19535
+ ` + `- Tool results verbatim or paraphrased. Concretely, never produce a fact whose
19536
+ ` + ` text resembles any of these: "File created successfully at /path/to/file",
19537
+ ` + ` "A background command with ID bctz4yskm is running, and its output will be
19538
+ ` + ` written to /tmp/...", "Async agent a745598ba84e71df1 was launched successfully
19539
+ ` + ` and is running in the background", "User executed a Bash command to sleep for
19540
+ ` + ` 200 seconds", "The assistant used grep to locate 'truncateSync' in src/foo.ts".
19541
+ ` + `- Anything mentioning a path under /tmp, a scratchpad directory, or a .tmp file.
19542
+ ` + `- Agent tool-use traces or narration of what the assistant did (e.g. "the
19543
+ ` + ` assistant used X to query Y", "ran a search", "sent the message").
19544
+ ` + `- In-flight workflow/process narration (a sub-task started, paused, or is still
19545
+ ` + ` running) — retain the outcome only once the task completes or a decision is made.
19546
+ ` + `- Operation, request, batch, agent, command or session IDs, UUIDs, hashes, or error codes.
19547
+ ` + `- Slash commands the user typed and their effects (e.g. "User issued /clear to
19548
+ ` + ` reset assistant state").
19549
+ ` + `- Hindsight's own errors, retries, backlogs, or internal state — the memory
19550
+ ` + ` system's self-reports are not memories.
19551
+ ` + `- Restatements of the user's current request or the task in progress.
19552
+ ` + `- Transient state (unread counts, build status, what is running right now) unless
19553
+ ` + ` the fact is explicitly dated, in which case record it as a dated observation.
19554
+ ` + `- Greetings, acknowledgements, and routine operational chatter.
19555
+ ` + `
19556
+ ` + `If a candidate fact matches an exclusion, drop it rather than rewording it. If
19557
+ ` + "nothing durable remains, return an empty facts list."
19558
+ ];
19559
+ var DEFAULT_OBSERVATIONS_MISSION = `Synthesise durable, standing knowledge about the people, projects, and systems this agent works with: preferences and standing rules, roles and relationships, skills and recurring patterns, technical and operational decisions with their rationale, and the state of long-running work once it lands.
19560
+ ` + `
19561
+ ` + `The test is durability, not notability: an observation must still be worth reading weeks from now. A single dated event belongs in an observation only when it establishes or changes a standing fact.
19562
+ ` + `
19563
+ ` + `Do NOT synthesise observations from:
19564
+ ` + `- Transcript exhaust — tool calls and their results, file paths, temp or scratchpad directories, where some output was written, or narration of what an assistant did.
19565
+ ` + `- Identifiers with no standing meaning: session, agent, request, batch or command IDs, UUIDs, hashes, error codes.
19566
+ ` + `- In-flight process narration — a task started, paused, or still running. Record the outcome once it lands, not the running state.
19567
+ ` + `- The memory system's own errors, retries, backlogs, or internal state.
19568
+ ` + `- Transient state (what is running right now, unread counts, build status) unless the fact is explicitly dated, in which case record it as dated.
19569
+ ` + `
19570
+ ` + "If the new facts contain nothing durable, record nothing rather than synthesising a weak observation.";
19571
+ var SUPERSEDED_OBSERVATIONS_MISSIONS = [
19572
+ "Synthesise the person's wellbeing patterns, motivations, and emotional " + "context — how habits, setbacks, and encouragement connect over time."
19480
19573
  ];
19481
19574
  var PROFILE_MEMORY_DEFAULTS = {
19482
19575
  "health-coach": {
19483
19576
  disposition: { skepticism: 2, literalism: 2, empathy: 5 },
19484
- observations_mission: "Synthesise the person's wellbeing patterns, motivations, and emotional " + "context how habits, setbacks, and encouragement connect over time."
19577
+ observations_mission: `You consolidate the memory of a health and fitness coach working with one person. This bank records how that person actually lives and trains.
19578
+ ` + `
19579
+ ` + `Synthesise into durable observations:
19580
+ ` + `- Goals, targets, and the plan currently in force, with the reasoning behind each.
19581
+ ` + `- Training, nutrition, sleep, and alcohol patterns as they hold over weeks — what the person reliably does, not what they did once.
19582
+ ` + `- Constraints that shape the plan: injuries, medical guidance, schedule, equipment, foods and sessions they refuse.
19583
+ ` + `- Motivations, and what actually helps or backfires when they slip.
19584
+ ` + `- Trends in the numbers: direction and range over time, not any single reading.
19585
+ ` + `- Corrections to earlier beliefs, recorded explicitly as corrections.
19586
+ ` + `
19587
+ ` + `A single day's log, weight reading, or session is evidence, not an observation. Record one only when it establishes or changes a standing pattern, target, or constraint — then fold it into the observation for that pattern and say what changed and roughly when.
19588
+ ` + `
19589
+ ` + `Granularity: one observation per habit, target, constraint, or trend. Aggregate repeated daily evidence into the observation for that pattern rather than creating one per day, and keep training, nutrition, and sleep as separate observations.
19590
+ ` + `
19591
+ ` + "Word observations as the person's own pattern and framing, never as a verdict on them."
19485
19592
  },
19486
19593
  "executive-assistant": {
19487
- disposition: { skepticism: 4, literalism: 4, empathy: 3 }
19594
+ disposition: { skepticism: 4, literalism: 4, empathy: 3 },
19595
+ observations_mission: `You consolidate the memory of an executive assistant working for one person. This bank records that person's commitments, people, and standing arrangements.
19596
+ ` + `
19597
+ ` + `Synthesise into durable observations:
19598
+ ` + `- Standing rules and preferences: how they want things scheduled, written, and filed, and when they want to be interrupted.
19599
+ ` + `- People and organisations, and the relationship: who they are, what they are involved in, how to reach them.
19600
+ ` + `- Recurring commitments and routines, and the constraints around them.
19601
+ ` + `- Obligations and their state: what was promised to whom, the deadline, and what is still outstanding.
19602
+ ` + `- Decisions made and decisions deferred, with the reasoning and the trade accepted.
19603
+ ` + `- Corrections to earlier beliefs, recorded explicitly as corrections.
19604
+ ` + `
19605
+ ` + `Live commitment state IS durable knowledge here, not ephemeral chatter. An outstanding obligation, a travel window, an unanswered request, a "currently X" arrangement — these are precisely what this agent must recall later. Keep them, and embed the date inside the observation text so a later reader can judge staleness. Do not drop them as ephemeral.
19606
+ ` + `
19607
+ ` + `Granularity: one observation per person, arrangement, or obligation. Aggregate repeated mentions into that observation rather than creating siblings; never merge two different people or two different commitments into one.
19608
+ ` + `
19609
+ ` + "Do not synthesise from transcript exhaust: tool calls and their results, message or event identifiers, or narration of what the assistant did."
19488
19610
  },
19489
19611
  coding: {
19490
- disposition: { skepticism: 4, literalism: 5, empathy: 2 }
19612
+ disposition: { skepticism: 4, literalism: 5, empathy: 2 },
19613
+ observations_mission: `You consolidate the memory of a software-engineering agent. This bank records real work on real codebases.
19614
+ ` + `
19615
+ ` + `Synthesise into durable observations:
19616
+ ` + `- Architecture and design decisions, each with its rationale and the trade accepted.
19617
+ ` + `- Root causes, with the evidence chain, and negative results — what was ruled out matters as much as what was found.
19618
+ ` + `- How the repository works: build, test, and lint commands, conventions, CI gates, and where things live.
19619
+ ` + `- Outcomes of code work: issue and PR numbers, what changed, whether it merged, what review found.
19620
+ ` + `- The user's standing rules, preferences, and corrections to this agent's behaviour.
19621
+ ` + `- Corrections to earlier beliefs, recorded explicitly as corrections.
19622
+ ` + `
19623
+ ` + `Repository and service state IS durable knowledge here, not ephemeral chatter. Versions, a failing gate, an open PR, a measured number, a "currently X" claim — these are precisely what this agent must recall later. Keep them, and embed the date inside the observation text so a later reader can judge staleness. Do not drop them as ephemeral.
19624
+ ` + `
19625
+ ` + `Granularity: one observation per distinct decision, cause, convention, or work item. Aggregate repeated evidence about the same one into that observation rather than creating siblings; never merge two separate decisions into a single summary.
19626
+ ` + `
19627
+ ` + "Do not synthesise from transcript exhaust: tool calls and their results, scratch paths, session or request identifiers, or narration of what the agent did. Prefer specific and falsifiable — naming the file, the number, the commit, or the decision beats summarising the topic."
19491
19628
  }
19492
19629
  };
19493
19630
  // src/agents/reconcile-default-skills.ts