@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,101 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @pi-unipi/utility — Shared types
|
|
3
|
-
*
|
|
4
|
-
* Type definitions for utility modules: lifecycle, cache, analytics,
|
|
5
|
-
* diagnostics, display, TUI, and tools.
|
|
2
|
+
* @pi-unipi/utility — Shared types (diagnostics)
|
|
6
3
|
*/
|
|
7
4
|
|
|
8
|
-
// ─── Lifecycle ───────────────────────────────────────────────────────────────
|
|
9
|
-
|
|
10
|
-
/** Cleanup function registered with the lifecycle manager */
|
|
11
|
-
export type CleanupFn = () => void | Promise<void>;
|
|
12
|
-
|
|
13
|
-
/** Process lifecycle state */
|
|
14
|
-
export type LifecycleState = "running" | "shutting_down" | "orphaned" | "error";
|
|
15
|
-
|
|
16
|
-
/** Options for ProcessLifecycle */
|
|
17
|
-
export interface ProcessLifecycleOptions {
|
|
18
|
-
/** Polling interval in ms for parent PID checks (default: 30000) */
|
|
19
|
-
pollIntervalMs?: number;
|
|
20
|
-
/** Whether to install signal handlers (default: true) */
|
|
21
|
-
handleSignals?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ─── Cache ───────────────────────────────────────────────────────────────────
|
|
25
|
-
|
|
26
|
-
/** Cache entry with metadata */
|
|
27
|
-
export interface CacheEntry<V> {
|
|
28
|
-
value: V;
|
|
29
|
-
expiresAt: number;
|
|
30
|
-
createdAt: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** TTL cache backend interface */
|
|
34
|
-
export interface CacheBackend<K, V> {
|
|
35
|
-
get(key: K): Promise<V | undefined>;
|
|
36
|
-
set(key: K, value: V, ttlMs: number): Promise<void>;
|
|
37
|
-
has(key: K): Promise<boolean>;
|
|
38
|
-
delete(key: K): Promise<boolean>;
|
|
39
|
-
cleanupExpired(): Promise<number>;
|
|
40
|
-
clear(): Promise<void>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** TTL cache options */
|
|
44
|
-
export interface TTLCacheOptions {
|
|
45
|
-
/** Use SQLite persistence (default: false) */
|
|
46
|
-
persistent?: boolean;
|
|
47
|
-
/** SQLite DB path (default: auto) */
|
|
48
|
-
dbPath?: string;
|
|
49
|
-
/** Default TTL in ms */
|
|
50
|
-
defaultTtlMs?: number;
|
|
51
|
-
/** Max entries in memory cache */
|
|
52
|
-
maxMemoryEntries?: number;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ─── Analytics ───────────────────────────────────────────────────────────────
|
|
56
|
-
|
|
57
|
-
/** Analytics event types */
|
|
58
|
-
export type AnalyticsEventType =
|
|
59
|
-
| "module_load"
|
|
60
|
-
| "command_run"
|
|
61
|
-
| "tool_call"
|
|
62
|
-
| "error"
|
|
63
|
-
| "compaction"
|
|
64
|
-
| "search";
|
|
65
|
-
|
|
66
|
-
/** Single analytics event record */
|
|
67
|
-
export interface AnalyticsEvent {
|
|
68
|
-
id: string;
|
|
69
|
-
type: AnalyticsEventType;
|
|
70
|
-
timestamp: number;
|
|
71
|
-
module?: string;
|
|
72
|
-
command?: string;
|
|
73
|
-
tool?: string;
|
|
74
|
-
durationMs?: number;
|
|
75
|
-
success?: boolean;
|
|
76
|
-
metadata?: Record<string, unknown>;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Daily rollup of analytics events */
|
|
80
|
-
export interface AnalyticsRollup {
|
|
81
|
-
date: string; // YYYY-MM-DD
|
|
82
|
-
events: Record<AnalyticsEventType, number>;
|
|
83
|
-
totalDurationMs: number;
|
|
84
|
-
errorCount: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Analytics collector options */
|
|
88
|
-
export interface AnalyticsOptions {
|
|
89
|
-
/** SQLite DB path */
|
|
90
|
-
dbPath?: string;
|
|
91
|
-
/** Max events before auto-rollup (default: 10000) */
|
|
92
|
-
maxEvents?: number;
|
|
93
|
-
/** Enable daily rollup (default: true) */
|
|
94
|
-
rollupEnabled?: boolean;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ─── Diagnostics ─────────────────────────────────────────────────────────────
|
|
98
|
-
|
|
99
5
|
/** Health status for a single check */
|
|
100
6
|
export type HealthStatus = "healthy" | "warning" | "error" | "unknown";
|
|
101
7
|
|
|
@@ -128,130 +34,3 @@ export interface DiagnosticPlugin {
|
|
|
128
34
|
module: string;
|
|
129
35
|
run(): Promise<DiagnosticCheck[]>;
|
|
130
36
|
}
|
|
131
|
-
|
|
132
|
-
// ─── Display ─────────────────────────────────────────────────────────────────
|
|
133
|
-
|
|
134
|
-
/** Detected terminal capabilities */
|
|
135
|
-
export interface TerminalCapabilities {
|
|
136
|
-
/** Terminal supports basic colors */
|
|
137
|
-
color: boolean;
|
|
138
|
-
/** Terminal supports 256/truecolor */
|
|
139
|
-
truecolor: boolean;
|
|
140
|
-
/** Nerd Font detected */
|
|
141
|
-
nerdFont: boolean;
|
|
142
|
-
/** Unicode support level */
|
|
143
|
-
unicode: "none" | "basic" | "full";
|
|
144
|
-
/** Terminal width in columns */
|
|
145
|
-
width: number;
|
|
146
|
-
/** Terminal height in rows */
|
|
147
|
-
height: number;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** Width management options */
|
|
151
|
-
export interface WidthOptions {
|
|
152
|
-
/** Truncation indicator (default: "…") */
|
|
153
|
-
ellipsis?: string;
|
|
154
|
-
/** Whether to break words (default: false) */
|
|
155
|
-
breakWords?: boolean;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// ─── TUI ─────────────────────────────────────────────────────────────────────
|
|
159
|
-
|
|
160
|
-
/** Settings schema entry */
|
|
161
|
-
export interface SettingSchema {
|
|
162
|
-
key: string;
|
|
163
|
-
type: "string" | "number" | "boolean" | "object" | "array";
|
|
164
|
-
description: string;
|
|
165
|
-
default?: unknown;
|
|
166
|
-
required?: boolean;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** Settings inspector state */
|
|
170
|
-
export interface SettingsInspectorState {
|
|
171
|
-
schemas: SettingSchema[];
|
|
172
|
-
values: Record<string, unknown>;
|
|
173
|
-
selectedIndex: number;
|
|
174
|
-
searchQuery: string;
|
|
175
|
-
editMode: boolean;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ─── Tools ───────────────────────────────────────────────────────────────────
|
|
179
|
-
|
|
180
|
-
/** Single batch command entry */
|
|
181
|
-
export interface BatchCommand {
|
|
182
|
-
type: "command" | "tool" | "search";
|
|
183
|
-
name: string;
|
|
184
|
-
args?: Record<string, unknown>;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** Batch execution options */
|
|
188
|
-
export interface BatchOptions {
|
|
189
|
-
/** Fail on first error (default: true) */
|
|
190
|
-
failFast?: boolean;
|
|
191
|
-
/** Timeout per command in ms (default: 30000) */
|
|
192
|
-
commandTimeoutMs?: number;
|
|
193
|
-
/** Total timeout in ms (default: 300000) */
|
|
194
|
-
totalTimeoutMs?: number;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** Result of a single batch command */
|
|
198
|
-
export interface BatchResult {
|
|
199
|
-
command: BatchCommand;
|
|
200
|
-
success: boolean;
|
|
201
|
-
result?: unknown;
|
|
202
|
-
error?: string;
|
|
203
|
-
durationMs: number;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/** Complete batch execution result */
|
|
207
|
-
export interface BatchReport {
|
|
208
|
-
success: boolean;
|
|
209
|
-
results: BatchResult[];
|
|
210
|
-
totalDurationMs: number;
|
|
211
|
-
rolledBack: boolean;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** Environment info returned by ctx_env */
|
|
215
|
-
export interface EnvironmentInfo {
|
|
216
|
-
nodeVersion: string;
|
|
217
|
-
piVersion: string;
|
|
218
|
-
os: string;
|
|
219
|
-
platform: string;
|
|
220
|
-
unipiModules: string[];
|
|
221
|
-
configPaths: string[];
|
|
222
|
-
extensionPaths: string[];
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// ─── Cleanup ─────────────────────────────────────────────────────────────────
|
|
226
|
-
|
|
227
|
-
/** Result of a cleanup operation */
|
|
228
|
-
export interface CleanupResult {
|
|
229
|
-
/** What was cleaned */
|
|
230
|
-
category: "db" | "temp" | "tool-results" | "session" | "cache" | "log";
|
|
231
|
-
/** Items removed */
|
|
232
|
-
removed: number;
|
|
233
|
-
/** Bytes freed (approximate) */
|
|
234
|
-
bytesFreed: number;
|
|
235
|
-
/** Paths that were cleaned */
|
|
236
|
-
paths: string[];
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** Complete cleanup report */
|
|
240
|
-
export interface CleanupReport {
|
|
241
|
-
timestamp: number;
|
|
242
|
-
results: CleanupResult[];
|
|
243
|
-
totalRemoved: number;
|
|
244
|
-
totalBytesFreed: number;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/** Cleanup options */
|
|
248
|
-
export interface CleanupOptions {
|
|
249
|
-
/** Max age in days for DB files (default: 14) */
|
|
250
|
-
dbMaxAgeDays?: number;
|
|
251
|
-
/** Max age in days for temp files (default: 7) */
|
|
252
|
-
tempMaxAgeDays?: number;
|
|
253
|
-
/** Max age in days for sessions (default: 30) */
|
|
254
|
-
sessionMaxAgeDays?: number;
|
|
255
|
-
/** Dry run — report only (default: false) */
|
|
256
|
-
dryRun?: boolean;
|
|
257
|
-
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { appendFileSync, mkdirSync } from "node:fs";
|
|
15
15
|
import * as os from "node:os";
|
|
16
16
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
17
|
-
import { askJev,
|
|
17
|
+
import { askJev, harnessToolResultDetails, harnessMetadata, resolveDecisionModel, sendHarnessUserMessage } from "@pi-unipi/core";
|
|
18
18
|
import { getSharedTaskRegistry } from "@pi-unipi/background-tasks";
|
|
19
19
|
import { loadWatchdogSettings, registerWatchdogSettings, type WatchdogSettings } from "./src/config.js";
|
|
20
20
|
import { evaluateTick } from "./src/decide.js";
|
|
@@ -25,8 +25,7 @@ import { extractText } from "./src/extract.js";
|
|
|
25
25
|
const NEVER_WATCH = new Set([
|
|
26
26
|
"read", "write", "edit", "grep", "find", "ls",
|
|
27
27
|
"ask_user",
|
|
28
|
-
"
|
|
29
|
-
"set_session_name", "ctx_env",
|
|
28
|
+
"read_subagent", "bg_kill", "bg_tasks",
|
|
30
29
|
]);
|
|
31
30
|
|
|
32
31
|
interface TrackedCall {
|
|
@@ -217,6 +216,12 @@ export function registerWatchdogExtension(pi: { on(event: string, handler: (even
|
|
|
217
216
|
return {
|
|
218
217
|
content: [{ type: "text", text: `${warning}\n\n${original}` }],
|
|
219
218
|
isError: true,
|
|
219
|
+
details: harnessToolResultDetails(
|
|
220
|
+
(event as { details?: unknown }).details,
|
|
221
|
+
{ source: "Watchdog", title: "Kill warning", synopsis: "Killed after timeout — do not blindly re-run", severity: "warning" },
|
|
222
|
+
"boundary",
|
|
223
|
+
warning,
|
|
224
|
+
),
|
|
220
225
|
};
|
|
221
226
|
});
|
|
222
227
|
|
|
@@ -230,6 +235,7 @@ export function registerWatchdogExtension(pi: { on(event: string, handler: (even
|
|
|
230
235
|
customType: "unipi-watchdog",
|
|
231
236
|
content,
|
|
232
237
|
display: true,
|
|
238
|
+
details: { unipiHarness: harnessMetadata({ source: "Watchdog", title: "Watchdog warnings", synopsis: "Drained pending warnings", severity: "warning" }, "before_agent_start") },
|
|
233
239
|
},
|
|
234
240
|
};
|
|
235
241
|
});
|
|
@@ -302,7 +308,7 @@ function gatherWatched(settings: WatchdogSettings): WatchedItem[] {
|
|
|
302
308
|
items.push({
|
|
303
309
|
key: `bg:${task.id}`,
|
|
304
310
|
kind: "bg",
|
|
305
|
-
toolName:
|
|
311
|
+
toolName: "bg_run",
|
|
306
312
|
command: task.command.slice(0, 500),
|
|
307
313
|
startedAt: task.startTime,
|
|
308
314
|
// Filled in tick() from the per-key tail history.
|
|
@@ -352,7 +358,7 @@ async function tick(enabled: boolean): Promise<void> {
|
|
|
352
358
|
else ctx.ui.setStatus("watchdog", undefined);
|
|
353
359
|
|
|
354
360
|
// One jevSettings read for the entire tick.
|
|
355
|
-
const jevSettings =
|
|
361
|
+
const jevSettings = resolveDecisionModel(ctx.cwd, "watchdog");
|
|
356
362
|
|
|
357
363
|
for (const item of items) {
|
|
358
364
|
// At most once per intervalMin per item.
|
|
@@ -459,7 +465,12 @@ async function tick(enabled: boolean): Promise<void> {
|
|
|
459
465
|
const text = `⚠ Watchdog aborted "${item.toolName}": jev judged it ${reason}.`;
|
|
460
466
|
try {
|
|
461
467
|
ctx.abort();
|
|
462
|
-
|
|
468
|
+
sendHarnessUserMessage(
|
|
469
|
+
state.pi!,
|
|
470
|
+
text,
|
|
471
|
+
{ source: "Watchdog", title: "Tool aborted", synopsis: "jev judged the tool stuck", severity: "warning" },
|
|
472
|
+
{ deliverAs: "followUp" },
|
|
473
|
+
);
|
|
463
474
|
} catch {
|
|
464
475
|
// best-effort
|
|
465
476
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-unipi/watchdog",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.21",
|
|
4
4
|
"description": "Jev watchdog for long-running tool calls and background tasks — judges stuck work via TypeSafe System One and kills or warns",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@pi-unipi/background-tasks": "3.0.0-alpha.
|
|
36
|
-
"@pi-unipi/core": "3.0.0-alpha.
|
|
35
|
+
"@pi-unipi/background-tasks": "3.0.0-alpha.21",
|
|
36
|
+
"@pi-unipi/core": "3.0.0-alpha.21"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@earendil-works/pi-coding-agent": "^0.87.1",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* edited via /unipi:settings (Watchdog group).
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { getSettings, registerSettings } from "@pi-unipi/core";
|
|
8
|
+
import { getSettings, registerSettings, decisionModelSection, DEFAULT_DECISION_OVERRIDE } from "@pi-unipi/core";
|
|
9
9
|
|
|
10
10
|
export type WatchdogAction = "kill" | "warn";
|
|
11
11
|
export type OtherToolsMode = "off" | "warn" | "abort-turn";
|
|
@@ -80,7 +80,7 @@ export function registerWatchdogSettings(cwd: string): void {
|
|
|
80
80
|
registerSettings({
|
|
81
81
|
namespace: "watchdog",
|
|
82
82
|
label: "Watchdog",
|
|
83
|
-
defaults: { ...DEFAULT_WATCHDOG_SETTINGS } as unknown as Record<string, unknown>,
|
|
83
|
+
defaults: { ...DEFAULT_WATCHDOG_SETTINGS, decisionModel: DEFAULT_DECISION_OVERRIDE } as unknown as Record<string, unknown>,
|
|
84
84
|
schema: [
|
|
85
85
|
{
|
|
86
86
|
title: "Watchdog",
|
|
@@ -115,6 +115,7 @@ export function registerWatchdogSettings(cwd: string): void {
|
|
|
115
115
|
},
|
|
116
116
|
],
|
|
117
117
|
},
|
|
118
|
+
decisionModelSection({ title: "Watchdog — Decision model" }),
|
|
118
119
|
],
|
|
119
120
|
});
|
|
120
121
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-unipi/web-api",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.21",
|
|
4
4
|
"description": "Web search, read, and summarize tools with provider-based backend selection for Pi coding agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@pi-unipi/core": "3.0.0-alpha.
|
|
34
|
+
"@pi-unipi/core": "3.0.0-alpha.21",
|
|
35
35
|
"defuddle": "^0.18.1",
|
|
36
36
|
"linkedom": "^0.18.12",
|
|
37
37
|
"wreq-js": "^2.3.0"
|
|
@@ -78,6 +78,9 @@ Entering plan mode (`/unipi:plan`, `Alt+P`):
|
|
|
78
78
|
- a compact message states the rules: investigation only, the plan file is the ONLY
|
|
79
79
|
writable path (`docs/plans/<YYYY-MM-DD>-<short-session-id>.md`), bash is limited
|
|
80
80
|
to read-only commands;
|
|
81
|
+
- the plan opens with `## Summary` — 5–10 lines of plain language for the human
|
|
82
|
+
deciding whether to approve (what changes and why, what you'll notice, risks or
|
|
83
|
+
open decisions) — then the full detail: Steps, Files, Risks, Verification;
|
|
81
84
|
- every later turn gets a short reminder `[plan mode: read-only · plan file … ·
|
|
82
85
|
call plan_submit when ready]` — appended as a message, never to the system prompt,
|
|
83
86
|
so the provider prefix cache stays intact.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-unipi/workflow",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.21",
|
|
4
4
|
"description": "Plan mode and permission modes for the Pi coding agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@pi-unipi/core": "3.0.0-alpha.
|
|
30
|
+
"@pi-unipi/core": "3.0.0-alpha.21"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@earendil-works/pi-ai": "^0.87.1",
|
|
@@ -20,10 +20,9 @@ export const READ_ONLY_TOOLS = new Set([
|
|
|
20
20
|
"ffgrep", "fffind", "session_recall", "ask_user",
|
|
21
21
|
"memory_search", "memory_list", "global_memory_search", "global_memory_list",
|
|
22
22
|
"web_search", "multi_web_content_read", "web_llm_summarize",
|
|
23
|
-
"bg_status", "bg_logs", "
|
|
24
|
-
"compactor_stats", "compactor_doctor", "context_budget", "
|
|
23
|
+
"bg_status", "bg_logs", "read_subagent",
|
|
24
|
+
"compactor_stats", "compactor_doctor", "context_budget", "ctx_budget",
|
|
25
25
|
"omniroute_status", "loop_status", "swarm_status", "view_agent_graph", "get_goal",
|
|
26
|
-
"read_subagent",
|
|
27
26
|
]);
|
|
28
27
|
|
|
29
28
|
export type Decision =
|
|
@@ -91,10 +90,13 @@ export async function decideToolCall(input: ToolCallInput, deps: DecideDeps): Pr
|
|
|
91
90
|
// 2. Read-only tools.
|
|
92
91
|
if (READ_ONLY_TOOLS.has(tool)) return { action: "allow", reason: "read-only tool" };
|
|
93
92
|
|
|
94
|
-
// 3. write / edit — inside the workspace or the temp dir is fine outside ask mode
|
|
93
|
+
// 3. write / edit — inside the workspace or the temp dir is fine outside ask mode;
|
|
94
|
+
// full mode runs everything (UNI-40: it must be able to write anywhere, e.g. the
|
|
95
|
+
// installed-extension hot-patch in ~/.pi), so only ask/auto prompt on outside writes.
|
|
95
96
|
if (isWrite) {
|
|
96
97
|
const inside = isInsidePath(subject, deps.cwd) || isInsidePath(subject, deps.tmpdir);
|
|
97
98
|
if (inside && deps.mode !== "ask") return { action: "allow", reason: "inside the workspace" };
|
|
99
|
+
if (deps.mode === "full") return { action: "allow", reason: "full mode · outside the workspace" };
|
|
98
100
|
if (!deps.hasUI) return { action: "allow", reason: "no UI — full behaviour" };
|
|
99
101
|
return {
|
|
100
102
|
action: "ask",
|
|
@@ -4,18 +4,21 @@
|
|
|
4
4
|
* Every tool call is classified (read-only, workspace write, bash, other) and
|
|
5
5
|
* gated by the active mode. In `auto`, an unrecognized bash command is judged by
|
|
6
6
|
* jev (one Decision-model call) instead of prompting; anything destructive or
|
|
7
|
-
* ambiguous always asks.
|
|
8
|
-
*
|
|
7
|
+
* ambiguous always asks. `full` runs everything short of saved deny rules (and
|
|
8
|
+
* dangerous bash in headless runs, where nothing could confirm it). Without a UI
|
|
9
|
+
* nothing prompts: it behaves like `full`, except saved deny rules and dangerous
|
|
10
|
+
* patterns, which are blocked outright.
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
import { appendFileSync, mkdirSync } from "node:fs";
|
|
12
14
|
import { homedir, tmpdir } from "node:os";
|
|
13
15
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
14
16
|
import {
|
|
17
|
+
getSettingsScoped,
|
|
15
18
|
UNIPI_EVENTS,
|
|
16
19
|
askJev,
|
|
17
20
|
emitEvent,
|
|
18
|
-
|
|
21
|
+
resolveDecisionModel,
|
|
19
22
|
registerCommandRunner,
|
|
20
23
|
runCommandByName,
|
|
21
24
|
setSharedPermissionMode,
|
|
@@ -62,7 +65,7 @@ function debugLog(line: string): void {
|
|
|
62
65
|
|
|
63
66
|
/** One jev risk question; null (fail-open → prompt) on error, timeout or no key. */
|
|
64
67
|
export async function askJevRisk(cwd: string, state: string): Promise<JevRisk | null> {
|
|
65
|
-
const settings =
|
|
68
|
+
const settings = resolveDecisionModel(cwd, "permission");
|
|
66
69
|
const answers = await askJev({
|
|
67
70
|
state,
|
|
68
71
|
questions: {
|
|
@@ -165,15 +168,22 @@ export function registerPermissionModes(pi: ExtensionAPI, controller: Permission
|
|
|
165
168
|
? "Prompt before every write, bash call and other tool"
|
|
166
169
|
: m === "auto"
|
|
167
170
|
? "Read-only and workspace writes run; jev judges ambiguous bash (default)"
|
|
168
|
-
: "Run everything
|
|
171
|
+
: "Run everything — only saved deny rules block",
|
|
169
172
|
}));
|
|
170
173
|
return items.length > 0 ? items : null;
|
|
171
174
|
},
|
|
172
175
|
handler: async (args, ctx) => {
|
|
173
176
|
const requested = (args ?? "").trim().toLowerCase();
|
|
174
|
-
if (!requested) {
|
|
177
|
+
if (!requested || requested === "status") {
|
|
175
178
|
const current = controller.mode(ctx.cwd);
|
|
176
|
-
|
|
179
|
+
const project = getSettingsScoped("permission", "project", ctx.cwd);
|
|
180
|
+
const global = getSettingsScoped("permission", "global", ctx.cwd);
|
|
181
|
+
const proj = typeof project?.mode === "string" ? project.mode : "-";
|
|
182
|
+
const glob = typeof global?.defaultMode === "string" ? global.defaultMode : typeof global?.mode === "string" ? global.mode : "-";
|
|
183
|
+
ctx.ui.notify(
|
|
184
|
+
`Permission mode: ${current} (project: ${proj} · default: ${glob})`,
|
|
185
|
+
"info",
|
|
186
|
+
);
|
|
177
187
|
return;
|
|
178
188
|
}
|
|
179
189
|
if (!MODES.includes(requested as PermissionMode)) {
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
getSettings,
|
|
8
|
+
getSettingsScoped,
|
|
8
9
|
registerSettings,
|
|
9
10
|
setSettings,
|
|
10
11
|
settingsLayers,
|
|
11
12
|
type SettingsSection,
|
|
13
|
+
decisionModelSection,
|
|
14
|
+
DEFAULT_DECISION_OVERRIDE,
|
|
12
15
|
} from "@pi-unipi/core";
|
|
13
16
|
import { normalizeRules, type PermissionRule } from "./rules.js";
|
|
14
17
|
|
|
@@ -16,6 +19,7 @@ export type PermissionMode = "ask" | "auto" | "full";
|
|
|
16
19
|
|
|
17
20
|
export interface PermissionSettings {
|
|
18
21
|
mode: PermissionMode;
|
|
22
|
+
defaultMode: PermissionMode;
|
|
19
23
|
jevJudge: boolean;
|
|
20
24
|
jevConfidence: number;
|
|
21
25
|
rules: PermissionRule[];
|
|
@@ -23,6 +27,7 @@ export interface PermissionSettings {
|
|
|
23
27
|
|
|
24
28
|
export const DEFAULT_SETTINGS = {
|
|
25
29
|
mode: "auto",
|
|
30
|
+
defaultMode: "auto",
|
|
26
31
|
jevJudge: true,
|
|
27
32
|
jevConfidence: 0.7,
|
|
28
33
|
rules: [] as PermissionRule[],
|
|
@@ -42,9 +47,19 @@ export const PERMISSION_SECTIONS: SettingsSection[] = [
|
|
|
42
47
|
{
|
|
43
48
|
key: "mode",
|
|
44
49
|
type: "enum",
|
|
45
|
-
label: "Mode",
|
|
50
|
+
label: "Mode (this project)",
|
|
46
51
|
options: MODE_OPTIONS.map((o) => ({ ...o })),
|
|
47
|
-
|
|
52
|
+
clearable: true,
|
|
53
|
+
scopes: ["project"],
|
|
54
|
+
description: "Alt+M cycles · use-default clears the project mode",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: "defaultMode",
|
|
58
|
+
type: "enum",
|
|
59
|
+
label: "Default mode (all projects)",
|
|
60
|
+
scope: "global",
|
|
61
|
+
options: MODE_OPTIONS.map((o) => ({ ...o })),
|
|
62
|
+
description: "Fallback mode for projects that set none",
|
|
48
63
|
},
|
|
49
64
|
{
|
|
50
65
|
key: "jevJudge",
|
|
@@ -69,14 +84,23 @@ export const PERMISSION_SECTIONS: SettingsSection[] = [
|
|
|
69
84
|
},
|
|
70
85
|
],
|
|
71
86
|
},
|
|
87
|
+
decisionModelSection({ title: "Auto mode — Decision model" }),
|
|
72
88
|
];
|
|
73
89
|
|
|
74
90
|
export function registerPermissionSettings(cwd?: string): void {
|
|
91
|
+
// One-time, idempotent migration: an existing global `mode` (pre-defaultMode
|
|
92
|
+
// installs) is copied to `defaultMode` so the hub shows it instead of "unset".
|
|
93
|
+
if (cwd) {
|
|
94
|
+
const global = getSettingsScoped("permission", "global", cwd);
|
|
95
|
+
if (global && typeof global.mode === "string" && global.defaultMode === undefined) {
|
|
96
|
+
setSettings("permission", { defaultMode: global.mode }, "global", cwd);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
75
99
|
const count = cwd ? readPermissionSettings(cwd).rules.length : 0;
|
|
76
100
|
registerSettings({
|
|
77
101
|
namespace: "permission",
|
|
78
102
|
label: "Permissions",
|
|
79
|
-
defaults: DEFAULT_SETTINGS as unknown as Record<string, unknown>,
|
|
103
|
+
defaults: { ...DEFAULT_SETTINGS, decisionModel: DEFAULT_DECISION_OVERRIDE } as unknown as Record<string, unknown>,
|
|
80
104
|
schema: PERMISSION_SECTIONS.map((section) => ({
|
|
81
105
|
...section,
|
|
82
106
|
fields: section.fields.map((field) =>
|
|
@@ -95,7 +119,8 @@ function coerceMode(value: unknown): PermissionMode {
|
|
|
95
119
|
export function readPermissionSettings(cwd: string): PermissionSettings {
|
|
96
120
|
const raw = getSettings("permission", cwd);
|
|
97
121
|
return {
|
|
98
|
-
mode:
|
|
122
|
+
mode: effectivePermissionMode(cwd),
|
|
123
|
+
defaultMode: coerceMode(raw.defaultMode),
|
|
99
124
|
jevJudge: raw.jevJudge !== false,
|
|
100
125
|
jevConfidence:
|
|
101
126
|
typeof raw.jevConfidence === "number" && raw.jevConfidence >= 0 && raw.jevConfidence <= 1
|
|
@@ -105,6 +130,16 @@ export function readPermissionSettings(cwd: string): PermissionSettings {
|
|
|
105
130
|
};
|
|
106
131
|
}
|
|
107
132
|
|
|
133
|
+
/** project `mode` → global `defaultMode` → legacy global `mode` → auto. */
|
|
134
|
+
export function effectivePermissionMode(cwd: string): PermissionMode {
|
|
135
|
+
const project = getSettingsScoped("permission", "project", cwd);
|
|
136
|
+
if (project && typeof project.mode === "string") return coerceMode(project.mode);
|
|
137
|
+
const global = getSettingsScoped("permission", "global", cwd);
|
|
138
|
+
if (global && typeof global.defaultMode === "string") return coerceMode(global.defaultMode);
|
|
139
|
+
if (global && typeof global.mode === "string") return coerceMode(global.mode); // legacy installs
|
|
140
|
+
return "auto";
|
|
141
|
+
}
|
|
142
|
+
|
|
108
143
|
/** Written to the project scope: the mode is a property of the workspace. */
|
|
109
144
|
export function writePermissionMode(mode: PermissionMode, cwd: string): void {
|
|
110
145
|
setSettings("permission", { mode }, "project", cwd);
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { existsSync, readFileSync } from "node:fs";
|
|
11
11
|
import { Type } from "typebox";
|
|
12
12
|
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
13
|
-
import { UNIPI_EVENTS, emitEvent, registerCommandRunner, setSharedPlanMode } from "@pi-unipi/core";
|
|
13
|
+
import { UNIPI_EVENTS, emitEvent, harnessMetadata, registerCommandRunner, sendHarnessUserMessage, setSharedPlanMode } from "@pi-unipi/core";
|
|
14
14
|
import {
|
|
15
15
|
PLAN_MESSAGE_TYPE,
|
|
16
16
|
PLAN_STATE_ENTRY,
|
|
@@ -37,8 +37,14 @@ export function planInstructions(planPath: string): string {
|
|
|
37
37
|
"Plan mode is ON — investigation only, no implementation.",
|
|
38
38
|
`The ONLY file you may write or edit is ${planPath}.`,
|
|
39
39
|
"Bash is limited to read-only commands; every mutating tool is refused.",
|
|
40
|
-
"Investigate the codebase, then write the plan to that file
|
|
40
|
+
"Investigate the codebase, then write the plan to that file using these",
|
|
41
|
+
"headings verbatim, in this order:",
|
|
41
42
|
PLAN_TEMPLATE.join("\n"),
|
|
43
|
+
"## Summary comes first and is written for the human approving the plan:",
|
|
44
|
+
"5–10 lines of plain language covering what will change and why, what the",
|
|
45
|
+
"user will notice, and any risks or decisions that need them — no file",
|
|
46
|
+
"paths or code unless essential. Everything below it is the full plan for",
|
|
47
|
+
"whoever implements it.",
|
|
42
48
|
`When the plan is written, call ${PLAN_TOOL} to ask for approval.`,
|
|
43
49
|
].join("\n");
|
|
44
50
|
}
|
|
@@ -92,8 +98,10 @@ export async function approvePlan(
|
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
disablePlanMode(pi, ctx, "approved");
|
|
95
|
-
|
|
101
|
+
sendHarnessUserMessage(
|
|
102
|
+
pi,
|
|
96
103
|
`Implement the approved plan below. Treat it as authoritative; do not re-plan.\n\n${content}`,
|
|
104
|
+
{ source: "Plan mode", title: "Approved plan", synopsis: "Plan approved — implementation handoff" },
|
|
97
105
|
{ deliverAs: "followUp" },
|
|
98
106
|
);
|
|
99
107
|
return { status: "approved" };
|
|
@@ -147,6 +155,7 @@ export function enablePlanMode(
|
|
|
147
155
|
customType: PLAN_MESSAGE_TYPE,
|
|
148
156
|
content: planInstructions(displayPlanPath(ctx.cwd, planFile)),
|
|
149
157
|
display: true,
|
|
158
|
+
details: { unipiHarness: harnessMetadata({ source: "Plan mode", title: "Plan mode on", synopsis: "Investigation only — plan file required" }, "direct") },
|
|
150
159
|
});
|
|
151
160
|
ctx.ui.notify(`Plan mode on — plan file ${displayPlanPath(ctx.cwd, planFile)}`, "info");
|
|
152
161
|
return planFile;
|
|
@@ -172,7 +181,12 @@ export function disablePlanMode(
|
|
|
172
181
|
});
|
|
173
182
|
if (reason !== "approved") {
|
|
174
183
|
const note = reason === "discarded" ? "[plan mode off — plan discarded]" : "[plan mode off]";
|
|
175
|
-
pi.sendMessage({
|
|
184
|
+
pi.sendMessage({
|
|
185
|
+
customType: PLAN_MESSAGE_TYPE,
|
|
186
|
+
content: note,
|
|
187
|
+
display: true,
|
|
188
|
+
details: { unipiHarness: harnessMetadata({ source: "Plan mode", title: reason === "discarded" ? "Plan discarded" : "Plan mode off" }, "direct") },
|
|
189
|
+
});
|
|
176
190
|
}
|
|
177
191
|
ctx.ui.notify(
|
|
178
192
|
reason === "discarded" ? "Plan mode off — plan discarded" : "Plan mode off",
|
|
@@ -329,6 +343,7 @@ export function registerPlanMode(pi: ExtensionAPI): void {
|
|
|
329
343
|
customType: PLAN_MESSAGE_TYPE,
|
|
330
344
|
content: planReminder(displayPlanPath(ctx.cwd, state.planFile)),
|
|
331
345
|
display: false,
|
|
346
|
+
details: { unipiHarness: harnessMetadata({ source: "Plan mode", title: "Plan reminder (hidden)" }, "before_agent_start") },
|
|
332
347
|
},
|
|
333
348
|
};
|
|
334
349
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '../src/delegate-child-extension.js';
|