switchroom 0.18.6 → 0.18.7
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 +1 -0
- package/dist/auth-broker/index.js +1 -0
- package/dist/cli/autoaccept-poll.js +140 -33
- package/dist/cli/notion-write-pretool.mjs +1 -0
- package/dist/cli/switchroom.js +269 -56
- package/dist/host-control/main.js +2 -1
- package/dist/vault/approvals/kernel-server.js +1 -0
- package/dist/vault/broker/server.js +1 -0
- package/package.json +3 -3
- package/profiles/_base/cron-session.sh.hbs +55 -16
- package/profiles/_base/start.sh.hbs +35 -16
- package/profiles/default/CLAUDE.md.hbs +1 -1
- package/telegram-plugin/dist/bridge/bridge.js +22 -0
- package/telegram-plugin/dist/gateway/gateway.js +1937 -580
- package/telegram-plugin/dist/server.js +24 -0
- package/telegram-plugin/gateway/always-allow-persist-queue.ts +438 -0
- package/telegram-plugin/gateway/approval-timeout-inbound-builders.ts +150 -0
- package/telegram-plugin/gateway/clean-shutdown-marker.ts +68 -20
- package/telegram-plugin/gateway/gateway.ts +1071 -130
- package/telegram-plugin/gateway/inbound-spool.ts +2 -1
- package/telegram-plugin/gateway/inject-handler.test.ts +19 -0
- package/telegram-plugin/gateway/inject-handler.ts +17 -0
- package/telegram-plugin/gateway/ipc-protocol.ts +44 -2
- package/telegram-plugin/gateway/ipc-server.ts +40 -0
- package/telegram-plugin/gateway/model-command.ts +212 -51
- package/telegram-plugin/gateway/pending-card-expiry.ts +98 -0
- package/telegram-plugin/gateway/pending-card-store.ts +173 -0
- package/telegram-plugin/gateway/pending-inbound-buffer.ts +12 -2
- package/telegram-plugin/gateway/resume-inbound-builder.ts +240 -2
- package/telegram-plugin/gateway/session-model-source.ts +73 -0
- package/telegram-plugin/gateway/worker-feed-dispatch.ts +24 -1
- package/telegram-plugin/hooks/subagent-tracker-pretool.mjs +30 -7
- package/telegram-plugin/model-label.ts +69 -0
- package/telegram-plugin/operator-events.ts +24 -0
- package/telegram-plugin/permission-diff.ts +128 -0
- package/telegram-plugin/registry/subagents-schema.ts +80 -1
- package/telegram-plugin/registry/subagents.test.ts +90 -0
- package/telegram-plugin/session-tail.ts +28 -0
- package/telegram-plugin/silent-end.ts +49 -4
- package/telegram-plugin/subagent-watcher.ts +222 -37
- package/telegram-plugin/tests/always-allow-persist-queue.test.ts +529 -0
- package/telegram-plugin/tests/approval-timeout-inbound-builders.test.ts +94 -0
- package/telegram-plugin/tests/button-tap-turn-gated.test.ts +263 -0
- package/telegram-plugin/tests/gateway-clean-shutdown-marker.test.ts +85 -27
- package/telegram-plugin/tests/gateway-session-model-relaunch.test.ts +4 -2
- package/telegram-plugin/tests/ipc-server-query-pending-permission.test.ts +157 -0
- package/telegram-plugin/tests/mental-model-propose-callback-gate.test.ts +8 -5
- package/telegram-plugin/tests/model-command.test.ts +202 -42
- package/telegram-plugin/tests/model-label.test.ts +64 -0
- package/telegram-plugin/tests/operator-events.test.ts +1 -0
- package/telegram-plugin/tests/pending-card-durability-wiring.test.ts +202 -0
- package/telegram-plugin/tests/pending-card-expiry.test.ts +190 -0
- package/telegram-plugin/tests/pending-card-store.test.ts +173 -0
- package/telegram-plugin/tests/permission-diff.test.ts +111 -0
- package/telegram-plugin/tests/resume-inbound-builder.test.ts +286 -0
- package/telegram-plugin/tests/session-model-source.test.ts +67 -0
- package/telegram-plugin/tests/session-tail.test.ts +64 -0
- package/telegram-plugin/tests/silent-end.test.ts +46 -1
- package/telegram-plugin/tests/subagent-tracker-hooks.test.ts +39 -0
- package/telegram-plugin/tests/subagent-watcher-boot-promotion-replay.test.ts +107 -4
- package/telegram-plugin/tests/subagent-watcher-handback-gaps.test.ts +42 -4
- package/telegram-plugin/tests/subagent-watcher-parent-turn-key.test.ts +47 -0
- package/telegram-plugin/tests/subagent-watcher-terminated-ids-cap.test.ts +150 -0
- package/telegram-plugin/tests/subagent-watcher.test.ts +54 -0
- package/telegram-plugin/tests/tool-activity-summary.test.ts +37 -0
- package/telegram-plugin/tests/typing-wrap.test.ts +23 -0
- package/telegram-plugin/tests/worker-activity-feed.test.ts +11 -0
- package/telegram-plugin/tests/worker-feed-dispatch.test.ts +126 -0
- package/telegram-plugin/tool-activity-summary.ts +22 -2
- package/telegram-plugin/typing-wrap.ts +72 -25
- package/telegram-plugin/worker-activity-feed.ts +9 -0
|
@@ -87,36 +87,75 @@ CRON_APPEND_PROMPT="You are the cheap background cron worker for {{name}}. You r
|
|
|
87
87
|
# claude's project key matches the pre-seeded trust state (.claude-cron).
|
|
88
88
|
cd "{{agentDir}}" || exit 1
|
|
89
89
|
|
|
90
|
-
# LiteLLM routing for the cron session —
|
|
90
|
+
# LiteLLM routing for the cron session — ports start.sh's boot contract.
|
|
91
91
|
# IMPORTANT: the vault key is provisioned under the BASE agent name ({{name}}),
|
|
92
92
|
# NOT the cron identity ({{name}}-cron). Use the Handlebars template var so the
|
|
93
|
-
# lookup is a compile-time literal — no fragile runtime suffix-stripping.
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
93
|
+
# lookup is a compile-time literal — no fragile runtime suffix-stripping. The
|
|
94
|
+
# attribution headers use the SAME compile-time-literal form ({{name}}-cron,
|
|
95
|
+
# identical to $SWITCHROOM_AGENT_NAME here — line 69 exports it) so this block
|
|
96
|
+
# refers to the agent one consistent way instead of mixing a template literal
|
|
97
|
+
# for the key with a runtime env var for the tags. Cron spend is attributed to
|
|
98
|
+
# {{name}}-cron so LiteLLM distinguishes it from main-session spend per agent.
|
|
99
|
+
#
|
|
100
|
+
# Two boot failure modes, handled DIFFERENTLY (ported 2026-07 from start.sh so
|
|
101
|
+
# cron no longer fails OPEN on a transient blip and silently runs UNTRACKED
|
|
102
|
+
# direct OAuth for the fire — the product invariant is all model traffic stays
|
|
103
|
+
# proxy-routed for cost/token tracking):
|
|
104
|
+
# - MISSING KEY → fail-open: strip routing, fall back to direct OAuth, LOUD
|
|
105
|
+
# log. Without a key there is no metered route to reach — correct here.
|
|
106
|
+
# - PROXY UNREACHABLE with key in hand → do NOT strip. Keep routing pointed at
|
|
107
|
+
# the proxy AND export the auth header so the session authenticates the
|
|
108
|
+
# moment the proxy recovers (the socat forwarder reconnects per-connection),
|
|
109
|
+
# LOUD log. Never a silent untracked direct-OAuth fallback.
|
|
110
|
+
# Retry budget is DELIBERATELY short — 3 attempts, worst-case ~25s (3×5s curl
|
|
111
|
+
# timeouts + 2×5s sleeps) — vs start.sh's 120s: a cron fire is
|
|
112
|
+
# latency-sensitive and short-lived, and unreachable now KEEPS routing anyway,
|
|
113
|
+
# so a long boot-probe would only add dead latency for no gain.
|
|
98
114
|
if [ -n "${SWITCHROOM_LITELLM:-}" ] && command -v switchroom >/dev/null 2>&1; then
|
|
99
115
|
sr_ll_key="$(switchroom vault get "litellm/{{name}}/api-key" 2>/dev/null || true)"
|
|
100
116
|
sr_ll_ok=""
|
|
117
|
+
sr_ll_unreachable=""
|
|
101
118
|
if [ -z "$sr_ll_key" ]; then
|
|
102
|
-
echo "litellm: no virtual key for
|
|
103
|
-
elif command -v curl >/dev/null 2>&1 && [ -n "$ANTHROPIC_BASE_URL" ]
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
echo "litellm(cron): no virtual key for '{{name}}' — falling back to direct OAuth (untracked, unguarded)" >&2
|
|
120
|
+
elif command -v curl >/dev/null 2>&1 && [ -n "$ANTHROPIC_BASE_URL" ]; then
|
|
121
|
+
# Bounded retry probe — short budget for cron latency (3 attempts,
|
|
122
|
+
# worst-case ~25s: 3×5s curl timeouts + 2×5s sleeps).
|
|
123
|
+
sr_ll_url="${SWITCHROOM_LITELLM_BASE:-${ANTHROPIC_BASE_URL%/anthropic}}/health/liveliness"
|
|
124
|
+
sr_ll_try=0
|
|
125
|
+
sr_ll_up=""
|
|
126
|
+
while :; do
|
|
127
|
+
if curl -fsS -m 5 -o /dev/null "$sr_ll_url" 2>/dev/null; then sr_ll_up="1"; break; fi
|
|
128
|
+
sr_ll_try=$(( sr_ll_try + 1 ))
|
|
129
|
+
[ "$sr_ll_try" -ge 3 ] && break
|
|
130
|
+
sleep 5
|
|
131
|
+
done
|
|
132
|
+
if [ -z "$sr_ll_up" ]; then
|
|
133
|
+
# Proxy unreachable but the key is present. Do NOT strip: keep routing so
|
|
134
|
+
# the cron session self-heals once the proxy is back.
|
|
135
|
+
sr_ll_unreachable="1"
|
|
136
|
+
echo "litellm(cron): proxy unreachable at ${SWITCHROOM_LITELLM_BASE:-$ANTHROPIC_BASE_URL} after 3 retries — routing LEFT IN PLACE so it self-heals; NOT falling back to untracked direct Anthropic OAuth." >&2
|
|
137
|
+
else
|
|
138
|
+
sr_ll_ok="1"
|
|
139
|
+
fi
|
|
140
|
+
unset sr_ll_url sr_ll_try sr_ll_up
|
|
106
141
|
else
|
|
107
142
|
sr_ll_ok="1"
|
|
108
143
|
fi
|
|
109
|
-
if [ -n "$sr_ll_ok" ]; then
|
|
144
|
+
if [ -n "$sr_ll_ok" ] || [ -n "$sr_ll_unreachable" ]; then
|
|
145
|
+
# Key fetched successfully — export the auth header REGARDLESS of the probe
|
|
146
|
+
# outcome so the virtual key reaches the process env. On unreachable this is
|
|
147
|
+
# what lets the session authenticate the moment the proxy recovers instead
|
|
148
|
+
# of 401-ing (the same self-heal fix as start.sh's inner/outer blocks).
|
|
110
149
|
export ANTHROPIC_CUSTOM_HEADERS="x-litellm-api-key: Bearer $sr_ll_key
|
|
111
|
-
x-litellm-customer-id:
|
|
112
|
-
x-litellm-tags: agent
|
|
150
|
+
x-litellm-customer-id: {{name}}-cron
|
|
151
|
+
x-litellm-tags: agent:{{name}}-cron,profile:${SWITCHROOM_AGENT_PROFILE:-default}"
|
|
113
152
|
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
|
|
114
153
|
else
|
|
115
|
-
#
|
|
116
|
-
# directly on its OAuth credential (subscription path), unproxied.
|
|
154
|
+
# Missing-key fail-open: drop every routing var so the claude CLI talks to
|
|
155
|
+
# Anthropic directly on its OAuth credential (subscription path), unproxied.
|
|
117
156
|
unset ANTHROPIC_BASE_URL ANTHROPIC_SMALL_FAST_MODEL SWITCHROOM_LITELLM SWITCHROOM_LITELLM_BASE
|
|
118
157
|
fi
|
|
119
|
-
unset sr_ll_key sr_ll_ok
|
|
158
|
+
unset sr_ll_key sr_ll_ok sr_ll_unreachable
|
|
120
159
|
fi
|
|
121
160
|
|
|
122
161
|
# Create the cron tmux session DETACHED (-d), not in attach mode. This is a
|
|
@@ -46,6 +46,17 @@ if [ "$SWITCHROOM_RUNTIME" = "docker" ] && [ -z "$SWITCHROOM_DOCKER_TMUX_INNER"
|
|
|
46
46
|
# compose env and the inner-pass export. Pinned by the scaffold-order test.
|
|
47
47
|
export SWITCHROOM_AGENT_NAME="{{name}}"
|
|
48
48
|
|
|
49
|
+
# Boot-resume policy (session_continuity.boot_resume; default 'in-flight').
|
|
50
|
+
# The gateway's boot-resume block reads SWITCHROOM_BOOT_RESUME to decide
|
|
51
|
+
# whether a genuinely in-flight turn is auto-resumed across a deliberate
|
|
52
|
+
# restart ('in-flight' — default), always ('always'), or downgraded to a
|
|
53
|
+
# passive notice ('never'). MUST be exported here, before the gateway fork
|
|
54
|
+
# below, or the daemon never sees it and every agent defaults silently — same
|
|
55
|
+
# start.sh env-fork landmine as the channels.telegram knobs. The later
|
|
56
|
+
# SWITCHROOM_RESUME_MODE block is set AFTER the fork (it drives the inner
|
|
57
|
+
# `claude` --continue path, not the gateway), so this needs its own hoist.
|
|
58
|
+
export SWITCHROOM_BOOT_RESUME="{{#if bootResumeMode}}{{{bootResumeMode}}}{{else}}in-flight{{/if}}"
|
|
59
|
+
|
|
49
60
|
# Gateway-consumed env MUST be exported HERE, before the gateway fork
|
|
50
61
|
# below. The gateway daemon reads channels.telegram.* knobs (and any
|
|
51
62
|
# agent env) from process.env at startup — e.g. SWITCHROOM_TG_STREAM_
|
|
@@ -120,17 +131,19 @@ if [ "$SWITCHROOM_RUNTIME" = "docker" ] && [ -z "$SWITCHROOM_DOCKER_TMUX_INNER"
|
|
|
120
131
|
else
|
|
121
132
|
sr_ll_ok="1"
|
|
122
133
|
fi
|
|
123
|
-
if [ -n "$sr_ll_ok" ]; then
|
|
134
|
+
if [ -n "$sr_ll_ok" ] || [ -n "$sr_ll_unreachable" ]; then
|
|
135
|
+
# Key fetched successfully — export the proxy auth header REGARDLESS of the
|
|
136
|
+
# reachability probe outcome. The header is what carries the virtual key
|
|
137
|
+
# into the process env; without it the gateway's sr-* discovery
|
|
138
|
+
# (gateway.ts discoverSrModels) is dead and, once the proxy recovers,
|
|
139
|
+
# every request 401s until a manual restart. Since routing is LEFT IN
|
|
140
|
+
# PLACE on unreachable (below/above), the header must be too so the
|
|
141
|
+
# session actually self-heals when litellm returns. The probe result gates
|
|
142
|
+
# only log wording + inner-pass _LITELLM_OK, never the header.
|
|
124
143
|
export ANTHROPIC_CUSTOM_HEADERS="x-litellm-api-key: Bearer $sr_ll_key
|
|
125
144
|
x-litellm-customer-id: $SWITCHROOM_AGENT_NAME
|
|
126
145
|
x-litellm-tags: agent:$SWITCHROOM_AGENT_NAME,profile:${SWITCHROOM_AGENT_PROFILE:-default}"
|
|
127
146
|
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
|
|
128
|
-
elif [ -n "$sr_ll_unreachable" ]; then
|
|
129
|
-
# Proxy unreachable at boot: routing intentionally LEFT IN PLACE (loud
|
|
130
|
-
# warning already emitted) so it survives into the inner pass and
|
|
131
|
-
# self-heals once litellm returns. NO unset — the permanent strip here
|
|
132
|
-
# was what made the inner self-heal fix inert on docker.
|
|
133
|
-
:
|
|
134
147
|
else
|
|
135
148
|
# Missing-key fail-open: gateway talks direct OAuth, unproxied.
|
|
136
149
|
unset ANTHROPIC_BASE_URL ANTHROPIC_SMALL_FAST_MODEL SWITCHROOM_LITELLM SWITCHROOM_LITELLM_BASE
|
|
@@ -1016,8 +1029,15 @@ if [ -n "${SWITCHROOM_LITELLM:-}" ] && command -v switchroom >/dev/null 2>&1; th
|
|
|
1016
1029
|
else
|
|
1017
1030
|
sr_ll_ok="1"
|
|
1018
1031
|
fi
|
|
1019
|
-
if [ -n "$sr_ll_ok" ]; then
|
|
1020
|
-
|
|
1032
|
+
if [ -n "$sr_ll_ok" ] || [ -n "$sr_ll_unreachable" ]; then
|
|
1033
|
+
# Key fetched successfully — export the proxy auth header REGARDLESS of the
|
|
1034
|
+
# reachability probe outcome. Routing is LEFT IN PLACE on unreachable so the
|
|
1035
|
+
# session self-heals when litellm returns; the header MUST survive with it,
|
|
1036
|
+
# otherwise every request 401s once the proxy recovers (the "self-heals"
|
|
1037
|
+
# promise below was inert without this) and gateway sr-* discovery stays
|
|
1038
|
+
# dead. The probe outcome gates ONLY the _LITELLM_OK flag (sr-* override
|
|
1039
|
+
# drop) and the log wording above — never the header.
|
|
1040
|
+
#
|
|
1021
1041
|
# Newline-separated Name: Value pairs (claude CLI ANTHROPIC_CUSTOM_HEADERS format).
|
|
1022
1042
|
# Tags: agent:<name> for per-agent spend tracking; profile:<profile> for
|
|
1023
1043
|
# fleet-level cost breakdown by role. Per-turn tags (cron vs telegram) are
|
|
@@ -1031,13 +1051,12 @@ x-litellm-tags: agent:$SWITCHROOM_AGENT_NAME,profile:${SWITCHROOM_AGENT_PROFILE:
|
|
|
1031
1051
|
# models configured in the proxy appear in the /model picker and can be
|
|
1032
1052
|
# selected via --model. Without this, the CLI only knows its bundled list.
|
|
1033
1053
|
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
:
|
|
1054
|
+
if [ -n "$sr_ll_ok" ]; then
|
|
1055
|
+
# Probe succeeded: proxy is live, so honor any sr-* session model override
|
|
1056
|
+
# below. On unreachable, _LITELLM_OK stays empty so the override is dropped
|
|
1057
|
+
# (claude would 4xx an unknown model against a down endpoint).
|
|
1058
|
+
_LITELLM_OK="1"
|
|
1059
|
+
fi
|
|
1041
1060
|
else
|
|
1042
1061
|
# Missing key fail-open: drop every routing var so the claude CLI talks to
|
|
1043
1062
|
# Anthropic directly on its OAuth credential (subscription path), unproxied.
|
|
@@ -105,7 +105,7 @@ By default, every restart starts a **fresh `claude` session** — the in-flight
|
|
|
105
105
|
- **`resume_interrupted`** (operator restart / SIGTERM / crash): pick the work back up and carry it to completion. Briefly tell the user you're resuming and roughly how long ago it was interrupted — then just do it. Do NOT ask whether to resume.
|
|
106
106
|
- **`resume_watchdog_timeout`** (hang-watchdog killed it after no progress): do NOT silently resume — it may hang the same way. Tell the user plainly that your last turn was killed after N minutes of no progress, roughly what it was doing, and ask whether to retry or take a different angle. Report only the honest cause; don't invent a deeper root cause.
|
|
107
107
|
The one-shot `SWITCHROOM_PENDING_*` env vars are passive forensic context for the wake-audit / "why did you restart" protocols — not the resume trigger.
|
|
108
|
-
- **`.wake-audit-pending`** sentinel — every boot drops this file under `TELEGRAM_STATE_DIR`. On your first turn, run the three-signal check (owed reply / orphan sub-agents / open todos) per the wake-audit protocol in
|
|
108
|
+
- **`.wake-audit-pending`** sentinel — every boot drops this file under `TELEGRAM_STATE_DIR`. On your first turn, run the three-signal check (owed reply / orphan sub-agents / open todos) per the wake-audit protocol in the `switchroom-runtime` skill (`skills/switchroom-runtime/SKILL.md`), then `rm -f` the sentinel.
|
|
109
109
|
|
|
110
110
|
A config-summary greeting card is sent automatically by the SessionStart hook — you don't need to announce yourself. If your context feels thin (after compaction or any fresh session), proactively recall from Hindsight before proceeding.
|
|
111
111
|
|
|
@@ -23132,6 +23132,20 @@ function createToolLabelSidecar(opts) {
|
|
|
23132
23132
|
};
|
|
23133
23133
|
}
|
|
23134
23134
|
|
|
23135
|
+
// model-label.ts
|
|
23136
|
+
function isModelSentinel(model) {
|
|
23137
|
+
if (typeof model !== "string")
|
|
23138
|
+
return true;
|
|
23139
|
+
const m = model.trim();
|
|
23140
|
+
if (m.length === 0)
|
|
23141
|
+
return true;
|
|
23142
|
+
if (m.startsWith("<"))
|
|
23143
|
+
return true;
|
|
23144
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(m))
|
|
23145
|
+
return true;
|
|
23146
|
+
return false;
|
|
23147
|
+
}
|
|
23148
|
+
|
|
23135
23149
|
// session-tail.ts
|
|
23136
23150
|
function isMultiAgentEnabled(env = process.env) {
|
|
23137
23151
|
return env.PROGRESS_CARD_MULTI_AGENT !== "0";
|
|
@@ -23263,6 +23277,10 @@ function projectTranscriptLine(line) {
|
|
|
23263
23277
|
if (!Array.isArray(content))
|
|
23264
23278
|
return [];
|
|
23265
23279
|
const events = [];
|
|
23280
|
+
const mainModel = message?.model;
|
|
23281
|
+
if (typeof mainModel === "string" && !isModelSentinel(mainModel)) {
|
|
23282
|
+
events.push({ kind: "model", model: mainModel });
|
|
23283
|
+
}
|
|
23266
23284
|
const textEvents = projectAssistantTextBlocks(content, (text, blockIndex, lastInMessage) => ({ kind: "text", text, blockIndex, lastInMessage }));
|
|
23267
23285
|
content.forEach((c, i) => {
|
|
23268
23286
|
const ct = c.type;
|
|
@@ -23365,6 +23383,10 @@ function projectSubagentLine(line, agentId, state) {
|
|
|
23365
23383
|
if (!Array.isArray(content))
|
|
23366
23384
|
return [];
|
|
23367
23385
|
const events = [];
|
|
23386
|
+
const subModel = message?.model;
|
|
23387
|
+
if (typeof subModel === "string" && !isModelSentinel(subModel)) {
|
|
23388
|
+
events.push({ kind: "sub_agent_model", agentId, model: subModel });
|
|
23389
|
+
}
|
|
23368
23390
|
const textEvents = projectAssistantTextBlocks(content, (text, blockIndex, lastInMessage) => ({
|
|
23369
23391
|
kind: "sub_agent_text",
|
|
23370
23392
|
agentId,
|