@pratikgajjar/pi-recall 0.1.0 → 0.1.1

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 (3) hide show
  1. package/README.md +17 -0
  2. package/package.json +1 -1
  3. package/src/index.ts +70 -19
package/README.md CHANGED
@@ -41,6 +41,23 @@ pi -e ./packages/pi-recall/src/index.ts
41
41
 
42
42
  All tools accept `repo` (pass `"."` for the current project), `source` (`cursor` \| `claude` \| `codex` \| `pi`), and `since` (e.g. `7d`).
43
43
 
44
+ ### Navigating large sessions
45
+
46
+ Some sessions are huge (thousands of messages). `recall_transcript` takes two
47
+ extra params to slice instead of dumping everything:
48
+
49
+ - `range` — Python-style slice over the message list: `":100"` first 100,
50
+ `"-50:"` last 50, `"305:315"` window. Negative indices count from the end.
51
+ - `outline` — one line per message: `[N] role: first-line`. A cheap table of
52
+ contents you can scan before slicing in.
53
+
54
+ Every rendered message carries its own `## msg N/TOTAL role` header so any
55
+ slice is self-locating. **Default-cap:** if a session has more than 200
56
+ messages and you ask for neither `range` nor `outline`, the tool returns the
57
+ outline (plus a one-line note explaining how to drill in) instead of a
58
+ context-blowing wall of text. After a `recall_search` hit at `msg_idx=N`,
59
+ prefer `range: "N-5:N+5"` over reading the whole session.
60
+
44
61
  ### Recommended agent prompt
45
62
 
46
63
  Drop into your project's `AGENTS.md` / `CLAUDE.md`:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pratikgajjar/pi-recall",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "pi extension: search your past AI chat history (Cursor, Claude Code, Codex, pi) via the recall CLI",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -338,37 +338,89 @@ export default function recallExtension(pi: ExtensionAPI) {
338
338
  repo: Type.Optional(Type.String({ description: REPO_HELP })),
339
339
  source: Type.Optional(Type.String({ description: SOURCE_HELP })),
340
340
  since: Type.Optional(Type.String({ description: SINCE_HELP })),
341
+ range: Type.Optional(
342
+ Type.String({
343
+ description:
344
+ "Python-style slice over the message list. ':100' = first 100, '-50:' = last 50, '305:315' = window around a recall_search hit (msg_idx). Negative indices count from the end.",
345
+ }),
346
+ ),
347
+ outline: Type.Optional(
348
+ Type.Boolean({
349
+ description:
350
+ "One line per message ([N] role: first-line). Use to navigate a large session before slicing in with 'range'.",
351
+ }),
352
+ ),
341
353
  });
342
354
 
