switchroom 0.19.24 → 0.19.25
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.
- package/dist/agent-scheduler/index.js +15 -6
- package/dist/auth-broker/index.js +85 -27
- package/dist/cli/autoaccept-poll.js +0 -1
- package/dist/cli/drive-write-pretool.mjs +5 -0
- package/dist/cli/ms-365-write-pretool.mjs +5 -0
- package/dist/cli/notion-write-pretool.mjs +15 -5
- package/dist/cli/switchroom.js +2690 -1415
- package/dist/host-control/main.js +84 -28
- package/dist/vault/approvals/kernel-server.js +83 -27
- package/dist/vault/broker/server.js +249 -70
- package/examples/switchroom.yaml +1 -1
- package/package.json +1 -1
- package/profiles/_base/start.sh.hbs +52 -13
- package/skills/switchroom-health/SKILL.md +19 -0
- package/skills/switchroom-status/SKILL.md +1 -1
- package/telegram-plugin/auth-snapshot-format.ts +9 -2
- package/telegram-plugin/dist/gateway/gateway.js +5757 -5689
- package/telegram-plugin/quota-bar-format.ts +4 -1
- package/telegram-plugin/tests/auth-snapshot-format.test.ts +42 -0
- package/telegram-plugin/tests/quota-bar-format.test.ts +50 -0
- package/telegram-plugin/tests/secret-detect-false-positives.test.ts +1 -1
- package/vendor/hindsight-memory/scripts/lib/config.py +61 -19
- package/vendor/hindsight-memory/scripts/lib/content.py +376 -1
- package/vendor/hindsight-memory/scripts/lib/english_words.txt +10799 -0
- package/vendor/hindsight-memory/scripts/recall.py +503 -252
- package/vendor/hindsight-memory/scripts/tests/test_recall_bank_slots.py +509 -0
- package/vendor/hindsight-memory/scripts/tests/test_recall_envelope_strip_telemetry.py +22 -5
- package/vendor/hindsight-memory/scripts/tests/test_recall_error_text.py +147 -0
- package/vendor/hindsight-memory/scripts/tests/test_recall_hook_budget.py +266 -0
- package/vendor/hindsight-memory/scripts/tests/test_recall_integration.py +0 -401
- package/vendor/hindsight-memory/scripts/tests/test_recall_no_lexical_gate.py +261 -0
- package/vendor/hindsight-memory/scripts/tests/test_recall_query_shaping.py +473 -0
- package/vendor/hindsight-memory/scripts/tests/test_recall_transcript_fallback.py +25 -8
- package/vendor/hindsight-memory/tests/test_content.py +218 -0
|
@@ -4164,7 +4164,11 @@ var init_schema = __esm(() => {
|
|
|
4164
4164
|
recall: exports_external.object({
|
|
4165
4165
|
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
4166
|
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."),
|
|
4167
|
-
|
|
4167
|
+
query_max_tokens: exports_external.number().int().min(0).optional().describe("Cap on the number of DISTINCT BM25 terms the recall hook may " + "put on the wire. `recallMaxQueryChars` bounds characters, which " + "is not the cost driver: Hindsight OR-joins every query token " + "into one tsquery and Postgres native FTS ranks the entire " + "matched set before the top-60 heapsort, so cost tracks TERMS. " + "An 800-char composed query is ~96 distinct terms and matched " + "119,510 of 135,565 rows on the `overlord` bank (14.0s for the " + "3-arm " + "BM25 UNION), past the per-bank timeout — 96.8% of that agent's " + "own-bank recalls returned nothing. Plugin default is 24 " + "(measured 48,433 rows / 2.7s on the same bank). Terms are " + "chosen recency-first (the latest turn beats prior context), " + "then by selectivity. 0 disables shaping (rollback lever)."),
|
|
4168
|
+
query_stop_terms: exports_external.array(exports_external.string().min(1).regex(/^[\w./-]+$/)).optional().describe("Extra terms dropped from the BM25 recall query, on top of the " + "built-in English stopword list. For BANK-SPECIFIC " + "high-document-frequency words a generic stoplist cannot know " + "about: on `overlord`, `switchroom` matches 20% of the bank and " + "`agent` another 20%, purely because that is what the corpus is " + "about, and each such term drags tens of thousands of rows into " + "the ranking. Defaults to []."),
|
|
4169
|
+
request_timeout_seconds: exports_external.number().int().min(1).optional().describe("Per-bank HTTP read timeout, in seconds, for one recall " + "request. Plugin default is 12, matching the UserPromptSubmit " + "hook ceiling; the shared `recallParallelDeadlineSeconds` (10) " + "is the tighter outer guard in the default configuration, so " + "this is a per-request safety net. Was a hardcoded 8 in the " + "plugin before #3757."),
|
|
4170
|
+
own_bank_min_slots: exports_external.number().int().min(0).optional().describe("Slots inside `max_memories` reserved as a FLOOR for the agent's " + "own bank when recall fans out to more than one bank. The merged " + "set is sorted globally by relevance and head-sliced, which is " + "winner-take-all across banks: when both banks return more " + "candidates than the cap, one bank's score distribution can fill " + "every slot and the agent gets a dossier about its operator with " + "none of its own session memory. A floor, not a quota: at most " + "this many slots, only if the own bank returned that many, and " + "only up to HALF the cap shared with `additional_bank_min_slots` " + "— the rest is always won on pure relevance, so composition still " + "moves with the scores. Fixes score-based crowd-out only; a " + "timed-out bank returns no candidates and reservation is a no-op " + "there. 0 disables (default). Switchroom-managed agents use 2 " + "against the fleet-deployed cap of 6."),
|
|
4171
|
+
additional_bank_min_slots: exports_external.number().int().min(0).optional().describe("Slots inside `max_memories` reserved as a FLOOR for the " + "additional (profile / shared / sender) banks. Symmetric with " + "`own_bank_min_slots` — same floor-not-quota semantics, and the " + "two share the same half-of-cap reservation budget. When they sum " + "above that budget the own-bank floor is honoured first. 0 " + "disables (default). Switchroom-managed agents use 1 against the " + "fleet-deployed cap of 6. Observe `injected_own_bank_count` / " + "`injected_additional_bank_count` via " + "`switchroom memory recall-log`."),
|
|
4168
4172
|
types: exports_external.array(exports_external.string()).optional().describe("Hindsight fact types to recall. Switchroom default is " + '["world", "experience", "observation"] — the synthesized ' + "`observation` tier is on by default. Set to " + '["world", "experience"] to opt out of observation-backed ' + "recall for this agent (or fleet-wide under defaults)."),
|
|
4169
4173
|
additional_banks: exports_external.array(exports_external.string()).optional().describe("Extra Hindsight banks to recall from on every turn, merged into " + "the agent's own bank results — e.g. a shared operator/household " + "profile bank authored via `switchroom memory profile`. Each is " + "recalled with an 8s timeout and is non-fatal on failure. Stays " + "within the single tenant: all banks are the operator's data, in " + "the operator's Hindsight instance (see the `single-tenant` " + "invariant). Defaults to [] (no extra banks)."),
|
|
4170
4174
|
sender_banks: exports_external.record(exports_external.string(), exports_external.string()).optional().describe("Per-speaker recall routing: a map of Telegram sender → extra " + "recall bank. When a message arrives, the agent also recalls the " + "speaker's bank (matched by Telegram username — a leading @ is " + "optional — or numeric user_id), merged " + "into its own results — so each trusted user gets their own " + "profile context. Additive recall scoping within the single " + "tenant: never an access boundary (who may drive an agent stays " + "the per-agent user assignment in `access.allowFrom`). Author the " + "banks via `switchroom memory profile`."),
|
|
@@ -4389,7 +4393,7 @@ var init_schema = __esm(() => {
|
|
|
4389
4393
|
reflect: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `reflect` LLM op (synthesis / mental-model " + "refresh). Emits `HINDSIGHT_API_REFLECT_LLM_*`. Absent → uses global."),
|
|
4390
4394
|
consolidation: HindsightPerOpLlmSchema.optional().describe("Per-op override for the `consolidation` LLM op (background memory " + "merge). Emits `HINDSIGHT_API_CONSOLIDATION_LLM_*`. Absent → global.")
|
|
4391
4395
|
}).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."),
|
|
4392
|
-
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, " + "RECALL_MAX_CANDIDATES_PER_SOURCE, LINK_EXPANSION_PER_ENTITY_LIMIT, " + "LINK_EXPANSION_TIMEOUT, LLM_REASONING_EFFORT), 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), 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).")
|
|
4396
|
+
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).")
|
|
4393
4397
|
});
|
|
4394
4398
|
MicrosoftWorkspaceConfigSchema = exports_external.object({
|
|
4395
4399
|
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)."),
|
|
@@ -4525,7 +4529,11 @@ var init_schema = __esm(() => {
|
|
|
4525
4529
|
recall: exports_external.object({
|
|
4526
4530
|
max_memories: exports_external.number().int().min(0).optional(),
|
|
4527
4531
|
cache_ttl_secs: exports_external.number().int().min(0).optional(),
|
|
4528
|
-
|
|
4532
|
+
query_max_tokens: exports_external.number().int().min(0).optional(),
|
|
4533
|
+
query_stop_terms: exports_external.array(exports_external.string().min(1).regex(/^[\w./-]+$/)).optional(),
|
|
4534
|
+
request_timeout_seconds: exports_external.number().int().min(1).optional(),
|
|
4535
|
+
own_bank_min_slots: exports_external.number().int().min(0).optional(),
|
|
4536
|
+
additional_bank_min_slots: exports_external.number().int().min(0).optional(),
|
|
4529
4537
|
additional_banks: exports_external.array(exports_external.string()).optional(),
|
|
4530
4538
|
sender_banks: exports_external.record(exports_external.string(), exports_external.string()).optional()
|
|
4531
4539
|
}).optional()
|
|
@@ -4559,7 +4567,8 @@ var init_schema = __esm(() => {
|
|
|
4559
4567
|
memory: exports_external.string().regex(/^\d+(\.\d+)?[kmgKMG]?$/, "memory must be a Docker size string like '6g', '512m', '1.5g'").optional().describe("Hard memory cap (Docker `mem_limit` → cgroup memory.max). When the " + "container exceeds this, the kernel OOM-kills processes in the cgroup. " + "Format: '6g', '1.5g', '512m'. When unset at every cascade layer the " + "compose generator falls back to the hard-coded per-profile defaults " + "in src/agents/compose.ts (klanker 6g, coding 2g, conversational 1.5g, " + "lightweight 1g, default 1.5g)."),
|
|
4560
4568
|
memory_reservation: exports_external.string().regex(/^\d+(\.\d+)?[kmgKMG]?$/, "memory_reservation must be a Docker size string like '4g', '256m'").optional().describe("Soft memory floor (Docker `mem_reservation` → cgroup memory.low). " + "Under host-wide memory pressure, the kernel protects at least this " + "much from being reclaimed from the cgroup. Must be ≤ memory. Use to " + "keep an agent RAM-resident when the host has other tenants that " + "might push the box (Coolify apps, build jobs). Default: unset."),
|
|
4561
4569
|
pids_limit: exports_external.number().int().positive().optional().describe("Max processes the cgroup can spawn (cgroup pids.max). Prevents " + "fork bombs and runaway test runners. Counts every process in the " + "cgroup including bash subprocesses, claude itself, sidecars, and " + "any test/build worker. A typical agent at idle uses ~30 PIDs; " + "`npm test`-style workloads can spike to 200+. Set generously " + "(2000 is a comfortable cap for test-running agents). Default: " + "unset (no cgroup pid cap)."),
|
|
4562
|
-
cpus: exports_external.number().positive().optional().describe("CPU quota (Docker `cpus`). Fractional values OK (e.g. 0.5, 2.0). " + "When unset at every cascade layer the compose generator falls " + "back to the per-profile default (klanker/coding 2.0, default 1.0, " + "lightweight 0.5).")
|
|
4570
|
+
cpus: exports_external.number().positive().optional().describe("CPU quota (Docker `cpus`). Fractional values OK (e.g. 0.5, 2.0). " + "When unset at every cascade layer the compose generator falls " + "back to the per-profile default (klanker/coding 2.0, default 1.0, " + "lightweight 0.5)."),
|
|
4571
|
+
tmp_size: exports_external.string().regex(/^\d+(\.\d+)?[kmgKMG]?$/, "tmp_size must be a Docker size string like '1g', '4g', '512m'").refine((v) => parseFloat(v) > 0, "tmp_size must be greater than zero").optional().describe("Size of the agent container's RAM-backed `/tmp` (Docker " + "`tmpfs: - /tmp:size=<this>,mode=1777`). The container root FS is " + "read-only, so /tmp is the only scratch space the agent and its " + "sub-agents get for repo clones and toolchain caches (bunx/npx/pip) " + "— a fan-out of several sub-agents exhausts the 1g default. A tmpfs " + "only consumes host RAM for the pages actually written, so raising " + "the ceiling costs nothing until it is used; those pages are still " + "charged to the container's `memory` cap, so raise both together. " + "Format: '1g', '4g', '512m'. Default when unset at every cascade " + "layer: '1g'.")
|
|
4563
4572
|
}).optional().describe("Per-agent resource limits. Cascades through defaults → profile → " + "per-agent with per-field merge (agent wins on each field independently). " + "Any field left unset at every layer falls back to the hard-coded " + "per-profile defaults in src/agents/compose.ts."),
|
|
4564
4573
|
experimental: exports_external.object({
|
|
4565
4574
|
legacy_pty: exports_external.boolean().optional().describe("Opt out of the default tmux supervisor (#725) and run the agent under " + "the legacy PTY supervisor instead. Default: false (tmux is the default)."),
|
|
@@ -4652,7 +4661,8 @@ var init_schema = __esm(() => {
|
|
|
4652
4661
|
memory: exports_external.string().regex(/^\d+(\.\d+)?[kmgKMG]?$/).optional(),
|
|
4653
4662
|
memory_reservation: exports_external.string().regex(/^\d+(\.\d+)?[kmgKMG]?$/).optional(),
|
|
4654
4663
|
pids_limit: exports_external.number().int().positive().optional(),
|
|
4655
|
-
cpus: exports_external.number().positive().optional()
|
|
4664
|
+
cpus: exports_external.number().positive().optional(),
|
|
4665
|
+
tmp_size: exports_external.string().regex(/^\d+(\.\d+)?[kmgKMG]?$/, "tmp_size must be a Docker size string like '1g', '4g', '512m'").refine((v) => parseFloat(v) > 0, "tmp_size must be greater than zero").optional()
|
|
4656
4666
|
}).optional()
|
|
4657
4667
|
}).superRefine((agent, ctx) => {
|
|
4658
4668
|
if (agent.dm_only !== true)
|
|
@@ -18225,7 +18235,7 @@ var require_lib = __commonJS((exports, module) => {
|
|
|
18225
18235
|
|
|
18226
18236
|
// src/vault/broker/server.ts
|
|
18227
18237
|
import * as net from "node:net";
|
|
18228
|
-
import { mkdirSync as
|
|
18238
|
+
import { mkdirSync as mkdirSync8, chmodSync as chmodSync5, chownSync as chownSync2, existsSync as existsSync12, readFileSync as readFileSync12, readdirSync as readdirSync5, statSync as statSync7, unlinkSync as unlinkSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
18229
18239
|
|
|
18230
18240
|
// src/agents/compose.ts
|
|
18231
18241
|
init_schema();
|
|
@@ -18867,6 +18877,27 @@ function assertPositive(value, label) {
|
|
|
18867
18877
|
// src/setup/host-capabilities.ts
|
|
18868
18878
|
init_paths();
|
|
18869
18879
|
|
|
18880
|
+
// src/setup/hindsight-pg-defaults.ts
|
|
18881
|
+
var HINDSIGHT_PG_MEM_LIMIT_MIB_FOR_DERIVATION = 8 * 1024;
|
|
18882
|
+
var HINDSIGHT_PG_APP_ANON_MIB = 2560;
|
|
18883
|
+
var HINDSIGHT_PG_PAGE_CACHE_FLOOR_MIB = 2048;
|
|
18884
|
+
var HINDSIGHT_PG_SHARED_BUFFERS_BUDGET_MIB = HINDSIGHT_PG_MEM_LIMIT_MIB_FOR_DERIVATION - HINDSIGHT_PG_APP_ANON_MIB - HINDSIGHT_PG_PAGE_CACHE_FLOOR_MIB;
|
|
18885
|
+
var HINDSIGHT_PG_DEFAULT_SHARED_BUFFERS_MIB = 1536;
|
|
18886
|
+
var HINDSIGHT_PG_DEFAULT_EFFECTIVE_CACHE_SIZE_MIB = 4096;
|
|
18887
|
+
function pgMib(mib) {
|
|
18888
|
+
return `${mib}MB`;
|
|
18889
|
+
}
|
|
18890
|
+
var HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE_ENV = "SWITCHROOM_HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE";
|
|
18891
|
+
var HINDSIGHT_PG_SHARED_BUFFERS_ENV = "SWITCHROOM_HINDSIGHT_PG_SHARED_BUFFERS";
|
|
18892
|
+
var HINDSIGHT_PG_DEFAULTS = [
|
|
18893
|
+
[
|
|
18894
|
+
HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE_ENV,
|
|
18895
|
+
pgMib(HINDSIGHT_PG_DEFAULT_EFFECTIVE_CACHE_SIZE_MIB)
|
|
18896
|
+
],
|
|
18897
|
+
[HINDSIGHT_PG_SHARED_BUFFERS_ENV, pgMib(HINDSIGHT_PG_DEFAULT_SHARED_BUFFERS_MIB)]
|
|
18898
|
+
];
|
|
18899
|
+
var HINDSIGHT_PG_ENV_KEYS = new Set(HINDSIGHT_PG_DEFAULTS.map(([k]) => k));
|
|
18900
|
+
|
|
18870
18901
|
// src/setup/hindsight-perf-defaults.ts
|
|
18871
18902
|
var HINDSIGHT_RERANKER_MAX_CANDIDATES_FOR_DERIVATION = 150;
|
|
18872
18903
|
var HINDSIGHT_DEFAULT_RECALL_MAX_CANDIDATES_PER_SOURCE = Math.ceil(HINDSIGHT_RERANKER_MAX_CANDIDATES_FOR_DERIVATION * 0.4);
|
|
@@ -18881,6 +18912,15 @@ var HINDSIGHT_DEFAULT_RERANKER_LOCAL_BATCH_SIZE = 128;
|
|
|
18881
18912
|
var HINDSIGHT_DEFAULT_LLM_STRICT_SCHEMA = "true";
|
|
18882
18913
|
var HINDSIGHT_DEFAULT_LLM_MAX_RETRIES = 2;
|
|
18883
18914
|
var HINDSIGHT_DEFAULT_CONSOLIDATION_LLM_PARALLELISM = 2;
|
|
18915
|
+
var HINDSIGHT_DEFAULT_MAX_OBSERVATIONS_PER_SCOPE = 1000;
|
|
18916
|
+
var HINDSIGHT_DEFAULT_RERANKER_BUCKET_BATCHING = "true";
|
|
18917
|
+
var HINDSIGHT_DEFAULT_RERANKER_MAX_CANDIDATES = 150;
|
|
18918
|
+
var HINDSIGHT_DEFAULT_RERANKER_LOCAL_MAX_CONCURRENT = 4;
|
|
18919
|
+
var HINDSIGHT_DEFAULT_RECALL_MAX_CONCURRENT = 8;
|
|
18920
|
+
var HINDSIGHT_DEFAULT_REFLECT_WALL_TIMEOUT_S = 600;
|
|
18921
|
+
var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_MEMORIES_PER_ROUND = 500;
|
|
18922
|
+
var HINDSIGHT_DEFAULT_CONSOLIDATION_SLOT_LIMIT = 6;
|
|
18923
|
+
var HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_SLOTS = 1;
|
|
18884
18924
|
var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
|
|
18885
18925
|
[
|
|
18886
18926
|
"HINDSIGHT_API_RECALL_MAX_CANDIDATES_PER_SOURCE",
|
|
@@ -18898,6 +18938,42 @@ var HINDSIGHT_PERF_DEFAULTS_UNGATED = [
|
|
|
18898
18938
|
[
|
|
18899
18939
|
"HINDSIGHT_API_CONSOLIDATION_LLM_PARALLELISM",
|
|
18900
18940
|
String(HINDSIGHT_DEFAULT_CONSOLIDATION_LLM_PARALLELISM)
|
|
18941
|
+
],
|
|
18942
|
+
[
|
|
18943
|
+
"HINDSIGHT_API_MAX_OBSERVATIONS_PER_SCOPE",
|
|
18944
|
+
String(HINDSIGHT_DEFAULT_MAX_OBSERVATIONS_PER_SCOPE)
|
|
18945
|
+
],
|
|
18946
|
+
[
|
|
18947
|
+
"HINDSIGHT_API_RERANKER_LOCAL_BUCKET_BATCHING",
|
|
18948
|
+
HINDSIGHT_DEFAULT_RERANKER_BUCKET_BATCHING
|
|
18949
|
+
],
|
|
18950
|
+
[
|
|
18951
|
+
"HINDSIGHT_API_RERANKER_MAX_CANDIDATES",
|
|
18952
|
+
String(HINDSIGHT_DEFAULT_RERANKER_MAX_CANDIDATES)
|
|
18953
|
+
],
|
|
18954
|
+
[
|
|
18955
|
+
"HINDSIGHT_API_RERANKER_LOCAL_MAX_CONCURRENT",
|
|
18956
|
+
String(HINDSIGHT_DEFAULT_RERANKER_LOCAL_MAX_CONCURRENT)
|
|
18957
|
+
],
|
|
18958
|
+
[
|
|
18959
|
+
"HINDSIGHT_API_RECALL_MAX_CONCURRENT",
|
|
18960
|
+
String(HINDSIGHT_DEFAULT_RECALL_MAX_CONCURRENT)
|
|
18961
|
+
],
|
|
18962
|
+
[
|
|
18963
|
+
"HINDSIGHT_API_REFLECT_WALL_TIMEOUT",
|
|
18964
|
+
String(HINDSIGHT_DEFAULT_REFLECT_WALL_TIMEOUT_S)
|
|
18965
|
+
],
|
|
18966
|
+
[
|
|
18967
|
+
"HINDSIGHT_API_WORKER_CONSOLIDATION_MAX_SLOTS",
|
|
18968
|
+
String(HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_SLOTS)
|
|
18969
|
+
],
|
|
18970
|
+
[
|
|
18971
|
+
"HINDSIGHT_API_WORKER_CONSOLIDATION_SLOT_LIMIT",
|
|
18972
|
+
String(HINDSIGHT_DEFAULT_CONSOLIDATION_SLOT_LIMIT)
|
|
18973
|
+
],
|
|
18974
|
+
[
|
|
18975
|
+
"HINDSIGHT_API_CONSOLIDATION_MAX_MEMORIES_PER_ROUND",
|
|
18976
|
+
String(HINDSIGHT_DEFAULT_CONSOLIDATION_MAX_MEMORIES_PER_ROUND)
|
|
18901
18977
|
]
|
|
18902
18978
|
];
|
|
18903
18979
|
var HINDSIGHT_PERF_DEFAULTS_GPU = [
|
|
@@ -18921,7 +18997,8 @@ var HINDSIGHT_PERF_DEFAULTS_LOCAL_LLM = [
|
|
|
18921
18997
|
["HINDSIGHT_API_LLM_MAX_RETRIES", String(HINDSIGHT_DEFAULT_LLM_MAX_RETRIES)]
|
|
18922
18998
|
];
|
|
18923
18999
|
var HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS = new Set([
|
|
18924
|
-
"HINDSIGHT_API_WORKER_CONSOLIDATION_BANK_PRIORITY"
|
|
19000
|
+
"HINDSIGHT_API_WORKER_CONSOLIDATION_BANK_PRIORITY",
|
|
19001
|
+
"HINDSIGHT_CE_DECISIVE_RELATIVE_GAP"
|
|
18925
19002
|
]);
|
|
18926
19003
|
var HINDSIGHT_PERF_ENV_KEYS = new Set([
|
|
18927
19004
|
...[
|
|
@@ -18932,27 +19009,6 @@ var HINDSIGHT_PERF_ENV_KEYS = new Set([
|
|
|
18932
19009
|
...HINDSIGHT_PERF_OVERRIDE_ONLY_KEYS
|
|
18933
19010
|
]);
|
|
18934
19011
|
|
|
18935
|
-
// src/setup/hindsight-pg-defaults.ts
|
|
18936
|
-
var HINDSIGHT_PG_MEM_LIMIT_MIB_FOR_DERIVATION = 8 * 1024;
|
|
18937
|
-
var HINDSIGHT_PG_APP_ANON_MIB = 2560;
|
|
18938
|
-
var HINDSIGHT_PG_PAGE_CACHE_FLOOR_MIB = 2048;
|
|
18939
|
-
var HINDSIGHT_PG_SHARED_BUFFERS_BUDGET_MIB = HINDSIGHT_PG_MEM_LIMIT_MIB_FOR_DERIVATION - HINDSIGHT_PG_APP_ANON_MIB - HINDSIGHT_PG_PAGE_CACHE_FLOOR_MIB;
|
|
18940
|
-
var HINDSIGHT_PG_DEFAULT_SHARED_BUFFERS_MIB = 1536;
|
|
18941
|
-
var HINDSIGHT_PG_DEFAULT_EFFECTIVE_CACHE_SIZE_MIB = 4096;
|
|
18942
|
-
function pgMib(mib) {
|
|
18943
|
-
return `${mib}MB`;
|
|
18944
|
-
}
|
|
18945
|
-
var HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE_ENV = "SWITCHROOM_HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE";
|
|
18946
|
-
var HINDSIGHT_PG_SHARED_BUFFERS_ENV = "SWITCHROOM_HINDSIGHT_PG_SHARED_BUFFERS";
|
|
18947
|
-
var HINDSIGHT_PG_DEFAULTS = [
|
|
18948
|
-
[
|
|
18949
|
-
HINDSIGHT_PG_EFFECTIVE_CACHE_SIZE_ENV,
|
|
18950
|
-
pgMib(HINDSIGHT_PG_DEFAULT_EFFECTIVE_CACHE_SIZE_MIB)
|
|
18951
|
-
],
|
|
18952
|
-
[HINDSIGHT_PG_SHARED_BUFFERS_ENV, pgMib(HINDSIGHT_PG_DEFAULT_SHARED_BUFFERS_MIB)]
|
|
18953
|
-
];
|
|
18954
|
-
var HINDSIGHT_PG_ENV_KEYS = new Set(HINDSIGHT_PG_DEFAULTS.map(([k]) => k));
|
|
18955
|
-
|
|
18956
19012
|
// src/setup/hindsight-context-budget.ts
|
|
18957
19013
|
var HINDSIGHT_UPSTREAM_RETAIN_CHUNK_SIZE = 3000;
|
|
18958
19014
|
var HINDSIGHT_RETAIN_MAX_COMPLETION_FLOOR = HINDSIGHT_UPSTREAM_RETAIN_CHUNK_SIZE + 72;
|
|
@@ -19892,6 +19948,73 @@ function migrateLegacyGrantsDbLocation(newDbPath = getGrantsDbPath(), deps) {
|
|
|
19892
19948
|
// src/agents/compose.ts
|
|
19893
19949
|
var BIND_MOUNT_EXACT_SOURCE_DENY = new Set(["/var/run/docker.sock"]);
|
|
19894
19950
|
|
|
19951
|
+
// src/vault/broker/write-token-file.ts
|
|
19952
|
+
import { chownSync, mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "node:fs";
|
|
19953
|
+
import { join as join6 } from "node:path";
|
|
19954
|
+
class TokenFileWriteError extends Error {
|
|
19955
|
+
tokenPath;
|
|
19956
|
+
constructor(tokenPath, message, options) {
|
|
19957
|
+
super(message, options);
|
|
19958
|
+
this.name = "TokenFileWriteError";
|
|
19959
|
+
this.tokenPath = tokenPath;
|
|
19960
|
+
}
|
|
19961
|
+
}
|
|
19962
|
+
function writeAgentTokenFile(args, deps = {}) {
|
|
19963
|
+
const { agentsDir, agent, token } = args;
|
|
19964
|
+
const mkdir = deps.mkdir ?? ((p) => {
|
|
19965
|
+
mkdirSync4(p, { recursive: true });
|
|
19966
|
+
});
|
|
19967
|
+
const writeFile = deps.writeFile ?? ((p, d) => {
|
|
19968
|
+
writeFileSync2(p, d, { mode: 384 });
|
|
19969
|
+
});
|
|
19970
|
+
const readFile = deps.readFile ?? ((p) => readFileSync7(p, "utf8"));
|
|
19971
|
+
const chown = deps.chown ?? ((p, uid, gid) => {
|
|
19972
|
+
chownSync(p, uid, gid);
|
|
19973
|
+
});
|
|
19974
|
+
const agentUid = deps.agentUid ?? allocateAgentUid;
|
|
19975
|
+
const tokenDir = join6(agentsDir, agent);
|
|
19976
|
+
const tokenPath = join6(tokenDir, ".vault-token");
|
|
19977
|
+
try {
|
|
19978
|
+
mkdir(tokenDir);
|
|
19979
|
+
} catch (err) {
|
|
19980
|
+
throw new TokenFileWriteError(tokenPath, `cannot create agent token dir ${tokenDir}: ${errText(err)}`, { cause: err });
|
|
19981
|
+
}
|
|
19982
|
+
let preExisting;
|
|
19983
|
+
try {
|
|
19984
|
+
readFile(tokenPath);
|
|
19985
|
+
preExisting = true;
|
|
19986
|
+
} catch {
|
|
19987
|
+
preExisting = false;
|
|
19988
|
+
}
|
|
19989
|
+
try {
|
|
19990
|
+
writeFile(tokenPath, token);
|
|
19991
|
+
} catch (err) {
|
|
19992
|
+
throw new TokenFileWriteError(tokenPath, `cannot write token file ${tokenPath}: ${errText(err)}`, { cause: err });
|
|
19993
|
+
}
|
|
19994
|
+
let onDisk;
|
|
19995
|
+
try {
|
|
19996
|
+
onDisk = readFile(tokenPath);
|
|
19997
|
+
} catch (err) {
|
|
19998
|
+
throw new TokenFileWriteError(tokenPath, `token file ${tokenPath} is unreadable after write: ${errText(err)}`, { cause: err });
|
|
19999
|
+
}
|
|
20000
|
+
if (onDisk !== token) {
|
|
20001
|
+
throw new TokenFileWriteError(tokenPath, `token file ${tokenPath} did not verify after write ` + `(${onDisk.length} bytes on disk, ${token.length} expected)`);
|
|
20002
|
+
}
|
|
20003
|
+
let chownWarning = null;
|
|
20004
|
+
if (!preExisting) {
|
|
20005
|
+
try {
|
|
20006
|
+
const uid = agentUid(agent);
|
|
20007
|
+
chown(tokenPath, uid, uid);
|
|
20008
|
+
} catch (err) {
|
|
20009
|
+
chownWarning = `token file ${tokenPath} created but chown to the agent UID failed: ` + `${errText(err)} (CAP_CHOWN missing?)`;
|
|
20010
|
+
}
|
|
20011
|
+
}
|
|
20012
|
+
return { tokenPath, chownWarning };
|
|
20013
|
+
}
|
|
20014
|
+
function errText(err) {
|
|
20015
|
+
return err instanceof Error ? err.message : String(err);
|
|
20016
|
+
}
|
|
20017
|
+
|
|
19895
20018
|
// src/vault/broker/server.ts
|
|
19896
20019
|
import { dirname as dirname7, resolve as resolve9, basename as basename5 } from "node:path";
|
|
19897
20020
|
import * as os3 from "node:os";
|
|
@@ -19904,23 +20027,23 @@ import {
|
|
|
19904
20027
|
existsSync as existsSync8,
|
|
19905
20028
|
fsyncSync as fsyncSync4,
|
|
19906
20029
|
lstatSync as lstatSync2,
|
|
19907
|
-
mkdirSync as
|
|
20030
|
+
mkdirSync as mkdirSync5,
|
|
19908
20031
|
openSync as openSync4,
|
|
19909
20032
|
closeSync as closeSync4,
|
|
19910
|
-
readFileSync as
|
|
20033
|
+
readFileSync as readFileSync8,
|
|
19911
20034
|
renameSync as renameSync4,
|
|
19912
20035
|
statSync as statSync4,
|
|
19913
20036
|
symlinkSync,
|
|
19914
20037
|
unlinkSync as unlinkSync3
|
|
19915
20038
|
} from "node:fs";
|
|
19916
20039
|
import { createHash as createHash2 } from "node:crypto";
|
|
19917
|
-
import { basename as basename3, dirname as dirname4, join as
|
|
20040
|
+
import { basename as basename3, dirname as dirname4, join as join7 } from "node:path";
|
|
19918
20041
|
function vaultLayoutPaths(home2) {
|
|
19919
|
-
const switchroomRoot =
|
|
20042
|
+
const switchroomRoot = join7(home2, ".switchroom");
|
|
19920
20043
|
return {
|
|
19921
|
-
oldPath:
|
|
19922
|
-
newPath:
|
|
19923
|
-
parent:
|
|
20044
|
+
oldPath: join7(switchroomRoot, "vault.enc"),
|
|
20045
|
+
newPath: join7(switchroomRoot, "vault", "vault.enc"),
|
|
20046
|
+
parent: join7(switchroomRoot, "vault"),
|
|
19924
20047
|
switchroomRoot
|
|
19925
20048
|
};
|
|
19926
20049
|
}
|
|
@@ -19969,7 +20092,7 @@ function runMigration(home2, opts) {
|
|
|
19969
20092
|
if (oldStat?.isFile() && !newExists) {
|
|
19970
20093
|
if (opts.dryRun)
|
|
19971
20094
|
return { kind: "migrated" };
|
|
19972
|
-
|
|
20095
|
+
mkdirSync5(parent, { recursive: true, mode: 448 });
|
|
19973
20096
|
const tempNew = `${newPath}.tmp`;
|
|
19974
20097
|
copyFileSync2(oldPath, tempNew);
|
|
19975
20098
|
chmodSync2(tempNew, 384);
|
|
@@ -19997,11 +20120,11 @@ function lstatSyncOrNull(path2) {
|
|
|
19997
20120
|
}
|
|
19998
20121
|
}
|
|
19999
20122
|
function sha256File(path2) {
|
|
20000
|
-
const data =
|
|
20123
|
+
const data = readFileSync8(path2);
|
|
20001
20124
|
return createHash2("sha256").update(data).digest("hex");
|
|
20002
20125
|
}
|
|
20003
20126
|
function atomicReplaceWithSymlink(target, linkTarget) {
|
|
20004
|
-
const tmp =
|
|
20127
|
+
const tmp = join7(dirname4(target), `.${basename3(target)}.symlink-tmp`);
|
|
20005
20128
|
if (existsSync8(tmp)) {
|
|
20006
20129
|
try {
|
|
20007
20130
|
unlinkSync3(tmp);
|
|
@@ -20037,9 +20160,9 @@ import {
|
|
|
20037
20160
|
closeSync as closeSync5,
|
|
20038
20161
|
existsSync as existsSync9,
|
|
20039
20162
|
fsyncSync as fsyncSync5,
|
|
20040
|
-
mkdirSync as
|
|
20163
|
+
mkdirSync as mkdirSync6,
|
|
20041
20164
|
openSync as openSync5,
|
|
20042
|
-
readFileSync as
|
|
20165
|
+
readFileSync as readFileSync9,
|
|
20043
20166
|
renameSync as renameSync5,
|
|
20044
20167
|
unlinkSync as unlinkSync4,
|
|
20045
20168
|
writeSync as writeSync4
|
|
@@ -20078,7 +20201,7 @@ function readMachineId() {
|
|
|
20078
20201
|
}
|
|
20079
20202
|
for (const path2 of [MACHINE_ID_PRIMARY, MACHINE_ID_FALLBACK]) {
|
|
20080
20203
|
try {
|
|
20081
|
-
const id =
|
|
20204
|
+
const id = readFileSync9(path2, "utf8").trim();
|
|
20082
20205
|
if (id.length > 0)
|
|
20083
20206
|
return id;
|
|
20084
20207
|
} catch {}
|
|
@@ -20120,7 +20243,7 @@ function readAutoUnlockFile(filePath) {
|
|
|
20120
20243
|
}
|
|
20121
20244
|
let blob;
|
|
20122
20245
|
try {
|
|
20123
|
-
blob =
|
|
20246
|
+
blob = readFileSync9(filePath);
|
|
20124
20247
|
} catch {
|
|
20125
20248
|
throw new AutoUnlockDecryptError("io");
|
|
20126
20249
|
}
|
|
@@ -20201,7 +20324,7 @@ function seedChain(path2) {
|
|
|
20201
20324
|
// src/vault/broker/test-isolation-guard.ts
|
|
20202
20325
|
import { mkdtempSync } from "node:fs";
|
|
20203
20326
|
import { homedir as homedir5, tmpdir } from "node:os";
|
|
20204
|
-
import { join as
|
|
20327
|
+
import { join as join8, resolve as resolve8, sep } from "node:path";
|
|
20205
20328
|
function isTestRuntime() {
|
|
20206
20329
|
return process.env.VITEST !== undefined;
|
|
20207
20330
|
}
|
|
@@ -20222,7 +20345,7 @@ function safeVaultPath(requestedPath) {
|
|
|
20222
20345
|
return requestedPath;
|
|
20223
20346
|
if (!isUnderRealSwitchroomHome(requestedPath))
|
|
20224
20347
|
return requestedPath;
|
|
20225
|
-
const redirected =
|
|
20348
|
+
const redirected = join8(mkdtempSync(join8(tmpdir(), "sw-test-vault-")), "vault.enc");
|
|
20226
20349
|
if (!warnedVault) {
|
|
20227
20350
|
warnedVault = true;
|
|
20228
20351
|
process.stderr.write(`[test-isolation guard] vault path redirected away from the ` + `production tree to an isolated tmpdir — a vault/broker test ` + `resolved its vault path inside ~/.switchroom. See CLAUDE.md ` + `"Vault & shared-state test discipline".
|
|
@@ -20238,7 +20361,7 @@ function safeAuditLogPath(requestedPath) {
|
|
|
20238
20361
|
if (!isUnderRealSwitchroomHome(requestedPath))
|
|
20239
20362
|
return requestedPath;
|
|
20240
20363
|
if (!cachedTmpAuditLog) {
|
|
20241
|
-
cachedTmpAuditLog =
|
|
20364
|
+
cachedTmpAuditLog = join8(mkdtempSync(join8(tmpdir(), "sw-test-audit-")), "vault-audit.log");
|
|
20242
20365
|
}
|
|
20243
20366
|
if (!warnedAudit) {
|
|
20244
20367
|
warnedAudit = true;
|
|
@@ -22384,6 +22507,37 @@ function listGrants(db, agent_slug) {
|
|
|
22384
22507
|
return rows.map(rowToGrant);
|
|
22385
22508
|
}
|
|
22386
22509
|
|
|
22510
|
+
// src/vault/broker/reap-token-file.ts
|
|
22511
|
+
import { readFileSync as readFileSync11, writeFileSync as writeFileSync4 } from "node:fs";
|
|
22512
|
+
import { join as join11 } from "node:path";
|
|
22513
|
+
var REAPABLE_REASONS = new Set(["grant-invalid", "grant-expired"]);
|
|
22514
|
+
function reapUnusableGrantToken(args, deps = {}) {
|
|
22515
|
+
const { agentsDir, agent, presentedToken, reason } = args;
|
|
22516
|
+
if (!REAPABLE_REASONS.has(reason))
|
|
22517
|
+
return "kept:reason-not-reapable";
|
|
22518
|
+
if (!agent)
|
|
22519
|
+
return "kept:no-agent-identity";
|
|
22520
|
+
const readFile = deps.readFile ?? ((p) => readFileSync11(p, "utf8"));
|
|
22521
|
+
const writeFile = deps.writeFile ?? ((p, d) => writeFileSync4(p, d, { mode: 384 }));
|
|
22522
|
+
const tokenPath = join11(agentsDir, agent, ".vault-token");
|
|
22523
|
+
let onDisk;
|
|
22524
|
+
try {
|
|
22525
|
+
onDisk = readFile(tokenPath);
|
|
22526
|
+
} catch {
|
|
22527
|
+
return "kept:nothing-on-disk";
|
|
22528
|
+
}
|
|
22529
|
+
if (onDisk.trim() === "")
|
|
22530
|
+
return "kept:nothing-on-disk";
|
|
22531
|
+
if (onDisk.trim() !== presentedToken.trim())
|
|
22532
|
+
return "kept:superseded";
|
|
22533
|
+
try {
|
|
22534
|
+
writeFile(tokenPath, "");
|
|
22535
|
+
} catch {
|
|
22536
|
+
return "kept:io-error";
|
|
22537
|
+
}
|
|
22538
|
+
return "reaped";
|
|
22539
|
+
}
|
|
22540
|
+
|
|
22387
22541
|
// src/vault/admin-only-keys.ts
|
|
22388
22542
|
function globToRegExp(pattern) {
|
|
22389
22543
|
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
@@ -22945,7 +23099,7 @@ class VaultBroker {
|
|
|
22945
23099
|
}
|
|
22946
23100
|
process.umask(63);
|
|
22947
23101
|
const parentDir = dirname7(this.socketPath);
|
|
22948
|
-
|
|
23102
|
+
mkdirSync8(parentDir, { recursive: true, mode: 448 });
|
|
22949
23103
|
try {
|
|
22950
23104
|
chmodSync5(parentDir, 448);
|
|
22951
23105
|
} catch {}
|
|
@@ -22985,7 +23139,7 @@ class VaultBroker {
|
|
|
22985
23139
|
return;
|
|
22986
23140
|
try {
|
|
22987
23141
|
if (ready) {
|
|
22988
|
-
|
|
23142
|
+
writeFileSync5(p, "", { mode: 384 });
|
|
22989
23143
|
} else if (existsSync12(p)) {
|
|
22990
23144
|
unlinkSync6(p);
|
|
22991
23145
|
}
|
|
@@ -23063,7 +23217,7 @@ class VaultBroker {
|
|
|
23063
23217
|
const dir = abs.slice(0, -"/sock".length);
|
|
23064
23218
|
if (existsSync12(dir)) {
|
|
23065
23219
|
try {
|
|
23066
|
-
|
|
23220
|
+
chownSync2(dir, 0, 0);
|
|
23067
23221
|
} catch {}
|
|
23068
23222
|
try {
|
|
23069
23223
|
chmodSync5(dir, 448);
|
|
@@ -23091,12 +23245,12 @@ class VaultBroker {
|
|
|
23091
23245
|
try {
|
|
23092
23246
|
agentUid = allocateAgentUid(agentName);
|
|
23093
23247
|
try {
|
|
23094
|
-
|
|
23248
|
+
chownSync2(abs, agentUid, agentUid);
|
|
23095
23249
|
} catch {}
|
|
23096
23250
|
if (abs.endsWith("/sock")) {
|
|
23097
23251
|
const dir = abs.slice(0, -"/sock".length);
|
|
23098
23252
|
try {
|
|
23099
|
-
|
|
23253
|
+
chownSync2(dir, agentUid, agentUid);
|
|
23100
23254
|
} catch {}
|
|
23101
23255
|
}
|
|
23102
23256
|
} catch {}
|
|
@@ -23123,7 +23277,7 @@ class VaultBroker {
|
|
|
23123
23277
|
} catch {}
|
|
23124
23278
|
if (agentUid !== null) {
|
|
23125
23279
|
try {
|
|
23126
|
-
|
|
23280
|
+
chownSync2(unlockAbs, agentUid, agentUid);
|
|
23127
23281
|
} catch {}
|
|
23128
23282
|
}
|
|
23129
23283
|
this.agentServers.set(unlockAbs, { server: unlockServer, agentName });
|
|
@@ -23158,7 +23312,7 @@ class VaultBroker {
|
|
|
23158
23312
|
return;
|
|
23159
23313
|
try {
|
|
23160
23314
|
if (existsSync12(this.vaultPath))
|
|
23161
|
-
|
|
23315
|
+
chownSync2(this.vaultPath, uid, uid);
|
|
23162
23316
|
} catch {}
|
|
23163
23317
|
}
|
|
23164
23318
|
bindOperatorListener(socketPath, operatorUid) {
|
|
@@ -23172,7 +23326,7 @@ class VaultBroker {
|
|
|
23172
23326
|
const dir = abs.slice(0, -"/sock".length);
|
|
23173
23327
|
if (existsSync12(dir)) {
|
|
23174
23328
|
try {
|
|
23175
|
-
|
|
23329
|
+
chownSync2(dir, 0, 0);
|
|
23176
23330
|
} catch {}
|
|
23177
23331
|
try {
|
|
23178
23332
|
chmodSync5(dir, 448);
|
|
@@ -23196,7 +23350,7 @@ class VaultBroker {
|
|
|
23196
23350
|
chmodSync5(abs, 384);
|
|
23197
23351
|
} catch {}
|
|
23198
23352
|
try {
|
|
23199
|
-
|
|
23353
|
+
chownSync2(abs, operatorUid, operatorUid);
|
|
23200
23354
|
} catch {}
|
|
23201
23355
|
const unlockServer = net.createServer((sock) => {
|
|
23202
23356
|
this._handleUnlockConnection(sock, true);
|
|
@@ -23207,12 +23361,12 @@ class VaultBroker {
|
|
|
23207
23361
|
chmodSync5(unlockAbs, 384);
|
|
23208
23362
|
} catch {}
|
|
23209
23363
|
try {
|
|
23210
|
-
|
|
23364
|
+
chownSync2(unlockAbs, operatorUid, operatorUid);
|
|
23211
23365
|
} catch {}
|
|
23212
23366
|
if (abs.endsWith("/sock")) {
|
|
23213
23367
|
const dir = abs.slice(0, -"/sock".length);
|
|
23214
23368
|
try {
|
|
23215
|
-
|
|
23369
|
+
chownSync2(dir, operatorUid, operatorUid);
|
|
23216
23370
|
} catch {}
|
|
23217
23371
|
try {
|
|
23218
23372
|
chmodSync5(dir, 448);
|
|
@@ -23514,6 +23668,14 @@ class VaultBroker {
|
|
|
23514
23668
|
socket.write(encodeResponse(errorResponse("DENIED", "grant-revoked")));
|
|
23515
23669
|
return;
|
|
23516
23670
|
}
|
|
23671
|
+
if (!grantResult.ok) {
|
|
23672
|
+
reapUnusableGrantToken({
|
|
23673
|
+
agentsDir: this.config ? resolveAgentsDir(this.config) : path5.join(os3.homedir(), ".switchroom", "agents"),
|
|
23674
|
+
agent: agentName,
|
|
23675
|
+
presentedToken: req.token,
|
|
23676
|
+
reason: grantResult.reason
|
|
23677
|
+
});
|
|
23678
|
+
}
|
|
23517
23679
|
}
|
|
23518
23680
|
if (isOperator) {
|
|
23519
23681
|
const entry2 = this.secrets[req.key];
|
|
@@ -24104,22 +24266,39 @@ class VaultBroker {
|
|
|
24104
24266
|
}
|
|
24105
24267
|
try {
|
|
24106
24268
|
const agentsDir = this.config ? resolveAgentsDir(this.config) : path5.join(os3.homedir(), ".switchroom", "agents");
|
|
24107
|
-
const
|
|
24108
|
-
|
|
24109
|
-
|
|
24110
|
-
|
|
24111
|
-
|
|
24112
|
-
|
|
24113
|
-
|
|
24114
|
-
const uid = allocateAgentUid(agent);
|
|
24115
|
-
chownSync(tokenPath, uid, uid);
|
|
24116
|
-
} catch (chownErr) {
|
|
24117
|
-
process.stderr.write(`[vault-broker] mint_grant: token written but chown failed for agent ${agent}: ${chownErr.message} (CAP_CHOWN missing?)
|
|
24269
|
+
const { chownWarning } = writeAgentTokenFile({
|
|
24270
|
+
agentsDir,
|
|
24271
|
+
agent,
|
|
24272
|
+
token: mintResult.token
|
|
24273
|
+
});
|
|
24274
|
+
if (chownWarning !== null) {
|
|
24275
|
+
process.stderr.write(`[vault-broker] mint_grant: ${chownWarning} (agent ${agent})
|
|
24118
24276
|
`);
|
|
24119
24277
|
}
|
|
24120
24278
|
} catch (err) {
|
|
24121
|
-
|
|
24279
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
24280
|
+
let rolledBack = false;
|
|
24281
|
+
let rollbackErr = null;
|
|
24282
|
+
try {
|
|
24283
|
+
rolledBack = revokeGrant(this.grantsDb, mintResult.id);
|
|
24284
|
+
} catch (revokeError) {
|
|
24285
|
+
rollbackErr = revokeError instanceof Error ? revokeError.message : String(revokeError);
|
|
24286
|
+
}
|
|
24287
|
+
const rollbackNote = rolledBack ? "grant rolled back (revoked)" : `GRANT ROLLBACK FAILED — revoke ${mintResult.id} manually${rollbackErr ? `: ${rollbackErr}` : ""}`;
|
|
24288
|
+
process.stderr.write(`[vault-broker] mint_grant: failed to write token file for agent ${agent}: ${msg}; ${rollbackNote}
|
|
24122
24289
|
`);
|
|
24290
|
+
this.auditLogger.write({
|
|
24291
|
+
ts: new Date().toISOString(),
|
|
24292
|
+
op: "mint_grant",
|
|
24293
|
+
caller: auditCaller,
|
|
24294
|
+
pid: auditPid,
|
|
24295
|
+
cgroup: auditCgroup,
|
|
24296
|
+
result: `error:token-write-failed:${msg}`,
|
|
24297
|
+
method: "grant",
|
|
24298
|
+
grant_id: mintResult.id
|
|
24299
|
+
});
|
|
24300
|
+
socket.write(encodeResponse(errorResponse("INTERNAL", `Failed to write token file for agent ${agent}: ${msg} (${rollbackNote})`)));
|
|
24301
|
+
return;
|
|
24123
24302
|
}
|
|
24124
24303
|
this.auditLogger.write({
|
|
24125
24304
|
ts: new Date().toISOString(),
|
|
@@ -24395,7 +24574,7 @@ class VaultBroker {
|
|
|
24395
24574
|
_writePidFile() {
|
|
24396
24575
|
try {
|
|
24397
24576
|
const pidPath = resolvePath(PID_FILE_DEFAULT);
|
|
24398
|
-
|
|
24577
|
+
writeFileSync5(pidPath, String(process.pid) + `
|
|
24399
24578
|
`, { mode: 384 });
|
|
24400
24579
|
} catch {}
|
|
24401
24580
|
}
|
|
@@ -24451,7 +24630,7 @@ class VaultBroker {
|
|
|
24451
24630
|
const credPath = `${dir}/vault-passphrase`;
|
|
24452
24631
|
let passphrase;
|
|
24453
24632
|
try {
|
|
24454
|
-
passphrase =
|
|
24633
|
+
passphrase = readFileSync12(credPath, "utf8").replace(/\n+$/, "");
|
|
24455
24634
|
} catch (err) {
|
|
24456
24635
|
const code = err.code;
|
|
24457
24636
|
if (code === "ENOENT") {
|
package/examples/switchroom.yaml
CHANGED
|
@@ -249,7 +249,7 @@ agents:
|
|
|
249
249
|
# topic_emoji: "💻"
|
|
250
250
|
# bot_token: "vault:telegram-dev-bot-token" # its own bot
|
|
251
251
|
# extends: coder # inherits from inline profile above
|
|
252
|
-
# model:
|
|
252
|
+
# model: opus # override defaults.model for this agent
|
|
253
253
|
# memory:
|
|
254
254
|
# collection: coding
|
|
255
255
|
# cli_args: ["--effort", "high"] # escape hatch: extra exec claude flags
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "switchroom",
|
|
3
3
|
"//version": "NOT the release version — source of truth is the git tag, resolved by scripts/build.mjs:resolveVersion() (see CLAUDE.md > Standard release process). This field is stale by design and only the Layer-4 dev/non-tag fallback for build.mjs + src/cli/resolve-version.ts; do NOT bump it expecting a release to pick it up. npm-pack tarball naming needs a real version — do that as an UNCOMMITTED pack-time bump (see release step 6), never a committed one.",
|
|
4
|
-
"version": "0.19.
|
|
4
|
+
"version": "0.19.25",
|
|
5
5
|
"description": "Run Claude Code 24/7 on your Claude Pro/Max subscription over Telegram. Open-source alternative to OpenClaw and NanoClaw — no API keys.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|