@aiwayds/dsh-tui-pi 2.38.0 → 2.38.2
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/README.md +3 -1
- package/README.zh-CN.md +4 -0
- package/bin/boot.mjs +16 -4
- package/bin/companion-policy.mjs +102 -0
- package/bin/onboard-core.mjs +188 -28
- package/bin/registry-dist-tag.mjs +51 -0
- package/package.json +25 -8
- package/scripts/link-dsh-closure.mjs +13 -9
- package/skills/dsh-tui-pi-config/SKILL.md +1 -0
- package/scripts/postinstall.mjs +0 -54
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ A fully-featured pi-style terminal UI for [DeepSeek Harness](https://github.com/
|
|
|
6
6
|
|
|
7
7
|
**Requires dsh >= 0.2.2-rc.1** — this plugin targets the dsh RC/stable line only (CI and releases resolve the newest of the `latest`/`next` dist-tags at runtime). **The alpha line is no longer supported.** A startup guard logs a one-line warning and exits cleanly when the host is older than the floor (opt out with `DSH_TUI_SKIP_HOST_CHECK=1`). See [ADR 0002](docs/adr/0002-target-dsh-0.1.2-alpha.3-single-target.md) for the now-superseded alpha single-target decision.
|
|
8
8
|
|
|
9
|
+
**Companion versions on first/upgrade onboarding** — bundled companions are pinned to their registry `dist-tags.latest` by default (with a cross-major guard, a post-install version check and automatic fallback to the declared range). Set `DSH_TUI_COMPANION_LATEST=0` (or `false`/`off`) to install the declared ranges instead. The switch is read in the launcher before the TUI config loads; a failed registry query never blocks startup.
|
|
10
|
+
|
|
9
11
|
https://github.com/user-attachments/assets/67a7c6ca-ff42-4005-b543-437ba61771bb
|
|
10
12
|
|
|
11
13
|
*A live recording of a session (MP4, 1.5× speed) — todos, running subagents, think/tool panels and the powerline footer in action.*
|
|
@@ -42,7 +44,7 @@ npm i -g @aiwayds/dsh-tui-pi
|
|
|
42
44
|
dsh-tui-pi # or the short form: dst
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
The
|
|
47
|
+
The package carries no install-time hook — the machine is set up on the first run of the launcher, which prints one progress line per step: it installs the `@deepseek-ai/dsh` host when missing (via npm, resolved as the newest of the `latest`/`next` dist-tags — the `latest` tag alone lags the rc line; if npm itself is not on PATH, it prints what to install and stops), installs pnpm, and creates the `tui` profile with this plugin and its bundled companions. The first run can take a few minutes — the host download is large. Host compatibility window: **0.2.2-rc.1 and newer** — a host at or above the floor is kept as-is; an older one is upgraded automatically. Whatever the first run cannot finish (e.g. an offline machine) completes automatically on a later launch. After a later `npm i -g` upgrade of this package, the profile's mounted copy is moved to the new version on the next launch — a profile that is newer than the global install (dev-upgraded ahead) is left untouched.
|
|
46
48
|
|
|
47
49
|
The manual steps do exactly what the onboarding runs, if you prefer them:
|
|
48
50
|
|
package/README.zh-CN.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
**要求 dsh >= 0.2.2-rc.1** —— 本插件只跟随 dsh RC/stable 线(CI 与发版在运行时解析 latest/next 中更新的 dist-tag)。**不再支持 alpha 线。**宿主低于下限时,启动守卫会打一行 warning 并干净退出(可用 `DSH_TUI_SKIP_HOST_CHECK=1` 跳过)。alpha 单目标决策的历史见 [ADR 0002](docs/adr/0002-target-dsh-0.1.2-alpha.3-single-target.md)(已被取代)。
|
|
8
8
|
|
|
9
|
+
**首启/升级 onboard 时的 companion 版本** —— bundled companions 默认钉到 registry 的 `dist-tags.latest`(带跨 major 守卫、装后版本自检和失败自动回退声明范围)。设 `DSH_TUI_COMPANION_LATEST=0`(或 `false`/`off`)改为按 `package.json` 声明范围安装。该开关在 launcher 层、TUI Config 加载前读取;registry 查询失败不会阻塞启动。
|
|
10
|
+
|
|
9
11
|
https://github.com/user-attachments/assets/67a7c6ca-ff42-4005-b543-437ba61771bb
|
|
10
12
|
|
|
11
13
|
*一次真实 session 的实况录制(MP4,1.5× 速度)——todos、运行中的 subagents、think/tool 面板和 powerline footer 的实际效果。*
|
|
@@ -40,6 +42,8 @@ dsh plugin --profile tui add @aiwayds/dsh-tui-pi
|
|
|
40
42
|
dsh --profile tui # 启动(或:dsh-tui-pi)
|
|
41
43
|
```
|
|
42
44
|
|
|
45
|
+
本包不带任何安装期钩子——装机在启动器首次运行时完成,每步打一行进度:缺 `@deepseek-ai/dsh` 宿主时经 npm 全局安装(解析 `latest`/`next` 中更新的 dist-tag)、装 pnpm、创建带本插件与自带 companion 的 `tui` profile。首启要下载宿主,可能耗时数分钟;首次没装完的部分(如离线机器)下次启动自动补齐。之后升级本包,profile 的挂载副本在下次启动时随版本前移。
|
|
46
|
+
|
|
43
47
|
过去需要手工 patch 的一切——画布背景、`@deepseek-ai` 模块闭包、compaction 后端——现在都自动完成。发版后升级现有 profile:
|
|
44
48
|
|
|
45
49
|
```sh
|
package/bin/boot.mjs
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* SyntaxError, so the guard stops with the paths and the removal commands.
|
|
13
13
|
*
|
|
14
14
|
* Version follow: after `npm i -g` upgrades this package, the profile still
|
|
15
|
-
* holds the old copy; the next launch
|
|
16
|
-
* the
|
|
17
|
-
*
|
|
15
|
+
* holds the old copy; the next launch re-runs the add to move the profile to
|
|
16
|
+
* the new version. A profile that is NEWER than the global install
|
|
17
|
+
* (dev-upgraded ahead) is left untouched.
|
|
18
18
|
*
|
|
19
19
|
* See bin/onboard-core.mjs for the setup logic and its failure contract.
|
|
20
20
|
*/
|
|
@@ -32,6 +32,15 @@ import {
|
|
|
32
32
|
|
|
33
33
|
const args = process.argv.slice(2)
|
|
34
34
|
|
|
35
|
+
// Single kill switch for companion-latest onboarding, read once in the bin
|
|
36
|
+
// layer (before the TUI Config exists). Anything other than 0/false/off —
|
|
37
|
+
// including unset — means enabled. Mirrors the DSH_TUI_SKIP_HOST_CHECK style.
|
|
38
|
+
function companionLatestEnabled() {
|
|
39
|
+
const raw = process.env.DSH_TUI_COMPANION_LATEST
|
|
40
|
+
if (raw === undefined) return true
|
|
41
|
+
return !['0', 'false', 'off'].includes(String(raw).trim().toLowerCase())
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
function boot(dsh) {
|
|
36
45
|
const result = spawnSync(dsh, ['--profile', 'tui', ...args], { stdio: 'inherit' })
|
|
37
46
|
process.exit(result.status ?? 1)
|
|
@@ -51,7 +60,10 @@ if (dsh && profileMounted() && !profileBehind()) {
|
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
console.log('dsh-tui-pi setup (first run / upgrade only):')
|
|
54
|
-
const setup = runOnboard({
|
|
63
|
+
const setup = runOnboard({
|
|
64
|
+
log: (line) => console.log(line),
|
|
65
|
+
companionLatest: companionLatestEnabled(),
|
|
66
|
+
})
|
|
55
67
|
if (!setup.ok) {
|
|
56
68
|
console.error(`\ndsh-tui-pi: setup stopped at "${setup.step}".`)
|
|
57
69
|
if (setup.detail) console.error(`dsh-tui-pi: ${setup.step} — ${setup.detail}`)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure decision table for the "install companion latest" onboarding step.
|
|
3
|
+
*
|
|
4
|
+
* No I/O, no process.env, no clock: every input is passed in, so the whole
|
|
5
|
+
* table is unit-testable (same shape as src/host-version.ts's pure functions).
|
|
6
|
+
* The caller (bin/onboard-core.mjs) owns the registry query, the profile
|
|
7
|
+
* reads and the actual install; this module only answers one question:
|
|
8
|
+
* given a declared range, a resolved latest version and the currently
|
|
9
|
+
* mounted pin, what exact spec (if any) should be handed to `dsh plugin add`?
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const REASONS = Object.freeze({
|
|
13
|
+
LATEST: 'latest',
|
|
14
|
+
DISABLED: 'disabled',
|
|
15
|
+
UNRESOLVED: 'unresolved',
|
|
16
|
+
CROSS_MAJOR: 'cross_major',
|
|
17
|
+
DOWNGRADE: 'downgrade',
|
|
18
|
+
IDEMPOTENT: 'idempotent',
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// Companions are 0.x packages: major is the only hard boundary, a 0.x minor
|
|
22
|
+
// jump (0.9 → 0.10, 0.20 → 0.21) is exactly the case this feature must allow.
|
|
23
|
+
// We only need the numeric core for the guard; prerelease suffixes are kept
|
|
24
|
+
// verbatim in the spec but ignored for comparisons.
|
|
25
|
+
// npm dist-tags are usually bare (`0.14.9`) but occasionally carry a leading
|
|
26
|
+
// `v` (`v0.14.9`). The version recorded in an installed manifest never has the
|
|
27
|
+
// `v`, so normalise before building the spec — otherwise the post-install
|
|
28
|
+
// self-check compares `0.14.9` against `v0.14.9` and fails spuriously.
|
|
29
|
+
// Prerelease suffixes (`0.3.0-rc.1`) are part of the version and kept verbatim.
|
|
30
|
+
export function normalizeVersion(version) {
|
|
31
|
+
return String(version).trim().replace(/^v/, '')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseCore(version) {
|
|
35
|
+
if (typeof version !== 'string') return null
|
|
36
|
+
// Declared ranges carry an operator prefix (^0.14.0, ~0.9.0, >=1.2.3);
|
|
37
|
+
// resolved pins are bare (0.14.5, possibly v-prefixed). Only the numeric
|
|
38
|
+
// core is needed for the major guard.
|
|
39
|
+
const match = /^[v^~><=\s]*(\d+)\.(\d+)\.(\d+)/.exec(version.trim())
|
|
40
|
+
if (!match) return null
|
|
41
|
+
return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]) }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function compareCore(a, b) {
|
|
45
|
+
const pa = parseCore(a)
|
|
46
|
+
const pb = parseCore(b)
|
|
47
|
+
if (!pa || !pb) return null
|
|
48
|
+
for (const key of ['major', 'minor', 'patch']) {
|
|
49
|
+
if (pa[key] !== pb[key]) return pa[key] - pb[key]
|
|
50
|
+
}
|
|
51
|
+
return 0
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Decide one companion's install action.
|
|
56
|
+
*
|
|
57
|
+
* Inputs:
|
|
58
|
+
* packageName — e.g. '@aiwayds/dsh-dcp' (used to build the exact spec)
|
|
59
|
+
* declaredRange — the caret range from package.json.dependencies
|
|
60
|
+
* resolved — dist-tags.latest from the registry, or null on failure
|
|
61
|
+
* currentPin — version mounted in the profile, or null on a fresh install
|
|
62
|
+
* enabled — the bin-layer kill switch (DSH_TUI_COMPANION_LATEST)
|
|
63
|
+
*
|
|
64
|
+
* Output:
|
|
65
|
+
* { action, spec, reason }
|
|
66
|
+
* action 'latest' → spec is 'pkg@<resolved>'; pass it to plugin add
|
|
67
|
+
* action 'fallback' → spec is null; install the declared range (today's path)
|
|
68
|
+
* action 'skip' → spec is null; no-op (already pinned / never downgrade)
|
|
69
|
+
*
|
|
70
|
+
* Decision order matters: the kill switch wins first, then an unusable
|
|
71
|
+
* resolution, then the cross-major guard, then the current-pin comparison.
|
|
72
|
+
*/
|
|
73
|
+
export function decideCompanionInstall({
|
|
74
|
+
packageName,
|
|
75
|
+
declaredRange,
|
|
76
|
+
resolved,
|
|
77
|
+
currentPin = null,
|
|
78
|
+
enabled = true,
|
|
79
|
+
} = {}) {
|
|
80
|
+
const fallback = (reason) => ({ action: 'fallback', spec: null, reason })
|
|
81
|
+
const skip = (reason) => ({ action: 'skip', spec: null, reason })
|
|
82
|
+
const latest = () => ({ action: 'latest', spec: `${packageName}@${normalizeVersion(resolved)}`, reason: REASONS.LATEST })
|
|
83
|
+
|
|
84
|
+
if (!enabled) return fallback(REASONS.DISABLED)
|
|
85
|
+
|
|
86
|
+
const resolvedCore = parseCore(resolved)
|
|
87
|
+
const declaredCore = parseCore(declaredRange)
|
|
88
|
+
// Without a trustworthy resolved version or a declared range to guard
|
|
89
|
+
// against, fall back — never send a half-checked spec to plugin add.
|
|
90
|
+
if (!resolvedCore || !declaredCore) return fallback(REASONS.UNRESOLVED)
|
|
91
|
+
|
|
92
|
+
if (resolvedCore.major !== declaredCore.major) return fallback(REASONS.CROSS_MAJOR)
|
|
93
|
+
|
|
94
|
+
if (currentPin) {
|
|
95
|
+
const cmp = compareCore(resolved, currentPin)
|
|
96
|
+
if (cmp === null) return fallback(REASONS.UNRESOLVED)
|
|
97
|
+
if (cmp < 0) return skip(REASONS.DOWNGRADE)
|
|
98
|
+
if (cmp === 0) return skip(REASONS.IDEMPOTENT)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return latest()
|
|
102
|
+
}
|
package/bin/onboard-core.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One-time onboarding for the `dsh-tui-pi` / `dst` launcher
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* One-time onboarding for the `dsh-tui-pi` / `dst` launcher. The package
|
|
3
|
+
* carries no install hook — the historical `scripts/postinstall.mjs` was
|
|
4
|
+
* removed because pnpm 11's strictDepBuilds validation gates dependencies'
|
|
5
|
+
* install scripts (see docs/adr/0004-onboarding-first-launch-not-postinstall.md)
|
|
6
|
+
* — so `bin/boot.mjs` is the single entry point: it runs on the first
|
|
7
|
+
* `dsh-tui-pi` invocation and on any later one that finds the machine
|
|
8
|
+
* missing a piece (fresh machine, offline first run, profile behind after
|
|
9
|
+
* an upgrade, …).
|
|
9
10
|
*
|
|
10
11
|
* Contract:
|
|
11
12
|
* - idempotent: every step checks before it acts, so a re-run only prints
|
|
@@ -21,9 +22,12 @@
|
|
|
21
22
|
|
|
22
23
|
import { execFileSync, spawnSync } from 'node:child_process'
|
|
23
24
|
import { accessSync, constants, existsSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
25
|
+
import { createRequire } from 'node:module'
|
|
24
26
|
import { homedir } from 'node:os'
|
|
25
27
|
import { delimiter, dirname, join } from 'node:path'
|
|
26
28
|
import { fileURLToPath } from 'node:url'
|
|
29
|
+
import { decideCompanionInstall, normalizeVersion } from './companion-policy.mjs'
|
|
30
|
+
import { queryDistTagLatest } from './registry-dist-tag.mjs'
|
|
27
31
|
|
|
28
32
|
const PKG = '@aiwayds/dsh-tui-pi'
|
|
29
33
|
const HOST = '@deepseek-ai/dsh'
|
|
@@ -77,6 +81,70 @@ export function companions() {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
84
|
+
// Same companions, but with their declared caret ranges — the policy guard
|
|
85
|
+
// needs the range to reject a cross-major latest. The declaration is read
|
|
86
|
+
// from this package, never from the profile (which only holds resolved pins).
|
|
87
|
+
export function companionRanges() {
|
|
88
|
+
try {
|
|
89
|
+
const deps = readSelfPackage().dependencies ?? {}
|
|
90
|
+
const ranges = {}
|
|
91
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
92
|
+
if (name.startsWith('@aiwayds/') && name !== PKG) ranges[name] = range
|
|
93
|
+
}
|
|
94
|
+
return ranges
|
|
95
|
+
} catch {
|
|
96
|
+
return {}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function profileCompanionDir(name) {
|
|
101
|
+
return join(dshHome(), 'profiles', PROFILE, 'node_modules', name)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The version currently mounted in the profile, or null when absent. Used
|
|
105
|
+
// only for the idempotent / no-downgrade guard, never to change a user pin.
|
|
106
|
+
export function profileCompanionVersion(name) {
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(readFileSync(join(profileCompanionDir(name), 'package.json'), 'utf8')).version ?? null
|
|
109
|
+
} catch {
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The spec recorded for a companion in the profile's own package.json
|
|
115
|
+
// `dependencies`. `dsh plugin add pkg@<spec>` writes that line verbatim, so
|
|
116
|
+
// re-reading it is how the fallback verifies an exact pin was really replaced
|
|
117
|
+
// by the declared range (a bare add leaves the exact pin untouched).
|
|
118
|
+
export function profileCompanionSpec(name) {
|
|
119
|
+
try {
|
|
120
|
+
const manifest = JSON.parse(readFileSync(join(dshHome(), 'profiles', PROFILE, 'package.json'), 'utf8'))
|
|
121
|
+
return manifest.dependencies?.[name] ?? null
|
|
122
|
+
} catch {
|
|
123
|
+
return null
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Post-install self-check: resolve the freshly installed companion from the
|
|
128
|
+
// profile and compare its package.json version with the exact spec we asked
|
|
129
|
+
// for. A load failure or a version mismatch means the pin did not land and
|
|
130
|
+
// the caller must fall back to the declared range (today's path).
|
|
131
|
+
function companionSelfCheck(name, expectedVersion) {
|
|
132
|
+
try {
|
|
133
|
+
const req = createRequire(join(profileCompanionDir(name), 'noop.js'))
|
|
134
|
+
let manifest
|
|
135
|
+
try {
|
|
136
|
+
manifest = req.resolve(`${name}/package.json`)
|
|
137
|
+
} catch {
|
|
138
|
+
// Some companions do not export ./package.json; fall back to the
|
|
139
|
+
// profile's physical path, which is where `dsh plugin add` mounts it.
|
|
140
|
+
manifest = join(profileCompanionDir(name), 'package.json')
|
|
141
|
+
}
|
|
142
|
+
return JSON.parse(readFileSync(manifest, 'utf8')).version === expectedVersion
|
|
143
|
+
} catch {
|
|
144
|
+
return false
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
80
148
|
export function which(cmd) {
|
|
81
149
|
const dirs = (process.env.PATH || '').split(delimiter).filter(Boolean)
|
|
82
150
|
const suffixes = process.platform === 'win32' ? ['.cmd', '.exe', '.bat', ''] : ['']
|
|
@@ -230,10 +298,11 @@ export function compareVersions(a, b) {
|
|
|
230
298
|
}
|
|
231
299
|
|
|
232
300
|
// pnpm ≥10 fails a fresh `add` with ERR_PNPM_IGNORED_BUILDS when the added
|
|
233
|
-
// packages carry lifecycle scripts. The
|
|
234
|
-
// the closure
|
|
235
|
-
//
|
|
236
|
-
// approve-builds` would do interactively
|
|
301
|
+
// packages carry lifecycle scripts. The packages this suite ships declare
|
|
302
|
+
// none (the dev-tree closure linker is not wired as a hook in any published
|
|
303
|
+
// tarball), so filling the allowBuilds block approves nothing that can run
|
|
304
|
+
// unvetted — it is what `pnpm approve-builds` would do interactively, and it
|
|
305
|
+
// stays safe as companions evolve. pnpm sometimes records an
|
|
237
306
|
// allowBuilds skeleton in the profile's pnpm-workspace.yaml with a
|
|
238
307
|
// "set this to true or false" placeholder — fill those placeholders; when
|
|
239
308
|
// it does not (behavior varies by pnpm build and environment), write the
|
|
@@ -265,10 +334,18 @@ function approvePrintedBuilds() {
|
|
|
265
334
|
* itself is not on PATH, print what to install and stop
|
|
266
335
|
* 2/3 pnpm — the host's plugin manager shells out to it; installed
|
|
267
336
|
* globally when missing
|
|
268
|
-
* 3/3 tui profile — `dsh plugin --profile tui add` this package (+ companions)
|
|
337
|
+
* 3/3 tui profile — `dsh plugin --profile tui add` this package (+ companions).
|
|
338
|
+
* With companion latest enabled (the default), each companion's
|
|
339
|
+
* `dist-tags.latest` is resolved and guarded before the add, so the
|
|
340
|
+
* exact version is pinned; a failed query/guard falls back to the
|
|
341
|
+
* declared range (today's path) without blocking onboard.
|
|
269
342
|
* Returns { ok: true, dsh } or { ok: false, step, hint, detail }.
|
|
343
|
+
*
|
|
344
|
+
* `companionLatest` comes from the bin-layer DSH_TUI_COMPANION_LATEST switch;
|
|
345
|
+
* it is an explicit parameter, not an env read here, so the decision stays
|
|
346
|
+
* testable and the TUI Config layer never gets a second source of truth.
|
|
270
347
|
*/
|
|
271
|
-
export function runOnboard({ log = () => {} } = {}) {
|
|
348
|
+
export function runOnboard({ log = () => {}, companionLatest = true } = {}) {
|
|
272
349
|
let dsh = dshBinPath()
|
|
273
350
|
const wanted = resolveHostVersion()
|
|
274
351
|
const hostSpec = wanted ? `${HOST}@${wanted}` : HOST
|
|
@@ -318,25 +395,108 @@ export function runOnboard({ log = () => {} } = {}) {
|
|
|
318
395
|
const list = companions()
|
|
319
396
|
log(` [3/3] tui profile ${verb}: installing ${PKG}${list.length ? ` + ${list.length} bundled companions` : ''}…`)
|
|
320
397
|
if (list.length) log(` ${list.join(', ')}`)
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
398
|
+
|
|
399
|
+
// Resolve → guard → decide, one line per companion. The registry query
|
|
400
|
+
// inherits the install's env and runs from the profile dir when present,
|
|
401
|
+
// so a profile-level .npmrc (private registry) is seen by both sides.
|
|
402
|
+
const profileDir = join(dshHome(), 'profiles', PROFILE)
|
|
403
|
+
const registryCwd = existsSync(profileDir) ? profileDir : process.cwd()
|
|
404
|
+
const ranges = companionRanges()
|
|
405
|
+
const decisions = list.map((name) => {
|
|
406
|
+
const declaredRange = ranges[name] ?? null
|
|
407
|
+
const queried = companionLatest && declaredRange
|
|
408
|
+
? queryDistTagLatest(name, { cwd: registryCwd, env: process.env })
|
|
409
|
+
: null
|
|
410
|
+
// Normalise once so the spec handed to plugin add and the version the
|
|
411
|
+
// self-check expects are the same string (a `v`-prefixed dist-tag would
|
|
412
|
+
// otherwise make the installed manifest compare unequal to the spec).
|
|
413
|
+
const resolved = queried ? normalizeVersion(queried) : null
|
|
414
|
+
const currentPin = profileCompanionVersion(name)
|
|
415
|
+
const decision = decideCompanionInstall({ packageName: name, declaredRange, resolved, currentPin, enabled: companionLatest })
|
|
416
|
+
if (decision.action === 'latest') {
|
|
417
|
+
log(` ${name}: ${declaredRange} → ${resolved} (latest)`)
|
|
418
|
+
} else if (decision.action === 'skip') {
|
|
419
|
+
log(` ${name}: skip ${declaredRange ?? '(no range)'} (${decision.reason})`)
|
|
420
|
+
} else {
|
|
421
|
+
log(` ${name}: fallback ${declaredRange ?? '(no range)'} (${decision.reason})`)
|
|
422
|
+
}
|
|
423
|
+
return { name, resolved, decision }
|
|
324
424
|
})
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
425
|
+
|
|
426
|
+
// Only guarded, resolved companions get an explicit exact spec; every
|
|
427
|
+
// fallback / skip leaves the declared-range resolution to the host, which
|
|
428
|
+
// is byte-for-byte today's `dsh plugin add PKG` behaviour.
|
|
429
|
+
const specDecisions = decisions.filter((entry) => entry.decision.action === 'latest')
|
|
430
|
+
const declaredArgs = ['plugin', '--profile', PROFILE, 'add', PKG]
|
|
431
|
+
const addArgs = [...declaredArgs, ...specDecisions.map((entry) => entry.decision.spec)]
|
|
432
|
+
const profileFail = {
|
|
433
|
+
ok: false,
|
|
434
|
+
step: 'tui profile setup',
|
|
435
|
+
hint: `run it manually with: dsh plugin --profile ${PROFILE} add ${PKG} — then re-run dsh-tui-pi`,
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// One add attempt, keeping the existing build-approval retry: pnpm ≥10 can
|
|
439
|
+
// fail a fresh add with ERR_PNPM_IGNORED_BUILDS, which filling its
|
|
440
|
+
// allowBuilds skeleton fixes. When approvePrintedBuilds changes nothing we
|
|
441
|
+
// do not retry — that is today's behaviour. Returns the final spawn result.
|
|
442
|
+
function pluginAdd(args) {
|
|
443
|
+
let res = spawnSync(dsh, args, { stdio: 'inherit', timeout: INSTALL_TIMEOUT_MS })
|
|
444
|
+
if (res.status !== 0) {
|
|
445
|
+
if (!approvePrintedBuilds()) return res
|
|
446
|
+
log(' [3/3] tui profile approved the printed build scripts (our closure-linker no-ops) — retrying…')
|
|
447
|
+
res = spawnSync(dsh, args, { stdio: 'inherit', timeout: INSTALL_TIMEOUT_MS })
|
|
448
|
+
}
|
|
449
|
+
return res
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
let result = pluginAdd(addArgs)
|
|
453
|
+
|
|
454
|
+
// An exact-spec add can be rejected for reasons the build-approval retry
|
|
455
|
+
// does not address: the host's pre-install compatibility preflight, a
|
|
456
|
+
// dist-tag that moved between query and add, or its post-install rollback
|
|
457
|
+
// (all exit 1). Downgrade to the declared range once; only a second failure
|
|
458
|
+
// falls into today's abort semantics. The log states the observed exit and
|
|
459
|
+
// the likely causes so this retry is distinguishable from the one above.
|
|
460
|
+
let specAddFellBack = false
|
|
461
|
+
if (result.status !== 0 && specDecisions.length > 0) {
|
|
462
|
+
const cause = result.signal ? `signal ${result.signal}` : `exit ${result.status ?? 'unknown'}`
|
|
463
|
+
log(` companion spec add failed (${cause}; e.g. host compatibility preflight / dist-tag moved / post-install rollback) — retrying declared range`)
|
|
464
|
+
specAddFellBack = true
|
|
465
|
+
result = pluginAdd(declaredArgs)
|
|
466
|
+
}
|
|
467
|
+
if (result.status !== 0) return profileFail
|
|
468
|
+
|
|
469
|
+
// Post-install self-check on the exact specs only. When a pinned companion
|
|
470
|
+
// did not land at the requested version, reinstall its declared range with
|
|
471
|
+
// an EXPLICIT spec — a bare add would leave the bad exact pin in the
|
|
472
|
+
// profile's package.json (P1-2). Read that line back after the fallback and
|
|
473
|
+
// report only what actually happened. Skipped entirely if the add already
|
|
474
|
+
// fell back.
|
|
475
|
+
const broken = specAddFellBack
|
|
476
|
+
? []
|
|
477
|
+
: specDecisions.filter((entry) => !companionSelfCheck(entry.name, entry.resolved))
|
|
478
|
+
if (broken.length) {
|
|
479
|
+
log(` ${broken.map((entry) => entry.name).join(', ')}: self-check failed — reinstalling declared range with explicit specs`)
|
|
480
|
+
const fallbackSpecs = broken.map((entry) => `${entry.name}@${ranges[entry.name]}`)
|
|
481
|
+
const fallback = pluginAdd([...declaredArgs, ...fallbackSpecs])
|
|
482
|
+
if (fallback.status !== 0) return profileFail
|
|
483
|
+
// Verified only when the line now holds exactly the declared range we
|
|
484
|
+
// asked for — not merely a value that changed from the bad pin.
|
|
485
|
+
const verified = broken.filter((entry) => profileCompanionSpec(entry.name) === ranges[entry.name])
|
|
486
|
+
if (verified.length) {
|
|
487
|
+
log(` ${verified.map((entry) => entry.name).join(', ')}: declared spec restored and verified in profile manifest`)
|
|
328
488
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const retry = spawnSync(dsh, ['plugin', '--profile', PROFILE, 'add', PKG], {
|
|
333
|
-
stdio: 'inherit',
|
|
334
|
-
timeout: INSTALL_TIMEOUT_MS,
|
|
335
|
-
})
|
|
336
|
-
if (retry.status !== 0) {
|
|
337
|
-
return { ok: false, step: 'tui profile setup', hint: `run it manually with: dsh plugin --profile ${PROFILE} add ${PKG} — then re-run dsh-tui-pi` }
|
|
489
|
+
const unverified = broken.filter((entry) => !verified.includes(entry))
|
|
490
|
+
if (unverified.length) {
|
|
491
|
+
log(` ${unverified.map((entry) => entry.name).join(', ')}: fallback re-check inconclusive — declared spec not reflected in profile manifest`)
|
|
338
492
|
}
|
|
339
493
|
}
|
|
494
|
+
|
|
495
|
+
const latestCount = specAddFellBack ? 0 : specDecisions.length - broken.length
|
|
496
|
+
const fallbackCount = decisions.filter((entry) => entry.decision.action === 'fallback').length
|
|
497
|
+
+ (specAddFellBack ? specDecisions.length : broken.length)
|
|
498
|
+
const skipCount = decisions.filter((entry) => entry.decision.action === 'skip').length
|
|
499
|
+
log(` companions: ${latestCount} latest, ${fallbackCount} fallback, ${skipCount} skipped`)
|
|
340
500
|
log(` [3/3] tui profile ${verb === 'updating' ? 'updated' : 'done'}`)
|
|
341
501
|
}
|
|
342
502
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin wrapper around `npm view <pkg> dist-tags.latest --json`. Kept separate
|
|
3
|
+
* from the policy module so the policy stays pure and the subprocess can be
|
|
4
|
+
* replaced by a fake `npm` shim in tests.
|
|
5
|
+
*
|
|
6
|
+
* Contract:
|
|
7
|
+
* - query the `latest` DIST-TAG (not "newest published version"): when a
|
|
8
|
+
* maintainer moves the tag these two diverge, and `latest` is the defined
|
|
9
|
+
* source of truth;
|
|
10
|
+
* - inherit the exact cwd/env the install uses, so a profile-level .npmrc
|
|
11
|
+
* (private registry / auth) is seen by both the query and the install;
|
|
12
|
+
* - fail SOFT: any timeout, spawn error, non-zero exit or unparsable output
|
|
13
|
+
* returns null and the caller installs the declared range (never throws,
|
|
14
|
+
* never blocks onboard).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { execFileSync } from 'node:child_process'
|
|
18
|
+
|
|
19
|
+
// npm dist-tags are usually bare but occasionally carry a leading `v`. Accept
|
|
20
|
+
// both here; the caller normalises the value before building the install spec.
|
|
21
|
+
const VERSION_RE = /^v?\d+\.\d+\.\d+/
|
|
22
|
+
const QUERY_TIMEOUT_MS = 15_000
|
|
23
|
+
|
|
24
|
+
export function queryDistTagLatest(packageName, { cwd, env = process.env, timeout = QUERY_TIMEOUT_MS } = {}) {
|
|
25
|
+
if (!packageName) return null
|
|
26
|
+
try {
|
|
27
|
+
const out = execFileSync('npm', ['view', packageName, 'dist-tags.latest', '--json'], {
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
timeout,
|
|
30
|
+
cwd,
|
|
31
|
+
env,
|
|
32
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
33
|
+
}).trim()
|
|
34
|
+
if (!out) return null
|
|
35
|
+
|
|
36
|
+
// Real npm --json prints a quoted string ("0.21.0"); tolerate a bare
|
|
37
|
+
// value too, but reject objects (e.g. a dist-tags map) — that is a
|
|
38
|
+
// different query shape and must not be mistaken for a single version.
|
|
39
|
+
let value = out
|
|
40
|
+
try {
|
|
41
|
+
value = JSON.parse(out)
|
|
42
|
+
} catch {
|
|
43
|
+
/* bare version, keep as-is */
|
|
44
|
+
}
|
|
45
|
+
if (typeof value !== 'string') return null
|
|
46
|
+
const version = value.trim()
|
|
47
|
+
return VERSION_RE.test(version) ? version : null
|
|
48
|
+
} catch {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiwayds/dsh-tui-pi",
|
|
3
|
-
"version": "2.38.
|
|
3
|
+
"version": "2.38.2",
|
|
4
4
|
"description": "A fully-featured pi-style terminal UI for DeepSeek Harness (dsh) — history look-back & fork-at-turn, guided preset switching, live subagent steering, model profiles & themes",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -59,23 +59,23 @@
|
|
|
59
59
|
"scripts": {
|
|
60
60
|
"link-closure": "node scripts/link-dsh-closure.mjs",
|
|
61
61
|
"build": "tsc -p tsconfig.json",
|
|
62
|
+
"prebuild": "node scripts/link-dsh-closure.mjs",
|
|
62
63
|
"check": "tsc --noEmit -p tsconfig.json",
|
|
63
64
|
"precheck": "node scripts/link-dsh-closure.mjs",
|
|
64
65
|
"pretest": "npm run build",
|
|
65
66
|
"test": "node --test test/*.test.mjs",
|
|
66
|
-
"smoke": "node scripts/smoke-boot.mjs"
|
|
67
|
-
"postinstall": "node scripts/postinstall.mjs"
|
|
67
|
+
"smoke": "node scripts/smoke-boot.mjs"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@aiwayds/dsh-ask-router": "^0.7.0",
|
|
71
71
|
"@aiwayds/dsh-dcp": "^0.14.0",
|
|
72
72
|
"@aiwayds/dsh-jev-core": "^0.2.0",
|
|
73
|
-
"@aiwayds/dsh-llm-proxy": "^0.8.
|
|
73
|
+
"@aiwayds/dsh-llm-proxy": "^0.8.1",
|
|
74
74
|
"@aiwayds/dsh-llm-stats": "^0.9.0",
|
|
75
|
-
"@aiwayds/dsh-mcp-adapter": "^0.8.
|
|
75
|
+
"@aiwayds/dsh-mcp-adapter": "^0.8.1",
|
|
76
76
|
"@aiwayds/dsh-model-sync": "^0.9.0",
|
|
77
|
-
"@aiwayds/dsh-profile-switch": "^0.4.
|
|
78
|
-
"@aiwayds/dsh-subagent-registry": "^0.
|
|
77
|
+
"@aiwayds/dsh-profile-switch": "^0.4.1",
|
|
78
|
+
"@aiwayds/dsh-subagent-registry": "^0.20.1",
|
|
79
79
|
"@aiwayds/dsh-web-search-anysearch": "^0.9.0",
|
|
80
80
|
"@earendil-works/pi-tui": "0.85.1"
|
|
81
81
|
},
|
|
@@ -106,7 +106,24 @@
|
|
|
106
106
|
"dsh": {
|
|
107
107
|
"bundle": {
|
|
108
108
|
"patch": "./cordis.patch.yml"
|
|
109
|
-
}
|
|
109
|
+
},
|
|
110
|
+
"companions": [
|
|
111
|
+
{
|
|
112
|
+
"name": "@aiwayds/dsh-subagent-registry",
|
|
113
|
+
"description": "提供 subagent 协作能力,启用多代理任务编排与调度。",
|
|
114
|
+
"required": true
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"name": "@aiwayds/dsh-dcp",
|
|
118
|
+
"description": "提供上下文动态压缩,长会话自动收敛 token 占用。",
|
|
119
|
+
"required": false
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "@aiwayds/dsh-topics-memory",
|
|
123
|
+
"description": "提供会话记忆,跨会话保留长期上下文。",
|
|
124
|
+
"required": false
|
|
125
|
+
}
|
|
126
|
+
]
|
|
110
127
|
},
|
|
111
128
|
"author": "fan56",
|
|
112
129
|
"publishConfig": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* global dsh closure.
|
|
2
|
+
* Dev-tree closure linker: point every `node_modules/@deepseek-ai/*` entry
|
|
3
|
+
* at the global dsh closure.
|
|
4
4
|
*
|
|
5
5
|
* Why this exists: dsh-tui-pi is a plugin that runs *inside* the installed
|
|
6
6
|
* dsh CLI, and its source imports the `@deepseek-ai/*` packages (cordis,
|
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
* (`Property 'settings' does not exist on type 'Context'`), so they must stay
|
|
18
18
|
* *undeclared*. pnpm then treats the closure links as extraneous — and, as
|
|
19
19
|
* it prunes entries it once managed, the links can still disappear after an
|
|
20
|
-
* install. This script re-creates them
|
|
20
|
+
* install. This script re-creates them after an install: in the dev tree it
|
|
21
|
+
* runs through the `link-closure` / `precheck` scripts — it is not wired as
|
|
22
|
+
* a lifecycle hook anywhere, and the published tarball carries no hooks at
|
|
23
|
+
* all (ADR 0004).
|
|
21
24
|
*
|
|
22
25
|
* It is a no-op (exit 0) when no global dsh install is found — a dev machine
|
|
23
26
|
* without dsh simply cannot typecheck against dsh types.
|
|
@@ -29,12 +32,13 @@ import { dirname, join } from 'node:path'
|
|
|
29
32
|
import { fileURLToPath } from 'node:url'
|
|
30
33
|
|
|
31
34
|
const repoRoot = dirname(dirname(fileURLToPath(import.meta.url)))
|
|
32
|
-
// Guard: this
|
|
33
|
-
// published tarball carries scripts/ but no
|
|
34
|
-
// consumer's node_modules (it would delete
|
|
35
|
-
// replace them with symlinks into their
|
|
36
|
-
//
|
|
37
|
-
//
|
|
35
|
+
// Guard: this linker is a dev-machine convenience for THIS repo, invoked
|
|
36
|
+
// only through the dev scripts. A published tarball carries scripts/ but no
|
|
37
|
+
// src/, and must never touch a consumer's node_modules (it would delete
|
|
38
|
+
// their @deepseek-ai packages and replace them with symlinks into their
|
|
39
|
+
// global dsh closure). npm would run a script wired under this name as a
|
|
40
|
+
// lifecycle hook — the published package wires none, and the guard stays as
|
|
41
|
+
// a hard boundary: exit silently outside the repo.
|
|
38
42
|
if (!existsSync(join(repoRoot, 'src'))) {
|
|
39
43
|
process.exit(0)
|
|
40
44
|
}
|
|
@@ -56,6 +56,7 @@ dsh 0.1.5 的 `~/.dsh/settings.yaml` 已移除:其顶层 `dsh-tui:` 段会在
|
|
|
56
56
|
| `DSH_TUI_COPY_ON_SELECT` | `0` 让拖选仅视觉选中、不自动复制(默认开) |
|
|
57
57
|
| `DSH_TUI_BTW_CONTEXT_MESSAGES` | `/btw` 侧问快照的最近消息条数 |
|
|
58
58
|
| `DSH_TUI_SKIP_HOST_CHECK` | `1` 跳过宿主版本下限检查(测试用) |
|
|
59
|
+
| `DSH_TUI_COMPANION_LATEST` | 首次/升级 onboard 时是否把 bundled companions 钉到 registry 的 `dist-tags.latest`(默认开);`0`/`false`/`off` 关闭,关闭后按 `package.json` 声明范围安装。在 bin 层读取,早于 TUI Config;查询失败/跨 major 自动回退声明范围,不阻塞启动 |
|
|
59
60
|
|
|
60
61
|
retention/resume/askUser 组的优先级:**显式配置值 > env > 默认**(只看 entry `config:` 段里
|
|
61
62
|
实际写下的键,未写的键回落 env,再回落默认)。
|
package/scripts/postinstall.mjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* npm postinstall for `@aiwayds/dsh-tui-pi` — two jobs, in order:
|
|
4
|
-
*
|
|
5
|
-
* 1. The repo's dev linker (link-dsh-closure.mjs). It self-guards: on a
|
|
6
|
-
* published tarball (no src/) it exits 0 without touching anything, so
|
|
7
|
-
* this is a no-op for consumers and the dev-machine behavior is
|
|
8
|
-
* unchanged.
|
|
9
|
-
*
|
|
10
|
-
* 2. Global installs then run the one-time onboarding — dsh host, pnpm and
|
|
11
|
-
* the `tui` profile are in place by the time npm prints "added 1
|
|
12
|
-
* package", so the first `dsh-tui-pi` (or `dst`) boots straight into the
|
|
13
|
-
* TUI. Anything this cannot finish (offline machine, no npm on PATH, a
|
|
14
|
-
* package manager that skips lifecycle scripts) is deferred to the
|
|
15
|
-
* launcher's first run, which re-runs the same idempotent onboarding.
|
|
16
|
-
*
|
|
17
|
-
* Guards:
|
|
18
|
-
* - local/dev installs (`npm i` inside a project, `pnpm link`, CI
|
|
19
|
-
* checkouts) skip the onboarding silently — it is only meaningful for a
|
|
20
|
-
* user-wide install;
|
|
21
|
-
* - this script NEVER fails the install: every failure path exits 0.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { spawnSync } from 'node:child_process'
|
|
25
|
-
import { dirname, join } from 'node:path'
|
|
26
|
-
import { fileURLToPath } from 'node:url'
|
|
27
|
-
|
|
28
|
-
const scriptDir = dirname(fileURLToPath(import.meta.url))
|
|
29
|
-
|
|
30
|
-
// 1) dev closure linker — self-guarding, always safe to run
|
|
31
|
-
const linker = spawnSync(process.execPath, [join(scriptDir, 'link-dsh-closure.mjs')], {
|
|
32
|
-
stdio: 'inherit',
|
|
33
|
-
})
|
|
34
|
-
if (linker.error) {
|
|
35
|
-
console.warn(`[postinstall] closure linker skipped: ${linker.error.message}`)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 2) onboarding — global installs only, never fails the install
|
|
39
|
-
if (process.env.npm_config_global !== 'true') process.exit(0)
|
|
40
|
-
|
|
41
|
-
console.log('dsh-tui-pi: preparing the dsh host, pnpm and the "tui" profile…')
|
|
42
|
-
try {
|
|
43
|
-
const { runOnboard } = await import('../bin/onboard-core.mjs')
|
|
44
|
-
const setup = runOnboard({ log: (line) => console.log(line) })
|
|
45
|
-
if (!setup.ok) {
|
|
46
|
-
console.log(`dsh-tui-pi: setup stopped at "${setup.step}"${setup.detail ? ` — ${setup.detail}` : ''} — ${setup.hint}`)
|
|
47
|
-
console.log('dsh-tui-pi: it will complete automatically on first launch.')
|
|
48
|
-
} else {
|
|
49
|
-
console.log('dsh-tui-pi: ready — launch with `dsh-tui-pi` (short: `dst`).')
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.log(`dsh-tui-pi: setup skipped (${error?.message ?? error}) — it will run on first launch.`)
|
|
53
|
-
}
|
|
54
|
-
process.exit(0)
|