pi-tuck 1.3.4 → 1.5.0
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 +52 -0
- package/README.md +67 -122
- package/dist/index.d.ts +1 -4
- package/dist/index.js +56 -10
- package/dist/src/budget.d.ts +6 -15
- package/dist/src/budget.js +6 -11
- package/dist/src/build-id.d.ts +1 -1
- package/dist/src/build-id.js +1 -1
- package/dist/src/compaction.d.ts +15 -20
- package/dist/src/compaction.js +236 -204
- package/dist/src/content-observations.d.ts +24 -0
- package/dist/src/content-observations.js +122 -0
- package/dist/src/diagnostics.d.ts +1 -3
- package/dist/src/footer.d.ts +37 -0
- package/dist/src/footer.js +91 -0
- package/dist/src/ledger.d.ts +6 -3
- package/dist/src/ledger.js +14 -7
- package/dist/src/llama-continuation.d.ts +8 -0
- package/dist/src/llama-continuation.js +179 -0
- package/dist/src/recall.js +8 -25
- package/dist/src/request-capacity.d.ts +11 -26
- package/dist/src/request-capacity.js +20 -57
- package/dist/src/run.d.ts +16 -7
- package/dist/src/run.js +53 -25
- package/dist/src/status.d.ts +9 -0
- package/dist/src/status.js +14 -9
- package/dist/src/tuck/core/format.js +1 -1
- package/dist/src/tuck/core/readable-content.d.ts +14 -0
- package/dist/src/tuck/core/readable-content.js +43 -0
- package/dist/src/tuck.d.ts +2 -1
- package/dist/src/tuck.js +92 -30
- package/index.ts +46 -10
- package/package.json +3 -1
- package/src/budget.ts +7 -12
- package/src/build-id.ts +1 -1
- package/src/compaction.ts +228 -194
- package/src/content-observations.ts +115 -0
- package/src/diagnostics.ts +1 -1
- package/src/footer.ts +111 -0
- package/src/ledger.ts +17 -10
- package/src/llama-continuation.ts +176 -0
- package/src/recall.ts +8 -20
- package/src/request-capacity.ts +18 -57
- package/src/run.ts +48 -22
- package/src/status.ts +20 -9
- package/src/tuck/core/format.ts +1 -1
- package/src/tuck/core/readable-content.ts +44 -0
- package/src/tuck.ts +79 -28
package/dist/src/tuck.js
CHANGED
|
@@ -9,6 +9,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
10
|
import { keptReadCandidates } from "./kept-reads.js";
|
|
11
11
|
import { keptSearchCandidates } from "./kept-searches.js";
|
|
12
|
+
import { fileObservations, thinkingRecords } from "./content-observations.js";
|
|
13
|
+
import { pathKey } from "./path-key.js";
|
|
12
14
|
import { convertToLlm, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
13
15
|
import { ATTEMPT_NOTICE, createRecall } from "./recall.js";
|
|
14
16
|
/** Includes JSON escaping, hit metadata and continuation, not just excerpt text. */
|
|
@@ -22,8 +24,9 @@ import { rankRecallRows } from "./tuck/core/search-entries.js";
|
|
|
22
24
|
export const tuck = { buildOwnCut, applyTailBudget, calibrateCharsPerToken, buildGlobalIndexById, compileDialogue, prepareKeywordQuery, rankRecallRows };
|
|
23
25
|
/** Uses pi-tuck's own cut, calibrated maximum tail and dialogue compiler; Pi owns persistence and continuation.
|
|
24
26
|
* `_operatorManual` retains the exported positional slot for existing callers. */
|
|
25
|
-
export function tuckDraft(tuck, event, ctx, reserveTokens, measure, policy = {}, retainCurrentInput = true, _operatorManual = false, newPrompt = false, protectedPromptEntryId) {
|
|
26
|
-
return tuckObservedDraft(tuck, { branchEntries: event.branchEntries, tokensBefore: event.preparation.tokensBefore, previousSummary: event.preparation.previousSummary, newPrompt, protectedPromptEntryId
|
|
27
|
+
export function tuckDraft(tuck, event, ctx, reserveTokens, measure, policy = {}, retainCurrentInput = true, _operatorManual = false, newPrompt = false, protectedPromptEntryId, keepRecentTokens) {
|
|
28
|
+
return tuckObservedDraft(tuck, { branchEntries: event.branchEntries, tokensBefore: event.preparation.tokensBefore, previousSummary: event.preparation.previousSummary, newPrompt, protectedPromptEntryId,
|
|
29
|
+
keepRecentTokens: event.preparation.settings?.keepRecentTokens ?? keepRecentTokens }, ctx, reserveTokens, measure, policy, retainCurrentInput);
|
|
27
30
|
}
|
|
28
31
|
/** Shared compiler observes canonical branch and current token estimate; no native preparation utility. */
|
|
29
32
|
/** `newPrompt`: the cut is planned for a run that has not begun (a prompt Pi has not appended yet, an operator's manual cut, Pi's own cut before
|
|
@@ -339,7 +342,8 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
339
342
|
const fixedRowsCost = preferredHigh.cost + lineCost(preferredLists.records);
|
|
340
343
|
const baseCharacters = frameLength(fixedRowsCost, preferredHigh.rows.length + preferredLists.records.length);
|
|
341
344
|
const base = price(baseCharacters, preferredBoundary);
|
|
342
|
-
|
|
345
|
+
// Cap historical fill at native keep-recent for post-cut headroom parity, preserving the floor and preferred tail.
|
|
346
|
+
const target = Math.min(carriedTarget(model.contextWindow, reserveTokens, base, before), Math.max(base, offset + (input.keepRecentTokens ?? Infinity)));
|
|
343
347
|
// The old tail rule supplies an ordering boundary only. Its recent
|
|
344
348
|
// suffix follows the openings, and is charged to the same total grant.
|
|
345
349
|
const boundaries = [floorBoundary];
|
|
@@ -378,34 +382,19 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
378
382
|
const lists = listsAt(boundary);
|
|
379
383
|
const maxSummaryCharactersAt = (at) => Math.floor((target - offset - nativeAt(at)) * 4) - wrapperCharacters;
|
|
380
384
|
const maxSummaryCharacters = maxSummaryCharactersAt(boundary);
|
|
381
|
-
let
|
|
382
|
-
|
|
383
|
-
const prefix = [header, ...entries.slice(0, boundary)], resolvable = (entry) => readable(entry) !== undefined;
|
|
384
|
-
const candidates = [...keptReadCandidates(prefix, indices, resolvable), ...keptSearchCandidates(prefix, indices, resolvable)]
|
|
385
|
-
.sort((a, b) => b.sourceIndex - a.sourceIndex || Number(a.title === "Kept-search") - Number(b.title === "Kept-search"));
|
|
386
|
-
for (const record of candidates) {
|
|
387
|
-
if ((counts.get(record.title) ?? 0) === 4)
|
|
388
|
-
continue;
|
|
389
|
-
const cost = lineCost([record]);
|
|
390
|
-
if (cost > allowance)
|
|
391
|
-
continue;
|
|
392
|
-
keptResults.push(record);
|
|
393
|
-
allowance -= cost;
|
|
394
|
-
counts.set(record.title, (counts.get(record.title) ?? 0) + 1);
|
|
395
|
-
}
|
|
396
|
-
let ledger = [...lists.records, ...keptResults];
|
|
385
|
+
let ledger = lists.records;
|
|
386
|
+
let listedKeep = Math.max(MAX_LEDGER_LINES, MAX_ACTION_LINES);
|
|
397
387
|
// List caps are existing ranking policy; only the carried target is a
|
|
398
388
|
// spending limit. Candidate list sizes have fixed, cached line prices.
|
|
399
|
-
while (keptResults.length && price(frameLength(protectedView.cost + lineCost(ledger), protectedView.rows.length + ledger.length), boundary) > target) {
|
|
400
|
-
keptResults.pop();
|
|
401
|
-
ledger = [...lists.records, ...keptResults];
|
|
402
|
-
}
|
|
403
389
|
if (price(frameLength(protectedView.cost + lineCost(ledger), protectedView.rows.length + ledger.length), boundary) > target) {
|
|
404
390
|
ledger = [];
|
|
391
|
+
listedKeep = 0;
|
|
405
392
|
for (let keep = 0; keep <= Math.min(Math.max(MAX_LEDGER_LINES, MAX_ACTION_LINES), Math.max(lists.files.length, lists.actions.length)); keep++) {
|
|
406
393
|
const candidate = [...actionRecords(lists.actions, keep), ...ledgerRecords(lists.files, keep)];
|
|
407
|
-
if (price(frameLength(protectedView.cost + lineCost(candidate), protectedView.rows.length + candidate.length), boundary) <= target)
|
|
394
|
+
if (price(frameLength(protectedView.cost + lineCost(candidate), protectedView.rows.length + candidate.length), boundary) <= target) {
|
|
408
395
|
ledger = candidate;
|
|
396
|
+
listedKeep = keep;
|
|
397
|
+
}
|
|
409
398
|
}
|
|
410
399
|
}
|
|
411
400
|
const mandatory = new Set([...protectedView.whole].filter(index => {
|
|
@@ -424,6 +413,7 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
424
413
|
const compiledBoundary = boundary;
|
|
425
414
|
// A protected custom prompt uses its native entry ID in the same anchoring/movement path as indexed user prompts.
|
|
426
415
|
const sourceKey = (record) => current?.type === "custom_message" && record.sourceEntryId === current.id ? current.id : record.sourceIndex;
|
|
416
|
+
const keptResults = [], thinking = [];
|
|
427
417
|
const assemble = (compiled, at = compiledBoundary) => {
|
|
428
418
|
const split = compiled ? splitSummary(compiled) : undefined;
|
|
429
419
|
if (compiled && !split)
|
|
@@ -472,11 +462,82 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
472
462
|
}
|
|
473
463
|
}
|
|
474
464
|
orderByOriginalSource(records, sourceIndices, originals.selectedIds);
|
|
475
|
-
const
|
|
476
|
-
|
|
465
|
+
const thoughtOpenings = thinking.filter(record => !moved.has(record.sourceIndex));
|
|
466
|
+
const summary = render([...records, ...ledger, ...keptResults, ...thoughtOpenings]);
|
|
467
|
+
return { summary, records: [...records, ...thoughtOpenings] };
|
|
477
468
|
};
|
|
478
469
|
const compiled = tuck.compileDialogue(compileInput);
|
|
479
470
|
let offer = assemble(compiled.text);
|
|
471
|
+
// After the complete dialogue fill, observations spend the remaining
|
|
472
|
+
// room before the native tail's older end. The pinned tail is untouched.
|
|
473
|
+
let keptResultCost = 0;
|
|
474
|
+
const keptResultCap = Math.min(Math.floor(0.20 * maxSummaryCharacters), 24000);
|
|
475
|
+
const counts = new Map();
|
|
476
|
+
const prefix = [header, ...entries.slice(0, boundary)], resolvable = (entry) => readable(entry) !== undefined;
|
|
477
|
+
// Reads and searches share the lead rank, newest result first, and one
|
|
478
|
+
// allowance. Keep L2's independent four-item caps and whole-item skips.
|
|
479
|
+
const candidates = [...keptReadCandidates(prefix, indices, resolvable), ...keptSearchCandidates(prefix, indices, resolvable)]
|
|
480
|
+
.sort((a, b) => b.sourceIndex - a.sourceIndex || Number(a.title === "Kept-search") - Number(b.title === "Kept-search"));
|
|
481
|
+
for (const record of candidates) {
|
|
482
|
+
if ((counts.get(record.title) ?? 0) === 4)
|
|
483
|
+
continue;
|
|
484
|
+
const extra = lineCost([record]);
|
|
485
|
+
if (keptResultCost + extra > keptResultCap || price(offer.summary.length + keptResultCost + extra, boundary) > target)
|
|
486
|
+
continue;
|
|
487
|
+
keptResults.push(record);
|
|
488
|
+
keptResultCost += extra;
|
|
489
|
+
counts.set(record.title, (counts.get(record.title) ?? 0) + 1);
|
|
490
|
+
}
|
|
491
|
+
if (keptResults.length)
|
|
492
|
+
offer = assemble(compiled.text, boundary);
|
|
493
|
+
const shownActions = lists.actions.slice(0, Math.min(listedKeep, MAX_ACTION_LINES));
|
|
494
|
+
const shownFiles = lists.files.slice(0, Math.min(listedKeep, MAX_LEDGER_LINES));
|
|
495
|
+
const keptReadPaths = new Set(keptResults.filter(record => record.title === "Kept-read").map(record => {
|
|
496
|
+
const heading = record.text.slice(0, record.text.indexOf("\n"));
|
|
497
|
+
return pathKey(heading.slice(5, heading.lastIndexOf(` (as recorded at #${record.sourceIndex};`)), header.cwd);
|
|
498
|
+
}));
|
|
499
|
+
const filesWithoutKeptReads = shownFiles.filter(item => !keptReadPaths.has(pathKey(item.path, header.cwd)));
|
|
500
|
+
const observations = fileObservations(new Set(filesWithoutKeptReads.map(item => item.path)), entries, indices, failedCalls);
|
|
501
|
+
for (const item of shownFiles)
|
|
502
|
+
item.definitions = observations.get(item.path);
|
|
503
|
+
const outputs = new Set(), definitions = new Set();
|
|
504
|
+
let observationCost = 0;
|
|
505
|
+
const fitsObservation = (extra) => price(offer.summary.length + observationCost + extra, boundary) <= target;
|
|
506
|
+
// Each kind gives way as whole items, oldest first; an oversized newest
|
|
507
|
+
// item cannot promote an older one. Pointer lines need no extra omission.
|
|
508
|
+
for (const item of shownActions) {
|
|
509
|
+
if (!item.outputTail)
|
|
510
|
+
continue;
|
|
511
|
+
const extra = lineCost(actionRecords([item], 1, new Set([item]))) - lineCost(actionRecords([item], 1));
|
|
512
|
+
if (!fitsObservation(extra))
|
|
513
|
+
break;
|
|
514
|
+
outputs.add(item);
|
|
515
|
+
observationCost += extra;
|
|
516
|
+
}
|
|
517
|
+
for (const item of shownFiles) {
|
|
518
|
+
if (!item.definitions)
|
|
519
|
+
continue;
|
|
520
|
+
const extra = lineCost(ledgerRecords([item], 1, new Set([item]))) - lineCost(ledgerRecords([item], 1));
|
|
521
|
+
if (!fitsObservation(extra))
|
|
522
|
+
break;
|
|
523
|
+
definitions.add(item);
|
|
524
|
+
observationCost += extra;
|
|
525
|
+
}
|
|
526
|
+
if (outputs.size || definitions.size) {
|
|
527
|
+
ledger = [...actionRecords(lists.actions, listedKeep, outputs), ...ledgerRecords(lists.files, listedKeep, definitions)];
|
|
528
|
+
offer = assemble(compiled.text, boundary);
|
|
529
|
+
}
|
|
530
|
+
// Plain thinking follows kept reads/searches, output tails and definition maps.
|
|
531
|
+
let thinkingCost = 0;
|
|
532
|
+
for (const record of thinkingRecords(entries.slice(0, boundary), indices, openingLength)) {
|
|
533
|
+
const extra = lineCost([record]);
|
|
534
|
+
if (price(offer.summary.length + thinkingCost + extra, boundary) > target)
|
|
535
|
+
break;
|
|
536
|
+
thinking.push(record);
|
|
537
|
+
thinkingCost += extra;
|
|
538
|
+
}
|
|
539
|
+
if (thinking.length)
|
|
540
|
+
offer = assemble(compiled.text, boundary);
|
|
480
541
|
// Only capacity left after all higher ranks can extend the native tail
|
|
481
542
|
// beyond its preferred rank boundary. No old allocator is consulted.
|
|
482
543
|
const liveStartId = calibration.ok ? calibration.selectedIds[0] : undefined;
|
|
@@ -521,12 +582,13 @@ export function tuckObservedDraft(tuck, input, ctx, reserveTokens, measure, poli
|
|
|
521
582
|
missing.forEach((unit, at) => counts[at + 1] = counts[at] + unit.count);
|
|
522
583
|
return [{ role, missing, ends, counts, cost: lineCost([record]) }];
|
|
523
584
|
});
|
|
524
|
-
const baseCost = lineCost(offer.records) + lineCost(ledger), baseCount = offer.records.length + ledger.length;
|
|
525
|
-
const
|
|
585
|
+
const baseCost = lineCost(offer.records) + lineCost(ledger) + keptResultCost, baseCount = offer.records.length + ledger.length + keptResults.length;
|
|
586
|
+
const keptResultIndices = new Set(keptResults.map(record => record.sourceIndex));
|
|
526
587
|
const lastKeptResultPosition = entries.findLastIndex(entry => keptResultIndices.has(indices.get(entry.id)));
|
|
527
588
|
const extensionPrice = (at) => {
|
|
528
|
-
//
|
|
529
|
-
|
|
589
|
+
// Kept results already spend this extension's price. They stay in
|
|
590
|
+
// the compacted prefix, so the native tail never repeats them.
|
|
591
|
+
if (keptResults.length && at <= lastKeptResultPosition)
|
|
530
592
|
return Infinity;
|
|
531
593
|
let cost = baseCost - (recordCosts[compiledBoundary] - recordCosts[at]);
|
|
532
594
|
let count = baseCount - (recordCounts[compiledBoundary] - recordCounts[at]);
|
package/index.ts
CHANGED
|
@@ -4,16 +4,15 @@ import { join } from "node:path";
|
|
|
4
4
|
import { installCompaction } from "./src/compaction";
|
|
5
5
|
import { validCutAt } from "./src/budget";
|
|
6
6
|
import { notify } from "./src/notify";
|
|
7
|
+
import type { LlamaContinuation } from "./src/llama-continuation";
|
|
7
8
|
import { cleanupLegacyFiles } from "./src/legacy-cleanup";
|
|
9
|
+
import { installFooter } from "./src/footer";
|
|
8
10
|
|
|
9
11
|
export type { CompactionOptions } from "./src/compaction";
|
|
10
12
|
export { installCompaction } from "./src/compaction";
|
|
11
13
|
export { inspectIncident, readableIncident } from "./src/diagnostic-replay.js";
|
|
12
14
|
|
|
13
|
-
/**
|
|
14
|
-
* 1) fixes the cut point as a fraction of the input room; without it, the cut point adapts. */
|
|
15
|
-
/** The oldest Pi with every hook and API pi-tuck uses, and the oldest its tests pass on (Pi 1.2 added the custom message that starts a
|
|
16
|
-
* run to before_agent_start, which the prompt's cut counts). */
|
|
15
|
+
/** Pi 1.2 added the run's custom message to before_agent_start so preflight can count it. */
|
|
17
16
|
export const PI_FLOOR = "1.2.0";
|
|
18
17
|
/** Whether a Pi version is at or above the floor. A version that does not parse is taken as supported. */
|
|
19
18
|
export function piSupported(version: string): boolean {
|
|
@@ -35,24 +34,61 @@ export default async function (pi: ExtensionAPI) {
|
|
|
35
34
|
return;
|
|
36
35
|
}
|
|
37
36
|
const settings = readSettings(join(getAgentDir(), "pi-tuck.json"));
|
|
38
|
-
const handle = await installCompaction(pi, { cutAt: settings.cutAt });
|
|
37
|
+
const handle = await installCompaction(pi, { cutAt: settings.cutAt, cacheSensitiveModels: settings.cacheSensitiveModels, continuationModel: settings.llamaContinuation?.model });
|
|
38
|
+
if (settings.footer !== false) installFooter(pi, ctx => handle.cutPoint(ctx));
|
|
39
|
+
const continuation = settings.llamaContinuation;
|
|
40
|
+
let continuationError: string | undefined;
|
|
41
|
+
if (continuation) {
|
|
42
|
+
try {
|
|
43
|
+
const [{ getApiProvider }, { llamaContinuationStream }] = await Promise.all([
|
|
44
|
+
import("@earendil-works/pi-ai/compat"), import("./src/llama-continuation"),
|
|
45
|
+
]);
|
|
46
|
+
const native = getApiProvider("openai-completions")?.streamSimple;
|
|
47
|
+
if (!native) throw new Error("Pi's Chat Completions provider is unavailable");
|
|
48
|
+
pi.registerProvider(continuation.model.split("/")[0]!, {
|
|
49
|
+
api: "openai-completions",
|
|
50
|
+
streamSimple: llamaContinuationStream(continuation, native),
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
continuationError = `pi-tuck: native continuation unavailable: ${String(error)}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
39
56
|
let said = false;
|
|
40
57
|
pi.on("session_start", async (_event, ctx) => {
|
|
41
58
|
await cleanupLegacyFiles(ctx);
|
|
42
59
|
if (handle.state?.(ctx).kind === "standingDown") return;
|
|
60
|
+
if (continuationError) notify(ctx, continuationError, "warning");
|
|
43
61
|
if (settings.error && !said) {
|
|
44
|
-
said = notify(ctx, `pi-tuck: ${settings.error}
|
|
62
|
+
said = notify(ctx, `pi-tuck: ${settings.error}`, "warning");
|
|
45
63
|
}
|
|
46
64
|
});
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
|
|
67
|
+
type Settings = { cutAt?: number; cacheSensitiveModels?: string[]; llamaContinuation?: LlamaContinuation; footer?: boolean; error?: string };
|
|
68
|
+
const modelRef = (value: unknown) => typeof value === "string" && /^[^/]+\/.+/.test(value);
|
|
69
|
+
function readSettings(path: string): Settings {
|
|
50
70
|
let text: string;
|
|
51
71
|
try { text = readFileSync(path, "utf8"); } catch { return {}; }
|
|
72
|
+
const cutAtHint = `${path} should be a JSON object like {"cutAt": 0.8}, with cutAt a number above 0 and at most 1`;
|
|
52
73
|
try {
|
|
53
74
|
const value = JSON.parse(text);
|
|
54
|
-
if (value && typeof value === "object" &&
|
|
55
|
-
|
|
75
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
76
|
+
const settings: Settings = {};
|
|
77
|
+
const warnings: string[] = [];
|
|
78
|
+
if (value.cutAt === undefined || validCutAt(value.cutAt)) settings.cutAt = value.cutAt;
|
|
79
|
+
else warnings.push(`${cutAtHint}; using the default cut point.`);
|
|
80
|
+
const models = value.cacheSensitiveModels;
|
|
81
|
+
if (Array.isArray(models) && models.every(modelRef)) settings.cacheSensitiveModels = models;
|
|
82
|
+
else if (models !== undefined) warnings.push(`${path} cacheSensitiveModels must be an array of provider/model identifiers; ignoring that setting.`);
|
|
83
|
+
const c = value.llamaContinuation;
|
|
84
|
+
if (c && modelRef(c.model) && Number.isSafeInteger(c.extraTokens) && c.extraTokens > 0 &&
|
|
85
|
+
Number.isSafeInteger(c.deadlineMs) && c.deadlineMs > 0 && c.deadlineMs <= 2_147_483_647) settings.llamaContinuation = c;
|
|
86
|
+
else if (c !== undefined) warnings.push(`${path} llamaContinuation requires a provider/model identifier in model, a positive safe integer extraTokens, and an integer deadlineMs from 1 to 2147483647; native continuation is off.`);
|
|
87
|
+
if (typeof value.footer === "boolean") settings.footer = value.footer;
|
|
88
|
+
else if (value.footer !== undefined) warnings.push(`${path} footer must be true or false; showing pi-tuck's footer.`);
|
|
89
|
+
if (warnings.length) settings.error = warnings.join(" ");
|
|
90
|
+
return settings;
|
|
91
|
+
}
|
|
56
92
|
} catch { /* reported below */ }
|
|
57
|
-
return { error: `${
|
|
93
|
+
return { error: `${cutAtHint}; using the defaults.` };
|
|
58
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-tuck",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Deterministic compaction for Pi with no model call, plus exact recall of earlier history.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -59,11 +59,13 @@
|
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@earendil-works/pi-ai": ">=1.2.0",
|
|
61
61
|
"@earendil-works/pi-coding-agent": ">=1.2.0",
|
|
62
|
+
"@earendil-works/pi-tui": ">=1.2.0",
|
|
62
63
|
"typebox": "*"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@earendil-works/pi-ai": "1.4.0",
|
|
66
67
|
"@earendil-works/pi-coding-agent": "1.4.0",
|
|
68
|
+
"@earendil-works/pi-tui": "1.4.0",
|
|
67
69
|
"@types/node": "24.10.1",
|
|
68
70
|
"typebox": "1.3.27",
|
|
69
71
|
"typescript": "5.9.3",
|
package/src/budget.ts
CHANGED
|
@@ -19,20 +19,15 @@ export interface ToolShape { name: string; description: string; parameters: unkn
|
|
|
19
19
|
export const TRIGGER_MARGIN_FRACTION = 0.02;
|
|
20
20
|
/** Whether `value` is a cut point: a fraction of the room above 0 and at most 1. */
|
|
21
21
|
export const validCutAt = (value: unknown): value is number => typeof value === "number" && value > 0 && value <= 1;
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
/** The initial default cut point: 60% of the room before a usable previous cut. Measured against 1 with paired replays (no answer loss) and billed
|
|
27
|
-
* input under automatic and explicit prompt caching (about 17% less at 128k, 10-14% at 32k). */
|
|
28
|
-
export const DEFAULT_CUT_AT = 0.6;
|
|
29
|
-
/** Preferred native carry, in the planner's estimate: never more than the
|
|
30
|
-
* keep-recent cut offers or the tail amount the adaptive band assumes. */
|
|
22
|
+
/** Trigger at the room for native parity of post-cut headroom. */
|
|
23
|
+
export const DEFAULT_CUT_AT = 1;
|
|
24
|
+
/** Preferred native carry, in the planner's estimate, bounded by the keep-recent offer and the existing tail limit. */
|
|
31
25
|
export const carriedTailTokens = (offeredTokens: number): number => Math.min(offeredTokens, MAX_TAIL_TOKENS / 2);
|
|
32
|
-
|
|
26
|
+
/** The one owner of the band: the trigger and preferred planning limit, capped by the margin. */
|
|
27
|
+
export const bandOf = (room: number, cutAt = DEFAULT_CUT_AT): number => {
|
|
33
28
|
const positive = Math.max(0, room);
|
|
34
29
|
const base = Math.floor(positive * cutAt);
|
|
35
|
-
return Math.min(room - Math.ceil(positive * TRIGGER_MARGIN_FRACTION),
|
|
30
|
+
return Math.min(room - Math.ceil(positive * TRIGGER_MARGIN_FRACTION), base);
|
|
36
31
|
};
|
|
37
32
|
|
|
38
33
|
/** The cut's one carried-context grant, in the planner's estimate. Combines
|
|
@@ -115,7 +110,7 @@ export type Decision<D extends object = {}> =
|
|
|
115
110
|
| { kind: "cut"; target: Target; plan: Extract<Plan<D>, { draft: true }> }
|
|
116
111
|
| { kind: "fault"; capacity: boolean; message: string };
|
|
117
112
|
export interface CutInput<D extends object = {}> {
|
|
118
|
-
/**
|
|
113
|
+
/** With no explicit cut point, a cut that isn't due must also free a tenth of the room. */
|
|
119
114
|
usefulOnly?: boolean;
|
|
120
115
|
/** Saved conversation, measured by the planner's own function. */
|
|
121
116
|
before: number;
|
package/src/build-id.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BUILD_ID = "
|
|
1
|
+
export const BUILD_ID = "afdb81c50c0608b05013bc64aee8a7ff9f4100d7f7e3da9784a7ac789f92aff3";
|