shellpuppet 0.1.0 → 0.2.0

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 (95) hide show
  1. package/README.md +191 -32
  2. package/dist/cli/desktopShortcut.d.ts +22 -0
  3. package/dist/cli/desktopShortcut.js +157 -0
  4. package/dist/cli/desktopShortcut.js.map +1 -0
  5. package/dist/cli/index.js +205 -52
  6. package/dist/cli/index.js.map +1 -1
  7. package/dist/client/http.d.ts +62 -1
  8. package/dist/client/http.js +388 -32
  9. package/dist/client/http.js.map +1 -1
  10. package/dist/core/dialogs.d.ts +20 -12
  11. package/dist/core/dialogs.js +31 -19
  12. package/dist/core/dialogs.js.map +1 -1
  13. package/dist/core/manager.d.ts +35 -5
  14. package/dist/core/manager.js +121 -8
  15. package/dist/core/manager.js.map +1 -1
  16. package/dist/core/nativePty.d.ts +9 -5
  17. package/dist/core/nativePty.js +11 -6
  18. package/dist/core/nativePty.js.map +1 -1
  19. package/dist/core/promptDetector.d.ts +37 -3
  20. package/dist/core/promptDetector.js +303 -12
  21. package/dist/core/promptDetector.js.map +1 -1
  22. package/dist/core/reasoning.d.ts +19 -6
  23. package/dist/core/reasoning.js +223 -30
  24. package/dist/core/reasoning.js.map +1 -1
  25. package/dist/core/regexBudget.d.ts +20 -0
  26. package/dist/core/regexBudget.js +25 -1
  27. package/dist/core/regexBudget.js.map +1 -1
  28. package/dist/core/renderer.d.ts +16 -1
  29. package/dist/core/renderer.js +97 -6
  30. package/dist/core/renderer.js.map +1 -1
  31. package/dist/core/selection.d.ts +6 -0
  32. package/dist/core/selection.js +48 -0
  33. package/dist/core/selection.js.map +1 -0
  34. package/dist/core/session.d.ts +266 -12
  35. package/dist/core/session.js +583 -99
  36. package/dist/core/session.js.map +1 -1
  37. package/dist/core/types.d.ts +53 -18
  38. package/dist/core/types.js +30 -6
  39. package/dist/core/types.js.map +1 -1
  40. package/dist/core/waiter.d.ts +12 -4
  41. package/dist/core/waiter.js +63 -70
  42. package/dist/core/waiter.js.map +1 -1
  43. package/dist/core/windowsConsoleHost.d.ts +147 -0
  44. package/dist/core/windowsConsoleHost.js +588 -0
  45. package/dist/core/windowsConsoleHost.js.map +1 -0
  46. package/dist/core/windowsPtyStart.d.ts +100 -29
  47. package/dist/core/windowsPtyStart.js +143 -36
  48. package/dist/core/windowsPtyStart.js.map +1 -1
  49. package/dist/daemon/auth.d.ts +72 -2
  50. package/dist/daemon/auth.js +128 -3
  51. package/dist/daemon/auth.js.map +1 -1
  52. package/dist/daemon/config.d.ts +44 -1
  53. package/dist/daemon/config.js +276 -9
  54. package/dist/daemon/config.js.map +1 -1
  55. package/dist/daemon/folderPicker.d.ts +27 -0
  56. package/dist/daemon/folderPicker.js +115 -0
  57. package/dist/daemon/folderPicker.js.map +1 -0
  58. package/dist/daemon/index.js +20 -19
  59. package/dist/daemon/index.js.map +1 -1
  60. package/dist/daemon/launchProfiles.d.ts +155 -0
  61. package/dist/daemon/launchProfiles.js +554 -0
  62. package/dist/daemon/launchProfiles.js.map +1 -0
  63. package/dist/daemon/paths.d.ts +2 -0
  64. package/dist/daemon/paths.js.map +1 -1
  65. package/dist/daemon/screenshot.d.ts +58 -1
  66. package/dist/daemon/screenshot.js +172 -26
  67. package/dist/daemon/screenshot.js.map +1 -1
  68. package/dist/daemon/server.d.ts +219 -10
  69. package/dist/daemon/server.js +1970 -203
  70. package/dist/daemon/server.js.map +1 -1
  71. package/dist/daemon/sessionFeed.d.ts +48 -0
  72. package/dist/daemon/sessionFeed.js +101 -0
  73. package/dist/daemon/sessionFeed.js.map +1 -0
  74. package/dist/daemon/viewerLauncher.d.ts +100 -9
  75. package/dist/daemon/viewerLauncher.js +349 -67
  76. package/dist/daemon/viewerLauncher.js.map +1 -1
  77. package/dist/mcp/config.d.ts +7 -14
  78. package/dist/mcp/config.js +10 -21
  79. package/dist/mcp/config.js.map +1 -1
  80. package/dist/mcp/index.js +20 -11
  81. package/dist/mcp/index.js.map +1 -1
  82. package/dist/mcp/tools.d.ts +14 -7
  83. package/dist/mcp/tools.js +161 -60
  84. package/dist/mcp/tools.js.map +1 -1
  85. package/dist/viewer/dashboard-folders.js +20 -0
  86. package/dist/viewer/dashboard-layout.js +52 -0
  87. package/dist/viewer/dashboard.css +67 -0
  88. package/dist/viewer/dashboard.html +44 -0
  89. package/dist/viewer/dashboard.js +1518 -0
  90. package/dist/viewer/icon.ico +0 -0
  91. package/dist/viewer/index.html +12 -7
  92. package/dist/viewer/pane.js +736 -0
  93. package/dist/viewer/viewer.css +18 -7
  94. package/dist/viewer/viewer.js +47 -624
  95. package/package.json +13 -13
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Token generation and verification (design §4.1).
3
3
  *
