@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
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hint store — ~/.unipi/global/hints/hints.json, write-through JSON.
|
|
3
|
+
*
|
|
4
|
+
* Persists show counts, learned hints, and last seen unipi version:
|
|
5
|
+
* {
|
|
6
|
+
* "counts": { "<hintId>": { "count": 2, "last": 1730000000000 } },
|
|
7
|
+
* "learned": ["utility.settings-hub"],
|
|
8
|
+
* "lastSeenVersion": "3.0.0-alpha.20"
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
13
|
+
import { statePath } from "../workspace/paths.js";
|
|
14
|
+
|
|
15
|
+
export interface HintRecord {
|
|
16
|
+
count: number;
|
|
17
|
+
last: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface HintStoreData {
|
|
21
|
+
counts: Record<string, HintRecord>;
|
|
22
|
+
learned: string[];
|
|
23
|
+
lastSeenVersion?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let cache: HintStoreData | null = null;
|
|
27
|
+
|
|
28
|
+
function emptyStore(): HintStoreData {
|
|
29
|
+
return {
|
|
30
|
+
counts: {},
|
|
31
|
+
learned: [],
|
|
32
|
+
lastSeenVersion: undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function loadHintStore(): HintStoreData {
|
|
37
|
+
if (cache) return cache;
|
|
38
|
+
try {
|
|
39
|
+
const raw = readFileSync(statePath("hints", "hints.json", "global"), "utf-8");
|
|
40
|
+
const parsed = JSON.parse(raw);
|
|
41
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
42
|
+
cache = {
|
|
43
|
+
counts: (typeof parsed.counts === "object" && parsed.counts !== null ? parsed.counts : {}) as Record<string, HintRecord>,
|
|
44
|
+
learned: Array.isArray(parsed.learned) ? parsed.learned : [],
|
|
45
|
+
lastSeenVersion: typeof parsed.lastSeenVersion === "string" ? parsed.lastSeenVersion : undefined,
|
|
46
|
+
};
|
|
47
|
+
} else {
|
|
48
|
+
cache = emptyStore();
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
cache = emptyStore();
|
|
52
|
+
}
|
|
53
|
+
return cache;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function saveStore(): void {
|
|
57
|
+
if (!cache) return;
|
|
58
|
+
try {
|
|
59
|
+
writeFileSync(statePath("hints", "hints.json", "global"), JSON.stringify(cache, null, 2));
|
|
60
|
+
} catch {
|
|
61
|
+
// best-effort
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function recordHintShow(id: string): void {
|
|
66
|
+
const store = loadHintStore();
|
|
67
|
+
const prev = store.counts[id];
|
|
68
|
+
store.counts[id] = { count: (prev?.count ?? 0) + 1, last: Date.now() };
|
|
69
|
+
saveStore();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function recordHintLearned(id: string): void {
|
|
73
|
+
const store = loadHintStore();
|
|
74
|
+
if (!store.learned.includes(id)) {
|
|
75
|
+
store.learned.push(id);
|
|
76
|
+
saveStore();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function isHintLearned(id: string): boolean {
|
|
81
|
+
const store = loadHintStore();
|
|
82
|
+
return store.learned.includes(id);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function setLastSeenVersion(version: string): void {
|
|
86
|
+
const store = loadHintStore();
|
|
87
|
+
store.lastSeenVersion = version;
|
|
88
|
+
saveStore();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function getLastSeenVersion(): string | undefined {
|
|
92
|
+
const store = loadHintStore();
|
|
93
|
+
return store.lastSeenVersion;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function resetHintHistory(): void {
|
|
97
|
+
const store = loadHintStore();
|
|
98
|
+
store.counts = {};
|
|
99
|
+
store.learned = [];
|
|
100
|
+
try {
|
|
101
|
+
writeFileSync(statePath("hints", "hints.json", "global"), JSON.stringify(store, null, 2));
|
|
102
|
+
} catch {
|
|
103
|
+
// best effort
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Clear disk file and cached store completely (e.g. for testing clean slate). */
|
|
108
|
+
export function clearHintStoreFile(): void {
|
|
109
|
+
cache = null;
|
|
110
|
+
try {
|
|
111
|
+
unlinkSync(statePath("hints", "hints.json", "global"));
|
|
112
|
+
} catch {
|
|
113
|
+
// absent file is already clear
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Test hook: drop memoized store so next call re-reads disk. */
|
|
118
|
+
export function resetHintStoreCache(): void {
|
|
119
|
+
cache = null;
|
|
120
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chatter detection shared by jev consumers (auto-rename, skill judging):
|
|
3
|
+
* greetings, thanks, acknowledgements and bare "continue"-style nudges carry
|
|
4
|
+
* no subject, so no decision should be made from them.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const CHATTER = new RegExp(
|
|
8
|
+
"^(?:" + [
|
|
9
|
+
"h(?:i|ello|ey|owdy)(?: there)?", "yo", "sup", "good (?:morning|afternoon|evening)",
|
|
10
|
+
"thanks?(?: you)?(?: so much)?", "thx", "ty", "cheers", "nice", "great", "cool", "perfect", "awesome",
|
|
11
|
+
"ok(?:ay)?", "k", "yes", "yep", "yeah", "no", "nope", "sure", "lgtm", "sounds good", "go(?: on| ahead)?",
|
|
12
|
+
"continue", "proceed", "retry", "again", "do it", "next", "done",
|
|
13
|
+
].join("|") + ")[\\s.!?,]*$",
|
|
14
|
+
"i",
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
/** True for messages with no subject of their own (no jev call needed). */
|
|
18
|
+
export function isChatter(text: string): boolean {
|
|
19
|
+
const t = text.trim();
|
|
20
|
+
if (t.length < 3) return true;
|
|
21
|
+
if (t.startsWith("/")) return true;
|
|
22
|
+
return CHATTER.test(t);
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -1,23 +1,186 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Decision Model — one shared setting for the fast calibrated classifier
|
|
3
|
+
* (TypeSafe jev today) that several modules consult: long-horizon mode
|
|
4
|
+
* routing, permission auto-judging, skill exposure, the watchdog, kanboard
|
|
5
|
+
* strategy choice and compactor pruning.
|
|
6
|
+
*
|
|
7
|
+
* The model lives in its own settings namespace ("decision-model"), not in
|
|
8
|
+
* any consumer, so a different decision model can be adopted in one place.
|
|
9
|
+
* Each consumer carries a `decisionModel` block: `source: "inherit"` (the
|
|
10
|
+
* default) uses the shared model; `source: "custom"` overrides provider,
|
|
11
|
+
* model, base URL, key or timeout for that consumer only (empty fields fall
|
|
12
|
+
* back to the shared value).
|
|
5
13
|
*/
|
|
6
14
|
|
|
7
|
-
import { getSettings } from "../settings/engine.js";
|
|
15
|
+
import { getSettings, getSettingsScoped, registerSettings, setSettings } from "../settings/engine.js";
|
|
16
|
+
import type { SettingsField, SettingsSection } from "../settings/schema.js";
|
|
17
|
+
import { globalSettingsPath } from "../settings/paths.js";
|
|
8
18
|
import type { JevSettings } from "./client.js";
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
export const DECISION_MODEL_NAMESPACE = "decision-model";
|
|
21
|
+
|
|
22
|
+
export type DecisionProvider = JevSettings["provider"];
|
|
23
|
+
|
|
24
|
+
export interface DecisionModelSettings {
|
|
25
|
+
provider: DecisionProvider;
|
|
26
|
+
model: string;
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
apiKey: string;
|
|
29
|
+
timeoutMs: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface DecisionModelOverride extends DecisionModelSettings {
|
|
33
|
+
source: "inherit" | "custom";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const DEFAULT_DECISION_MODEL: DecisionModelSettings = {
|
|
37
|
+
provider: "openrouter",
|
|
38
|
+
model: "typesafe/jev-1.13",
|
|
39
|
+
baseUrl: "",
|
|
40
|
+
apiKey: "",
|
|
41
|
+
timeoutMs: 0,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The per-consumer block's defaults: inherit, custom fields empty. */
|
|
45
|
+
export const DEFAULT_DECISION_OVERRIDE: DecisionModelOverride = {
|
|
46
|
+
source: "inherit",
|
|
47
|
+
provider: "openrouter",
|
|
48
|
+
model: "",
|
|
49
|
+
baseUrl: "",
|
|
50
|
+
apiKey: "",
|
|
51
|
+
timeoutMs: 0,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const PROVIDER_OPTIONS = [
|
|
55
|
+
{ value: "openrouter", label: "openrouter (decisions endpoint)" },
|
|
56
|
+
{ value: "typesafe", label: "typesafe (native systemone)" },
|
|
57
|
+
{ value: "custom", label: "custom (Base URL + API key)" },
|
|
58
|
+
] as const;
|
|
59
|
+
|
|
60
|
+
const MODEL_PRESETS = {
|
|
61
|
+
typesafe: ["jev-latest"],
|
|
62
|
+
openrouter: ["typesafe/jev-1.13"],
|
|
63
|
+
custom: ["typesafe/jev-1.13"],
|
|
64
|
+
} as const;
|
|
65
|
+
|
|
66
|
+
/** Provider / model / base URL / key / timeout fields under a key prefix. */
|
|
67
|
+
function modelFields(prefix: string, emptyModel?: string): SettingsField[] {
|
|
68
|
+
const k = (name: string) => (prefix ? `${prefix}.${name}` : name);
|
|
69
|
+
return [
|
|
70
|
+
{ key: k("provider"), type: "enum", label: "Provider", options: PROVIDER_OPTIONS, description: "openrouter = decisions endpoint · typesafe = native systemone · custom = your own gateway" },
|
|
71
|
+
{
|
|
72
|
+
key: k("model"),
|
|
73
|
+
type: "model",
|
|
74
|
+
label: "Model",
|
|
75
|
+
description: "A decision (classifier) model — jev; custom… for others",
|
|
76
|
+
providerKey: k("provider"),
|
|
77
|
+
presetsByProvider: MODEL_PRESETS,
|
|
78
|
+
...(emptyModel ? { emptyLabel: emptyModel, emptyOption: emptyModel } : {}),
|
|
79
|
+
},
|
|
80
|
+
{ key: k("baseUrl"), type: "string", label: "Base URL", description: "Required when provider = custom", emptyLabel: "provider default" },
|
|
81
|
+
{ key: k("apiKey"), type: "secret", label: "API key", description: "A stored key wins over the environment (OPENROUTER_API_KEY / TYPESAFE_API_KEY)", emptyLabel: "environment" },
|
|
82
|
+
{ key: k("timeoutMs"), type: "number", label: "Timeout ms", min: 0, zeroLabel: "auto (1s native / 6s decisions)" },
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
registerSettings({
|
|
87
|
+
namespace: DECISION_MODEL_NAMESPACE,
|
|
88
|
+
label: "Decision Model",
|
|
89
|
+
defaults: DEFAULT_DECISION_MODEL as unknown as Record<string, unknown>,
|
|
90
|
+
schema: [
|
|
91
|
+
{
|
|
92
|
+
title: "Decision model",
|
|
93
|
+
description:
|
|
94
|
+
"A fast calibrated classifier used for mode routing, permission judging, skill exposure, the watchdog, kanboard strategy and compaction pruning. Each of those can inherit this or use its own.",
|
|
95
|
+
fields: modelFields(""),
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The hub section a consumer adds to its own settings: inherit the shared
|
|
102
|
+
* Decision Model, or use a custom one (fields empty = shared value).
|
|
103
|
+
*/
|
|
104
|
+
export function decisionModelSection(opts: { title?: string; advanced?: boolean } = {}): SettingsSection {
|
|
105
|
+
return {
|
|
106
|
+
title: opts.title ?? "Decision model",
|
|
107
|
+
description: "inherit = the shared Decision Model settings · custom = override below for this module only (empty = shared value)",
|
|
108
|
+
advanced: opts.advanced ?? true,
|
|
109
|
+
fields: [
|
|
110
|
+
{
|
|
111
|
+
key: "decisionModel.source",
|
|
112
|
+
type: "enum",
|
|
113
|
+
label: "Decision model",
|
|
114
|
+
options: [
|
|
115
|
+
{ value: "inherit", label: "inherit (Decision Model settings)" },
|
|
116
|
+
{ value: "custom", label: "custom" },
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
...modelFields("decisionModel", "shared model"),
|
|
120
|
+
],
|
|
14
121
|
};
|
|
15
|
-
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const isRecord = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
125
|
+
|
|
126
|
+
function normalize(raw: Record<string, unknown>, fallback: DecisionModelSettings): DecisionModelSettings {
|
|
127
|
+
const provider: DecisionProvider =
|
|
128
|
+
raw.provider === "typesafe" || raw.provider === "custom" || raw.provider === "openrouter" ? raw.provider : fallback.provider;
|
|
129
|
+
const str = (v: unknown, dflt: string) => (typeof v === "string" && v.trim() ? v.trim() : dflt);
|
|
130
|
+
const model = str(raw.model, provider === fallback.provider ? fallback.model : provider === "typesafe" ? "jev-latest" : "typesafe/jev-1.13");
|
|
16
131
|
return {
|
|
17
|
-
provider
|
|
18
|
-
model
|
|
19
|
-
baseUrl:
|
|
20
|
-
apiKey:
|
|
21
|
-
timeoutMs: typeof
|
|
132
|
+
provider,
|
|
133
|
+
model,
|
|
134
|
+
baseUrl: str(raw.baseUrl, fallback.baseUrl),
|
|
135
|
+
apiKey: str(raw.apiKey, fallback.apiKey),
|
|
136
|
+
timeoutMs: typeof raw.timeoutMs === "number" && raw.timeoutMs > 0 ? raw.timeoutMs : fallback.timeoutMs,
|
|
22
137
|
};
|
|
23
138
|
}
|
|
139
|
+
|
|
140
|
+
/** Latched per global settings file (one per HOME), not per process. */
|
|
141
|
+
const migrated = new Set<string>();
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* One-time move of the pre-namespace settings (long-horizon `judge.*`
|
|
145
|
+
* transport fields) into "decision-model". Additive: long-horizon keeps its
|
|
146
|
+
* copy; runs only while the decision-model global file does not exist.
|
|
147
|
+
*/
|
|
148
|
+
export function migrateLegacyDecisionModel(cwd: string): void {
|
|
149
|
+
const target = globalSettingsPath(DECISION_MODEL_NAMESPACE);
|
|
150
|
+
if (migrated.has(target)) return;
|
|
151
|
+
migrated.add(target);
|
|
152
|
+
try {
|
|
153
|
+
if (getSettingsScoped(DECISION_MODEL_NAMESPACE, "global", cwd)) return;
|
|
154
|
+
const judge = getSettingsScoped("long-horizon", "global", cwd)?.judge;
|
|
155
|
+
if (!isRecord(judge)) return;
|
|
156
|
+
const patch: Record<string, unknown> = {};
|
|
157
|
+
for (const key of ["provider", "model", "baseUrl", "apiKey", "timeoutMs"]) {
|
|
158
|
+
if (judge[key] !== undefined && judge[key] !== "") patch[key] = judge[key];
|
|
159
|
+
}
|
|
160
|
+
if (patch.provider === "auto") patch.provider = "openrouter";
|
|
161
|
+
if (Object.keys(patch).length > 0) setSettings(DECISION_MODEL_NAMESPACE, patch, "global", cwd);
|
|
162
|
+
} catch {
|
|
163
|
+
// Unreadable legacy settings: defaults apply.
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The shared Decision Model. */
|
|
168
|
+
export function readDecisionModel(cwd: string): DecisionModelSettings {
|
|
169
|
+
migrateLegacyDecisionModel(cwd);
|
|
170
|
+
return normalize(getSettings(DECISION_MODEL_NAMESPACE, cwd), DEFAULT_DECISION_MODEL);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The Decision Model a consumer should use: its own `decisionModel` block
|
|
175
|
+
* when `source: "custom"`, otherwise the shared one.
|
|
176
|
+
*/
|
|
177
|
+
export function resolveDecisionModel(cwd: string, namespace?: string): DecisionModelSettings {
|
|
178
|
+
const shared = readDecisionModel(cwd);
|
|
179
|
+
if (!namespace) return shared;
|
|
180
|
+
const block = getSettings(namespace, cwd)?.decisionModel;
|
|
181
|
+
if (!isRecord(block) || block.source !== "custom") return shared;
|
|
182
|
+
return normalize(block, shared);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** @deprecated Use resolveDecisionModel(cwd, namespace). */
|
|
186
|
+
export const readJudgeJevSettings = (cwd: string): DecisionModelSettings => readDecisionModel(cwd);
|
|
@@ -41,6 +41,7 @@ export const PACKAGE_COLORS: Record<string, string> = {
|
|
|
41
41
|
"background-tasks": `${ESC}[91m`, // Bright Red
|
|
42
42
|
fusion: `${ESC}[96m`, // Bright Cyan
|
|
43
43
|
watchdog: `${ESC}[90m`, // Bright Black (gray)
|
|
44
|
+
"skill-registry": `${ESC}[92m`, // Bright Green
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
/** Hub namespace → PACKAGE_COLORS key (others use the namespace identity). */
|
|
@@ -48,6 +49,7 @@ const NAMESPACE_COLOR_KEYS: Record<string, string> = {
|
|
|
48
49
|
"command-enchantment": "autocomplete",
|
|
49
50
|
"info-screen": "info",
|
|
50
51
|
compactor: "compact",
|
|
52
|
+
skills: "skill-registry",
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
/** ANSI color for a settings namespace ("" when unknown — no color). */
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Model catalog for `model`-type settings fields — the searchable picker's data.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Primary source: the unipi model cache (~/.unipi/config/models-cache.json),
|
|
5
|
+
* written by utility from pi's live registry every session — it covers
|
|
6
|
+
* built-in providers with credentials and the image-generation collection,
|
|
7
|
+
* with input/output modalities. Pi's models.json (custom providers, shape
|
|
8
|
+
* { providers: { <provider>: { models: [{ id, ... }] } } })
|
|
9
|
+
* fills in anything the cache has not seen yet (first run, no session yet).
|
|
8
10
|
*
|
|
9
11
|
* The loader is sync + cached + never throws (empty catalog on any error), and
|
|
10
12
|
* the path is injectable so tests feed a fixture instead of the real registry.
|
|
@@ -13,6 +15,7 @@
|
|
|
13
15
|
import { readFileSync } from "node:fs";
|
|
14
16
|
import { homedir } from "node:os";
|
|
15
17
|
import { join } from "node:path";
|
|
18
|
+
import { readModelCache, modelInputs, modelOutputs, modelRef } from "../../model-cache.js";
|
|
16
19
|
|
|
17
20
|
export function defaultModelCatalogPath(): string {
|
|
18
21
|
return join(homedir(), ".pi", "agent", "models.json");
|
|
@@ -23,21 +26,44 @@ export interface ModelCatalogEntry {
|
|
|
23
26
|
readonly id: string;
|
|
24
27
|
/** Declared input modalities, e.g. ["text"] or ["text", "image"]. */
|
|
25
28
|
readonly input: string[];
|
|
29
|
+
/** Declared output modalities; absent → ["text"]. */
|
|
30
|
+
readonly output?: string[];
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
export type ModelCapability = "text" | "image-input" | "image-output" | "image-edit";
|
|
29
34
|
|
|
30
|
-
/**
|
|
35
|
+
/** Capability filter shared by every model picker. */
|
|
36
|
+
export function matchesCapability(entry: ModelCatalogEntry, capability: ModelCapability): boolean {
|
|
37
|
+
// No declared input = unknown → hidden from capability pickers (custom… still
|
|
38
|
+
// accepts any id). Output defaults to text: chat catalogs rarely declare it.
|
|
39
|
+
const input = entry.input;
|
|
40
|
+
const output = entry.output?.length ? entry.output : ["text"];
|
|
41
|
+
switch (capability) {
|
|
42
|
+
case "text": return input.includes("text") && output.includes("text");
|
|
43
|
+
case "image-input": return input.includes("image") && output.includes("text");
|
|
44
|
+
case "image-output": return output.includes("image");
|
|
45
|
+
case "image-edit": return input.includes("image") && output.includes("image");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Load the full "provider/model" id list. Empty on any failure. */
|
|
31
50
|
export function loadModelCatalog(path: string = defaultModelCatalogPath()): string[] {
|
|
32
51
|
return loadModelCatalogEntries(path).map((e) => e.id);
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
/** Load
|
|
54
|
+
/** Load catalog entries (ids + modalities). Read per call (picker open), so a
|
|
55
|
+
* cache rewritten mid-session is seen. Empty on any failure. */
|
|
36
56
|
export function loadModelCatalogEntries(path: string = defaultModelCatalogPath()): ModelCatalogEntry[] {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
|
|
57
|
+
const isDefault = path === defaultModelCatalogPath();
|
|
58
|
+
const fromFile = parseModelCatalogEntries(() => readFileSync(path, "utf8"));
|
|
59
|
+
if (!isDefault) return fromFile;
|
|
60
|
+
const cached: ModelCatalogEntry[] = readModelCache().map((m) => ({
|
|
61
|
+
id: modelRef(m),
|
|
62
|
+
input: modelInputs(m),
|
|
63
|
+
output: modelOutputs(m),
|
|
64
|
+
}));
|
|
65
|
+
const seen = new Set(cached.map((e) => e.id));
|
|
66
|
+
return [...cached, ...fromFile.filter((e) => !seen.has(e.id))];
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
/** Pure parser — testable without the filesystem. */
|
|
@@ -78,10 +104,8 @@ export function parseModelCatalogEntries(read: () => string): ModelCatalogEntry[
|
|
|
78
104
|
}
|
|
79
105
|
}
|
|
80
106
|
|
|
81
|
-
/** Test hook. */
|
|
82
|
-
export function resetModelCatalogCache(): void {
|
|
83
|
-
entryCache = undefined;
|
|
84
|
-
}
|
|
107
|
+
/** Test hook (the catalog is no longer cached in memory; kept for callers). */
|
|
108
|
+
export function resetModelCatalogCache(): void {}
|
|
85
109
|
|
|
86
110
|
/** Pure id-only parser (back-compat shim over parseModelCatalogEntries). */
|
|
87
111
|
export function parseModelCatalog(read: () => string): string[] {
|
|
@@ -27,6 +27,20 @@ export interface SettingsDefinition {
|
|
|
27
27
|
readonly projectOverrides?: boolean;
|
|
28
28
|
/** Field schema — sections/fields the hub renders automatically. */
|
|
29
29
|
readonly schema?: readonly SettingsSection[];
|
|
30
|
+
/**
|
|
31
|
+
* Called after every write to one layer (set or unset) with that layer's
|
|
32
|
+
* new content — for settings that mirror into another program's config
|
|
33
|
+
* (e.g. fusion's startup model → pi's settings.json). Errors are swallowed.
|
|
34
|
+
*/
|
|
35
|
+
readonly onSet?: (layer: Record<string, unknown>, scope: SettingsScope, cwd: string) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function notifySet(definition: SettingsDefinition, layer: Record<string, unknown>, scope: SettingsScope, cwd: string): void {
|
|
39
|
+
try {
|
|
40
|
+
definition.onSet?.(layer, scope, cwd);
|
|
41
|
+
} catch {
|
|
42
|
+
/* a mirror failure must not fail the settings write */
|
|
43
|
+
}
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
const registry = new Map<string, SettingsDefinition>();
|
|
@@ -139,8 +153,40 @@ export function setSettings(
|
|
|
139
153
|
}
|
|
140
154
|
const target =
|
|
141
155
|
scope === "global" ? globalSettingsPath(namespace) : projectSettingsPath(cwd, namespace);
|
|
142
|
-
const
|
|
143
|
-
writeJson(target,
|
|
156
|
+
const next = deepMerge(readJson(target) ?? {}, patch);
|
|
157
|
+
writeJson(target, next);
|
|
158
|
+
notifySet(definition, next, scope, cwd);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Delete a dot-path key from ONE scope — the "use default" / clear write. */
|
|
162
|
+
export function unsetSettings(namespace: string, key: string, scope: SettingsScope, cwd: string): void {
|
|
163
|
+
runGates(cwd);
|
|
164
|
+
const definition = registry.get(namespace);
|
|
165
|
+
if (!definition) throw new Error(`unknown settings namespace: ${namespace}`);
|
|
166
|
+
const target = scope === "global" ? globalSettingsPath(namespace) : projectSettingsPath(cwd, namespace);
|
|
167
|
+
const current = readJson(target);
|
|
168
|
+
if (!current) return;
|
|
169
|
+
const segments = key.split(".");
|
|
170
|
+
let cursor: Record<string, unknown> = current;
|
|
171
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
172
|
+
const next = cursor[segments[i]!];
|
|
173
|
+
if (typeof next !== "object" || next === null) return;
|
|
174
|
+
cursor = next as Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
delete cursor[segments[segments.length - 1]!];
|
|
177
|
+
writeJson(target, current);
|
|
178
|
+
notifySet(definition, current, scope, cwd);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** One layer only (no defaults, no merge) — for layered fallback chains. */
|
|
182
|
+
export function getSettingsScoped(
|
|
183
|
+
namespace: string,
|
|
184
|
+
scope: SettingsScope,
|
|
185
|
+
cwd: string,
|
|
186
|
+
): Record<string, unknown> | undefined {
|
|
187
|
+
runGates(cwd);
|
|
188
|
+
const path = scope === "global" ? globalSettingsPath(namespace) : projectSettingsPath(cwd, namespace);
|
|
189
|
+
return readJson(path) ?? undefined;
|
|
144
190
|
}
|
|
145
191
|
|
|
146
192
|
/** Which layers currently exist for a namespace (hub status display). */
|