From e831a614441b0897effbae53cf5877a53b53984e Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 14:25:01 +0100 Subject: [PATCH 1/4] Support Pi 1.5 and edit the context only at the threshold Pi 1.5 no longer exports Type from pi-ai, so the extension imports it from typebox, which Pi 1.0.3 and 1.5 both provide to extensions. Development now uses Pi 1.5.2; the tests pass on 1.5.2 and 1.0.3. The faux provider in Pi 1.0 counts a session's first prompt as both input and cache write, so the tests disable its cache to get the same usage on every version. Every context edit changes the prompt prefix. The provider then reads all later text without its cache, and Anthropic drops every thinking block after the edit. In local sessions, superseded-read edits below the threshold cost about 4.8 times the input tokens they saved, and a second edit within a few turns of the previous one often missed the whole cache. Superseded reads are therefore replaced only above the threshold, in the same batch as pruning and shaking, and anywhere in the context. Without a compaction, edits are kept only when they bring the context to the threshold or below, so they do not repeat at each turn. The staleSuffixTokens setting no longer has a purpose and is removed. Also: cancel obsolete background handoff requests after session-tree navigation, and state recall's limits (current branch only, images as MIME types). --- CHANGELOG.md | 6 + README.md | 55 ++-- extensions/index.ts | 26 +- package-lock.json | 642 ++++++----------------------------------- package.json | 8 +- src/config.ts | 9 - src/context.ts | 15 - src/maintain.ts | 23 +- src/shake.ts | 3 +- src/stale.ts | 12 +- test/extension.test.ts | 139 +++++++-- test/maintain.test.ts | 53 +++- test/recall.test.ts | 40 +++ test/stale.test.ts | 25 +- 14 files changed, 358 insertions(+), 698 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c64296..3fb8989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +- Replace superseded reads only above the threshold, in one batch with pruning and shaking, and anywhere in the context. Without a compaction, keep edits only when they bring the context to the threshold or below, so they do not repeat at each turn. Every context edit makes the provider miss its cache for the later text, and Anthropic drops every later thinking block. In local sessions, the estimated cache cost of these edits was about 4.8 times the input tokens they saved. +- Remove the `staleSuffixTokens` setting. A configured value now reports "is not a setting". +- Cancel obsolete background handoff requests immediately after session-tree navigation. +- Clarify that recall retrieves text only from the current branch, represents images by MIME type, and does not delete original session entries. +- Document the Pi development baseline and existing locked/latest-version CI checks. + ## 0.2.1 - Rewrite the README for users who do not know Pi internals: it explains the terms, the sequence of a session, and each setting with its default and an example. diff --git a/README.md b/README.md index de9be5d..cf63fe0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # pi-context-kit pi-context-kit keeps long [Pi](https://github.com/earendil-works/pi) sessions small, so the AI model can continue to work. -You install it once. After that, it works automatically. +Install it once. The defaults work without configuration. +Summaries can lose details. `recall` retrieves earlier text on the current branch, but returns only MIME types for images. ## The problem @@ -14,9 +15,9 @@ A summary can lose details, and it costs time and money. pi-context-kit does three things: -1. It removes text that the model does not need any more, before the window is full. -2. When a summary is necessary, it prepares a better summary in advance. -3. It keeps all removed text available. The model can read it again with the `recall` tool. +1. It replaces repeated file reads and old tool outputs in the model's context. +2. When a summary is necessary, it can prepare a handoff note in advance. +3. It leaves the original session entries unchanged. The model can retrieve earlier text on the current branch with `recall`. ## Words used in this document @@ -102,7 +103,7 @@ Sometimes the model reads the same file two times. The first copy is then old. pi-context-kit replaces the old copy with this text: `[Superseded by a newer read of this file]`. It does this only when the newer read covers all of the old read. If the newer read was cut short, the old copy stays. -It does this only for recent entries, limited by `staleSuffixTokens`. This limit tries to keep the prompt cache useful, but the provider decides about caching. +It does this only when the context is above the threshold, in the same change as pruning, shaking or compaction. Each change to old text makes the provider read all later text again without its cache. With Anthropic, it also removes the model's earlier reasoning from the request. One change near the threshold costs less than one change at each turn. ### 2. A handoff note is prepared in advance @@ -132,18 +133,25 @@ Your work continues during these steps. pi-context-kit never stops a running tas ### The `recall` tool -The model can always read removed text again. The `recall` tool can: +The `recall` tool reads original session text, not the shortened context sent to the model. It can: -- search all messages of the current conversation branch, also the removed and summarized messages; -- read one full entry, with the ID given in a notice. +- search earlier conversation text on the current branch, including removed and summarized messages; +- read an entry's text by ID, with pagination for large entries. -Images cannot be recovered. `recall` shows only their file type. +Other branches and sessions are excluded. System prompt entries are not searched. +Images remain in the original session entries, but `recall` returns only their MIME types, not image content. +The model must call `recall` to retrieve a missing detail. Retrieval is not automatic. -## What it never changes +## What maintenance preserves -- Your messages. Your instructions and your images always stay. -- The tool calls of the model, and the model's reasoning. -- The pairs of tool call and tool result. Each tool call keeps its result. +File-read replacement, pruning, and shaking do not rewrite the original session entries. +In the model's context, these steps preserve: + +- Your messages, including your instructions and images. +- The model's tool calls and reasoning. Anthropic can still drop the reasoning after an edited message (see [Old file reads are replaced](#1-old-file-reads-are-replaced)). +- Tool-call and tool-result pairs. Each tool call keeps its result, but the result content can be shortened. + +Compaction is different: it replaces older context with a summary, including older user messages. The original entries remain in session history. ## Settings @@ -175,7 +183,6 @@ Copy only the lines that you want to change. "methodOrder": ["handoff", "shake", "soft"], "asyncEnabled": true, "supersedeReads": true, - "staleSuffixTokens": 8000, "progressRatio": 0.8, "prune": { "enabled": true, @@ -202,7 +209,6 @@ Copy only the lines that you want to change. | [`methodOrder`](#methodorder) | A list of `"handoff"`, `"shake"`, `"soft"` | `["handoff", "shake", "soft"]` | The methods to try, and their order. | | [`asyncEnabled`](#asyncenabled) | `true`, `false` | `true` | Prepares the handoff note in the background. | | [`supersedeReads`](#supersedereads) | `true`, `false` | `true` | Replaces old copies of a file that was read again. | -| [`staleSuffixTokens`](#stalesuffixtokens) | A whole number, 0 or more | `8000` | Limits which old copies can be replaced. | | [`progressRatio`](#progressratio) | A number above 0, up to 1 | `0.8` | How small the context must become. | | [`prune.enabled`](#pruneenabled) | `true`, `false` | `true` | Turns pruning of old tool outputs on or off. | | [`prune.protectTokens`](#pruneprotecttokens) | A whole number, 0 or more | `40000` | The newest tool outputs that are never pruned. | @@ -343,27 +349,12 @@ Replaces the old copy of a file when the model reads the same file again. - `true` (default): the old copy becomes `[Superseded by a newer read of this file]`. - `false`: all copies stay. -This works at every turn, also below the threshold. +This works only above the threshold, together with pruning and shaking. ```json { "contextKit": { "supersedeReads": false } } ``` -### `staleSuffixTokens` - -Limits which old file copies `supersedeReads` can replace. -pi-context-kit replaces an old copy only if the old copy and all newer text are smaller than this number of tokens. Thus only recent copies are replaced. - -Why: the provider can keep the start of the conversation in a cache. A change in old text can make the provider read all the text after it again, which costs more. - -- `8000` (default). -- A larger value replaces more copies, but can cause more cache misses. -- `0` replaces nothing. It has the same effect as `"supersedeReads": false`. - -```json -{ "contextKit": { "staleSuffixTokens": 16000 } } -``` - ### `progressRatio` How small the context must become after a method, as a fraction of the threshold. @@ -546,6 +537,8 @@ npm run check ``` The tests run offline with Pi's faux provider. They do not call a real model. +Development uses Pi `1.5.2`. The oldest supported version is Pi `1.0.3`. CI checks the locked dependencies on Node 22 and 24, and Pi `1.0.3` and latest Pi on Node 24. +Host-provided peer dependencies use `"*"`, as required by Pi's package guide. This is not a guarantee that every Pi version works. ## Contributing and releases diff --git a/extensions/index.ts b/extensions/index.ts index 9bdfda2..3b5818f 100644 --- a/extensions/index.ts +++ b/extensions/index.ts @@ -1,9 +1,5 @@ -import { - type Api, - type Message, - type Model, - Type, -} from "@earendil-works/pi-ai"; +import { type Api, type Message, type Model } from "@earendil-works/pi-ai"; +import { Type } from "typebox"; import { convertToLlm, type ExtensionAPI, @@ -243,6 +239,11 @@ export default function contextKit(pi: ExtensionAPI): void { const shakeFirst = before(methods, "shake", "handoff"); let result = plan(shakeFirst); const drafts = () => toDrafts(result.edits); + // Without compaction, edits that leave the context above the threshold break the cache again next turn. + const persisted = () => + result.edits.length > 0 && result.tokens <= limit + ? { entries: drafts() } + : undefined; const leafId = ctx.sessionManager.getLeafId(); const current = epoch(branch); @@ -286,7 +287,7 @@ export default function contextKit(pi: ExtensionAPI): void { } if (own && keptEntryId && failedEpoch !== current) { const writing = background.writing(current); - if (writing && limit < piThreshold(model)) return { entries: drafts() }; + if (writing && limit < piThreshold(model)) return persisted(); const signal = ctx.signal ?? new AbortController().signal; try { const compaction = await handoff({ @@ -343,7 +344,7 @@ export default function contextKit(pi: ExtensionAPI): void { } softFailedEpoch = current; } - return result.edits.length > 0 ? { entries: drafts() } : undefined; + return persisted(); }); pi.on("session_before_compact", async (event, ctx) => { @@ -396,6 +397,10 @@ export default function contextKit(pi: ExtensionAPI): void { } }); + pi.on("session_tree", (_event, ctx) => { + const branch = ctx.sessionManager.getBranch(); + background.invalidate(epoch(branch), branch); + }); pi.on("session_compact", () => background.cancel()); pi.on("session_shutdown", () => background.cancel()); @@ -403,8 +408,9 @@ export default function contextKit(pi: ExtensionAPI): void { name: "recall", label: "Recall", description: - "Search or read the full session history, including messages removed by compaction and tool outputs that were pruned or elided. " + - "Pass `query` to list matching entries with their IDs, newest first. Pass `entryId` to read one entry in full.", + "Search or read earlier text on the current session branch, including messages removed by compaction and tool outputs that were pruned or elided. " + + "Other branches are excluded. Images are represented only by MIME type. " + + "Pass `query` to list matching entries with their IDs, newest first. Pass `entryId` to read one entry's text, with pagination for large entries.", parameters: Type.Object({ query: Type.Optional( Type.String({ description: "Text to find, case-insensitive." }), diff --git a/package-lock.json b/package-lock.json index 3c8f48f..c9ca05d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,15 +9,17 @@ "version": "0.2.1", "license": "MIT", "devDependencies": { - "@earendil-works/pi-ai": "^1.0.3", - "@earendil-works/pi-coding-agent": "^1.0.3", + "@earendil-works/pi-ai": "^1.5.2", + "@earendil-works/pi-coding-agent": "^1.5.2", "@types/node": "^26.6.4", + "typebox": "^1.3.27", "typescript": "^7.0.2", "vitest": "^5.0.3" }, "peerDependencies": { "@earendil-works/pi-ai": "*", - "@earendil-works/pi-coding-agent": "*" + "@earendil-works/pi-coding-agent": "*", + "typebox": "*" } }, "node_modules/@anthropic-ai/sdk": { @@ -413,50 +415,37 @@ "node": ">=6.9.0" } }, - "node_modules/@earendil-works/chord": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/chord/-/chord-1.0.3.tgz", - "integrity": "sha512-H5pKMs3S1z2q4V7NkDGKDFzOMW+OkzdsnGxxj5wNJUANG03VKj29UVmc1xnnnf0FAc03COHYNxwgNApO0nt0fg==", - "dev": true, - "license": "MIT", - "dependencies": { - "esbuild": "0.28.2" - }, - "engines": { - "node": ">=22.19.0" - } - }, "node_modules/@earendil-works/pi-agent-core": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/pi-agent-core/-/pi-agent-core-1.0.3.tgz", - "integrity": "sha512-lnvi2PJYaq8mDLzwWBttNqfxrLS63SSMONUJnTCypdvt/flmNJchXwWXsXUOJ5Yhe/mN+iHkrXu696lWZZ8o+w==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-agent-core/-/pi-agent-core-1.5.2.tgz", + "integrity": "sha512-ie5mejS7mGfXt//9As7i3LfxVXdktZvF1JP4EQsUXTp4mU437h23MNGx7wXZ5VYs3YiG/Qnj3e7OZ2HC069OMw==", "dev": true, "license": "MIT", "dependencies": { - "@earendil-works/pi-ai": "^1.0.3", - "typebox": "1.3.27" + "@earendil-works/pi-ai": "1.5.2", + "@earendil-works/pi-schema": "1.5.2" }, "engines": { "node": ">=22.19.0" } }, "node_modules/@earendil-works/pi-ai": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/pi-ai/-/pi-ai-1.0.3.tgz", - "integrity": "sha512-p+/EUrbmfT0xWOtL/NJRtWOsyzcKKFSyiivHLDBMG0DUVpHdaIykd5jFibq0YZDFGBN/nv61zdOelMb+ylPfSg==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-ai/-/pi-ai-1.5.2.tgz", + "integrity": "sha512-2tWPSnV3qzfiDIY3aWluBag3vC++Vs+VsXt/UquSU5onPMohPih72FUhIhaqmDdMYubOgB3Byl9uF4Vk40JLvQ==", "dev": true, "license": "MIT", "dependencies": { "@anthropic-ai/sdk": "0.129.0", "@aws-sdk/client-bedrock-runtime": "3.1127.0", - "@earendil-works/pi-telemetry": "^1.0.3", + "@earendil-works/pi-schema": "1.5.2", + "@earendil-works/pi-telemetry": "1.5.2", "@google/genai": "2.21.0", "@smithy/node-http-handler": "4.12.1", "http-proxy-agent": "9.1.0", "https-proxy-agent": "9.1.0", "openai": "7.19.0", - "partial-json": "0.1.7", - "typebox": "1.3.27" + "partial-json": "0.1.7" }, "bin": { "pi-ai": "dist/cli.js" @@ -466,9 +455,9 @@ } }, "node_modules/@earendil-works/pi-codemode": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/pi-codemode/-/pi-codemode-1.0.3.tgz", - "integrity": "sha512-/rgWAXA9PhuFm0+j6N5FVvvWrAwt1LnhmbjA3Hy5+Q033XUHgh0YCMGAmU76S90ocr0Vfxm50ddYT/O76T5OGQ==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-codemode/-/pi-codemode-1.5.2.tgz", + "integrity": "sha512-HoZQ40a9RgdZ1VgmrX6x8887cNXedaRJT1l+Ie5YRIMK4gY7v0EpsiNqf6dmixrKylZlTgUSyR+vE8xhjfkr+w==", "dev": true, "license": "MIT", "dependencies": { @@ -479,34 +468,33 @@ } }, "node_modules/@earendil-works/pi-coding-agent": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/pi-coding-agent/-/pi-coding-agent-1.0.3.tgz", - "integrity": "sha512-t2lb0dw4y/jr5a2PRo6eTHGTZOPB3/YAMVyhhYFC1W3Hl5xE+462I/gMWjF4gCLuhGipNEfuNqONFmdqLFz4SQ==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-coding-agent/-/pi-coding-agent-1.5.2.tgz", + "integrity": "sha512-mUWI04rqF1Vd/m1q+Ps1XeWsTXEVvRUnsmRa83I3Dzua0Tx5bYS93imeqtIfrXf7PkkaR6ERz+AuQhIJlom5yA==", "dev": true, "license": "MIT", "dependencies": { - "@earendil-works/chord": "^1.0.3", - "@earendil-works/pi-agent-core": "^1.0.3", - "@earendil-works/pi-ai": "^1.0.3", - "@earendil-works/pi-codemode": "^1.0.3", - "@earendil-works/pi-mcp": "^1.0.3", - "@earendil-works/pi-tui": "^1.0.3", + "@earendil-works/pi-agent-core": "1.5.2", + "@earendil-works/pi-ai": "1.5.2", + "@earendil-works/pi-codemode": "1.5.2", + "@earendil-works/pi-mcp": "1.5.2", + "@earendil-works/pi-tui": "1.5.2", "@silvia-odwyer/photon-node": "0.3.4", "brace-expansion": "5.0.12", "chalk": "6.0.0", "cross-spawn": "7.0.6", "diff": "8.0.4", - "grok-mermaid": "0.2.3", "highlight.js": "10.7.3", "hosted-git-info": "9.0.3", "ignore": "7.0.8", "jiti": "2.7.0", - "minimatch": "10.2.6", + "lovely-mermaid": "0.3.3", + "minimatch": "11.0.3", "proper-lockfile": "4.1.2", "quickjs-wasi": "3.6.2", "semver": "7.8.5", "typebox": "1.3.27", - "undici": "8.10.2", + "undici": "8.12.3", "yaml": "2.9.0" }, "bin": { @@ -517,9 +505,9 @@ } }, "node_modules/@earendil-works/pi-mcp": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/pi-mcp/-/pi-mcp-1.0.3.tgz", - "integrity": "sha512-ZAhL/g0rpjyKtcKzD0jSDk7sFIrMCQocmKtpAE1F9eRnI5fGGVWUyiZwALG/Tn1sagzxFbSqtc29zGx5OvDDGA==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-mcp/-/pi-mcp-1.5.2.tgz", + "integrity": "sha512-zU1UgeXDlbixPqGEWD7Ql0brEMIpYr7aEWjoEE5h5enJbM/kQ2jIr7lN8JoR80oUnq1fJSU7SC8kLx2Fx/IZYg==", "dev": true, "license": "MIT", "dependencies": { @@ -529,470 +517,39 @@ "node": ">=22.19.0" } }, - "node_modules/@earendil-works/pi-telemetry": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/pi-telemetry/-/pi-telemetry-1.0.3.tgz", - "integrity": "sha512-Li4YamN09x9zzCquPbtEL2AQmwqv3Vn3sNOYqG0DRg24fjiMfntCsb7QKbejCXZssTAyaN+hutLl6O0UnJDrfg==", + "node_modules/@earendil-works/pi-schema": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-schema/-/pi-schema-1.5.2.tgz", + "integrity": "sha512-hJoyCXWUhsSrXY5wJo2Q4kHXUsR51pNhkJHAMkWRwVMLDRtMDPkKNaa+JlVRVqTw1hjdSxcVVaFLSDbKlaTXEQ==", "dev": true, "license": "MIT", "engines": { "node": ">=22.19.0" } }, - "node_modules/@earendil-works/pi-tui": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@earendil-works/pi-tui/-/pi-tui-1.0.3.tgz", - "integrity": "sha512-C7b8Y+7iz+/oPEZUJubv6NPm3M/4ziq0hjQ2jhqMNpBwcXeqDMYKL2FYP90t2b5S1IoGc2io47dj5ZlIC1IZWg==", + "node_modules/@earendil-works/pi-telemetry": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-telemetry/-/pi-telemetry-1.5.2.tgz", + "integrity": "sha512-m+cumjIqNh1aMISi/9ttcG3ZOwIdriPbz/eMyWmRMJCGa/WcgY1RX4lrb7HvsHhSfI/JUeBESA4nOCr8C3y5ow==", "dev": true, "license": "MIT", - "dependencies": { - "get-east-asian-width": "1.6.0", - "marked": "18.0.11" - }, "engines": { "node": ">=22.19.0" } }, - "node_modules/@esbuild/aix-ppc64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", - "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "aix" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-arm": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz", - "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz", - "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz", - "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/darwin-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz", - "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz", - "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz", - "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz", - "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz", - "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz", - "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz", - "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz", - "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz", - "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz", - "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz", - "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz", - "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/linux-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz", - "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/netbsd-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz", - "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz", - "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openbsd-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz", - "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz", - "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/openharmony-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz", - "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openharmony" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz", - "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz", - "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz", - "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz", - "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==", - "cpu": [ - "x64" - ], + "node_modules/@earendil-works/pi-tui": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@earendil-works/pi-tui/-/pi-tui-1.5.2.tgz", + "integrity": "sha512-WK8ih+c88GWizaB79y7Pq3PV7ySf5VI1pZ1i/6aBBjDOAiG2EE3ojKjl+pxQqLfyQGnzHYu4VfakOBJgumuoyw==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "win32" - ], + "dependencies": { + "get-east-asian-width": "1.6.0", + "marked": "18.0.11", + "marked-cjk-friendly": "0.1.2" + }, "engines": { - "node": ">=18" + "node": ">=22.19.0" } }, "node_modules/@google/genai": { @@ -1020,6 +577,13 @@ } } }, + "node_modules/@isaacs/nonrecursive-glob-match": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.1.0.tgz", + "integrity": "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", @@ -2134,48 +1698,6 @@ "dev": true, "license": "MIT" }, - "node_modules/esbuild": { - "version": "0.28.2", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", - "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "bin": { - "esbuild": "bin/esbuild" - }, - "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "@esbuild/aix-ppc64": "0.28.2", - "@esbuild/android-arm": "0.28.2", - "@esbuild/android-arm64": "0.28.2", - "@esbuild/android-x64": "0.28.2", - "@esbuild/darwin-arm64": "0.28.2", - "@esbuild/darwin-x64": "0.28.2", - "@esbuild/freebsd-arm64": "0.28.2", - "@esbuild/freebsd-x64": "0.28.2", - "@esbuild/linux-arm": "0.28.2", - "@esbuild/linux-arm64": "0.28.2", - "@esbuild/linux-ia32": "0.28.2", - "@esbuild/linux-loong64": "0.28.2", - "@esbuild/linux-mips64el": "0.28.2", - "@esbuild/linux-ppc64": "0.28.2", - "@esbuild/linux-riscv64": "0.28.2", - "@esbuild/linux-s390x": "0.28.2", - "@esbuild/linux-x64": "0.28.2", - "@esbuild/netbsd-arm64": "0.28.2", - "@esbuild/netbsd-x64": "0.28.2", - "@esbuild/openbsd-arm64": "0.28.2", - "@esbuild/openbsd-x64": "0.28.2", - "@esbuild/openharmony-arm64": "0.28.2", - "@esbuild/sunos-x64": "0.28.2", - "@esbuild/win32-arm64": "0.28.2", - "@esbuild/win32-ia32": "0.28.2", - "@esbuild/win32-x64": "0.28.2" - } - }, "node_modules/estree-walker": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", @@ -2383,16 +1905,6 @@ "dev": true, "license": "ISC" }, - "node_modules/grok-mermaid": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/grok-mermaid/-/grok-mermaid-0.2.3.tgz", - "integrity": "sha512-/4KopAbsjvuRP9MdPtlDjOHUmUVEohOX73JNcsWpzAtFxh+bq5+Dhb6gzvRieLDwIPQIR3/vy8V1NNTuz4Zsmg==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": ">=18" - } - }, "node_modules/highlight.js": { "version": "10.7.3", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz", @@ -2812,6 +2324,16 @@ "dev": true, "license": "Apache-2.0" }, + "node_modules/lovely-mermaid": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/lovely-mermaid/-/lovely-mermaid-0.3.3.tgz", + "integrity": "sha512-EMLJS934qwt2MLO/a5o+T/89HGbuXZPwmCpHIhHO+DVrm+y5tHlEHgpZzlC2o4yW/rFPHRFO9xSMafzqH4wH5A==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, "node_modules/lru-cache": { "version": "11.5.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.3.tgz", @@ -2845,14 +2367,28 @@ "node": ">= 20" } }, + "node_modules/marked-cjk-friendly": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/marked-cjk-friendly/-/marked-cjk-friendly-0.1.2.tgz", + "integrity": "sha512-GUj8HjiEbur9yhgUo52FBgKizggF1QtT6gVdrYdWW6ZB4lVVjgS3EyyXPyfyRD0V4ghGRPlO7MO80rgSWbm0eA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "marked": ">=15.0.0" + } + }, "node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "version": "11.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.3.tgz", + "integrity": "sha512-iny/40PEGkNJQ5/Pv6z3nm6FbRAby32GeZRjCUJk2WnNDbgPSTcdI+DDvLqsgBdD4cD5sMtMheqPPnehCCa8Nw==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { - "brace-expansion": "^5.0.8" + "@isaacs/nonrecursive-glob-match": "^1.0.3", + "brace-expansion": "^5.0.12" }, "engines": { "node": "18 || 20 || >=22" @@ -3365,9 +2901,9 @@ } }, "node_modules/undici": { - "version": "8.10.2", - "resolved": "https://registry.npmjs.org/undici/-/undici-8.10.2.tgz", - "integrity": "sha512-/y4/bH9YNU5hi9NIrpOuvGXFcxrj3CMrV+/AYpowAYTpHn8gX/XPFjNy766FPoYY0miQhdW977JFWKGNhBdwyQ==", + "version": "8.12.3", + "resolved": "https://registry.npmjs.org/undici/-/undici-8.12.3.tgz", + "integrity": "sha512-+fdndUTwBP86cVjihTp21hZHo7d6oj1c/47XPA3lL8mM0XHs+C4EkcjmgRsFnFk2f/UONGDy9ItBItmXsLOQHw==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index 065fdb7..57b54d2 100644 --- a/package.json +++ b/package.json @@ -39,12 +39,14 @@ }, "peerDependencies": { "@earendil-works/pi-ai": "*", - "@earendil-works/pi-coding-agent": "*" + "@earendil-works/pi-coding-agent": "*", + "typebox": "*" }, "devDependencies": { - "@earendil-works/pi-ai": "^1.0.3", - "@earendil-works/pi-coding-agent": "^1.0.3", + "@earendil-works/pi-ai": "^1.5.2", + "@earendil-works/pi-coding-agent": "^1.5.2", "@types/node": "^26.6.4", + "typebox": "^1.3.27", "typescript": "^7.0.2", "vitest": "^5.0.3" } diff --git a/src/config.ts b/src/config.ts index 457f893..248c1d9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,8 +12,6 @@ export interface ContextKitConfig { methodOrder: Method[]; /** Replace older reads of a file that was read again. */ supersedeReads: boolean; - /** Superseded reads are replaced only within this many newest tokens, to keep the prompt cache. */ - staleSuffixTokens: number; prune: PruneOptions & { enabled: boolean }; shake: ShakeOptions; /** Pruning and shaking must reach this fraction of the threshold, or compaction runs instead. */ @@ -39,7 +37,6 @@ export const DEFAULT_CONFIG: ContextKitConfig = { thresholdPercent: -1, methodOrder: [...METHODS], supersedeReads: true, - staleSuffixTokens: 8_000, prune: { enabled: true, protectTokens: 40_000, @@ -154,11 +151,6 @@ export function readConfig(raw: unknown): ConfigResult { ); const methods = root.get("methodOrder", methodOrder, d.methodOrder); const supersedeReads = root.get("supersedeReads", boolean, d.supersedeReads); - const staleSuffixTokens = root.get( - "staleSuffixTokens", - count, - d.staleSuffixTokens, - ); const progressRatio = root.get("progressRatio", ratio, d.progressRatio); const p = root.section("prune"); @@ -188,7 +180,6 @@ export function readConfig(raw: unknown): ConfigResult { thresholdPercent, methodOrder: [...new Set(methods.filter(isMethod))], supersedeReads, - staleSuffixTokens, prune, shake, progressRatio, diff --git a/src/context.ts b/src/context.ts index 3711bfb..8b61d03 100644 --- a/src/context.ts +++ b/src/context.ts @@ -46,21 +46,6 @@ export function messageTokens(message: AgentMessage): number { return estimateTokens(message); } -/** Tokens from each entry through the end of the projected context. */ -export function suffixTokens( - entries: readonly ProjectedSessionEntry[], -): number[] { - const suffix = new Array(entries.length).fill(0); - let total = 0; - for (let i = entries.length - 1; i >= 0; i--) { - for (const message of entries[i]?.messages ?? []) { - if (message.role !== "system") total += estimateTokens(message); - } - suffix[i] = total; - } - return suffix; -} - export function withContent( message: EditableMessage, content: ContextEditableContent, diff --git a/src/maintain.ts b/src/maintain.ts index 8a8dc9e..85b6c9b 100644 --- a/src/maintain.ts +++ b/src/maintain.ts @@ -12,7 +12,7 @@ import { supersededReads } from "./stale.ts"; export type MaintenanceOptions = Pick< ContextKitConfig, - "supersedeReads" | "staleSuffixTokens" | "prune" | "progressRatio" + "supersedeReads" | "prune" | "progressRatio" > & { /** Undefined leaves the context unshaken. */ shake: ShakeOptions | undefined; @@ -35,24 +35,19 @@ export interface MaintenancePlan { } /** - * Plans context edits for one turn boundary. Any context edit makes Pi estimate the context - * from characters, so edits are kept only when that estimate stays on the same side of the - * compaction threshold, or when pruning and shaking make compaction unnecessary. + * Plans context edits for one turn boundary. Any context edit changes the prompt prefix, so the + * provider cache and, on Anthropic, the thinking blocks after the edit are lost. Edits are + * therefore made only above the compaction threshold, in one batch. */ export function planMaintenance(input: MaintenanceInput): MaintenancePlan { const { options } = input; const unchanged = { edits: [], tokens: input.tokens }; + if (input.tokens <= input.threshold) return unchanged; + const stale = options.supersedeReads - ? supersededReads(input.entries, input.edited, options.staleSuffixTokens) + ? supersededReads(input.entries, input.edited) : []; const afterStale = applyEdits(input.entries, stale); - const staleTokens = contextTokens(projectedMessages(afterStale)); - - if (input.tokens <= input.threshold) { - return stale.length > 0 && staleTokens <= input.threshold - ? { edits: stale, tokens: staleTokens } - : unchanged; - } const edited = new Set([ ...input.edited, @@ -71,7 +66,9 @@ export function planMaintenance(input: MaintenanceInput): MaintenancePlan { return edits.length > 0 ? { edits, tokens: reducedTokens } : unchanged; } // Compaction runs next. Stale edits only shrink what it has to summarize. - return stale.length > 0 ? { edits: stale, tokens: staleTokens } : unchanged; + return stale.length > 0 + ? { edits: stale, tokens: contextTokens(projectedMessages(afterStale)) } + : unchanged; } function latestPerTarget(edits: readonly Edit[]): Edit[] { diff --git a/src/shake.ts b/src/shake.ts index a92c4e9..bca9114 100644 --- a/src/shake.ts +++ b/src/shake.ts @@ -26,7 +26,8 @@ const BLOCK = /** * Elides large blocks and images from older messages. Tool calls and thinking stay intact, - * so every tool call keeps its result and signed reasoning stays valid. + * so every tool call keeps its result. Signatures stay valid, but Anthropic drops every thinking + * block after the first changed message. */ export function shake( entries: readonly ProjectedSessionEntry[], diff --git a/src/stale.ts b/src/stale.ts index bd59975..3a5807f 100644 --- a/src/stale.ts +++ b/src/stale.ts @@ -4,7 +4,6 @@ import { type Edit, editableMessage, messageTokens, - suffixTokens, withContent, } from "./context.ts"; import { toolCallsById } from "./tool-calls.ts"; @@ -26,16 +25,13 @@ interface NewerReads { /** * Replaces read results that a newer read of the same file makes redundant. * A newer full read covers every older read; a newer ranged read covers only the same range; - * a failed read covers only older failed reads. A candidate and its newer messages must fit - * within `suffixLimit` tokens. + * a failed read covers only older failed reads. */ export function supersededReads( entries: readonly ProjectedSessionEntry[], edited: ReadonlySet, - suffixLimit: number, ): Edit[] { const calls = toolCallsById(entries); - const suffix = suffixTokens(entries); const newer = new Map(); const edits: Edit[] = []; @@ -59,11 +55,7 @@ export function supersededReads( : seen.fullSuccess || (key.range !== undefined && seen.successRanges.has(key.range)); - if ( - superseded && - !edited.has(entry.sourceEntry.id) && - (suffix[i] ?? Number.POSITIVE_INFINITY) <= suffixLimit - ) { + if (superseded && !edited.has(entry.sourceEntry.id)) { const content = [{ type: "text" as const, text: SUPERSEDED_NOTICE }]; if ( messageTokens(withContent(message, content)) < messageTokens(message) diff --git a/test/extension.test.ts b/test/extension.test.ts index a1091ed..ff924e6 100644 --- a/test/extension.test.ts +++ b/test/extension.test.ts @@ -54,7 +54,15 @@ async function start( authPath: join(agentDir, "auth.json"), modelsPath: join(agentDir, "models.json"), }); - modelRuntime.registerNativeProvider(faux.provider); + // Pi 1.0 faux usage counts a session's first prompt as input and cache write; without the cache every version reports the same tokens. + modelRuntime.registerNativeProvider({ + ...faux.provider, + streamSimple: (model, context, options) => + faux.provider.streamSimple(model, context, { + ...options, + cacheRetention: "none", + }), + }); const resourceLoader = new DefaultResourceLoader({ cwd, agentDir, @@ -90,7 +98,7 @@ describe("pi-context-kit inside Pi", () => { ["enabled", true], ["disabled", false], ])( - "replaces an older read of the same file with compaction %s", + "keeps an older read below the threshold with compaction %s", async (_, enabled) => { const { session } = await start( [ @@ -102,18 +110,55 @@ describe("pi-context-kit inside Pi", () => { enabled, ); await session.prompt("Read a.ts twice"); - const edits = session.sessionManager - .getBranch() - .filter((entry) => entry.type === "context_edit"); - expect(edits).toHaveLength(1); expect( - JSON.stringify( - session.sessionManager.buildSessionProjection().messages, - ), - ).toContain("[Superseded by a newer read of this file]"); + session.sessionManager + .getBranch() + .filter((entry) => entry.type === "context_edit"), + ).toEqual([]); }, ); + it("replaces an older read when that brings the context below the threshold", async () => { + const { session } = await start( + [ + fauxAssistantMessage(fauxToolCall("read", { path: "b.ts" })), + fauxAssistantMessage(fauxToolCall("read", { path: "b.ts" })), + fauxAssistantMessage("done"), + ], + 200_000, + true, + { thresholdTokens: 8_000, methodOrder: [] }, + ); + await session.prompt("Read b.ts twice"); + const edits = session.sessionManager + .getBranch() + .filter((entry) => entry.type === "context_edit"); + expect(edits).toHaveLength(1); + expect( + JSON.stringify(session.sessionManager.buildSessionProjection().messages), + ).toContain("[Superseded by a newer read of this file]"); + }); + + // An edit without compaction costs the provider cache again at each turn above the threshold. + it("keeps an older read above the threshold when nothing compacts", async () => { + const { session } = await start( + [ + fauxAssistantMessage(fauxToolCall("read", { path: "a.ts" })), + fauxAssistantMessage(fauxToolCall("read", { path: "a.ts" })), + fauxAssistantMessage("done"), + ], + 200_000, + true, + { thresholdTokens: 1_000, methodOrder: [] }, + ); + await session.prompt("Read a.ts twice"); + expect( + session.sessionManager + .getBranch() + .filter((entry) => entry.type === "context_edit"), + ).toEqual([]); + }); + it("compacts with a handoff note from the live context and Pi's file sections", async () => { let turnOptions: SimpleStreamOptions | undefined; let handoffOptions: SimpleStreamOptions | undefined; @@ -193,7 +238,7 @@ describe("pi-context-kit inside Pi", () => { if (!next) throw new Error("unexpected request"); return next; }; - const { session } = await start(Array(8).fill(reply), 24_000, true, { + const { session } = await start(Array(8).fill(reply), 19_000, true, { asyncEnabled: true, supersedeReads: false, prune: { enabled: false }, @@ -219,6 +264,62 @@ describe("pi-context-kit inside Pi", () => { expect(result.summary).toMatch(/^## Goal\nBackground note/); }); + it.each(["tree", "reload"])( + "cancels an unfinished background note on %s", + async (action) => { + const main = [ + ...Array.from({ length: 3 }, () => + fauxAssistantMessage(fauxToolCall("read", { path: "b.ts" })), + ), + fauxAssistantMessage("done"), + ]; + let noteSignal: AbortSignal | undefined; + const reply: FauxResponseStep = (context, options) => { + if (JSON.stringify(context.messages.at(-1)).includes("handoff note")) { + const signal = options?.signal; + if (!signal) throw new Error("missing note cancellation signal"); + noteSignal = signal; + return new Promise((resolve) => { + signal.addEventListener( + "abort", + () => + resolve(fauxAssistantMessage("", { stopReason: "aborted" })), + { once: true }, + ); + }); + } + const next = main.shift(); + if (!next) throw new Error("unexpected request"); + return next; + }; + const { session } = await start(Array(8).fill(reply), 19_000, true, { + supersedeReads: false, + prune: { enabled: false }, + progressRatio: 1, + }); + await session.prompt("Read b.ts three times"); + expect(noteSignal?.aborted).toBe(false); + try { + if (action === "reload") await session.reload(); + else { + const target = session.sessionManager + .getBranch() + .find( + (entry) => + entry.type === "message" && entry.message.role === "assistant", + ); + if (!target) throw new Error("missing tree navigation target"); + expect(await session.navigateTree(target.id)).toMatchObject({ + cancelled: false, + }); + } + expect(noteSignal?.aborted).toBe(true); + } finally { + await session.reload(); + } + }, + ); + it("tries shake at Pi's threshold instead of waiting for an unfinished note", async () => { const main = [ ...Array.from({ length: 4 }, () => @@ -251,7 +352,7 @@ describe("pi-context-kit inside Pi", () => { if (!next) throw new Error("unexpected request"); return next; }; - const { session, cwd } = await start(Array(12).fill(reply), 24_000, true, { + const { session, cwd } = await start(Array(12).fill(reply), 17_500, true, { supersedeReads: false, prune: { enabled: false }, shake: { protectTokens: 0, minSavings: 1, blockMinTokens: 10 }, @@ -365,7 +466,7 @@ describe("pi-context-kit inside Pi", () => { supersedeReads: false, prune: { enabled: false }, }); - await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(2_500)}`); + await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(5_000)}`); const compactions = session.sessionManager .getBranch() .filter((entry) => entry.type === "compaction"); @@ -401,7 +502,7 @@ describe("pi-context-kit inside Pi", () => { supersedeReads: false, prune: { enabled: false }, }); - await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(2_500)}`); + await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(5_000)}`); const compactions = session.sessionManager .getBranch() .filter((entry) => entry.type === "compaction"); @@ -439,7 +540,7 @@ describe("pi-context-kit inside Pi", () => { supersedeReads: false, prune: { enabled: false }, }); - await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(2_500)}`); + await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(5_000)}`); expect( session.sessionManager .getBranch() @@ -508,7 +609,7 @@ describe("pi-context-kit inside Pi", () => { first?.id ?? null, 0, ); - await session.prompt(`Read b.ts. ${"history ".repeat(2_500)}`); + await session.prompt(`Read b.ts. ${"history ".repeat(5_000)}`); expect(request).toContain(""); expect(request).toContain("Old goal"); }); @@ -538,7 +639,7 @@ describe("pi-context-kit inside Pi", () => { supersedeReads: false, prune: { enabled: false }, }); - await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(2_500)}`); + await session.prompt(`Read b.ts then a.ts. ${"history ".repeat(5_000)}`); expect(summaries).toBe(1); expect(JSON.stringify(session.messages.at(-1))).toContain("done"); }); @@ -630,7 +731,7 @@ describe("pi-context-kit inside Pi", () => { "shakes after a failed handoff with a %i-token context window", async (contextWindow) => { const main = [ - fauxAssistantMessage(["```ts", "x".repeat(40_000), "```"].join("\n")), + fauxAssistantMessage(["```ts", "x".repeat(56_000), "```"].join("\n")), fauxAssistantMessage(fauxToolCall("read", { path: "b.ts" })), fauxAssistantMessage("done"), ]; @@ -741,7 +842,7 @@ describe("pi-context-kit inside Pi", () => { ["soft", "shake", "handoff"], ])("honors automatic priority %s, %s, %s", async (first, second, third) => { const main = [ - fauxAssistantMessage(["```ts", "x".repeat(40_000), "```"].join("\n")), + fauxAssistantMessage(["```ts", "x".repeat(56_000), "```"].join("\n")), fauxAssistantMessage(fauxToolCall("read", { path: "b.ts" })), fauxAssistantMessage("done"), ]; diff --git a/test/maintain.test.ts b/test/maintain.test.ts index 6cb0e3d..f25ad3d 100644 --- a/test/maintain.test.ts +++ b/test/maintain.test.ts @@ -10,9 +10,20 @@ function staleSession() { return { t, old }; } +/** An older read of a.ts, far from the end, and more context than pruning can save. */ +function staleSessionBeforeCompaction() { + const t = new Transcript(); + const old = t.tool("read", { path: "a.ts" }, filler(2_000)); + t.tool("bash", { command: "a" }, filler(21_000)); + t.tool("read", { path: "a.ts" }, filler(2_000)); + t.tool("bash", { command: "b" }, filler(60_000)); + return { t, old }; +} + describe("planMaintenance", () => { - it("applies stale edits below the threshold", () => { - const { t, old } = staleSession(); + // Any edit changes the prompt prefix: the provider cache and the later thinking blocks are lost. + it("applies no edits below the threshold", () => { + const { t } = staleSession(); const plan = planMaintenance({ entries: t.entries(), edited: new Set(), @@ -20,20 +31,38 @@ describe("planMaintenance", () => { tokens: 4_100, threshold: 10_000, }); + expect(plan).toEqual({ edits: [], tokens: 4_100 }); + }); + + it("supersedes older reads anywhere in the context before compaction", () => { + const { t, old } = staleSessionBeforeCompaction(); + const plan = planMaintenance({ + entries: t.entries(), + edited: new Set(), + options: DEFAULT_CONFIG, + tokens: 85_100, + threshold: 70_000, + }); expect(plan.edits.map((edit) => edit.targetId)).toEqual([old]); - expect(plan.tokens).toBeLessThan(2_200); + expect(plan.tokens).toBeLessThan(84_000); }); - it("skips stale edits whose estimate would cross the threshold", () => { - const { t } = staleSession(); + it("supersedes older reads together with pruning", () => { + const t = new Transcript(); + const old = t.tool("read", { path: "a.ts" }, filler(2_000)); + const output = t.tool("bash", { command: "a" }, filler(30_000)); + t.tool("read", { path: "a.ts" }, filler(2_000)); + t.tool("bash", { command: "b" }, filler(41_000)); const plan = planMaintenance({ entries: t.entries(), edited: new Set(), options: DEFAULT_CONFIG, - tokens: 1_000, - threshold: 1_500, + tokens: 75_100, + threshold: 70_000, }); - expect(plan).toEqual({ edits: [], tokens: 1_000 }); + expect(plan.edits.map((edit) => edit.targetId)).toEqual( + expect.arrayContaining([old, output]), + ); }); it("prunes over the threshold when that gets well below it", () => { @@ -84,15 +113,15 @@ describe("planMaintenance", () => { }); it("keeps older reads when supersedeReads is off", () => { - const { t } = staleSession(); + const { t } = staleSessionBeforeCompaction(); const plan = planMaintenance({ entries: t.entries(), edited: new Set(), options: { ...DEFAULT_CONFIG, supersedeReads: false }, - tokens: 4_100, - threshold: 10_000, + tokens: 85_100, + threshold: 70_000, }); - expect(plan).toEqual({ edits: [], tokens: 4_100 }); + expect(plan).toEqual({ edits: [], tokens: 85_100 }); }); it("does not prune when pruning is off", () => { diff --git a/test/recall.test.ts b/test/recall.test.ts index 0bb9e8f..fb7c035 100644 --- a/test/recall.test.ts +++ b/test/recall.test.ts @@ -62,6 +62,22 @@ describe("searchEntries", () => { await expect(pending).rejects.toThrow(/abort/i); }); + it("excludes abandoned branches from search and reads", async () => { + const t = new Transcript(); + const root = t.user("shared history"); + const abandoned = t.assistant("ABANDONED-MARKER"); + t.session.branch(root); + t.assistant("current branch"); + + expect(await searchEntries(t.branch(), { query: "ABANDONED-MARKER" })).toBe( + "No entries match.", + ); + expect(() => readEntry(t.branch(), abandoned, {})).toThrow( + `No entry ${abandoned} on the current branch.`, + ); + expect(t.session.getEntry(abandoned)).toBeDefined(); + }); + it("finds raw content that a context edit hides", async () => { const t = new Transcript(); const id = t.tool("read", { path: "a.ts" }, "secret value"); @@ -90,6 +106,30 @@ describe("readEntry", () => { ); }); + it("keeps raw images after edits but recalls only their MIME type", () => { + const t = new Transcript(); + const image = { + type: "image", + data: "AAAA", + mimeType: "image/png", + } as const; + const id = t.tool("read", { path: "a.png" }, [image]); + t.session.appendContextEdit(id, { + content: [{ type: "text", text: "[image elided]" }], + }); + + const entry = t.session.getEntry(id); + if (entry?.type !== "message" || entry.message.role !== "toolResult") + throw new Error("missing raw image result"); + expect(entry.message.content).toEqual([image]); + expect(readEntry(t.branch(), id, {})).toBe( + "[read result]\n[image image/png]", + ); + expect( + JSON.stringify(t.session.buildSessionProjection().messages), + ).not.toContain('"data":"AAAA"'); + }); + it("describes tool calls and images", () => { const t = new Transcript(); const id = t.tool("read", { path: "a.png" }, [ diff --git a/test/stale.test.ts b/test/stale.test.ts index 0d88842..28b688a 100644 --- a/test/stale.test.ts +++ b/test/stale.test.ts @@ -3,12 +3,8 @@ import { editedEntryIds } from "../src/context.ts"; import { SUPERSEDED_NOTICE, supersededReads } from "../src/stale.ts"; import { filler, Transcript } from "./fixtures.ts"; -function staleIds(t: Transcript, suffixLimit = 8_000): string[] { - return supersededReads( - t.entries(), - editedEntryIds(t.branch()), - suffixLimit, - ).map((edit) => edit.targetId); +function staleIds(t: Transcript): string[] { + return supersededReads(t.entries(), editedEntryIds(t.branch())).map((edit) => edit.targetId); } describe("supersededReads", () => { @@ -16,7 +12,7 @@ describe("supersededReads", () => { const t = new Transcript(); const old = t.tool("read", { path: "a.ts" }, filler(500)); t.tool("read", { path: "a.ts" }, filler(500)); - const edits = supersededReads(t.entries(), new Set(), 8_000); + const edits = supersededReads(t.entries(), new Set()); expect(edits).toEqual([ { targetId: old, content: [{ type: "text", text: SUPERSEDED_NOTICE }] }, ]); @@ -78,21 +74,6 @@ describe("supersededReads", () => { expect(staleIds(t)).not.toContain(success); }); - it("counts the candidate itself against the suffix limit", () => { - const t = new Transcript(); - t.tool("read", { path: "a.ts" }, filler(12_000)); - t.tool("read", { path: "a.ts" }, filler(100)); - expect(staleIds(t, 8_000)).toEqual([]); - }); - - it("skips candidates followed by more than the suffix limit", () => { - const t = new Transcript(); - t.tool("read", { path: "a.ts" }, filler(500)); - t.tool("bash", { command: "ls" }, filler(9_000)); - t.tool("read", { path: "a.ts" }, filler(500)); - expect(staleIds(t)).toEqual([]); - }); - it("skips entries that are already edited or too small to shrink", () => { const t = new Transcript(); const old = t.tool("read", { path: "a.ts" }, filler(500)); From 685fb47153bc8a7006b826acbd1acaa8af4c40ef Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 14:28:32 +0100 Subject: [PATCH 2/4] Publish from GitHub releases, pin workflow actions and test Pi 1.0.3 in CI Align the repository with pi-claude-pro. A GitHub release is now the only release step: its tag sets the version and its generated notes replace CHANGELOG.md, which removes the release PR, the manual tag push, the dispatch, and the release script with its tests. The workflow still requires the owner, a vX.Y.Z tag on main with green CI, and approval of the npm environment. Tags can move; commit SHAs cannot, so workflow actions are pinned and Dependabot keeps them current with a 7-day cooldown. zizmor checks the workflows and CodeQL scans the TypeScript and the workflows. CI now also checks Pi 1.0.3, the oldest supported version. Pi's packages depend on each other with caret ranges, so installing only pi-coding-agent@1.0.3 mixes in newer sub-packages; every Pi package is pinned, as in a real install. --- .github/dependabot.yml | 4 + .github/pull_request_template.md | 1 - .github/workflows/ci.yml | 36 +++- .github/workflows/codeql.yml | 38 +++++ .github/workflows/release.yml | 76 +++------ .github/zizmor.yml | 6 + CHANGELOG.md | 37 ---- CONTRIBUTING.md | 25 ++- README.md | 19 +-- package.json | 6 +- scripts/release.ts | 268 ----------------------------- test/release.test.ts | 285 ------------------------------- tsconfig.json | 2 +- 13 files changed, 118 insertions(+), 685 deletions(-) create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/zizmor.yml delete mode 100644 CHANGELOG.md delete mode 100644 scripts/release.ts delete mode 100644 test/release.test.ts diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 633cb38..9dd8bc8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,6 +4,8 @@ updates: directory: / schedule: interval: weekly + cooldown: + default-days: 7 groups: actions: patterns: ["*"] @@ -11,6 +13,8 @@ updates: directory: / schedule: interval: weekly + cooldown: + default-days: 7 groups: dependencies: patterns: ["*"] diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index f76b1c1..a2989ab 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -9,5 +9,4 @@ ## Checks - [ ] `npm run check` passes. -- [ ] User-visible changes have an entry under `## Unreleased` in `CHANGELOG.md`. - [ ] The README matches the new behavior. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2e10da..a181c0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,11 @@ on: permissions: contents: read +env: + PI_PACKAGES: >- + @earendil-works/chord @earendil-works/pi-agent-core @earendil-works/pi-ai @earendil-works/pi-codemode + @earendil-works/pi-coding-agent @earendil-works/pi-mcp @earendil-works/pi-telemetry @earendil-works/pi-tui + concurrency: group: ci-${{ github.ref }} cancel-in-progress: true @@ -25,23 +30,36 @@ jobs: # Pi requires Node 22.19 or later. node: [22, 24] steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - fetch-depth: 0 persist-credentials: false - - uses: actions/setup-node@v7 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ matrix.node }} cache: npm - run: npm ci - run: npm run check - - name: Validate version change - if: github.event_name == 'pull_request' - run: node scripts/release.ts check "$BASE_SHA" - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} + # Pi's packages depend on each other with caret ranges, so each one is pinned to match a real install. + - name: Check oldest supported Pi + if: matrix.node == 24 + run: | + read -ra packages <<< "$PI_PACKAGES" + npm install --no-save --package-lock=false "${packages[@]/%/@1.0.3}" + npm run check - name: Check latest Pi if: matrix.node == 24 run: | - npm install --no-save --package-lock=false @earendil-works/pi-ai@latest @earendil-works/pi-coding-agent@latest + read -ra packages <<< "$PI_PACKAGES" + npm install --no-save --package-lock=false "${packages[@]/%/@latest}" npm run check + + workflow-security: + name: Workflow security + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1 + with: + advanced-security: false diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..b3ad318 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,38 @@ +name: CodeQL + +on: + push: + branches: [main] + pull_request: + schedule: + - cron: "17 4 * * 1" + +permissions: {} + +concurrency: + group: codeql-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write # upload CodeQL results + strategy: + fail-fast: false + matrix: + language: [actions, javascript-typescript] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + with: + languages: ${{ matrix.language }} + build-mode: none + queries: security-and-quality + - uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 + with: + category: /language:${{ matrix.language }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7511249..cd811ae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,9 @@ name: Publish release -run-name: Publish ${{ inputs.tag }} +run-name: Publish ${{ github.event.release.tag_name }} on: - workflow_dispatch: - inputs: - tag: - description: 'Existing tag to publish to npm (latest), for example v1.2.3' - required: true - type: string + release: + types: [published] permissions: contents: read @@ -22,68 +18,42 @@ concurrency: jobs: release: - if: github.ref == format('refs/tags/{0}', inputs.tag) && github.actor == github.repository_owner && github.triggering_actor == github.repository_owner + name: Publish + if: github.actor == github.repository_owner && github.triggering_actor == github.repository_owner && !github.event.release.prerelease runs-on: ubuntu-latest environment: npm permissions: - actions: read - contents: write - id-token: write + actions: read # read CI runs of the release commit + id-token: write # npm trusted publishing and provenance steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ github.sha }} fetch-depth: 0 persist-credentials: false - - uses: actions/setup-node@v7 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24 registry-url: https://registry.npmjs.org - cache: npm - - name: Resolve and validate the requested tag - id: target - run: node scripts/release.ts target "$RELEASE_TAG" >> "$GITHUB_OUTPUT" - env: - RELEASE_TAG: ${{ inputs.tag }} - - name: Require successful CI on the exact commit + package-manager-cache: false + - name: Require a tested main commit run: | - test "$COMMIT" = "$GITHUB_SHA" - conclusion=$(gh api --paginate "repos/$GITHUB_REPOSITORY/actions/workflows/ci.yml/runs?head_sha=$COMMIT&branch=main" | jq --slurp --raw-output '[.[].workflow_runs[]] | max_by(.run_number) | .conclusion') + if [[ ! "$TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then + echo "Release tag must be vX.Y.Z, got $TAG." >&2 + exit 1 + fi + git merge-base --is-ancestor "$GITHUB_SHA" origin/main + conclusion=$(gh api --paginate "repos/$GITHUB_REPOSITORY/actions/workflows/ci.yml/runs?head_sha=$GITHUB_SHA&branch=main" | jq --slurp --raw-output '[.[].workflow_runs[]] | max_by(.run_number) | .conclusion') if [ "$conclusion" != "success" ]; then - echo "The latest CI run for $COMMIT on main must succeed before publication." >&2 + echo "The latest CI run for $GITHUB_SHA on main must succeed before publication." >&2 exit 1 fi - printf '### Publication target\n- Tag: `%s`\n- Commit: `%s`\n' "$RELEASE_TAG" "$COMMIT" >> "$GITHUB_STEP_SUMMARY" env: GH_TOKEN: ${{ github.token }} - COMMIT: ${{ steps.target.outputs.commit }} - RELEASE_TAG: ${{ inputs.tag }} + TAG: ${{ github.event.release.tag_name }} - run: npm ci - - run: npm run check - - name: Check existing publication and tag identity - id: publication - run: | - git fetch --no-tags origin "refs/tags/$RELEASE_TAG" - test "$(git rev-parse 'FETCH_HEAD^{commit}')" = "$COMMIT" - node scripts/release.ts notes "$VERSION" > "$RUNNER_TEMP/notes.md" - name=$(node -p 'require("./package.json").name') - published=$(node scripts/release.ts published "$name" "$VERSION" "$COMMIT") - released=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq ".[] | select(.tag_name == \"$RELEASE_TAG\" and .draft == false) | .id") - { - echo "published=$published" - echo "released=$released" - } >> "$GITHUB_OUTPUT" - env: - GH_TOKEN: ${{ github.token }} - RELEASE_TAG: ${{ inputs.tag }} - VERSION: ${{ steps.target.outputs.version }} - COMMIT: ${{ steps.target.outputs.commit }} - name: Publish to npm - if: steps.publication.outputs.published == 'false' - run: npm publish - - name: Create the GitHub release - if: steps.publication.outputs.released == '' - run: gh release create "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --verify-tag --title "$RELEASE_TAG" --notes-file "$RUNNER_TEMP/notes.md" + run: | + npm version "${TAG#v}" --no-git-tag-version --allow-same-version + npm publish env: - GH_TOKEN: ${{ github.token }} - RELEASE_TAG: ${{ inputs.tag }} + TAG: ${{ github.event.release.tag_name }} diff --git a/.github/zizmor.yml b/.github/zizmor.yml new file mode 100644 index 0000000..0326655 --- /dev/null +++ b/.github/zizmor.yml @@ -0,0 +1,6 @@ +rules: + adhoc-packages: + ignore: + # Testing against the oldest supported and the latest published Pi is the purpose of these steps. + - ci.yml:47 + - ci.yml:53 diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 3fb8989..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,37 +0,0 @@ -# Changelog - -## Unreleased - -- Replace superseded reads only above the threshold, in one batch with pruning and shaking, and anywhere in the context. Without a compaction, keep edits only when they bring the context to the threshold or below, so they do not repeat at each turn. Every context edit makes the provider miss its cache for the later text, and Anthropic drops every later thinking block. In local sessions, the estimated cache cost of these edits was about 4.8 times the input tokens they saved. -- Remove the `staleSuffixTokens` setting. A configured value now reports "is not a setting". -- Cancel obsolete background handoff requests immediately after session-tree navigation. -- Clarify that recall retrieves text only from the current branch, represents images by MIME type, and does not delete original session entries. -- Document the Pi development baseline and existing locked/latest-version CI checks. - -## 0.2.1 - -- Rewrite the README for users who do not know Pi internals: it explains the terms, the sequence of a session, and each setting with its default and an example. - -## 0.2.0 - -- Send handoff note requests with the session's thinking level and tool choice, so Anthropic reuses the cached conversation instead of re-billing it; reject notes that call a tool. -- `soft` now writes Pi's summary at `thresholdTokens` or `thresholdPercent`, so an earlier threshold compacts even when no handoff note is available. Before, Pi compacted only at its own threshold. -- Keep older read results when a newer full or ranged read is truncated, count the replaced read in the stale suffix budget, and preserve user-role messages during shaking. -- Bound recall regex searches in a worker and propagate cancellation; keep regex syntax errors and result paging. -- Reject length-truncated or oversized handoff notes, validate retained-context budgets, and use only ready background notes during native, manual, and overflow compaction. -- Apply the configured strategy order at both custom and Pi thresholds, including while a background note is unfinished; scale the background-note lead with small thresholds. -- Preserve projected retained history after earlier compactions and context edits; keep Pi's token estimate when maintenance makes no edits. -- Clarify measured provider behavior, fallback paths, and metadata-only image recall. - -- `contextKit` settings, named after the `compaction.*` settings of oh-my-pi: `enabled`, `thresholdTokens`, `thresholdPercent`, `methodOrder`, `asyncEnabled`, `supersedeReads`, and the prune and shake budgets. -- An earlier threshold compacts at the end of a turn, without interrupting the run. -- The background note starts one eighth of the threshold early, capped at 32,000 tokens. -- By default, a handoff note is tried before shaking. -- A failed threshold note is not retried until the next compaction. - -## 0.1.0 - -- Superseded read replacement at the end of each turn. -- Pruning of old tool outputs and elision of old blocks and images above the compaction threshold. -- Handoff compaction from the live context, with a background note near the threshold. -- `recall` tool for the full session history. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af2591c..7fb23be 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,9 +11,9 @@ npm ci npm run check ``` -`npm run check` validates package and lockfile metadata, release notes, TypeScript, and the offline tests. The tests use Pi's faux provider, not a real model. +`npm run check` validates TypeScript and the offline tests. The tests use Pi's faux provider, not a real model. -CI also installs the latest published Pi packages on Node 24 and reruns these checks. It runs weekly, even without repository changes. +CI also installs Pi `1.0.3`, the oldest supported version, and the latest published Pi packages on Node 24, and reruns these checks. It runs weekly, even without repository changes. Keep the lockfile baseline reproducible; do not replace it with an unbounded dependency tree. Host-provided peer dependencies stay `*`. For an optional manual test in Pi: @@ -31,7 +31,7 @@ Do not load another copy of this extension in the same session. - Prefer existing Pi APIs and small changes over new dependencies or abstractions. - Add a regression test for a bug and check that it fails before the fix. - Do not weaken tests or input validation to pass checks. -- Describe user-visible changes under `Unreleased` in `CHANGELOG.md`. +- Give the pull request a title that describes the user-visible change. Release notes are generated from these titles. - Never include credentials, account data, or private conversation content in commits, screenshots, or logs. ## Pull requests @@ -45,16 +45,23 @@ No third-party approval is required, so a solo maintainer can merge after CI suc ## Releases -Release preparation requires Node 24 or later, npm publish permission through the configured workflow, and an authenticated GitHub CLI. +Only the repository owner can publish. A GitHub release triggers **Publish release**, and the owner must approve the `npm` environment deployment. -Follow the [release procedure](README.md#contributing-and-releases). Do not bump the package version in ordinary contribution pull requests. +Do not bump the package version in pull requests. The release tag sets the published version. -Merging a release PR only prepares the version. The PR must update both manifests and include nonempty versioned release notes. CI rejects version rollback. +### Release procedure -Only the repository owner can launch **Publish release** from an explicit `vX.Y.Z` tag whose commit belongs to `main`. The owner must also approve the `npm` environment deployment. Pushes and tag creation do not publish. +1. Wait for CI to succeed on the `main` commit you want to publish. +2. On GitHub, open **Releases > Draft a new release**. +3. Create the tag `vX.Y.Z` on `main`. Choose `patch` for fixes, `minor` for compatible features, or `major` for breaking changes. +4. Select **Generate release notes**, then **Publish release**. +5. Approve the `npm` environment deployment in the Actions run. -Retry a failed release from its original Actions run and tag. Do not move any release tag or reuse its version for different code. -If the code needs a fix, open another release PR with a new version instead. +The workflow rejects a release that is not from the owner, a prerelease, a tag that is not `vX.Y.Z`, a commit outside `main`, or a commit without successful CI. It runs `npm run check`, sets the package version from the tag and publishes with npm provenance. A new npm publication updates the `latest` dist-tag. + +Releases and `v*` tags are immutable. If publication fails for an external cause, use **Re-run failed jobs** on the original run. If the code needs a fix, publish a new version. + +The workflow uses npm trusted publishing, so the repository stores no npm token. Configure the npm trusted publisher for this repository, `release.yml`, and the GitHub environment `npm`. Restrict that environment to tags `v*`, with the owner as its required reviewer and self-review allowed. ## Security diff --git a/README.md b/README.md index cf63fe0..e654c44 100644 --- a/README.md +++ b/README.md @@ -542,24 +542,7 @@ Host-provided peer dependencies use `"*"`, as required by Pi's package guide. Th ## Contributing and releases -See [CONTRIBUTING.md](CONTRIBUTING.md) for local checks and pull requests. Report vulnerabilities through [SECURITY.md](SECURITY.md), not public issues. - -1. Open a pull request. CI runs `npm run check` on Node 22 and 24. -2. Add user-visible changes under `## Unreleased` in `CHANGELOG.md`. -3. Choose `patch` for fixes, `minor` for compatible features, or `major` for breaking changes. -4. Run `npm run release -- ` from an up-to-date, clean `main`. This opens a release PR with matching package and lockfile versions, versioned notes, and an empty `Unreleased` section. -5. Merge the release PR, then wait for CI to succeed on the exact `main` commit you want to publish. -6. Create `vX.Y.Z` at that commit and push that tag. The tag must match the package version. Release tags cannot be moved or deleted. -7. As the repository owner, launch **Publish release** at that tag: `gh workflow run release.yml --ref vX.Y.Z -f tag=vX.Y.Z`. -8. Approve the `npm` environment deployment. The owner can approve their own run; no third-party approval is needed. - -Merges, pushes, and tag creation never publish. The manual workflow requires an existing stable-version tag, matching manifests and release notes, and successful CI on its exact commit. That commit must belong to `main`. The dispatch ref and input tag must match. Running from the tag keeps npm provenance tied to the selected commit. - -The workflow tests and publishes that commit, not the current tip of `main`, then creates the GitHub release. A new npm publication updates the `latest` dist-tag. - -If publication fails, fix the cause and use **Re-run failed jobs** on the original run, with the same tag. An existing npm version must have the same source commit; mismatches fail instead of overwriting a release. For code changes, prepare a new version and tag. npm can take time to make an accepted publication visible. - -The workflow uses npm trusted publishing, so the repository stores no npm token. Configure the npm trusted publisher for this repository, `release.yml`, and the GitHub environment `npm`. Restrict that environment to tags `v*`, with the owner as its required reviewer and self-review allowed. The workflow checks that the tagged commit belongs to `main`. Protect `v*` tags from updates and deletion, with no bypass actors. Keep these repository protections enabled to preserve release identity across retries. +See [CONTRIBUTING.md](CONTRIBUTING.md) for local checks, pull requests and releases. Report vulnerabilities through [SECURITY.md](SECURITY.md), not public issues. ## License diff --git a/package.json b/package.json index 57b54d2..6b8909d 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ ], "files": [ "extensions", - "src", - "CHANGELOG.md" + "src" ], "pi": { "extensions": [ @@ -32,9 +31,8 @@ ] }, "scripts": { - "check": "node scripts/release.ts check && tsc --noEmit && vitest --run", + "check": "tsc --noEmit && vitest --run", "test": "vitest --run", - "release": "node scripts/release.ts prepare", "prepublishOnly": "test -n \"$GITHUB_ACTIONS\" || test \"$(npm whoami)\" = hugolopes45 || { echo 'Publish only as the npm user hugolopes45.' >&2; exit 1; }; npm run check" }, "peerDependencies": { diff --git a/scripts/release.ts b/scripts/release.ts deleted file mode 100644 index 3e339f3..0000000 --- a/scripts/release.ts +++ /dev/null @@ -1,268 +0,0 @@ -import { execFileSync } from "node:child_process"; -import { readFileSync, writeFileSync } from "node:fs"; -import { isRecord } from "../src/config.ts"; - -const UNRELEASED = "## Unreleased"; - -function parse(version: string): [number, number, number] { - const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version); - if (!match) throw new Error(`Expected a version x.y.z, got "${version}".`); - return [Number(match[1]), Number(match[2]), Number(match[3])]; -} - -/** The version after `current`, from a bump name or an explicit newer version. */ -export function nextVersion(current: string, request: string): string { - const [major, minor, patch] = parse(current); - if (request === "major") return `${major + 1}.0.0`; - if (request === "minor") return `${major}.${minor + 1}.0`; - if (request === "patch") return `${major}.${minor}.${patch + 1}`; - const next = parse(request); - const order = next[0] - major || next[1] - minor || next[2] - patch; - if (order <= 0) - throw new Error(`Version ${request} must be newer than ${current}.`); - return request; -} - -/** Index range of the body of the `heading` section, or undefined. */ -function section( - changelog: string, - heading: string, -): { start: number; end: number } | undefined { - const lines = changelog.split(/\r?\n/); - const at = lines.indexOf(heading); - if (at < 0) return undefined; - const after = lines.slice(at + 1).findIndex((line) => line.startsWith("## ")); - return { start: at + 1, end: after < 0 ? lines.length : at + 1 + after }; -} - -function body(changelog: string, heading: string): string { - const range = section(changelog, heading); - const text = range - ? changelog.split(/\r?\n/).slice(range.start, range.end).join("\n").trim() - : ""; - if (!text) throw new Error(`CHANGELOG.md needs entries under "${heading}".`); - return text; -} - -/** The CHANGELOG entries of `version`. */ -export function releaseNotes(changelog: string, version: string): string { - return body(changelog, `## ${version}`); -} - -export function stampUnreleased(changelog: string, version: string): string { - parse(version); - body(changelog, UNRELEASED); - if (section(changelog, `## ${version}`)) - throw new Error(`CHANGELOG.md version ${version} already exists.`); - return changelog.replace( - /^## Unreleased\r?$/m, - `${UNRELEASED}\n\n## ${version}`, - ); -} - -function packageInfo(value: unknown): { name: string; version: string } { - if ( - !isRecord(value) || - typeof value.name !== "string" || - typeof value.version !== "string" - ) - throw new Error("Invalid package manifest: name and version are required."); - parse(value.version); - return { name: value.name, version: value.version }; -} - -export function validateRelease( - manifest: unknown, - lockfile: unknown, - changelog: string, -): { name: string; version: string } { - const info = packageInfo(manifest); - const lock = packageInfo(lockfile); - if (!isRecord(lockfile) || !isRecord(lockfile.packages)) - throw new Error("package-lock.json is missing root package metadata."); - const root = packageInfo(lockfile.packages[""]); - if ( - info.name !== lock.name || - info.version !== lock.version || - info.name !== root.name || - info.version !== root.version - ) - throw new Error( - "package.json and package-lock.json must have matching names and versions.", - ); - releaseNotes(changelog, info.version); - return info; -} - -export function releasePlan( - previous: unknown, - manifest: unknown, - lockfile: unknown, - changelog: string, -): { version: string; changed: boolean } { - const { version } = validateRelease(manifest, lockfile, changelog); - const before = packageInfo(previous).version; - const changed = version !== before; - if (changed) nextVersion(before, version); - return { version, changed }; -} - -/** Whether npm has `name@version`. Other registry failures throw. */ -export async function isPublished( - name: string, - version: string, - expectedCommit: string, - get: typeof fetch = fetch, -): Promise { - const response = await get( - `https://registry.npmjs.org/${encodeURIComponent(name)}`, - ); - if (response.status === 404) return false; - if (!response.ok) - throw new Error(`npm registry answered ${response.status} for ${name}.`); - const document: unknown = await response.json(); - if (!isRecord(document) || !isRecord(document.versions)) - throw new Error( - "Invalid npm registry response: expected package versions.", - ); - if (!Object.hasOwn(document.versions, version)) return false; - const published = document.versions[version]; - if (!isRecord(published) || published.gitHead !== expectedCommit) - throw new Error( - `npm version ${version} belongs to a different or unknown commit.`, - ); - return true; -} - -function run(command: string, args: string[]): string { - return execFileSync(command, args, { - encoding: "utf8", - stdio: ["inherit", "pipe", "inherit"], - }).trim(); -} - -export function publicationTarget(tag: string): { - version: string; - commit: string; -} { - if (!/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(tag)) - throw new Error("Expected a release tag vX.Y.Z."); - const commit = run("git", [ - "rev-parse", - "--verify", - `refs/tags/${tag}^{commit}`, - ]); - run("git", ["merge-base", "--is-ancestor", commit, "origin/main"]); - const manifest: unknown = JSON.parse( - run("git", ["show", `${commit}:package.json`]), - ); - const lockfile: unknown = JSON.parse( - run("git", ["show", `${commit}:package-lock.json`]), - ); - const changelog = run("git", ["show", `${commit}:CHANGELOG.md`]); - const { version } = validateRelease(manifest, lockfile, changelog); - if (tag !== `v${version}`) - throw new Error("Release tag and package version must match."); - return { version, commit }; -} - -function prepare(request: string): void { - if (run("git", ["branch", "--show-current"]) !== "main") - throw new Error("Run the release from main."); - if (run("git", ["status", "--porcelain"])) - throw new Error("Commit or stash your changes first."); - run("git", ["fetch", "origin", "main"]); - if ( - run("git", ["rev-parse", "HEAD"]) !== - run("git", ["rev-parse", "origin/main"]) - ) - throw new Error("Local main differs from origin/main. Pull or push first."); - - const current: unknown = JSON.parse( - readFileSync("package.json", "utf8"), - ).version; - if (typeof current !== "string") - throw new Error("package.json has no version."); - const version = nextVersion(current, request); - const changelog = stampUnreleased( - readFileSync("CHANGELOG.md", "utf8"), - version, - ); - - const branch = `release/v${version}`; - run("git", ["switch", "--create", branch]); - writeFileSync("CHANGELOG.md", changelog); - run("npm", ["version", version, "--no-git-tag-version"]); - execFileSync("npm", ["run", "check"], { stdio: "inherit" }); - run("git", ["add", "package.json", "package-lock.json", "CHANGELOG.md"]); - run("git", ["commit", "--message", `Release ${version}`]); - run("git", ["push", "--set-upstream", "origin", branch]); - const url = run("gh", [ - "pr", - "create", - "--base", - "main", - "--head", - branch, - "--title", - `Release ${version}`, - "--body", - `${releaseNotes(changelog, version)}\n\nMerging only prepares ${version}. The owner must tag the tested main commit and manually run Publish release to publish it.`, - "--assignee", - "@me", - ]); - console.log(url); -} - -function check(base: string | undefined): void { - const manifest: unknown = JSON.parse(readFileSync("package.json", "utf8")); - const lockfile: unknown = JSON.parse( - readFileSync("package-lock.json", "utf8"), - ); - const changelog = readFileSync("CHANGELOG.md", "utf8"); - if (base === undefined) { - validateRelease(manifest, lockfile, changelog); - return; - } - if (!/^[a-f0-9]{40}$/.test(base)) - throw new Error("Expected a base commit SHA."); - const previous: unknown = JSON.parse( - run("git", ["show", `${base}:package.json`]), - ); - const plan = releasePlan(previous, manifest, lockfile, changelog); - console.log(`version=${plan.version}\nchanged=${plan.changed}`); -} - -async function main(args: string[]): Promise { - const [command, ...rest] = args; - if (rest.some((argument) => argument === "")) - throw new Error("Release arguments must not be empty."); - switch (`${command}/${rest.length}`) { - case "prepare/1": - return prepare(rest[0]); - case "notes/1": - console.log(releaseNotes(readFileSync("CHANGELOG.md", "utf8"), rest[0])); - return; - case "published/3": - console.log(await isPublished(rest[0], rest[1], rest[2])); - return; - case "check/0": - case "check/1": - return check(rest[0]); - case "target/1": { - const target = publicationTarget(rest[0]); - console.log(`version=${target.version}\ncommit=${target.commit}`); - return; - } - } - throw new Error( - "Usage: release.ts prepare | notes | published | check [base-commit] | target ", - ); -} - -if (import.meta.main) { - main(process.argv.slice(2)).catch((error: unknown) => { - console.error(error instanceof Error ? error.message : String(error)); - process.exitCode = 1; - }); -} diff --git a/test/release.test.ts b/test/release.test.ts deleted file mode 100644 index 81a0aca..0000000 --- a/test/release.test.ts +++ /dev/null @@ -1,285 +0,0 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; - -const git = vi.hoisted(() => - vi.fn<(command: string, args: string[]) => string>(), -); -vi.mock("node:child_process", () => ({ execFileSync: git })); -import { - isPublished, - nextVersion, - releaseNotes, - stampUnreleased, - validateRelease, - releasePlan, - publicationTarget, -} from "../scripts/release.ts"; - -const changelog = `# Changelog - -## Unreleased - -- New thing. - -## 0.2.0 - -- Settings. -- Early compaction. - -## 0.1.0 - -- First release. -`; - -describe("nextVersion", () => { - it("bumps the requested part", () => { - expect(nextVersion("1.2.3", "patch")).toBe("1.2.4"); - expect(nextVersion("1.2.3", "minor")).toBe("1.3.0"); - expect(nextVersion("1.2.3", "major")).toBe("2.0.0"); - }); - - it("accepts an explicit newer version", () => { - expect(nextVersion("1.2.3", "1.10.0")).toBe("1.10.0"); - }); - - it("rejects an older, equal or malformed version", () => { - expect(() => nextVersion("1.2.3", "1.2.3")).toThrow("newer than 1.2.3"); - expect(() => nextVersion("1.2.3", "1.1.9")).toThrow("newer than 1.2.3"); - expect(() => nextVersion("1.2.3", "1.3")).toThrow("x.y.z"); - expect(() => nextVersion("1.2.3", "v1.3.0")).toThrow("x.y.z"); - }); -}); - -describe("releaseNotes", () => { - it("returns the section of that version", () => { - expect(releaseNotes(changelog, "0.2.0")).toBe( - "- Settings.\n- Early compaction.", - ); - expect(releaseNotes(changelog, "0.1.0")).toBe("- First release."); - }); - - it("rejects a missing or empty section", () => { - expect(() => releaseNotes(changelog, "9.9.9")).toThrow("## 9.9.9"); - expect(() => releaseNotes("## 1.0.0\n\n## 0.9.0\n- x", "1.0.0")).toThrow( - "## 1.0.0", - ); - }); -}); - -describe("stampUnreleased", () => { - it("names the Unreleased section after the version", () => { - const stamped = stampUnreleased(changelog, "0.3.0"); - expect(stamped).toContain("## 0.3.0\n\n- New thing."); - expect(stamped).toContain("## Unreleased\n\n## 0.3.0"); - expect(releaseNotes(stamped, "0.2.0")).toBe( - "- Settings.\n- Early compaction.", - ); - }); - - it("rejects stamping an already documented version", () => { - expect(() => stampUnreleased(changelog, "0.2.0")).toThrow("already exists"); - }); - - it("keeps the next Unreleased section with CRLF input", () => { - const stamped = stampUnreleased( - changelog.replaceAll("\n", "\r\n"), - "0.3.0", - ); - expect(releaseNotes(stamped, "0.3.0")).toBe("- New thing."); - expect(stamped).toMatch(/## Unreleased\r?\n\r?\n## 0.3.0/); - }); - - it("rejects a missing or empty Unreleased section", () => { - expect(() => - stampUnreleased("# Changelog\n\n## 0.1.0\n- x", "0.2.0"), - ).toThrow("## Unreleased"); - expect(() => - stampUnreleased("## Unreleased\n\n## 0.1.0\n- x", "0.2.0"), - ).toThrow("## Unreleased"); - }); -}); - -const manifest = { name: "pi-context-kit", version: "0.2.0" }; -const lockfile = { ...manifest, packages: { "": manifest } }; - -describe("validateRelease", () => { - it("accepts matching manifests and release notes", () => { - expect(validateRelease(manifest, lockfile, changelog)).toEqual(manifest); - }); - - it.each([ - { ...lockfile, version: "0.1.0" }, - { ...lockfile, packages: { "": { ...manifest, version: "0.1.0" } } }, - { ...lockfile, name: "another-package" }, - { ...lockfile, packages: { "": { ...manifest, name: "another-package" } } }, - ])("rejects inconsistent lockfile metadata: %j", (lock) => { - expect(() => validateRelease(manifest, lock, changelog)).toThrow( - "package-lock.json", - ); - }); - - it("rejects missing notes before publication", () => { - expect(() => validateRelease(manifest, lockfile, "# Changelog")).toThrow( - "## 0.2.0", - ); - }); - - it.each([null, {}, { version: 2 }, { name: "pi", version: "0.2" }])( - "rejects malformed manifests: %j", - (value) => { - expect(() => validateRelease(value, lockfile, changelog)).toThrow( - /manifest|version/, - ); - }, - ); -}); - -describe("releasePlan", () => { - it("does not publish dependency or documentation changes without a version bump", () => { - expect( - releasePlan( - manifest, - { ...manifest, dependencies: { changed: "*" } }, - lockfile, - changelog, - ), - ).toEqual({ version: "0.2.0", changed: false }); - }); - - it("plans a release only for an increased validated version", () => { - expect( - releasePlan( - { ...manifest, version: "0.1.0" }, - manifest, - lockfile, - changelog, - ), - ).toEqual({ version: "0.2.0", changed: true }); - }); - - it("rejects version rollback", () => { - expect(() => - releasePlan( - { ...manifest, version: "0.3.0" }, - manifest, - lockfile, - changelog, - ), - ).toThrow("newer than"); - }); -}); - -describe("publicationTarget", () => { - const commit = "a".repeat(40); - beforeEach(() => { - git.mockReset(); - git.mockImplementation((command, args) => { - if (command !== "git") throw new Error("Unexpected external command"); - if (args[0] === "rev-parse") return commit; - if (args[0] === "merge-base") return ""; - if (args[1] === `${commit}:package.json`) return JSON.stringify(manifest); - if (args[1] === `${commit}:package-lock.json`) - return JSON.stringify(lockfile); - if (args[1] === `${commit}:CHANGELOG.md`) return changelog; - throw new Error("Unexpected Git operation"); - }); - }); - - it("selects the commit and metadata from the explicit tag", () => { - expect(publicationTarget("v0.2.0")).toEqual({ version: "0.2.0", commit }); - expect(git).toHaveBeenCalledWith( - "git", - ["rev-parse", "--verify", "refs/tags/v0.2.0^{commit}"], - expect.any(Object), - ); - expect(git).toHaveBeenCalledWith( - "git", - ["merge-base", "--is-ancestor", commit, "origin/main"], - expect.any(Object), - ); - }); - - it.each(["main", "", "0.2.0", "v01.2.0", "v0.2.0~1", "v0.2.0-beta.1"])( - "rejects a non-release tag before Git lookup: %s", - (tag) => { - expect(() => publicationTarget(tag)).toThrow("tag"); - expect(git).not.toHaveBeenCalled(); - }, - ); - - it("rejects a tag that does not match the package version", () => { - expect(() => publicationTarget("v0.3.0")).toThrow("version"); - }); - - it("fails when the tag does not exist", () => { - git.mockImplementationOnce(() => { - throw new Error("Unknown tag"); - }); - expect(() => publicationTarget("v0.2.0")).toThrow("Unknown tag"); - }); - - it("fails when the tagged commit is outside main", () => { - git.mockReturnValueOnce(commit).mockImplementationOnce(() => { - throw new Error("Not an ancestor"); - }); - expect(() => publicationTarget("v0.2.0")).toThrow("Not an ancestor"); - }); -}); - -describe("isPublished", () => { - const registry = - (status: number, document: unknown = {}): typeof fetch => - async () => - new Response(JSON.stringify(document), { status }); - - it("reads the versions of the package", async () => { - const get = registry(200, { - versions: { "0.1.0": { gitHead: "expected" } }, - }); - expect(await isPublished("pi-context-kit", "0.1.0", "expected", get)).toBe( - true, - ); - expect(await isPublished("pi-context-kit", "0.2.0", "expected", get)).toBe( - false, - ); - }); - - it.each(["other", undefined])( - "refuses an existing version with a different or missing commit: %s", - async (gitHead) => { - await expect( - isPublished( - "pi-context-kit", - "0.1.0", - "expected", - registry(200, { versions: { "0.1.0": { gitHead } } }), - ), - ).rejects.toThrow("commit"); - }, - ); - - it("treats an unknown package as unpublished", async () => { - expect( - await isPublished("pi-context-kit", "0.1.0", "expected", registry(404)), - ).toBe(false); - }); - - it.each([null, {}, { versions: [] }, { versions: null }])( - "rejects malformed registry data instead of attempting publication: %j", - async (document) => { - await expect( - isPublished( - "pi-context-kit", - "0.1.0", - "expected", - registry(200, document), - ), - ).rejects.toThrow("Invalid npm registry response"); - }, - ); - - it("fails on other registry errors", async () => { - await expect( - isPublished("pi-context-kit", "0.1.0", "expected", registry(503)), - ).rejects.toThrow("503"); - }); -}); diff --git a/tsconfig.json b/tsconfig.json index fa2602f..90b9b3b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,5 @@ "noUnusedLocals": true, "noUnusedParameters": true }, - "include": ["extensions", "scripts", "src", "test"] + "include": ["extensions", "src", "test"] } From 6c41e77d7005ee2758118dda018f8962af59c49c Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 14:29:38 +0100 Subject: [PATCH 3/4] Update vite to 8.3.8 for its security fixes The locked vite 8.3.2, a dev dependency through vitest, has open advisories for files served outside server.fs.allow and for launch-editor. npm audit now reports no vulnerabilities. --- package-lock.json | 261 +++++++++++++++++++++++++++++++--------------- 1 file changed, 177 insertions(+), 84 deletions(-) diff --git a/package-lock.json b/package-lock.json index c9ca05d..95b6b63 100644 --- a/package-lock.json +++ b/package-lock.json @@ -552,6 +552,43 @@ "node": ">=22.19.0" } }, + "node_modules/@emnapi/core": { + "version": "2.0.0-beta.2", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.2.tgz", + "integrity": "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@emnapi/wasi-threads": "2.2.0", + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/runtime": { + "version": "2.0.0-beta.2", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.2.tgz", + "integrity": "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/wasi-threads": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz", + "integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@google/genai": { "version": "2.21.0", "resolved": "https://registry.npmjs.org/@google/genai/-/genai-2.21.0.tgz", @@ -612,10 +649,33 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@napi-rs/wasm-runtime": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz", + "integrity": "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.3" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1 || 2.0.0-beta.2", + "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2" + } + }, "node_modules/@oxc-project/types": { - "version": "0.152.0", - "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.152.0.tgz", - "integrity": "sha512-oM/5rLBm2tPkg0iBgkH/FOeR3PCDpY19GTgAZjMFM8h9WI9VW7cLgzp6nwtarYKmovavIQZ+Fe/RKX/8C8O/Rw==", + "version": "0.156.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.156.0.tgz", + "integrity": "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==", "dev": true, "license": "MIT", "peer": true, @@ -690,9 +750,9 @@ "license": "BSD-3-Clause" }, "node_modules/@rolldown/binding-android-arm-eabi": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.12.tgz", - "integrity": "sha512-dB/a1214qKfHMXCpgqR4OZT+jS4kTyEXbQGJPqzobt5EwH5rX080pxE37alt3RzvR1bf1Yz/yGqRfrYAxuPw0A==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz", + "integrity": "sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==", "cpu": [ "arm" ], @@ -708,9 +768,9 @@ } }, "node_modules/@rolldown/binding-android-arm64": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.12.tgz", - "integrity": "sha512-7KHFgQ5VJxIHcLlrwrc3Xbds7oTNQT7Pgi9gQCJKrd2VGab/UksIOYp6VD8MzCstGxOKMgNamPwUCfxPdP1OHg==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.19.tgz", + "integrity": "sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==", "cpu": [ "arm64" ], @@ -726,9 +786,9 @@ } }, "node_modules/@rolldown/binding-darwin-arm64": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.12.tgz", - "integrity": "sha512-3YIhqHD96nA5SaYNRBR16HnGv4oavZvXfD/ayHM+oYZ0WD/8lBAtf6zQua4kEyAvpqrluKXl0lnOBoiNby7x9w==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.19.tgz", + "integrity": "sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==", "cpu": [ "arm64" ], @@ -744,9 +804,9 @@ } }, "node_modules/@rolldown/binding-darwin-x64": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.12.tgz", - "integrity": "sha512-UuuJ35MFw4gmFOrE9pEqIV+K3syIKveph+Qc1/ljHZVdoDW4pz/JHR/eMVom+TZGl/5OOvGJOWaOCVt3ZfqhxA==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.19.tgz", + "integrity": "sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==", "cpu": [ "x64" ], @@ -762,9 +822,9 @@ } }, "node_modules/@rolldown/binding-freebsd-x64": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.12.tgz", - "integrity": "sha512-uMvssit0a4W+/7D8CbHUvG719mH3R2jwXAlh/XcPvuHTE0g++LymF88DCGNX0HM2rBOn0xrzgXktIB6fLSJBTQ==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.19.tgz", + "integrity": "sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==", "cpu": [ "x64" ], @@ -780,9 +840,9 @@ } }, "node_modules/@rolldown/binding-linux-arm-gnueabihf": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.12.tgz", - "integrity": "sha512-XcFu0R0xWnwzSf4IQgFH1rJIckPN1pLy2R+4r9IDB7Yfu/ys9cVqfa4pBrMHj7a3gl8mIR4nRNPg0e5IvEVs6g==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.19.tgz", + "integrity": "sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==", "cpu": [ "arm" ], @@ -798,9 +858,9 @@ } }, "node_modules/@rolldown/binding-linux-arm64-gnu": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.12.tgz", - "integrity": "sha512-260UrKgn8tz39ak+SMDOirKzr7V04M9dWPw5llW00SwBivCZoWcRBKV1d8cXnRkUmSZA3BdiUmBHWk7734Ulpw==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.19.tgz", + "integrity": "sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==", "cpu": [ "arm64" ], @@ -819,9 +879,9 @@ } }, "node_modules/@rolldown/binding-linux-arm64-musl": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.12.tgz", - "integrity": "sha512-5YK1I9SqDkbPgc1IA8BgDl34suqUS2q0KWnBrirm0E51YjOs6eo6dV6jbQfNE/argHRSvd0QUGgtpIoYx+WWpw==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.19.tgz", + "integrity": "sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==", "cpu": [ "arm64" ], @@ -840,9 +900,9 @@ } }, "node_modules/@rolldown/binding-linux-ppc64-gnu": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.12.tgz", - "integrity": "sha512-Rkcrmp7eFRg74yL5fXEU91JEWbdEPLevWwGtXpmhbjlD1StScbWTmO94Bhly+Mo+ketKYkdmM1vNUKeWSlx8cQ==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.19.tgz", + "integrity": "sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==", "cpu": [ "ppc64" ], @@ -861,9 +921,9 @@ } }, "node_modules/@rolldown/binding-linux-s390x-gnu": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.12.tgz", - "integrity": "sha512-qvK4DuAsQc2BSjlx+Xr+IzOIvvxbGZqxFwdWfG6F518Erj0GGISyQbJ6pIappnOxlNPzNHvo/L0BwB30GZ+zVw==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.19.tgz", + "integrity": "sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==", "cpu": [ "s390x" ], @@ -882,9 +942,9 @@ } }, "node_modules/@rolldown/binding-linux-x64-gnu": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.12.tgz", - "integrity": "sha512-Q9uLBO53Xd4QIq1WOycVQyPP1O4HhraEV2qqb3uTrnVw6QZih9duY4vNXOivL1xoUS1/z+W8eF4NMfl2a8Sdjw==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.19.tgz", + "integrity": "sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==", "cpu": [ "x64" ], @@ -903,9 +963,9 @@ } }, "node_modules/@rolldown/binding-linux-x64-musl": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.12.tgz", - "integrity": "sha512-3IBxWFMjbOZskDPKv8Lf9BCnahlKuHthWkYnyIxOH/QcJrFcS4EmcenthApkwr/5+nEqZlLzeYbxeMaX7A5u4g==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.19.tgz", + "integrity": "sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==", "cpu": [ "x64" ], @@ -924,9 +984,9 @@ } }, "node_modules/@rolldown/binding-openharmony-arm64": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.12.tgz", - "integrity": "sha512-xtX61xg4LKPkPWilZU1ynKClz5Gj4bf74LML4r3eVLWumKnGjoEr1OSHQhMdbBDoYTi+yjrujvpZe2pUnqCrrA==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.19.tgz", + "integrity": "sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==", "cpu": [ "arm64" ], @@ -941,10 +1001,30 @@ "node": "^20.19.0 || >=22.12.0" } }, + "node_modules/@rolldown/binding-wasm32-wasi": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.2.19.tgz", + "integrity": "sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@emnapi/core": "2.0.0-beta.2", + "@emnapi/runtime": "2.0.0-beta.2", + "@napi-rs/wasm-runtime": "1.2.6" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + } + }, "node_modules/@rolldown/binding-win32-arm64-msvc": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.12.tgz", - "integrity": "sha512-At7fPB6PCaIjzgIhEZFxuT+BBFqiQibJDT4d3PhiR3f4E7bbMZF4aKblbFfEM3sETRDd1YiQx/+U/g/B/ou5Ew==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.19.tgz", + "integrity": "sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==", "cpu": [ "arm64" ], @@ -960,9 +1040,9 @@ } }, "node_modules/@rolldown/binding-win32-x64-msvc": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.12.tgz", - "integrity": "sha512-WIw2haVKwjuYdXkHaoC0mF8Le71TuCBxjrdKqLbJGctbBABj+ClfmNvtbOnzpq3RokNo5+V1qhtSzJyXorsklQ==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.19.tgz", + "integrity": "sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==", "cpu": [ "x64" ], @@ -978,9 +1058,9 @@ } }, "node_modules/@rolldown/pluginutils": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", - "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.0.tgz", + "integrity": "sha512-K+NU2HDCEem4sClgHH4ZZXwdJeNFkJo+hRk479DIwdIviAPN2hFJH1KHHwg8CxHQXvi0M5XY4deTXINfIiSG6w==", "dev": true, "license": "MIT", "peer": true @@ -1086,6 +1166,18 @@ "dev": true, "license": "MIT" }, + "node_modules/@tybys/wasm-util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz", + "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@types/chai": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", @@ -2405,9 +2497,9 @@ "license": "MIT" }, "node_modules/nanoid": { - "version": "3.3.19", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.19.tgz", - "integrity": "sha512-Y2tUNy4ouw6tq5oDSKeQYGOyhkUBhNOcGV/02KC+6kd9eDGqdZd++mjMiIDilrBYvjEnCYvVtsuHCuP+okSfug==", + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", "dev": true, "funding": [ { @@ -2569,9 +2661,9 @@ } }, "node_modules/postcss": { - "version": "8.5.28", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.28.tgz", - "integrity": "sha512-RRuzqDtt5Y9h3quz5hWhK+TPnsmVs6WwSU6LkJMeY4HstUEDuYTG8UJSdawMRzmzAtV+KEoG8N3Qg2qLy5vM/A==", + "version": "8.5.32", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", + "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==", "dev": true, "funding": [ { @@ -2590,9 +2682,9 @@ "license": "MIT", "peer": true, "dependencies": { - "nanoid": "^3.3.18", + "nanoid": "^3.3.20", "picocolors": "^1.1.1", - "source-map-js": "^1.2.1" + "source-map-js": "^1.2.2" }, "engines": { "node": "^10 || ^12 || >=14" @@ -2680,14 +2772,14 @@ } }, "node_modules/rolldown": { - "version": "1.2.12", - "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.12.tgz", - "integrity": "sha512-8wafseiaG80xmXSfqidUNqZcylTlhmPZZt+za2m+js2sFZ8dTNlhIOV2WcbIPx2hgwPBJpEUGFAMZ9bgBBLTSQ==", + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.19.tgz", + "integrity": "sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==", "dev": true, "license": "MIT", "peer": true, "dependencies": { - "@oxc-project/types": "=0.152.0", + "@oxc-project/types": "=0.156.0", "@rolldown/pluginutils": "^1.0.0" }, "bin": { @@ -2697,21 +2789,22 @@ "node": "^20.19.0 || >=22.12.0" }, "optionalDependencies": { - "@rolldown/binding-android-arm-eabi": "1.2.12", - "@rolldown/binding-android-arm64": "1.2.12", - "@rolldown/binding-darwin-arm64": "1.2.12", - "@rolldown/binding-darwin-x64": "1.2.12", - "@rolldown/binding-freebsd-x64": "1.2.12", - "@rolldown/binding-linux-arm-gnueabihf": "1.2.12", - "@rolldown/binding-linux-arm64-gnu": "1.2.12", - "@rolldown/binding-linux-arm64-musl": "1.2.12", - "@rolldown/binding-linux-ppc64-gnu": "1.2.12", - "@rolldown/binding-linux-s390x-gnu": "1.2.12", - "@rolldown/binding-linux-x64-gnu": "1.2.12", - "@rolldown/binding-linux-x64-musl": "1.2.12", - "@rolldown/binding-openharmony-arm64": "1.2.12", - "@rolldown/binding-win32-arm64-msvc": "1.2.12", - "@rolldown/binding-win32-x64-msvc": "1.2.12" + "@rolldown/binding-android-arm-eabi": "1.2.19", + "@rolldown/binding-android-arm64": "1.2.19", + "@rolldown/binding-darwin-arm64": "1.2.19", + "@rolldown/binding-darwin-x64": "1.2.19", + "@rolldown/binding-freebsd-x64": "1.2.19", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.19", + "@rolldown/binding-linux-arm64-gnu": "1.2.19", + "@rolldown/binding-linux-arm64-musl": "1.2.19", + "@rolldown/binding-linux-ppc64-gnu": "1.2.19", + "@rolldown/binding-linux-s390x-gnu": "1.2.19", + "@rolldown/binding-linux-x64-gnu": "1.2.19", + "@rolldown/binding-linux-x64-musl": "1.2.19", + "@rolldown/binding-openharmony-arm64": "1.2.19", + "@rolldown/binding-wasm32-wasi": "1.2.19", + "@rolldown/binding-win32-arm64-msvc": "1.2.19", + "@rolldown/binding-win32-x64-msvc": "1.2.19" } }, "node_modules/safe-buffer": { @@ -2918,17 +3011,17 @@ "license": "MIT" }, "node_modules/vite": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.2.tgz", - "integrity": "sha512-SQr1x6W5vVSbROg7vsyXIaxK9b0G7zsT68acdWWRmnBUsgDieLCRG+Rep9WdZgcposvv/GSnr4GUUBqB3vXq6w==", + "version": "8.3.8", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.8.tgz", + "integrity": "sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==", "dev": true, "license": "MIT", "peer": true, "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", - "postcss": "^8.5.28", - "rolldown": "~1.2.11", + "postcss": "^8.5.32", + "rolldown": "~1.2.18", "tinyglobby": "^0.2.17" }, "bin": { @@ -2945,7 +3038,7 @@ }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", - "@vitejs/devtools": "^0.7.1", + "@vitejs/devtools": "^0.7.1 || ^0.8.0", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", From 2a937119ab7cdf2f3611ca929d0e5c070527d983 Mon Sep 17 00:00:00 2001 From: HugoLopes45 Date: Wed, 11 Nov 2026 14:32:31 +0100 Subject: [PATCH 4/4] Run zizmor from PyPI and keep CodeQL's default setup This repository allows only GitHub-owned actions, so the zizmor action could not start and CI failed at startup. CodeQL's default setup already scans actions and TypeScript weekly here, and GitHub rejects an advanced CodeQL workflow while it is enabled. --- .github/workflows/ci.yml | 7 ++++--- .github/workflows/codeql.yml | 38 ------------------------------------ 2 files changed, 4 insertions(+), 41 deletions(-) delete mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a181c0b..8ad1aae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,6 +60,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1 - with: - advanced-security: false + # Repository settings allow only GitHub-owned actions, so zizmor runs from PyPI. + - run: pipx run zizmor==1.32.0 --format=github .github + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index b3ad318..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: CodeQL - -on: - push: - branches: [main] - pull_request: - schedule: - - cron: "17 4 * * 1" - -permissions: {} - -concurrency: - group: codeql-${{ github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - analyze: - name: Analyze (${{ matrix.language }}) - runs-on: ubuntu-latest - permissions: - contents: read - security-events: write # upload CodeQL results - strategy: - fail-fast: false - matrix: - language: [actions, javascript-typescript] - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 - with: - languages: ${{ matrix.language }} - build-mode: none - queries: security-and-quality - - uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 - with: - category: /language:${{ matrix.language }}