pi-tuck 1.12.0 → 1.12.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.
- package/CHANGELOG.md +9 -0
- package/README.md +1 -1
- package/dist/src/build-id.d.ts +1 -1
- package/dist/src/build-id.js +1 -1
- package/dist/src/clip.d.ts +6 -0
- package/dist/src/clip.js +6 -4
- package/dist/src/tuck.d.ts +2 -0
- package/dist/src/tuck.js +13 -4
- package/package.json +1 -1
- package/src/build-id.ts +1 -1
- package/src/clip.ts +6 -3
- package/src/tuck.ts +13 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
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.12.1]
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- The first user turn (the task statement) rides whole in every summary, the smallest one after a length retry included, so an
|
|
11
|
+
instruction past its opening line is no longer cut off after a few chained cuts. A first turn over 8,000 characters keeps its first
|
|
12
|
+
and last 4,000, with a `tuck_recall` locator for the rest. Below a 64k-token room the cap is one character per 8 tokens of room, so
|
|
13
|
+
a small window keeps room to cut.
|
|
14
|
+
|
|
6
15
|
## [1.12.0]
|
|
7
16
|
|
|
8
17
|
### Changed
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ 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.12.
|
|
15
|
+
This README describes pi-tuck 1.12.1. To pin a published release, use a versioned source such as `pi install npm:pi-tuck@1.12.1` or `pi install git:github.com/galyavin/pi-tuck@v1.12.1`. To uninstall, run `pi remove` with the source you installed.
|
|
16
16
|
|
|
17
17
|
## Compaction and recall
|
|
18
18
|
|
package/dist/src/build-id.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const BUILD_ID = "
|
|
1
|
+
export declare const BUILD_ID = "ac0f5521dbcebddc66d89232ea3f21b9a914f51fa4ed281af9e9993f786b877e";
|
package/dist/src/build-id.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BUILD_ID = "
|
|
1
|
+
export const BUILD_ID = "ac0f5521dbcebddc66d89232ea3f21b9a914f51fa4ed281af9e9993f786b877e";
|
package/dist/src/clip.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export interface Clip {
|
|
|
4
4
|
toolCallId: string;
|
|
5
5
|
content: ToolResultMessage["content"];
|
|
6
6
|
}
|
|
7
|
+
/** `keep` characters of the text, half head and half tail, with where the rest is: the `tuck_recall` locator plus the offset the gap starts at. */
|
|
8
|
+
export declare const clipText: (text: string, keep: number, locator: {
|
|
9
|
+
entryId: string;
|
|
10
|
+
} | {
|
|
11
|
+
index: number;
|
|
12
|
+
}) => string;
|
|
7
13
|
/** The budgets to offer a fresh round the room cannot hold whole, in the units the round and the mandatory input are counted in, tried in order.
|
|
8
14
|
* The room is the provider's, so it is divided by the factor the provider's counts have been running at - the same conversion the planner's own
|
|
9
15
|
* reserve makes (budget.ts) - before the input no cut can remove is taken out; counting the provider's room against an estimate asks the round for
|
package/dist/src/clip.js
CHANGED
|
@@ -3,12 +3,14 @@ import { MAX_RECALL_CHARACTERS } from "./recall.js";
|
|
|
3
3
|
/** The text `tuck_recall {entryId, offset}` reads from a text-only result; any other result is not clipped. */
|
|
4
4
|
const textOf = (message) => message.content.every(block => block.type === "text")
|
|
5
5
|
? message.content.map(block => block.type === "text" ? block.text : "").join("\n") : undefined;
|
|
6
|
-
|
|
6
|
+
/** `keep` characters of the text, half head and half tail, with where the rest is: the `tuck_recall` locator plus the offset the gap starts at. */
|
|
7
|
+
export const clipText = (text, keep, locator) => {
|
|
7
8
|
const head = Math.ceil(keep / 2), tail = keep - head;
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
return text.slice(0, head) +
|
|
10
|
+
`\n[pi-tuck: characters ${head}-${text.length - tail} of ${text.length} are not shown, to fit the context window; read them with ` +
|
|
11
|
+
`tuck_recall ${JSON.stringify({ ...locator, offset: head })}, up to ${MAX_RECALL_CHARACTERS} characters a call]\n` + text.slice(text.length - tail);
|
|
11
12
|
};
|
|
13
|
+
const clipped = (text, keep, entryId) => [{ type: "text", text: clipText(text, keep, { entryId }) }];
|
|
12
14
|
/** The budgets to offer a fresh round the room cannot hold whole, in the units the round and the mandatory input are counted in, tried in order.
|
|
13
15
|
* The room is the provider's, so it is divided by the factor the provider's counts have been running at - the same conversion the planner's own
|
|
14
16
|
* reserve makes (budget.ts) - before the input no cut can remove is taken out; counting the provider's room against an estimate asks the round for
|
package/dist/src/tuck.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface RecallContinuation {
|
|
|
34
34
|
export declare const MAX_RANKED_RESPONSE_CHARACTERS = 16000;
|
|
35
35
|
/** The share of the summary's own allowance (beyond protected prompts) that the working set may take. */
|
|
36
36
|
export declare const WORKING_SET_SHARE: number;
|
|
37
|
+
/** The first user turn (the task statement) rides whole in every summary up to this many characters, and no more characters than an eighth of the room's tokens (rooms below 64k); a longer one keeps its head and tail (1.12.1). */
|
|
38
|
+
export declare const FIRST_TURN_CHARACTERS = 8000;
|
|
37
39
|
/** Deliberately narrow contract with the pinned pi-tuck source exports. No standalone hooks are installed. */
|
|
38
40
|
export interface Tuck {
|
|
39
41
|
buildOwnCut(entries: SessionEntry[], keep: number): Cut;
|
package/dist/src/tuck.js
CHANGED
|
@@ -10,6 +10,7 @@ import { MAX_ACTION_LINES, MAX_LEDGER_LINES, actionItems, actionRecords, ledgerI
|
|
|
10
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
|
+
import { clipText } from "./clip.js";
|
|
13
14
|
import { fileObservations, thinkingRecords } from "./content-observations.js";
|
|
14
15
|
import { pathKey } from "./path-key.js";
|
|
15
16
|
import { convertToLlm, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
@@ -18,6 +19,8 @@ import { ATTEMPT_NOTICE, createRecall } from "./recall.js";
|
|
|
18
19
|
export const MAX_RANKED_RESPONSE_CHARACTERS = 16000;
|
|
19
20
|
/** The share of the summary's own allowance (beyond protected prompts) that the working set may take. */
|
|
20
21
|
export const WORKING_SET_SHARE = 2 / 3;
|
|
22
|
+
/** The first user turn (the task statement) rides whole in every summary up to this many characters, and no more characters than an eighth of the room's tokens (rooms below 64k); a longer one keeps its head and tail (1.12.1). */
|
|
23
|
+
export const FIRST_TURN_CHARACTERS = 8_000;
|
|
21
24
|
import { buildOwnCut, applyTailBudget, MAX_TAIL_TOKENS, OVERSIZED_TAIL_FACTOR } from "./tuck/cut.js";
|
|
22
25
|
import { calibrateCharsPerToken, estimateSourceMessageChars } from "./tuck/core/token-estimate.js";
|
|
23
26
|
import { buildGlobalIndexById } from "./tuck/core/global-indices.js";
|
|
@@ -162,6 +165,8 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
162
165
|
throw new Error("Missing native session header");
|
|
163
166
|
const before = measure(projected.messages), room = Math.max(0, model.contextWindow - reserveTokens - 1);
|
|
164
167
|
const minimumOpeningLength = 80, openingLength = Math.max(80, Math.floor(Math.sqrt(room * 4)));
|
|
168
|
+
// At most about a thirty-second of the room in tokens, so a small window keeps its cut room (1.12.1).
|
|
169
|
+
const firstTurnCap = Math.min(FIRST_TURN_CHARACTERS, Math.floor(room / 8));
|
|
165
170
|
const positions = new Map(entries.map((entry, at) => [entry.id, at]));
|
|
166
171
|
const originals = tuck.buildOwnCut(entries.filter(entry => entry.type !== "compaction"), 0);
|
|
167
172
|
if (!originals.ok)
|
|
@@ -259,6 +264,7 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
259
264
|
list.forEach((unit, at) => count[at + 1] = count[at] + unit.count);
|
|
260
265
|
return [role, { end, count }];
|
|
261
266
|
}));
|
|
267
|
+
const shorter = (a, b) => a.length < b.length ? a : b;
|
|
262
268
|
const quoteCache = new Map();
|
|
263
269
|
const quote = (entry, take) => {
|
|
264
270
|
const key = `${entry.id}:${take}`;
|
|
@@ -269,11 +275,14 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
269
275
|
const text = entry.type === "custom_message" ? textOf(entry.content) : entry.type === "message" && entry.message.role === "user" ? textOf(entry.message.content) : "";
|
|
270
276
|
const sourceTimes = index === undefined ? undefined : [{ sourceIndex: index, ...resolveSourceTime(entry) }];
|
|
271
277
|
// Custom entries have a native identity but no global message index.
|
|
272
|
-
|
|
273
|
-
|
|
278
|
+
// The first user turn as an anchor: whole up to its cap, else its head and tail (1.12.1). A protected input stays whole.
|
|
279
|
+
const firstTurn = entry.id === firstUser?.id && take === firstTurnCap;
|
|
280
|
+
const records = index === undefined && entry.type !== "custom_message" ? [] : take === Infinity || firstTurn
|
|
281
|
+
? [{ kind: "excerpt", role: entry.type === "custom_message" ? "custom" : "user", ...(index === undefined ? {} : { sourceIndex: index }),
|
|
282
|
+
text: firstTurn && text.length > take ? shorter(clipText(text, take, { index: index }), text) : text, sourceTimes,
|
|
274
283
|
...(entry.type === "custom_message" ? { sourceEntryId: entry.id } : {}) }]
|
|
275
284
|
: userPrefixRecords({ kind: "user", text, originalText: text, startsSource: true, sourceIndex: index }, undefined, take).map(record => ({ ...record, sourceTimes }));
|
|
276
|
-
cached = { records, cost: lineCost(records), whole: take >= text.length };
|
|
285
|
+
cached = { records, cost: lineCost(records), whole: take >= text.length || firstTurn && records[0]?.text === text };
|
|
277
286
|
quoteCache.set(key, cached);
|
|
278
287
|
return cached;
|
|
279
288
|
};
|
|
@@ -296,7 +305,7 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
296
305
|
add(current, Infinity);
|
|
297
306
|
for (const entry of anchors)
|
|
298
307
|
if (entry.id !== latest?.id && entry.id !== current?.id && positions.get(entry.id) < boundary)
|
|
299
|
-
add(entry, length);
|
|
308
|
+
add(entry, entry.id === firstUser?.id ? firstTurnCap : length);
|
|
300
309
|
const omissions = [];
|
|
301
310
|
for (const role of ["user", "assistant", "toolResult"]) {
|
|
302
311
|
const list = units[role], prefix = prefixes[role];
|
package/package.json
CHANGED
package/src/build-id.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BUILD_ID = "
|
|
1
|
+
export const BUILD_ID = "ac0f5521dbcebddc66d89232ea3f21b9a914f51fa4ed281af9e9993f786b877e";
|
package/src/clip.ts
CHANGED
|
@@ -9,13 +9,16 @@ export interface Clip { toolCallId: string; content: ToolResultMessage["content"
|
|
|
9
9
|
const textOf = (message: ToolResultMessage) => message.content.every(block => block.type === "text")
|
|
10
10
|
? message.content.map(block => block.type === "text" ? block.text : "").join("\n") : undefined;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/** `keep` characters of the text, half head and half tail, with where the rest is: the `tuck_recall` locator plus the offset the gap starts at. */
|
|
13
|
+
export const clipText = (text: string, keep: number, locator: { entryId: string } | { index: number }): string => {
|
|
13
14
|
const head = Math.ceil(keep / 2), tail = keep - head;
|
|
14
|
-
return
|
|
15
|
+
return text.slice(0, head) +
|
|
15
16
|
`\n[pi-tuck: characters ${head}-${text.length - tail} of ${text.length} are not shown, to fit the context window; read them with ` +
|
|
16
|
-
`tuck_recall
|
|
17
|
+
`tuck_recall ${JSON.stringify({ ...locator, offset: head })}, up to ${MAX_RECALL_CHARACTERS} characters a call]\n` + text.slice(text.length - tail);
|
|
17
18
|
};
|
|
18
19
|
|
|
20
|
+
const clipped = (text: string, keep: number, entryId: string): ToolResultMessage["content"] => [{ type: "text", text: clipText(text, keep, { entryId }) }];
|
|
21
|
+
|
|
19
22
|
/** The budgets to offer a fresh round the room cannot hold whole, in the units the round and the mandatory input are counted in, tried in order.
|
|
20
23
|
* The room is the provider's, so it is divided by the factor the provider's counts have been running at - the same conversion the planner's own
|
|
21
24
|
* reserve makes (budget.ts) - before the input no cut can remove is taken out; counting the provider's room against an estimate asks the round for
|
package/src/tuck.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { MAX_ACTION_LINES, MAX_LEDGER_LINES, actionItems, actionRecords, ledgerI
|
|
|
10
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
|
+
import { clipText } from "./clip.js";
|
|
13
14
|
import { fileObservations, thinkingRecords } from "./content-observations";
|
|
14
15
|
import { pathKey } from "./path-key";
|
|
15
16
|
import { convertToLlm, SessionManager, type ExtensionContext,
|
|
@@ -34,6 +35,8 @@ export interface RecallContinuation { query: string; throughEntryId: string; off
|
|
|
34
35
|
export const MAX_RANKED_RESPONSE_CHARACTERS = 16000;
|
|
35
36
|
/** The share of the summary's own allowance (beyond protected prompts) that the working set may take. */
|
|
36
37
|
export const WORKING_SET_SHARE = 2 / 3;
|
|
38
|
+
/** The first user turn (the task statement) rides whole in every summary up to this many characters, and no more characters than an eighth of the room's tokens (rooms below 64k); a longer one keeps its head and tail (1.12.1). */
|
|
39
|
+
export const FIRST_TURN_CHARACTERS = 8_000;
|
|
37
40
|
/** Deliberately narrow contract with the pinned pi-tuck source exports. No standalone hooks are installed. */
|
|
38
41
|
export interface Tuck {
|
|
39
42
|
buildOwnCut(entries: SessionEntry[], keep: number): Cut;
|
|
@@ -181,6 +184,8 @@ export function tuckObservedDraft(tuck: Tuck, input: { branchEntries: SessionEnt
|
|
|
181
184
|
if (!header) throw new Error("Missing native session header");
|
|
182
185
|
const before = measure(projected.messages), room = Math.max(0, model.contextWindow - reserveTokens - 1);
|
|
183
186
|
const minimumOpeningLength = 80, openingLength = Math.max(80, Math.floor(Math.sqrt(room * 4)));
|
|
187
|
+
// At most about a thirty-second of the room in tokens, so a small window keeps its cut room (1.12.1).
|
|
188
|
+
const firstTurnCap = Math.min(FIRST_TURN_CHARACTERS, Math.floor(room / 8));
|
|
184
189
|
const positions = new Map(entries.map((entry, at) => [entry.id, at]));
|
|
185
190
|
const originals = tuck.buildOwnCut(entries.filter(entry => entry.type !== "compaction"), 0);
|
|
186
191
|
if (!originals.ok) return { unavailable: "No eligible original prefix to compile" };
|
|
@@ -263,6 +268,7 @@ export function tuckObservedDraft(tuck: Tuck, input: { branchEntries: SessionEnt
|
|
|
263
268
|
list.forEach((unit, at) => count[at + 1] = count[at]! + unit.count);
|
|
264
269
|
return [role, { end, count }];
|
|
265
270
|
})) as Record<keyof typeof units, { end: Int32Array; count: Int32Array }>;
|
|
271
|
+
const shorter = (a: string, b: string) => a.length < b.length ? a : b;
|
|
266
272
|
const quoteCache = new Map<string, { records: TranscriptRecord[]; cost: number; whole: boolean }>();
|
|
267
273
|
const quote = (entry: SessionEntry, take: number) => {
|
|
268
274
|
const key = `${entry.id}:${take}`;
|
|
@@ -272,11 +278,14 @@ export function tuckObservedDraft(tuck: Tuck, input: { branchEntries: SessionEnt
|
|
|
272
278
|
const text = entry.type === "custom_message" ? textOf(entry.content) : entry.type === "message" && entry.message.role === "user" ? textOf(entry.message.content) : "";
|
|
273
279
|
const sourceTimes = index === undefined ? undefined : [{ sourceIndex: index, ...resolveSourceTime(entry) }];
|
|
274
280
|
// Custom entries have a native identity but no global message index.
|
|
275
|
-
|
|
276
|
-
|
|
281
|
+
// The first user turn as an anchor: whole up to its cap, else its head and tail (1.12.1). A protected input stays whole.
|
|
282
|
+
const firstTurn = entry.id === firstUser?.id && take === firstTurnCap;
|
|
283
|
+
const records: TranscriptRecord[] = index === undefined && entry.type !== "custom_message" ? [] : take === Infinity || firstTurn
|
|
284
|
+
? [{ kind: "excerpt", role: entry.type === "custom_message" ? "custom" : "user", ...(index === undefined ? {} : { sourceIndex: index }),
|
|
285
|
+
text: firstTurn && text.length > take ? shorter(clipText(text, take, { index: index! }), text) : text, sourceTimes,
|
|
277
286
|
...(entry.type === "custom_message" ? { sourceEntryId: entry.id } : {}) }]
|
|
278
287
|
: userPrefixRecords({ kind: "user", text, originalText: text, startsSource: true, sourceIndex: index }, undefined, take).map(record => ({ ...record, sourceTimes }));
|
|
279
|
-
cached = { records, cost: lineCost(records), whole: take >= text.length };
|
|
288
|
+
cached = { records, cost: lineCost(records), whole: take >= text.length || firstTurn && records[0]?.text === text };
|
|
280
289
|
quoteCache.set(key, cached);
|
|
281
290
|
return cached;
|
|
282
291
|
};
|
|
@@ -290,7 +299,7 @@ export function tuckObservedDraft(tuck: Tuck, input: { branchEntries: SessionEnt
|
|
|
290
299
|
};
|
|
291
300
|
if (latestPosition >= 0 && latestPosition < boundary && latestTextOnly) add(latest!, Infinity);
|
|
292
301
|
if (currentPosition >= 0 && currentPosition < boundary && current?.id !== latest?.id) add(current!, Infinity);
|
|
293
|
-
for (const entry of anchors) if (entry.id !== latest?.id && entry.id !== current?.id && positions.get(entry.id)! < boundary) add(entry, length);
|
|
302
|
+
for (const entry of anchors) if (entry.id !== latest?.id && entry.id !== current?.id && positions.get(entry.id)! < boundary) add(entry, entry.id === firstUser?.id ? firstTurnCap : length);
|
|
294
303
|
const omissions: TranscriptRecord[] = [];
|
|
295
304
|
for (const role of ["user", "assistant", "toolResult"] as const) {
|
|
296
305
|
const list = units[role], prefix = prefixes[role];
|