pi-smart-compact 7.12.5 → 7.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +60 -9
- package/SECURITY.md +28 -0
- package/SUPPORT.md +17 -0
- package/dist/app/explore-wrap.d.ts +8 -0
- package/dist/app/explore-wrap.d.ts.map +1 -0
- package/dist/app/run-context.d.ts +196 -0
- package/dist/app/run-context.d.ts.map +1 -0
- package/dist/app/run-smart-compact.d.ts +69 -0
- package/dist/app/run-smart-compact.d.ts.map +1 -0
- package/dist/app/steps/extract.d.ts +21 -0
- package/dist/app/steps/extract.d.ts.map +1 -0
- package/dist/app/steps/metrics.d.ts +33 -0
- package/dist/app/steps/metrics.d.ts.map +1 -0
- package/dist/app/steps/persist.d.ts +47 -0
- package/dist/app/steps/persist.d.ts.map +1 -0
- package/dist/app/steps/prepare.d.ts +12 -0
- package/dist/app/steps/prepare.d.ts.map +1 -0
- package/dist/app/steps/recover.d.ts +13 -0
- package/dist/app/steps/recover.d.ts.map +1 -0
- package/dist/app/steps/state.d.ts +13 -0
- package/dist/app/steps/state.d.ts.map +1 -0
- package/dist/app/steps/synthesize.d.ts +22 -0
- package/dist/app/steps/synthesize.d.ts.map +1 -0
- package/dist/app/steps/tier.d.ts +12 -0
- package/dist/app/steps/tier.d.ts.map +1 -0
- package/dist/app/steps/verify.d.ts +19 -0
- package/dist/app/steps/verify.d.ts.map +1 -0
- package/dist/app/steps/window.d.ts +18 -0
- package/dist/app/steps/window.d.ts.map +1 -0
- package/dist/constants.d.ts +11 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/domain/summary-parse.d.ts +50 -0
- package/dist/domain/summary-parse.d.ts.map +1 -0
- package/dist/domain/summary-schema.d.ts +49 -0
- package/dist/domain/summary-schema.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3539 -2191
- package/dist/infra/clock.d.ts +13 -0
- package/dist/infra/clock.d.ts.map +1 -0
- package/dist/infra/fs.d.ts +57 -0
- package/dist/infra/fs.d.ts.map +1 -0
- package/dist/infra/git.d.ts +17 -0
- package/dist/infra/git.d.ts.map +1 -0
- package/dist/infra/llm-client.d.ts +42 -0
- package/dist/infra/llm-client.d.ts.map +1 -0
- package/dist/infra/llm-retry.d.ts +46 -0
- package/dist/infra/llm-retry.d.ts.map +1 -0
- package/dist/infra/paths.d.ts +46 -0
- package/dist/infra/paths.d.ts.map +1 -0
- package/dist/infra/services.d.ts +111 -0
- package/dist/infra/services.d.ts.map +1 -0
- package/dist/phases/explore.d.ts +15 -3
- package/dist/phases/explore.d.ts.map +1 -1
- package/dist/phases/synthesize.d.ts +4 -3
- package/dist/phases/synthesize.d.ts.map +1 -1
- package/dist/phases/verify.d.ts +18 -2
- package/dist/phases/verify.d.ts.map +1 -1
- package/dist/types.d.ts +42 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/dashboard-format.d.ts +14 -0
- package/dist/ui/dashboard-format.d.ts.map +1 -0
- package/dist/ui/overlays.d.ts +10 -2
- package/dist/ui/overlays.d.ts.map +1 -1
- package/dist/utils/cache.d.ts +42 -13
- package/dist/utils/cache.d.ts.map +1 -1
- package/dist/utils/damage.d.ts.map +1 -1
- package/dist/utils/extraction.d.ts +11 -1
- package/dist/utils/extraction.d.ts.map +1 -1
- package/dist/utils/fingerprint.d.ts +7 -0
- package/dist/utils/fingerprint.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +2 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/id-fingerprint.d.ts +52 -0
- package/dist/utils/id-fingerprint.d.ts.map +1 -0
- package/dist/utils/pruning.d.ts +17 -1
- package/dist/utils/pruning.d.ts.map +1 -1
- package/dist/utils/session-log.d.ts.map +1 -1
- package/dist/utils/state.d.ts +18 -1
- package/dist/utils/state.d.ts.map +1 -1
- package/dist/utils/tokens.d.ts +30 -2
- package/dist/utils/tokens.d.ts.map +1 -1
- package/dist/utils/type-guards.d.ts +22 -0
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/docs/RELEASE.md +40 -0
- package/package.json +14 -3
- package/dist/core.d.ts +0 -31
- package/dist/core.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [7.13.1] - 2026-05-26
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **Run-scoped service isolation** — Smart compaction runs now create isolated service containers for LLM calls, metrics, extraction-cache stats, token calibration, and provider prompt-cache session ids, reducing cross-run state pollution in concurrent Pi sessions.
|
|
7
|
+
- **Phase timing accuracy** — Prune, extract, explore, and synthesize timings are now measured at their actual phase boundaries instead of adjacent marker calls that could report near-zero durations.
|
|
8
|
+
- **Tool/noise accounting** — Tool character percentages now count only text blocks, avoiding accidental inclusion of provider tool-call fields with text-like payloads.
|
|
9
|
+
- **File operation extraction coverage** — File-change detection now recognizes common patch/create/append/update/apply-style tool names in addition to write/edit/delete/read variants.
|
|
10
|
+
|
|
11
|
+
### Tests
|
|
12
|
+
- Added regression coverage for run-scoped LLM metrics isolation, text-only tool character accounting, and broader file-operation tool matching.
|
|
13
|
+
|
|
14
|
+
## [7.13.0] - 2026-05-25
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- **Interactive metrics dashboard TUI** — `/smart-compact dashboard` now opens an in-terminal dashboard with overview, latest-run details, current-session runs, recent runs, and an explicit HTML export action.
|
|
18
|
+
- **Dashboard run detail formatting** — Added tested formatter helpers for legacy metrics, empty states, phase timings, compact run descriptions, and bounded percentage display.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- **Provider cache percentage accounting** — Provider prompt-cache hit rates now use an effective prompt-token denominator and are capped at 100%, preventing impossible values such as `572610%` when providers report cached tokens separately from new input tokens.
|
|
22
|
+
- **Verification repair for malformed summaries** — Missing canonical sections are now reported as verification gaps and deterministic repair can create sections such as `## Goal`, `## Progress`, `## Critical Context`, and `## Files Modified` before injecting required facts.
|
|
23
|
+
- **Dashboard comparison noise** — Legacy metrics entries without profile/provider metadata are omitted from profile/provider comparison groups instead of appearing as misleading `unknown` rows.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
- **Metrics readability** — Result overlays and notifications distinguish prompt, new, and cached input tokens when provider cache reads are present.
|
|
27
|
+
- **Dashboard navigation** — The TUI supports keybinding-aware navigation plus page-up/page-down and home/end scrolling.
|
|
28
|
+
|
|
3
29
|
## [7.12.5] - 2026-05-23
|
|
4
30
|
|
|
5
31
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# pi-smart-compact
|
|
2
2
|
|
|
3
|
+
[](https://github.com/alpertarhan/pi-smart-compact/actions/workflows/ci.yml)
|
|
3
4
|
[](https://www.npmjs.com/package/pi-smart-compact)
|
|
5
|
+
[](https://www.npmjs.com/package/pi-smart-compact)
|
|
4
6
|
[](./LICENSE)
|
|
5
|
-
[](https://github.com/earendil-works/pi)
|
|
6
8
|
|
|
7
9
|
<p align="center">
|
|
8
10
|
<img src="./docs/assets/pi-smart-compact.png" alt="pi-smart-compact" width="760" />
|
|
@@ -16,6 +18,14 @@ It uses an **EESV** pipeline:
|
|
|
16
18
|
|
|
17
19
|
**Extract → Explore → Synthesize → Verify**
|
|
18
20
|
|
|
21
|
+
## Highlights
|
|
22
|
+
|
|
23
|
+
- **Pi-native integration** — `/smart-compact`, `smart_compact`, and `session_before_compact` support.
|
|
24
|
+
- **Verification-oriented output** — deterministic extraction and repair before trusting LLM synthesis.
|
|
25
|
+
- **Adaptive cost profile** — skips unnecessary work on small sessions and uses chunking only when useful.
|
|
26
|
+
- **Operational safety** — pending summaries expire, backups are available, and metrics make regressions visible.
|
|
27
|
+
- **Companion-friendly** — designed to coexist with context hygiene tools such as `pi-toolkit`.
|
|
28
|
+
|
|
19
29
|
Under the hood, the design is grounded in two core ideas:
|
|
20
30
|
|
|
21
31
|
- **agentic compaction**: let the system inspect and reason about the session instead of collapsing everything into generic prose
|
|
@@ -37,6 +47,10 @@ The extension stages a short-lived pending summary in memory, then hands it back
|
|
|
37
47
|
|
|
38
48
|
---
|
|
39
49
|
|
|
50
|
+
## Project status
|
|
51
|
+
|
|
52
|
+
This is an actively maintained Pi extension. The public API is intentionally small, but the internals are still evolving as Pi's compaction lifecycle and extension APIs mature. Pin versions in production workflows if compaction behavior is mission-critical.
|
|
53
|
+
|
|
40
54
|
## Compatibility note
|
|
41
55
|
|
|
42
56
|
`pi-smart-compact` sits close to Pi's compaction path: it registers `session_before_compact`, reads the active branch and session log, stages a pending summary, and may call Pi's native compaction flow from `/smart-compact`.
|
|
@@ -186,7 +200,7 @@ The tool prepares a pending smart summary and lets Pi consume it on the next nat
|
|
|
186
200
|
- pending summaries are kept in memory for **5 minutes**
|
|
187
201
|
- exploration is adaptive and may be skipped for simple sessions
|
|
188
202
|
- use `/smart-compact metrics` for profile/provider comparisons
|
|
189
|
-
- use `/smart-compact dashboard` to
|
|
203
|
+
- use `/smart-compact dashboard` to open the interactive TUI dashboard (overview, latest run, current session, recent runs, or write HTML)
|
|
190
204
|
|
|
191
205
|
This keeps the extension helpful without forcing extra work when it is not needed.
|
|
192
206
|
|
|
@@ -308,17 +322,51 @@ At runtime, the extension writes to paths under `~/.pi/agent/`, including:
|
|
|
308
322
|
```text
|
|
309
323
|
.
|
|
310
324
|
├── src/
|
|
311
|
-
│ ├── index.ts
|
|
312
|
-
│ ├──
|
|
313
|
-
│ ├──
|
|
314
|
-
│ ├──
|
|
315
|
-
│
|
|
316
|
-
├──
|
|
325
|
+
│ ├── index.ts # extension registration + command routing
|
|
326
|
+
│ ├── constants.ts # version, thresholds, prompts
|
|
327
|
+
│ ├── types.ts # shared types
|
|
328
|
+
│ ├── app/ # orchestration layer
|
|
329
|
+
│ │ ├── run-smart-compact.ts # pipeline orchestrator (was core.ts)
|
|
330
|
+
│ │ ├── run-context.ts # typed stage chain
|
|
331
|
+
│ │ ├── explore-wrap.ts # explore re-export shim
|
|
332
|
+
│ │ └── steps/ # 10 stage modules
|
|
333
|
+
│ │ ├── prepare.ts → resolves config + auth
|
|
334
|
+
│ │ ├── window.ts → picks compaction window
|
|
335
|
+
│ │ ├── recover.ts → recovers truncated messages
|
|
336
|
+
│ │ ├── tier.ts → chooses compaction tier
|
|
337
|
+
│ │ ├── extract.ts → pruning + extraction + cache
|
|
338
|
+
│ │ ├── synthesize.ts→ single-pass / EESV summarization
|
|
339
|
+
│ │ ├── verify.ts → structural verify + repair
|
|
340
|
+
│ │ ├── state.ts → state machine + open loops
|
|
341
|
+
│ │ ├── persist.ts → apply compaction
|
|
342
|
+
│ │ └── metrics.ts → success / failure metrics
|
|
343
|
+
│ ├── domain/ # pure semantics (no I/O)
|
|
344
|
+
│ │ ├── summary-schema.ts
|
|
345
|
+
│ │ └── summary-parse.ts
|
|
346
|
+
│ ├── phases/ # algorithms
|
|
347
|
+
│ │ ├── explore.ts
|
|
348
|
+
│ │ ├── synthesize.ts
|
|
349
|
+
│ │ └── verify.ts
|
|
350
|
+
│ ├── infra/ # external-world interaction
|
|
351
|
+
│ │ ├── fs.ts # atomic writes, advisory locks
|
|
352
|
+
│ │ ├── paths.ts # canonical paths
|
|
353
|
+
│ │ ├── git.ts # git-root discovery (cached)
|
|
354
|
+
│ │ ├── clock.ts # injectable clock
|
|
355
|
+
│ │ ├── llm-client.ts # LLM client seam
|
|
356
|
+
│ │ ├── llm-retry.ts # 429/5xx backoff
|
|
357
|
+
│ │ └── services.ts # per-run services container
|
|
358
|
+
│ ├── ui/ # TUI overlays + dashboard
|
|
359
|
+
│ │ ├── overlays.ts
|
|
360
|
+
│ │ └── dashboard-format.ts
|
|
361
|
+
│ └── utils/ # 13 focused utility modules
|
|
362
|
+
├── test/ # 280+ tests across 28 files
|
|
317
363
|
├── docs/
|
|
318
364
|
├── dist/
|
|
319
365
|
└── package.json
|
|
320
366
|
```
|
|
321
367
|
|
|
368
|
+
See `ARCHITECTURE.md` for the full responsibility breakdown of each layer.
|
|
369
|
+
|
|
322
370
|
---
|
|
323
371
|
|
|
324
372
|
## Development
|
|
@@ -330,7 +378,7 @@ bun run build
|
|
|
330
378
|
bun run typecheck
|
|
331
379
|
```
|
|
332
380
|
|
|
333
|
-
Build output is published from `dist/`.
|
|
381
|
+
Build output is published from `dist/`. Pull requests are expected to pass the same verification in GitHub Actions before merge.
|
|
334
382
|
|
|
335
383
|
---
|
|
336
384
|
|
|
@@ -339,6 +387,9 @@ Build output is published from `dist/`.
|
|
|
339
387
|
- [`CHANGELOG.md`](./CHANGELOG.md) — release history
|
|
340
388
|
- [`ARCHITECTURE.md`](./ARCHITECTURE.md) — system design and execution model
|
|
341
389
|
- [`CONTRIBUTING.md`](./CONTRIBUTING.md) — contributor workflow and expectations
|
|
390
|
+
- [`SECURITY.md`](./SECURITY.md) — vulnerability reporting and data-handling notes
|
|
391
|
+
- [`SUPPORT.md`](./SUPPORT.md) — where to ask for help
|
|
392
|
+
- [`docs/RELEASE.md`](./docs/RELEASE.md) — release checklist
|
|
342
393
|
- [`ROADMAP.md`](./ROADMAP.md) — current priorities
|
|
343
394
|
- [`DEVPLAN.md`](./DEVPLAN.md) — archived implementation plan
|
|
344
395
|
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Security fixes target the latest published version of `pi-smart-compact`.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
Please do **not** open a public issue for vulnerabilities, leaked secrets, or private-session data exposure.
|
|
10
|
+
|
|
11
|
+
Report privately through GitHub Security Advisories:
|
|
12
|
+
|
|
13
|
+
<https://github.com/alpertarhan/pi-smart-compact/security/advisories/new>
|
|
14
|
+
|
|
15
|
+
If advisories are unavailable, contact the maintainer listed in `package.json`.
|
|
16
|
+
|
|
17
|
+
## Data handling notes
|
|
18
|
+
|
|
19
|
+
`pi-smart-compact` processes Pi session content to produce compaction summaries. Depending on your session, this may include repository paths, command output, tool results, and user-provided context.
|
|
20
|
+
|
|
21
|
+
Operational guidance:
|
|
22
|
+
|
|
23
|
+
- Do not paste secrets into sessions you plan to compact.
|
|
24
|
+
- Redact private logs before attaching them to issues.
|
|
25
|
+
- Treat generated compaction summaries as potentially sensitive project context.
|
|
26
|
+
- Review provider/model configuration before enabling auto-triggered compaction.
|
|
27
|
+
|
|
28
|
+
Runtime artifacts are written under `~/.pi/agent/`; see `README.md` for the current list.
|
package/SUPPORT.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Support
|
|
2
|
+
|
|
3
|
+
For usage questions or bug reports specific to `pi-smart-compact`, open an issue in this repository:
|
|
4
|
+
|
|
5
|
+
<https://github.com/alpertarhan/pi-smart-compact/issues>
|
|
6
|
+
|
|
7
|
+
For Pi Coding Agent core behavior that reproduces without this extension, use the upstream Pi repository:
|
|
8
|
+
|
|
9
|
+
<https://github.com/earendil-works/pi>
|
|
10
|
+
|
|
11
|
+
When asking for help, include:
|
|
12
|
+
|
|
13
|
+
- `pi-smart-compact` version
|
|
14
|
+
- Pi Coding Agent version
|
|
15
|
+
- the command or integration surface used (`/smart-compact`, `smart_compact`, or auto-trigger)
|
|
16
|
+
- relevant non-secret `smartCompact` configuration
|
|
17
|
+
- redacted error output or logs
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim that lets `app/steps/synthesize.ts` reach the
|
|
3
|
+
* exploration phase without importing through a deep path. Keeping the
|
|
4
|
+
* indirection here means callers don't need to know whether the
|
|
5
|
+
* implementation lives under `phases/` or some future `app/explore`.
|
|
6
|
+
*/
|
|
7
|
+
export { exploreConversation, shouldExplore } from "../phases/explore.ts";
|
|
8
|
+
//# sourceMappingURL=explore-wrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explore-wrap.d.ts","sourceRoot":"","sources":["../../src/app/explore-wrap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-run pipeline context as a typed state machine.
|
|
3
|
+
*
|
|
4
|
+
* The previous incarnation of `RunContext` was a single fat interface where
|
|
5
|
+
* every later-phase field was marked optional. That kept the type system
|
|
6
|
+
* quiet but had two real costs:
|
|
7
|
+
*
|
|
8
|
+
* 1. **Cast pollution.** `makeContext` initialized half the fields with
|
|
9
|
+
* `undefined as unknown as RunContext["config"]` because the type
|
|
10
|
+
* claimed they would be set. Every step then re-read them with `!`,
|
|
11
|
+
* silently relying on call ordering. A future refactor that moved one
|
|
12
|
+
* step would compile cleanly and crash at runtime.
|
|
13
|
+
*
|
|
14
|
+
* 2. **No phase guarantees.** `applyCompaction` reading `rc.details!` had
|
|
15
|
+
* no compile-time proof that `buildState` had actually run.
|
|
16
|
+
*
|
|
17
|
+
* We replace that with a stage chain. Each step accepts the previous stage
|
|
18
|
+
* type and returns the next, so:
|
|
19
|
+
*
|
|
20
|
+
* - `prepareRun(base)` → `PreparedRc`
|
|
21
|
+
* - `resolveCompactionWindow(prepared)` → `WindowedRc | null`
|
|
22
|
+
* - …
|
|
23
|
+
* - `buildState(verified)` → `StatedRc`
|
|
24
|
+
* - `applyCompaction(stated)` (cannot be invoked before `buildState`)
|
|
25
|
+
*
|
|
26
|
+
* Implementation note: mutation is preserved. Each step mutates the input
|
|
27
|
+
* object and returns it cast to the next stage. The `_brand` field on each
|
|
28
|
+
* extension is the only thing that distinguishes stages structurally — it is
|
|
29
|
+
* never read at runtime. This lets us avoid copying ~30 fields per step
|
|
30
|
+
* while still getting compile-time stage tracking.
|
|
31
|
+
*
|
|
32
|
+
* The final `RunContext = StatedRc` alias keeps backwards-compatible imports
|
|
33
|
+
* working for the `applyCompaction` / metrics paths that ran post-`buildState`.
|
|
34
|
+
*/
|
|
35
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
36
|
+
import type { Model, Api } from "@earendil-works/pi-ai";
|
|
37
|
+
import type { CompressionProfile, PendingCompaction, LlmMessage, StructuredExtraction, ExplorationReport, ChunkSummary, SessionMessageEntry, PipelinePhaseTiming, CompactConfig, ProfileConfig, ProviderCapabilities, SmartCompactDetails, CompactionState, OpenLoop } from "../types.ts";
|
|
38
|
+
import type { PruningResult } from "../utils/pruning.ts";
|
|
39
|
+
import type { CompactionTier } from "../utils/helpers.ts";
|
|
40
|
+
import type { SmartCompactServices } from "../infra/services.ts";
|
|
41
|
+
export type Notifier = (msg: string, type?: "info" | "success" | "warning" | "error") => void;
|
|
42
|
+
export interface CancellationToken {
|
|
43
|
+
controller: AbortController;
|
|
44
|
+
signal: AbortSignal;
|
|
45
|
+
/** Set when the auto-trigger hard timeout fires. */
|
|
46
|
+
timedOut: boolean;
|
|
47
|
+
/** Active setTimeout handle. Cleared in finally so we never leak timers. */
|
|
48
|
+
timeoutId: ReturnType<typeof setTimeout> | null;
|
|
49
|
+
}
|
|
50
|
+
export interface PendingRef {
|
|
51
|
+
value: PendingCompaction | null;
|
|
52
|
+
createdAt: number;
|
|
53
|
+
}
|
|
54
|
+
export interface RunFlags {
|
|
55
|
+
verbose: boolean;
|
|
56
|
+
dryRun: boolean;
|
|
57
|
+
autoTriggered: boolean;
|
|
58
|
+
skipCompact: boolean;
|
|
59
|
+
force: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface ResolvedAuth {
|
|
62
|
+
apiKey: string;
|
|
63
|
+
headers?: Record<string, string>;
|
|
64
|
+
}
|
|
65
|
+
export interface RcBase {
|
|
66
|
+
ctx: ExtensionCommandContext;
|
|
67
|
+
notify: Notifier;
|
|
68
|
+
vlog: (msg: string) => void;
|
|
69
|
+
services: SmartCompactServices;
|
|
70
|
+
cancellation: CancellationToken;
|
|
71
|
+
pendingRef: PendingRef;
|
|
72
|
+
isRunning: {
|
|
73
|
+
value: boolean;
|
|
74
|
+
};
|
|
75
|
+
flags: RunFlags;
|
|
76
|
+
userNote?: string;
|
|
77
|
+
timeoutMs: number;
|
|
78
|
+
phaseTimings: PipelinePhaseTiming[];
|
|
79
|
+
pipelineStart: number;
|
|
80
|
+
phaseStart: number;
|
|
81
|
+
summaryModel: Model<Api>;
|
|
82
|
+
segModel: Model<Api>;
|
|
83
|
+
modelLabel: string;
|
|
84
|
+
profile: CompressionProfile;
|
|
85
|
+
}
|
|
86
|
+
export interface PreparedExt {
|
|
87
|
+
/** Discriminator field; never read at runtime. */
|
|
88
|
+
readonly _prepared: true;
|
|
89
|
+
config: CompactConfig;
|
|
90
|
+
profileCfg: ProfileConfig;
|
|
91
|
+
providerCaps: ProviderCapabilities;
|
|
92
|
+
summaryAuth: ResolvedAuth;
|
|
93
|
+
segAuth: ResolvedAuth;
|
|
94
|
+
}
|
|
95
|
+
export type PreparedRc = RcBase & PreparedExt;
|
|
96
|
+
export interface WindowedExt extends PreparedExt {
|
|
97
|
+
readonly _windowed: true;
|
|
98
|
+
sessionId: string;
|
|
99
|
+
branch: unknown[];
|
|
100
|
+
msgs: SessionMessageEntry[];
|
|
101
|
+
totalTokens: number;
|
|
102
|
+
contextPercent: number;
|
|
103
|
+
toolPercent: number;
|
|
104
|
+
keepFrom: number;
|
|
105
|
+
toCompact: SessionMessageEntry[];
|
|
106
|
+
firstKeptId: string;
|
|
107
|
+
accTokens: number;
|
|
108
|
+
}
|
|
109
|
+
export type WindowedRc = RcBase & WindowedExt;
|
|
110
|
+
export interface RecoveredExt extends WindowedExt {
|
|
111
|
+
readonly _recovered: true;
|
|
112
|
+
llmMessages: LlmMessage[];
|
|
113
|
+
}
|
|
114
|
+
export type RecoveredRc = RcBase & RecoveredExt;
|
|
115
|
+
export type ActiveTier = Exclude<CompactionTier, "none">;
|
|
116
|
+
export interface TieredExt extends RecoveredExt {
|
|
117
|
+
readonly _tiered: true;
|
|
118
|
+
tier: ActiveTier;
|
|
119
|
+
}
|
|
120
|
+
export type TieredRc = RcBase & TieredExt;
|
|
121
|
+
export interface ExtractedExt extends TieredExt {
|
|
122
|
+
readonly _extracted: true;
|
|
123
|
+
pruning: PruningResult;
|
|
124
|
+
currentEntryIds: string[];
|
|
125
|
+
currentKeptEntryIds: string[];
|
|
126
|
+
/**
|
|
127
|
+
* ToolCallIndex over the **pruned** message list. Built once in
|
|
128
|
+
* `extractWithCache` and reused by extraction. Keyed against pruned offsets,
|
|
129
|
+
* not the unpruned message list — do not confuse with `pruning.toolCallIndex`.
|
|
130
|
+
*/
|
|
131
|
+
prunedToolCallIndex: import("../utils/extraction.ts").ToolCallIndex;
|
|
132
|
+
extraction: StructuredExtraction;
|
|
133
|
+
extractionCacheMissReason?: string;
|
|
134
|
+
prevContext: string;
|
|
135
|
+
projectCtx: string;
|
|
136
|
+
projectId: string;
|
|
137
|
+
/**
|
|
138
|
+
* Serialized pruned conversation text. Computed once in `extractWithCache`
|
|
139
|
+
* and reused by `summarizeConversation` so we don't `serializeConversation`
|
|
140
|
+
* the same 5000-message array twice on the hot path. `convTokens` is the
|
|
141
|
+
* cached `estimateTokens(convText)` value.
|
|
142
|
+
*/
|
|
143
|
+
convText: string;
|
|
144
|
+
convTokens: number;
|
|
145
|
+
backupPath: string | null;
|
|
146
|
+
}
|
|
147
|
+
export type ExtractedRc = RcBase & ExtractedExt;
|
|
148
|
+
export interface SynthesizedExt extends ExtractedExt {
|
|
149
|
+
readonly _synthesized: true;
|
|
150
|
+
finalSummary: string;
|
|
151
|
+
method: "eesv" | "single-pass" | "heuristic";
|
|
152
|
+
methodForMetrics: string;
|
|
153
|
+
llmCalls: number;
|
|
154
|
+
summaries: ChunkSummary[];
|
|
155
|
+
explorationReport: ExplorationReport | null;
|
|
156
|
+
explorationRounds: number;
|
|
157
|
+
chunkCount: number;
|
|
158
|
+
}
|
|
159
|
+
export type SynthesizedRc = RcBase & SynthesizedExt;
|
|
160
|
+
export interface VerifiedExt extends SynthesizedExt {
|
|
161
|
+
readonly _verified: true;
|
|
162
|
+
verificationScore: number;
|
|
163
|
+
verificationGaps: string[];
|
|
164
|
+
verified: boolean;
|
|
165
|
+
}
|
|
166
|
+
export type VerifiedRc = RcBase & VerifiedExt;
|
|
167
|
+
export interface StatedExt extends VerifiedExt {
|
|
168
|
+
readonly _stated: true;
|
|
169
|
+
openLoops: OpenLoop[];
|
|
170
|
+
compactionState: CompactionState;
|
|
171
|
+
details: SmartCompactDetails;
|
|
172
|
+
tokensSaved: number;
|
|
173
|
+
}
|
|
174
|
+
export type StatedRc = RcBase & StatedExt;
|
|
175
|
+
/**
|
|
176
|
+
* Backwards-compatible alias.
|
|
177
|
+
*
|
|
178
|
+
* Modules that don't care about pipeline ordering (e.g. `applyCompaction` in
|
|
179
|
+
* `persist.ts`, which only runs after `buildState`) can still take a
|
|
180
|
+
* `RunContext`. New code should prefer the explicit stage types.
|
|
181
|
+
*/
|
|
182
|
+
export type RunContext = StatedRc;
|
|
183
|
+
/** Record an already-measured phase and advance the phase boundary. */
|
|
184
|
+
export declare function markMeasuredPhase(rc: RcBase, phase: PipelinePhaseTiming["phase"], startMs: number, endMs?: number): void;
|
|
185
|
+
/** Mark the boundary between two pipeline phases for the metrics log. */
|
|
186
|
+
export declare function markPhase(rc: RcBase, phase: PipelinePhaseTiming["phase"]): void;
|
|
187
|
+
/**
|
|
188
|
+
* In-place stage advancement.
|
|
189
|
+
*
|
|
190
|
+
* Each step mutates its input then casts to the next stage. The cast is the
|
|
191
|
+
* only place we widen the type — the runtime object never copies. Centralizing
|
|
192
|
+
* it here means tests can spot the transition easily and IDE jumps to the
|
|
193
|
+
* factory rather than scattering `as` keywords through every step.
|
|
194
|
+
*/
|
|
195
|
+
export declare function advance<TIn extends RcBase, TOut extends TIn>(rc: TIn, _stage: keyof TOut): TOut;
|
|
196
|
+
//# sourceMappingURL=run-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run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B,iBAAiB,CAC/B,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,EACnC,OAAO,EAAE,MAAM,EACf,KAAK,SAAa,GACjB,IAAI,CAGN;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAAG,IAAI,CAE/E;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,GAAG,SAAS,MAAM,EAAE,IAAI,SAAS,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI,CAE/F"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orchestrator: thread the typed run context through every stage in order.
|
|
3
|
+
*
|
|
4
|
+
* Each step is now a typed transition (see `app/run-context.ts`): the input
|
|
5
|
+
* is the previous stage type, the output is the next. Skipping a step or
|
|
6
|
+
* reordering them is a TypeScript error rather than a runtime crash.
|
|
7
|
+
*
|
|
8
|
+
* Responsibilities owned by this file:
|
|
9
|
+
*
|
|
10
|
+
* - The try/finally that maintains `isRunning`.
|
|
11
|
+
* - The timeout `setTimeout` handle (set in prepare, cleared in finally).
|
|
12
|
+
* - The decision to bail out without side effects when the auto-trigger
|
|
13
|
+
* hard-timeout fires.
|
|
14
|
+
* - The post-success result screen + apply-compaction trigger.
|
|
15
|
+
*
|
|
16
|
+
* The function intentionally has no clever control flow: every cross-step
|
|
17
|
+
* dependency is data on the stage type, every conditional is a boolean flag.
|
|
18
|
+
*/
|
|
19
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
20
|
+
import type { Model, Api } from "@earendil-works/pi-ai";
|
|
21
|
+
import type { CompressionProfile } from "../types.ts";
|
|
22
|
+
import type { PendingRef } from "./run-context.ts";
|
|
23
|
+
/**
|
|
24
|
+
* Co-operative cancellation surface that the extension entry point can hand
|
|
25
|
+
* back to itself to drive an *external* hard timeout.
|
|
26
|
+
*
|
|
27
|
+
* Setting `timedOut = true` and calling `abort()` from outside the pipeline
|
|
28
|
+
* is the single source of truth for "give up on smart compaction and let Pi
|
|
29
|
+
* run its native compact". The orchestrator notices the flag and:
|
|
30
|
+
*
|
|
31
|
+
* - skips all remaining side effects (state persist, ctx.compact apply),
|
|
32
|
+
* - clears `pendingRef` in finally,
|
|
33
|
+
* - records a timeout metric instead of a success metric.
|
|
34
|
+
*/
|
|
35
|
+
export interface ExternalCancellation {
|
|
36
|
+
timedOut: boolean;
|
|
37
|
+
abort: () => void;
|
|
38
|
+
}
|
|
39
|
+
/** Options for runSmartCompact — avoids 10-parameter positional calls. */
|
|
40
|
+
export interface SmartCompactOptions {
|
|
41
|
+
ctx: ExtensionCommandContext;
|
|
42
|
+
summaryModel: Model<Api>;
|
|
43
|
+
segModel: Model<Api>;
|
|
44
|
+
profile: CompressionProfile;
|
|
45
|
+
verbose?: boolean;
|
|
46
|
+
dryRun?: boolean;
|
|
47
|
+
pendingRef: PendingRef;
|
|
48
|
+
isRunning: {
|
|
49
|
+
value: boolean;
|
|
50
|
+
};
|
|
51
|
+
autoTriggered?: boolean;
|
|
52
|
+
userNote?: string;
|
|
53
|
+
skipCompact?: boolean;
|
|
54
|
+
/** Explicit user command may bypass adaptive context-pressure tier gate. */
|
|
55
|
+
force?: boolean;
|
|
56
|
+
/** Optional hard budget for native auto-trigger only. Manual/tool runs do not time out by default. */
|
|
57
|
+
timeoutMs?: number;
|
|
58
|
+
/**
|
|
59
|
+
* If provided, populated with the run's cancellation handle before any
|
|
60
|
+
* async work begins. The session_before_compact hook uses this to enforce
|
|
61
|
+
* its own hard timeout in addition to the in-pipeline one (some providers
|
|
62
|
+
* ignore AbortSignal entirely).
|
|
63
|
+
*/
|
|
64
|
+
cancellationOut?: {
|
|
65
|
+
value: ExternalCancellation | null;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export declare function runSmartCompact(opts: SmartCompactOptions): Promise<void>;
|
|
69
|
+
//# sourceMappingURL=run-smart-compact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-smart-compact.d.ts","sourceRoot":"","sources":["../../src/app/run-smart-compact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAItD,OAAO,KAAK,EACQ,UAAU,EAC7B,MAAM,kBAAkB,CAAC;AAc1B;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,0EAA0E;AAC1E,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,uBAAuB,CAAC;IAC7B,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACrB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sGAAsG;IACtG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,eAAe,CAAC,EAAE;QAAE,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAAA;KAAE,CAAC;CAC1D;AAwCD,wBAAsB,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsK9E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step 5: deterministic extraction with incremental cache.
|
|
3
|
+
*
|
|
4
|
+
* Stage: `TieredRc` → `ExtractedRc`.
|
|
5
|
+
*
|
|
6
|
+
* Pruning + extraction are paired here because:
|
|
7
|
+
*
|
|
8
|
+
* 1. The extraction indexes (topic ranges, error message offsets, decisions)
|
|
9
|
+
* live in the pruned message domain. Caching the extraction is only safe
|
|
10
|
+
* when the pruned *prefix* of the next run matches the previous one.
|
|
11
|
+
* 2. Without the prefix guard, an incremental delta could be merged on top
|
|
12
|
+
* of a base whose pruning result drifted (e.g. a new duplicate read
|
|
13
|
+
* evicted an old cached read), producing index offsets that point at the
|
|
14
|
+
* wrong messages.
|
|
15
|
+
*
|
|
16
|
+
* `extractionCacheMissReason` captures *why* the cache could not be used so
|
|
17
|
+
* the metrics dashboard can show the hit-rate alongside the failure mode.
|
|
18
|
+
*/
|
|
19
|
+
import type { TieredRc, ExtractedRc } from "../run-context.ts";
|
|
20
|
+
export declare function extractWithCache(rc: TieredRc): ExtractedRc;
|
|
21
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../src/app/steps/extract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAiB/D,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,QAAQ,GAAG,WAAW,CA0J1D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step 10: record metrics for the run.
|
|
3
|
+
*
|
|
4
|
+
* Two paths:
|
|
5
|
+
*
|
|
6
|
+
* - `recordSuccessMetrics(rc: StatedRc, status)` runs after a full pipeline
|
|
7
|
+
* completion. Every field on the metric record is statically known.
|
|
8
|
+
*
|
|
9
|
+
* - `recordFailureMetrics(rc, err, fields)` runs from the catch block in
|
|
10
|
+
* the orchestrator and may execute before the pipeline ever populated
|
|
11
|
+
* stage data. The `fields` bag carries whatever the orchestrator managed
|
|
12
|
+
* to collect before the throw; missing values fall through to undefined.
|
|
13
|
+
*
|
|
14
|
+
* Metrics writes are intentionally append-only and idempotent — they target
|
|
15
|
+
* the JSONL log and never throw past the cache.ts boundary.
|
|
16
|
+
*/
|
|
17
|
+
import type { RcBase, StatedRc } from "../run-context.ts";
|
|
18
|
+
export declare function recordSuccessMetrics(rc: StatedRc, status: "success" | "dry-run"): void;
|
|
19
|
+
/**
|
|
20
|
+
* Partial summary that the orchestrator accumulates as steps complete. The
|
|
21
|
+
* failure path uses whatever is present at the moment of the throw.
|
|
22
|
+
*/
|
|
23
|
+
export interface FailureSummaryFields {
|
|
24
|
+
sessionId?: string;
|
|
25
|
+
tier?: string;
|
|
26
|
+
contextPercent?: number;
|
|
27
|
+
toolPercent?: number;
|
|
28
|
+
totalTokens?: number;
|
|
29
|
+
methodForMetrics?: string;
|
|
30
|
+
profile: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function recordFailureMetrics(rc: RcBase | StatedRc, err: unknown, fields: FailureSummaryFields): void;
|
|
33
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/app/steps/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAU1D,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAwCtF;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,MAAM,GAAG,QAAQ,EACrB,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,oBAAoB,GAC3B,IAAI,CAgBN"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step 9: apply compaction and persist durable state.
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle invariants:
|
|
5
|
+
*
|
|
6
|
+
* - `pendingRef` is set immediately so `session_before_compact` can consume
|
|
7
|
+
* it. We MUST clear it on failure (P1 #4 in the audit) — the previous
|
|
8
|
+
* implementation left a stale summary alive for up to 5 minutes after a
|
|
9
|
+
* `ctx.compact()` error.
|
|
10
|
+
*
|
|
11
|
+
* - Project fingerprint and compaction state are persisted **after** the
|
|
12
|
+
* native compact's `onComplete` confirms application. If we wrote state
|
|
13
|
+
* eagerly and the compact failed, the next run would believe a successful
|
|
14
|
+
* compaction had happened — corrupting damage detection and the
|
|
15
|
+
* cross-compaction delta. This addresses P1 #5 in the audit.
|
|
16
|
+
*
|
|
17
|
+
* - For manual / tool runs we run damage detection against the existing
|
|
18
|
+
* branch's previous compaction as a best-effort signal.
|
|
19
|
+
*/
|
|
20
|
+
import type { RunContext } from "../run-context.ts";
|
|
21
|
+
import type { PendingCompaction } from "../../types.ts";
|
|
22
|
+
/**
|
|
23
|
+
* Persist project fingerprint + compaction state. Pulled into its own function
|
|
24
|
+
* so the post-compact onComplete callback in the orchestrator can invoke it
|
|
25
|
+
* exactly once after the native compact succeeds.
|
|
26
|
+
*
|
|
27
|
+
* `RunContext` is the final `StatedRc` stage, so both `extraction` and
|
|
28
|
+
* `compactionState` are statically known to be present here — no defensive
|
|
29
|
+
* `!` or runtime guards needed.
|
|
30
|
+
*/
|
|
31
|
+
export declare function persistDurableState(rc: RunContext): void;
|
|
32
|
+
/** Run post-compaction damage detection. Best-effort — never throws. */
|
|
33
|
+
export declare function runDamageDetection(rc: RunContext): void;
|
|
34
|
+
/**
|
|
35
|
+
* Stash the prepared compaction in pendingRef and trigger the native compact
|
|
36
|
+
* if appropriate. Returns the pending summary so callers can decide whether
|
|
37
|
+
* the run should keep running side effects (it does until the timeout/cleanup
|
|
38
|
+
* step decides otherwise).
|
|
39
|
+
*/
|
|
40
|
+
export declare function stagePendingCompaction(rc: RunContext): PendingCompaction;
|
|
41
|
+
/**
|
|
42
|
+
* Trigger Pi's native compact in non-auto/non-tool runs. The state-persist
|
|
43
|
+
* callback fires on success; failure clears the pendingRef so the next
|
|
44
|
+
* compact event cannot grab a stale summary (audit P1 #4).
|
|
45
|
+
*/
|
|
46
|
+
export declare function applyCompaction(rc: RunContext): void;
|
|
47
|
+
//# sourceMappingURL=persist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persist.d.ts","sourceRoot":"","sources":["../../../src/app/steps/persist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAc,MAAM,gBAAgB,CAAC;AASpE;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CAGxD;AAED,wEAAwE;AACxE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CA6BvD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,UAAU,GAAG,iBAAiB,CAcxE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,UAAU,GAAG,IAAI,CAoBpD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step 1: prepare a run — load config, resolve auth, wire cancellation.
|
|
3
|
+
*
|
|
4
|
+
* Stage transition: `RcBase` → `PreparedRc`.
|
|
5
|
+
*
|
|
6
|
+
* Returns `null` when authentication fails so the orchestrator can bail
|
|
7
|
+
* before any side effects. The null return is the explicit guard that lets
|
|
8
|
+
* TypeScript prove later steps never see a half-initialised context.
|
|
9
|
+
*/
|
|
10
|
+
import type { RcBase, PreparedRc } from "../run-context.ts";
|
|
11
|
+
export declare function prepareRun(rc: RcBase): Promise<PreparedRc | null>;
|
|
12
|
+
//# sourceMappingURL=prepare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../../../src/app/steps/prepare.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO5D,wBAAsB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA8CvE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step 3: recover untruncated messages from the session log when needed.
|
|
3
|
+
*
|
|
4
|
+
* Stage: `WindowedRc` → `RecoveredRc`.
|
|
5
|
+
*
|
|
6
|
+
* pi-toolkit's context hook truncates tool results in-place on the branch.
|
|
7
|
+
* Where possible we read the original messages from the session log instead.
|
|
8
|
+
* If the log is unavailable we fall back to the (possibly truncated) branch
|
|
9
|
+
* messages — the summary still beats no summary at all.
|
|
10
|
+
*/
|
|
11
|
+
import type { WindowedRc, RecoveredRc } from "../run-context.ts";
|
|
12
|
+
export declare function recoverSessionLog(rc: WindowedRc): RecoveredRc;
|
|
13
|
+
//# sourceMappingURL=recover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../../src/app/steps/recover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMjE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,UAAU,GAAG,WAAW,CAgB7D"}
|