4
- * Three credentials, deliberately different in kind:
4
+ * Five credentials, deliberately different in kind:
5
5
  *
6
6
  * - **Client token**: full API access; generated per daemon run, written to
7
7
  * `daemon.json`, read by same-user clients. Rotates on restart. Travels in an
@@ -25,6 +25,15 @@
25
25
  * becomes: it is enforced by the daemon, not by the viewer page. The page's
26
26
  * own toggle stops that tab sending keystrokes and is a convenience; a
27
27
  * read-only credential means the daemon will not accept them.
28
+ * - **Dashboard grant**: the `dt` in a dashboard URL. One use, short life,
29
+ * not a session credential, and it cannot open a stream. Its only use is
30
+ * to be exchanged, once, at `GET /dashboard` for the cookie below. The
31
+ * daemon mints it and never returns it to the caller.
32
+ * - **Dashboard credential**: what that grant becomes. One `HttpOnly` cookie
33
+ * for the whole dashboard, plus a ring of the eight newest per-document
34
+ * proofs. A second redemption replaces the credential and drops its proofs.
35
+ * The cookie opens a session stream when the upgrade carries a live proof
36
+ * as the `sp-csrf` subprotocol. A viewer cookie is not this credential.
28
37
  */
29
38
  import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
30
39
  /**
@@ -37,11 +46,13 @@ import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
37
46
  * transcript is inert. Expired is not a dead end: mint another.
38
47
  */
39
48
  export const VIEWER_GRANT_TTL_MS = 5 * 60_000;
49
+ /** How many per-document proofs the current dashboard credential keeps. */
50
+ export const DASHBOARD_PROOF_RING = 8;
40
51
  export function generateToken() {
41
52
  return randomBytes(32).toString('hex');
42
53
  }
43
54
  /** Constant-time comparison over sha256 digests, so length never leaks. */
