pi-goosedump 0.10.8 → 0.10.10

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 +4 -3
  2. package/index.ts +47 -9
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -22,8 +22,8 @@ report that they are unavailable.
22
22
  - **`goose_get`** expands entry IDs returned by `goose_search` or `goose_grep`.
23
23
  - **`goose_grep`** filters session messages with a glob pattern.
24
24
  - **`goose_recall`** searches memory harvested by earlier compactions. It
25
- searches the current working directory by default and returns full entries
26
- with provenance.
25
+ searches the current working directory by default and returns remembered
26
+ excerpts with provenance within a 4,096-byte/token-safe output budget.
27
27
  - **`goose_compact`** starts asynchronous compaction of the current Pi session.
28
28
  Set `keep` to preserve the last N user turns verbatim.
29
29
 
@@ -75,7 +75,8 @@ global setting.
75
75
  ## Compaction behavior
76
76
 
77
77
  The extension replaces Pi's normal summary during manual, scheduled, and
78
- automatic compaction. It preserves the previous compaction summary and asks
78
+ automatic compaction. It passes `--train` so the compacted range is harvested
79
+ into persistent memory, preserves the previous compaction summary, and asks
79
80
  goosedump to summarize only the newly compacted range. A `keep:N` request
80
81
  instead keeps the last N active user turns; it is cancelled when no earlier
81
82
  history is available to summarize.
package/index.ts CHANGED
@@ -78,6 +78,13 @@ interface GoosedumpMemoryHit {
78
78
  source_path: string;
79
79
  }
80
80
 
81
+ const RECALL_TOKEN_BUDGET = 4096;
82
+ // Every non-empty token occupies at least one UTF-8 byte, so this byte cap is
83
+ // also a conservative hard cap on the number of tokens returned to Pi.
84
+ const RECALL_MAX_BYTES = RECALL_TOKEN_BUDGET;
85
+ const MEMORY_HIT_SEPARATOR = '\n\n---\n\n';
86
+ const MEMORY_TEXT_TRUNCATED = '\n[Entry text truncated]';
87
+
81
88
  // A `content` part of a pi-native message line.
82
89
  interface PiPartJson {
83
90
  type: string;
@@ -395,13 +402,44 @@ function parseMemoryHits(output: string): GoosedumpMemoryHit[] {
395
402
  );
396
403
  }
397
404
 
398
- function formatMemoryHits(hits: GoosedumpMemoryHit[]): string {
399
- return hits
400
- .map(
401
- (hit) =>
402
- `[${hit.hash}] ${hit.kind} (${hit.provider}:${hit.context_id}/${hit.entry_id})\nWorking directory: ${hit.path}\nSource: ${hit.source_path}\n${hit.text}`,
403
- )
404
- .join('\n\n---\n\n');
405
+ function formatMemoryHit(hit: GoosedumpMemoryHit, maxBytes: number): string {
406
+ const provenance =
407
+ `[${hit.hash}] ${hit.kind} (${hit.provider}:${hit.context_id}/${hit.entry_id})\n` +
408
+ `Working directory: ${hit.path}\nSource: ${hit.source_path}\n`;
409
+ const full = `${provenance}${hit.text}`;
410
+ if (Buffer.byteLength(full) <= maxBytes) return full;
411
+
412
+ const provenanceBytes = Buffer.byteLength(provenance);
413
+ const markerBytes = Buffer.byteLength(MEMORY_TEXT_TRUNCATED);
414
+ if (provenanceBytes + markerBytes >= maxBytes) return utf8Prefix(provenance, maxBytes);
415
+
416
+ const textBytes = maxBytes - provenanceBytes - markerBytes;
417
+ return `${provenance}${utf8Prefix(hit.text, textBytes)}${MEMORY_TEXT_TRUNCATED}`;
418
+ }
419
+
420
+ function formatMemoryHits(hits: GoosedumpMemoryHit[], maxBytes = RECALL_MAX_BYTES): string {
421
+ const formatted: string[] = [];
422
+ let remainingBytes = maxBytes;
423
+ const separatorBytes = Buffer.byteLength(MEMORY_HIT_SEPARATOR);
424
+
425
+ for (let index = 0; index < hits.length; index += 1) {
426
+ if (index > 0) {
427
+ if (remainingBytes < separatorBytes) break;
428
+ formatted.push(MEMORY_HIT_SEPARATOR);
429
+ remainingBytes -= separatorBytes;
430
+ }
431
+
432
+ const remainingHits = hits.length - index;
433
+ const futureSeparators = separatorBytes * (remainingHits - 1);
434
+ const hitBytes = Math.floor((remainingBytes - futureSeparators) / remainingHits);
435
+ if (hitBytes <= 0) break;
436
+
437
+ const hit = formatMemoryHit(hits[index], hitBytes);
438
+ formatted.push(hit);
439
+ remainingBytes -= Buffer.byteLength(hit);
440
+ }
441
+
442
+ return formatted.join('');
405
443
  }
406
444
 
407
445
  const ANSI_SGR = new RegExp(String.fromCharCode(27) + '\\[[0-9;]*m', 'g');
@@ -612,7 +650,7 @@ async function goosedumpCompact(
612
650
  executablePath?: string,
613
651
  ): Promise<{ summary: string; warning: string }> {
614
652
  const scope = options.scope ?? 'lineage';
615
- const args = ['compact', target, '--scope', scope];
653
+ const args = ['compact', target, '--train', '--scope', scope];
616
654
  if (options.from) args.push('--from', options.from);
617
655
  args.push('--until', options.until);
618
656
 
@@ -1519,7 +1557,7 @@ export function createGoosedumpIntegration(
1519
1557
  name: 'goose_recall',
1520
1558
  label: 'goose_recall',
1521
1559
  description:
1522
- 'Recall durable context harvested from earlier compactions. Searches the current project by default and returns full remembered entries with provenance.',
1560
+ 'Recall durable context harvested from earlier compactions. Searches the current project by default and returns bounded remembered excerpts with provenance.',
1523
1561
  promptSnippet: 'Recall durable context from earlier sessions',
1524
1562
  promptGuidelines: [
1525
1563
  'Use goose_recall for decisions, evidence, and context that may have disappeared from the current session.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-goosedump",
3
- "version": "0.10.8",
3
+ "version": "0.10.10",
4
4
  "description": "Pi extension for goosedump-backed session-history search, entry expansion, and compaction",
5
5
  "keywords": [
6
6
  "compaction",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@earendil-works/pi-tui": "^0.78.0",
36
- "@jarkkojs/goosedump": "^0.10.8",
36
+ "@jarkkojs/goosedump": "^0.10.10",
37
37
  "@sinclair/typebox": "^0.34.49"
38
38
  },
39
39
  "devDependencies": {