@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,281 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pi-unipi/subagents — Conversation Viewer
|
|
3
|
-
*
|
|
4
|
-
* Live-scrolling overlay for viewing agent conversations.
|
|
5
|
-
* Subscribes to session events for real-time streaming updates.
|
|
6
|
-
* Supports keyboard navigation: ↑↓, PgUp/PgDn, Home/End, Esc/q to close.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { AgentSession } from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import { formatMs, describeActivity } from "./widget.js";
|
|
11
|
-
import {
|
|
12
|
-
type Component,
|
|
13
|
-
matchesKey,
|
|
14
|
-
type TUI,
|
|
15
|
-
truncateToWidth,
|
|
16
|
-
visibleWidth,
|
|
17
|
-
wrapTextWithAnsi,
|
|
18
|
-
} from "@earendil-works/pi-tui";
|
|
19
|
-
import type { AgentActivity } from "./types.js";
|
|
20
|
-
|
|
21
|
-
/** Lines consumed by chrome: top border + header + header sep + footer sep + footer + bottom border. */
|
|
22
|
-
const CHROME_LINES = 6;
|
|
23
|
-
const MIN_VIEWPORT = 3;
|
|
24
|
-
|
|
25
|
-
/** Extract text from content array. */
|
|
26
|
-
function extractText(content: string | Array<{ type: string; text?: string }>): string {
|
|
27
|
-
if (typeof content === "string") return content;
|
|
28
|
-
return content
|
|
29
|
-
.filter((p): p is { type: "text"; text: string } => p.type === "text" && typeof p.text === "string")
|
|
30
|
-
.map((p) => p.text)
|
|
31
|
-
.join("");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Format tokens compactly. */
|
|
35
|
-
function formatTokens(count: number): string {
|
|
36
|
-
if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}M token`;
|
|
37
|
-
if (count >= 1_000) return `${(count / 1_000).toFixed(1)}k token`;
|
|
38
|
-
return `${count} token`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Describe current activity from active tools. */
|
|
42
|
-
|
|
43
|
-
interface ViewerRecord {
|
|
44
|
-
type: string;
|
|
45
|
-
description: string;
|
|
46
|
-
status: string;
|
|
47
|
-
toolUses: number;
|
|
48
|
-
startedAt: number;
|
|
49
|
-
completedAt?: number;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class ConversationViewer implements Component {
|
|
53
|
-
private scrollOffset = 0;
|
|
54
|
-
private autoScroll = true;
|
|
55
|
-
private unsubscribe: (() => void) | undefined;
|
|
56
|
-
private lastInnerW = 0;
|
|
57
|
-
private closed = false;
|
|
58
|
-
|
|
59
|
-
constructor(
|
|
60
|
-
private tui: TUI,
|
|
61
|
-
private session: AgentSession,
|
|
62
|
-
private record: ViewerRecord,
|
|
63
|
-
private activity: AgentActivity | undefined,
|
|
64
|
-
private theme: any,
|
|
65
|
-
private done: (result: undefined) => void,
|
|
66
|
-
) {
|
|
67
|
-
this.unsubscribe = session.subscribe(() => {
|
|
68
|
-
if (this.closed) return;
|
|
69
|
-
this.tui.requestRender();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
handleInput(data: string): void {
|
|
74
|
-
if (matchesKey(data, "escape") || matchesKey(data, "q")) {
|
|
75
|
-
this.closed = true;
|
|
76
|
-
this.done(undefined);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const totalLines = this.buildContentLines(this.lastInnerW).length;
|
|
81
|
-
const viewportHeight = this.viewportHeight();
|
|
82
|
-
const maxScroll = Math.max(0, totalLines - viewportHeight);
|
|
83
|
-
|
|
84
|
-
if (matchesKey(data, "up") || matchesKey(data, "k")) {
|
|
85
|
-
this.scrollOffset = Math.max(0, this.scrollOffset - 1);
|
|
86
|
-
this.autoScroll = this.scrollOffset >= maxScroll;
|
|
87
|
-
} else if (matchesKey(data, "down") || matchesKey(data, "j")) {
|
|
88
|
-
this.scrollOffset = Math.min(maxScroll, this.scrollOffset + 1);
|
|
89
|
-
this.autoScroll = this.scrollOffset >= maxScroll;
|
|
90
|
-
} else if (matchesKey(data, "pageUp")) {
|
|
91
|
-
this.scrollOffset = Math.max(0, this.scrollOffset - viewportHeight);
|
|
92
|
-
this.autoScroll = false;
|
|
93
|
-
} else if (matchesKey(data, "pageDown")) {
|
|
94
|
-
this.scrollOffset = Math.min(maxScroll, this.scrollOffset + viewportHeight);
|
|
95
|
-
this.autoScroll = this.scrollOffset >= maxScroll;
|
|
96
|
-
} else if (matchesKey(data, "home")) {
|
|
97
|
-
this.scrollOffset = 0;
|
|
98
|
-
this.autoScroll = false;
|
|
99
|
-
} else if (matchesKey(data, "end")) {
|
|
100
|
-
this.scrollOffset = maxScroll;
|
|
101
|
-
this.autoScroll = true;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
render(width: number): string[] {
|
|
106
|
-
if (width < 6) return [];
|
|
107
|
-
const th = this.theme;
|
|
108
|
-
const innerW = width - 4; // border + padding
|
|
109
|
-
this.lastInnerW = innerW;
|
|
110
|
-
const lines: string[] = [];
|
|
111
|
-
|
|
112
|
-
const pad = (s: string, len: number) => {
|
|
113
|
-
const vis = visibleWidth(s);
|
|
114
|
-
return s + " ".repeat(Math.max(0, len - vis));
|
|
115
|
-
};
|
|
116
|
-
const row = (content: string) =>
|
|
117
|
-
th.fg("border", "│") + " " + truncateToWidth(pad(content, innerW), innerW) + " " + th.fg("border", "│");
|
|
118
|
-
const hrTop = th.fg("border", `╭${"─".repeat(width - 2)}╮`);
|
|
119
|
-
const hrBot = th.fg("border", `╰${"─".repeat(width - 2)}╯`);
|
|
120
|
-
const hrMid = row(th.fg("dim", "─".repeat(innerW)));
|
|
121
|
-
|
|
122
|
-
// Header
|
|
123
|
-
lines.push(hrTop);
|
|
124
|
-
const name = this.record.type;
|
|
125
|
-
const statusIcon =
|
|
126
|
-
this.record.status === "running"
|
|
127
|
-
? th.fg("accent", "●")
|
|
128
|
-
: this.record.status === "completed"
|
|
129
|
-
? th.fg("success", "✓")
|
|
130
|
-
: this.record.status === "error"
|
|
131
|
-
? th.fg("error", "✗")
|
|
132
|
-
: th.fg("dim", "○");
|
|
133
|
-
|
|
134
|
-
const duration = this.record.completedAt
|
|
135
|
-
? formatMs(this.record.completedAt - this.record.startedAt)
|
|
136
|
-
: `${formatMs(Date.now() - this.record.startedAt)} (running)`;
|
|
137
|
-
|
|
138
|
-
const headerParts: string[] = [duration];
|
|
139
|
-
const toolUses = this.activity?.toolUses ?? this.record.toolUses;
|
|
140
|
-
if (toolUses > 0) headerParts.unshift(`${toolUses} tool${toolUses === 1 ? "" : "s"}`);
|
|
141
|
-
if (this.activity?.session) {
|
|
142
|
-
try {
|
|
143
|
-
const tokens = (this.activity.session as any).getSessionStats().tokens.total;
|
|
144
|
-
if (tokens > 0) headerParts.push(formatTokens(tokens));
|
|
145
|
-
} catch {
|
|
146
|
-
/* */
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
lines.push(
|
|
151
|
-
row(
|
|
152
|
-
`${statusIcon} ${th.bold(name)} ${th.fg("muted", this.record.description)} ${th.fg("dim", "·")} ${th.fg("dim", headerParts.join(" · "))}`,
|
|
153
|
-
),
|
|
154
|
-
);
|
|
155
|
-
lines.push(hrMid);
|
|
156
|
-
|
|
157
|
-
// Content area
|
|
158
|
-
const contentLines = this.buildContentLines(innerW);
|
|
159
|
-
const viewportHeight = this.viewportHeight();
|
|
160
|
-
const maxScroll = Math.max(0, contentLines.length - viewportHeight);
|
|
161
|
-
|
|
162
|
-
if (this.autoScroll) {
|
|
163
|
-
this.scrollOffset = maxScroll;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const visibleStart = Math.min(this.scrollOffset, maxScroll);
|
|
167
|
-
const visible = contentLines.slice(visibleStart, visibleStart + viewportHeight);
|
|
168
|
-
|
|
169
|
-
for (let i = 0; i < viewportHeight; i++) {
|
|
170
|
-
lines.push(row(visible[i] ?? ""));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Footer
|
|
174
|
-
lines.push(hrMid);
|
|
175
|
-
const scrollPct =
|
|
176
|
-
contentLines.length <= viewportHeight
|
|
177
|
-
? "100%"
|
|
178
|
-
: `${Math.round(((visibleStart + viewportHeight) / contentLines.length) * 100)}%`;
|
|
179
|
-
const footerLeft = th.fg("dim", `${contentLines.length} lines · ${scrollPct}`);
|
|
180
|
-
const footerRight = th.fg("dim", "↑↓ scroll · PgUp/PgDn · Esc close");
|
|
181
|
-
const footerGap = Math.max(1, innerW - visibleWidth(footerLeft) - visibleWidth(footerRight));
|
|
182
|
-
lines.push(row(footerLeft + " ".repeat(footerGap) + footerRight));
|
|
183
|
-
lines.push(hrBot);
|
|
184
|
-
|
|
185
|
-
return lines;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
invalidate(): void {
|
|
189
|
-
/* no cached state to clear */
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
dispose(): void {
|
|
193
|
-
this.closed = true;
|
|
194
|
-
if (this.unsubscribe) {
|
|
195
|
-
this.unsubscribe();
|
|
196
|
-
this.unsubscribe = undefined;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// ---- Private ----
|
|
201
|
-
|
|
202
|
-
private viewportHeight(): number {
|
|
203
|
-
return Math.max(MIN_VIEWPORT, this.tui.terminal.rows - CHROME_LINES);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
private buildContentLines(width: number): string[] {
|
|
207
|
-
if (width <= 0) return [];
|
|
208
|
-
|
|
209
|
-
const th = this.theme;
|
|
210
|
-
const messages = (this.session as any).messages;
|
|
211
|
-
const lines: string[] = [];
|
|
212
|
-
|
|
213
|
-
if (!messages || messages.length === 0) {
|
|
214
|
-
lines.push(th.fg("dim", "(waiting for first message...)"));
|
|
215
|
-
return lines;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
let needsSeparator = false;
|
|
219
|
-
for (const msg of messages) {
|
|
220
|
-
if (msg.role === "user") {
|
|
221
|
-
const text = typeof msg.content === "string" ? msg.content : extractText(msg.content);
|
|
222
|
-
if (!text.trim()) continue;
|
|
223
|
-
if (needsSeparator) lines.push(th.fg("dim", "───"));
|
|
224
|
-
lines.push(th.fg("accent", "[User]"));
|
|
225
|
-
for (const line of wrapTextWithAnsi(text.trim(), width)) {
|
|
226
|
-
lines.push(line);
|
|
227
|
-
}
|
|
228
|
-
} else if (msg.role === "assistant") {
|
|
229
|
-
const textParts: string[] = [];
|
|
230
|
-
const toolCalls: string[] = [];
|
|
231
|
-
for (const c of msg.content) {
|
|
232
|
-
if (c.type === "text" && c.text) textParts.push(c.text);
|
|
233
|
-
else if (c.type === "tool_use" || c.type === "toolCall") {
|
|
234
|
-
toolCalls.push((c as any).name ?? (c as any).toolName ?? "unknown");
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (needsSeparator) lines.push(th.fg("dim", "───"));
|
|
238
|
-
lines.push(th.bold("[Assistant]"));
|
|
239
|
-
if (textParts.length > 0) {
|
|
240
|
-
for (const line of wrapTextWithAnsi(textParts.join("\n").trim(), width)) {
|
|
241
|
-
lines.push(line);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
for (const name of toolCalls) {
|
|
245
|
-
lines.push(truncateToWidth(th.fg("muted", ` [Tool: ${name}]`), width));
|
|
246
|
-
}
|
|
247
|
-
} else if (msg.role === "toolResult") {
|
|
248
|
-
const text = extractText(msg.content);
|
|
249
|
-
const truncated = text.length > 500 ? text.slice(0, 500) + "... (truncated)" : text;
|
|
250
|
-
if (!truncated.trim()) continue;
|
|
251
|
-
if (needsSeparator) lines.push(th.fg("dim", "───"));
|
|
252
|
-
lines.push(th.fg("dim", "[Result]"));
|
|
253
|
-
for (const line of wrapTextWithAnsi(truncated.trim(), width)) {
|
|
254
|
-
lines.push(th.fg("dim", line));
|
|
255
|
-
}
|
|
256
|
-
} else if ((msg as any).role === "bashExecution") {
|
|
257
|
-
const bash = msg as any;
|
|
258
|
-
if (needsSeparator) lines.push(th.fg("dim", "───"));
|
|
259
|
-
lines.push(truncateToWidth(th.fg("muted", ` $ ${bash.command}`), width));
|
|
260
|
-
if (bash.output?.trim()) {
|
|
261
|
-
const out = bash.output.length > 500 ? bash.output.slice(0, 500) + "... (truncated)" : bash.output;
|
|
262
|
-
for (const line of wrapTextWithAnsi(out.trim(), width)) {
|
|
263
|
-
lines.push(th.fg("dim", line));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
} else {
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
needsSeparator = true;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Streaming indicator for running agents
|
|
273
|
-
if (this.record.status === "running" && this.activity) {
|
|
274
|
-
const act = describeActivity(this.activity.activeTools, this.activity.responseText);
|
|
275
|
-
lines.push("");
|
|
276
|
-
lines.push(truncateToWidth(th.fg("accent", "▍ ") + th.fg("dim", act), width));
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return lines.map((l) => truncateToWidth(l, width));
|
|
280
|
-
}
|
|
281
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pi-unipi/subagents — Local helpers (not in @pi-unipi/core)
|
|
3
|
-
*
|
|
4
|
-
* boundHelperOutput: bounded output with artifact-to-disk fallback.
|
|
5
|
-
* withHerdrBlocked: wraps a fn with herdr:blocked events.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { emitEvent } from "@pi-unipi/core";
|
|
9
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import { chmodSync, lstatSync, mkdirSync, writeFileSync } from "node:fs";
|
|
11
|
-
import { homedir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
import { randomUUID } from "node:crypto";
|
|
14
|
-
|
|
15
|
-
export interface BoundedHelperOutput {
|
|
16
|
-
text: string;
|
|
17
|
-
truncated: boolean;
|
|
18
|
-
originalBytes: number;
|
|
19
|
-
artifactPath?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const MAX_RAW_HELPER_ARTIFACT_BYTES = 16 * 1024 * 1024;
|
|
23
|
-
|
|
24
|
-
export function boundHelperOutput(
|
|
25
|
-
text: string,
|
|
26
|
-
maxBytes = 64 * 1024,
|
|
27
|
-
existingArtifactPath?: string,
|
|
28
|
-
): BoundedHelperOutput {
|
|
29
|
-
const originalBytes = Buffer.byteLength(text, "utf8");
|
|
30
|
-
if (originalBytes <= maxBytes) return { text, truncated: false, originalBytes };
|
|
31
|
-
|
|
32
|
-
let artifactPath = existingArtifactPath;
|
|
33
|
-
let artifactWarning: string | undefined;
|
|
34
|
-
if (!artifactPath && originalBytes <= MAX_RAW_HELPER_ARTIFACT_BYTES) {
|
|
35
|
-
try {
|
|
36
|
-
const dir = join(homedir(), ".unipi", "tool-results");
|
|
37
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
38
|
-
let stat = lstatSync(dir);
|
|
39
|
-
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
40
|
-
throw new Error(`Refusing unsafe tool-result directory: ${dir}`);
|
|
41
|
-
}
|
|
42
|
-
if ((stat.mode & 0o077) !== 0) {
|
|
43
|
-
chmodSync(dir, 0o700);
|
|
44
|
-
stat = lstatSync(dir);
|
|
45
|
-
if ((stat.mode & 0o077) !== 0) throw new Error(`Refusing non-private tool-result directory: ${dir}`);
|
|
46
|
-
}
|
|
47
|
-
artifactPath = join(dir, `helper-${randomUUID()}.txt`);
|
|
48
|
-
writeFileSync(artifactPath, text, { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
49
|
-
} catch (error) {
|
|
50
|
-
artifactWarning = `Full-output artifact unavailable: ${error instanceof Error ? error.message : String(error)}`;
|
|
51
|
-
artifactPath = undefined;
|
|
52
|
-
}
|
|
53
|
-
} else if (!artifactPath) {
|
|
54
|
-
artifactWarning = `Full output exceeded the ${MAX_RAW_HELPER_ARTIFACT_BYTES}-byte local artifact safety cap and was not retained.`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const marker = [
|
|
58
|
-
"",
|
|
59
|
-
"--- output bounded by UniPi ---",
|
|
60
|
-
artifactPath ? `Full output: ${artifactPath}` : artifactWarning!,
|
|
61
|
-
`Original size: ${originalBytes} bytes; model-visible ceiling: ${maxBytes} bytes.`,
|
|
62
|
-
...(artifactPath ? ["Use the read tool with offset/limit to inspect only the needed region."] : []),
|
|
63
|
-
].join("\n");
|
|
64
|
-
const markerBytes = Buffer.byteLength(marker, "utf8");
|
|
65
|
-
const contentBudget = Math.max(1, maxBytes - markerBytes - 80);
|
|
66
|
-
const bytes = Buffer.from(text, "utf8");
|
|
67
|
-
const headBytes = Math.ceil(contentBudget * 0.75);
|
|
68
|
-
const tailBytes = Math.max(0, contentBudget - headBytes);
|
|
69
|
-
const head = bytes.subarray(0, headBytes).toString("utf8").replace(/\uFFFD+$/u, "");
|
|
70
|
-
const tail = bytes.subarray(originalBytes - tailBytes).toString("utf8").replace(/^\uFFFD+/u, "");
|
|
71
|
-
let bounded = `${head}\n… ${Math.max(0, originalBytes - contentBudget)} bytes omitted …\n${tail}${marker}`;
|
|
72
|
-
if (Buffer.byteLength(bounded, "utf8") > maxBytes) {
|
|
73
|
-
bounded = Buffer.from(bounded, "utf8").subarray(0, maxBytes).toString("utf8").replace(/\uFFFD+$/u, "");
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
text: bounded,
|
|
77
|
-
truncated: true,
|
|
78
|
-
originalBytes,
|
|
79
|
-
artifactPath,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export async function withHerdrBlocked<T>(
|
|
84
|
-
pi: Pick<ExtensionAPI, "events">,
|
|
85
|
-
label: string,
|
|
86
|
-
fn: () => Promise<T>,
|
|
87
|
-
): Promise<T> {
|
|
88
|
-
emitEvent(pi, "herdr:blocked", { active: true, label });
|
|
89
|
-
try {
|
|
90
|
-
return await fn();
|
|
91
|
-
} finally {
|
|
92
|
-
emitEvent(pi, "herdr:blocked", { active: false, label });
|
|
93
|
-
}
|
|
94
|
-
}
|