@peekdev/mcp 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (72) hide show
  1. package/README.md +178 -0
  2. package/dist/db/open.d.ts +19 -1
  3. package/dist/db/open.d.ts.map +1 -1
  4. package/dist/db/open.js +25 -1
  5. package/dist/db/open.js.map +1 -1
  6. package/dist/entrypoint.d.ts +8 -0
  7. package/dist/entrypoint.d.ts.map +1 -0
  8. package/dist/entrypoint.js +33 -0
  9. package/dist/entrypoint.js.map +1 -0
  10. package/dist/mcp/action-schema.d.ts +156 -0
  11. package/dist/mcp/action-schema.d.ts.map +1 -1
  12. package/dist/mcp/action-schema.js +69 -0
  13. package/dist/mcp/action-schema.js.map +1 -1
  14. package/dist/mcp/event-blobs.d.ts +12 -2
  15. package/dist/mcp/event-blobs.d.ts.map +1 -1
  16. package/dist/mcp/event-blobs.js +55 -6
  17. package/dist/mcp/event-blobs.js.map +1 -1
  18. package/dist/mcp/event-walker.d.ts +30 -0
  19. package/dist/mcp/event-walker.d.ts.map +1 -1
  20. package/dist/mcp/event-walker.js +67 -1
  21. package/dist/mcp/event-walker.js.map +1 -1
  22. package/dist/mcp/host-bridge.d.ts +50 -1
  23. package/dist/mcp/host-bridge.d.ts.map +1 -1
  24. package/dist/mcp/host-bridge.js +133 -0
  25. package/dist/mcp/host-bridge.js.map +1 -1
  26. package/dist/mcp/index.d.ts +6 -0
  27. package/dist/mcp/index.d.ts.map +1 -1
  28. package/dist/mcp/index.js +11 -1
  29. package/dist/mcp/index.js.map +1 -1
  30. package/dist/mcp/playwright-repro.d.ts.map +1 -1
  31. package/dist/mcp/playwright-repro.js +58 -9
  32. package/dist/mcp/playwright-repro.js.map +1 -1
  33. package/dist/mcp/server.d.ts +3 -2
  34. package/dist/mcp/server.d.ts.map +1 -1
  35. package/dist/mcp/server.js +301 -63
  36. package/dist/mcp/server.js.map +1 -1
  37. package/dist/mcp/summary.d.ts +7 -0
  38. package/dist/mcp/summary.d.ts.map +1 -1
  39. package/dist/mcp/summary.js +7 -1
  40. package/dist/mcp/summary.js.map +1 -1
  41. package/dist/native-host/action-protocol.d.ts +15 -2
  42. package/dist/native-host/action-protocol.d.ts.map +1 -1
  43. package/dist/native-host/audit.d.ts +1 -1
  44. package/dist/native-host/audit.d.ts.map +1 -1
  45. package/dist/native-host/audit.js +1 -1
  46. package/dist/native-host/audit.js.map +1 -1
  47. package/dist/native-host/host-socket.d.ts +137 -0
  48. package/dist/native-host/host-socket.d.ts.map +1 -0
  49. package/dist/native-host/host-socket.js +369 -0
  50. package/dist/native-host/host-socket.js.map +1 -0
  51. package/dist/native-host/host.d.ts +11 -0
  52. package/dist/native-host/host.d.ts.map +1 -1
  53. package/dist/native-host/host.js +54 -0
  54. package/dist/native-host/host.js.map +1 -1
  55. package/dist/native-host/ingest.js +4 -4
  56. package/dist/native-host/ingest.js.map +1 -1
  57. package/dist/native-host/installer.d.ts +21 -0
  58. package/dist/native-host/installer.d.ts.map +1 -1
  59. package/dist/native-host/installer.js +64 -2
  60. package/dist/native-host/installer.js.map +1 -1
  61. package/dist/native-host/manifest.d.ts +7 -2
  62. package/dist/native-host/manifest.d.ts.map +1 -1
  63. package/dist/native-host/manifest.js +29 -15
  64. package/dist/native-host/manifest.js.map +1 -1
  65. package/dist/native-host/socket-path.d.ts +10 -0
  66. package/dist/native-host/socket-path.d.ts.map +1 -0
  67. package/dist/native-host/socket-path.js +31 -0
  68. package/dist/native-host/socket-path.js.map +1 -0
  69. package/dist/postinstall.d.ts.map +1 -1
  70. package/dist/postinstall.js +15 -15
  71. package/dist/postinstall.js.map +1 -1
  72. package/package.json +34 -4
@@ -1,11 +1,15 @@
1
1
  // generate_playwright_repro (Task 3.13): turn a window of extracted user
2
2
  // actions into a runnable Playwright test string. Each action maps to the
3
3
  // idiomatic Playwright call:
