@chatpanel/bridge 0.11.24 → 0.11.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.
Files changed (62) hide show
  1. package/README.md +7 -7
  2. package/package.json +1 -13
  3. package/scripts/sync-channels.mjs +8 -90
  4. package/scripts/sync-events.mjs +7 -78
  5. package/scripts/sync-pii.mjs +7 -68
  6. package/src/api-compat.js +5 -294
  7. package/src/channels/adapters/telegram.js +3 -298
  8. package/src/channels/bridge.js +1 -59
  9. package/src/channels/eventlog.js +3 -57
  10. package/src/channels/gateway.js +1 -114
  11. package/src/channels/invoke.js +1 -172
  12. package/src/channels/normalize.js +1 -58
  13. package/src/channels/pairing.js +1 -95
  14. package/src/channels/service.js +1 -329
  15. package/src/channels/stream.js +5 -104
  16. package/src/cli-errors.js +3 -136
  17. package/src/connections.js +1 -160
  18. package/src/connectors.js +1 -100
  19. package/src/engines/antigravity.js +5 -235
  20. package/src/engines/args.js +1 -47
  21. package/src/engines/claude.js +6 -586
  22. package/src/engines/cli-agents.js +7 -312
  23. package/src/engines/codex.js +6 -481
  24. package/src/engines/custom.js +17 -577
  25. package/src/engines/prompt.js +6 -32
  26. package/src/engines/stream-formats.js +2 -222
  27. package/src/entitlement.js +1 -77
  28. package/src/env.js +3 -628
  29. package/src/events/capability.js +1 -134
  30. package/src/events/event.js +1 -183
  31. package/src/events/reach.js +1 -31
  32. package/src/events/ref.js +1 -63
  33. package/src/events/scm-connection.js +1 -188
  34. package/src/events/scopes.js +1 -20
  35. package/src/events/skill-manifest.js +1 -338
  36. package/src/events/skill-scan.js +3 -217
  37. package/src/events/view.js +1 -96
  38. package/src/mcp-capabilities.js +2 -139
  39. package/src/mcp-local.js +0 -0
  40. package/src/mcp-quarantine.js +1 -110
  41. package/src/net.js +1 -107
  42. package/src/pii/index.js +1 -29
  43. package/src/pii/net.js +1 -111
  44. package/src/pii/pii-detect.js +2 -296
  45. package/src/pii/pii-redact.js +1 -470
  46. package/src/pii/pipeline.js +1 -137
  47. package/src/pii/sanitize.js +2 -179
  48. package/src/pii/tool-harness.js +1 -184
  49. package/src/pii/tool-rank.js +1 -110
  50. package/src/proc.js +2 -91
  51. package/src/relay-timeout.js +1 -21
  52. package/src/runs.js +1 -49
  53. package/src/sanitize.js +1 -7
  54. package/src/scm.js +1 -76
  55. package/src/server.js +10 -1492
  56. package/src/service.js +11 -176
  57. package/src/sign-in.js +1 -91
  58. package/src/skills.js +1 -399
  59. package/src/ssrf.js +1 -70
  60. package/src/update.js +1 -216
  61. package/src/workdir.js +1 -108
  62. package/src/worktree.js +3 -125
