@zew1me/pi-clear 0.0.0-stage → 0.1.1-alpha.162

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @zew1me/pi-clear
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Pi package for the `/clear` extension.
4
+
5
+ Install with:
6
+
7
+ ```bash
8
+ pi install npm:@zew1me/pi-clear@alpha
9
+ ```
@@ -0,0 +1,330 @@
1
+ # Attribution
2
+
3
+ ## Subagent context modes from `nigel-upstart/pi-buildout`
4
+
5
+ - Source: `nigel-upstart/pi-buildout`
6
+ - Canonical repository: <https://github.com/nigel-upstart/pi-buildout>
7
+ - Revision ported: `fe4e325a22cb4489b1c7083b84c5dcf6c79e3f55` (#138)
8
+ - License declared by the source: MIT (Copyright 2026 Nigel Stuke)
9
+
10
+ Copied code: the optional `contextMode` parameter, task-only creation path, mode metadata, documentation, and regression
11
+ tests in `extensions/subagents`. The default `task_compacted` behavior is preserved; `none` skips parent conversation
12
+ access and compaction without changing filesystem, credential, project-instruction, skill, or extension inheritance.
13
+
14
+ The fork's router and OpenTelemetry extensions, generic signaling protocol, final-only wait behavior, newer Pi patch
15
+ sets, internal release packaging, and dependency overrides were intentionally not adopted. This is a direct code port,
16
+ not solely conceptual inspiration; the repository's existing MIT notice covers the copied material.
17
+
18
+ ## Public npm packaging and release automation
19
+
20
+ - Source: `nigel-upstart/pi-buildout`
21
+ - Canonical URL: <https://github.com/nigel-upstart/pi-buildout>
22
+ - Revision reviewed: `5ed4c390ee13fd8c491d964008cf37b459b621d9`
23
+ - Declared license: MIT (Nigel Stuke, 2026); the root `LICENSE` preserves that notice.
24
+
25
+ The separate per-extension package directories, explicit Pi entrypoints, host-provided peer dependencies, minimal
26
+ `prepack` staging, inclusion of license/attribution files, and separate patch-only CLI were informed by the fork's
27
+ `packages/`, `scripts/stage-release-package.mjs`, and package tests. The staging helper structure and portions of the
28
+ archive assertions are modified adaptations of that MIT-licensed code, reduced to this repository's extension set and
29
+ installer; the root `LICENSE` preserves its notice. Public manifests and version-driven release planning/publishing
30
+ logic are authored here. No router, OTel, telemetry defaults, private package names, CodeArtifact endpoints, AWS
31
+ credentials, internal documentation, or manual-only alpha-release restriction are adopted.
32
+
33
+ - Pi package documentation: <https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/packages.md>
34
+ (installed `@earendil-works/pi-coding-agent@1.3.0`; MIT).
35
+ - npm trusted publishing guidance: <https://docs.npmjs.com/trusted-publishers/>
36
+ - GitHub Actions concurrency guidance:
37
+ <https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency>
38
+
39
+ These documentation sources informed explicit resource manifests, runtime/host dependency separation, npm OIDC
40
+ permissions and provenance, and queued non-cancelling release runs. Their prose and example workflows were not copied;
41
+ the workflow extends this repository's existing quality gate. Token-based publishing, git-tag-triggered releases, and Pi
42
+ runtime patching during npm installation were intentionally not adopted.
43
+
44
+ ## Subagent implementations
45
+
46
+ The subagent extension in [`extensions/subagents`](extensions/subagents) was informed by the two implementations
47
+ identified by the project owner. The implementation in this repository is original code, but it deliberately carries
48
+ forward architectural ideas and operational lessons from both projects.
49
+
50
+ ## `nicobailon/pi-subagents`
51
+
52
+ - Repository: <https://github.com/nicobailon/pi-subagents>
53
+ - Initial revision reviewed: `315e1eb1482c4ac2d912a8d95aac4287dc7e60ac`
54
+ - Latest revision reviewed: `1b64c35cc221a23a5b8293deb108a30c0646f520` (`0.48.0` plus unreleased changes)
55
+ - License declared by its package: MIT
56
+
57
+ Ideas and lessons used:
58
+
59
+ - Treat a subagent as a separate Pi process and session rather than an in-process prompt persona.
60
+ - Keep asynchronous child work observable through structured state and transcript tails.
61
+ - Expose explicit lifecycle controls for status inspection, steering, interruption, and stopping.
62
+ - Bound child protocol and diagnostic output so a malformed or noisy child cannot grow parent memory without limit.
63
+ - Make recursive delegation safe by scoping child registries and controls to a parent/child tree rather than a global
64
+ fleet.
65
+ - Validate model choices against Pi's live model registry and preserve a clear fallback path.
66
+ - Clean up child processes and extension-owned resources during Pi session shutdown/reload.
67
+ - Keep the child JSONL protocol bounded while allowing Pi-sized resized-image events; this repository uses a 16 MiB
68
+ per-line ceiling.
69
+ - Sanitize child-controlled transcript and diagnostic text before terminal rendering while retaining the original
70
+ bounded text in the model-facing tool result.
71
+
72
+ We intentionally did **not** reproduce its agent profiles, chain/parallel workflow engine, intercom/supervisor channel,
73
+ watchdog, artifact protocol, slash-command suite, or TUI fleet. This extension stays between that feature-rich design
74
+ and a one-shot runner.
75
+
76
+ ## `elpapi42/pi-minimal-subagent`
77
+
78
+ - Repository: <https://github.com/elpapi42/pi-minimal-subagent>
79
+ - Local revision reviewed: `4c847a37b7d675470a8c5eb50d736d11ceac910a`
80
+ - License declared by its package: MIT
81
+
82
+ Ideas and lessons used:
83
+
84
+ - Keep the model-facing surface centered on one small `subagent` tool.
85
+ - Let ordinary natural-language requests cause the parent model to delegate; do not require a special slash workflow.
86
+ - Launch child Pi with normal extension/resource discovery by default so configured tools and integrations remain
87
+ available.
88
+ - Resolve the Pi executable robustly when Pi is running either as a standalone executable or through Node.
89
+ - Use process isolation and propagate shutdown/abort behavior instead of sharing an agent session object.
90
+ - Keep task dispatch simple and avoid requiring named role/persona files.
91
+
92
+ We extended that minimal shape with persistent RPC children, task-targeted context compaction, automatic model/effort
93
+ classification, direct-child spying and control, and recursive child creation.
94
+
95
+ ## `tintinweb/pi-subagents`
96
+
97
+ - Repository: <https://github.com/tintinweb/pi-subagents>
98
+ - Initial revision reviewed: `c161865a0e8ca12f406041c263ea6c2ca35c74d5` (`0.14.1`)
99
+ - Latest revision reviewed: `4cc473855c2af4f12873c01dad130dd0b3d52639` (`0.15.1`)
100
+ - License: MIT
101
+
102
+ This package was reviewed after the initial implementation as a source of possible follow-up ideas. The review
103
+ considered its in-process SDK sessions, background concurrency queue, graceful turn limits, result/steering tools,
104
+ conversation viewer, context-usage statistics, compact tool-description mode, model-scope guardrail, and resumable
105
+ sessions.
106
+
107
+ Follow-up work adopted three conceptual patterns: explicit, bounded result waiting; richer inspection statistics
108
+ (tokens, cost, context utilization, compactions, and active tool); and treating an output-limit stop with no assistant
109
+ text as a failed child run rather than a successful empty result. They were implemented as original code inside the
110
+ existing single-tool RPC design. No tintinweb code was copied or modified. Major pieces intentionally not adopted
111
+ include named/default agent types, custom agent frontmatter, proactive completion notifications, FleetView/widget UI,
112
+ scheduling, event-bus RPC, persistent memory, worktree isolation, skill preloading, and its three-tool Claude
113
+ Code-compatible surface.
114
+
115
+ ## Pi 1.0.3 `/skills` runtime patch
116
+
117
+ - Source: `@earendil-works/pi-coding-agent@1.0.3`
118
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
119
+ - Upstream revision reviewed: `d78dc83d633229d12f8b79631384c4c2717c399f` (`v1.0.3`), from npm `gitHead`
120
+ - Source archive: `pi-1.0.3-source.tar.gz`, verified against the release's published `SHA256SUMS`
121
+ - License declared by the package: MIT
122
+
123
+ [`pi-overlay/versions/1.0.3/integration.patch`](pi-overlay/versions/1.0.3/integration.patch) adapts the existing opt-in
124
+ skills seam to the MIT-licensed 1.0.3 TypeScript sources and documentation. The generated
125
+ [`skills.patch`](patches/pi-1.0.3/skills.patch) modifies the published resource loader, slash-command list, CLI and
126
+ interactive entry points, and `docs/skills.md`; it adds this repository's original skill-management modules. The patch
127
+ reuses Pi's package/resource discovery, project-trust, and `proper-lockfile` APIs, including the adapted lock pattern
128
+ described under the TypeScript overlay below. It keeps discovered skills catalog-only, enables explicit global,
129
+ repository, and session activation, preserves explicit `--skill` paths when `--no-skills` is used, and leaves Pi's
130
+ unrelated extensions, prompts, themes, packages, providers, trust behavior, and bundled chunks unchanged. It does not
131
+ copy Pi's automatic skill-loading behavior or its runtime implementation into the overlay.
132
+
133
+ The `cli-runtime.js` and `rpc-entry.js` replacements are original wrappers written for this repository, not derived from
134
+ upstream's bundle output; Pi's published `dist/bundle/cli.js` compile-cache loader remains unchanged and is pinned by
135
+ checksum. Source inputs are fetched from the 1.0.3 release archive and npm tarball with committed checksums; no complete
136
+ Pi source checkout is committed.
137
+
138
+ ## Pi 1.0.4 `/skills` runtime patch (retired)
139
+
140
+ - Source: `@earendil-works/pi-coding-agent@1.0.4`
141
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
142
+ - Upstream revision reviewed: `7c10bd4337495ee613f2224843ecdf349b80d1df` (`v1.0.4`), from npm `gitHead`
143
+ - Source archive: `pi-1.0.4-source.tar.gz`, verified against the release's published `SHA256SUMS`
144
+ - License declared by the package: MIT
145
+
146
+ The retired 1.0.4 integration patch adapted the opt-in skills seam to the MIT-licensed TypeScript sources and
147
+ documentation. Its generated patch modified Pi's published resource loader, slash-command list, CLI and interactive
148
+ entry points, and skill documentation. It adds this repository's original skill-management modules and reuses Pi's
149
+ package/resource discovery, project-trust, and `proper-lockfile` APIs. It preserves explicit `--skill` with
150
+ `--no-skills`, makes discovered skills catalog-only until activated, and leaves unrelated extensions, prompts, themes,
151
+ packages, providers, trust behavior, and bundled chunks unchanged. Pi's automatic loading of all discovered skills and
152
+ its skill implementation were not copied into the overlay. The original `cli-runtime.js` and `rpc-entry.js` wrappers are
153
+ reused from the earlier patch; the published `dist/bundle/cli.js` loader is unchanged and checksum-pinned. Inputs come
154
+ from the verified release archive and npm tarball; no complete Pi source checkout is committed.
155
+
156
+ ## Pi 1.1.0 `/skills` runtime patch
157
+
158
+ - Source: `@earendil-works/pi-coding-agent@1.1.0`
159
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
160
+ - Upstream revision reviewed: `abe508e1b89912adde45528136c3221eb69acdd7` (`v1.1.0`)
161
+ - Source archive: `pi-1.1.0-source.tar.gz`, verified against the release's published `SHA256SUMS`
162
+ - License declared by the package: MIT
163
+
164
+ [`pi-overlay/versions/1.1.0/integration.patch`](pi-overlay/versions/1.1.0/integration.patch) adapts the opt-in skills
165
+ seam to Pi 1.1.0's MIT-licensed TypeScript sources and documentation. The generated
166
+ [`skills.patch`](patches/pi-1.1.0/skills.patch) modifies the published resource loader, slash-command list, CLI and
167
+ interactive entry points, and skill documentation. It adds this repository's original skill-management modules and
168
+ reuses Pi's package/resource discovery, project-trust, and `proper-lockfile` APIs. It keeps catalog skills inactive
169
+ until explicitly enabled, preserves explicit `--skill` paths with `--no-skills`, and does not copy Pi's automatic skill
170
+ loading or its skill implementation. The original `cli-runtime.js` wrapper reuses Pi's `setupCli()` path; the original
171
+ `rpc-entry.js` wrapper also preserves Pi 1.1.0's process markers and HTTP-dispatcher setup. The published
172
+ `dist/bundle/cli.js` loader remains unchanged and checksum-pinned. No complete Pi source checkout is committed.
173
+
174
+ ## Pi 1.3.0 `/skills` runtime patch
175
+
176
+ - Source: `@earendil-works/pi-coding-agent@1.3.0`
177
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
178
+ - Upstream revision reviewed: `71023aec1546d6d677a65669c5665c0927ce0dd0` (`v1.3.0`), the commit the lightweight release
179
+ tag points to; the npm registry publishes no `gitHead` for this release, and the commit is unsigned
180
+ - Source archive: `pi-1.3.0-source.tar.gz`, verified against the release's published `SHA256SUMS`
181
+ - npm tarball: `pi-coding-agent-1.3.0.tgz`, pinned by SHA-256 and registry integrity
182
+ - License declared by the package: MIT
183
+
184
+ [`pi-overlay/versions/1.3.0/integration.patch`](pi-overlay/versions/1.3.0/integration.patch) is the 1.1.0 seam rebased
185
+ onto Pi 1.3.0's MIT-licensed TypeScript sources and documentation: the added and removed lines are unchanged, and only
186
+ hunk positions and blob indexes differ. The generated [`skills.patch`](patches/pi-1.3.0/skills.patch) modifies the
187
+ published resource loader, slash-command list, CLI and interactive entry points, and skill documentation, within the
188
+ same 48-line seam budget. It adds this repository's original skill-management modules, which compile byte-identically to
189
+ the 1.1.0 output, and reuses Pi's package/resource discovery, project-trust, and `proper-lockfile` APIs. It keeps
190
+ catalog skills inactive until explicitly enabled, preserves explicit `--skill` paths with `--no-skills`, and does not
191
+ copy Pi's automatic skill loading or its skill implementation. The original `cli-runtime.js` and `rpc-entry.js` wrappers
192
+ are reused byte-for-byte from 1.1.0 because Pi 1.3.0's `src/cli.ts`, `src/rpc-entry.ts`, and `src/cli/setup.ts` are
193
+ unchanged. The published `dist/bundle/cli.js` loader remains unchanged and checksum-pinned. Upstream changes elsewhere
194
+ in 1.3.0, including those near the seams, were not adopted. No complete Pi source checkout is committed.
195
+
196
+ ## Pi 1.6.0 `/skills` runtime patch
197
+
198
+ - Source: `@earendil-works/pi-coding-agent@1.6.0` (MIT)
199
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
200
+ - Upstream revision reviewed: `faac585884ae2c013a6b1400f3e9e77f10b34bac` (`v1.6.0`)
201
+
202
+ The [1.6.0 integration patch](pi-overlay/versions/1.6.0/integration.patch) adapts the existing seam to Pi's 1.6.0
203
+ TypeScript sources and skill documentation, including the changed model-resolver import context in `main.ts`. It reuses
204
+ this repository's shared skill management and CLI/RPC wrappers. The generated patch contains edits to upstream runtime
205
+ files and docs; it does not vendor the upstream tree, adopt Pi's auto-loading policy, or rebuild its bundled chunks.
206
+
207
+ ## Pi 1.5.2 `/skills` runtime patch
208
+
209
+ - Source: [nigel-upstart/pi-buildout](https://github.com/nigel-upstart/pi-buildout), commit
210
+ `0704169310246b2b4fe8144f94ad4314c4a382e3`, MIT.
211
+ - Upstream Pi: [earendil-works/pi](https://github.com/earendil-works/pi), release `v1.5.2`, commit
212
+ `b4afdddf44e059c67ccf5097e5317d913521b470`, MIT.
213
+
214
+ The 1.5.2 integration seam, entrypoint wrappers, and pinned build inputs are adapted from the downstream patch, which
215
+ modifies Pi source and documentation. The generated runtime patch uses this repository's shared overlay and portable
216
+ path behavior rather than copying downstream's generated skill implementation. Other downstream changes and a complete
217
+ Pi source checkout were not adopted.
218
+
219
+ ## Pi 1.4.0 `/skills` runtime patch
220
+
221
+ - Source: `@earendil-works/pi-coding-agent@1.4.0`
222
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
223
+ - Upstream revision reviewed: `4a080252f06caf63a525d7873c5d94d3c23887e0` (`v1.4.0`), the commit referenced by the
224
+ lightweight release tag; the npm registry publishes no `gitHead`, and GitHub reports the commit as unsigned
225
+ - Source archive: `pi-1.4.0-source.tar.gz`, verified against the release's published `SHA256SUMS`
226
+ - npm tarball: `pi-coding-agent-1.4.0.tgz`, pinned by SHA-256 and registry integrity
227
+ - License declared by the package: MIT
228
+
229
+ [`pi-overlay/versions/1.4.0/integration.patch`](pi-overlay/versions/1.4.0/integration.patch) adapts the existing seam
230
+ against Pi 1.4.0's MIT-licensed TypeScript sources and documentation. The modified-code patch retains the same additions
231
+ and removals as 1.3.0; the interactive-mode hunk positions and blob indexes are refreshed. The generated
232
+ [`skills.patch`](patches/pi-1.4.0/skills.patch) changes the resource loader, slash-command list, CLI/interactive
233
+ dispatch, and skill documentation within the same 48-line generated-runtime seam budget. It adds this repository's
234
+ original skill-management modules unchanged, reusing Pi's package discovery, project trust, path, and locking APIs
235
+ rather than copying its skill implementation. The original CLI/RPC wrappers are reused byte-for-byte from 1.3.0 after
236
+ reviewing 1.4.0's unchanged entrypoint sources and setup. The unchanged compile-cache loader is checksum-pinned. The
237
+ build order follows 1.4.0's root build, with telemetry first. Pi's automatic activation of all discovered skills and
238
+ unrelated runtime changes are intentionally not adopted into the overlay; unrelated package files and bundled chunks are
239
+ left unchanged. No complete Pi source checkout is committed.
240
+
241
+ ## Pi `/skills` TypeScript overlay
242
+
243
+ - Source: `@earendil-works/pi-coding-agent@1.0.3`, `@earendil-works/pi-coding-agent@1.0.4`,
244
+ `@earendil-works/pi-coding-agent@1.1.0`, `@earendil-works/pi-coding-agent@1.3.0`, and
245
+ `@earendil-works/pi-coding-agent@1.4.0`
246
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
247
+ - Upstream revisions reviewed: `d78dc83d633229d12f8b79631384c4c2717c399f` (`v1.0.3`) and
248
+ `7c10bd4337495ee613f2224843ecdf349b80d1df` (`v1.0.4`), taken from the npm registry's `gitHead`; and
249
+ `abe508e1b89912adde45528136c3221eb69acdd7` (`v1.1.0`), `71023aec1546d6d677a65669c5665c0927ce0dd0` (`v1.3.0`), and
250
+ `4a080252f06caf63a525d7873c5d94d3c23887e0` (`v1.4.0`), the commits the release tags point to, because the registry
251
+ publishes no `gitHead` for those releases
252
+ - Source acquired from the 1.0.3, 1.0.4, 1.1.0, 1.3.0, and 1.4.0 release archives and verified against each release's
253
+ published `SHA256SUMS`
254
+ - License declared by the package: MIT
255
+
256
+ [`pi-overlay`](pi-overlay) is the authored form of the `/skills` runtime patch; the artifacts under `patches/pi-1.0.3/`,
257
+ `patches/pi-1.0.4/`, `patches/pi-1.1.0/`, `patches/pi-1.3.0/`, and `patches/pi-1.4.0/` are generated from it.
258
+
259
+ `pi-overlay/skill-management-core.ts` and `pi-overlay/skill-management.ts` are original code for this repository. They
260
+ are a TypeScript reimplementation of the `dist/core/skill-management.js` previously authored here as JavaScript,
261
+ informed by Pi's resource-loading and command conventions rather than copied from an upstream file. They additionally
262
+ absorb logic that earlier versions of the patch inlined into upstream files, so those files now receive only imports and
263
+ call sites.
264
+
265
+ The persisted-skill lock in `pi-overlay/skill-management-core.ts` (`acquireSkillConfigLock` and `withSkillConfigLock`)
266
+ is a modified adaptation of the `acquireTrustLockSync` and `withTrustFileLock` pattern in Pi's MIT-licensed
267
+ `src/core/trust-manager.ts`: a synchronous `proper-lockfile` lock on a sibling `.lock` path, retried only on `ELOCKED`,
268
+ and released in `finally`. It differs by waiting with `Atomics.wait` instead of busy-spinning, allowing more attempts,
269
+ and reporting rather than throwing a failed release so the update's own result or error is preserved. The shell binds
270
+ Pi's existing `proper-lockfile` dependency; no new upstream dependency is introduced.
271
+
272
+ `pi-overlay/versions/<version>/integration.patch` is a modified-code patch against Pi's MIT-licensed TypeScript sources:
273
+ `src/core/resource-loader.ts`, `src/core/slash-commands.ts`, `src/main.ts`, `src/modes/interactive/interactive-mode.ts`,
274
+ and `docs/skills.md`. Its unchanged context and modified lines derive from the MIT-licensed Pi package.
275
+
276
+ `pi-overlay/versions/<version>/replacements/dist/bundle/cli-runtime.js` and `rpc-entry.js` are original hand-written
277
+ wrappers, not derived from upstream's generated bundle output. They replace Pi's esbuild-produced bundled entrypoints so
278
+ the patched unbundled runtime handles CLI and RPC execution.
279
+
280
+ `scripts/skills-patch-103.test.mjs` pins the unchanged `dist/bundle/cli.js` loader with a byte-identical five-line
281
+ stand-in based on that MIT-licensed loader, and asserts it against each release's checksum manifest.
282
+
283
+ The overlay intentionally does not adopt Pi's automatic loading of every discovered skill, configured-path confinement,
284
+ new public resource-loader mutator APIs, or changes to Pi's unrelated extension, prompt, theme, package, trust, and
285
+ provider behavior.
286
+
287
+ This repository vendors no upstream source and maintains no fork. Upstream source is fetched per generation run against
288
+ pinned, checksum-verified inputs, and is not committed here.
289
+
290
+ ## Pi documentation and examples
291
+
292
+ - Source: `@earendil-works/pi-coding-agent`
293
+ - Canonical repository: <https://github.com/earendil-works/pi> (`packages/coding-agent`)
294
+ - Releases reviewed: `0.80.6`, `0.82.0`, `0.82.1`, `0.83.0`, `0.84.0`, `0.84.1`, `0.84.2`, `0.84.4`, `0.85.1`, `0.99.2`,
295
+ and `1.0.3`
296
+ - Latest documentation and example revision reviewed: `d78dc83d633229d12f8b79631384c4c2717c399f`
297
+ - License declared by the package: MIT
298
+
299
+ Ideas and API patterns used:
300
+
301
+ - Extension tool registration, lifecycle shutdown hooks, resource discovery, and TUI tool rendering.
302
+ - The versioned skills catalog reuses `DefaultPackageManager.resolve()` and its resolved-resource metadata to discover
303
+ package and settings skills with upstream manifest, filtering, scope, and precedence behavior. The catalog merge and
304
+ opt-in activation logic remain original code; Pi's automatic skill loading is intentionally not adopted.
305
+ - The skills patches adapt the synchronous `proper-lockfile` acquisition/retry and `finally` release pattern from Pi's
306
+ trust manager so skill configuration updates serialize across processes.
307
+ - SDK `AgentSession.compact()` with custom instructions and in-memory sessions.
308
+ - RPC JSONL framing and the `prompt`, `steer`, `follow_up`, `abort`, state, and event protocols. The real-RPC
309
+ integration test exercises these documented patterns against the pinned Pi CLI with a test-only provider registered
310
+ through `ExtensionAPI.registerProvider` and a deterministic loopback streaming endpoint; no Pi provider or RPC client
311
+ code was copied.
312
+ - Model-registry authentication, fuzzy CLI-equivalent model resolution, thinking-level capability maps, and normal child
313
+ resource inheritance.
314
+ - Pi's thinking-level clamp policy (prefer the nearest supported level above the request, fall back downward only when
315
+ necessary) is a conceptual adaptation, reimplemented in `extensions/subagents/helpers.ts`; no Pi code was copied.
316
+ `supportedThinkingLevels` additionally narrows OpenAI's direct GPT-5.6 levels beyond what Pi's generated model
317
+ metadata declares, because the live endpoint rejects `minimal` and `max`. Pi's own permissive handling of those two
318
+ levels is intentionally not adopted.
319
+ - Pi's bundled subagent and custom-compaction examples as reference implementations for process invocation, output
320
+ bounds, and compaction setup.
321
+
322
+ Major pieces intentionally not adopted include Pi's full interactive mode, session-replacement runtime, prompt-template
323
+ workflows, production custom provider implementations, and bundled role-based subagent profiles. No Pi source file or
324
+ example was copied verbatim; the extension is original code using Pi's published APIs and adapting the documented
325
+ architectural patterns.
326
+
327
+ Pi's official launcher signatures and managed marker fields informed nonexecuting managed-install recognition:
328
+ <https://github.com/earendil-works/pi>, local source revision `741fb3a686f8dcc075f12ea77f985967ced59e21`
329
+ (`packages/coding-agent/src/package-manager-cli.ts`; MIT), plus the installed official launcher. These are behavioral
330
+ references only; no launcher code, execution, installation, or self-update machinery was copied or adopted.
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nigel Stuke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,40 @@
1
+ export type ContextFile = { path: string; content: string };
2
+ export type SkillDisclosure = { name: string; description: string; filePath: string };
3
+
4
+ export function buildFreshContextDisclosure({
5
+ contextFiles,
6
+ skills,
7
+ selectedTools,
8
+ }: {
9
+ contextFiles: ContextFile[];
10
+ skills: SkillDisclosure[];
11
+ selectedTools: string[];
12
+ }): string {
13
+ const instructionFiles = contextFiles.length
14
+ ? contextFiles
15
+ .map((file) => `<project_instructions path="${file.path}">\n${file.content}\n</project_instructions>`)
16
+ .join("\n\n")
17
+ : "- (none found in the current working directory)";
18
+ const skillList = skills.length
19
+ ? skills.map((skill) => `- ${skill.name}: ${skill.description} (${skill.filePath})`).join("\n")
20
+ : "- (none active)";
21
+ const toolList = selectedTools.length
22
+ ? selectedTools.map((tool) => `- ${tool}`).join("\n")
23
+ : "- (none active; no MCP tools are configured)";
24
+
25
+ return `# Fresh Context
26
+
27
+ Previous conversation context was discarded. The following resources were reloaded for this new session.
28
+
29
+ ## Current-directory instructions
30
+
31
+ ${instructionFiles}
32
+
33
+ ## Active skills
34
+
35
+ ${skillList}
36
+
37
+ ## Active tools (including configured MCP tools)
38
+
39
+ ${toolList}`;
40
+ }
@@ -0,0 +1,69 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+ import { buildFreshContextDisclosure } from "./helpers.ts";
5
+ import type { ContextFile } from "./helpers.ts";
6
+
7
+ const CONTEXT_FILE_NAMES = new Set(["AGENTS.MD", "CLAUDE.MD"]);
8
+
9
+ /** Read every AGENTS.md and CLAUDE.md variant directly in the working directory. */
10
+ async function loadCurrentDirectoryContextFiles(cwd: string): Promise<ContextFile[]> {
11
+ let entries: string[];
12
+ try {
13
+ entries = await readdir(cwd);
14
+ } catch {
15
+ return [];
16
+ }
17
+
18
+ const files: ContextFile[] = [];
19
+ for (const name of entries) {
20
+ if (!CONTEXT_FILE_NAMES.has(name.toUpperCase())) continue;
21
+ const path = join(cwd, name);
22
+ try {
23
+ files.push({ path, content: await readFile(path, "utf8") });
24
+ } catch {
25
+ // A disappearing or unreadable context file must not prevent a fresh session.
26
+ }
27
+ }
28
+ return files.sort((a, b) => a.path.localeCompare(b.path));
29
+ }
30
+
31
+ export default function clearExtension(pi: ExtensionAPI) {
32
+ pi.registerCommand("clear", {
33
+ description: "Discard conversation context and start fresh with project instructions, skills, and tools",
34
+ handler: async (_args, ctx) => {
35
+ // Session replacement is only safe after a running agent has fully settled.
36
+ await ctx.waitForIdle();
37
+
38
+ const result = await ctx.newSession({
39
+ withSession: async (freshCtx) => {
40
+ const options = freshCtx.getSystemPromptOptions();
41
+ const contextFiles = await loadCurrentDirectoryContextFiles(freshCtx.cwd);
42
+ const disclosure = buildFreshContextDisclosure({
43
+ contextFiles,
44
+ skills: options.skills ?? [],
45
+ selectedTools: options.selectedTools ?? [],
46
+ });
47
+
48
+ // This context message ensures both AGENTS.md and CLAUDE.md are available even
49
+ // when Pi's normal context discovery prefers one filename over the other.
50
+ await freshCtx.sendMessage({
51
+ customType: "fresh-context-disclosure",
52
+ content: disclosure,
53
+ display: true,
54
+ details: {
55
+ contextFiles: contextFiles.map((file) => file.path),
56
+ skills: options.skills?.map((skill) => skill.name) ?? [],
57
+ tools: options.selectedTools ?? [],
58
+ },
59
+ });
60
+ freshCtx.ui.notify("Fresh context started; project instructions, skills, and tools were reloaded", "info");
61
+ },
62
+ });
63
+
64
+ if (result.cancelled) {
65
+ ctx.ui.notify("Fresh context cancelled", "info");
66
+ }
67
+ },
68
+ });
69
+ }
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@zew1me/pi-clear",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1-alpha.162",
4
+ "type": "module",
5
+ "description": "Pi /clear extension with fresh-context disclosure",
6
+ "license": "SEE LICENSE IN dist/LICENSE",
7
+ "keywords": [
8
+ "pi-package",
9
+ "pi",
10
+ "pi-extension",
11
+ "clear"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/zew1me/pi-buildout.git",
16
+ "directory": "packages/pi-clear"
17
+ },
18
+ "engines": {
19
+ "node": ">=22.19.0"
20
+ },
21
+ "pi": {
22
+ "extensions": [
23
+ "./dist/extensions/clear/index.ts"
24
+ ]
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "registry": "https://registry.npmjs.org/"
32
+ },
33
+ "scripts": {
34
+ "prepack": "node ../../scripts/stage-release-package.mjs clear"
35
+ },
36
+ "peerDependencies": {
37
+ "@earendil-works/pi-coding-agent": "*"
38
+ }
39
+ }