pi-tuck 1.10.2 → 1.10.3

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to pi-tuck. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
4
4
  [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## [1.10.3]
7
+
8
+ ### Fixed
9
+
10
+ - Summary: the output of a command a prompt told the agent to run (such as "New telex. Run: telex read NAME") is now carried, newest four
11
+ first and at most 8,000 characters in all (the rest is cut with a recall pointer), ahead of kept reads and searches. An agent driven by messages gets its tasks only as such tool results, and the summary kept
12
+ just a pointer to them, so a queued task could fall out of view after a cut.
13
+
6
14
  ## [1.10.2]
7
15
 
8
16
  ### Fixed
package/README.md CHANGED
@@ -12,11 +12,11 @@ pi install npm:pi-tuck
12
12
 
13
13
  Start a new Pi process after installing or updating. pi-tuck handles automatic compaction and `/compact` by default. Run `/tuck` to see the loaded version, cut history, and active cut policy.
14
14
 
15
- This README describes pi-tuck 1.10.2. To pin a published release, use a versioned source such as `pi install npm:pi-tuck@1.10.2` or `pi install git:github.com/galyavin/pi-tuck@v1.10.2`. To uninstall, run `pi remove` with the source you installed.
15
+ This README describes pi-tuck 1.10.3. To pin a published release, use a versioned source such as `pi install npm:pi-tuck@1.10.3` or `pi install git:github.com/galyavin/pi-tuck@v1.10.3`. To uninstall, run `pi remove` with the source you installed.
16
16
 
17
17
  ## Compaction and recall
18
18
 
19
- A cut replaces older turns in the model's context with a summary while keeping the original entries in the session. The summary prioritizes the current prompt, recent turns, excerpts from earlier prompts, and pointers to files and tool actions. It can also carry recent reads and searches when the session records no action that could have changed their files. The recorded text is historical evidence about the session. Re-read a file before editing it.
19
+ A cut replaces older turns in the model's context with a summary while keeping the original entries in the session. The summary prioritizes the current prompt, recent turns, excerpts from earlier prompts, and pointers to files and tool actions. It carries the output of a command a prompt told the agent to run (such as "Run: telex read NAME"), the newest four and at most 8,000 characters in all, since an agent driven by messages gets its tasks that way. It can also carry recent reads and searches when the session records no action that could have changed their files. The recorded text is historical evidence about the session. Re-read a file before editing it.
20
20
 
21
21
  Files the agent has read more than once are carried whole after the summary, most-read first, as far as a share of the summary allows. A file is carried only when its last read covered the whole file and the file on disk still holds exactly that text; the agent can edit from a carried copy without re-reading it. When a session's cuts keep dropping files the agent then reads again unchanged, pi-tuck moves its trim point later, to native Pi's (the larger of the room and `keepRecentTokens`), while keeping room for the next reply. Cuts still trim to the usual size.
22
22
 
@@ -1 +1 @@
1
- export declare const BUILD_ID = "40fe96e6b860dcdd5a9a060eac86b30698e64e377f1d2c4d9e243308cb2a6bf9";
1
+ export declare const BUILD_ID = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
@@ -1 +1 @@
1
- export const BUILD_ID = "40fe96e6b860dcdd5a9a060eac86b30698e64e377f1d2c4d9e243308cb2a6bf9";
1
+ export const BUILD_ID = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
@@ -1,6 +1,6 @@
1
1
  import { type RecallPolicy } from './recall.js';
2
2
  import type { SessionEntry } from '@earendil-works/pi-coding-agent';
3
- export declare const DIAGNOSTIC_BUILD = "40fe96e6b860dcdd5a9a060eac86b30698e64e377f1d2c4d9e243308cb2a6bf9";
3
+ export declare const DIAGNOSTIC_BUILD = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
4
4
  export interface Receipt {
5
5
  id: string;
6
6
  build: string;
@@ -2,3 +2,8 @@ import type { SessionEntry, SessionHeader } from "@earendil-works/pi-coding-agen
2
2
  import type { TranscriptRecord } from "./tuck/core/transcript.js";
3
3
  /** Whole successful text reads, newest result first. Mutations invalidate earlier calls even when they fail or have no result. */
4
4
  export declare function keptReadCandidates(entries: readonly (SessionEntry | SessionHeader)[], indices: ReadonlyMap<string, number>, resolvable: (entry: SessionEntry) => boolean, exclude?: ReadonlySet<string>): TranscriptRecord[];
5
+ /** At most this many outputs, newest first, holding at most this much output text in all; the rest is cut with a pointer. */
6
+ export declare const MAX_PROMPT_OUTPUTS = 4, MAX_PROMPT_OUTPUT_CHARACTERS = 8000;
7
+ /** The output of a command a user prompt names ("New telex. Run: telex read NAME"), from the first response after that prompt, newest
8
+ * first. A message-driven agent receives its tasks this way, as tool results, so these stay whole while older observations go. */
9
+ export declare function promptOutputCandidates(entries: readonly (SessionEntry | SessionHeader)[], indices: ReadonlyMap<string, number>, resolvable: (entry: SessionEntry) => boolean): TranscriptRecord[];
@@ -1,5 +1,6 @@
1
1
  import { classifyBash } from "./bash-command.js";
2
2
  import { pathKey } from "./path-key.js";
3
+ import { isDiscardedResponse } from "./protocol.js";
3
4
  import { isTextOnly, textOf } from "./tuck/core/content.js";
4
5
  import { extractPath } from "./tuck/core/tool-args.js";
5
6
  /** Whole successful text reads, newest result first. Mutations invalidate earlier calls even when they fail or have no result. */
@@ -65,3 +66,53 @@ export function keptReadCandidates(entries, indices, resolvable, exclude = new S
65
66
  }
66
67
  return records;
67
68
  }
69
+ /** At most this many outputs, newest first, holding at most this much output text in all; the rest is cut with a pointer. */
70
+ export const MAX_PROMPT_OUTPUTS = 4, MAX_PROMPT_OUTPUT_CHARACTERS = 8000;
71
+ const words = (text) => text.replace(/\s+/gu, " ").trim();
72
+ /** The output of a command a user prompt names ("New telex. Run: telex read NAME"), from the first response after that prompt, newest
73
+ * first. A message-driven agent receives its tasks this way, as tool results, so these stay whole while older observations go. */
74
+ export function promptOutputCandidates(entries, indices, resolvable) {
75
+ const results = new Map(), named = new Map();
76
+ let prompt;
77
+ for (const entry of entries) {
78
+ if (entry.type !== "message")
79
+ continue;
80
+ const message = entry.message;
81
+ if (message.role === "user") {
82
+ prompt = words(textOf(message.content));
83
+ continue;
84
+ }
85
+ if (message.role === "toolResult") {
86
+ results.set(message.toolCallId, entry);
87
+ continue;
88
+ }
89
+ if (message.role !== "assistant" || prompt === undefined || isDiscardedResponse(message))
90
+ continue;
91
+ for (const block of message.content) {
92
+ if (block.type !== "toolCall" || block.name !== "bash" || typeof block.arguments?.command !== "string")
93
+ continue;
94
+ const command = block.arguments.command, lead = words(command.split(/[|;&<>]|\d>/u)[0]);
95
+ if (lead.includes(" ") && prompt.includes(lead))
96
+ named.set(block.id, command);
97
+ }
98
+ prompt = undefined;
99
+ }
100
+ const records = [];
101
+ let room = MAX_PROMPT_OUTPUT_CHARACTERS;
102
+ for (const [id, command] of [...named].reverse()) {
103
+ const entry = results.get(id), sourceIndex = entry && indices.get(entry.id);
104
+ if (entry?.type !== "message" || entry.message.role !== "toolResult" || entry.message.isError || !isTextOnly(entry.message.content) ||
105
+ sourceIndex === undefined || !resolvable(entry))
106
+ continue;
107
+ const text = textOf(entry.message.content);
108
+ if (!text.length)
109
+ continue;
110
+ const kept = text.length <= room ? text : `${text.slice(0, room)}\n… (truncated; whole output: tuck_recall {"index":${sourceIndex}})`;
111
+ records.push({ kind: "section", title: "Kept-prompt-output", sourceIndex,
112
+ text: `bash ${words(command)} (run as a user prompt asked; output as recorded at #${sourceIndex}):\n${kept}` });
113
+ room -= Math.min(room, text.length);
114
+ if (!room || records.length === MAX_PROMPT_OUTPUTS)
115
+ break;
116
+ }
117
+ return records;
118
+ }
package/dist/src/tuck.js CHANGED
@@ -7,7 +7,7 @@ import { carriedTailTokens, carriedTarget, conversationTokens } from "./budget.j
7
7
  import { omissionRecord, userPrefixRecords } from "./tuck/core/brief.js";
8
8
  import { isTextOnly, textOf } from "./tuck/core/content.js";
9
9
  import { MAX_ACTION_LINES, MAX_LEDGER_LINES, actionItems, actionRecords, ledgerItems, ledgerRecords } from "./ledger.js";
10
- import { keptReadCandidates } from "./kept-reads.js";
10
+ import { keptReadCandidates, promptOutputCandidates } from "./kept-reads.js";
11
11
  import { workingSetCandidates } from "./working-set.js";
12
12
  import { keptSearchCandidates } from "./kept-searches.js";
13
13
  import { fileObservations, thinkingRecords } from "./content-observations.js";
@@ -580,10 +580,10 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
580
580
  const keptResultCap = Math.min(Math.floor(0.20 * maxSummaryCharacters), 24000);
581
581
  const counts = new Map();
582
582
  const prefix = [header, ...entries.slice(0, boundary)];
583
- // Reads and searches share the lead rank, newest result first, and one
584
- // allowance. Keep L2's independent four-item caps and whole-item skips.
585
- const candidates = [...keptReadCandidates(prefix, indices, resolvable, carriedKeys), ...keptSearchCandidates(prefix, indices, resolvable)]
586
- .sort((a, b) => b.sourceIndex - a.sourceIndex || Number(a.title === "Kept-search") - Number(b.title === "Kept-search"));
583
+ // Outputs a user prompt asked for lead (a message-driven agent's tasks); reads and searches follow, newest result first. One
584
+ // allowance; L2's independent four-item caps and whole-item skips.
585
+ const candidates = [...promptOutputCandidates(prefix, indices, resolvable), ...[...keptReadCandidates(prefix, indices, resolvable, carriedKeys), ...keptSearchCandidates(prefix, indices, resolvable)]
586
+ .sort((a, b) => b.sourceIndex - a.sourceIndex || Number(a.title === "Kept-search") - Number(b.title === "Kept-search"))];
587
587
  for (const record of candidates) {
588
588
  if ((counts.get(record.title) ?? 0) === 4)
589
589
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-tuck",
3
- "version": "1.10.2",
3
+ "version": "1.10.3",
4
4
  "description": "Deterministic compaction for Pi with no model call, plus exact recall of earlier history.",
5
5
  "keywords": [
6
6
  "pi-package",
package/src/build-id.ts CHANGED
@@ -1 +1 @@
1
- export const BUILD_ID = "40fe96e6b860dcdd5a9a060eac86b30698e64e377f1d2c4d9e243308cb2a6bf9";
1
+ export const BUILD_ID = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
package/src/kept-reads.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { SessionEntry, SessionHeader } from "@earendil-works/pi-coding-agent";
2
2
  import { classifyBash } from "./bash-command";
3
3
  import { pathKey } from "./path-key";
4
+ import { isDiscardedResponse } from "./protocol";
4
5
  import { isTextOnly, textOf } from "./tuck/core/content";
5
6
  import { extractPath } from "./tuck/core/tool-args";
6
7
  import type { TranscriptRecord } from "./tuck/core/transcript";
@@ -51,3 +52,42 @@ export function keptReadCandidates(entries: readonly (SessionEntry | SessionHead
51
52
  }
52
53
  return records;
53
54
  }
55
+
56
+ /** At most this many outputs, newest first, holding at most this much output text in all; the rest is cut with a pointer. */
57
+ export const MAX_PROMPT_OUTPUTS = 4, MAX_PROMPT_OUTPUT_CHARACTERS = 8000;
58
+ const words = (text: string) => text.replace(/\s+/gu, " ").trim();
59
+ /** The output of a command a user prompt names ("New telex. Run: telex read NAME"), from the first response after that prompt, newest
60
+ * first. A message-driven agent receives its tasks this way, as tool results, so these stay whole while older observations go. */
61
+ export function promptOutputCandidates(entries: readonly (SessionEntry | SessionHeader)[], indices: ReadonlyMap<string, number>,
62
+ resolvable: (entry: SessionEntry) => boolean): TranscriptRecord[] {
63
+ const results = new Map<string, SessionEntry>(), named = new Map<string, string>();
64
+ let prompt: string | undefined;
65
+ for (const entry of entries) {
66
+ if (entry.type !== "message") continue;
67
+ const message = entry.message;
68
+ if (message.role === "user") { prompt = words(textOf(message.content)); continue; }
69
+ if (message.role === "toolResult") { results.set(message.toolCallId, entry); continue; }
70
+ if (message.role !== "assistant" || prompt === undefined || isDiscardedResponse(message)) continue;
71
+ for (const block of message.content) {
72
+ if (block.type !== "toolCall" || block.name !== "bash" || typeof (block.arguments as { command?: unknown })?.command !== "string") continue;
73
+ const command = (block.arguments as { command: string }).command, lead = words(command.split(/[|;&<>]|\d>/u)[0]!);
74
+ if (lead.includes(" ") && prompt.includes(lead)) named.set(block.id, command);
75
+ }
76
+ prompt = undefined;
77
+ }
78
+ const records: TranscriptRecord[] = [];
79
+ let room = MAX_PROMPT_OUTPUT_CHARACTERS;
80
+ for (const [id, command] of [...named].reverse()) {
81
+ const entry = results.get(id), sourceIndex = entry && indices.get(entry.id);
82
+ if (entry?.type !== "message" || entry.message.role !== "toolResult" || entry.message.isError || !isTextOnly(entry.message.content) ||
83
+ sourceIndex === undefined || !resolvable(entry)) continue;
84
+ const text = textOf(entry.message.content);
85
+ if (!text.length) continue;
86
+ const kept = text.length <= room ? text : `${text.slice(0, room)}\n… (truncated; whole output: tuck_recall {"index":${sourceIndex}})`;
87
+ records.push({ kind: "section", title: "Kept-prompt-output", sourceIndex,
88
+ text: `bash ${words(command)} (run as a user prompt asked; output as recorded at #${sourceIndex}):\n${kept}` });
89
+ room -= Math.min(room, text.length);
90
+ if (!room || records.length === MAX_PROMPT_OUTPUTS) break;
91
+ }
92
+ return records;
93
+ }
package/src/tuck.ts CHANGED
@@ -7,7 +7,7 @@ import { carriedTailTokens, carriedTarget, conversationTokens } from "./budget";
7
7
  import { omissionRecord, userPrefixRecords } from "./tuck/core/brief";
8
8
  import { isTextOnly, textOf } from "./tuck/core/content";
9
9
  import { MAX_ACTION_LINES, MAX_LEDGER_LINES, actionItems, actionRecords, ledgerItems, ledgerRecords } from "./ledger.js";
10
- import { keptReadCandidates } from "./kept-reads.js";
10
+ import { keptReadCandidates, promptOutputCandidates } from "./kept-reads.js";
11
11
  import { workingSetCandidates, type WorkingFile } from "./working-set.js";
12
12
  import { keptSearchCandidates } from "./kept-searches.js";
13
13
  import { fileObservations, thinkingRecords } from "./content-observations";
@@ -537,10 +537,10 @@ export function tuckObservedDraft(tuck: Tuck, input: { branchEntries: SessionEnt
537
537
  const keptResultCap = Math.min(Math.floor(0.20 * maxSummaryCharacters), 24000);
538
538
  const counts = new Map<string, number>();
539
539
  const prefix = [header, ...entries.slice(0, boundary)];
540
- // Reads and searches share the lead rank, newest result first, and one
541
- // allowance. Keep L2's independent four-item caps and whole-item skips.
542
- const candidates = [...keptReadCandidates(prefix, indices, resolvable, carriedKeys), ...keptSearchCandidates(prefix, indices, resolvable)]
543
- .sort((a, b) => b.sourceIndex! - a.sourceIndex! || Number(a.title === "Kept-search") - Number(b.title === "Kept-search"));
540
+ // Outputs a user prompt asked for lead (a message-driven agent's tasks); reads and searches follow, newest result first. One
541
+ // allowance; L2's independent four-item caps and whole-item skips.
542
+ const candidates = [...promptOutputCandidates(prefix, indices, resolvable), ...[...keptReadCandidates(prefix, indices, resolvable, carriedKeys), ...keptSearchCandidates(prefix, indices, resolvable)]
543
+ .sort((a, b) => b.sourceIndex! - a.sourceIndex! || Number(a.title === "Kept-search") - Number(b.title === "Kept-search"))];
544
544
  for (const record of candidates) {
545
545
  if ((counts.get(record.title!) ?? 0) === 4) continue;
546
546
  const extra = lineCost([record]);