package/src/service.js CHANGED
@@ -1,193 +1,28 @@
1
- // Background auto-start for the ChatPanel Bridge.
2
- //
3
- // So non-technical users never touch a terminal: download the app, run it once
4
- // with --install, and it launches at login and stays running.
5
- //
6
- // chatpanel-bridge --install register login auto-start + start now
7
- // chatpanel-bridge --uninstall remove it
8
- // chatpanel-bridge --status is it registered?
9
- //
10
- // macOS → LaunchAgent · Windows → Scheduled Task (ONLOGON) · Linux → systemd user.
11
-
12
- import os from 'node:os';
13
- import path from 'node:path';
14
- import { mkdirSync, writeFileSync, rmSync, existsSync } from 'node:fs';
15
- import { spawn, spawnSync } from 'node:child_process';
16
-
17
- const LABEL = 'net.chatpanel.bridge';
18
- const DISPLAY = 'ChatPanel Bridge';
19
-
20
- // The command that launches THIS bridge. A compiled single-file binary launches
21
- // itself (no args); running under node/bun launches the interpreter + this script.
22
- export function resolveLaunch() {
23
- const exe = process.execPath;
24
- const base = path.basename(exe).toLowerCase();
25
- const underInterpreter = base.startsWith('node') || base.startsWith('bun');
26
- if (underInterpreter && process.argv[1]) {
27
- return { program: exe, args: [path.resolve(process.argv[1])] };
28
- }
29
- return { program: exe, args: [] };
30
- }
31
-
32
- function logPaths() {
33
- const dir = path.join(os.homedir(), '.chatpanel');
34
- mkdirSync(dir, { recursive: true });
35
- return { out: path.join(dir, 'bridge.log'), err: path.join(dir, 'bridge.err.log') };
36
- }
37
-
38
- function run(cmd, args, opts = {}) {
39
- return spawnSync(cmd, args, { encoding: 'utf8', ...opts });
40
- }
41
-
42
- // ---------------------------------------------------------------- macOS
43
- const macPlist = () => path.join(os.homedir(), 'Library', 'LaunchAgents', `${LABEL}.plist`);
44
-
45
- function macInstall() {
46
- const { program, args } = resolveLaunch();
47
- const { out, err } = logPaths();
48
- const progArgs = [program, ...args].map((a) => ` <string>${a}</string>`).join('\n');
49
- const plist = `<?xml version="1.0" encoding="UTF-8"?>
1
+ import u from"node:os";import e from"node:path";import{mkdirSync as l,writeFileSync as p,rmSync as b,existsSync as v}from"node:fs";import{spawn as f,spawnSync as P}from"node:child_process";const d="net.chatpanel.bridge",I="ChatPanel Bridge";function m(){const t=process.execPath,r=e.basename(t).toLowerCase();return(r.startsWith("node")||r.startsWith("bun"))&&process.argv[1]?{program:t,args:[e.resolve(process.argv[1])]}:{program:t,args:[]}}function E(){const t=e.join(u.homedir(),".chatpanel");return l(t,{recursive:!0}),{out:e.join(t,"bridge.log"),err:e.join(t,"bridge.err.log")}}function n(t,r,s={}){return P(t,r,{encoding:"utf8",...s})}const S=()=>e.join(u.homedir(),"Library","LaunchAgents",`${d}.plist`);function L(){const{program:t,args:r}=m(),{out:s,err:i}=E(),a=[t,...r].map($=>` <string>${$}</string>`).join(`
2
+ `),c=`<?xml version="1.0" encoding="UTF-8"?>
50
3
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
51
4
  <plist version="1.0">
52
5
  <dict>
53
- <key>Label</key><string>${LABEL}</string>
6
+ <key>Label</key><string>${d}</string>
54
7
  <key>ProgramArguments</key>
55
8
  <array>
56
- ${progArgs}
9
+ ${a}
57
10
  </array>
58
11
  <key>RunAtLoad</key><true/>
59
12
  <key>KeepAlive</key><true/>
60
- <key>StandardOutPath</key><string>${out}</string>
61
- <key>StandardErrorPath</key><string>${err}</string>
13
+ <key>StandardOutPath</key><string>${s}</string>
14
+ <key>StandardErrorPath</key><string>${i}</string>
62
15
  </dict>
63
16
  </plist>
64
- `;
65
- const p = macPlist();
66
- mkdirSync(path.dirname(p), { recursive: true });
67
- writeFileSync(p, plist);
68
- run('launchctl', ['unload', p]); // ignore if not loaded
69
- const r = run('launchctl', ['load', '-w', p]);
70
- if (r.status !== 0) throw new Error((r.stderr || '').trim() || 'launchctl load failed');
71
- }
72
- function macUninstall() {
73
- const p = macPlist();
74
- run('launchctl', ['unload', '-w', p]);
75
- if (existsSync(p)) rmSync(p);
76
- }
77
- function macStatus() {
78
- return (run('launchctl', ['list']).stdout || '').includes(LABEL);
79
- }
80
-
81
- // ---------------------------------------------------------------- Windows
82
- // Per-user auto-start via the HKCU Run key — works without admin (a scheduled
83
- // task can be blocked by policy: "Access is denied"). A tiny .vbs launcher runs
84
- // the bridge with NO console window.
85
- const WIN_RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
86
- const WIN_RUN_NAME = 'ChatPanelBridge';
87
- // A user-writable location for the launcher. NOT next to the program — under
88
- // `npm i -g` the program is node.exe, whose dir is protected (EPERM).
89
- const winVbs = () => path.join(os.homedir(), '.chatpanel', 'launch.vbs');
90
-
91
- function winInstall() {
92
- const { program, args } = resolveLaunch();
93
- // VBS quoting: "" is a literal quote inside a string. Run(cmd, 0=hidden, False).
94
- const parts = [program, ...args].map((p) => `""${p}""`).join(' ');
95
- const vbs = winVbs();
96
- mkdirSync(path.dirname(vbs), { recursive: true });
97
- writeFileSync(vbs, `CreateObject("WScript.Shell").Run "${parts}", 0, False\r\n`);
98
- const r = run('reg', ['add', WIN_RUN_KEY, '/v', WIN_RUN_NAME, '/t', 'REG_SZ', '/d', `wscript.exe "${vbs}"`, '/f']);
99
- if (r.status !== 0) throw new Error((r.stderr || '').trim() || 'reg add failed');
100
- run('wscript.exe', [vbs]); // start now, hidden
101
- }
102
- function winUninstall() {
103
- run('reg', ['delete', WIN_RUN_KEY, '/v', WIN_RUN_NAME, '/f']);
104
- run('taskkill', ['/IM', 'chatpanel-bridge.exe', '/F']);
105
- }
106
- function winStatus() {
107
- return run('reg', ['query', WIN_RUN_KEY, '/v', WIN_RUN_NAME]).status === 0;
108
- }
109
-
110
- // ---------------------------------------------------------------- Linux (systemd user)
111
- const linUnit = () => path.join(os.homedir(), '.config', 'systemd', 'user', 'chatpanel-bridge.service');
112
-
113
- function linInstall() {
114
- const { program, args } = resolveLaunch();
115
- const exec = [program, ...args].map((a) => (/\s/.test(a) ? `"${a}"` : a)).join(' ');
116
- const unit = `[Unit]
117
- Description=${DISPLAY}
17
+ `,o=S();l(e.dirname(o),{recursive:!0}),p(o,c),n("launchctl",["unload",o]);const y=n("launchctl",["load","-w",o]);if(y.status!==0)throw new Error((y.stderr||"").trim()||"launchctl load failed")}function j(){const t=S();n("launchctl",["unload","-w",t]),v(t)&&b(t)}function A(){return(n("launchctl",["list"]).stdout||"").includes(d)}const g="HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",h="ChatPanelBridge",k=()=>e.join(u.homedir(),".chatpanel","launch.vbs");function U(){const{program:t,args:r}=m(),s=[t,...r].map(c=>`""${c}""`).join(" "),i=k();l(e.dirname(i),{recursive:!0}),p(i,`CreateObject("WScript.Shell").Run "${s}", 0, False\r
18
+ `);const a=n("reg",["add",g,"/v",h,"/t","REG_SZ","/d",`wscript.exe "${i}"`,"/f"]);if(a.status!==0)throw new Error((a.stderr||"").trim()||"reg add failed");n("wscript.exe",[i])}function C(){n("reg",["delete",g,"/v",h,"/f"]),n("taskkill",["/IM","chatpanel-bridge.exe","/F"])}function D(){return n("reg",["query",g,"/v",h]).status===0}const x=()=>e.join(u.homedir(),".config","systemd","user","chatpanel-bridge.service");function R(){const{program:t,args:r}=m(),s=[t,...r].map(o=>/\s/.test(o)?`"${o}"`:o).join(" "),i=`[Unit]
19
+ Description=${I}
118
20
  After=network.target
119
21
 
120
22
  [Service]
121
- ExecStart=${exec}
23
+ ExecStart=${s}
122
24
  Restart=on-failure
123
25
 
124
26
  [Install]
125
27
  WantedBy=default.target
126
- `;
127
- const p = linUnit();
128
- mkdirSync(path.dirname(p), { recursive: true });
129
- writeFileSync(p, unit);
130
- run('systemctl', ['--user', 'daemon-reload']);
131
- const r = run('systemctl', ['--user', 'enable', '--now', 'chatpanel-bridge']);
132
- if (r.status !== 0) throw new Error((r.stderr || '').trim() || 'systemctl enable failed');
133
- }
134
- function linUninstall() {
135
- run('systemctl', ['--user', 'disable', '--now', 'chatpanel-bridge']);
136
- const p = linUnit();
137
- if (existsSync(p)) rmSync(p);
138
- }
139
- function linStatus() {
140
- return (run('systemctl', ['--user', 'is-enabled', 'chatpanel-bridge']).stdout || '').trim() === 'enabled';
141
- }
142
-
143
- // ---------------------------------------------------------------- dispatch
144
- function byPlatform(mac, win, lin) {
145
- if (process.platform === 'darwin') return mac();
146
- if (process.platform === 'win32') return win();
147
- if (process.platform === 'linux') return lin();
148
- throw new Error(`Auto-start isn't supported on ${process.platform} yet — run the bridge directly.`);
149
- }
150
-
151
- export function installService() {
152
- return byPlatform(macInstall, winInstall, linInstall);
153
- }
154
- export function uninstallService() {
155
- return byPlatform(macUninstall, winUninstall, linUninstall);
156
- }
157
- export function serviceStatus() {
158
- return byPlatform(macStatus, winStatus, linStatus);
159
- }
160
-
161
- // Restart the installed service into a freshly-swapped binary (used by self-
162
- // update). Detached so it survives the restart killing the caller — works whether
163
- // invoked from inside the service (POST /update) or a CLI `--update`.
164
- // • macOS — `launchctl kickstart -k` kills + relaunches the LaunchAgent.
165
- // • Linux — `systemctl --user restart`.
166
- // • Windows — kill the running bridge, wait ~2s (port frees), relaunch via the
167
- // hidden VBS, then delete the renamed old-*.exe.
168
- export function restartService() {
169
- try {
170
- if (process.platform === 'darwin') {
171
- const uid = typeof process.getuid === 'function' ? process.getuid() : 0;
172
- spawn('launchctl', ['kickstart', '-k', `gui/${uid}/${LABEL}`], { detached: true, stdio: 'ignore' }).unref();
173
- return true;
174
- }
175
- if (process.platform === 'linux') {
176
- spawn('systemctl', ['--user', 'restart', 'chatpanel-bridge'], { detached: true, stdio: 'ignore' }).unref();
177
- return true;
178
- }
179
- if (process.platform === 'win32') {
180
- const vbs = winVbs();
181
- const dir = path.dirname(process.execPath);
182
- const cmd =
183
- `taskkill /IM chatpanel-bridge.exe /F >nul 2>&1 & ` +
184
- `timeout /t 2 >nul & wscript.exe "${vbs}" & ` +
185
- `del /q "${path.join(dir, 'chatpanel-bridge.old-*.exe')}" >nul 2>&1`;
186
- spawn('cmd', ['/c', cmd], { detached: true, stdio: 'ignore', windowsHide: true }).unref();
187
- return true;
188
- }
189
- } catch {
190
- /* fall through */
191
- }
192
- return false;
193
- }
28
+ `,a=x();l(e.dirname(a),{recursive:!0}),p(a,i),n("systemctl",["--user","daemon-reload"]);const c=n("systemctl",["--user","enable","--now","chatpanel-bridge"]);if(c.status!==0)throw new Error((c.stderr||"").trim()||"systemctl enable failed")}function W(){n("systemctl",["--user","disable","--now","chatpanel-bridge"]);const t=x();v(t)&&b(t)}function N(){return(n("systemctl",["--user","is-enabled","chatpanel-bridge"]).stdout||"").trim()==="enabled"}function w(t,r,s){if(process.platform==="darwin")return t();if(process.platform==="win32")return r();if(process.platform==="linux")return s();throw new Error(`Auto-start isn't supported on ${process.platform} yet — run the bridge directly.`)}function M(){return w(L,U,R)}function K(){return w(j,C,W)}function O(){return w(A,D,N)}function Y(){try{if(process.platform==="darwin"){const t=typeof process.getuid=="function"?process.getuid():0;return f("launchctl",["kickstart","-k",`gui/${t}/${d}`],{detached:!0,stdio:"ignore"}).unref(),!0}if(process.platform==="linux")return f("systemctl",["--user","restart","chatpanel-bridge"],{detached:!0,stdio:"ignore"}).unref(),!0;if(process.platform==="win32"){const t=k(),r=e.dirname(process.execPath),s=`taskkill /IM chatpanel-bridge.exe /F >nul 2>&1 & timeout /t 2 >nul & wscript.exe "${t}" & del /q "${e.join(r,"chatpanel-bridge.old-*.exe")}" >nul 2>&1`;return f("cmd",["/c",s],{detached:!0,stdio:"ignore",windowsHide:!0}).unref(),!0}}catch{}return!1}export{M as installService,m as resolveLaunch,Y as restartService,O as serviceStatus,K as uninstallService};
package/src/sign-in.js CHANGED
@@ -1,91 +1 @@
1
- // "Not signed in" — the commonest first-run failure, said as an instruction instead of an exit code.
2
- //
3
- // A user installs ChatPanel, picks Claude Code or Codex, and sends a message before they have
4
- // ever signed in to that CLI. The CLI prints one line ("Not logged in · Please run /login"),
5
- // exits 1, and what reached the panel was "Claude Code exited 1" — which reads as a ChatPanel
6
- // bug, and says nothing about the one thing that fixes it. Worse, in stream-json mode Claude
7
- // Code emits that line as an ASSISTANT message, so it could arrive as if it were the answer.
8
- //
9
- // Two halves, one vocabulary:
10
- // • `signInStatus(agentId, spec)` asks the CLI itself, cheaply, BEFORE a turn is sent —
11
- // `claude auth status` (JSON, `loggedIn`) and `codex login status` (a line) — so the
12
- // agent's availability says "not signed in: run …" and the panel shows it up front. Only
13
- // an answer that clearly says "not signed in" counts; an old CLI without the subcommand,
14
- // a timeout or anything unreadable is taken as signed in, because the turn itself is the
15
- // final judge and a wrong "not signed in" would block a working agent.
16
- // • `loginRequired(text)` recognises the failure in a turn's output; `signInMessage` is
17
- // the sentence both halves say.
18
- //
19
- // ChatPanel cannot sign in for the user: the login is the CLI's own OAuth flow, in a browser,
20
- // started from a terminal. So the message names the exact command and says to send again.
21
-
22
- import { spawn } from 'node:child_process';
23
- import { buildSpawnSpec } from './env.js';
24
-
25
- /** How to sign in, per harness — the command a person types. */
26
- export const SIGN_IN_HINTS = Object.freeze({
27
- claude: 'open a terminal, run `claude`, and type `/login`',
28
- codex: 'open a terminal and run `codex login`',
29
- copilot: 'open a terminal, run `copilot`, and type `/login`',
30
- opencode: 'open a terminal and run `opencode auth login`',
31
- kiro: 'open a terminal and run `kiro-cli login`',
32
- hermes: 'open a terminal and run `hermes setup`',
33
- antigravity: 'open a terminal, run `agy`, and sign in',
34
- deepseek: 'open a terminal and sign in to the DeepSeek CLI',
35
- pi: 'open a terminal, run `pi`, and sign in',
36
- });
37
-
38
- const LOGIN_RE = /not logged in|please run \/login|authentication_failed|invalid api key(?:\s*·\s*please run)?|please (?:log|sign) ?in|login required|not authenticated|unauthenticated|missing bearer token|no credentials|\b401\b.*unauthori[sz]ed|token (?:has )?expired.*(?:log|sign) ?in|run `?(?:codex|claude) login`?/i;
39
-
40
- /** Does this output say the CLI is not signed in? MCP-server auth failures are a different thing and are excluded. */
41
- export function loginRequired(text) {
42
- const t = String(text || '');
43
- if (!t) return false;
44
- if (/\bmcp\b/i.test(t) && !/not logged in|please run \/login|authentication_failed/i.test(t)) return false;
45
- return LOGIN_RE.test(t);
46
- }
47
-
48
- /** The one sentence: what happened, that nothing was sent, what to do, and that ChatPanel cannot do it. */
49
- export function signInMessage(label, agentId) {
50
- const hint = SIGN_IN_HINTS[agentId] || `sign in to ${label} in your terminal`;
51
- return `${label} isn't signed in on this machine, so your message was not sent. ChatPanel uses your own ${label} login and can't sign in for you: ${hint}, finish the sign-in in the browser, then send your message again.`;
52
- }
53
-
54
- const CHECKS = {
55
- claude: { args: ['auth', 'status'], read: (out) => { try { const j = JSON.parse(out.slice(out.indexOf('{'))); return typeof j.loggedIn === 'boolean' ? j.loggedIn : null; } catch { return null; } } },
56
- codex: { args: ['login', 'status'], read: (out) => (/not logged in/i.test(out) ? false : /logged in/i.test(out) ? true : null) },
57
- };
58
-
59
- const cache = new Map(); // agentId -> { at, signedIn }
60
- const TTL_MS = 15_000;
61
-
62
- /**
63
- * `true` / `false` when the CLI says so; `null` when it does not have a status command, did
64
- * not answer in time, or said something unreadable — never a guess. `spec` is the launch spec
65
- * from resolveCommand (native / script / cmd / wsl), so the check runs the SAME binary a turn
66
- * would. Cached briefly: /health asks for every agent on every probe.
67
- */
68
- export async function signInStatus(agentId, spec, { timeoutMs = 5000, now = Date.now(), spawnImpl = spawn } = {}) {
69
- const check = CHECKS[agentId];
70
- if (!check || !spec) return null;
71
- const hit = cache.get(agentId);
72
- if (hit && now - hit.at < TTL_MS) return hit.signedIn;
73
- const result = await new Promise((resolve) => {
74
- let out = '';
75
- let child;
76
- try {
77
- const [bin, argv, opts] = buildSpawnSpec(spec, check.args, process.cwd(), null);
78
- child = spawnImpl(bin, argv, { ...opts, stdio: ['ignore', 'pipe', 'pipe'] });
79
- } catch { return resolve(null); }
80
- const t = setTimeout(() => { try { child.kill('SIGKILL'); } catch { /* gone */ } resolve(null); }, timeoutMs);
81
- child.stdout?.on('data', (d) => { out += d.toString(); });
82
- child.stderr?.on('data', (d) => { out += d.toString(); });
83
- child.on('error', () => { clearTimeout(t); resolve(null); });
84
- child.on('close', () => { clearTimeout(t); resolve(check.read(out)); });
85
- });
86
- cache.set(agentId, { at: now, signedIn: result });
87
- return result;
88
- }
89
-
90
- /** Forget a cached answer — after a sign-in the next probe should ask again. */
91
- export function resetSignInCache() { cache.clear(); }
1
+ import{spawn as f}from"node:child_process";import{buildSpawnSpec as y}from"./env.js";const S=Object.freeze({claude:"open a terminal, run `claude`, and type `/login`",codex:"open a terminal and run `codex login`",copilot:"open a terminal, run `copilot`, and type `/login`",opencode:"open a terminal and run `opencode auth login`",kiro:"open a terminal and run `kiro-cli login`",hermes:"open a terminal and run `hermes setup`",antigravity:"open a terminal, run `agy`, and sign in",deepseek:"open a terminal and sign in to the DeepSeek CLI",pi:"open a terminal, run `pi`, and sign in"}),I=/not logged in|please run \/login|authentication_failed|invalid api key(?:\s*·\s*please run)?|please (?:log|sign) ?in|login required|not authenticated|unauthenticated|missing bearer token|no credentials|\b401\b.*unauthori[sz]ed|token (?:has )?expired.*(?:log|sign) ?in|run `?(?:codex|claude) login`?/i;function _(n){const e=String(n||"");return!e||/\bmcp\b/i.test(e)&&!/not logged in|please run \/login|authentication_failed/i.test(e)?!1:I.test(e)}function T(n,e){const a=S[e]||`sign in to ${n} in your terminal`;return`${n} isn't signed in on this machine, so your message was not sent. ChatPanel uses your own ${n} login and can't sign in for you: ${a}, finish the sign-in in the browser, then send your message again.`}const x={claude:{args:["auth","status"],read:n=>{try{const e=JSON.parse(n.slice(n.indexOf("{")));return typeof e.loggedIn=="boolean"?e.loggedIn:null}catch{return null}}},codex:{args:["login","status"],read:n=>/not logged in/i.test(n)?!1:/logged in/i.test(n)?!0:null}},u=new Map,k=15e3;async function C(n,e,{timeoutMs:a=5e3,now:c=Date.now(),spawnImpl:p=f}={}){const r=x[n];if(!r||!e)return null;const s=u.get(n);if(s&&c-s.at<k)return s.signedIn;const g=await new Promise(o=>{let l="",t;try{const[i,h,m]=y(e,r.args,process.cwd(),null);t=p(i,h,{...m,stdio:["ignore","pipe","pipe"]})}catch{return o(null)}const d=setTimeout(()=>{try{t.kill("SIGKILL")}catch{}o(null)},a);t.stdout?.on("data",i=>{l+=i.toString()}),t.stderr?.on("data",i=>{l+=i.toString()}),t.on("error",()=>{clearTimeout(d),o(null)}),t.on("close",()=>{clearTimeout(d),o(r.read(l))})});return u.set(n,{at:c,signedIn:g}),g}function L(){u.clear()}export{S as SIGN_IN_HINTS,_ as loginRequired,L as resetSignInCache,T as signInMessage,C as signInStatus};