@developerz.ai/ui-debugger-mcp 1.0.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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/adapters/android/adb.d.ts +38 -0
  4. package/dist/adapters/android/adb.js +72 -0
  5. package/dist/adapters/android/adb.js.map +1 -0
  6. package/dist/adapters/android/android-adapter.d.ts +63 -0
  7. package/dist/adapters/android/android-adapter.js +306 -0
  8. package/dist/adapters/android/android-adapter.js.map +1 -0
  9. package/dist/adapters/android/commands.d.ts +59 -0
  10. package/dist/adapters/android/commands.js +178 -0
  11. package/dist/adapters/android/commands.js.map +1 -0
  12. package/dist/adapters/android/uiautomator.d.ts +81 -0
  13. package/dist/adapters/android/uiautomator.js +296 -0
  14. package/dist/adapters/android/uiautomator.js.map +1 -0
  15. package/dist/adapters/browser/browser-adapter.d.ts +72 -0
  16. package/dist/adapters/browser/browser-adapter.js +434 -0
  17. package/dist/adapters/browser/browser-adapter.js.map +1 -0
  18. package/dist/adapters/browser/cdp.d.ts +83 -0
  19. package/dist/adapters/browser/cdp.js +308 -0
  20. package/dist/adapters/browser/cdp.js.map +1 -0
  21. package/dist/adapters/browser/query.d.ts +25 -0
  22. package/dist/adapters/browser/query.js +85 -0
  23. package/dist/adapters/browser/query.js.map +1 -0
  24. package/dist/adapters/contract.d.ts +159 -0
  25. package/dist/adapters/contract.js +22 -0
  26. package/dist/adapters/contract.js.map +1 -0
  27. package/dist/adapters/desktop/atspi.d.ts +95 -0
  28. package/dist/adapters/desktop/atspi.js +359 -0
  29. package/dist/adapters/desktop/atspi.js.map +1 -0
  30. package/dist/adapters/desktop/capture.d.ts +35 -0
  31. package/dist/adapters/desktop/capture.js +67 -0
  32. package/dist/adapters/desktop/capture.js.map +1 -0
  33. package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
  34. package/dist/adapters/desktop/desktop-adapter.js +215 -0
  35. package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
  36. package/dist/adapters/desktop/input.d.ts +67 -0
  37. package/dist/adapters/desktop/input.js +191 -0
  38. package/dist/adapters/desktop/input.js.map +1 -0
  39. package/dist/adapters/desktop/proc.d.ts +23 -0
  40. package/dist/adapters/desktop/proc.js +38 -0
  41. package/dist/adapters/desktop/proc.js.map +1 -0
  42. package/dist/adapters/factory.d.ts +23 -0
  43. package/dist/adapters/factory.js +45 -0
  44. package/dist/adapters/factory.js.map +1 -0
  45. package/dist/agent/belt/act.d.ts +100 -0
  46. package/dist/agent/belt/act.js +166 -0
  47. package/dist/agent/belt/act.js.map +1 -0
  48. package/dist/agent/belt/look.d.ts +98 -0
  49. package/dist/agent/belt/look.js +160 -0
  50. package/dist/agent/belt/look.js.map +1 -0
  51. package/dist/agent/belt/observe.d.ts +102 -0
  52. package/dist/agent/belt/observe.js +185 -0
  53. package/dist/agent/belt/observe.js.map +1 -0
  54. package/dist/agent/belt/report.d.ts +133 -0
  55. package/dist/agent/belt/report.js +112 -0
  56. package/dist/agent/belt/report.js.map +1 -0
  57. package/dist/agent/loop.d.ts +136 -0
  58. package/dist/agent/loop.js +173 -0
  59. package/dist/agent/loop.js.map +1 -0
  60. package/dist/agent/models.d.ts +26 -0
  61. package/dist/agent/models.js +22 -0
  62. package/dist/agent/models.js.map +1 -0
  63. package/dist/agent/prompts/android-addendum.d.ts +12 -0
  64. package/dist/agent/prompts/android-addendum.js +76 -0
  65. package/dist/agent/prompts/android-addendum.js.map +1 -0
  66. package/dist/agent/prompts/compose.d.ts +30 -0
  67. package/dist/agent/prompts/compose.js +52 -0
  68. package/dist/agent/prompts/compose.js.map +1 -0
  69. package/dist/agent/prompts/debug-agent.d.ts +9 -0
  70. package/dist/agent/prompts/debug-agent.js +102 -0
  71. package/dist/agent/prompts/debug-agent.js.map +1 -0
  72. package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
  73. package/dist/agent/prompts/desktop-addendum.js +66 -0
  74. package/dist/agent/prompts/desktop-addendum.js.map +1 -0
  75. package/dist/agent/prompts/web-addendum.d.ts +9 -0
  76. package/dist/agent/prompts/web-addendum.js +70 -0
  77. package/dist/agent/prompts/web-addendum.js.map +1 -0
  78. package/dist/agent/provider.d.ts +17 -0
  79. package/dist/agent/provider.js +29 -0
  80. package/dist/agent/provider.js.map +1 -0
  81. package/dist/cli/control.d.ts +19 -0
  82. package/dist/cli/control.js +152 -0
  83. package/dist/cli/control.js.map +1 -0
  84. package/dist/cli/help.d.ts +9 -0
  85. package/dist/cli/help.js +41 -0
  86. package/dist/cli/help.js.map +1 -0
  87. package/dist/cli/init.d.ts +20 -0
  88. package/dist/cli/init.js +119 -0
  89. package/dist/cli/init.js.map +1 -0
  90. package/dist/config/load.d.ts +64 -0
  91. package/dist/config/load.js +105 -0
  92. package/dist/config/load.js.map +1 -0
  93. package/dist/config/schema.d.ts +105 -0
  94. package/dist/config/schema.js +62 -0
  95. package/dist/config/schema.js.map +1 -0
  96. package/dist/errors.d.ts +41 -0
  97. package/dist/errors.js +90 -0
  98. package/dist/errors.js.map +1 -0
  99. package/dist/findings/schema.d.ts +64 -0
  100. package/dist/findings/schema.js +27 -0
  101. package/dist/findings/schema.js.map +1 -0
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +4 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/main.d.ts +2 -0
  106. package/dist/main.js +95 -0
  107. package/dist/main.js.map +1 -0
  108. package/dist/mcp/server.d.ts +25 -0
  109. package/dist/mcp/server.js +31 -0
  110. package/dist/mcp/server.js.map +1 -0
  111. package/dist/mcp/tools/describe.d.ts +12 -0
  112. package/dist/mcp/tools/describe.js +32 -0
  113. package/dist/mcp/tools/describe.js.map +1 -0
  114. package/dist/mcp/tools/end-session.d.ts +11 -0
  115. package/dist/mcp/tools/end-session.js +27 -0
  116. package/dist/mcp/tools/end-session.js.map +1 -0
  117. package/dist/mcp/tools/get-findings.d.ts +12 -0
  118. package/dist/mcp/tools/get-findings.js +42 -0
  119. package/dist/mcp/tools/get-findings.js.map +1 -0
  120. package/dist/mcp/tools/index.d.ts +17 -0
  121. package/dist/mcp/tools/index.js +24 -0
  122. package/dist/mcp/tools/index.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +10 -0
  124. package/dist/mcp/tools/result.js +20 -0
  125. package/dist/mcp/tools/result.js.map +1 -0
  126. package/dist/mcp/tools/send-message.d.ts +11 -0
  127. package/dist/mcp/tools/send-message.js +31 -0
  128. package/dist/mcp/tools/send-message.js.map +1 -0
  129. package/dist/mcp/tools/start-debug.d.ts +12 -0
  130. package/dist/mcp/tools/start-debug.js +50 -0
  131. package/dist/mcp/tools/start-debug.js.map +1 -0
  132. package/dist/services/debug-service.d.ts +133 -0
  133. package/dist/services/debug-service.js +163 -0
  134. package/dist/services/debug-service.js.map +1 -0
  135. package/dist/services/replay.d.ts +102 -0
  136. package/dist/services/replay.js +184 -0
  137. package/dist/services/replay.js.map +1 -0
  138. package/dist/services/session-builder.d.ts +65 -0
  139. package/dist/services/session-builder.js +198 -0
  140. package/dist/services/session-builder.js.map +1 -0
  141. package/dist/services/summarize.d.ts +59 -0
  142. package/dist/services/summarize.js +93 -0
  143. package/dist/services/summarize.js.map +1 -0
  144. package/dist/session/findings-store.d.ts +52 -0
  145. package/dist/session/findings-store.js +176 -0
  146. package/dist/session/findings-store.js.map +1 -0
  147. package/dist/session/manager.d.ts +47 -0
  148. package/dist/session/manager.js +66 -0
  149. package/dist/session/manager.js.map +1 -0
  150. package/dist/session/process-identity.d.ts +45 -0
  151. package/dist/session/process-identity.js +81 -0
  152. package/dist/session/process-identity.js.map +1 -0
  153. package/dist/session/session.d.ts +156 -0
  154. package/dist/session/session.js +309 -0
  155. package/dist/session/session.js.map +1 -0
  156. package/dist/session/state-file.d.ts +72 -0
  157. package/dist/session/state-file.js +104 -0
  158. package/dist/session/state-file.js.map +1 -0
  159. package/dist/session/workspace.d.ts +60 -0
  160. package/dist/session/workspace.js +75 -0
  161. package/dist/session/workspace.js.map +1 -0
  162. package/package.json +53 -0
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Session manager — the cwd-keyed registry that enforces one debug run per project.
3
+ *
4
+ * One project (cwd) = one session (`idea/overview.md`, `idea/architecture.md`).
5
+ * That project's persistent Chrome profile can only be driven by a single
6
+ * browser at a time, so the manager is the in-process gate that holds the
7
+ * profile lock: while a session is registered for a cwd, a second `start()`
8
+ * fails loud with `SessionBusyError`. Ending the session frees the lock.
9
+ *
10
+ * The manager is deliberately blind to what a session *is* — it only needs the
11
+ * `ManagedSession` surface (an id + how to close it). The concrete session
12
+ * (agent loop, adapter, findings store) is wired in later tasks.
13
+ */
14
+ import { SessionBusyError, SessionNotFoundError } from '../errors.js';
15
+ /**
16
+ * Registry of active debug sessions, keyed by absolute cwd.
17
+ * @typeParam S - concrete session type (defaults to the bare `ManagedSession` surface).
18
+ */
19
+ export class SessionManager {
20
+ /** Active sessions keyed by absolute cwd. Presence of an entry = the project's profile is locked. */
21
+ #sessions = new Map();
22
+ /**
23
+ * Register `session` as the active run for `cwd`, taking the project's profile lock.
24
+ * @returns the same session, for ergonomic inline construction.
25
+ * @throws {SessionBusyError} if a session is already active for this cwd.
26
+ */
27
+ start(cwd, session) {
28
+ const existing = this.#sessions.get(cwd);
29
+ if (existing) {
30
+ throw new SessionBusyError(`A debug session ('${existing.id}') is already active for '${cwd}'. ` +
31
+ 'End it before starting another — one run per project at a time.');
32
+ }
33
+ this.#sessions.set(cwd, session);
34
+ return session;
35
+ }
36
+ /**
37
+ * Get the active session for `cwd`.
38
+ * @throws {SessionNotFoundError} if no session is active for this cwd.
39
+ */
40
+ get(cwd) {
41
+ const session = this.#sessions.get(cwd);
42
+ if (!session) {
43
+ throw new SessionNotFoundError(`No active debug session for '${cwd}'.`);
44
+ }
45
+ return session;
46
+ }
47
+ /** Whether a session is currently active for `cwd` (non-throwing). */
48
+ has(cwd) {
49
+ return this.#sessions.has(cwd);
50
+ }
51
+ /**
52
+ * End the active session for `cwd`: free the profile lock, then close the session.
53
+ * The slot is released *before* `close()` runs, so a failed teardown never wedges
54
+ * the project — the close error still propagates to the caller.
55
+ * @throws {SessionNotFoundError} if no session is active for this cwd.
56
+ */
57
+ async end(cwd) {
58
+ const session = this.#sessions.get(cwd);
59
+ if (!session) {
60
+ throw new SessionNotFoundError(`No active debug session to end for '${cwd}'.`);
61
+ }
62
+ this.#sessions.delete(cwd);
63
+ await session.close();
64
+ }
65
+ }
66
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/session/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAUtE;;;GAGG;AACH,MAAM,OAAO,cAAc;IACzB,qGAAqG;IAC5F,SAAS,GAAG,IAAI,GAAG,EAAa,CAAC;IAE1C;;;;OAIG;IACH,KAAK,CAAC,GAAW,EAAE,OAAU;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,IAAI,gBAAgB,CACxB,qBAAqB,QAAQ,CAAC,EAAE,6BAA6B,GAAG,KAAK;gBACnE,iEAAiE,CACpE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,GAAW;QACb,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,oBAAoB,CAAC,gCAAgC,GAAG,IAAI,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,sEAAsE;IACtE,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,oBAAoB,CAAC,uCAAuC,GAAG,IAAI,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Process-identity fingerprint — the guard that keeps `stop` from SIGTERM-ing a
3
+ * recycled PID.
4
+ *
5
+ * `process.kill(pid, 0)` proves a PID is *alive*; it cannot prove it is still
6
+ * *our* server. If the server died and the OS handed its PID to an unrelated
7
+ * process, a bare liveness check would green-light a signal against that
8
+ * innocent process. The OS process start time disambiguates: a recycled PID
9
+ * belongs to a process that booted *later*, so its start time differs from the
10
+ * one we recorded at boot. We capture that start time when the run opens (in the
11
+ * `state.json` breadcrumb) and re-check it before signaling.
12
+ *
13
+ * Linux-only by design (this server targets Linux — see CLAUDE.md). The start
14
+ * time comes from `/proc/<pid>/stat` field 22 (clock ticks since boot). On any
15
+ * other platform the fingerprint is `null` (unverifiable) and callers fall back
16
+ * to a bare liveness check — no protection, but no regression either.
17
+ */
18
+ import { z } from 'zod';
19
+ /** The fingerprint persisted in `state.json` and re-checked before signaling. */
20
+ export declare const ProcessIdentitySchema: z.ZodObject<{
21
+ startTicks: z.ZodNullable<z.ZodNumber>;
22
+ }, z.core.$strip>;
23
+ export type ProcessIdentity = z.infer<typeof ProcessIdentitySchema>;
24
+ /** Outcome of matching a recorded identity against the PID's live process. */
25
+ export type IdentityCheck =
26
+ /** Live process start time matches — this PID is still our server. */
27
+ 'match'
28
+ /** Live start time differs — the PID was recycled by an unrelated process. */
29
+ | 'stale'
30
+ /** No process owns the PID — the server is already gone (the benign race). */
31
+ | 'gone'
32
+ /** Can't read a start time (non-Linux, or none recorded) — fall back to liveness. */
33
+ | 'unverifiable';
34
+ /**
35
+ * Parse the start time (field 22) out of a `/proc/<pid>/stat` line.
36
+ *
37
+ * Layout is `pid (comm) state ppid ...`; `comm` may itself contain spaces and
38
+ * parentheses, so we anchor on the *last* `)` — field 3 (state) begins just
39
+ * after it, making field 22 (starttime) the 20th whitespace token of the rest.
40
+ */
41
+ export declare function parseStartTicks(stat: string): number | null;
42
+ /** Capture the fingerprint of a live process (defaults to this one) for `state.json`. */
43
+ export declare function captureIdentity(pid?: number): ProcessIdentity;
44
+ /** Match a recorded identity against whatever process currently owns `pid`. */
45
+ export declare function verifyIdentity(pid: number, recorded: ProcessIdentity): IdentityCheck;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Process-identity fingerprint — the guard that keeps `stop` from SIGTERM-ing a
3
+ * recycled PID.
4
+ *
5
+ * `process.kill(pid, 0)` proves a PID is *alive*; it cannot prove it is still
6
+ * *our* server. If the server died and the OS handed its PID to an unrelated
7
+ * process, a bare liveness check would green-light a signal against that
8
+ * innocent process. The OS process start time disambiguates: a recycled PID
9
+ * belongs to a process that booted *later*, so its start time differs from the
10
+ * one we recorded at boot. We capture that start time when the run opens (in the
11
+ * `state.json` breadcrumb) and re-check it before signaling.
12
+ *
13
+ * Linux-only by design (this server targets Linux — see CLAUDE.md). The start
14
+ * time comes from `/proc/<pid>/stat` field 22 (clock ticks since boot). On any
15
+ * other platform the fingerprint is `null` (unverifiable) and callers fall back
16
+ * to a bare liveness check — no protection, but no regression either.
17
+ */
18
+ import { readFileSync } from 'node:fs';
19
+ import { z } from 'zod';
20
+ /** The fingerprint persisted in `state.json` and re-checked before signaling. */
21
+ export const ProcessIdentitySchema = z.object({
22
+ /**
23
+ * OS process start time — Linux `/proc/<pid>/stat` field 22 (clock ticks since
24
+ * boot). `null` when `/proc` is unavailable (non-Linux): the PID is then
25
+ * unverifiable and callers degrade to a bare liveness check.
26
+ */
27
+ startTicks: z.number().int().nonnegative().nullable(),
28
+ });
29
+ /**
30
+ * Parse the start time (field 22) out of a `/proc/<pid>/stat` line.
31
+ *
32
+ * Layout is `pid (comm) state ppid ...`; `comm` may itself contain spaces and
33
+ * parentheses, so we anchor on the *last* `)` — field 3 (state) begins just
34
+ * after it, making field 22 (starttime) the 20th whitespace token of the rest.
35
+ */
36
+ export function parseStartTicks(stat) {
37
+ const close = stat.lastIndexOf(')');
38
+ if (close === -1)
39
+ return null;
40
+ const fields = stat
41
+ .slice(close + 1)
42
+ .trim()
43
+ .split(/\s+/);
44
+ // starttime is field 22; the slice starts at field 3, so index 22 - 3 = 19.
45
+ const raw = fields[19];
46
+ if (raw === undefined)
47
+ return null;
48
+ const ticks = Number.parseInt(raw, 10);
49
+ return Number.isNaN(ticks) ? null : ticks;
50
+ }
51
+ /** Read a live PID's start time, distinguishing "gone" from "can't tell". */
52
+ function readLiveTicks(pid) {
53
+ if (process.platform !== 'linux')
54
+ return { kind: 'unknown' };
55
+ try {
56
+ const ticks = parseStartTicks(readFileSync(`/proc/${pid}/stat`, 'utf8'));
57
+ return ticks === null ? { kind: 'unknown' } : { kind: 'ticks', ticks };
58
+ }
59
+ catch (err) {
60
+ const code = err.code;
61
+ // ENOENT on Linux means the PID truly has no process — the benign race.
62
+ return code === 'ENOENT' || code === 'ESRCH' ? { kind: 'gone' } : { kind: 'unknown' };
63
+ }
64
+ }
65
+ /** Capture the fingerprint of a live process (defaults to this one) for `state.json`. */
66
+ export function captureIdentity(pid = process.pid) {
67
+ const live = readLiveTicks(pid);
68
+ return { startTicks: live.kind === 'ticks' ? live.ticks : null };
69
+ }
70
+ /** Match a recorded identity against whatever process currently owns `pid`. */
71
+ export function verifyIdentity(pid, recorded) {
72
+ if (recorded.startTicks === null)
73
+ return 'unverifiable';
74
+ const live = readLiveTicks(pid);
75
+ if (live.kind === 'gone')
76
+ return 'gone';
77
+ if (live.kind === 'unknown')
78
+ return 'unverifiable';
79
+ return live.ticks === recorded.startTicks ? 'match' : 'stale';
80
+ }
81
+ //# sourceMappingURL=process-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-identity.js","sourceRoot":"","sources":["../../src/session/process-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C;;;;OAIG;IACH,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE;CACtD,CAAC,CAAC;AAkBH;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9B,MAAM,MAAM,GAAG,IAAI;SAChB,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;SAChB,IAAI,EAAE;SACN,KAAK,CAAC,KAAK,CAAC,CAAC;IAChB,4EAA4E;IAC5E,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACvB,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AAC5C,CAAC;AAED,6EAA6E;AAC7E,SAAS,aAAa,CAAC,GAAW;IAChC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAC7D,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC,SAAS,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACzE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACzE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,GAAI,GAA6B,CAAC,IAAI,CAAC;QACjD,wEAAwE;QACxE,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACxF,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,eAAe,CAAC,MAAc,OAAO,CAAC,GAAG;IACvD,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACnE,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,QAAyB;IACnE,IAAI,QAAQ,CAAC,UAAU,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC;IACxD,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACxC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,cAAc,CAAC;IACnD,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAChE,CAAC"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Session — the per-run state container plus the debug agent's background run.
3
+ *
4
+ * One debug run = one `Session`. It holds the run's identity (`id`), the `story`
5
+ * the smart agent handed over (+ optional pass/fail `criteria`), the live run
6
+ * `status`, the queue of mid-run messages (`inbox`), the target `adapter`, and
7
+ * the `findingsStore` that persists evidence to disk.
8
+ *
9
+ * `start()` kicks the debug agent loop off as a **background task** (non-blocking)
10
+ * so the outer MCP tools stay live while it runs: `pushMessage()` injects work
11
+ * (`send_message`) into the `inbox` the loop drains between steps, and `snapshot()`
12
+ * reads the progress (`get_findings`) the loop flushes incrementally — optionally
13
+ * long-polling (`wait`) until the run settles its verdict. When the
14
+ * loop concludes, the session settles `status` from `running` to the terminal
15
+ * verdict the `report` step wrote to disk (`passed`/`failed`); a run aborted by
16
+ * `close()` (`end_session`) settles as `failed`; an agent crash settles as
17
+ * `failed` and is surfaced into the findings as an {@link AgentError}, so
18
+ * `get_findings` shows what went wrong instead of an empty verdict.
19
+ *
20
+ * The loop itself is assembled outside the session (model + belt + prompt) and
21
+ * handed to `start()` as a {@link LoopRunner}. The session stays model- and
22
+ * adapter-blind: it owns only the loop's *lifecycle* — its inbox seam, its
23
+ * progress sink (the findings store), its abort signal, and the status it settles
24
+ * into. `id` + `close()` make it a `ManagedSession` for the manager.
25
+ */
26
+ import type { LoopInbox, ProgressWriter } from '../agent/loop.js';
27
+ import type { Findings } from '../findings/schema.js';
28
+ import type { FindingsStore } from './findings-store.js';
29
+ /** Run lifecycle status — mirrors the findings verdict (`running` until concluded). */
30
+ export type SessionStatus = Findings['status'];
31
+ /** Selectable top-level findings keys for a sparse `snapshot` (the `get_findings` `fields` param). */
32
+ export type SnapshotField = keyof Findings;
33
+ /** The only adapter capability the session itself uses: release the target on close. */
34
+ export interface SessionAdapter {
35
+ close(): Promise<void>;
36
+ }
37
+ /**
38
+ * Post-verdict findings condenser — the summary actor. Given the run's terminal
39
+ * findings, returns one actionable paragraph for the smart agent. Bound to the
40
+ * summary model OUTSIDE the session (so the session stays model-blind); the session
41
+ * invokes it only when the driver left `findings.summary` empty.
42
+ */
43
+ export type SummarizeStep = (findings: Findings) => Promise<string>;
44
+ /**
45
+ * Outcome of the post-verdict replay attempt:
46
+ * - `rendered` — the clip was stitched; `path` is recorded in `findings.evidence`.
47
+ * - `skipped` — no clip was produced. A `note` (when present) explains why — e.g.
48
+ * ffmpeg is not installed — and the session surfaces it into the findings so a
49
+ * reviewer knows the missing `replay.mp4` was expected, not silently dropped. No
50
+ * `note` means there was simply nothing to stitch (no screenshots); skipped quietly.
51
+ */
52
+ export type ReplayOutcome = {
53
+ kind: 'rendered';
54
+ path: string;
55
+ } | {
56
+ kind: 'skipped';
57
+ note?: string;
58
+ };
59
+ /**
60
+ * Post-verdict replay generator — stitches the run's ordered screenshots into a
61
+ * captioned `replay.mp4` for PR evidence, reporting its {@link ReplayOutcome}. Bound
62
+ * to ffmpeg + the session paths OUTSIDE the session, so the session stays tool- and
63
+ * path-blind (the same shape as {@link SummarizeStep}). It probes for ffmpeg and
64
+ * skips gracefully when absent — never crashing teardown.
65
+ */
66
+ export type ReplayStep = () => Promise<ReplayOutcome>;
67
+ /** Everything needed to construct a session. The loop is handed to `start()`, not the constructor. */
68
+ export interface SessionOptions<A extends SessionAdapter> {
69
+ /** Stable session id (from `generateSessionId`). */
70
+ id: string;
71
+ /** The goal the smart agent handed over, in plain language. */
72
+ story: string;
73
+ /** Optional explicit pass/fail rules for the run. */
74
+ criteria?: string;
75
+ /** The target driver (browser/desktop/android), behind the shared adapter contract. */
76
+ adapter: A;
77
+ /** On-disk evidence locker for this session. */
78
+ findingsStore: FindingsStore;
79
+ /**
80
+ * Optional summary actor: fills `findings.summary` after the verdict when the
81
+ * driver left it empty. Omit to keep whatever summary the driver wrote.
82
+ */
83
+ summarize?: SummarizeStep;
84
+ /**
85
+ * Optional replay generator: stitches the ordered screenshots into a captioned
86
+ * `replay.mp4` after the verdict and records its path in `findings.evidence`.
87
+ * Omit to skip replay generation. Best-effort — the session wraps it fail-soft.
88
+ */
89
+ replay?: ReplayStep;
90
+ }
91
+ /** The lifecycle seams the session hands a {@link LoopRunner}: its inbox, progress sink, abort signal. */
92
+ export interface LoopRunContext {
93
+ /** Mid-run messages, drained and cleared between steps (backs the session's `inbox`). */
94
+ inbox: LoopInbox;
95
+ /** Where the loop flushes its running step trail and final verdict (the findings store). */
96
+ progress: ProgressWriter;
97
+ /** Aborts the in-flight model/tool calls when the session closes (`end_session`). */
98
+ signal: AbortSignal;
99
+ }
100
+ /**
101
+ * Builds and runs the debug loop to its verdict, bound to the session's seams.
102
+ * Assembled outside the session (model + belt + prompt) so the session stays
103
+ * model-blind. Resolves once the driver `report`s (or the step cap trips), rejects
104
+ * if aborted or if the agent fails. Its resolved value is ignored — the verdict is
105
+ * read back from the findings store the `report` step wrote.
106
+ */
107
+ export type LoopRunner = (context: LoopRunContext) => Promise<unknown>;
108
+ /**
109
+ * Per-run state container + background agent run, keyed into the manager by cwd.
110
+ * Structurally a `ManagedSession` (exposes `id` + `close`).
111
+ * @typeParam A - concrete adapter type; the session itself only needs `close()`.
112
+ */
113
+ export declare class Session<A extends SessionAdapter = SessionAdapter> {
114
+ #private;
115
+ readonly id: string;
116
+ readonly story: string;
117
+ readonly criteria?: string;
118
+ constructor(options: SessionOptions<A>);
119
+ /** Current run status. `running` until the loop settles a verdict (`passed`/`failed`). */
120
+ get status(): SessionStatus;
121
+ /** Pending mid-run messages, oldest first (defensive copy; the loop drains them while running). */
122
+ get inbox(): readonly string[];
123
+ /**
124
+ * Queue a mid-run message for the agent (the `send_message` tool). The loop
125
+ * folds these in between steps; here we only enqueue.
126
+ */
127
+ pushMessage(message: string): void;
128
+ /**
129
+ * Start the debug agent loop as a background task (non-blocking): it runs to its
130
+ * verdict while the outer tools stay responsive, and the session settles
131
+ * `status` when it finishes. Returns the run promise for teardown/tests; normal
132
+ * callers fire-and-forget it. Call once per session.
133
+ * @throws {AgentError} if the loop has already been started.
134
+ */
135
+ start(runLoop: LoopRunner): Promise<void>;
136
+ /**
137
+ * Current findings view for `get_findings`: the persisted verdict (empty until
138
+ * the loop writes one) with the live `status` overlaid. Pass `fields` to project
139
+ * a subset (sparse read); omit for the whole findings object.
140
+ *
141
+ * Pass `wait` (ms) to long-poll: while the run is still `running`, the call
142
+ * blocks until the loop settles a terminal verdict or `wait` elapses (whichever
143
+ * comes first), then reads — so `get_findings` can wait out a near-done run
144
+ * instead of busy-polling. Omit `wait` (or pass `0`) to read immediately. A run
145
+ * that has already settled, or one not yet `start()`ed, returns at once.
146
+ */
147
+ snapshot(fields?: undefined, wait?: number): Promise<Findings>;
148
+ snapshot(fields: readonly SnapshotField[], wait?: number): Promise<Partial<Findings>>;
149
+ /**
150
+ * Release the run's resources: abort the loop, wait for it to settle, then close
151
+ * the target adapter. Called by the manager on `end_session`. A run still in
152
+ * flight settles as `failed` (it never reached a verdict). Closing after a run
153
+ * already concluded leaves its verdict untouched.
154
+ */
155
+ close(): Promise<void>;
156
+ }
@@ -0,0 +1,309 @@
1
+ /**
2
+ * Session — the per-run state container plus the debug agent's background run.
3
+ *
4
+ * One debug run = one `Session`. It holds the run's identity (`id`), the `story`
5
+ * the smart agent handed over (+ optional pass/fail `criteria`), the live run
6
+ * `status`, the queue of mid-run messages (`inbox`), the target `adapter`, and
7
+ * the `findingsStore` that persists evidence to disk.
8
+ *
9
+ * `start()` kicks the debug agent loop off as a **background task** (non-blocking)
10
+ * so the outer MCP tools stay live while it runs: `pushMessage()` injects work
11
+ * (`send_message`) into the `inbox` the loop drains between steps, and `snapshot()`
12
+ * reads the progress (`get_findings`) the loop flushes incrementally — optionally
13
+ * long-polling (`wait`) until the run settles its verdict. When the
14
+ * loop concludes, the session settles `status` from `running` to the terminal
15
+ * verdict the `report` step wrote to disk (`passed`/`failed`); a run aborted by
16
+ * `close()` (`end_session`) settles as `failed`; an agent crash settles as
17
+ * `failed` and is surfaced into the findings as an {@link AgentError}, so
18
+ * `get_findings` shows what went wrong instead of an empty verdict.
19
+ *
20
+ * The loop itself is assembled outside the session (model + belt + prompt) and
21
+ * handed to `start()` as a {@link LoopRunner}. The session stays model- and
22
+ * adapter-blind: it owns only the loop's *lifecycle* — its inbox seam, its
23
+ * progress sink (the findings store), its abort signal, and the status it settles
24
+ * into. `id` + `close()` make it a `ManagedSession` for the manager.
25
+ */
26
+ import { AgentError } from '../errors.js';
27
+ /**
28
+ * Per-run state container + background agent run, keyed into the manager by cwd.
29
+ * Structurally a `ManagedSession` (exposes `id` + `close`).
30
+ * @typeParam A - concrete adapter type; the session itself only needs `close()`.
31
+ */
32
+ export class Session {
33
+ id;
34
+ story;
35
+ criteria;
36
+ #adapter;
37
+ #findingsStore;
38
+ /** The summary actor, or `undefined` when no summarizer was wired (driver's summary stands). */
39
+ #summarize;
40
+ /** The replay generator, or `undefined` when none was wired (no `replay.mp4` is produced). */
41
+ #replay;
42
+ #inbox = [];
43
+ #abort = new AbortController();
44
+ /** The background loop run, set once by `start()`; `null` until then. */
45
+ #run = null;
46
+ #status = 'running';
47
+ constructor(options) {
48
+ this.id = options.id;
49
+ this.story = options.story;
50
+ this.criteria = options.criteria;
51
+ this.#adapter = options.adapter;
52
+ this.#findingsStore = options.findingsStore;
53
+ this.#summarize = options.summarize;
54
+ this.#replay = options.replay;
55
+ }
56
+ /** Current run status. `running` until the loop settles a verdict (`passed`/`failed`). */
57
+ get status() {
58
+ return this.#status;
59
+ }
60
+ /** Pending mid-run messages, oldest first (defensive copy; the loop drains them while running). */
61
+ get inbox() {
62
+ return [...this.#inbox];
63
+ }
64
+ /**
65
+ * Queue a mid-run message for the agent (the `send_message` tool). The loop
66
+ * folds these in between steps; here we only enqueue.
67
+ */
68
+ pushMessage(message) {
69
+ this.#inbox.push(message);
70
+ }
71
+ /**
72
+ * Start the debug agent loop as a background task (non-blocking): it runs to its
73
+ * verdict while the outer tools stay responsive, and the session settles
74
+ * `status` when it finishes. Returns the run promise for teardown/tests; normal
75
+ * callers fire-and-forget it. Call once per session.
76
+ * @throws {AgentError} if the loop has already been started.
77
+ */
78
+ start(runLoop) {
79
+ if (this.#run !== null) {
80
+ throw new AgentError(`Session '${this.id}' is already running; start() may be called once.`);
81
+ }
82
+ this.#run = this.#execute(runLoop);
83
+ return this.#run;
84
+ }
85
+ async snapshot(fields, wait) {
86
+ if (wait !== undefined && wait > 0)
87
+ await this.#waitForVerdict(wait);
88
+ const findings = await this.#currentFindings();
89
+ if (!fields || fields.length === 0)
90
+ return findings;
91
+ return Object.fromEntries(fields.filter((field) => field in findings).map((field) => [field, findings[field]]));
92
+ }
93
+ /**
94
+ * Release the run's resources: abort the loop, wait for it to settle, then close
95
+ * the target adapter. Called by the manager on `end_session`. A run still in
96
+ * flight settles as `failed` (it never reached a verdict). Closing after a run
97
+ * already concluded leaves its verdict untouched.
98
+ */
99
+ async close() {
100
+ this.#abort.abort();
101
+ if (this.#run !== null)
102
+ await this.#run;
103
+ await this.#adapter.close();
104
+ }
105
+ /** Run the loop to settlement, then fold its outcome into `status` (+ findings on failure). */
106
+ async #execute(runLoop) {
107
+ try {
108
+ await runLoop({
109
+ inbox: { drain: () => this.#drainInbox() },
110
+ progress: this.#findingsStore,
111
+ signal: this.#abort.signal,
112
+ });
113
+ // Aborted by `close()` but the loop resolved anyway (observed the signal and
114
+ // returned instead of rejecting): honor the teardown contract — an aborted run
115
+ // settles `failed`, never the verdict it may have written just before close.
116
+ if (this.#abort.signal.aborted) {
117
+ this.#status = 'failed';
118
+ return;
119
+ }
120
+ this.#status = await this.#verdict();
121
+ // Best-effort, non-blocking: race the summary against the abort signal so a
122
+ // hung summary model can never stall `close()` (which aborts, then awaits the
123
+ // run). A natural finish awaits it fully; teardown short-circuits the wait.
124
+ await this.#raceAbort(this.#ensureSummary());
125
+ // Then stitch the ordered screenshots into a captioned replay.mp4, recording
126
+ // its path in findings.evidence — same best-effort, abort-raced contract, run
127
+ // after the summary so its write-back preserves it.
128
+ await this.#raceAbort(this.#ensureReplay());
129
+ }
130
+ catch (error) {
131
+ this.#status = 'failed';
132
+ // Aborted by `close()` — the teardown is the verdict; nothing to surface.
133
+ if (this.#abort.signal.aborted)
134
+ return;
135
+ await this.#surfaceAgentError(error);
136
+ }
137
+ }
138
+ /** Hand the loop every pending message and clear the queue (the `LoopInbox` seam over `#inbox`). */
139
+ #drainInbox() {
140
+ return this.#inbox.splice(0, this.#inbox.length);
141
+ }
142
+ /**
143
+ * Fill `findings.summary` with the summary actor's paragraph when the driver left
144
+ * it empty (and a summarizer is wired). Best-effort and non-blocking: any failure
145
+ * is swallowed so a missing summary never delays teardown — the verdict already
146
+ * stands and `get_findings` falls back to the driver's own summary (if any). Writes
147
+ * back under the settled terminal `status`, never a stale `running`.
148
+ */
149
+ async #ensureSummary() {
150
+ if (this.#summarize === undefined)
151
+ return;
152
+ try {
153
+ const findings = await this.#findingsStore.tryReadFindings();
154
+ if (findings === null || hasText(findings.summary))
155
+ return;
156
+ // Summarize the terminal record: `#verdict()` may have settled `status` to a
157
+ // value the persisted findings don't yet carry (e.g. `failed` over a stale
158
+ // `running`), so the digest must reflect the final verdict, not the disk copy.
159
+ const terminalFindings = { ...findings, status: this.#status };
160
+ const summary = await this.#summarize(terminalFindings);
161
+ if (!hasText(summary))
162
+ return;
163
+ await this.#findingsStore.writeFindings({ ...terminalFindings, summary });
164
+ }
165
+ catch {
166
+ // Fail soft: the verdict stands; the driver's own summary (if any) is the fallback.
167
+ }
168
+ }
169
+ /**
170
+ * Stitch the run's ordered screenshots into a captioned `replay.mp4` and record
171
+ * its path in `findings.evidence` — PR evidence the smart agent can attach. Runs
172
+ * after the verdict (and after the summary, so its write-back preserves the
173
+ * summary). Best-effort and fail-soft: no frames, a missing ffmpeg, or any stitch
174
+ * failure is swallowed so the replay never delays teardown or overturns the
175
+ * verdict. A `skipped` outcome with a `note` (e.g. ffmpeg absent) is recorded as a
176
+ * step so the missing video is explained, not silent. Writes back under the settled
177
+ * terminal `status`, never a stale `running`.
178
+ */
179
+ async #ensureReplay() {
180
+ if (this.#replay === undefined)
181
+ return;
182
+ try {
183
+ const outcome = await this.#replay();
184
+ if (outcome.kind === 'skipped') {
185
+ if (outcome.note !== undefined)
186
+ await this.#noteReplaySkipped(outcome.note);
187
+ return;
188
+ }
189
+ const findings = await this.#findingsStore.tryReadFindings();
190
+ if (findings === null)
191
+ return;
192
+ await this.#findingsStore.writeFindings({
193
+ ...findings,
194
+ status: this.#status,
195
+ evidence: outcome.path,
196
+ });
197
+ }
198
+ catch {
199
+ // Fail soft: replay is best-effort PR evidence; the verdict always stands.
200
+ }
201
+ }
202
+ /**
203
+ * Record a skipped replay as a `failed` step in the findings so `get_findings`
204
+ * explains the absent `replay.mp4` (the loud `agent.log` line is written upstream
205
+ * in the replay step). Preserves the existing trail + summary; writes under the
206
+ * settled terminal `status`. Best-effort — wrapped by `#ensureReplay`'s catch.
207
+ */
208
+ async #noteReplaySkipped(note) {
209
+ const findings = await this.#findingsStore.tryReadFindings();
210
+ if (findings === null)
211
+ return;
212
+ await this.#findingsStore.writeFindings({
213
+ ...findings,
214
+ status: this.#status,
215
+ steps: [...findings.steps, { step: 'replay video', ok: false, note }],
216
+ });
217
+ }
218
+ /**
219
+ * Await `promise`, but stop waiting the moment the session aborts — so the
220
+ * best-effort summary can never keep `close()` (which aborts, then awaits the run)
221
+ * blocked on a hung model. The in-flight call is abandoned, not cancelled; the
222
+ * verdict already stands, so dropping the summary is the documented fail-soft.
223
+ */
224
+ async #raceAbort(promise) {
225
+ const { signal } = this.#abort;
226
+ if (signal.aborted)
227
+ return;
228
+ let onAbort;
229
+ try {
230
+ await Promise.race([
231
+ promise,
232
+ new Promise((resolve) => {
233
+ onAbort = () => resolve();
234
+ signal.addEventListener('abort', onAbort, { once: true });
235
+ }),
236
+ ]);
237
+ }
238
+ finally {
239
+ if (onAbort)
240
+ signal.removeEventListener('abort', onAbort);
241
+ }
242
+ }
243
+ /** The terminal verdict the `report` step wrote; `failed` if the run ended without one. */
244
+ async #verdict() {
245
+ const findings = await this.#findingsStore.tryReadFindings();
246
+ return findings && findings.status !== 'running' ? findings.status : 'failed';
247
+ }
248
+ /** Write a `failed` verdict carrying the agent failure so `get_findings` surfaces it. */
249
+ async #surfaceAgentError(error) {
250
+ const agentError = toAgentError(error);
251
+ const prior = await this.#findingsStore.tryReadFindings().catch(() => null);
252
+ try {
253
+ await this.#findingsStore.writeFindings({
254
+ status: 'failed',
255
+ steps: prior?.steps ?? [],
256
+ bugs: prior?.bugs ?? [],
257
+ visual: prior?.visual ?? [],
258
+ summary: `Debug run failed: ${agentError.message}`,
259
+ });
260
+ }
261
+ catch {
262
+ // Best-effort surfacing — `status` is already `failed`, so the loud signal stands.
263
+ }
264
+ }
265
+ /**
266
+ * Block until the background run settles a terminal verdict or `timeoutMs`
267
+ * elapses, whichever comes first (the `snapshot` long-poll). No-op when the run
268
+ * already settled (status is no longer `running`) or was never `start()`ed
269
+ * (`#run` is null) — neither changes on its own, so there is nothing to wait
270
+ * for. The run promise never rejects (`#execute` folds failures into `status`),
271
+ * so the race is safe; the timer is always cleared so a fast verdict leaves no
272
+ * dangling handle.
273
+ */
274
+ async #waitForVerdict(timeoutMs) {
275
+ const run = this.#run;
276
+ if (run === null || this.#status !== 'running')
277
+ return;
278
+ let timer;
279
+ try {
280
+ await Promise.race([
281
+ run,
282
+ new Promise((resolve) => {
283
+ timer = setTimeout(resolve, timeoutMs);
284
+ }),
285
+ ]);
286
+ }
287
+ finally {
288
+ clearTimeout(timer);
289
+ }
290
+ }
291
+ /** Latest verdict: persisted findings if present, else an empty run, status overlaid. */
292
+ async #currentFindings() {
293
+ const persisted = await this.#findingsStore.tryReadFindings();
294
+ return persisted
295
+ ? { ...persisted, status: this.#status }
296
+ : { status: this.#status, steps: [], bugs: [], visual: [] };
297
+ }
298
+ }
299
+ /** Normalize any thrown value into an {@link AgentError} (passing an existing one through). */
300
+ function toAgentError(error) {
301
+ if (error instanceof AgentError)
302
+ return error;
303
+ return new AgentError(error instanceof Error ? error.message : String(error));
304
+ }
305
+ /** True when `value` is a non-blank string (a real summary, not absent or whitespace). */
306
+ function hasText(value) {
307
+ return typeof value === 'string' && value.trim().length > 0;
308
+ }
309
+ //# sourceMappingURL=session.js.map