@pi-unipi/unipi 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +292 -0
- package/README.md +8 -11
- package/docs/prefix-cache-architecture.md +14 -0
- package/package.json +22 -24
- package/packages/ask-user/README.md +55 -107
- package/packages/ask-user/ask-ui.ts +306 -732
- package/packages/ask-user/clipboard.ts +50 -0
- package/packages/ask-user/config.ts +74 -78
- package/packages/ask-user/package.json +2 -2
- package/packages/ask-user/questions.ts +151 -0
- package/packages/ask-user/skills/ask-user/SKILL.md +59 -133
- package/packages/ask-user/tools.ts +198 -432
- package/packages/autocomplete/package.json +1 -1
- package/packages/autocomplete/src/constants.ts +38 -43
- package/packages/autocomplete/src/sorting.ts +8 -0
- package/packages/background-tasks/package.json +2 -2
- package/packages/background-tasks/src/config.ts +0 -73
- package/packages/background-tasks/src/index.ts +20 -16
- package/packages/background-tasks/src/registry.ts +1 -171
- package/packages/background-tasks/src/types.ts +0 -32
- package/packages/btw/README.md +13 -56
- package/packages/btw/extensions/btw.ts +403 -1796
- package/packages/btw/package.json +5 -2
- package/packages/btw/skills/btw/SKILL.md +7 -143
- package/packages/compactor/README.md +56 -287
- package/packages/compactor/package.json +5 -9
- package/packages/compactor/skills/compactor/SKILL.md +13 -20
- package/packages/compactor/src/card.ts +90 -0
- package/packages/compactor/src/commands/index.ts +73 -130
- package/packages/compactor/src/compaction/compact-args.ts +5 -3
- package/packages/compactor/src/compaction/filter-noise.ts +1 -1
- package/packages/compactor/src/compaction/hooks.ts +487 -311
- package/packages/compactor/src/compaction/source.ts +178 -0
- package/packages/compactor/src/compaction/summarize.ts +586 -52
- package/packages/compactor/src/config/manager.ts +130 -127
- package/packages/compactor/src/config/schema.ts +32 -48
- package/packages/compactor/src/index.ts +40 -431
- package/packages/compactor/src/info-screen.ts +44 -190
- package/packages/compactor/src/session/recall-blocks.ts +1 -1
- package/packages/compactor/src/stats.ts +76 -0
- package/packages/compactor/src/tools/context-budget.ts +17 -34
- package/packages/compactor/src/tools/ctx-doctor.ts +45 -36
- package/packages/compactor/src/tools/register.ts +29 -269
- package/packages/compactor/src/types.ts +47 -186
- package/packages/core/README.md +25 -0
- package/packages/core/child-agent.ts +1 -0
- package/packages/core/command-echo.ts +63 -0
- package/packages/core/compaction-context.ts +41 -0
- package/packages/core/constants.ts +8 -38
- package/packages/core/events.ts +0 -53
- package/packages/core/fusion-status.ts +4 -0
- package/packages/core/global.d.ts +10 -0
- package/packages/core/harness-messages.ts +392 -0
- package/packages/core/index.ts +14 -0
- package/packages/core/kanboard-status.ts +49 -0
- package/packages/core/long-horizon-owner-status.ts +46 -0
- package/packages/core/model-cache.ts +81 -7
- package/packages/core/package.json +6 -3
- package/packages/core/src/attach/detect.ts +163 -0
- package/packages/core/src/child-agent/child-args.ts +31 -0
- package/packages/core/src/child-agent/delivery.ts +41 -0
- package/packages/core/src/child-agent/index.ts +5 -0
- package/packages/core/src/child-agent/readers.ts +203 -0
- package/packages/core/src/child-agent/runtime.ts +584 -0
- package/packages/core/src/evidence.ts +78 -0
- package/packages/core/src/hints/browser.ts +278 -0
- package/packages/core/src/hints/crab-data.ts +19 -0
- package/packages/core/src/hints/index.ts +865 -0
- package/packages/core/src/hints/lines.ts +607 -0
- package/packages/core/src/hints/store.ts +120 -0
- package/packages/core/src/jev/chatter.ts +24 -0
- package/packages/core/src/jev/settings.ts +177 -14
- package/packages/core/src/package-colors.ts +2 -0
- package/packages/core/src/settings/catalog.ts +39 -15
- package/packages/core/src/settings/engine.ts +48 -2
- package/packages/core/src/settings/hub.ts +83 -20
- package/packages/core/src/settings/open.ts +49 -0
- package/packages/core/src/settings/schema.ts +27 -7
- package/packages/core/src/tui/hub-kit.ts +18 -5
- package/packages/core/src/tui/kit.ts +198 -0
- package/packages/core/src/tui/progress.ts +73 -0
- package/packages/core/src/turn/arbiter.ts +290 -0
- package/packages/footer/README.md +4 -6
- package/packages/footer/package.json +3 -3
- package/packages/footer/src/glance-editor.ts +19 -11
- package/packages/footer/src/help.ts +1 -1
- package/packages/footer/src/index.ts +36 -3
- package/packages/footer/src/presets.ts +3 -4
- package/packages/footer/src/rendering/icons.ts +0 -20
- package/packages/footer/src/segments/compactor.ts +52 -142
- package/packages/footer/src/segments/status-ext.ts +0 -1
- package/packages/fusion/README.md +14 -4
- package/packages/fusion/package.json +4 -3
- package/packages/fusion/src/child-args.ts +1 -0
- package/packages/fusion/src/index.ts +161 -8
- package/packages/fusion/src/pi-settings.ts +57 -0
- package/packages/fusion/src/picker.ts +186 -51
- package/packages/fusion/src/preset.ts +56 -2
- package/packages/fusion/src/prompts.ts +1 -1
- package/packages/fusion/src/sidekick-runtime.ts +1 -420
- package/packages/fusion/src/tools.ts +107 -128
- package/packages/fusion/src/transcript.ts +27 -85
- package/packages/info-screen/package.json +2 -2
- package/packages/input-shortcuts/README.md +18 -30
- package/packages/input-shortcuts/package.json +2 -2
- package/packages/input-shortcuts/src/burst.ts +88 -0
- package/packages/input-shortcuts/src/chord-overlay.ts +20 -70
- package/packages/input-shortcuts/src/cleared-input.ts +97 -0
- package/packages/input-shortcuts/src/index.ts +99 -193
- package/packages/input-shortcuts/src/last-response.ts +40 -0
- package/packages/input-shortcuts/src/registers.ts +8 -23
- package/packages/input-shortcuts/src/types.ts +4 -16
- package/packages/input-shortcuts/src/undo-redo.ts +59 -47
- package/packages/kanboard/README.md +51 -47
- package/packages/kanboard/index.ts +293 -55
- package/packages/kanboard/package.json +8 -8
- package/packages/kanboard/skills/kanboard/SKILL.md +61 -27
- package/packages/kanboard/src/badges.ts +93 -0
- package/packages/kanboard/src/bin.ts +4 -2
- package/packages/kanboard/src/commands.ts +218 -84
- package/packages/kanboard/src/debug.ts +20 -0
- package/packages/kanboard/src/guard.ts +267 -109
- package/packages/kanboard/src/monitor.ts +330 -0
- package/packages/kanboard/src/notice-buffer.ts +74 -0
- package/packages/kanboard/src/progress.ts +27 -0
- package/packages/kanboard/src/reminders.ts +234 -0
- package/packages/kanboard/src/settings.ts +69 -15
- package/packages/kanboard/src/shapes.ts +5 -0
- package/packages/long-horizon/index.ts +190 -13
- package/packages/long-horizon/package.json +3 -3
- package/packages/long-horizon/src/commands.ts +103 -7
- package/packages/long-horizon/src/compaction-brief.ts +35 -0
- package/packages/long-horizon/src/engine/continuation.ts +84 -15
- package/packages/long-horizon/src/engine/goal-state.ts +64 -13
- package/packages/long-horizon/src/engine/nudge-stash.ts +71 -0
- package/packages/long-horizon/src/engine/ralph.ts +3 -2
- package/packages/long-horizon/src/engine/runaway.ts +68 -11
- package/packages/long-horizon/src/engine/verifier.ts +19 -0
- package/packages/long-horizon/src/gate.ts +37 -12
- package/packages/long-horizon/src/judge/resolve.ts +1 -0
- package/packages/long-horizon/src/owner.ts +35 -2
- package/packages/long-horizon/src/progress.ts +87 -0
- package/packages/long-horizon/src/prompts/goal.ts +1 -1
- package/packages/long-horizon/src/runtime.ts +172 -18
- package/packages/long-horizon/src/settings.ts +54 -39
- package/packages/long-horizon/src/tools/goal.ts +6 -0
- package/packages/long-horizon/src/tools/graph.ts +1 -1
- package/packages/long-horizon/src/tools/swarm.ts +3 -3
- package/packages/mcp/package.json +2 -2
- package/packages/memory/commands.ts +7 -2
- package/packages/memory/index.ts +210 -32
- package/packages/memory/package.json +3 -3
- package/packages/memory/save-session.ts +264 -0
- package/packages/memory/settings.ts +17 -0
- package/packages/memory/tools.ts +253 -203
- package/packages/notify/package.json +2 -2
- package/packages/skill-registry/README.md +53 -16
- package/packages/skill-registry/index.ts +230 -0
- package/packages/skill-registry/package.json +19 -8
- package/packages/skill-registry/src/editor.ts +206 -0
- package/packages/skill-registry/src/judge.ts +289 -0
- package/packages/skill-registry/src/registry.ts +87 -0
- package/packages/skill-registry/src/settings.ts +259 -0
- package/packages/skill-registry/src/vault.ts +80 -0
- package/packages/subagents/README.md +39 -119
- package/packages/subagents/package.json +6 -13
- package/packages/subagents/skills/subagents/SKILL.md +18 -42
- package/packages/subagents/src/agents.ts +213 -0
- package/packages/subagents/src/cards.ts +182 -0
- package/packages/subagents/src/index.ts +609 -1084
- package/packages/subagents/src/manager.ts +429 -0
- package/packages/subagents/src/profiles.ts +130 -0
- package/packages/subagents/src/transcript.ts +154 -0
- package/packages/subagents/src/ui.ts +389 -0
- package/packages/unipi/bundled.js +39756 -45569
- package/packages/unipi/index.ts +55 -10
- package/packages/updater/package.json +2 -2
- package/packages/utility/README.md +76 -69
- package/packages/utility/package.json +2 -2
- package/packages/utility/skills/image/SKILL.md +37 -0
- package/packages/utility/skills/utility/SKILL.md +17 -60
- package/packages/utility/src/answer/extract.ts +128 -0
- package/packages/utility/src/answer/index.ts +213 -0
- package/packages/utility/src/answer/reply.ts +133 -0
- package/packages/utility/src/answer/web.ts +167 -0
- package/packages/utility/src/attach/index.ts +205 -0
- package/packages/utility/src/commands.ts +38 -142
- package/packages/utility/src/diagnostics/engine.ts +50 -5
- package/packages/utility/src/image/index.ts +33 -0
- package/packages/utility/src/image/models.ts +221 -0
- package/packages/{image/src → utility/src/image}/recognize.ts +2 -2
- package/packages/utility/src/image/settings.ts +178 -0
- package/packages/{image/src/image-source.ts → utility/src/image/source.ts} +1 -1
- package/packages/utility/src/image/tools.ts +168 -0
- package/packages/utility/src/image/transports.ts +186 -0
- package/packages/utility/src/index.ts +68 -389
- package/packages/utility/src/lifecycle/cleanup.ts +116 -311
- package/packages/utility/src/rename/gate.ts +102 -0
- package/packages/utility/src/rename/index.ts +191 -0
- package/packages/utility/src/rename/session.ts +170 -0
- package/packages/utility/src/render/delegated.ts +285 -0
- package/packages/utility/src/render/harness.ts +683 -0
- package/packages/utility/src/render/parse.ts +156 -0
- package/packages/utility/src/render/pi-settings.ts +38 -0
- package/packages/utility/src/render/reply-bg.ts +307 -0
- package/packages/utility/src/render/simple.ts +724 -0
- package/packages/utility/src/render/spacing.ts +235 -0
- package/packages/utility/src/render/styled.ts +251 -0
- package/packages/utility/src/render/tools.ts +353 -0
- package/packages/utility/src/settings.ts +166 -233
- package/packages/utility/src/types.ts +1 -222
- package/packages/watchdog/index.ts +17 -6
- package/packages/watchdog/package.json +3 -3
- package/packages/watchdog/src/config.ts +3 -2
- package/packages/web-api/package.json +2 -2
- package/packages/workflow/README.md +3 -0
- package/packages/workflow/index.ts +0 -2
- package/packages/workflow/package.json +2 -2
- package/packages/workflow/src/permission/decide.ts +6 -4
- package/packages/workflow/src/permission/index.ts +17 -7
- package/packages/workflow/src/permission/settings.ts +39 -4
- package/packages/workflow/src/plan/index.ts +19 -4
- package/packages/background-tasks/extensions/delegate-child.ts +0 -1
- package/packages/background-tasks/src/context-parent-snapshot.ts +0 -142
- package/packages/background-tasks/src/context-token-budget.ts +0 -903
- package/packages/background-tasks/src/context-visible-conversation-v2.ts +0 -551
- package/packages/background-tasks/src/delegate/artifacts.ts +0 -487
- package/packages/background-tasks/src/delegate/budget.ts +0 -415
- package/packages/background-tasks/src/delegate/hook-contract-evidence.json +0 -18
- package/packages/background-tasks/src/delegate/hook-contract.ts +0 -154
- package/packages/background-tasks/src/delegate/launch.ts +0 -484
- package/packages/background-tasks/src/delegate/result-package.ts +0 -459
- package/packages/background-tasks/src/delegate/runner.ts +0 -430
- package/packages/background-tasks/src/delegate/seed.ts +0 -423
- package/packages/background-tasks/src/delegate/types.ts +0 -323
- package/packages/background-tasks/src/delegate-child-extension.ts +0 -978
- package/packages/background-tasks/src/delegate-extension.ts +0 -654
- package/packages/background-tasks/src/fixtures/delegate-context-incident.json +0 -17
- package/packages/compactor/skills/compactor-detail/SKILL.md +0 -116
- package/packages/compactor/skills/compactor-doctor/SKILL.md +0 -71
- package/packages/compactor/skills/compactor-stats/SKILL.md +0 -51
- package/packages/compactor/src/compaction/build-sections.ts +0 -76
- package/packages/compactor/src/compaction/extract/goals.ts +0 -36
- package/packages/compactor/src/compaction/extract/preferences.ts +0 -40
- package/packages/compactor/src/compaction/format.ts +0 -53
- package/packages/compactor/src/compaction/merge.ts +0 -143
- package/packages/compactor/src/config/presets.ts +0 -160
- package/packages/compactor/src/executor/executor.ts +0 -233
- package/packages/compactor/src/executor/runtime.ts +0 -115
- package/packages/compactor/src/security/evaluator.ts +0 -89
- package/packages/compactor/src/security/policy.ts +0 -96
- package/packages/compactor/src/security/scanner.ts +0 -65
- package/packages/compactor/src/session/auto-inject.ts +0 -60
- package/packages/compactor/src/session/db.ts +0 -325
- package/packages/compactor/src/session/extract.ts +0 -144
- package/packages/compactor/src/session/resume-inject.ts +0 -64
- package/packages/compactor/src/session/snapshot.ts +0 -327
- package/packages/compactor/src/tools/ctx-batch-execute.ts +0 -41
- package/packages/compactor/src/tools/ctx-execute-file.ts +0 -23
- package/packages/compactor/src/tools/ctx-execute.ts +0 -23
- package/packages/compactor/src/tools/ctx-stats.ts +0 -96
- package/packages/image/README.md +0 -99
- package/packages/image/package.json +0 -61
- package/packages/image/skills/image/SKILL.md +0 -76
- package/packages/image/src/generate.ts +0 -256
- package/packages/image/src/index.ts +0 -135
- package/packages/image/src/models.ts +0 -519
- package/packages/image/src/openai-images-api.ts +0 -282
- package/packages/image/src/register-providers.ts +0 -209
- package/packages/image/src/settings.ts +0 -173
- package/packages/image/src/tools.ts +0 -326
- package/packages/input-shortcuts/src/clipboard.ts +0 -119
- package/packages/kanboard/src/runner.ts +0 -817
- package/packages/skill-registry/skills/auto/SKILL.md +0 -465
- package/packages/skill-registry/skills/brainstorm/SKILL.md +0 -219
- package/packages/skill-registry/skills/chore-create/SKILL.md +0 -315
- package/packages/skill-registry/skills/chore-execute/SKILL.md +0 -314
- package/packages/skill-registry/skills/consolidate/SKILL.md +0 -142
- package/packages/skill-registry/skills/consultant/SKILL.md +0 -97
- package/packages/skill-registry/skills/debug/SKILL.md +0 -228
- package/packages/skill-registry/skills/document/SKILL.md +0 -120
- package/packages/skill-registry/skills/fix/SKILL.md +0 -212
- package/packages/skill-registry/skills/gather-context/SKILL.md +0 -145
- package/packages/skill-registry/skills/plan/SKILL.md +0 -231
- package/packages/skill-registry/skills/quick-fix/SKILL.md +0 -135
- package/packages/skill-registry/skills/quick-work/SKILL.md +0 -110
- package/packages/skill-registry/skills/research/SKILL.md +0 -251
- package/packages/skill-registry/skills/review-work/SKILL.md +0 -187
- package/packages/skill-registry/skills/scan-issues/SKILL.md +0 -195
- package/packages/skill-registry/skills/work/SKILL.md +0 -218
- package/packages/skill-registry/skills/worktree-create/SKILL.md +0 -69
- package/packages/skill-registry/skills/worktree-list/SKILL.md +0 -78
- package/packages/skill-registry/skills/worktree-merge/SKILL.md +0 -89
- package/packages/subagents/agents/delegate.md +0 -14
- package/packages/subagents/agents/oracle.md +0 -78
- package/packages/subagents/agents/researcher.md +0 -52
- package/packages/subagents/agents/reviewer.md +0 -80
- package/packages/subagents/agents/scout.md +0 -50
- package/packages/subagents/agents/worker.md +0 -59
- package/packages/subagents/prompts/council.md +0 -48
- package/packages/subagents/prompts/gather-context-and-clarify.md +0 -13
- package/packages/subagents/prompts/parallel-cleanup.md +0 -59
- package/packages/subagents/prompts/parallel-research.md +0 -50
- package/packages/subagents/prompts/parallel-review.md +0 -54
- package/packages/subagents/prompts/review-loop.md +0 -43
- package/packages/subagents/skills/council-mode/SKILL.md +0 -230
- package/packages/subagents/skills/subagents/references/constraints-and-recipes.md +0 -259
- package/packages/subagents/skills/subagents/references/execution-controls.md +0 -454
- package/packages/subagents/skills/subagents/references/management-authoring-rpc.md +0 -161
- package/packages/subagents/skills/subagents/references/multi-lane-orchestration.md +0 -39
- package/packages/subagents/skills/subagents/references/prompting-and-roles.md +0 -267
- package/packages/subagents/src/acceptance.ts +0 -331
- package/packages/subagents/src/agent-manager.ts +0 -405
- package/packages/subagents/src/agent-memory.ts +0 -300
- package/packages/subagents/src/agent-overrides.ts +0 -183
- package/packages/subagents/src/agent-runner.ts +0 -271
- package/packages/subagents/src/async-runner.ts +0 -422
- package/packages/subagents/src/authority-policy.ts +0 -47
- package/packages/subagents/src/budgets.ts +0 -285
- package/packages/subagents/src/child-safety.ts +0 -140
- package/packages/subagents/src/config.ts +0 -249
- package/packages/subagents/src/conversation-viewer.ts +0 -281
- package/packages/subagents/src/core-compat.ts +0 -94
- package/packages/subagents/src/custom-agents.ts +0 -343
- package/packages/subagents/src/file-system-retry.ts +0 -50
- package/packages/subagents/src/fleet-data.ts +0 -105
- package/packages/subagents/src/fleet-view.ts +0 -322
- package/packages/subagents/src/foreground-detach.ts +0 -59
- package/packages/subagents/src/fork-context.ts +0 -285
- package/packages/subagents/src/global.d.ts +0 -7
- package/packages/subagents/src/guide.ts +0 -129
- package/packages/subagents/src/mission-state.ts +0 -133
- package/packages/subagents/src/mission-store.ts +0 -436
- package/packages/subagents/src/output-limits.ts +0 -142
- package/packages/subagents/src/parity-types.ts +0 -315
- package/packages/subagents/src/pi-args.ts +0 -167
- package/packages/subagents/src/result-files.ts +0 -232
- package/packages/subagents/src/result-watcher.ts +0 -221
- package/packages/subagents/src/retained-children.ts +0 -176
- package/packages/subagents/src/run-fanout-budget.ts +0 -356
- package/packages/subagents/src/scheduled-runs.ts +0 -349
- package/packages/subagents/src/schemas.ts +0 -263
- package/packages/subagents/src/slash-commands.ts +0 -80
- package/packages/subagents/src/supervisor-channel.ts +0 -249
- package/packages/subagents/src/tool-handler.ts +0 -1144
- package/packages/subagents/src/types.ts +0 -238
- package/packages/subagents/src/widget.ts +0 -457
- package/packages/subagents/src/workflow-script.ts +0 -737
- package/packages/subagents/src/workflow-worker.ts +0 -384
- package/packages/subagents/src/worktree.ts +0 -614
- package/packages/utility/src/analytics/collector.ts +0 -293
- package/packages/utility/src/info-screen.ts +0 -80
- package/packages/utility/src/lifecycle/process.ts +0 -162
- package/packages/utility/src/prefix-cache.ts +0 -263
- package/packages/utility/src/skill-discovery.ts +0 -542
- package/packages/utility/src/tools/env.ts +0 -113
- package/packages/utility/src/tui/name-badge-state.ts +0 -315
- package/packages/utility/src/tui/name-badge.ts +0 -109
- /package/packages/{subagents/src → core/src/child-agent}/pi-spawn.ts +0 -0
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: compactor-detail
|
|
3
|
-
description: Full compactor reference — tool parameters, anti-patterns, sandbox languages, context budget, workflows.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Compactor — Full Reference
|
|
7
|
-
|
|
8
|
-
## Tool Parameter Reference
|
|
9
|
-
|
|
10
|
-
### compact
|
|
11
|
-
```
|
|
12
|
-
compact(dryRun?: boolean)
|
|
13
|
-
```
|
|
14
|
-
Agent-facing compaction request. Use `dryRun: true` to preview estimated message reduction without compacting.
|
|
15
|
-
|
|
16
|
-
For user-triggered immediate compaction, prefer the slash command `/unipi:lossless-compact`.
|
|
17
|
-
|
|
18
|
-
### session_recall
|
|
19
|
-
```
|
|
20
|
-
session_recall(query: string, mode?: "bm25" | "regex", limit?: number, offset?: number, expand?: boolean)
|
|
21
|
-
```
|
|
22
|
-
Search current session history. BM25 is default; regex is fallback. The recall path prefers Pi's append-only session branch so it can find messages that are no longer present in live LLM context after compaction.
|
|
23
|
-
|
|
24
|
-
Deprecated alias: `vcc_recall`.
|
|
25
|
-
|
|
26
|
-
### sandbox
|
|
27
|
-
```
|
|
28
|
-
sandbox(language: string, code: string, timeout?: number)
|
|
29
|
-
```
|
|
30
|
-
Run code in a sandboxed environment. Only stdout enters context. 100MB output cap. 30s default timeout.
|
|
31
|
-
|
|
32
|
-
Deprecated alias: `ctx_execute`.
|
|
33
|
-
|
|
34
|
-
### sandbox_file
|
|
35
|
-
```
|
|
36
|
-
sandbox_file(language: string, path: string, timeout?: number)
|
|
37
|
-
```
|
|
38
|
-
Execute a file. File content is injected as `FILE_CONTENT`.
|
|
39
|
-
|
|
40
|
-
Deprecated alias: `ctx_execute_file`.
|
|
41
|
-
|
|
42
|
-
### sandbox_batch
|
|
43
|
-
```
|
|
44
|
-
sandbox_batch(items: Array<{ type: "execute", language: string, code: string, timeout?: number }>)
|
|
45
|
-
```
|
|
46
|
-
Run multiple sandbox executions and return a single combined result.
|
|
47
|
-
|
|
48
|
-
Deprecated alias: `ctx_batch_execute`.
|
|
49
|
-
|
|
50
|
-
### compactor_stats
|
|
51
|
-
```
|
|
52
|
-
compactor_stats()
|
|
53
|
-
```
|
|
54
|
-
Dashboard: session events, compactions, tokens saved, compression ratio, sandbox runs, and search queries.
|
|
55
|
-
|
|
56
|
-
Deprecated alias: `ctx_stats`.
|
|
57
|
-
|
|
58
|
-
### compactor_doctor
|
|
59
|
-
```
|
|
60
|
-
compactor_doctor()
|
|
61
|
-
```
|
|
62
|
-
Diagnostics: config file, session DB, and available runtimes (node, python3, bash).
|
|
63
|
-
|
|
64
|
-
Deprecated alias: `ctx_doctor`.
|
|
65
|
-
|
|
66
|
-
### context_budget
|
|
67
|
-
```
|
|
68
|
-
context_budget()
|
|
69
|
-
```
|
|
70
|
-
Estimate remaining context tokens and percent full. Uses Pi's live context usage when available and includes percentage auto-compaction guidance when enabled.
|
|
71
|
-
|
|
72
|
-
## Sandbox Language Reference
|
|
73
|
-
|
|
74
|
-
| Language | Binaries | Timeout | Notes |
|
|
75
|
-
|----------|----------|---------|-------|
|
|
76
|
-
| javascript | Bun/node | 30s | Default: Bun if available |
|
|
77
|
-
| typescript | Bun/node | 30s | Compiled via Bun transform |
|
|
78
|
-
| python | python3 | 30s | - |
|
|
79
|
-
| shell | bash | 30s | Pipelines supported |
|
|
80
|
-
| ruby | ruby | 30s | - |
|
|
81
|
-
| go | go | 30s | go run |
|
|
82
|
-
| rust | rustc+cargo | 30s | cargo script or rustc |
|
|
83
|
-
| php | php | 30s | - |
|
|
84
|
-
| perl | perl | 30s | - |
|
|
85
|
-
| r | Rscript | 30s | - |
|
|
86
|
-
| elixir | elixir | 30s | - |
|
|
87
|
-
|
|
88
|
-
## Anti-Patterns
|
|
89
|
-
|
|
90
|
-
1. **Don't compact in a tight loop.** Use `context_budget` first and compact at natural break points.
|
|
91
|
-
2. **Don't use `session_recall` for project-wide code search.** It searches the conversation/session only — use `read`/`bash`(rg) for files.
|
|
92
|
-
3. **Don't use `sandbox` for file operations.** Use normal file tools for reads/writes; sandbox is for computation or quick scripts.
|
|
93
|
-
4. **Don't use empty or vague recall queries.** Search for specific filenames, issue numbers, commands, or decisions.
|
|
94
|
-
5. **Don't compact mid-thought if avoidable.** Finish the current step, then compact.
|
|
95
|
-
|
|
96
|
-
## Workflow Patterns
|
|
97
|
-
|
|
98
|
-
### Before Complex Work
|
|
99
|
-
1. `context_budget` — check pressure.
|
|
100
|
-
2. `session_recall("goal files decisions")` — recover relevant prior context.
|
|
101
|
-
3. `compact(dryRun: true)` — preview if context is tight.
|
|
102
|
-
4. `/unipi:lossless-compact` or `compact` at a clean boundary.
|
|
103
|
-
|
|
104
|
-
### Diagnose Compactor Health
|
|
105
|
-
1. `compactor_doctor` — check config, DB, runtimes.
|
|
106
|
-
2. Fix reported issues.
|
|
107
|
-
3. `compactor_stats` — verify counters and savings.
|
|
108
|
-
|
|
109
|
-
### Long Session Recovery
|
|
110
|
-
1. `session_recall(query)` — find older details hidden by compaction.
|
|
111
|
-
2. `context_budget` — decide whether another compaction is needed.
|
|
112
|
-
3. `compactor_stats` — confirm compactions/savings are recorded.
|
|
113
|
-
|
|
114
|
-
### Project Search
|
|
115
|
-
Compactor does not own project content indexing. For code search use `bash` with rg.
|
|
116
|
-
1. `bash` with `rg` for code search
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: compactor-doctor
|
|
3
|
-
description: Diagnostics — validate config, session DB, runtimes, and troubleshoot compactor issues.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Compactor Doctor
|
|
7
|
-
|
|
8
|
-
Run diagnostics and troubleshoot compactor issues.
|
|
9
|
-
|
|
10
|
-
## Commands and Tools
|
|
11
|
-
|
|
12
|
-
- `/unipi:compact-doctor` — user-facing diagnostics
|
|
13
|
-
- `compactor_doctor` tool — agent-callable diagnostics
|
|
14
|
-
- `ctx_doctor` tool — deprecated alias
|
|
15
|
-
|
|
16
|
-
## Checks Performed
|
|
17
|
-
|
|
18
|
-
| Check | What It Validates |
|
|
19
|
-
|-------|-------------------|
|
|
20
|
-
| **Config file** | `~/.unipi/config/compactor/config.json` exists or defaults can be used |
|
|
21
|
-
| **Session DB** | SQLite connection works and session schema is usable |
|
|
22
|
-
| **Runtime: node** | Node.js available for sandbox/runtime helpers |
|
|
23
|
-
| **Runtime: python3** | Python 3 available for Python sandbox execution |
|
|
24
|
-
| **Runtime: bash** | Bash available for shell sandbox execution |
|
|
25
|
-
|
|
26
|
-
## Status Icons
|
|
27
|
-
|
|
28
|
-
- ✅ **pass** — check succeeded
|
|
29
|
-
- ⚠️ **warn** — non-critical issue, such as an optional runtime missing
|
|
30
|
-
- ❌ **fail** — critical issue; a feature may not work
|
|
31
|
-
|
|
32
|
-
## Common Issues
|
|
33
|
-
|
|
34
|
-
### "Config file: Using defaults"
|
|
35
|
-
|
|
36
|
-
- Normal on first run.
|
|
37
|
-
- Config is created by the extension or on settings save.
|
|
38
|
-
- Fix: open `/unipi:settings (Compactor)`, adjust if desired, then save.
|
|
39
|
-
|
|
40
|
-
### "Session DB: Connection failed"
|
|
41
|
-
|
|
42
|
-
- SQLite or `better-sqlite3` may be unavailable.
|
|
43
|
-
- Compaction can still degrade gracefully, but stats/recall may be limited.
|
|
44
|
-
- Fix: verify dependencies and run package install/build steps.
|
|
45
|
-
|
|
46
|
-
### "Runtime: python3 Not found"
|
|
47
|
-
|
|
48
|
-
- Python is not installed or not in `PATH`.
|
|
49
|
-
- Only needed for Python sandbox execution.
|
|
50
|
-
- Fix: install Python 3 or ignore if not needed.
|
|
51
|
-
|
|
52
|
-
## Manual Diagnostics
|
|
53
|
-
|
|
54
|
-
### Check config
|
|
55
|
-
```bash
|
|
56
|
-
cat ~/.unipi/config/compactor/config.json
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Check DB files
|
|
60
|
-
```bash
|
|
61
|
-
ls -la ~/.unipi/db/compactor/
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Check runtimes
|
|
65
|
-
```bash
|
|
66
|
-
node --version
|
|
67
|
-
python3 --version
|
|
68
|
-
bash --version
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Project content indexing is not part of compactor.
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: compactor-stats
|
|
3
|
-
description: Stats display — context savings, session metrics, compactions, sandbox and recall/search counters.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Compactor Stats
|
|
7
|
-
|
|
8
|
-
Display and interpret compactor statistics.
|
|
9
|
-
|
|
10
|
-
## Commands and Tools
|
|
11
|
-
|
|
12
|
-
- `/unipi:compact-stats` — user-facing dashboard
|
|
13
|
-
- `compactor_stats` tool — agent-callable stats
|
|
14
|
-
- `ctx_stats` tool — deprecated alias
|
|
15
|
-
|
|
16
|
-
## Metrics Explained
|
|
17
|
-
|
|
18
|
-
| Metric | Description |
|
|
19
|
-
|--------|-------------|
|
|
20
|
-
| **Session events** | Events tracked for the current session in the compactor session DB |
|
|
21
|
-
| **Compactions** | Number of compaction events recorded |
|
|
22
|
-
| **Tokens saved** | Estimated tokens freed by compaction, using Pi token counts when available and DB fallbacks otherwise |
|
|
23
|
-
| **Compression ratio** | Approximate before/kept ratio from stored compaction stats |
|
|
24
|
-
| **Sandbox runs** | Agent sandbox executions recorded in runtime counters/DB |
|
|
25
|
-
| **Search queries** | Session recall/search queries recorded in runtime counters/DB |
|
|
26
|
-
|
|
27
|
-
## Health Indicators
|
|
28
|
-
|
|
29
|
-
- **Compactions > 0** on long sessions = compaction is happening.
|
|
30
|
-
- **Tokens saved > 0** after compaction = savings were recorded.
|
|
31
|
-
- **Sandbox runs** increasing = sandbox tool usage is tracked.
|
|
32
|
-
- **Search queries** increasing = recall/search activity is tracked.
|
|
33
|
-
|
|
34
|
-
## Reading Stats
|
|
35
|
-
|
|
36
|
-
```text
|
|
37
|
-
📊 Compactor Stats
|
|
38
|
-
Session events: 42
|
|
39
|
-
Compactions: 3
|
|
40
|
-
Tokens saved: 15000
|
|
41
|
-
Sandbox runs: 7
|
|
42
|
-
Search queries: 15
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
This means:
|
|
46
|
-
|
|
47
|
-
- 42 events are tracked for the session.
|
|
48
|
-
- 3 compactions saved roughly 15K tokens.
|
|
49
|
-
- 7 sandbox executions and 15 recall/search queries were recorded.
|
|
50
|
-
|
|
51
|
-
Project content indexing stats are not owned by compactor; use `read`/`bash` (rg) for file search.
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stage 3: Build Sections — Goals, Files, Commits, Blockers, Preferences
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { NormalizedBlock } from "../types.js";
|
|
6
|
-
import { clip, clipSentence, firstLine, nonEmptyLines } from "./content.js";
|
|
7
|
-
import { extractGoals } from "./extract/goals.js";
|
|
8
|
-
import { extractFiles } from "./extract/files.js";
|
|
9
|
-
import { extractPreferences, dedupPreferencesAgainstGoals } from "./extract/preferences.js";
|
|
10
|
-
import { extractCommits, formatCommits } from "./extract/commits.js";
|
|
11
|
-
import { buildBriefSections, stringifyBrief } from "./brief.js";
|
|
12
|
-
import type { SectionData } from "../types.js";
|
|
13
|
-
export type { SectionData } from "../types.js";
|
|
14
|
-
|
|
15
|
-
const BLOCKER_RE =
|
|
16
|
-
/\b(fail(ed|s|ure|ing)?|broken|cannot|can't|won't work|does not work|doesn't work|still (broken|failing|wrong)|blocked|blocker|not (fixed|resolved|working)|crash(es|ed|ing)?)\b/i;
|
|
17
|
-
|
|
18
|
-
const extractOutstandingContext = (blocks: NormalizedBlock[]): string[] => {
|
|
19
|
-
const items: string[] = [];
|
|
20
|
-
const tail = blocks.slice(-20);
|
|
21
|
-
|
|
22
|
-
for (const b of tail) {
|
|
23
|
-
if (b.kind === "tool_result" && b.isError) {
|
|
24
|
-
items.push(`[${b.name}] ${firstLine(b.text, 150)}`);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (b.kind === "assistant" || b.kind === "user") {
|
|
29
|
-
for (const line of nonEmptyLines(b.text)) {
|
|
30
|
-
if (!BLOCKER_RE.test(line)) continue;
|
|
31
|
-
if (line.length < 15) continue;
|
|
32
|
-
if (/^\s*[-*+>]\s/.test(line)) continue;
|
|
33
|
-
if (/^\s*\(/.test(line)) continue;
|
|
34
|
-
if (!/^\s*["'`*_]?[A-Z`]/.test(line)) continue;
|
|
35
|
-
const clipped = b.kind === "user" ? `[user] ${clipSentence(line, 150)}` : clipSentence(line, 150);
|
|
36
|
-
if (!items.includes(clipped)) items.push(clipped);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return items.slice(0, 5);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const formatFileActivity = (blocks: NormalizedBlock[]): string[] => {
|
|
46
|
-
const act = extractFiles(blocks);
|
|
47
|
-
for (const p of act.modified) act.created.delete(p);
|
|
48
|
-
const lines: string[] = [];
|
|
49
|
-
const cap = (set: Set<string>, limit: number) => {
|
|
50
|
-
const arr = [...set];
|
|
51
|
-
if (arr.length <= limit) return arr.join(", ");
|
|
52
|
-
return arr.slice(0, limit).join(", ") + ` (+${arr.length - limit} more)`;
|
|
53
|
-
};
|
|
54
|
-
if (act.modified.size > 0) lines.push(`Modified: ${cap(act.modified, 10)}`);
|
|
55
|
-
if (act.created.size > 0) lines.push(`Created: ${cap(act.created, 10)}`);
|
|
56
|
-
if (act.read.size > 0) lines.push(`Read: ${cap(act.read, 10)}`);
|
|
57
|
-
return lines;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const buildSections = (input: { blocks: NormalizedBlock[]; briefBlocks?: NormalizedBlock[] }): SectionData => {
|
|
61
|
-
const { blocks } = input;
|
|
62
|
-
const briefSections = buildBriefSections(input.briefBlocks ?? blocks);
|
|
63
|
-
const sessionGoal = extractGoals(blocks);
|
|
64
|
-
const userPreferences = dedupPreferencesAgainstGoals(
|
|
65
|
-
extractPreferences(blocks),
|
|
66
|
-
sessionGoal,
|
|
67
|
-
);
|
|
68
|
-
return {
|
|
69
|
-
sessionGoal,
|
|
70
|
-
outstandingContext: extractOutstandingContext(blocks),
|
|
71
|
-
filesAndChanges: formatFileActivity(blocks),
|
|
72
|
-
commits: formatCommits(extractCommits(blocks)),
|
|
73
|
-
userPreferences,
|
|
74
|
-
briefTranscript: stringifyBrief(briefSections),
|
|
75
|
-
};
|
|
76
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Goal extraction — regex-based, scope changes, task verbs
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { NormalizedBlock } from "../../types.js";
|
|
6
|
-
import { nonEmptyLines } from "../content.js";
|
|
7
|
-
|
|
8
|
-
const SCOPE_CHANGE_RE = /\b(scope|focus|switch|move|now|instead|rather than|change|shift|pivot|let's|let us)\b/i;
|
|
9
|
-
const TASK_VERB_RE = /\b(add|create|build|implement|fix|refactor|update|remove|delete|rename|extract|merge|split|convert|migrate|optimize|test|write|generate|setup|configure|install|deploy|release|publish|document|review|audit|analyze|debug|resolve|handle|support|enable|disable|integrate|connect|sync|import|export|validate|verify|check|ensure|make|set|get|put|post|patch|delete)\b/i;
|
|
10
|
-
const GOAL_PREFIX_RE = /^(?:Goal|Objective|Task|Plan|Target|Aim|Intent|Purpose|Mission|Action item|To-do|TODO|FIXME|NOTE|IDEA|HACK|BUG|FEATURE|STORY|EPIC):?\s*/i;
|
|
11
|
-
|
|
12
|
-
export function extractGoals(blocks: NormalizedBlock[]): string[] {
|
|
13
|
-
const goals: string[] = [];
|
|
14
|
-
const seen = new Set<string>();
|
|
15
|
-
|
|
16
|
-
for (const b of blocks) {
|
|
17
|
-
if (b.kind !== "user" && b.kind !== "assistant") continue;
|
|
18
|
-
for (const line of nonEmptyLines(b.text)) {
|
|
19
|
-
let candidate = line;
|
|
20
|
-
// Strip goal prefix
|
|
21
|
-
candidate = candidate.replace(GOAL_PREFIX_RE, "").trim();
|
|
22
|
-
if (candidate.length < 10) continue;
|
|
23
|
-
// Must contain a task verb or scope change
|
|
24
|
-
if (!TASK_VERB_RE.test(candidate) && !SCOPE_CHANGE_RE.test(candidate)) continue;
|
|
25
|
-
// Deduplicate
|
|
26
|
-
const key = candidate.toLowerCase().slice(0, 80);
|
|
27
|
-
if (seen.has(key)) continue;
|
|
28
|
-
seen.add(key);
|
|
29
|
-
goals.push(candidate);
|
|
30
|
-
if (goals.length >= 6) break;
|
|
31
|
-
}
|
|
32
|
-
if (goals.length >= 6) break;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return goals;
|
|
36
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* User preference extraction — track explicit preferences and constraints
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { NormalizedBlock } from "../../types.js";
|
|
6
|
-
import { nonEmptyLines } from "../content.js";
|
|
7
|
-
|
|
8
|
-
const PREF_RE = /\b(prefer|preference|want|would like|should|must|need to|important|critical|avoid|don't|do not|never|always|only|make sure|ensure|remember|keep in mind|note that)\b/i;
|
|
9
|
-
const PREF_PREFIX_RE = /^(?:Preference|Note|Remember|Keep in mind|Important|Critical|Constraint|Rule|Guideline|Style|Format):?\s*/i;
|
|
10
|
-
|
|
11
|
-
export function extractPreferences(blocks: NormalizedBlock[]): string[] {
|
|
12
|
-
const prefs: string[] = [];
|
|
13
|
-
const seen = new Set<string>();
|
|
14
|
-
|
|
15
|
-
for (const b of blocks) {
|
|
16
|
-
if (b.kind !== "user") continue;
|
|
17
|
-
for (const line of nonEmptyLines(b.text)) {
|
|
18
|
-
let candidate = line.replace(PREF_PREFIX_RE, "").trim();
|
|
19
|
-
if (candidate.length < 10) continue;
|
|
20
|
-
if (!PREF_RE.test(candidate)) continue;
|
|
21
|
-
const key = candidate.toLowerCase().slice(0, 80);
|
|
22
|
-
if (seen.has(key)) continue;
|
|
23
|
-
seen.add(key);
|
|
24
|
-
prefs.push(candidate);
|
|
25
|
-
if (prefs.length >= 10) break;
|
|
26
|
-
}
|
|
27
|
-
if (prefs.length >= 10) break;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return prefs;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Remove preferences that overlap with goals */
|
|
34
|
-
export function dedupPreferencesAgainstGoals(prefs: string[], goals: string[]): string[] {
|
|
35
|
-
const goalSet = new Set(goals.map((g) => g.toLowerCase().slice(0, 60)));
|
|
36
|
-
return prefs.filter((p) => {
|
|
37
|
-
const key = p.toLowerCase().slice(0, 60);
|
|
38
|
-
return !goalSet.has(key);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stage 5: Format — Render sections with separators
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { SectionData } from "../types.js";
|
|
6
|
-
|
|
7
|
-
const section = (title: string, items: string[]): string => {
|
|
8
|
-
if (items.length === 0) return "";
|
|
9
|
-
const body = items.map((i) => `- ${i}`).join("\n");
|
|
10
|
-
return `[${title}]\n${body}`;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const BRIEF_MAX_LINES = 120;
|
|
14
|
-
|
|
15
|
-
export const capBrief = (text: string): string => {
|
|
16
|
-
const lines = text.split("\n");
|
|
17
|
-
if (lines.length <= BRIEF_MAX_LINES) return text;
|
|
18
|
-
const omitted = lines.length - BRIEF_MAX_LINES;
|
|
19
|
-
const kept = lines.slice(-BRIEF_MAX_LINES);
|
|
20
|
-
const firstHeader = kept.findIndex((l) => /^\[.+\]/.test(l));
|
|
21
|
-
const clean = firstHeader > 0 ? kept.slice(firstHeader) : kept;
|
|
22
|
-
return `...(${omitted} earlier lines omitted)\n\n${clean.join("\n")}`;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const RECALL_NOTE =
|
|
26
|
-
"Use `vcc_recall` to search for prior work, decisions, and context from before this summary. " +
|
|
27
|
-
"Do not redo work already completed.";
|
|
28
|
-
|
|
29
|
-
export interface FormatSummaryOptions {
|
|
30
|
-
capBriefTranscript?: boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const formatSummary = (data: SectionData, options: FormatSummaryOptions = {}): string => {
|
|
34
|
-
const capBriefTranscript = options.capBriefTranscript ?? true;
|
|
35
|
-
const headerParts = [
|
|
36
|
-
section("Session Goal", data.sessionGoal),
|
|
37
|
-
section("Files And Changes", data.filesAndChanges),
|
|
38
|
-
section("Commits", data.commits),
|
|
39
|
-
section("Outstanding Context", data.outstandingContext),
|
|
40
|
-
section("User Preferences", data.userPreferences),
|
|
41
|
-
].filter(Boolean);
|
|
42
|
-
|
|
43
|
-
const parts: string[] = [];
|
|
44
|
-
if (headerParts.length > 0) {
|
|
45
|
-
parts.push(headerParts.join("\n\n"));
|
|
46
|
-
}
|
|
47
|
-
if (data.briefTranscript) {
|
|
48
|
-
parts.push(capBriefTranscript ? capBrief(data.briefTranscript) : data.briefTranscript);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (parts.length === 0) return "";
|
|
52
|
-
return parts.join("\n\n---\n\n");
|
|
53
|
-
};
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stage 6: Merge — Merge with previous summary, dedup, rolling window
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { capBrief, BRIEF_MAX_LINES } from "./format.js";
|
|
6
|
-
|
|
7
|
-
const HEADER_NAMES = ["Session Goal", "Files And Changes", "Commits", "Outstanding Context", "User Preferences"];
|
|
8
|
-
const SEPARATOR = "\n\n---\n\n";
|
|
9
|
-
|
|
10
|
-
const sectionOf = (text: string, header: string): string => {
|
|
11
|
-
const tag = `[${header}]`;
|
|
12
|
-
const start = text.indexOf(tag);
|
|
13
|
-
if (start < 0) return "";
|
|
14
|
-
const after = text.slice(start);
|
|
15
|
-
const nextSection = HEADER_NAMES
|
|
16
|
-
.filter((h) => h !== header)
|
|
17
|
-
.map((h) => after.indexOf(`[${h}]`))
|
|
18
|
-
.filter((n) => n > 0);
|
|
19
|
-
const nextSep = after.indexOf("\n\n---\n\n");
|
|
20
|
-
const candidates = [...nextSection, ...(nextSep > 0 ? [nextSep] : [])].sort((a, b) => a - b);
|
|
21
|
-
const end = candidates[0];
|
|
22
|
-
return (end ? after.slice(0, end) : after).trim();
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const briefOf = (text: string): string => {
|
|
26
|
-
const idx = text.indexOf(SEPARATOR);
|
|
27
|
-
if (idx < 0) return "";
|
|
28
|
-
return text.slice(idx + SEPARATOR.length).trim();
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const mergeHeaderSection = (header: string, prev: string, fresh: string): string => {
|
|
32
|
-
if (header === "Outstanding Context") return fresh;
|
|
33
|
-
if (!prev) return fresh;
|
|
34
|
-
if (!fresh) return prev;
|
|
35
|
-
|
|
36
|
-
if (header === "Files And Changes") {
|
|
37
|
-
return mergeFileLines(prev, fresh);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const isClean = (l: string) => l.startsWith("- ") && !l.includes("<skill") && !l.includes("</skill");
|
|
41
|
-
const prevLines = prev.split("\n").filter(isClean);
|
|
42
|
-
const freshLines = fresh.split("\n").filter(isClean);
|
|
43
|
-
const combined = [...new Set([...prevLines, ...freshLines])];
|
|
44
|
-
const CAP = header === "Session Goal" ? 8 : header === "Commits" ? 8 : 15;
|
|
45
|
-
const capped = combined.length > CAP ? combined.slice(-CAP) : combined;
|
|
46
|
-
if (capped.length === 0) return "";
|
|
47
|
-
return `[${header}]\n${capped.join("\n")}`;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const mergeFileLines = (prev: string, fresh: string): string => {
|
|
51
|
-
const categories = ["Modified", "Created", "Read"] as const;
|
|
52
|
-
const merged: Record<string, Set<string>> = {};
|
|
53
|
-
for (const cat of categories) merged[cat] = new Set();
|
|
54
|
-
|
|
55
|
-
for (const text of [prev, fresh]) {
|
|
56
|
-
for (const line of text.split("\n")) {
|
|
57
|
-
for (const cat of categories) {
|
|
58
|
-
const prefix = `- ${cat}: `;
|
|
59
|
-
if (!line.startsWith(prefix)) continue;
|
|
60
|
-
let rest = line.slice(prefix.length).replace(/\s*\(\+\d+ more\)\s*$/, "");
|
|
61
|
-
for (const p of rest.split(",")) {
|
|
62
|
-
const trimmed = p.trim();
|
|
63
|
-
if (trimmed) merged[cat].add(trimmed);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
for (const p of merged.Modified) merged.Created.delete(p);
|
|
70
|
-
|
|
71
|
-
const cap = (set: Set<string>, limit: number) => {
|
|
72
|
-
const arr = [...set];
|
|
73
|
-
if (arr.length <= limit) return arr.join(", ");
|
|
74
|
-
return arr.slice(0, limit).join(", ") + ` (+${arr.length - limit} more)`;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const lines: string[] = [];
|
|
78
|
-
if (merged.Modified.size > 0) lines.push(`- Modified: ${cap(merged.Modified, 10)}`);
|
|
79
|
-
if (merged.Created.size > 0) lines.push(`- Created: ${cap(merged.Created, 10)}`);
|
|
80
|
-
if (merged.Read.size > 0) lines.push(`- Read: ${cap(merged.Read, 10)}`);
|
|
81
|
-
if (lines.length === 0) return "";
|
|
82
|
-
return `[Files And Changes]\n${lines.join("\n")}`;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const mergeBriefTranscript = (prev: string, fresh: string): string => {
|
|
86
|
-
if (!prev) return fresh;
|
|
87
|
-
if (!fresh) return prev;
|
|
88
|
-
return prev + "\n\n" + fresh;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const briefLineCount = (text: string): number =>
|
|
92
|
-
text ? text.split("\n").length : 0;
|
|
93
|
-
|
|
94
|
-
const capBriefToLineBudget = (text: string, maxLines: number): string => {
|
|
95
|
-
if (!text || maxLines <= 0) return "";
|
|
96
|
-
const lines = text.split("\n");
|
|
97
|
-
if (lines.length <= maxLines) return text;
|
|
98
|
-
const kept = lines.slice(-maxLines);
|
|
99
|
-
const firstHeader = kept.findIndex((l) => /^\[.+\]/.test(l));
|
|
100
|
-
const clean = firstHeader > 0 ? kept.slice(firstHeader) : kept;
|
|
101
|
-
const omitted = lines.length - clean.length;
|
|
102
|
-
return `...(${omitted} earlier lines omitted)\n\n${clean.join("\n")}`;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/** Fresh brief gets the line budget; previous brief fills the remainder (pi-vcc parity) */
|
|
106
|
-
export const mergeBriefTranscriptWithFreshBudget = (prev: string, fresh: string): string => {
|
|
107
|
-
if (!prev) return fresh;
|
|
108
|
-
if (!fresh) return capBrief(prev);
|
|
109
|
-
const freshLines = briefLineCount(fresh);
|
|
110
|
-
const remainingPrevLines = Math.max(0, BRIEF_MAX_LINES - freshLines);
|
|
111
|
-
const prevTail = capBriefToLineBudget(prev, remainingPrevLines);
|
|
112
|
-
return prevTail ? `${prevTail}\n\n${fresh}` : fresh;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const mergePrevious = (
|
|
116
|
-
prev: string,
|
|
117
|
-
fresh: string,
|
|
118
|
-
options: { preserveFreshBrief?: boolean } = {},
|
|
119
|
-
): string => {
|
|
120
|
-
const headers = HEADER_NAMES
|
|
121
|
-
.map((header) => {
|
|
122
|
-
const freshSec = sectionOf(fresh, header);
|
|
123
|
-
const prevSec = sectionOf(prev, header);
|
|
124
|
-
return mergeHeaderSection(header, prevSec, freshSec);
|
|
125
|
-
})
|
|
126
|
-
.filter(Boolean);
|
|
127
|
-
|
|
128
|
-
const prevBrief = briefOf(prev);
|
|
129
|
-
const freshBrief = briefOf(fresh);
|
|
130
|
-
const mergedBrief = options.preserveFreshBrief
|
|
131
|
-
? mergeBriefTranscriptWithFreshBudget(prevBrief, freshBrief)
|
|
132
|
-
: mergeBriefTranscript(prevBrief, freshBrief);
|
|
133
|
-
|
|
134
|
-
const parts: string[] = [];
|
|
135
|
-
if (headers.length > 0) {
|
|
136
|
-
parts.push(headers.join("\n\n"));
|
|
137
|
-
}
|
|
138
|
-
if (mergedBrief) {
|
|
139
|
-
parts.push(options.preserveFreshBrief ? mergedBrief : capBrief(mergedBrief));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return parts.join(SEPARATOR);
|
|
143
|
-
};
|