repoburg 1.3.290 → 1.3.292

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 (32) hide show
  1. package/daemon/dist/index.js +1 -0
  2. package/daemon/dist/tabtape/api/router.js +36 -1
  3. package/daemon/dist/tabtape/api/router.spec.js +47 -0
  4. package/daemon/dist/tabtape/e2e-server.js +1 -0
  5. package/daemon/dist/tabtape/index.js +10 -0
  6. package/daemon/dist/tabtape/index.spec.js +35 -2
  7. package/daemon/dist/tabtape/mcp/definitions.js +14 -3
  8. package/daemon/dist/tabtape/mcp/server.js +2 -1
  9. package/daemon/dist/tabtape/mcp/server.spec.js +50 -2
  10. package/daemon/dist/tabtape/mcp/tools.js +19 -0
  11. package/daemon/dist/tabtape/proxy/proxy.js +361 -0
  12. package/daemon/dist/tabtape/proxy/proxy.spec.js +497 -0
  13. package/daemon/dist/tabtape/proxy/rewrite.js +176 -0
  14. package/daemon/dist/tabtape/proxy/rewrite.spec.js +140 -0
  15. package/package.json +1 -1
  16. package/tabtape/extension/dist/background.js +4 -4
  17. package/tabtape/extension/dist/background.js.map +4 -4
  18. package/tabtape/extension/dist/bridge.js +2 -2
  19. package/tabtape/extension/dist/bridge.js.map +2 -2
  20. package/tabtape/extension/dist/build-info.json +4 -4
  21. package/tabtape/extension/dist/manifest.json +1 -1
  22. package/tabtape/extension/dist/popup.js +1 -1
  23. package/tabtape/extension/dist/popup.js.map +2 -2
  24. package/tabtape/extension/dist/proxy-bridge.js +3 -0
  25. package/tabtape/extension/dist/proxy-bridge.js.map +1 -0
  26. package/tabtape/extension/dist/recorder.js +39 -39
  27. package/tabtape/extension/dist/recorder.js.map +1 -1
  28. package/tabtape/extension/dist/state.js +1 -1
  29. package/tabtape/extension/dist/state.js.map +1 -1
  30. package/tabtape/playwright/tabtape.d.mts +17 -0
  31. package/tabtape/playwright/tabtape.mjs +40 -2
  32. package/tabtape/ui/dist/build-info.json +4 -4
@@ -37,6 +37,7 @@ function loadTabtape() {
37
37
  return (0, tabtape_1.createTabtape)({
38
38
  baseURL: `http://127.0.0.1:${PORT}${tabtape_1.TABTAPE_MOUNT}`,
39
39
  uiDist: (0, tabtape_1.resolveTabtapeUiDist)(__dirname),
40
+ scriptsDir: (0, tabtape_1.resolveTabtapeScriptsDir)(__dirname),
40
41
  });
41
42
  }
42
43
  catch (err) {
@@ -25,6 +25,7 @@ const zlib_1 = __importDefault(require("zlib"));
25
25
  const errors_1 = require("../errors");
26
26
  const export_1 = require("../export/export");
27
27
  const har_1 = require("../har/har");
28
+ const proxy_1 = require("../proxy/proxy");
28
29
  const repro_1 = require("../repro/repro");
29
30
  const sink_1 = require("../sink");
30
31
  const record_1 = require("../store/record");
@@ -37,7 +38,7 @@ const DEFAULT_MAX_BATCH_BYTES = 64 << 20;
37
38
  /** Must accompany every write; see the file comment. */
38
39
  exports.CLIENT_HEADER = 'X-Tabtape-Client';
39
40
  function createApiRouter(opts) {
40
- const { st, rd, buffers, logger } = opts;
41
+ const { st, rd, buffers, proxies, logger } = opts;
41
42
  const maxBatch = opts.maxBatchBytes ?? DEFAULT_MAX_BATCH_BYTES;
42
43
  const router = express_1.default.Router();
43
44
  const wrap = (fn) => (req, res, next) => {
@@ -476,6 +477,40 @@ function createApiRouter(opts) {
476
477
  }
477
478
  (0, http_1.sendStatus)(res, 204);
478
479
  }));