44
- function tokensEqual(a, b) {
55
+ export function tokensEqual(a, b) {
45
56
  const da = createHash('sha256').update(a).digest();
46
57
  const db = createHash('sha256').update(b).digest();
47
58
  return timingSafeEqual(da, db);
@@ -63,6 +74,9 @@ export class TokenStore {
63
74
  clientToken;
64
75
  grants = new Map();
65
76
  streams = new Map();
77
+ dashboardGrants = new Map();
78
+ /** The one live dashboard credential. A new redemption replaces it. */
79
+ dashboardCredential = null;
66
80
  constructor(clientToken = generateToken()) {
67
81
  this.clientToken = clientToken;
68
82
  }
@@ -161,10 +175,94 @@ export class TokenStore {
161
175
  this.streams.delete(token);
162
176
  }
163
177
  }
178
+ /**
179
+ * Mint a one-use dashboard grant. It is not a session credential. The HTTP
180
+ * client cannot choose its lifetime: only a test passes `ttlMs`.
181
+ */
182
+ mintDashboardGrant(options = {}) {
183
+ const now = options.now ?? Date.now();
184
+ this.pruneExpiredDashboard(now);
185
+ const token = generateToken();
186
+ this.dashboardGrants.set(token, {
187
+ expiresAt: now + (options.ttlMs ?? VIEWER_GRANT_TTL_MS),
188
+ });
189
+ return token;
190
+ }
191
+ /**
192
+ * Exchange a dashboard grant for the one dashboard credential, consuming
193
+ * the grant. Returns null for an unknown, already-redeemed or expired
194
+ * grant. The three cases are deliberately indistinguishable. A successful
195
+ * redemption replaces whatever credential was current and drops its proofs.
196
+ * A failed redemption leaves the current credential alone.
197
+ */
198
+ redeemDashboardGrant(presented, now = Date.now()) {
199
+ this.pruneExpiredDashboard(now);
200
+ if (presented === undefined || presented === null || presented === '')
201
+ return null;
202
+ const key = findKey(this.dashboardGrants, presented);
203
+ if (key === null)
204
+ return null;
205
+ const grant = this.dashboardGrants.get(key);
206
+ this.dashboardGrants.delete(key);
207
+ if (grant === undefined || grant.expiresAt <= now)
208
+ return null;
209
+ const token = generateToken();
210
+ this.dashboardCredential = { token, grant: key, proofs: [] };
211
+ return { token };
212
+ }
213
+ /** The dashboard cookie value, or false when nothing current matches. */
214
+ verifyDashboardToken(presented) {
215
+ if (presented === undefined || presented === null || presented === '')
216
+ return false;
217
+ if (this.dashboardCredential === null)
218
+ return false;
219
+ return tokensEqual(presented, this.dashboardCredential.token);
220
+ }
221
+ /**
222
+ * Take back a dashboard grant and the credential it became. An unspent
223
+ * grant is deleted. A spent one drops the credential and its proofs.
224
+ */
225
+ revokeDashboardGrant(grant) {
226
+ if (grant === '')
227
+ return;
228
+ const key = findKey(this.dashboardGrants, grant);
229
+ if (key !== null)
230
+ this.dashboardGrants.delete(key);
231
+ if (this.dashboardCredential !== null && tokensEqual(this.dashboardCredential.grant, grant)) {
232
+ this.dashboardCredential = null;
233
+ }
234
+ }
235
+ /**
236
+ * A fresh proof for the current credential, or null when there is none.
237
+ * The ninth proof drops the oldest.
238
+ */
239
+ issueDashboardProof() {
240
+ if (this.dashboardCredential === null)
241
+ return null;
242
+ const proof = generateToken();
243
+ this.dashboardCredential.proofs.push(proof);
244
+ while (this.dashboardCredential.proofs.length > DASHBOARD_PROOF_RING) {
245
+ this.dashboardCredential.proofs.shift();
246
+ }
247
+ return proof;
248
+ }
249
+ /**
250
+ * Whether `presented` is one of the proofs still in the ring. The compare
251
+ * hashes both strings, so a wrong proof of the same length takes the same
252
+ * path as a right one.
253
+ */
254
+ acceptsDashboardProof(presented) {
255
+ if (presented === undefined || presented === null || presented === '')
256
+ return false;
257
+ if (this.dashboardCredential === null)
258
+ return false;
259
+ return this.dashboardCredential.proofs.some((proof) => tokensEqual(presented, proof));
260
+ }
164
261
  /**
165
262
  * Verify a bearer token. Only the client token authenticates this way:
166
263
  * viewer credentials are cookie-borne and session-scoped, and are checked
167
- * with `verifyStreamToken`.
264
+ * with `verifyStreamToken`. The dashboard cookie is checked with
265
+ * `verifyDashboardToken`.
168
266
  */
169
267
  verify(presented) {
170
268
  if (presented === undefined || presented === null || presented === '')
@@ -179,6 +277,12 @@ export class TokenStore {
179
277
  this.grants.delete(token);
180
278
  }
181
279
  }
280
+ pruneExpiredDashboard(now) {
281
+ for (const [token, grant] of this.dashboardGrants) {
282
+ if (grant.expiresAt <= now)
283
+ this.dashboardGrants.delete(token);
284
+ }
285
+ }
182
286
  }
183
287
  /** Extract a bearer token from an Authorization header value. */
184
288
  export function bearerToken(header) {
@@ -238,4 +342,25 @@ export function viewerCookie(sessionId, streamToken) {
238
342
  `; Path=/sessions/${encodeURIComponent(sessionId)}` +
239
343
  '; HttpOnly; SameSite=Strict');
240
344
  }
345
+ /**
346
+ * The dashboard's cookie name. One credential for the dashboard, so one
347
+ * path: `/`. Cookies ignore ports, and `cookieValues` tries every value.
348
+ */
349
+ export const DASHBOARD_COOKIE = 'sp_dash';
350
+ /**
351
+ * The `Set-Cookie` value delivering the dashboard credential.
352
+ *
353
+ * `HttpOnly` keeps it out of `document.cookie`. `SameSite=Strict` stops any
354
+ * other site's navigation carrying it. No `Max-Age`: it dies with the
355
+ * browsing session. No `Secure`: the daemon is loopback-only http, and a
356
+ * `Secure` cookie would never be stored. No `Domain`: it stays host-only.
357
+ */
358
+ export function dashboardCookie(token) {
359
+ return `${DASHBOARD_COOKIE}=${encodeURIComponent(token)}; Path=/; HttpOnly; SameSite=Strict`;
360
+ }
361
+ /** The proof inside `sp-csrf.<64 hex>`, or null when the protocol is not that. */
362
+ export function dashboardProofFromProtocol(protocol) {
363
+ const match = /^sp-csrf\.([0-9a-f]{64})$/.exec(protocol);
364
+ return match?.[1] ?? null;
365
+ }
241
366
  //# sourceMappingURL=auth.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/daemon/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,a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U,WAAW,CAAC,MAA0B,EAAE,IAAY;IAClE,OAAO,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC/C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB,EAAE,WAAmB;IACjE,OAAO,CACL,GAAG,aAAa,IAAI,kBAAkB,CAAC,WAAW,CAAC,EAAE;QACrD,oBAAoB,kBAAkB,CAAC,SAAS,CAAC,EAAE;QACnD,6BAA6B,CAC9B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,GAAG,gBAAgB,IAAI,kBAAkB,CAAC,KAAK,CAAC,qCAAqC,CAAC;AAC/F,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,0BAA0B,CAAC,QAAgB;IACzD,MAAM,KAAK,GAAG,2BAA2B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC5B,CAAC"}
@@ -33,8 +33,15 @@
33
33
  import type { DialogSignature } from '../core/dialogs.js';
34
34
  import type { AgentSignature } from '../core/reasoning.js';
35
35
  import type { PolicyConfig, SessionEnvMode } from '../core/types.js';
36
- import type { ViewerLaunchConfig } from './viewerLauncher.js';
36
+ import type { ViewerLaunchConfig, ViewerLaunchMode } from './viewerLauncher.js';
37
+ import type { LauncherConfig } from './launchProfiles.js';
38
+ export declare const DEFAULT_VIEWER_LAUNCH_MODE: ViewerLaunchMode;
37
39
  export interface DaemonConfig {
40
+ /** How clients start a missing daemon. This is read before daemon startup. */
41
+ daemon?: {
42
+ startWith?: string[];
43
+ startWithOnlyIfEnvContains?: string;
44
+ };
38
45
  policy?: PolicyConfig;
39
46
  /** Idle self-shutdown threshold in minutes; fractions allowed (design §2.3). */
40
47
  idleMinutes?: number;
@@ -46,6 +53,16 @@ export interface DaemonConfig {
46
53
  };
47
54
  /** How the viewer window is opened. */
48
55
  viewer?: ViewerLaunchConfig;
56
+ /** Initial dashboard text size when the browser has no saved preference. */
57
+ dashboard?: {
58
+ fontSize?: number;
59
+ };
60
+ /**
61
+ * The named programs the dashboard may start (`launcher.profiles`, design
62
+ * §4.3). Absent means a watch-only dashboard. Invalid entries are named in
63
+ * `problems` and left out; their siblings still load.
64
+ */
65
+ launcher?: LauncherConfig;
49
66
  /**
50
67
  * Permission dialogs to recognise beyond the built-in ones (`dialogs.ts`):
51
68
  * the entries that compile. The rest are reported and left out.
@@ -64,12 +81,38 @@ export interface DaemonConfig {
64
81
  * daemon only checks them, so a mistake is reported in `daemon.log` too.
65
82
  */
66
83
  agentPassEnv?: Record<string, string[]>;
84
+ /**
85
+ * The variables a caller may name at start for a session that runs as no
86
+ * agent (`envNames`, design §4.6): `terminal_start`'s `envNames` and the
87
+ * CLI's `--env-name`. The MCP server and the CLI hold the values and apply
88
+ * the list; the daemon only checks it, so a mistake is reported in
89
+ * `daemon.log` too.
90
+ */
91
+ envNames?: string[];
67
92
  }
68
93
  export interface ParsedDaemonConfig {
69
94
  config: DaemonConfig;
70
95
  /** Human-readable problems. The daemon logs each one loudly at startup. */
71
96
  problems: string[];
72
97
  }
98
+ /**
99
+ * Whether a problem bears on the `envNames` list, for the clients that apply
100
+ * it to report alongside their own refusals: a problem with the list itself,
101
+ * the unread `mcp.passEnv`, or a `config.json` that could not be read at all,
102
+ * which leaves the list empty.
103
+ */
104
+ export declare function isEnvNamesProblem(problem: string): boolean;
105
+ /**
106
+ * The daemon.log line for a signature that ran past the regular-expression
107
+ * time budget on a screen and is set aside for a minute (`SET_ASIDE_MS`), to
108
+ * be tried again. One from config is a CONFIG PROBLEM its author can act on.
109
+ * A built-in one is not anybody's to change, and a busy machine can make an
110
+ * ordinary pattern overrun, so its line says so and asks nothing.
111
+ */
112
+ export declare function signatureOverBudgetLog(kind: 'dialog' | 'agent', name: string, builtIn: boolean): {
113
+ message: string;
114
+ meta: Record<string, string>;
115
+ };
73
116
  /** Validate a parsed config value. `undefined` means "no file": pure defaults. */
74
117
  export declare function parseDaemonConfig(raw: unknown): ParsedDaemonConfig;
75
118
  /** Read and validate the config file. ENOENT ⇒ defaults; unreadable ⇒ fail closed. */
@@ -35,9 +35,14 @@ import { configPath } from './paths.js';
35
35
  import { compileDialogs } from '../core/dialogs.js';
36
36
  import { BUILT_IN_SIGNATURES, compileSignatures } from '../core/reasoning.js';
37
37
  import { ENV_NAME_PATTERN } from '../core/types.js';
38
+ import { parseLauncher } from './launchProfiles.js';
39
+ export const DEFAULT_VIEWER_LAUNCH_MODE = 'dashboard';
38
40
  const POLICY_MODES = ['allow-all', 'allowlist', 'denylist'];
39
41
  const POLICY_KEYS = new Set(['mode', 'allow', 'deny', 'maxSessions']);
40
- /** `mcp` is the MCP adapter's section, known here so it is not flagged. */
42
+ /**
43
+ * `mcp` is the MCP adapter's section, known here so it is not flagged; the
44
+ * daemon looks inside it only for a `passEnv`, which it reports.
45
+ */
41
46
  const TOP_LEVEL_KEYS = new Set([
42
47
  'policy',
43
48
  'idleMinutes',
@@ -45,17 +50,23 @@ const TOP_LEVEL_KEYS = new Set([
45
50
  'audit',
46
51
  'mcp',
47
52
  'viewer',
53
+ 'dashboard',
48
54
  'prompts',
49
55
  'agents',
56
+ 'envNames',
57
+ 'launcher',
58
+ 'daemon',
50
59
  ]);
60
+ const DAEMON_KEYS = new Set(['startWith', 'startWithOnlyIfEnvContains']);
51
61
  const VIEWER_KEYS = new Set(['launchMode', 'browserPath', 'profileDir']);
52
62
  const VIEWER_LAUNCH_MODES = [
63
+ 'dashboard',
53
64
  'isolated-app',
54
65
  'default-browser',
55
- 'none',
66
+ 'no-window',
56
67
  ];
57
68
  /**
58
- * Viewer launch options. An invalid value falls back to "none", NOT to the
69
+ * Viewer launch options. An invalid value falls back to "no-window", NOT to the
59
70
  * launching default: config the daemon cannot read must not cause it to start
60
71
  * spawning browser windows on someone's desktop, and a viewer that did not
61
72
  * open is visibly wrong in a way the operator can act on.
@@ -63,7 +74,7 @@ const VIEWER_LAUNCH_MODES = [
63
74
  function parseViewer(raw, problems) {
64
75
  if (!isRecord(raw)) {
65
76
  problems.push('viewer must be an object: not opening the viewer automatically');
66
- return { launchMode: 'none' };
77
+ return { launchMode: 'no-window' };
67
78
  }
68
79
  for (const key of Object.keys(raw)) {
69
80
  if (!VIEWER_KEYS.has(key)) {
@@ -73,12 +84,15 @@ function parseViewer(raw, problems) {
73
84
  const config = {};
74
85
  const launchMode = raw['launchMode'];
75
86
  if (launchMode !== undefined) {
76
- if (typeof launchMode === 'string' &&
87
+ if (launchMode === 'none') {
88
+ config.launchMode = 'no-window';
89
+ }
90
+ else if (typeof launchMode === 'string' &&
77
91
  VIEWER_LAUNCH_MODES.includes(launchMode)) {
78
92
  config.launchMode = launchMode;
79
93
  }
80
94
  else {
81
- config.launchMode = 'none';
95
+ config.launchMode = 'no-window';
82
96
  problems.push(`viewer.launchMode must be one of ${VIEWER_LAUNCH_MODES.join(' | ')}: not opening the viewer automatically`);
83
97
  }
84
98
  }
@@ -130,6 +144,43 @@ function parseAgentPassEnv(value, known, problems) {
130
144
  }
131
145
  return lists;
132
146
  }
147
+ /**
148
+ * Whether a problem bears on the `envNames` list, for the clients that apply
149
+ * it to report alongside their own refusals: a problem with the list itself,
150
+ * the unread `mcp.passEnv`, or a `config.json` that could not be read at all,
151
+ * which leaves the list empty.
152
+ */
153
+ export function isEnvNamesProblem(problem) {
154
+ return (problem.startsWith('envNames') ||
155
+ problem.startsWith('mcp.passEnv') ||
156
+ (problem.startsWith('config.json ') && problem.includes('refusing all commands')));
157
+ }
158
+ /**
159
+ * The daemon.log line for a signature that ran past the regular-expression
160
+ * time budget on a screen and is set aside for a minute (`SET_ASIDE_MS`), to
161
+ * be tried again. One from config is a CONFIG PROBLEM its author can act on.
162
+ * A built-in one is not anybody's to change, and a busy machine can make an
163
+ * ordinary pattern overrun, so its line says so and asks nothing.
164
+ */
165
+ export function signatureOverBudgetLog(kind, name, builtIn) {
166
+ if (builtIn) {
167
+ return {
168
+ message: 'signature set aside',
169
+ meta: {
170
+ signature: name,
171
+ note: `the built-in "${name}" ${kind} signature ran past the regular-expression time budget on a ` +
172
+ 'screen, as a busy machine can make it do; it is tried again in a minute, and there is nothing to change',
173
+ },
174
+ };
175
+ }
176
+ return {
177
+ message: 'CONFIG PROBLEM',
178
+ meta: {
179
+ problem: `the "${name}" ${kind} signature ran past the regular-expression time budget on a screen ` +
180
+ 'and is set aside for a minute at a time; if it keeps happening, simplify its patterns',
181
+ },
182
+ };
183
+ }
133
184
  /** A policy that refuses every command, naming the configuration problem. */
134
185
  function denyAllPolicy(reason) {
135
186
  // The empty allowlist is belt-and-braces: even if configError were ever
@@ -192,6 +243,40 @@ export function parseDaemonConfig(raw) {
192
243
  }
193
244
  if (raw['policy'] !== undefined)
194
245
  config.policy = parsePolicy(raw['policy'], problems);
246
+ if (raw['daemon'] !== undefined) {
247
+ const daemon = raw['daemon'];
248
+ if (!isRecord(daemon)) {
249
+ problems.push('daemon must be an object: starting directly');
250
+ }
251
+ else {
252
+ let valid = true;
253
+ for (const key of Object.keys(daemon)) {
254
+ if (!DAEMON_KEYS.has(key)) {
255
+ problems.push(`daemon has an unknown key "${key}": starting directly`);
256
+ valid = false;
257
+ }
258
+ }
259
+ const startWith = daemon['startWith'];
260
+ const condition = daemon['startWithOnlyIfEnvContains'];
261
+ if (startWith !== undefined && (!Array.isArray(startWith) || startWith.length < 1 ||
262
+ startWith.length > 16 || startWith.some((part) => typeof part !== 'string' ||
263
+ part.trim() === '' || part.length > 1024 || part.includes('\0')))) {
264
+ problems.push('daemon.startWith must have 1 to 16 non-blank strings of at most 1024 characters: starting directly');
265
+ valid = false;
266
+ }
267
+ if (condition !== undefined && (typeof condition !== 'string' || condition.trim() === '' ||
268
+ condition.length > 256)) {
269
+ problems.push('daemon.startWithOnlyIfEnvContains must be a non-blank string of at most 256 characters: starting directly');
270
+ valid = false;
271
+ }
272
+ if (valid && isStringArray(startWith)) {
273
+ config.daemon = {
274
+ startWith,
275
+ ...(typeof condition === 'string' ? { startWithOnlyIfEnvContains: condition } : {}),
276
+ };
277
+ }
278
+ }
279
+ }
195
280
  const sessionEnv = raw['sessionEnv'];
196
281
  if (sessionEnv !== undefined) {
197
282
  if (sessionEnv === 'passthrough' || sessionEnv === 'clean' || isStringArray(sessionEnv)) {
@@ -225,6 +310,28 @@ export function parseDaemonConfig(raw) {
225
310
  }
226
311
  if (raw['viewer'] !== undefined)
227
312
  config.viewer = parseViewer(raw['viewer'], problems);
313
+ if (raw['dashboard'] !== undefined) {
314
+ const dashboard = raw['dashboard'];
315
+ if (!isRecord(dashboard)) {
316
+ problems.push('dashboard must be an object: ignored');
317
+ }
318
+ else {
319
+ config.dashboard = {};
320
+ for (const key of Object.keys(dashboard)) {
321
+ if (key !== 'fontSize')
322
+ problems.push(`dashboard has an unknown key "${key}": ignored (typo?)`);
323
+ }
324
+ if (dashboard['fontSize'] !== undefined) {
325
+ const size = dashboard['fontSize'];
326
+ if (typeof size === 'number' && Number.isInteger(size) && size >= 8 && size <= 32) {
327
+ config.dashboard.fontSize = size;
328
+ }
329
+ else {
330
+ problems.push('dashboard.fontSize must be an integer from 8 to 32: ignored');
331
+ }
332
+ }
333
+ }
334
+ }
228
335
  // Extra dialog signatures. A broken one is reported and left out, and the
229
336
  // built-in ones are recognised regardless: detection that misses a dialog
230
337
  // costs only what it cost before, so there is nothing to fail closed for.
@@ -277,8 +384,165 @@ export function parseDaemonConfig(raw) {
277
384
  }
278
385
  }
279
386
  }
387
+ // Dashboard launch profiles. A broken entry is named and left out; its
388
+ // siblings still load, and nothing here changes policy.
389
+ if (raw['launcher'] !== undefined) {
390
+ const known = new Set([
391
+ ...BUILT_IN_SIGNATURES.map((signature) => signature.name),
392
+ ...(config.agentSignatures ?? []).map((signature) => signature.name),
393
+ ]);
394
+ const parsed = parseLauncher(raw['launcher'], known);
395
+ config.launcher = parsed.launcher;
396
+ problems.push(...parsed.problems);
397
+ }
398
+ // The variables a caller may name at start. A list under `mcp.passEnv` is
399
+ // not read: it passes nothing, and the problem says where the list goes.
400
+ const envNames = raw['envNames'];
401
+ if (envNames !== undefined) {
402
+ if (!Array.isArray(envNames)) {
403
+ problems.push('envNames in config.json must be an array of variable names: passing none');
404
+ }
405
+ else {
406
+ const valid = envNames.filter((name) => typeof name === 'string' && ENV_NAME_PATTERN.test(name));
407
+ if (valid.length !== envNames.length) {
408
+ problems.push('envNames in config.json: ignoring entries that are not variable names');
409
+ }
410
+ config.envNames = valid;
411
+ }
412
+ }
413
+ const mcp = raw['mcp'];
414
+ if (isRecord(mcp) && mcp['passEnv'] !== undefined) {
415
+ problems.push('mcp.passEnv is not read, so nothing passes from it: the variables a caller may name at start ' +
416
+ 'are read from envNames, at the top level of config.json');
417
+ }
280
418
  return { config, problems };
281
419
  }
420
+ /** Locate a JSON syntax error without using V8's message, which may quote config text. */
421
+ function jsonErrorLocation(raw) {
422
+ class InvalidJson extends Error {
423
+ offset;
424
+ constructor(offset) {
425
+ super('invalid JSON');
426
+ this.offset = offset;
427
+ }
428
+ }
429
+ let at = 0;
430
+ const fail = () => { throw new InvalidJson(at); };
431
+ const space = () => {
432
+ while (at < raw.length && /[ \t\r\n]/.test(raw[at] ?? ''))
433
+ at++;
434
+ };
435
+ const expectChar = (ch) => {
436
+ if (raw[at] !== ch)
437
+ fail();
438
+ at++;
439
+ };
440
+ const string = () => {
441
+ expectChar('"');
442
+ while (at < raw.length) {
443
+ const ch = raw[at] ?? '';
444
+ if (ch === '"') {
445
+ at++;
446
+ return;
447
+ }
448
+ if (ch.charCodeAt(0) < 0x20)
449
+ fail();
450
+ if (ch === '\\') {
451
+ at++;
452
+ const escaped = raw[at] ?? '';
453
+ if (escaped === 'u') {
454
+ at++;
455
+ for (let n = 0; n < 4; n++, at++) {
456
+ if (!/[0-9a-fA-F]/.test(raw[at] ?? ''))
457
+ fail();
458
+ }
459
+ continue;
460
+ }
461
+ if (!/["\\/bfnrt]/.test(escaped))
462
+ fail();
463
+ }
464
+ at++;
465
+ }
466
+ fail();
467
+ };
468
+ const value = (depth) => {
469
+ if (depth > 256)
470
+ fail();
471
+ space();
472
+ const ch = raw[at];
473
+ if (ch === '"') {
474
+ string();
475
+ return;
476
+ }
477
+ if (ch === '{') {
478
+ at++;
479
+ space();
480
+ if (raw[at] === '}') {
481
+ at++;
482
+ return;
483
+ }
484
+ for (;;) {
485
+ string();
486
+ space();
487
+ expectChar(':');
488
+ value(depth + 1);
489
+ space();
490
+ if (raw[at] === '}') {
491
+ at++;
492
+ return;
493
+ }
494
+ expectChar(',');
495
+ space();
496
+ }
497
+ }
498
+ if (ch === '[') {
499
+ at++;
500
+ space();
501
+ if (raw[at] === ']') {
502
+ at++;
503
+ return;
504
+ }
505
+ for (;;) {
506
+ value(depth + 1);
507
+ space();
508
+ if (raw[at] === ']') {
509
+ at++;
510
+ return;
511
+ }
512
+ expectChar(',');
513
+ }
514
+ }
515
+ for (const literal of ['true', 'false', 'null']) {
516
+ if (ch === literal[0]) {
517
+ for (const expected of literal)
518
+ expectChar(expected);
519
+ return;
520
+ }
521
+ }
522
+ if (ch === '-' || (ch !== undefined && /[0-9]/.test(ch))) {
523
+ const number = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(raw.slice(at));
524
+ if (number === null)
525
+ return fail();
526
+ at += number[0].length;
527
+ return;
528
+ }
529
+ fail();
530
+ };
531
+ try {
532
+ value(0);
533
+ space();
534
+ if (at < raw.length)
535
+ fail();
536
+ }
537
+ catch (error) {
538
+ if (!(error instanceof InvalidJson))
539
+ at = 0;
540
+ else
541
+ at = error.offset;
542
+ }
543
+ const lines = raw.slice(0, at).split(/\r\n|\r|\n/);
544
+ return { line: lines.length, column: (lines.at(-1) ?? '').length + 1 };
545
+ }
282
546
  /** Read and validate the config file. ENOENT ⇒ defaults; unreadable ⇒ fail closed. */
283
547
  export function readDaemonConfig(home) {
284
548
  let rawText;
@@ -291,11 +555,14 @@ export function readDaemonConfig(home) {
291
555
  }
292
556
  return unknowableConfig(`config.json exists but could not be read (${String(error)}).`, `config.json could not be read (${String(error)}): refusing all commands`);
293
557
  }
558
+ let raw;
294
559
  try {
295
- return parseDaemonConfig(JSON.parse(rawText));
560
+ raw = JSON.parse(rawText);
296
561
  }
297
- catch (error) {
298
- return unknowableConfig(`config.json is not valid JSON (${String(error)}).`, `config.json is not valid JSON (${String(error)}): refusing all commands`);
562
+ catch {
563
+ const { line, column } = jsonErrorLocation(rawText);
564
+ return unknowableConfig(`config.json is not valid JSON at line ${String(line)}, column ${String(column)}.`, `config.json is not valid JSON at line ${String(line)}, column ${String(column)}: refusing all commands`);
299
565
  }
566
+ return parseDaemonConfig(raw);
300
567
  }
301
568
  //# sourceMappingURL=config.js.map