4
- // navigate -> await page.goto('url')
5
- // click -> await page.click('selector')
6
- // input -> await page.fill('selector', 'value')
4
+ // navigate -> await page.goto('url')
5
+ // click -> await page.click('selector')
6
+ // input (select) -> await page.selectOption('selector', 'value')
7
+ // input (checkbox/radio) -> await page.check/uncheck('selector')
8
+ // input (other) -> await page.fill('selector', 'value')
7
9
  // The first navigation seeds the opening goto; subsequent navigations are
8
10
  // emitted inline (e.g. an in-app route change that triggered a full load).
11
+ // After the actions, a final `await expect(page).toHaveURL(...)` is emitted
12
+ // for the last navigation so the repro verifies the end state, not just replays.
9
13
  import { extractUserActions } from './event-walker.js';
10
14
  /** Default ceiling on emitted actions — caps the output size (PRD §B token budget). */
11
15
  const DEFAULT_MAX_ACTIONS = 200;
@@ -26,10 +30,43 @@ function actionToStatement(action) {
26
30
  return action.url ? ` await page.goto(${jsString(action.url)});` : undefined;
27
31
  case 'click':
28
32
  return action.selector ? ` await page.click(${jsString(action.selector)});` : undefined;
29
- case 'input':
30
- return action.selector
31
- ? ` await page.fill(${jsString(action.selector)}, ${jsString(action.value ?? '')});`
32
- : undefined;
33
+ case 'input': {
34
+ if (!action.selector)
35
+ return undefined;
36
+ const sel = jsString(action.selector);
37
+ if (action.elementTag === 'input') {
38
+ if (action.inputType === 'checkbox' || action.inputType === 'radio') {
39
+ if (action.checked === true)
40
+ return ` await page.check(${sel});`;
41
+ if (action.checked === false)
42
+ return ` await page.uncheck(${sel});`;
43
+ return ` // TODO: <input type="${action.inputType}"> ${action.selector} — checked state unknown; add check()/uncheck()`;
44
+ }
45
+ if (action.inputType === 'hidden' ||
46
+ action.inputType === 'submit' ||
47
+ action.inputType === 'button' ||
48
+ action.inputType === 'reset' ||
49
+ action.inputType === 'image') {
50
+ return ` // TODO: skipped <input type="${action.inputType}"> (not a user text entry)`;
51
+ }
52
+ if (action.inputType === 'file') {
53
+ return ` // TODO: file input ${action.selector} — setInputFiles can't be reconstructed from a recording`;
54
+ }
55
+ }
56
+ if (action.elementTag === 'select') {
57
+ // rrweb captures only a single text value per input event, so only
58
+ // single-value <select> interactions are representable here. A
59
+ // <select multiple> repro would be incorrect (only one option captured);
60
+ // no multi-select detection is attempted — this is a known v1 limitation.
61
+ const value = action.value ?? '';
62
+ // I1: an empty value would make Playwright throw at runtime
63
+ // ("did not find some options"). Emit a TODO so the script stays runnable.
64
+ if (value === '')
65
+ return ' // TODO: <select> reset to placeholder — selectOption needs a value or { index: 0 }';
66
+ return ` await page.selectOption(${jsString(action.selector)}, ${jsString(value)});`;
67
+ }
68
+ return ` await page.fill(${jsString(action.selector)}, ${jsString(action.value ?? '')});`;
69
+ }
33
70
  default:
34
71
  return undefined;
35
72
  }
@@ -69,10 +106,22 @@ export function generatePlaywrightRepro(events, options = {}) {
69
106
  lines.push(` // TODO: ${action.summary} (target selector unresolved)`);
70
107
  }
71
108
  }
109
+ // T0.5: assert the end state. Find the last navigate (with a url) in the
110
+ // capped window and verify the page landed there — turning a blind replay
111
+ // into a test with a real oracle for the final URL.
112
+ for (let i = actions.length - 1; i >= 0; i -= 1) {
113
+ const a = actions[i];
114
+ if (a && a.type === 'navigate' && a.url) {
115
+ lines.push(` await expect(page).toHaveURL(${jsString(a.url)});`);
116
+ break;
117
+ }
118
+ }
72
119
  lines.push('});');
73
120
  lines.push('');
74
121
  return lines.join('\n');
75
122
  }
76
- // `expect` is imported in the generated script for the author to add assertions;
77
- // we don't synthesize assertions in v1 (we have no oracle for "correct" state).
123
+ // `expect` is used for the final-URL assertion above (the one oracle we can
124
+ // derive from a recording). We don't synthesize other assertions we have no
125
+ // ground truth for "correct" intermediate state — so the author still adds
126
+ // content/visibility checks as needed.
78
127
  //# sourceMappingURL=playwright-repro.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"playwright-repro.js","sourceRoot":"","sources":["../../src/mcp/playwright-repro.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,0EAA0E;AAC1E,6BAA6B;AAC7B,uCAAuC;AACvC,6CAA6C;AAC7C,qDAAqD;AACrD,0EAA0E;AAC1E,2EAA2E;AAG3E,OAAO,EAAE,kBAAkB,EAAE,M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AClB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,uCAAuC"}