480
+ // ---------- recording through a proxy ----------
481
+ if (proxies) {
482
+ const proxyError = (res, err) => {
483
+ if (err instanceof proxy_1.ProxyInputError)
484
+ (0, http_1.sendText)(res, 400, err.message);
485
+ else
486
+ (0, http_1.sendText)(res, 500, err.message);
487
+ };
488
+ // Body: {"url": "http://localhost:3000/cart", "name": "checkout"}.
489
+ router.post('/api/proxy', wrap(async (req, res) => {
490
+ const body = await (0, http_1.readJSON)(req, res);
491
+ if (body === undefined)
492
+ return;
493
+ const { url, name } = isObject(body) ? body : {};
494
+ if (typeof url !== 'string' || (name !== undefined && typeof name !== 'string')) {
495
+ (0, http_1.sendText)(res, 400, 'invalid JSON body: url must be a string and name, if set, too');
496
+ return;
497
+ }
498
+ try {
499
+ (0, http_1.sendJSON)(res, 201, await proxies.start({ url, name }));
500
+ }
501
+ catch (err) {
502
+ proxyError(res, err);
503
+ }
504
+ }));
505
+ router.post('/api/proxy/:id/stop', wrap(async (req, res) => {
506
+ try {
507
+ (0, http_1.sendJSON)(res, 200, await proxies.stop(req.params.id));
508
+ }
509
+ catch (err) {
510
+ proxyError(res, err);
511
+ }
512
+ }));
513
+ }
479
514
  // ---------- MCP ----------
480
515
  if (opts.mcp) {
481
516
  const mcp = opts.mcp;
@@ -11,6 +11,7 @@ const zlib_1 = __importDefault(require("zlib"));
11
11
  const ws_1 = __importDefault(require("ws"));
12
12
  const buffer_1 = require("../buffer/buffer");
13
13
  const log_1 = require("../log");
14
+ const proxy_1 = require("../proxy/proxy");
14
15
  const reader_1 = require("../query/reader");
15
16
  const redact_1 = require("../redact");
16
17
  const record_1 = require("../store/record");
@@ -40,6 +41,7 @@ async function serve(o = {}) {
40
41
  viewer: () => o.viewer ?? null,
41
42
  mcp: o.mcp ?? null,
42
43
  recordToken: o.recordToken ?? '',
44
+ proxies: o.proxies ?? null,
43
45
  followers,
44
46
  stop,
45
47
  logger: log_1.silentLogger,
@@ -247,6 +249,51 @@ describe('record links', () => {
247
249
  expect(js.body).toContain('const MOUNT = "/tabtape"');
248
250
  });
249
251
  });
