switchroom 0.14.32 → 0.14.33

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.
@@ -110,6 +110,138 @@ async function runAutoaccept(opts) {
110
110
  return { fired, reason: "manual-stop" };
111
111
  }
112
112
 
113
+ // src/agents/autoaccept.ts
114
+ import { execFileSync as execFileSync2 } from "node:child_process";
115
+ var PROMPTS2 = [
116
+ {
117
+ name: "dev-channels-loading",
118
+ match: /Loading.{1,30}development.{1,30}channels/,
119
+ keys: ["Enter"]
120
+ },
121
+ {
122
+ name: "dev-channels-local",
123
+ match: /using this for local development/,
124
+ keys: ["Enter"]
125
+ },
126
+ {
127
+ name: "dev-channels",
128
+ match: /I.{0,5}accept.{0,80}development.{0,10}channels/,
129
+ keys: ["Down", "Enter"]
130
+ },
131
+ {
132
+ name: "mcp-trust",
133
+ match: /Use this and all future MCP servers/,
134
+ keys: ["Enter"]
135
+ },
136
+ {
137
+ name: "theme",
138
+ match: /Choose.{1,30}text.{1,30}style/,
139
+ keys: ["Enter"]
140
+ },
141
+ {
142
+ name: "provider",
143
+ match: /Anthropic.{1,80}Bedrock/,
144
+ keys: ["Enter"]
145
+ },
146
+ {
147
+ name: "enter-to-confirm",
148
+ match: /Enter.{1,30}confirm/,
149
+ keys: ["Enter"]
150
+ }
151
+ ];
152
+ function capturePane2(agentName) {
153
+ const socket = `switchroom-${agentName}`;
154
+ try {
155
+ const out = execFileSync2("tmux", ["-L", socket, "capture-pane", "-p", "-t", agentName], {
156
+ timeout: 3000,
157
+ stdio: ["ignore", "pipe", "pipe"],
158
+ maxBuffer: 4 * 1024 * 1024
159
+ });
160
+ return out.toString("utf8");
161
+ } catch (err) {
162
+ console.error(`[autoaccept] ${agentName}: capture-pane failed: ${err.message}`);
163
+ return "";
164
+ }
165
+ }
166
+ function sendKeys2(agentName, keys) {
167
+ const socket = `switchroom-${agentName}`;
168
+ try {
169
+ execFileSync2("tmux", ["-L", socket, "send-keys", "-t", agentName, ...keys], { timeout: 3000, stdio: ["ignore", "pipe", "pipe"] });
170
+ return true;
171
+ } catch (err) {
172
+ console.error(`[autoaccept] ${agentName}: send-keys ${keys.join(" ")} failed: ${err.message}`);
173
+ return false;
174
+ }
175
+ }
176
+
177
+ // src/agents/wedge-watchdog.ts
178
+ var WEDGE_FOOTER_SIGNATURE = /(?=[\s\S]*[Ee]sc(?:ape)?[^\n]*cancel)(?=[\s\S]*(?:to select|to navigate|\u2191\/\u2193))/;
179
+ var DEFAULT_POLL_MS2 = 5000;
180
+ var DEFAULT_STABILITY_THRESHOLD = 3;
181
+ var DEFAULT_COOLDOWN_MS = 60000;
182
+ function defaultSleep2(ms) {
183
+ return new Promise((r) => setTimeout(r, ms));
184
+ }
185
+ function stabilityKey(text) {
186
+ return text.split(`
187
+ `).map((l) => l.replace(/\s+$/, "")).join(`
188
+ `);
189
+ }
190
+ async function runWedgeWatchdog(opts) {
191
+ const pollIntervalMs = opts.pollIntervalMs ?? DEFAULT_POLL_MS2;
192
+ const stabilityThreshold = opts.stabilityThreshold ?? DEFAULT_STABILITY_THRESHOLD;
193
+ const cooldownMs = opts.cooldownMs ?? DEFAULT_COOLDOWN_MS;
194
+ const deferToPrompts = opts.deferToPrompts ?? PROMPTS2;
195
+ const signature = opts.wedgeSignature ?? WEDGE_FOOTER_SIGNATURE;
196
+ const maxPolls = opts.maxPolls ?? Number.POSITIVE_INFINITY;
197
+ const now = opts.now ?? Date.now;
198
+ const sleep = opts.sleep ?? defaultSleep2;
199
+ const capture = opts.capture ?? capturePane2;
200
+ const send = opts.send ?? sendKeys2;
201
+ let stableCount = 0;
202
+ let lastKey = null;
203
+ let cooldownUntil = 0;
204
+ let fires = 0;
205
+ let polls = 0;
206
+ while (polls < maxPolls) {
207
+ polls++;
208
+ let text = "";
209
+ try {
210
+ text = capture(opts.agentName);
211
+ } catch (err) {
212
+ console.error(`[wedge-watchdog] ${opts.agentName}: capture threw: ${err.message}`);
213
+ text = "";
214
+ }
215
+ const isBlockingModal = !!text && signature.test(text) && !deferToPrompts.some((p) => p.match.test(text));
216
+ if (isBlockingModal) {
217
+ const key = stabilityKey(text);
218
+ if (key === lastKey) {
219
+ stableCount++;
220
+ } else {
221
+ stableCount = 1;
222
+ lastKey = key;
223
+ }
224
+ if (stableCount >= stabilityThreshold && now() >= cooldownUntil) {
225
+ console.error(`[wedge-watchdog] ${opts.agentName}: dismissing stuck blocking prompt ` + `(Esc) after ${stableCount} stable polls (~${stableCount * pollIntervalMs / 1000}s) \u2014 no human to answer it`);
226
+ try {
227
+ send(opts.agentName, ["Escape"]);
228
+ } catch (err) {
229
+ console.error(`[wedge-watchdog] ${opts.agentName}: send threw: ${err.message}`);
230
+ }
231
+ fires++;
232
+ cooldownUntil = now() + cooldownMs;
233
+ stableCount = 0;
234
+ lastKey = null;
235
+ }
236
+ } else {
237
+ stableCount = 0;
238
+ lastKey = null;
239
+ }
240
+ await sleep(pollIntervalMs);
241
+ }
242
+ return { fires, polls, reason: "max-polls" };
243
+ }
244
+
113
245
  // src/cli/autoaccept-poll.ts