@@ -40,11 +40,12 @@ export interface CreatePeekMcpServerOptions {
40
40
  readonly auditLogPath?: string;
41
41
  }
42
42
  /**
43
- * Build the peek MCP server with all Level-1 read tools registered. Call
43
+ * Build the peek MCP server with all tools registered (read, act, suggest, and
44
+ * control tiers). Call
44
45
  * `.server.connect(transport)` to start it. The DB is opened lazily on the
45
46
  * first tool call (and reused), so construction never fails on a missing store.
46
47
  */
47
48
  export declare function createPeekMcpServer(options?: CreatePeekMcpServerOptions): PeekMcpServer;
48
49
  /** The tool names this server registers, for smoke tests / docs. */
49
- export declare const PEEK_MCP_TOOLS: readonly ["list_recent_sessions", "get_session_summary", "get_session_console_errors", "get_session_network_errors", "get_user_action_before_error", "generate_playwright_repro", "get_dom_snapshot", "query_dom_history", "request_authorization", "execute_action"];
50
+ export declare const PEEK_MCP_TOOLS: readonly ["list_recent_sessions", "get_session_summary", "get_session_console_errors", "get_session_network_errors", "get_user_action_before_error", "generate_playwright_repro", "get_dom_snapshot", "query_dom_history", "request_authorization", "execute_action", "suggest_element", "clear_highlight", "request_user_input", "set_intent"];
50
51
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAUpE,eAAO,MAAM,cAAc,QAAe,CAAC;AAU3C,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,kBAAkB,CAAC;AAUtE,OAAO,EAAE,KAAK,UAAU,EAAqB,MAAM,YAAY,CAAC;AAGhE,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,eAAO,MAAM,mBAAmB,QAUqB,C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AAS,CAAC;IAC3B,sCAAsC;IACtC,KAAK,IAAI,IAAI,CAAC;IACd,sFAAsF;IACtF,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3D,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,sDAAsD;IACtD,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,GAAG,aAAa,CAiwB3F;AAED,oEAAoE;AACpE,eAAO,MAAM,cAAc,iVAoBjB,CAAC"}
@@ -1,7 +1,10 @@
1
- // The peek MCP server (Tasks 3.11-3.14). Builds an `McpServer` with the Level-1
2
- // READ-ONLY tool surface (PRD §B3): seven session/query tools plus the
3
- // Playwright repro generator. Writes/action-execution (execute_action,
4
- // request_authorization) are Phase 3d not registered here.
1
+ // The peek MCP server. Builds an `McpServer` and registers the full 14-tool
2
+ // surface: eight read-only session/query tools (incl. the Playwright repro
3
+ // generator), the act tools (execute_action, request_authorization), the
4
+ // Level-2 Suggest tools (suggest_element, clear_highlight), and the Level-4
5
+ // control tools (set_intent, request_user_input). All write tools are gated at
6
+ // dispatch by the per-origin permission model — see `registerTools` +
7
+ // `dispatchActTool`.
5
8
  //
6
9
  // Design notes:
7
10
  // • DB is opened read-only and lazily (openReadonlyDb) so a server can start
@@ -58,7 +61,8 @@ function clip(s, max) {
58
61
  return s.length <= max ? s : `${s.slice(0, max)}… [+${s.length - max} chars]`;
59
62
  }
60
63
  /**
61
- * Build the peek MCP server with all Level-1 read tools registered. Call
64
+ * Build the peek MCP server with all tools registered (read, act, suggest, and
65
+ * control tiers). Call
62
66
  * `.server.connect(transport)` to start it. The DB is opened lazily on the
63
67
  * first tool call (and reused), so construction never fails on a missing store.
64
68
  */