252
+ describe('recording through a proxy', () => {
253
+ const proxies = {
254
+ start: async (input) => {
255
+ if (input.url === 'bad')
256
+ throw new proxy_1.ProxyInputError('url "bad": not a URL');
257
+ if (input.url === 'broken')
258
+ throw new Error('no recorder');
259
+ return { id: 'r1', url: 'http://127.0.0.1:5000/', target: input.url, replay: input.name };
260
+ },
261
+ stop: async (id) => {
262
+ if (id !== 'r1')
263
+ throw new proxy_1.ProxyInputError(`no proxy recording ${id}`);
264
+ return { id, recorded: true, replay: 'x' };
265
+ },
266
+ };
267
+ const post = (s, p, body, headers = client) => request(s, 'POST', `${MOUNT}${p}`, { body, headers });
268
+ it('starts and stops', async () => {
269
+ const s = await serve({ proxies });
270
+ const started = await post(s, '/api/proxy', '{"url":"http://localhost:3000","name":"n"}');
271
+ expect(started.status).toBe(201);
272
+ expect(JSON.parse(started.body)).toEqual({ id: 'r1', url: 'http://127.0.0.1:5000/', target: 'http://localhost:3000', replay: 'n' });
273
+ const stopped = await post(s, '/api/proxy/r1/stop');
274
+ expect([stopped.status, JSON.parse(stopped.body).recorded]).toEqual([200, true]);
275
+ });
276
+ it('stays closed to web pages', async () => {
277
+ const s = await serve({ proxies });
278
+ const body = '{"url":"http://localhost:3000"}';
279
+ expect((await post(s, '/api/proxy', body, {})).status).toBe(403);
280
+ expect((await post(s, '/api/proxy/r1/stop', undefined, {})).status).toBe(403);
281
+ expect((await request(s, 'POST', `${MOUNT}/api/proxy`, { body, headers: client, host: 'evil.test' })).status).toBe(403);
282
+ expect((await post(s, '/api/proxy', body, { ...client, Origin: 'https://evil.test' })).headers['access-control-allow-origin']).toBeUndefined();
283
+ });
284
+ it('says what is wrong', async () => {
285
+ const s = await serve({ proxies });
286
+ for (const body of ['not json', '{}', '{"url":1}', '{"url":"x","name":1}', '[]'])
287
+ expect([body, (await post(s, '/api/proxy', body)).status]).toEqual([body, 400]);
288
+ expect(await post(s, '/api/proxy', '{"url":"bad"}')).toMatchObject({ status: 400, body: 'url "bad": not a URL\n' });
289
+ expect(await post(s, '/api/proxy', '{"url":"broken"}')).toMatchObject({ status: 500, body: 'no recorder\n' });
290
+ expect(await post(s, '/api/proxy/nope/stop')).toMatchObject({ status: 400, body: 'no proxy recording nope\n' });
291
+ });
292
+ it('is not there without proxies', async () => {
293
+ const s = await serve();
294
+ expect((await post(s, '/api/proxy', '{"url":"http://localhost:3000"}')).status).toBe(404);
295
+ });
296
+ });
250
297
  describe('MCP mount', () => {
251
298
  it('needs no client header but a loopback host', async () => {
252
299
  let called = false;
@@ -63,6 +63,7 @@ async function main() {
63
63
  const tabtape = (0, index_1.createTabtape)({
64
64
  baseURL: `http://${baseHost}:${port}/tabtape`,
65
65
  uiDist: (0, index_1.resolveTabtapeUiDist)(path_1.default.join(__dirname, '..')),
66
+ scriptsDir: (0, index_1.resolveTabtapeScriptsDir)(path_1.default.join(__dirname, '..')),
66
67
  config,
67
68
  });
68
69
  const app = (0, express_1.default)();
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TABTAPE_VERSION = exports.TABTAPE_MOUNT = void 0;
7
7
  exports.resolveTabtapeUiDist = resolveTabtapeUiDist;
8
+ exports.resolveTabtapeScriptsDir = resolveTabtapeScriptsDir;
8
9
  exports.createTabtape = createTabtape;
9
10
  const path_1 = __importDefault(require("path"));
10
11
  const buffer_1 = require("./buffer/buffer");
@@ -12,6 +13,7 @@ const config_1 = require("./config");
12
13
  const lock_1 = require("./lock");
13
14
  const log_1 = require("./log");
14
15
  const server_1 = require("./mcp/server");
16
+ const proxy_1 = require("./proxy/proxy");
15
17
  const reader_1 = require("./query/reader");
16
18
  const redact_1 = require("./redact");
17
19
  const store_1 = require("./store/store");
@@ -32,6 +34,10 @@ Object.defineProperty(exports, "TABTAPE_VERSION", { enumerable: true, get: funct
32
34
  function resolveTabtapeUiDist(fromDir) {
33
35
  return path_1.default.resolve(fromDir, '../../tabtape/ui/dist');
34
36
  }
37
+ /** Same for the extension build, which holds the recorder. */
38
+ function resolveTabtapeScriptsDir(fromDir) {
39
+ return path_1.default.resolve(fromDir, '../../tabtape/extension/dist');
40
+ }
35
41
  /** Opens the stores (repairing and trimming them) and builds the routes. */
36
42
  function createTabtape(opts) {
37
43
  const config = opts.config ?? (0, config_1.loadConfig)();
@@ -65,6 +71,7 @@ function createTabtape(opts) {
65
71
  // Record links carry this token; the MCP tool get_record_link hands it
66
72
  // out. A new one each start: links from an earlier run stop working.
67
73
  const recordToken = (0, record_1.newRecordToken)();
74
+ const proxies = new proxy_1.Proxies({ st, baseURL: opts.baseURL, scriptsDir: opts.scriptsDir, logger });
68
75
  const mcp = new server_1.TabtapeMcp(st, rd, {
69
76
  version: config_1.TABTAPE_VERSION,
70
77
  baseURL: opts.baseURL,
@@ -72,6 +79,7 @@ function createTabtape(opts) {
72
79
  showSecrets: config.showSecrets,
73
80
  token: config.mcpToken,
74
81
  recordToken,
82
+ proxies,
75
83
  logger,
76
84
  });
77
85
  let stopNow;
@@ -91,6 +99,7 @@ function createTabtape(opts) {
91
99
  viewer: (0, static_1.viewerLoader)(opts.uiDist),
92
100
  mcp,
93
101
  recordToken,
102
+ proxies,
94
103
  followers,
95
104
  stop,
96
105
  logger,
@@ -121,6 +130,7 @@ function createTabtape(opts) {
121
130
  upgrades.close();
122
131
  buffers.close();
123
132
  try {
133
+ await proxies.close();
124
134
  await st.close();
125
135
  }
126
136
  finally {
@@ -48,6 +48,7 @@ describe('createTabtape', () => {
48
48
  tabtape = (0, index_1.createTabtape)({
49
49
  baseURL: 'http://127.0.0.1:9998/tabtape',
50
50
  uiDist,
51
+ scriptsDir: null,
51
52
  config: (0, config_1.loadConfig)({ REPOBURG_TABTAPE_DATA: dataDir }),
52
53
  logger: log_1.silentLogger,
53
54
  });
@@ -80,9 +81,40 @@ describe('createTabtape', () => {
80
81
  await tabtape.close();
81
82
  expect(await closed).toBe(1001);
82
83
  });
84
+ it('records through a proxy and ends it on close', async () => {
85
+ const app = http_1.default.createServer((_req, res) => {
86
+ res.writeHead(200, { 'Content-Type': 'text/html' });
87
+ res.end('<html><head></head><body>app</body></html>');
88
+ });
89
+ await new Promise((r) => app.listen(0, '127.0.0.1', r));
90
+ const scriptsDir = (0, tmp_1.tempDir)();
91
+ for (const f of ['proxy-bridge.js', 'state.js', 'recorder.js'])
92
+ fs_1.default.writeFileSync(path_1.default.join(scriptsDir, f), '//');
93
+ const dataDir = (0, tmp_1.tempDir)();
94
+ tabtape = (0, index_1.createTabtape)({ baseURL: 'http://127.0.0.1:9998/tabtape', uiDist: null, scriptsDir, config: (0, config_1.loadConfig)({ REPOBURG_TABTAPE_DATA: dataDir }), logger: log_1.silentLogger });
95
+ const daemon = (0, express_1.default)();
96
+ daemon.use(index_1.TABTAPE_MOUNT, tabtape.router);
97
+ server = http_1.default.createServer(daemon);
98
+ await new Promise((r) => server.listen(0, '127.0.0.1', r));
99
+ const started = await fetch(`http://127.0.0.1:${server.address().port}${index_1.TABTAPE_MOUNT}/api/proxy`, {
100
+ method: 'POST',
101
+ headers: { 'X-Tabtape-Client': 'test' },
102
+ body: JSON.stringify({ url: `http://127.0.0.1:${app.address().port}/` }),
103
+ });
104
+ expect(started.status).toBe(201);
105
+ const { id, url } = (await started.json());
106
+ const page = await (await fetch(url, { headers: { 'Sec-Fetch-Dest': 'document' } })).text();
107
+ expect(page).toContain('/__tabtape/recorder.js');
108
+ await tabtape.close();
109
+ await expect(fetch(url)).rejects.toThrow();
110
+ const meta = JSON.parse(fs_1.default.readFileSync(path_1.default.join(dataDir, 'sessions', id, 'meta.json'), 'utf8'));
111
+ expect(meta.endedAt).toBeGreaterThan(0);
112
+ app.closeAllConnections();
113
+ app.close();
114
+ });
83
115
  it('keeps one process per data directory', async () => {
84
116
  const dataDir = (0, tmp_1.tempDir)();
85
- const open = () => (0, index_1.createTabtape)({ baseURL: 'http://127.0.0.1:9998/tabtape', uiDist: null, config: (0, config_1.loadConfig)({ REPOBURG_TABTAPE_DATA: dataDir }), logger: log_1.silentLogger });
117
+ const open = () => (0, index_1.createTabtape)({ baseURL: 'http://127.0.0.1:9998/tabtape', uiDist: null, scriptsDir: null, config: (0, config_1.loadConfig)({ REPOBURG_TABTAPE_DATA: dataDir }), logger: log_1.silentLogger });
86
118
  const first = open();
87
119
  expect(() => open()).toThrow(/already open/);
88
120
  await first.close();
@@ -97,8 +129,9 @@ describe('createTabtape', () => {
97
129
  fs_1.default.rmSync(path_1.default.join(dataDir, '.lock'));
98
130
  tabtape = null;
99
131
  });
100
- it('resolves the UI build from the daemon directory', () => {
132
+ it('resolves the builds from the daemon directory', () => {
101
133
  expect((0, index_1.resolveTabtapeUiDist)('/repo/daemon/dist')).toBe(path_1.default.resolve('/repo/tabtape/ui/dist'));
102
134
  expect((0, index_1.resolveTabtapeUiDist)('/repo/daemon/src')).toBe(path_1.default.resolve('/repo/tabtape/ui/dist'));
135
+ expect((0, index_1.resolveTabtapeScriptsDir)('/repo/daemon/dist')).toBe(path_1.default.resolve('/repo/tabtape/extension/dist'));
103
136
  });
104
137
  });
@@ -114,14 +114,16 @@ const OUTPUT = {
114
114
  context: obj({ at: STR, offsetMs: INT, items: list(itemOut), stateActions: list(stateActionOut) }, ['at', 'offsetMs', 'items']),
115
115
  repro: obj({ markdown: STR, steps: INT, replay: STR }, ['markdown', 'steps', 'replay']),
116
116
  recordLink: obj({ start: STR, stop: STR }, ['start', 'stop']),
117
+ proxyRecording: obj({ id: STR, url: STR, target: STR, replay: STR }, ['id', 'url', 'target', 'replay']),
118
+ proxyStopped: obj({ id: STR, recorded: BOOL, replay: STR }, ['id', 'recorded', 'replay']),
117
119
  };
118
120
  // ---------- the tools ----------
119
121
  const SESSION_LATEST = 'session id, or latest';
120
122
  const CURSOR = 'continue a cut result: pass next_cursor from the previous call';
121
123
  const FROM = 'start of the time window: mm:ss(.mmm), a duration like 90s, or milliseconds';
122
124
  const TO = 'end of the time window, same format as from';
123
- function def(name, description, params, output, run) {
124
- return { name, description, params, output, run: run };
125
+ function def(name, description, params, output, run, extra = {}) {
126
+ return { name, description, params, output, run: run, ...extra };
125
127
  }
126
128
  const TOOLS = [
127
129
  def('list_sessions', 'List tabtape recordings, newest first, with page, click, error and failed-request counts, the identified user and a replay link. Filter by text, user, time and errors.', [
@@ -203,6 +205,15 @@ const TOOLS = [
203
205
  description: 'page the tab opens once the recording runs (http, https or file URL); recorded from its first request',
204
206
  },
205
207
  ], OUTPUT.recordLink, (t, input) => t.getRecordLink(input)),
208
+ def('start_proxy_recording', 'Starts recording an app through a local proxy, for a browser without the tabtape extension: any browser, any Playwright context. Returns the URL to open instead of the app\'s. Stop it with stop_proxy_recording.', [
209
+ { name: 'url', type: 'string', description: 'the page to record (http or https); the proxy serves its origin', required: true },
210
+ {
211
+ name: 'name',
212
+ type: 'string',
213
+ description: "what is about to be recorded, e.g. the check you are going to run; it becomes the recording's title",
214
+ },
215
+ ], OUTPUT.proxyRecording, (t, input) => t.startProxyRecording(input), { writes: true }),
216
+ def('stop_proxy_recording', 'Stops a recording made with start_proxy_recording and closes its proxy. Returns the replay link.', [{ name: 'session_id', type: 'string', description: 'the session id start_proxy_recording returned', required: true }], OUTPUT.proxyStopped, (t, input) => t.stopProxyRecording(input), { writes: true }),
206
217
  ].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)); // the Go SDK lists tools by name
207
218
  const BY_NAME = new Map(TOOLS.map((t) => [t.name, t]));
208
219
  function inputSchema(params) {
@@ -219,7 +230,7 @@ exports.TOOL_LIST = TOOLS.map((t) => ({
219
230
  inputSchema: inputSchema(t.params),
220
231
  outputSchema: t.output,
221
232
  // The Go SDK always sends idempotentHint and readOnlyHint.
222
- annotations: { idempotentHint: false, openWorldHint: false, readOnlyHint: true },
233
+ annotations: { idempotentHint: false, openWorldHint: false, readOnlyHint: !t.writes },
223
234
  }));
224
235
  // ---------- arguments ----------
225
236
  /** Arguments that do not match a tool's input schema. */
@@ -31,7 +31,7 @@ Start with list_sessions or get_session_summary (session_id "latest" is the most
31
31
  Request and response bodies are only returned by get_request or with include_bodies=true. Sensitive headers are shown as [redacted].
32
32
  Recordings made in deep mode also have the real request headers and cookies, the timing split, why a request failed (CORS, blocked cookies, mixed content) and WebSocket connections: get_network with kind=websocket lists them, get_request on a connection pages its messages.
33
33
  get_session_summary says how the JS heap grew over the recording; get_context_at gives the heap at the moment and ends with the last store actions before it and the state paths they changed.
34
- To record a browser you drive yourself (Playwright MCP, a Playwright script), get_record_link returns links that start and stop a recording in it; open the start link before the check and the stop link after it.`;
34
+ To record a browser you drive yourself (Playwright MCP, a Playwright script), get_record_link returns links that start and stop a recording in it; open the start link before the check and the stop link after it. That browser needs the tabtape extension; start_proxy_recording needs none and works in any browser: open the URL it returns and call stop_proxy_recording after the check.`;
35
35
  const RESOURCE_PREFIX = 'tabtape://session/';
36
36
  const SESSION_TEMPLATE = {
37
37
  name: 'session',
@@ -78,6 +78,7 @@ class TabtapeMcp {
78
78
  redact: opts.redact,
79
79
  showSecrets: opts.showSecrets,
80
80
  recordToken: opts.recordToken,
81
+ proxies: opts.proxies ?? null,
81
82
  timeZone: opts.timeZone,
82
83
  now: opts.now ?? Date.now,
83
84
  });
@@ -41,6 +41,7 @@ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
41
41
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
42
42
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
43
43
  const log_1 = require("../log");
44
+ const proxy_1 = require("../proxy/proxy");
44
45
  const reader_1 = require("../query/reader");
45
46
  const redact_1 = require("../redact");
46
47
  const record_1 = require("../store/record");
@@ -158,7 +159,7 @@ const PING = '{"jsonrpc":"2.0","id":1,"method":"ping"}';
158
159
  /** The text of a resource's contents. */
159
160
  const textOf = (c) => ('text' in c ? c.text : '');
160
161
  describe('TabtapeMcp', () => {
161
- it('lists the tools as read-only', async () => {
162
+ it('lists the tools, read-only but for the proxy', async () => {
162
163
  const e = await setup();
163
164
  const res = await e.client.listTools();
164
165
  const names = res.tools.map((t) => t.name);
@@ -171,9 +172,12 @@ describe('TabtapeMcp', () => {
171
172
  'get_request',
172
173
  'get_session_summary',
173
174
  'list_sessions',
175
+ 'start_proxy_recording',
176
+ 'stop_proxy_recording',
174
177
  ]);
175
178
  for (const tool of res.tools) {
176
- expect([tool.name, tool.annotations]).toEqual([tool.name, { idempotentHint: false, openWorldHint: false, readOnlyHint: true }]);
179
+ const readOnlyHint = !tool.name.endsWith('_proxy_recording');
180
+ expect([tool.name, tool.annotations]).toEqual([tool.name, { idempotentHint: false, openWorldHint: false, readOnlyHint }]);
177
181
  expect(tool.outputSchema?.type).toBe('object');
178
182
  expect(tool.inputSchema.additionalProperties).toBe(false);
179
183
  }
@@ -639,6 +643,50 @@ describe('TabtapeMcp', () => {
639
643
  expect(data.resBody.endsWith('END')).toBe(true);
640
644
  });
641
645
  });
646
+ describe('proxy recordings', () => {
647
+ it('starts and stops one', async () => {
648
+ const stopped = { id: 'r1', recorded: true, replay: `${base}/#/s/r1` };
649
+ const started = { id: 'r1', url: 'http://127.0.0.1:5000/cart', target: `${site}/cart`, replay: `${base}/#/s/r1` };
650
+ const proxies = { start: jest.fn(async () => started), stop: jest.fn(async () => stopped) };
651
+ const e = await setup({ proxies });
652
+ let res = await call(e, 'start_proxy_recording', { url: `${site}/cart`, name: 'checkout' });
653
+ expect(res.isError).toBe(false);
654
+ expect(res.data).toEqual(started);
655
+ expect(proxies.start).toHaveBeenCalledWith({ url: `${site}/cart`, name: 'checkout' });
656
+ expect(res.text).toContain(`Open ${started.url} in the browser`);
657
+ expect(res.text).toContain('without the tabtape extension');
658
+ expect(res.text).toContain(`Session: r1\nReplay: ${started.replay}`);
659
+ expect(res.text).toContain('stop_proxy_recording');
660
+ res = await call(e, 'stop_proxy_recording', { session_id: ' r1 ' });
661
+ expect(res.data).toEqual(stopped);
662
+ expect(proxies.stop).toHaveBeenCalledWith('r1');
663
+ expect(res.text).toBe(`Saved recording r1.\nReplay: ${stopped.replay}`);
664
+ });
665
+ it('says when nothing was recorded', async () => {
666
+ const proxies = { stop: async () => ({ id: 'r1', recorded: false, replay: 'x' }) };
667
+ const { text } = await call(await setup({ proxies }), 'stop_proxy_recording', { session_id: 'r1' });
668
+ expect(text).toBe('No page was opened through the proxy of r1: nothing was recorded.');
669
+ });
670
+ it('wants a url and a session id, and passes on what goes wrong', async () => {
671
+ const proxies = {
672
+ start: async () => {
673
+ throw new proxy_1.ProxyInputError('url "x": not a URL');
674
+ },
675
+ stop: async () => {
676
+ throw new proxy_1.ProxyInputError('no proxy recording x');
677
+ },
678
+ };
679
+ const e = await setup({ proxies });
680
+ expect((await call(e, 'start_proxy_recording')).isError).toBe(true);
681
+ expect((await call(e, 'stop_proxy_recording')).isError).toBe(true);
682
+ expect(await call(e, 'start_proxy_recording', { url: 'x' })).toMatchObject({ isError: true, text: 'url "x": not a URL' });
683
+ expect(await call(e, 'stop_proxy_recording', { session_id: 'x' })).toMatchObject({ isError: true, text: 'no proxy recording x' });
684
+ });
685
+ it('is off without proxies', async () => {
686
+ const res = await call(await setup(), 'start_proxy_recording', { url: site });
687
+ expect(res).toMatchObject({ isError: true, text: 'proxy recordings are turned off in this Repoburg daemon' });
688
+ });
689
+ });
642
690
  describe('get_record_link', () => {
643
691
  it('builds start and stop links', async () => {
644
692
  const e = await setup({ recordToken: 'tok-123' });
@@ -627,6 +627,25 @@ class Tools {
627
627
  async getRecordLink(input) {
628
628
  return (0, recordLink_1.getRecordLink)({ baseURL: this.opts.baseURL, recordToken: this.opts.recordToken }, input);
629
629
  }
630
+ // ---------- start_proxy_recording, stop_proxy_recording ----------
631
+ async startProxyRecording(input) {
632
+ const out = await this.proxies().start({ url: input.url, name: input.name });
633
+ const text = `Open ${out.url} in the browser: it is ${out.target} through a recording proxy, in any browser, without the tabtape extension.\n\n` +
634
+ `Session: ${out.id}\nReplay: ${out.replay}\n\n` +
635
+ 'Every page opened through that origin is recorded, from the first one on, one tab at a time. Links to other origins leave the proxy and the recording. ' +
636
+ 'There is no deep mode. After the check call stop_proxy_recording with the session id: the proxy closes, and the session can be read with the other tools. Unused, it closes after 30 minutes.';
637
+ return { text, out };
638
+ }
639
+ async stopProxyRecording(input) {
640
+ const out = await this.proxies().stop((0, gofmt_1.goTrimSpace)(input.session_id));
641
+ const text = out.recorded ? `Saved recording ${out.id}.\nReplay: ${out.replay}` : `No page was opened through the proxy of ${out.id}: nothing was recorded.`;
642
+ return { text, out };
643
+ }
644
+ proxies() {
645
+ if (!this.opts.proxies)
646
+ throw new Error('proxy recordings are turned off in this Repoburg daemon');
647
+ return this.opts.proxies;
648
+ }
630
649
  }
631
650
  exports.Tools = Tools;
632
651
  // ---------- texts ----------