114
246
  async function main() {
115
247
  const agentName = process.argv[2];
@@ -119,9 +251,20 @@ async function main() {
119
251
  }
120
252
  try {
121
253
  const res = await runAutoaccept({ agentName });
122
- console.error(`[autoaccept-poll] ${agentName}: done reason=${res.reason} fired=${res.fired.length ? res.fired.join(",") : "(none)"}`);
254
+ console.error(`[autoaccept-poll] ${agentName}: boot done reason=${res.reason} fired=${res.fired.length ? res.fired.join(",") : "(none)"}`);
255
+ } catch (err) {
256
+ console.error(`[autoaccept-poll] ${agentName}: boot unexpected throw: ${err.message}`);
257
+ }
258
+ if (process.env.SWITCHROOM_WEDGE_WATCHDOG === "0") {
259
+ console.error(`[autoaccept-poll] ${agentName}: wedge-watchdog disabled (SWITCHROOM_WEDGE_WATCHDOG=0) \u2014 exiting after boot phase`);
260
+ process.exit(0);
261
+ }
262
+ try {
263
+ console.error(`[autoaccept-poll] ${agentName}: entering wedge-watchdog (continuous)`);
264
+ const res = await runWedgeWatchdog({ agentName });
265
+ console.error(`[autoaccept-poll] ${agentName}: wedge-watchdog returned reason=${res.reason} fires=${res.fires}`);
123
266
  } catch (err) {
124
- console.error(`[autoaccept-poll] ${agentName}: unexpected throw: ${err.message}`);
267
+ console.error(`[autoaccept-poll] ${agentName}: wedge-watchdog unexpected throw: ${err.message}`);
125
268
  }
126
269
  process.exit(0);
127
270
  }
@@ -14,7 +14,7 @@ var __export = (target, all) => {
14
14
  };
15
15
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
16
16
 
17
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
17
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/util.js
18
18
  var util, objectUtil, ZodParsedType, getParsedType = (data) => {
19
19
  const t = typeof data;
20
20
  switch (t) {
@@ -145,7 +145,7 @@ var init_util = __esm(() => {
145
145
  ]);
146
146
  });
147
147
 
148
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
148
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/ZodError.js
149
149
  var ZodIssueCode, quotelessJson = (obj) => {
150
150
  const json = JSON.stringify(obj, null, 2);
151
151
  return json.replace(/"([^"]+)":/g, "$1:");
@@ -266,7 +266,7 @@ var init_ZodError = __esm(() => {
266
266
  };
267
267
  });
268
268
 
269
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
269
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/locales/en.js
270
270
  var errorMap = (issue, _ctx) => {
271
271
  let message;
272
272
  switch (issue.code) {
@@ -373,7 +373,7 @@ var init_en = __esm(() => {
373
373
  en_default = errorMap;
374
374
  });
375
375
 
376
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
376
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/errors.js
377
377
  function setErrorMap(map) {
378
378
  overrideErrorMap = map;
379
379
  }
@@ -386,7 +386,7 @@ var init_errors = __esm(() => {
386
386
  overrideErrorMap = en_default;
387
387
  });
388
388
 
389
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
389
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
390
390
  function addIssueToContext(ctx, issueData) {
391
391
  const overrideMap = getErrorMap();
392
392
  const issue = makeIssue({
@@ -491,10 +491,10 @@ var init_parseUtil = __esm(() => {
491
491
  });
492
492
  });
493
493
 
494
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/typeAliases.js
494
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/typeAliases.js
495
495
  var init_typeAliases = () => {};
496
496
 
497
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
497
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
498
498
  var errorUtil;
499
499
  var init_errorUtil = __esm(() => {
500
500
  (function(errorUtil2) {
@@ -503,7 +503,7 @@ var init_errorUtil = __esm(() => {
503
503
  })(errorUtil || (errorUtil = {}));
504
504
  });
505
505
 
506
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
506
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/types.js
507
507
  class ParseInputLazyPath {
508
508
  constructor(parent, value, path, key) {
509
509
  this._cachedPath = [];
@@ -3854,7 +3854,7 @@ var init_types = __esm(() => {
3854
3854
  NEVER = INVALID;
3855
3855
  });
3856
3856
 
3857
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
3857
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
3858
3858
  var exports_external = {};
3859
3859
  __export(exports_external, {
3860
3860
  void: () => voidType,
@@ -3974,7 +3974,7 @@ var init_external = __esm(() => {
3974
3974
  init_ZodError();
3975
3975
  });
3976
3976
 
3977
- // ../switchroom-sec-1417/node_modules/.bun/zod@3.25.76/node_modules/zod/index.js
3977
+ // node_modules/.bun/zod@3.25.76/node_modules/zod/index.js
3978
3978
  var init_zod = __esm(() => {
3979
3979
  init_external();
3980
3980
  init_external();