pi-tuck 1.10.5 → 1.11.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 CHANGED
@@ -3,6 +3,16 @@
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.11.0]
7
+
8
+ ### Changed
9
+
10
+ - Act-now turn: on a Chat Completions model, the request that asks the model to act after a thinking-only stop now goes out at the lowest
11
+ thinking effort the server lists (read from its model list at session start; sent top level and in the chat template arguments if Pi sends
12
+ one there) and with at most 20,480 output tokens, above the largest real reply seen on the founder's server. Before, it ran at the
13
+ session's effort and often thought itself into the same stall again. Other requests and other APIs are unchanged. A stop at that
14
+ smaller cap counts as a full-cap stop, so it gets the next act-now turn rather than a length retry.
15
+
6
16
  ## [1.10.5]
7
17
 
8
18
  ### Fixed
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.10.5. To pin a published release, use a versioned source such as `pi install npm:pi-tuck@1.10.5` or `pi install git:github.com/galyavin/pi-tuck@v1.10.5`. To uninstall, run `pi remove` with the source you installed.
15
+ This README describes pi-tuck 1.11.0. To pin a published release, use a versioned source such as `pi install npm:pi-tuck@1.11.0` or `pi install git:github.com/galyavin/pi-tuck@v1.11.0`. To uninstall, run `pi remove` with the source you installed.
16
16
 
17
17
  ## Compaction and recall
18
18
 
@@ -75,7 +75,7 @@ Optional settings go in `pi-tuck.json` in Pi's agent directory (`~/.pi/agent` by
75
75
 
76
76
  ## Output exhaustion and small windows
77
77
 
78
- - Pi-tuck preserves thinking-only stops in session history. At the model's full output allowance, it reports exhaustion if the reply remains unfinished. Below that allowance, it retries once, re-armed as Pi's overflow recovery is. After any length stop on the branch, pi-tuck trims so the next reply gets twice that stop's output (at most `maxTokens` and half the window). When such a stop is not retried, pi-tuck queues one more user turn asking the model to act: "Your last reply used the whole output budget on thinking. Act now: make the next tool call or give the answer, with brief reasoning." The stopped reply stays saved but leaves that request's context. At most two such turns go out in a row until a reply finishes, and only when the request fits and no message is already queued; if the second also stops, the notice below stands. A stop at the full `maxTokens` while still thinking names the setting and `models.json`; a lower thinking level usually helps more than a bigger cap.
78
+ - Pi-tuck preserves thinking-only stops in session history. At the model's full output allowance, it reports exhaustion if the reply remains unfinished. Below that allowance, it retries once, re-armed as Pi's overflow recovery is. After any length stop on the branch, pi-tuck trims so the next reply gets twice that stop's output (at most `maxTokens` and half the window). When such a stop is not retried, pi-tuck queues one more user turn asking the model to act: "Your last reply used the whole output budget on thinking. Act now: make the next tool call or give the answer, with brief reasoning." The stopped reply stays saved but leaves that request's context. On a Chat Completions model, that request alone goes out at the lowest thinking effort the server lists (pi-tuck reads the list at session start) and with at most 20,480 output tokens; a stop at that cap counts as a full-cap stop. At most two such turns go out in a row until a reply finishes, and only when the request fits and no message is already queued; if the second also stops, the notice below stands. A stop at the full `maxTokens` while still thinking names the setting and `models.json`; a lower thinking level usually helps more than a bigger cap.
79
79
  - Pi-tuck uses the context window declared in Pi's model configuration. A length stop alone does not establish a smaller window. If the server has a smaller effective limit, set that limit in Pi's model configuration.
80
80
  - Pi's compaction reserve sets the cut target. For larger requests, pi-tuck estimates reply needs from observed output on the current branch for the active model, bounded by the reserve and model output limit. A cut above the room aims to leave 3,584 reply tokens within those bounds; where no cut can, the request goes out as before. If cuts cannot leave enough room for the protected prompt and a reply, try a shorter prompt, fewer tools, or a larger window. Pi-tuck's checks use estimates. Pi handles recognized provider overflows, and silent truncation can go undetected.