355
+ // Above this many messages, recall_transcript called without 'range' or
356
+ // 'outline' returns the outline instead of the full body — protects the
357
+ // agent from accidentally pulling a 25 MB transcript into context.
358
+ const BIG_SESSION_THRESHOLD = 200;
359
+
360
+ function parseMsgCount(outlineStdout: string): number {
361
+ const m = outlineStdout.match(/msgs=(\d+)\s+\(outline\)/);
362
+ return m ? Number.parseInt(m[1], 10) : 0;
363
+ }
364
+
343
365
  pi.registerTool({
344
366
  name: "recall_transcript",
345
367
  label: "recall transcript",
346
368
  description:
347
- "Read a past AI session as a full transcript. Pass a session_id from recall_search, or omit it to get the most recent session (optionally filtered by repo/source/since).",
369
+ "Read a past AI session as a transcript. Pass a session_id from recall_search, or omit it to get the most recent session (optionally filtered by repo/source/since). Large sessions: use 'outline' to navigate, then 'range' to slice. After a recall_search hit at msg_idx=N, prefer range='N-5:N+5' over the full session.",
348
370
  promptSnippet: "Read a past AI session transcript",
349
371
  promptGuidelines: [
350
372
  "Call recall_transcript after recall_search to read a specific session before reusing its decisions.",
351
373
  "Omit session_id with repo: '.' to pull the most recent conversation in this project.",
374
+ "After a recall_search hit at msg_idx=N, call recall_transcript with range='N-5:N+5' to read around it instead of dumping the whole session.",
375
+ "For an unfamiliar large session, call with outline=true first — it returns one line per message so you can pick a range to drill into.",
352
376
  ],
353
377
  parameters: transcriptSchema,
354
378
 
355
379
  async execute(_id, params, signal) {
356
- const args = params.session_id
357
- ? ["show", params.session_id]
358
- : ["last", ...buildFilterArgs({
359
- repo: params.repo,
360
- source: params.source,
361
- since: params.since,
362
- })];
363
- const res = await runRecall(args, signal);
364
- if (!res.ok) {
365
- const msg = res.stderr || res.stdout.trim() || `recall exited with code ${res.code}`;
380
+ const filterArgs = buildFilterArgs({
381
+ repo: params.repo,
382
+ source: params.source,
383
+ since: params.since,
384
+ });
385
+ const cmd = params.session_id ? ["show", params.session_id] : ["last", ...filterArgs];
386
+
387
+ // Honor an explicit slice as-is.
388
+ if (params.range || params.outline) {
389
+ if (params.range) cmd.push("--range", params.range);
390
+ if (params.outline) cmd.push("--outline");
391
+ const res = await runRecall(cmd, signal);
392
+ if (!res.ok) {
393
+ const msg = res.stderr || res.stdout.trim() || `recall exited with code ${res.code}`;
394
+ return { content: [{ type: "text", text: msg }], details: { found: false }, isError: true };
395
+ }
396
+ return {
397
+ content: [{ type: "text", text: capTranscript(res.stdout.trim()) }],
398
+ details: { found: true },
399
+ };
400
+ }
401
+
402
+ // No slice asked for: peek at the outline first to size the session.
403
+ // ~ms; lets us auto-protect the agent's context on huge transcripts.
404
+ const peek = await runRecall([...cmd, "--outline"], signal);
405
+ if (!peek.ok) {
406
+ const msg = peek.stderr || peek.stdout.trim() || `recall exited with code ${peek.code}`;
407
+ return { content: [{ type: "text", text: msg }], details: { found: false }, isError: true };
408
+ }
409
+ const msgCount = parseMsgCount(peek.stdout);
410
+ if (msgCount > BIG_SESSION_THRESHOLD) {
411
+ const note =
412
+ `// session has ${msgCount} messages; defaulting to outline. Call recall_transcript again with range='FROM:TO' (e.g. range='-50:') to read a slice.\n\n`;
366
413
  return {
367
- content: [{ type: "text", text: msg }],
368
- details: { found: false },
369
- isError: true,
414
+ content: [{ type: "text", text: capTranscript(note + peek.stdout.trim()) }],
415
+ details: { found: true },
370
416
  };
371
417
  }
418
+ // Small session — the full transcript is safe.
419
+ const res = await runRecall(cmd, signal);
420
+ if (!res.ok) {
421
+ const msg = res.stderr || res.stdout.trim() || `recall exited with code ${res.code}`;
422
+ return { content: [{ type: "text", text: msg }], details: { found: false }, isError: true };
423
+ }
372
424
  return {
373
425
  content: [{ type: "text", text: capTranscript(res.stdout.trim()) }],
374
426
  details: { found: true },
@@ -378,11 +430,10 @@ export default function recallExtension(pi: ExtensionAPI) {
378
430
  renderCall(args, theme, context) {
379
431
  const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
380
432
  const target = args?.session_id ?? (args?.repo ? `last in ${args.repo}` : "last");
381
- text.setText(
382
- theme.fg("toolTitle", theme.bold("recall transcript")) +
383
- " " +
384
- theme.fg("accent", target),
385
- );
433
+ let c = theme.fg("toolTitle", theme.bold("recall transcript")) + " " + theme.fg("accent", target);
434
+ if (args?.outline) c += theme.fg("muted", " [outline]");
435
+ else if (args?.range) c += theme.fg("muted", ` [${args.range}]`);
436
+ text.setText(c);
386
437
  return text;
387
438
  },
388
439
  renderResult(result, options, theme, context) {