pi-tuck 1.10.1 → 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 +16 -0
- package/README.md +3 -3
- package/dist/src/budget.d.ts +4 -0
- package/dist/src/budget.js +5 -1
- package/dist/src/build-id.d.ts +1 -1
- package/dist/src/build-id.js +1 -1
- package/dist/src/compaction.js +4 -3
- package/dist/src/diagnostics.d.ts +1 -1
- package/dist/src/kept-reads.d.ts +5 -0
- package/dist/src/kept-reads.js +51 -0
- package/dist/src/tuck.js +5 -5
- package/package.json +1 -1
- package/src/budget.ts +7 -1
- package/src/build-id.ts +1 -1
- package/src/compaction.ts +5 -3
- package/src/kept-reads.ts +40 -0
- package/src/tuck.ts +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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
|
+
|
|
14
|
+
## [1.10.2]
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Lean line: a trim the lean line asks for must now free at least a quarter of the conversation it replaces, or no trim is made. In a long
|
|
19
|
+
session at a large window, a lean trim could keep almost everything (17,590 tokens down to 17,556): the cost of a new summary for no
|
|
20
|
+
room gained. Trims at the default line are unchanged.
|
|
21
|
+
|
|
6
22
|
## [1.10.1]
|
|
7
23
|
|
|
8
24
|
### Fixed
|
package/README.md
CHANGED
|
@@ -12,15 +12,15 @@ 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.
|
|
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
|
|
|
23
|
-
Once a session has trimmed and grown for a few requests, pi-tuck can move its trim point earlier, to the line that balances the cost of a trim (the summary and the re-reads that follow) against the cost of carrying a larger context on every request. At large windows this means more, smaller trims and smaller requests; it never trims later than the default line. Each summary begins with the previous summary's dialogue, unchanged, and adds what was trimmed since, so consecutive summaries share a prefix a provider's prompt cache can serve. `/tuck` names the line in use: the default, the lean line, or native Pi's line.
|
|
23
|
+
Once a session has trimmed and grown for a few requests, pi-tuck can move its trim point earlier, to the line that balances the cost of a trim (the summary and the re-reads that follow) against the cost of carrying a larger context on every request. At large windows this means more, smaller trims and smaller requests; it never trims later than the default line, and a lean trim must free at least a quarter of the conversation it replaces. Each summary begins with the previous summary's dialogue, unchanged, and adds what was trimmed since, so consecutive summaries share a prefix a provider's prompt cache can serve. `/tuck` names the line in use: the default, the lean line, or native Pi's line.
|
|
24
24
|
|
|
25
25
|
When pi-tuck is active, `tuck_recall` becomes available after a cut on the current branch. Use a keyword query to locate a passage.
|
|
26
26
|
|
package/dist/src/budget.d.ts
CHANGED
|
@@ -89,9 +89,13 @@ export type Decision<D extends object = {}> =
|
|
|
89
89
|
capacity: boolean;
|
|
90
90
|
message: string;
|
|
91
91
|
};
|
|
92
|
+
/** The least share of the saved conversation a cut due only at the lean line must free. */
|
|
93
|
+
export declare const LEAN_MIN_FREE = 0.25;
|
|
92
94
|
export interface CutInput<D extends object = {}> {
|
|
93
95
|
/** With no explicit cut point, a cut that isn't due must also free a tenth of the room. */
|
|
94
96
|
usefulOnly?: boolean;
|
|
97
|
+
/** The cut is due only at the lean line: it must free LEAN_MIN_FREE of the saved conversation, or it is no cut. */
|
|
98
|
+
leanDue?: boolean;
|
|
95
99
|
/** Saved conversation, measured by the planner's own function. */
|
|
96
100
|
before: number;
|
|
97
101
|
/** Input that no cut can remove: system part, host input, queued messages, or the incoming prompt. */
|
package/dist/src/budget.js
CHANGED
|
@@ -78,6 +78,8 @@ export const projectedConversationTokens = (messages, ctx, policy) => conversati
|
|
|
78
78
|
export const measurableConversationTokens = (messages, ctx, policy) => conversationTokens(measurableMessages(messages, ctx, policy));
|
|
79
79
|
/** Raw reserve for the cut planner: the window less the raw tokens that fit the target room, plus the input no cut can remove. */
|
|
80
80
|
export const planningReserve = (window, targetRoom, factor, mandatory) => window - Math.floor(targetRoom / factor) + mandatory;
|
|
81
|
+
/** The least share of the saved conversation a cut due only at the lean line must free. */
|
|
82
|
+
export const LEAN_MIN_FREE = 0.25;
|
|
81
83
|
/** Plan the band first at every cut point. An opportunistic cut must land
|
|
82
84
|
* below it and free the existing minimum. A due cut takes a band draft, or
|
|
83
85
|
* falls back to the room only when the band has no draft. Final reduction and
|
|
@@ -87,7 +89,9 @@ export function chooseCut(input) {
|
|
|
87
89
|
const lands = (p) => p.draft && p.after < before && fits(p.after + mandatory, band);
|
|
88
90
|
// A cut no one needs yet must be worth its summary: one that frees under a tenth of the room would trigger again within a round or two.
|
|
89
91
|
// A due cut is not asked: it has to happen.
|
|
90
|
-
|
|
92
|
+
// A cut the lean line asks for must free a quarter of what it replaces; less leaves the context about where it was, at the price of a summary.
|
|
93
|
+
const worthwhile = (p) => !input.opportunistic ||
|
|
94
|
+
(input.leanDue ? before - p.after >= LEAN_MIN_FREE * before : !input.usefulOnly || !fits(10 * (before - p.after), room));
|
|
91
95
|
const preferred = plan("band");
|
|
92
96
|
if (input.opportunistic) {
|
|
93
97
|
if (!lands(preferred) || !worthwhile(preferred))
|
package/dist/src/build-id.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const BUILD_ID = "
|
|
1
|
+
export declare const BUILD_ID = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
|
package/dist/src/build-id.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BUILD_ID = "
|
|
1
|
+
export const BUILD_ID = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
|
package/dist/src/compaction.js
CHANGED
|
@@ -452,6 +452,7 @@ export async function installCompaction(pi, options = {}) {
|
|
|
452
452
|
};
|
|
453
453
|
// A cut the lean line makes due inside the band is sized by that line, not by the tenth-of-the-room rule for opportunistic cuts.
|
|
454
454
|
const usefulOnlyAt = (total, band, lean, ctx) => options.cutAt === undefined && !(lean !== undefined && fits(total, band, ctx));
|
|
455
|
+
const leanDueAt = (total, band, lean, ctx) => options.cutAt === undefined && lean !== undefined && fits(total, band, ctx);
|
|
455
456
|
/** The cut point in tokens, for the operator (`/tuck`, the footer): the band the triggers use, from the same limits. Reads only. */
|
|
456
457
|
const cutPoint = (ctx) => {
|
|
457
458
|
if (!active() || !ctx.model || stateFor(ctx).kind !== "active")
|
|
@@ -718,7 +719,7 @@ export async function installCompaction(pi, options = {}) {
|
|
|
718
719
|
}
|
|
719
720
|
// Pi checks old history before appending a new idle prompt. During an active run/manual cut the latest admitted input stays protected.
|
|
720
721
|
const decide = (targetRoom = room, targetBand = band) => chooseCut({
|
|
721
|
-
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx),
|
|
722
|
+
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), leanDue: leanDueAt(before + mandatory, targetBand, lean, ctx),
|
|
722
723
|
opportunistic: thresholdOpportunistic,
|
|
723
724
|
unreduced: "Compaction did not reduce context within the estimated request budget",
|
|
724
725
|
plan: (target) => {
|
|
@@ -890,7 +891,7 @@ export async function installCompaction(pi, options = {}) {
|
|
|
890
891
|
return;
|
|
891
892
|
const previousSummary = saved.find(message => message.role === "compactionSummary")?.summary;
|
|
892
893
|
const decide = (targetRoom, targetBand, opportunistic) => chooseCut({
|
|
893
|
-
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), opportunistic,
|
|
894
|
+
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), leanDue: leanDueAt(before + mandatory, targetBand, lean, ctx), opportunistic,
|
|
894
895
|
unreduced: "Incoming prompt compaction did not reduce context within the estimated request budget",
|
|
895
896
|
plan: (target) => {
|
|
896
897
|
const reserve = planReserve(target, targetRoom, targetBand, mandatory, ctx);
|
|
@@ -1044,7 +1045,7 @@ export async function installCompaction(pi, options = {}) {
|
|
|
1044
1045
|
if (gate.kind !== "plan")
|
|
1045
1046
|
return gate;
|
|
1046
1047
|
return chooseCut({
|
|
1047
|
-
opportunistic: gate.opportunistic, mandatory, before, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx),
|
|
1048
|
+
opportunistic: gate.opportunistic, mandatory, before, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), leanDue: leanDueAt(before + mandatory, targetBand, lean, ctx),
|
|
1048
1049
|
unreduced: "Tool-loop preflight compaction did not reduce context within the estimated request budget",
|
|
1049
1050
|
plan: (target) => {
|
|
1050
1051
|
const reserve = planReserve(target, targetRoom, targetBand, mandatory, ctx);
|
|
@@ -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 = "
|
|
3
|
+
export declare const DIAGNOSTIC_BUILD = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
|
|
4
4
|
export interface Receipt {
|
|
5
5
|
id: string;
|
|
6
6
|
build: string;
|
package/dist/src/kept-reads.d.ts
CHANGED
|
@@ -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[];
|
package/dist/src/kept-reads.js
CHANGED
|
@@ -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
|
-
//
|
|
584
|
-
// allowance
|
|
585
|
-
const candidates = [...keptReadCandidates(prefix, indices, resolvable, carriedKeys), ...keptSearchCandidates(prefix, indices, resolvable)]
|
|
586
|
-
|
|
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
package/src/budget.ts
CHANGED
|
@@ -109,9 +109,13 @@ export type Decision<D extends object = {}> =
|
|
|
109
109
|
| { kind: "defer" }
|
|
110
110
|
| { kind: "cut"; target: Target; plan: Extract<Plan<D>, { draft: true }> }
|
|
111
111
|
| { kind: "fault"; capacity: boolean; message: string };
|
|
112
|
+
/** The least share of the saved conversation a cut due only at the lean line must free. */
|
|
113
|
+
export const LEAN_MIN_FREE = 0.25;
|
|
112
114
|
export interface CutInput<D extends object = {}> {
|
|
113
115
|
/** With no explicit cut point, a cut that isn't due must also free a tenth of the room. */
|
|
114
116
|
usefulOnly?: boolean;
|
|
117
|
+
/** The cut is due only at the lean line: it must free LEAN_MIN_FREE of the saved conversation, or it is no cut. */
|
|
118
|
+
leanDue?: boolean;
|
|
115
119
|
/** Saved conversation, measured by the planner's own function. */
|
|
116
120
|
before: number;
|
|
117
121
|
/** Input that no cut can remove: system part, host input, queued messages, or the incoming prompt. */
|
|
@@ -136,7 +140,9 @@ export function chooseCut<D extends object = {}>(input: CutInput<D> & { opportun
|
|
|
136
140
|
const lands = (p: Plan<D>): p is Extract<Plan<D>, { draft: true }> => p.draft && p.after < before && fits(p.after + mandatory, band);
|
|
137
141
|
// A cut no one needs yet must be worth its summary: one that frees under a tenth of the room would trigger again within a round or two.
|
|
138
142
|
// A due cut is not asked: it has to happen.
|
|
139
|
-
|
|
143
|
+
// A cut the lean line asks for must free a quarter of what it replaces; less leaves the context about where it was, at the price of a summary.
|
|
144
|
+
const worthwhile = (p: Extract<Plan<D>, { draft: true }>) => !input.opportunistic ||
|
|
145
|
+
(input.leanDue ? before - p.after >= LEAN_MIN_FREE * before : !input.usefulOnly || !fits(10 * (before - p.after), room));
|
|
140
146
|
const preferred = plan("band");
|
|
141
147
|
if (input.opportunistic) {
|
|
142
148
|
if (!lands(preferred) || !worthwhile(preferred)) return { kind: "none" };
|
package/src/build-id.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BUILD_ID = "
|
|
1
|
+
export const BUILD_ID = "b7162b2a60e8357e1abeb6decc9b739a75077207592f169e6db105b5e2647e90";
|
package/src/compaction.ts
CHANGED
|
@@ -420,6 +420,8 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
|
|
|
420
420
|
// A cut the lean line makes due inside the band is sized by that line, not by the tenth-of-the-room rule for opportunistic cuts.
|
|
421
421
|
const usefulOnlyAt = (total: number, band: number, lean: number | undefined, ctx: ExtensionContext) =>
|
|
422
422
|
options.cutAt === undefined && !(lean !== undefined && fits(total, band, ctx));
|
|
423
|
+
const leanDueAt = (total: number, band: number, lean: number | undefined, ctx: ExtensionContext) =>
|
|
424
|
+
options.cutAt === undefined && lean !== undefined && fits(total, band, ctx);
|
|
423
425
|
/** The cut point in tokens, for the operator (`/tuck`, the footer): the band the triggers use, from the same limits. Reads only. */
|
|
424
426
|
const cutPoint = (ctx: ExtensionContext): number | undefined => {
|
|
425
427
|
if (!active() || !ctx.model || stateFor(ctx).kind !== "active") return undefined;
|
|
@@ -640,7 +642,7 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
|
|
|
640
642
|
}
|
|
641
643
|
// Pi checks old history before appending a new idle prompt. During an active run/manual cut the latest admitted input stays protected.
|
|
642
644
|
const decide = (targetRoom = room, targetBand = band) => chooseCut({
|
|
643
|
-
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx),
|
|
645
|
+
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), leanDue: leanDueAt(before + mandatory, targetBand, lean, ctx),
|
|
644
646
|
opportunistic: thresholdOpportunistic,
|
|
645
647
|
unreduced: "Compaction did not reduce context within the estimated request budget",
|
|
646
648
|
plan: (target): Plan<CutPlan> => {
|
|
@@ -790,7 +792,7 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
|
|
|
790
792
|
if (gate.kind === "none") return;
|
|
791
793
|
const previousSummary = saved.find(message => message.role === "compactionSummary")?.summary;
|
|
792
794
|
const decide = (targetRoom: number, targetBand: number, opportunistic: boolean) => chooseCut({
|
|
793
|
-
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), opportunistic,
|
|
795
|
+
before, mandatory, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), leanDue: leanDueAt(before + mandatory, targetBand, lean, ctx), opportunistic,
|
|
794
796
|
unreduced: "Incoming prompt compaction did not reduce context within the estimated request budget",
|
|
795
797
|
plan: (target): Plan<CutPlan> => {
|
|
796
798
|
const reserve = planReserve(target, targetRoom, targetBand, mandatory, ctx);
|
|
@@ -926,7 +928,7 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
|
|
|
926
928
|
gateCut({ total: before + mandatory, mandatory, room: targetRoom, band: targetBand, trigger: targetBand === band ? triggerLine(ctx, room) : undefined, lean, fits: (tokens, limit) => fits(tokens, limit, ctx) });
|
|
927
929
|
if (gate.kind !== "plan") return gate;
|
|
928
930
|
return chooseCut({
|
|
929
|
-
opportunistic: gate.opportunistic, mandatory, before, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx),
|
|
931
|
+
opportunistic: gate.opportunistic, mandatory, before, room: targetRoom, band: targetBand, fits: (tokens, limit) => fits(tokens, limit, ctx), usefulOnly: usefulOnlyAt(before + mandatory, targetBand, lean, ctx), leanDue: leanDueAt(before + mandatory, targetBand, lean, ctx),
|
|
930
932
|
unreduced: "Tool-loop preflight compaction did not reduce context within the estimated request budget",
|
|
931
933
|
plan: (target): Plan<CutPlan> => {
|
|
932
934
|
const reserve = planReserve(target, targetRoom, targetBand, mandatory, ctx);
|
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
|
-
//
|
|
541
|
-
// allowance
|
|
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]);
|