81
81
 
@@ -1 +1 @@
1
- export declare const BUILD_ID = "092a7cfa8000bf0285eb4fd76580b229336faaf9af7b50d3c30b11d0f1a8d787";
1
+ export declare const BUILD_ID = "e11927281c0dc22058687647b4d0658d8a588470b4fae558169cc0532bb02d4e";
@@ -1 +1 @@
1
- export const BUILD_ID = "092a7cfa8000bf0285eb4fd76580b229336faaf9af7b50d3c30b11d0f1a8d787";
1
+ export const BUILD_ID = "e11927281c0dc22058687647b4d0658d8a588470b4fae558169cc0532bb02d4e";
@@ -11,6 +11,15 @@ export declare const overflowNotice: (contextWindow: number, bound: number, lear
11
11
  export declare const capStopNotice: (model: string, maxTokens: number, file: string) => string;
12
12
  /** The follow-up turn sent after a reply that spent its whole output on thinking, with no text or tool call. */
13
13
  export declare const ACT_NOW = "Your last reply used the whole output budget on thinking. Act now: make the next tool call or give the answer, with brief reasoning.";
14
+ /** The act-now request's reply cap: above the largest real reply seen on mac-studio (18.6k tokens in 476 replies), well under the 32k-65k caps
15
+ * a thinking runaway fills. */
16
+ export declare const ACT_NOW_MAX_TOKENS = 20480;
17
+ /** The act-now request, rewritten (Chat Completions payloads only): the lowest effort the server lists, top level (where vLLM-style servers
18
+ * read it) and in chat_template_kwargs if Pi sent one there, and an output cap of at most ACT_NOW_MAX_TOKENS. Undefined for any other request. */
19
+ export declare function actNowPayload(payload: unknown, effort: string | undefined): {
20
+ payload: Record<string, unknown>;
21
+ cap?: number;
22
+ } | undefined;
14
23
  /** Act-now turns on the branch since its last finished reply (stopReason "stop" or "toolUse"). Read from the log, so a restart, /tree
15
24
  * or fork keeps the count; a length stop with content (a cut-off tool call) does not reset it. Operator messages do not reset it. */
16
25
  export declare function actNowsInARow(branch: readonly SessionEntry[]): number;
@@ -2,6 +2,7 @@ import { textOf } from "./tuck/core/content.js";
2
2
  import { PendingCut, StartingPrompt, Run } from "./run.js";
3
3
  import { CUT_REPLY_FLOOR, requestReplyFloor, stoppedReplyRoom, carriesPrompt, thinkingOnlyLength, piContextSafetyMargin, loadPiRequestMath } from "./request-capacity.js";
4
4
  import { BUILD_ID } from "./build-id.js";
5
+ import { lowestEffort, pendingCheck, serverEfforts } from "./config-check.js";
5
6
  import { IncidentRecorder, attachReceipt, permittedEntries, receiptId, findReceiptEntry } from "./diagnostics.js";
6
7
  import { createHash } from "node:crypto";
7
8
  import { readFileSync } from "node:fs";
@@ -68,6 +69,35 @@ export const capStopNotice = (model, maxTokens, file) => `pi-tuck: ${model} used
68
69
  "The unfinished response is saved in the session.";
69
70
  /** The follow-up turn sent after a reply that spent its whole output on thinking, with no text or tool call. */
70
71
  export const ACT_NOW = "Your last reply used the whole output budget on thinking. Act now: make the next tool call or give the answer, with brief reasoning.";
72
+ /** The act-now request's reply cap: above the largest real reply seen on mac-studio (18.6k tokens in 476 replies), well under the 32k-65k caps
73
+ * a thinking runaway fills. */
74
+ export const ACT_NOW_MAX_TOKENS = 20_480;
75
+ /** The act-now request, rewritten (Chat Completions payloads only): the lowest effort the server lists, top level (where vLLM-style servers
76
+ * read it) and in chat_template_kwargs if Pi sent one there, and an output cap of at most ACT_NOW_MAX_TOKENS. Undefined for any other request. */
77
+ export function actNowPayload(payload, effort) {
78
+ const body = payload;
79
+ const messages = body?.messages;
80
+ if (!Array.isArray(messages))
81
+ return undefined;
82
+ const last = messages.at(-1);
83
+ const text = typeof last?.content === "string" ? last.content
84
+ : Array.isArray(last?.content) ? last.content.map(part => part?.type === "text" ? String(part.text) : "").join("") : undefined;
85
+ if (last?.role !== "user" || text !== ACT_NOW)
86
+ return undefined;
87
+ const out = { ...body };
88
+ let cap;
89
+ for (const field of ["max_tokens", "max_completion_tokens"]) {
90
+ if (typeof out[field] === "number")
91
+ cap = out[field] = Math.min(out[field], ACT_NOW_MAX_TOKENS);
92
+ }
93
+ if (effort) {
94
+ out.reasoning_effort = effort;
95
+ const kwargs = out.chat_template_kwargs;
96
+ if (kwargs && typeof kwargs === "object" && "reasoning_effort" in kwargs)
97
+ out.chat_template_kwargs = { ...kwargs, reasoning_effort: effort };
98
+ }
99
+ return { payload: out, cap };
100
+ }
71
101
  /** At most this many act-now turns in a row; after that a stall gets the cap-stop notice until a reply finishes (stop or toolUse). */
72
102
  const ACT_NOW_LIMIT = 2;
73
103
  /** Act-now turns on the branch since its last finished reply (stopReason "stop" or "toolUse"). Read from the log, so a restart, /tree
@@ -353,6 +383,20 @@ export async function installCompaction(pi, options = {}) {
353
383
  if (ctx.model && `${ctx.model.provider}/${ctx.model.id}` !== options.continuationModel)
354
384
  run?.rearmLengthRetry();
355
385
  };
386
+ // The act-now request asks for a short act, so it goes out at the server's lowest effort with a smaller cap. The cap sent is kept: a stop
387
+ // at it is a full-cap stop, not a squeezed one.
388
+ let actNowCap;
389
+ pi.on("before_provider_request", async (event, ctx) => {
390
+ const model = ctx.model;
391
+ if (model?.api !== "openai-completions" || !actNowPayload(event.payload, undefined)) {
392
+ actNowCap = undefined;
393
+ return undefined;
394
+ }
395
+ await pendingCheck;
396
+ const rewritten = actNowPayload(event.payload, lowestEffort(serverEfforts.get(`${model.provider}/${model.id}`)));
397
+ actNowCap = rewritten.cap;
398
+ return rewritten.payload;
399
+ });
356
400
  // The act-now turn is pi-tuck's own, not the operator's: it grants no retry.
357
401
  pi.on("message_start", (event, ctx) => { if (event.message.role === "user" && textOf(event.message.content) !== ACT_NOW)
358
402
  rearmLengthRetry(ctx); });
@@ -1232,7 +1276,7 @@ export async function installCompaction(pi, options = {}) {
1232
1276
  if (event.message.role !== "assistant" || !ctx.model)
1233
1277
  return;
1234
1278
  const stoppedOutput = event.message.usage?.output;
1235
- if (stoppedOutput >= ctx.model.maxTokens) {
1279
+ if (stoppedOutput >= (actNowCap ?? ctx.model.maxTokens)) {
1236
1280
  return { entries: event.entries, continue: false };
1237
1281
  }
1238
1282
  // Pi's supported boundary drafts commit before finishTurn honors `continue`. Omitting the selected failed response also prevents
@@ -12,6 +12,12 @@ export interface ServerModel {
12
12
  window?: number;
13
13
  efforts?: string[];
14
14
  }
15
+ /** The lowest ranked effort a server lists, or undefined. */
16
+ export declare const lowestEffort: (efforts: readonly string[] | undefined) => string | undefined;
17
+ /** The efforts each provider/model's server listed at this process's check; the act-now request reads them. */
18
+ export declare const serverEfforts: globalThis.Map<string, string[]>;
19
+ /** This process's check while it runs; the act-now request waits for it rather than go out without the efforts. */
20
+ export declare let pendingCheck: Promise<void> | undefined;
15
21
  export declare function serverModel(body: unknown, id: string): ServerModel | undefined;
16
22
  export interface Finding {
17
23
  kind: "window" | "thinking";
@@ -9,6 +9,14 @@ import { join } from "node:path";
9
9
  export const CONFIG_CHECK_ENTRY = "pi-tuck-config-check";
10
10
  /** Pi's thinking levels that a server can list; "off" is never a server effort. */
11
11
  const LEVELS = ["minimal", "low", "medium", "high", "xhigh", "max"];
12
+ /** Server efforts from low to high, for the names pi-tuck can rank; "none" and "off" turn thinking off and are never picked. */
13
+ const EFFORT_RANK = ["xlow", "minimal", "low", "medium", "xmedium", "high", "xhigh", "max"];
14
+ /** The lowest ranked effort a server lists, or undefined. */
15
+ export const lowestEffort = (efforts) => EFFORT_RANK.find(e => efforts?.includes(e));
16
+ /** The efforts each provider/model's server listed at this process's check; the act-now request reads them. */
17
+ export const serverEfforts = new Map();
18
+ /** This process's check while it runs; the act-now request waits for it rather than go out without the efforts. */
19
+ export let pendingCheck;
12
20
  export function serverModel(body, id) {
13
21
  const data = body?.data;
14
22
  const entry = Array.isArray(data) ? data.find(m => m?.id === id) : undefined;
@@ -157,7 +165,10 @@ export async function checkModel(pi, ctx, deps) {
157
165
  const server = serverModel(await response.json(), model.id);
158
166
  if (!server)
159
167
  return;
160
- const ref = `${model.provider}/${model.id}`, no = declined(settingsPath)[ref] ?? {};
168
+ const ref = `${model.provider}/${model.id}`;
169
+ if (server.efforts)
170
+ serverEfforts.set(ref, server.efforts);
171
+ const no = declined(settingsPath)[ref] ?? {};
161
172
  const open = findings(model, server).filter(f => no[f.kind] !== f.server);
162
173
  if (!open.length)
163
174
  return;
@@ -191,6 +202,6 @@ export function installConfigCheck(pi, deps) {
191
202
  if (done)
192
203
  return;
193
204
  done = true;
194
- void checkModel(pi, ctx, deps);
205
+ pendingCheck = checkModel(pi, ctx, deps).finally(() => { pendingCheck = undefined; });
195
206
  });
196
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-tuck",
3
- "version": "1.10.5",
3
+ "version": "1.11.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",
package/src/build-id.ts CHANGED
@@ -1 +1 @@
1
- export const BUILD_ID = "092a7cfa8000bf0285eb4fd76580b229336faaf9af7b50d3c30b11d0f1a8d787";
1
+ export const BUILD_ID = "e11927281c0dc22058687647b4d0658d8a588470b4fae558169cc0532bb02d4e";
package/src/compaction.ts CHANGED
@@ -2,6 +2,7 @@ import { textOf } from "./tuck/core/content.js";
2
2
  import { PendingCut, StartingPrompt, Run, type CutEntry } from "./run.js";
3
3
  import { CUT_REPLY_FLOOR, requestReplyFloor, stoppedReplyRoom, carriesPrompt, thinkingOnlyLength, piContextSafetyMargin, loadPiRequestMath } from "./request-capacity.js";
4
4
  import { BUILD_ID } from "./build-id.js";
5
+ import { lowestEffort, pendingCheck, serverEfforts } from "./config-check.js";
5
6
  import { IncidentRecorder, attachReceipt, permittedEntries, receiptId, findReceiptEntry, type Receipt, type RecorderOptions } from "./diagnostics.js";
6
7
  import { createHash } from "node:crypto";
7
8
  import { readFileSync } from "node:fs";
@@ -71,6 +72,31 @@ export const capStopNotice = (model: string, maxTokens: number, file: string) =>
71
72
  "The unfinished response is saved in the session.";
72
73
  /** The follow-up turn sent after a reply that spent its whole output on thinking, with no text or tool call. */
73
74
  export const ACT_NOW = "Your last reply used the whole output budget on thinking. Act now: make the next tool call or give the answer, with brief reasoning.";
75
+ /** The act-now request's reply cap: above the largest real reply seen on mac-studio (18.6k tokens in 476 replies), well under the 32k-65k caps
76
+ * a thinking runaway fills. */
77
+ export const ACT_NOW_MAX_TOKENS = 20_480;
78
+ /** The act-now request, rewritten (Chat Completions payloads only): the lowest effort the server lists, top level (where vLLM-style servers
79
+ * read it) and in chat_template_kwargs if Pi sent one there, and an output cap of at most ACT_NOW_MAX_TOKENS. Undefined for any other request. */
80
+ export function actNowPayload(payload: unknown, effort: string | undefined): { payload: Record<string, unknown>; cap?: number } | undefined {
81
+ const body = payload as Record<string, unknown> | null;
82
+ const messages = body?.messages;
83
+ if (!Array.isArray(messages)) return undefined;
84
+ const last = messages.at(-1) as { role?: unknown; content?: unknown } | undefined;
85
+ const text = typeof last?.content === "string" ? last.content
86
+ : Array.isArray(last?.content) ? last.content.map(part => (part as { type?: unknown; text?: unknown })?.type === "text" ? String((part as { text: unknown }).text) : "").join("") : undefined;
87
+ if (last?.role !== "user" || text !== ACT_NOW) return undefined;
88
+ const out: Record<string, unknown> = { ...body };
89
+ let cap: number | undefined;
90
+ for (const field of ["max_tokens", "max_completion_tokens"]) {
91
+ if (typeof out[field] === "number") cap = out[field] = Math.min(out[field] as number, ACT_NOW_MAX_TOKENS);
92
+ }
93
+ if (effort) {
94
+ out.reasoning_effort = effort;
95
+ const kwargs = out.chat_template_kwargs as Record<string, unknown> | undefined;
96
+ if (kwargs && typeof kwargs === "object" && "reasoning_effort" in kwargs) out.chat_template_kwargs = { ...kwargs, reasoning_effort: effort };
97
+ }
98
+ return { payload: out, cap };
99
+ }
74
100
  /** At most this many act-now turns in a row; after that a stall gets the cap-stop notice until a reply finishes (stop or toolUse). */
75
101
  const ACT_NOW_LIMIT = 2;
76
102
  /** Act-now turns on the branch since its last finished reply (stopReason "stop" or "toolUse"). Read from the log, so a restart, /tree
@@ -330,6 +356,17 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
330
356
  const rearmLengthRetry = (ctx: ExtensionContext) => {
331
357
  if (ctx.model && `${ctx.model.provider}/${ctx.model.id}` !== options.continuationModel) run?.rearmLengthRetry();
332
358
  };
359
+ // The act-now request asks for a short act, so it goes out at the server's lowest effort with a smaller cap. The cap sent is kept: a stop
360
+ // at it is a full-cap stop, not a squeezed one.
361
+ let actNowCap: number | undefined;
362
+ pi.on("before_provider_request", async (event, ctx) => {
363
+ const model = ctx.model;
364
+ if (model?.api !== "openai-completions" || !actNowPayload(event.payload, undefined)) { actNowCap = undefined; return undefined; }
365
+ await pendingCheck;
366
+ const rewritten = actNowPayload(event.payload, lowestEffort(serverEfforts.get(`${model.provider}/${model.id}`)))!;
367
+ actNowCap = rewritten.cap;
368
+ return rewritten.payload;
369
+ });
333
370
  // The act-now turn is pi-tuck's own, not the operator's: it grants no retry.
334
371
  pi.on("message_start", (event, ctx) => { if (event.message.role === "user" && textOf(event.message.content) !== ACT_NOW) rearmLengthRetry(ctx); });
335
372
  pi.on("message_end", (event, ctx) => {
@@ -1091,7 +1128,7 @@ export async function installCompaction(pi: ExtensionAPI, options: CompactionOpt
1091
1128
  // Native Pi does not compact-and-retry output that reached the catalogue cap.
1092
1129
  if (event.message.role !== "assistant" || !ctx.model) return;
1093
1130
  const stoppedOutput = event.message.usage?.output;
1094
- if (stoppedOutput >= ctx.model.maxTokens) {
1131
+ if (stoppedOutput >= (actNowCap ?? ctx.model.maxTokens)) {
1095
1132
  return { entries: event.entries, continue: false };
1096
1133
  }
1097
1134
  // Pi's supported boundary drafts commit before finishTurn honors `continue`. Omitting the selected failed response also prevents
@@ -15,6 +15,14 @@ type Map = Partial<Record<string, string | null>>;
15
15
 
16
16
  /** What the server says about one model. Window from the first of these it reports; never n_ctx_train (the training length). */
17
17
  export interface ServerModel { window?: number; efforts?: string[] }
18
+ /** Server efforts from low to high, for the names pi-tuck can rank; "none" and "off" turn thinking off and are never picked. */
19
+ const EFFORT_RANK = ["xlow", "minimal", "low", "medium", "xmedium", "high", "xhigh", "max"];
20
+ /** The lowest ranked effort a server lists, or undefined. */
21
+ export const lowestEffort = (efforts: readonly string[] | undefined) => EFFORT_RANK.find(e => efforts?.includes(e));
22
+ /** The efforts each provider/model's server listed at this process's check; the act-now request reads them. */
23
+ export const serverEfforts = new Map<string, string[]>();
24
+ /** This process's check while it runs; the act-now request waits for it rather than go out without the efforts. */
25
+ export let pendingCheck: Promise<void> | undefined;
18
26
  export function serverModel(body: unknown, id: string): ServerModel | undefined {
19
27
  const data = (body as { data?: unknown } | null)?.data;
20
28
  const entry = Array.isArray(data) ? data.find(m => (m as { id?: unknown } | null)?.id === id) as Record<string, unknown> | undefined : undefined;
@@ -130,7 +138,9 @@ export async function checkModel(pi: Pick<ExtensionAPI, "appendEntry">, ctx: Ext
130
138
  if (!response.ok) return;
131
139
  const server = serverModel(await response.json(), model.id);
132
140
  if (!server) return;
133
- const ref = `${model.provider}/${model.id}`, no = declined(settingsPath)[ref] ?? {};
141
+ const ref = `${model.provider}/${model.id}`;
142
+ if (server.efforts) serverEfforts.set(ref, server.efforts);
143
+ const no = declined(settingsPath)[ref] ?? {};
134
144
  const open = findings(model as never, server).filter(f => no[f.kind] !== f.server);
135
145
  if (!open.length) return;
136
146
  const lines = open.map(f => f.question.replace(/\?$/, "."));
@@ -157,6 +167,6 @@ export function installConfigCheck(pi: ExtensionAPI, deps: CheckDeps): void {
157
167
  pi.on("session_start", (_event, ctx) => {
158
168
  if (done) return;
159
169
  done = true;
160
- void checkModel(pi, ctx, deps);
170
+ pendingCheck = checkModel(pi, ctx, deps).finally(() => { pendingCheck = undefined; });
161
171
  });
162
172
  }