@@ -125,19 +129,29 @@ export function createPeekMcpServer(options = {}) {
125
129
  function registerTools() {
126
130
  // 1. list_recent_sessions ------------------------------------------------
127
131
  server.registerTool('list_recent_sessions', {
128
- description: "List the user's recently recorded browser sessions, newest first. " +
129
- 'Returns compact rows with ids to pass to the get_session_* tools.',
132
+ title: 'List recent browser sessions',
133
+ description: "List the user's recorded browser sessions, newest first — the entry point for the get_session_* and DOM tools. Returns compact JSON rows ({ sessionId, origin, url, title, startedAt, ... }); free-text fields are clipped (origin 100, url 300, title 200 chars). If the MCP client scoped roots to specific origins and no origin filter is given, results are restricted to the client's scoped origins. Start here to obtain a sessionId, then call get_session_summary.",
130
134
  inputSchema: {
131
- limit: z.number().int().min(1).max(50).default(10),
132
- origin: z.string().optional(),
135
+ limit: z
136
+ .number()
137
+ .int()
138
+ .min(1)
139
+ .max(50)
140
+ .default(10)
141
+ .describe('Maximum sessions to return (1-50, newest first; default 10).'),
142
+ origin: z
143
+ .string()
144
+ .optional()
145
+ .describe("Filter to one origin, e.g. 'https://app.example.com'. Omit to list across all recorded origins (subject to client roots scoping)."),
133
146
  },
147
+ annotations: { readOnlyHint: true, openWorldHint: false },
134
148
  }, ({ limit, origin }) => {
135
149
  const handle = getDb();
136
150
  if (!handle)
137
151
  return textResult(NO_DB_MESSAGE);
138
152
  // Apply the roots soft-scope: if the client scoped to origins and the
139
- // caller didn't ask for a specific one, restrict to the first scoped
140
- // origin set by filtering post-query (origins are few).
153
+ // caller didn't ask for a specific one, restrict to the scoped origin
154
+ // set by filtering post-query against all allowedOrigins (origins are few).
141
155
  const rows = listRecentSessions(handle, {
142
156
  limit,
143
157
  ...(origin !== undefined ? { origin } : {}),
@@ -155,9 +169,12 @@ export function createPeekMcpServer(options = {}) {
155
169
  });
156
170
  // 2. get_session_summary -------------------------------------------------
157
171
  server.registerTool('get_session_summary', {
158
- description: 'Get an LLM-readable narrative summary of one session: pages visited, ' +
159
- 'click/input counts, navigations, and error counts.',
160
- inputSchema: { sessionId: z.string() },
172
+ title: 'Summarize a session',
173
+ description: 'Get an LLM-readable narrative summary of one session: pages visited, click/input/navigation counts, and error counts. Use this first for an overview before drilling into get_session_console_errors / get_session_network_errors. Returns a structured JSON summary.',
174
+ inputSchema: {
175
+ sessionId: z.string().describe('Session id from list_recent_sessions.'),
176
+ },
177
+ annotations: { readOnlyHint: true, openWorldHint: false },
161
178
  }, ({ sessionId }) => {
162
179
  const handle = getDb();
163
180
  if (!handle)
@@ -173,13 +190,24 @@ export function createPeekMcpServer(options = {}) {
173
190
  });
174
191
  // 3. get_session_console_errors -----------------------------------------
175
192
  server.registerTool('get_session_console_errors', {
176
- description: 'List console error messages recorded in a session, oldest first. ' +
177
- 'Each row has an id usable with get_user_action_before_error.',
193
+ title: 'List console errors',
194
+ description: 'List console error messages recorded in a session, oldest first. Each row has a numeric id to pass to get_user_action_before_error. Returns JSON rows ({ id, ts, level, message, stack }); message clipped to 500 and stack to 800 chars. For error counts at a glance, use get_session_summary first.',
178
195
  inputSchema: {
179
- sessionId: z.string(),
180
- since: z.number().int().optional(),
181
- limit: z.number().int().min(1).max(200).default(50),
196
+ sessionId: z.string().describe('Session id from list_recent_sessions.'),
197
+ since: z
198
+ .number()
199
+ .int()
200
+ .optional()
201
+ .describe('Only return errors with ts >= this epoch-ms timestamp (to page forward through a long session). Omit to start from the beginning.'),
202
+ limit: z
203
+ .number()
204
+ .int()
205
+ .min(1)
206
+ .max(200)
207
+ .default(50)
208
+ .describe('Maximum errors to return (1-200, oldest first; default 50).'),
182
209
  },
210
+ annotations: { readOnlyHint: true, openWorldHint: false },
183
211
  }, ({ sessionId, since, limit }) => {
184
212
  const handle = getDb();
185
213
  if (!handle)
@@ -198,13 +226,26 @@ export function createPeekMcpServer(options = {}) {
198
226
  });
199
227
  // 4. get_session_network_errors -----------------------------------------
200
228
  server.registerTool('get_session_network_errors', {
201
- description: 'List failed/notable network requests in a session (status >= statusGte ' +
202
- 'or a network error), oldest first.',
229
+ title: 'List failed network requests',
230
+ description: 'List failed or notable network requests in a session (HTTP status >= statusGte, or a transport-level network error), oldest first. Returns JSON rows ({ id, ts, method, url, status, statusText, resourceType, durationMs, errorText }); url and errorText clipped to 300 chars.',
203
231
  inputSchema: {
204
- sessionId: z.string(),
205
- statusGte: z.number().int().min(100).max(599).default(400),
206
- limit: z.number().int().min(1).max(200).default(50),
232
+ sessionId: z.string().describe('Session id from list_recent_sessions.'),
233
+ statusGte: z
234
+ .number()
235
+ .int()
236
+ .min(100)
237
+ .max(599)
238
+ .default(400)
239
+ .describe('Minimum HTTP status treated as notable (100-599; default 400, i.e. 4xx/5xx). Transport-level errors are always included regardless.'),
240
+ limit: z
241
+ .number()
242
+ .int()
243
+ .min(1)
244
+ .max(200)
245
+ .default(50)
246
+ .describe('Maximum requests to return (1-200, oldest first; default 50).'),
207
247
  },
248
+ annotations: { readOnlyHint: true, openWorldHint: false },
208
249
  }, ({ sessionId, statusGte, limit }) => {
209
250
  const handle = getDb();
210
251
  if (!handle)
@@ -224,14 +265,20 @@ export function createPeekMcpServer(options = {}) {
224
265
  });
225
266
  // 5. get_user_action_before_error ---------------------------------------
226
267
  server.registerTool('get_user_action_before_error', {
227
- description: 'Show the last N user actions (click/type/navigate) before a console ' +
228
- 'error, to reconstruct what the user did. errorId comes from ' +
229
- 'get_session_console_errors.',
268
+ title: 'Actions before an error',
269
+ description: 'Reconstruct what the user did right before a console error: returns the last `window` user actions (click/type/navigate) preceding the error, to explain how it was triggered. Returns JSON { errorId, errorTs, actions }. Get errorId from get_session_console_errors first.',
230
270
  inputSchema: {
231
- sessionId: z.string(),
232
- errorId: z.number().int(),
233
- window: z.number().int().min(1).max(50).default(10),
271
+ sessionId: z.string().describe('Session id from list_recent_sessions.'),
272
+ errorId: z.number().int().describe('Console error id from get_session_console_errors.'),
273
+ window: z
274
+ .number()
275
+ .int()
276
+ .min(1)
277
+ .max(50)
278
+ .default(10)
279
+ .describe('How many preceding user actions to return (1-50; default 10).'),
234
280
  },
281
+ annotations: { readOnlyHint: true, openWorldHint: false },
235
282
  }, ({ sessionId, errorId, window }) => {
236
283
  const handle = getDb();
237
284
  if (!handle)
@@ -248,13 +295,22 @@ export function createPeekMcpServer(options = {}) {
248
295
  });
249
296
  // 6. generate_playwright_repro ------------------------------------------
250
297
  server.registerTool('generate_playwright_repro', {
251
- description: 'Generate a runnable Playwright test from the user actions in a session ' +
252
- '(optionally limited to a [startTs, endTs] window).',
298
+ title: 'Generate Playwright repro',
299
+ description: 'Generate a runnable Playwright test (TypeScript) reproducing the user actions in a session: clicks, typing, navigation, and <select> changes. Optionally limit to a [startTs, endTs] epoch-ms window. Returns the test source as text. Note: only single-value <select> is represented (rrweb captures one value per input).',
253
300
  inputSchema: {
254
- sessionId: z.string(),
255
- startTs: z.number().int().optional(),
256
- endTs: z.number().int().optional(),
301
+ sessionId: z.string().describe('Session id from list_recent_sessions.'),
302
+ startTs: z
303
+ .number()
304
+ .int()
305
+ .optional()
306
+ .describe('Only include actions at or after this epoch-ms timestamp. Omit to start at the session beginning.'),
307
+ endTs: z
308
+ .number()
309
+ .int()
310
+ .optional()
311
+ .describe('Only include actions at or before this epoch-ms timestamp. Omit to run through the session end.'),
257
312
  },
313
+ annotations: { readOnlyHint: true, openWorldHint: false },
258
314
  }, ({ sessionId, startTs, endTs }) => {
259
315
  const handle = getDb();
260
316
  if (!handle)
@@ -274,14 +330,20 @@ export function createPeekMcpServer(options = {}) {
274
330
  });
275
331
  // 7. get_dom_snapshot ----------------------------------------------------
276
332
  server.registerTool('get_dom_snapshot', {
277
- description: 'Reconstruct the DOM at a timestamp (or a selector subtree within it) ' +
278
- 'and return it as HTML. v1 applies structural/attribute/text mutations ' +
279
- 'on top of the nearest full snapshot.',
333
+ title: 'Reconstruct DOM at a time',
334
+ description: 'Reconstruct the page DOM as it existed at a timestamp (or a selector subtree within it) and return it as HTML. Applies structural/attribute/text mutations on top of the nearest full snapshot at or before ts. Returns JSON { baseSnapshotTs, mutationsApplied, html }; html clipped to 24000 chars. Fails if no full snapshot exists at or before ts.',
280
335
  inputSchema: {
281
- sessionId: z.string(),
282
- ts: z.number().int(),
283
- selector: z.string().optional(),
336
+ sessionId: z.string().describe('Session id from list_recent_sessions.'),
337
+ ts: z
338
+ .number()
339
+ .int()
340
+ .describe('Epoch-ms timestamp to reconstruct the DOM at. Use timestamps from get_session_summary, error rows, or get_user_action_before_error.'),
341
+ selector: z
342
+ .string()
343
+ .optional()
344
+ .describe('CSS selector to return only that subtree. Omit to return the full document.'),
284
345
  },
346
+ annotations: { readOnlyHint: true, openWorldHint: false },
285
347
  }, ({ sessionId, ts, selector }) => {
286
348
  const handle = getDb();
287
349
  if (!handle)
@@ -302,14 +364,26 @@ export function createPeekMcpServer(options = {}) {
302
364
  });
303
365
  // 8. query_dom_history ---------------------------------------------------
304
366
  server.registerTool('query_dom_history', {
305
- description: "Timeline of attribute and/or text changes for a selector's node over " +
306
- 'a session. op restricts to attributeChanges or innerText.',
367
+ title: 'DOM change timeline',
368
+ description: 'Timeline of attribute and/or text changes over a session for the node matching a CSS selector - useful for tracking how one element evolved. Returns JSON { selector, changes }. Use op to restrict to attribute changes or innerText; omit for both.',
307
369
  inputSchema: {
308
- sessionId: z.string(),
309
- selector: z.string(),
310
- op: z.enum(['attributeChanges', 'innerText']).optional(),
311
- limit: z.number().int().min(1).max(500).default(100),
370
+ sessionId: z.string().describe('Session id from list_recent_sessions.'),
371
+ selector: z
372
+ .string()
373
+ .describe("CSS selector for the node to track, e.g. '#status' or '.cart-count'."),
374
+ op: z
375
+ .enum(['attributeChanges', 'innerText'])
376
+ .optional()
377
+ .describe("Restrict to 'attributeChanges' or 'innerText'. Omit to include both."),
378
+ limit: z
379
+ .number()
380
+ .int()
381
+ .min(1)
382
+ .max(500)
383
+ .default(100)
384
+ .describe('Maximum changes to return (1-500; default 100).'),
312
385
  },
386
+ annotations: { readOnlyHint: true, openWorldHint: false },
313
387
  }, ({ sessionId, selector, op, limit }) => {
314
388
  const handle = getDb();
315
389
  if (!handle)
@@ -329,13 +403,19 @@ export function createPeekMcpServer(options = {}) {
329
403
  // banner. On Allow the host returns a one-shot confirmToken the AI passes
330
404
  // to execute_action. EVERY call (including denied ones) is audit-logged.
331
405
  server.registerTool('request_authorization', {
332
- description: 'Ask the user to authorize an action in their browser via the side-' +
333
- 'panel banner (Level 3 act-with-confirm). Returns a one-shot ' +
334
- 'confirmToken to pass to execute_action, or denies the request. ' +
335
- 'Every call is recorded to ~/.peek/audit.log.',
406
+ title: 'Request action authorization',
407
+ description: 'Ask the user to authorize a browser action via the side-panel banner (Level-3 act-with-confirm). On Allow, returns a one-shot confirmToken to pass to execute_action; on Deny, returns the denial. Every call - allowed or denied - is recorded to ~/.peek/audit.log. Use before execute_action when the origin is at permission Level 3, or to pre-authorize.',
336
408
  inputSchema: {
337
- sessionId: z.string(),
338
- action: ActionSchema,
409
+ sessionId: z
410
+ .string()
411
+ .describe('Session id (origin context) from list_recent_sessions; determines the per-origin permission level.'),
412
+ action: ActionSchema.describe('The browser action to authorize (e.g. click/type/navigate; see the action schema).'),
413
+ },
414
+ annotations: {
415
+ readOnlyHint: false,
416
+ destructiveHint: false,
417
+ idempotentHint: false,
418
+ openWorldHint: true,
339
419
  },
340
420
  }, async ({ sessionId, action }) => {
341
421
  return await dispatchActTool({
@@ -351,17 +431,23 @@ export function createPeekMcpServer(options = {}) {
351
431
  // banner step at Level 3. Without it: Level 3 raises a banner; Level 4
352
432
  // proceeds (unless destructive); Level <3 denies.
353
433
  server.registerTool('execute_action', {
354
- description: "Execute an action in the user's browser. Requires per-origin " +
355
- 'permission Level 3+ (Level 3 prompts unless confirmToken is passed; ' +
356
- 'Level 4 auto-allows non-destructive). The destructive-action ' +
357
- 'override (delete/remove/transfer/send/pay/purchase/buy/confirm/' +
358
- 'subscribe/logout/sign out/unsubscribe/cancel subscription/wire/' +
359
- 'withdraw) always prompts, even at Level 4. Every call is ' +
360
- 'recorded to ~/.peek/audit.log.',
434
+ title: 'Execute a browser action',
435
+ description: "Execute an action (click/type/navigate/...) in the user's live browser. Requires per-origin permission Level 3+: Level 3 raises a confirm banner unless a valid confirmToken from request_authorization is passed; Level 4 auto-allows non-destructive actions; Level <3 denies. The destructive-action override (delete/remove/transfer/send/pay/purchase/buy/confirm/subscribe/logout/sign out/unsubscribe/cancel subscription/wire/withdraw) always prompts, even at Level 4. Every call is recorded to ~/.peek/audit.log.",
361
436
  inputSchema: {
362
- sessionId: z.string(),
363
- action: ActionSchema,
364
- confirmToken: z.string().optional(),
437
+ sessionId: z
438
+ .string()
439
+ .describe('Session id (origin context) from list_recent_sessions; determines the per-origin permission level.'),
440
+ action: ActionSchema.describe('The browser action to execute (e.g. click/type/navigate; see the action schema).'),
441
+ confirmToken: z
442
+ .string()
443
+ .optional()
444
+ .describe('One-shot token from a prior request_authorization Allow, to skip the Level-3 banner. Omit to trigger the banner (Level 3) or rely on Level-4 auto-allow.'),
445
+ },
446
+ annotations: {
447
+ readOnlyHint: false,
448
+ destructiveHint: true,
449
+ idempotentHint: false,
450
+ openWorldHint: true,
365
451
  },
366
452
  }, async ({ sessionId, action, confirmToken }) => {
367
453
  return await dispatchActTool({
@@ -371,6 +457,150 @@ export function createPeekMcpServer(options = {}) {
371
457
  ...(confirmToken !== undefined ? { confirmToken } : {}),
372
458
  });
373
459
  });
460
+ // 11. suggest_element (Level-2 Suggest tier) -----------------------------
461
+ // Non-mutating highlight overlay. Routed through the execute_action audit
462
+ // path (wire tool='execute_action'); the SW intercepts the `highlight`
463
+ // action BEFORE the act gate and auto-allows it at per-origin Level 2+.
464
+ server.registerTool('suggest_element', {
465
+ title: 'Highlight an element in the live browser',
466
+ description: "Draw a non-destructive highlight overlay on a CSS selector in the user's live browser, with an optional label, to point something out. Available at per-origin permission Level 2 (Suggest) and above; it never clicks, types, or navigates. The overlay persists until clear_highlight is called. Every call is recorded to ~/.peek/audit.log.",
467
+ inputSchema: {
468
+ sessionId: z
469
+ .string()
470
+ .describe('Session id (origin context) from list_recent_sessions; determines the per-origin permission level.'),
471
+ selector: z.string().min(1).describe('CSS selector of the element to highlight.'),
472
+ label: z
473
+ .string()
474
+ .max(120)
475
+ .optional()
476
+ .describe('Optional short text shown in a badge next to the highlight (<=120 chars).'),
477
+ },
478
+ annotations: {
479
+ readOnlyHint: false,
480
+ destructiveHint: false,
481
+ idempotentHint: true,
482
+ openWorldHint: true,
483
+ },
484
+ }, async ({ sessionId, selector, label }) => {
485
+ return await dispatchActTool({
486
+ tool: 'execute_action',
487
+ sessionId,
488
+ action: { type: 'highlight', selector, ...(label !== undefined ? { label } : {}) },
489
+ });
490
+ });
491
+ // 12. clear_highlight (Level-2 Suggest tier) -----------------------------
492
+ server.registerTool('clear_highlight', {
493
+ title: 'Clear the highlight overlay',
494
+ description: "Remove the highlight overlay previously drawn by suggest_element in the user's live browser. Available at per-origin permission Level 2 (Suggest) and above. Idempotent. Recorded to ~/.peek/audit.log.",
495
+ inputSchema: {
496
+ sessionId: z
497
+ .string()
498
+ .describe('Session id (origin context) from list_recent_sessions; determines the per-origin permission level.'),
499
+ },
500
+ annotations: {
501
+ readOnlyHint: false,
502
+ destructiveHint: false,
503
+ idempotentHint: true,
504
+ openWorldHint: true,
505
+ },
506
+ }, async ({ sessionId }) => {
507
+ return await dispatchActTool({
508
+ tool: 'execute_action',
509
+ sessionId,
510
+ action: { type: 'clear_highlight' },
511
+ });
512
+ });
513
+ // 13. set_intent (Part 2 — control-shield banner) ------------------------
514
+ // Set the agent's status banner shown on the Level-4 control shield so the
515
+ // user can follow what the agent is doing. Rides the execute_action audit
516
+ // path on the wire; auto-allowed at Level 4 with the shield up.
517
+ server.registerTool('set_intent', {
518
+ title: 'Set the control-shield banner text',
519
+ description: "Set the agent's status banner shown on the control shield (e.g. 'Applying to Senior Frontend · step 2/4'), so the user can follow what you're doing. Up to 80 chars, plain text. Requires the origin at Level 4 with the shield up; auto-allowed. Recorded to ~/.peek/audit.log.",
520
+ inputSchema: {
521
+ sessionId: z
522
+ .string()
523
+ .describe('Session id (origin context) from list_recent_sessions; determines the per-origin permission level.'),
524
+ text: z
525
+ .string()
526
+ .max(80)
527
+ .describe('Status text shown in the shield banner (<=80 chars). Pass an empty string to clear it.'),
528
+ },
529
+ annotations: {
530
+ readOnlyHint: false,
531
+ destructiveHint: false,
532
+ idempotentHint: true,
533
+ openWorldHint: true,
534
+ },
535
+ }, async ({ sessionId, text }) => {
536
+ return await dispatchActTool({
537
+ tool: 'execute_action',
538
+ sessionId,
539
+ action: { type: 'set_intent', text },
540
+ });
541
+ });
542
+ // 14. request_user_input (Plan B — input handoff) ------------------------
543
+ // Pause the agent + hand the keyboard back to the user for ONE editable,
544
+ // non-destructive field (or a free-text prompt), then resume. Rides the
545
+ // execute_action audit path on the wire; the SW gates it at per-origin
546
+ // Level 4 with the control shield up. The per-request bridge timeout is
547
+ // clamped to 30s ABOVE the handoff timeout so the SW controller's timer
548
+ // fires first → structured {resumed:false,'timeout'} (not a transport error).
549
+ server.registerTool('request_user_input', {
550
+ title: 'Pause and ask the user to fill something in on the page',
551
+ description: "Pause the agent and hand the keyboard back to the user for ONE editable, non-destructive field (or a free-text prompt), then resume. Requires the origin at Level 4 with the control shield up. Blocks until the user clicks Done, a timeout fires, or the run is stopped. Returns { resumed:true, value? } or { resumed:false, reason }. The returned value is only included when readBack:true and the field isn't a password/OTP/credit-card field. Recorded to ~/.peek/audit.log (prompt + selector only — never the value).",
552
+ inputSchema: {
553
+ sessionId: z
554
+ .string()
555
+ .describe('Session id (origin context) from list_recent_sessions; determines the per-origin permission level.'),
556
+ prompt: z
557
+ .string()
558
+ .max(280)
559
+ .describe('What to ask the user to do (shown in the card, below a peek-authored framing line).'),
560
+ selector: z
561
+ .string()
562
+ .optional()
563
+ .describe('CSS selector of the editable field to unlock for the user. Omit for a free-text prompt card.'),
564
+ readBack: z
565
+ .boolean()
566
+ .optional()
567
+ .describe('If true, return what the user typed to the agent (never for password/OTP/cc fields). Default false.'),
568
+ timeoutMs: z
569
+ .number()
570
+ .int()
571
+ .min(0)
572
+ .max(600000)
573
+ .optional()
574
+ .describe('How long to wait for the user (default 120000, max 600000).'),
575
+ scope: z
576
+ .enum(['field', 'page'])
577
+ .default('field')
578
+ .describe("'field' (default) unlocks one editable field; 'page' hands full page control back (CAPTCHAs, native widgets, final review) until Resume. Inherits the handoff recording-suspension."),
579
+ },
580
+ annotations: {
581
+ readOnlyHint: false,
582
+ destructiveHint: false,
583
+ idempotentHint: false,
584
+ openWorldHint: true,
585
+ },
586
+ }, async ({ sessionId, prompt, selector, readBack, timeoutMs, scope }) => {
587
+ const handoffTimeout = Math.min(Math.max(timeoutMs ?? 120000, 0), 600000);
588
+ return await dispatchActTool({
589
+ tool: 'execute_action',
590
+ sessionId,
591
+ action: {
592
+ type: 'request_user_input',
593
+ prompt,
594
+ ...(selector !== undefined ? { selector } : {}),
595
+ scope,
596
+ readBack: readBack ?? false,
597
+ timeoutMs: handoffTimeout,
598
+ },
599
+ // The bridge waits 30s longer than the handoff so the SW controller's
600
+ // timer fires first → structured {resumed:false,'timeout'}.
601
+ timeoutMs: handoffTimeout + 30_000,
602
+ });
603
+ });
374
604
  }
375
605
  // --- Act-tool dispatch (shared between execute_action + request_authorization) ---
376
606
  async function dispatchActTool(input) {
@@ -387,6 +617,7 @@ export function createPeekMcpServer(options = {}) {
387
617
  action: input.action,
388
618
  client,
389
619
  ...(input.confirmToken !== undefined ? { confirmToken: input.confirmToken } : {}),
620
+ ...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),
390
621
  });
391
622
  }
392
623
  catch (err) {
@@ -472,5 +703,12 @@ export const PEEK_MCP_TOOLS = [
472
703
  // Write tools (Phase 3d, Level 3+).
473
704
  'request_authorization',
474
705
  'execute_action',
706
+ // Suggest tools (Level 2+ — non-mutating highlight overlay).
707
+ 'suggest_element',
708
+ 'clear_highlight',
709
+ // Input handoff (Plan B — Level 4 with the control shield up).
710
+ 'request_user_input',
711
+ // Control-shield banner (Part 2 — Level 4 auto-allowed).
712
+ 'set_intent',
475
713
  ];
476
714
  //# sourceMappingURL=server.js.map