dsh-harness-toolbox 1.6.4 → 1.8.8

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/index.js CHANGED
@@ -6,14 +6,17 @@ import { attachContextMeter, compactionWindowNote, contextReportText, readContex
6
6
  import { attachCompactQueue, COMPACT_TOOL_NAME, resolveCompaction } from './src/manual-compact.js'
7
7
  import { readSettings, writeSettings, normalizeRepoName } from './src/store.js'
8
8
  import { MAX_RULES_CHARS, readRules, rulesPromptBlock, saveRules } from './src/rules.js'
9
- import { beginGithubLogin, cancelGithubLogin, ghAuthStatus, ghStatus, githubLoginStatus, listRepos, prependGhPath, resolveGh, startGhDownload } from './src/gh.js'
9
+ import { beginGithubLogin, cancelGithubLogin, ghAuthStatus, ghDownloadRunning, ghStatus, githubLoginStatus, listRepos, prependGhPath, resolveGh, startGhDownload } from './src/gh.js'
10
10
  import { networkReport, detectProxy } from './src/publish.js'
11
- import { ffmpegStatus, prependFfmpegPath, startFfmpegDownload } from './src/ffmpeg.js'
12
- import { pushFlow, pushReportText, resolvePushCwd } from './src/push-flow.js'
13
- import { dirname } from 'node:path'
11
+ import { ffmpegDownloadRunning, ffmpegStatus, prependFfmpegPath, startFfmpegDownload } from './src/ffmpeg.js'
12
+ import { COMPONENT_IDS, componentBinDirs, componentDownloadRunning, componentStatus, prependComponentPath, startComponentDownload } from './src/components.js'
13
+ import { COMPONENT_ORDER, componentRows } from './src/component-rows.js'
14
+ import { migrateTools, parseToolsPath, resolveToolsPath, toolsStatus } from './src/tools-path.js'
15
+ import { pushFlow, pushReportText, resolvePushCwd, sessionTarget } from './src/push-flow.js'
16
+ import { dirname, join } from 'node:path'
14
17
  import { fileURLToPath } from 'node:url'
15
18
  import { formatRouteLines, parseRouteLines } from './src/routes.js'
16
- import { errorStatus, guard, queryParam, readBody, sendJson } from './src/http.js'
19
+ import { errorStatus, guard, httpError, queryParam, readBody, sendJson } from './src/http.js'
17
20
 
18
21
  export const name = 'compression-tiers'
19
22
  export const inject = ['tools', 'systemPrompt']
@@ -37,6 +40,57 @@ function githubSettings() {
37
40
  return readSettings(homeDir()).settings.github
38
41
  }
39
42
 
43
+ /** The one download root both managed tools install below. */
44
+ function toolsRoot() {
45
+ return resolveToolsPath(homeDir(), readSettings(homeDir()).settings)
46
+ }
47
+
48
+ /** Whether any managed install is in flight (migration refuses to move one). */
49
+ function toolsRunning(root = toolsRoot()) {
50
+ const running = { gh: ghDownloadRunning(root), ffmpeg: ffmpegDownloadRunning(root) }
51
+ for (const id of COMPONENT_IDS) running[id] = componentDownloadRunning(root, id)
52
+ return running
53
+ }
54
+
55
+ /** Every directory the managed components put on PATH below one root. */
56
+ function toolPathDirs(root) {
57
+ const dirs = [join(root, 'gh', 'bin'), join(root, 'ffmpeg', 'bin')]
58
+ for (const id of COMPONENT_IDS) dirs.push(...componentBinDirs(root, id))
59
+ return dirs
60
+ }
61
+
62
+ /**
63
+ * After the managed tools move, the PATH entries for the old directories must go
64
+ * as well; otherwise the process keeps resolving the binaries that are no
65
+ * longer there.
66
+ */
67
+ function repointToolsPath(previous, target) {
68
+ const separator = process.platform === 'win32' ? ';' : ':'
69
+ const fold = (dir) => (process.platform === 'win32' ? dir.toLowerCase() : dir)
70
+ const stale = new Set(toolPathDirs(previous).map(fold))
71
+ process.env.PATH = String(process.env.PATH || '')
72
+ .split(separator)
73
+ .filter((dir) => dir && !stale.has(fold(dir)))
74
+ .join(separator)
75
+ try {
76
+ prependGhPath(target)
77
+ } catch (error) {
78
+ trace('gh:path-failed', error instanceof Error ? error.message : String(error))
79
+ }
80
+ try {
81
+ prependFfmpegPath(target)
82
+ } catch (error) {
83
+ trace('ffmpeg:path-failed', error instanceof Error ? error.message : String(error))
84
+ }
85
+ for (const id of COMPONENT_IDS) {
86
+ try {
87
+ prependComponentPath(target, id)
88
+ } catch (error) {
89
+ trace(`${id}:path-failed`, error instanceof Error ? error.message : String(error))
90
+ }
91
+ }
92
+ }
93
+
40
94
  /** The directory the calling session lives in; empty when unavailable. */
41
95
  function sessionDirectory(ctx, exec) {
42
96
  const session = exec && exec.agent ? exec.agent.session : undefined
@@ -60,7 +114,8 @@ function sessionIdOf(exec) {
60
114
  /** The repository this session publishes to, or null. */
61
115
  function sessionRepoBinding(sessionId, settings = readSettings(homeDir()).settings) {
62
116
  if (!sessionId) return null
63
- return settings.sessionRepos[sessionId] || null
117
+ const repos = settings && settings.sessionRepos ? settings.sessionRepos : {}
118
+ return repos[sessionId] || null
64
119
  }
65
120
 
66
121
  function trace(stage, detail) { // Keep the console quiet: only failures, skipped work and adoption matter.
@@ -185,7 +240,7 @@ function statePayload(ctx) {
185
240
  modelRoutes: state.settings.modelRoutes,
186
241
  routeLines: formatRouteLines(state.settings.modelRoutes),
187
242
  lastCompact: state.settings.lastCompact,
188
- paths: { settings: state.paths.settings },
243
+ paths: { settings: state.paths.settings, tools: resolveToolsPath(homeDir(), state.settings) },
189
244
  github: state.settings.github,
190
245
  ...engineSummary(ctx),
191
246
  }
@@ -204,6 +259,41 @@ function rulesPayload(rules) {
204
259
  }
205
260
  }
206
261
 
262
+ /**
263
+ * One row per managed component, in the order the settings page renders them.
264
+ * The mapping lives in `src/component-rows.js` so the page contract is testable
265
+ * without the host services this file needs.
266
+ */
267
+ const MANAGED_COMPONENTS = new Set(COMPONENT_ORDER)
268
+
269
+ /** The four managed components plus the shared download root, for one load. */
270
+ async function componentsPayload(root) {
271
+ const [ffmpeg, git, python] = await Promise.all([
272
+ ffmpegStatus(root),
273
+ componentStatus(root, 'git'),
274
+ componentStatus(root, 'python'),
275
+ ])
276
+ return {
277
+ root: toolsStatus(homeDir(), readSettings(homeDir()).settings, { running: toolsRunning(root) }),
278
+ components: componentRows(root, { gh: ghStatus(root), git, ffmpeg, python }),
279
+ }
280
+ }
281
+
282
+ async function startManagedDownload(root, id) {
283
+ if (!MANAGED_COMPONENTS.has(id)) {
284
+ throw httpError(400, `unknown component: ${id || '(empty)'}; pass one of ${COMPONENT_ORDER.join(', ')}`)
285
+ }
286
+ if (id === 'gh') {
287
+ startGhDownload(root)
288
+ return
289
+ }
290
+ if (id === 'ffmpeg') {
291
+ startFfmpegDownload(root)
292
+ return
293
+ }
294
+ await startComponentDownload(root, id)
295
+ }
296
+
207
297
  export function apply(ctx) {
208
298
  const compactQueue = attachCompactQueue(ctx, { trace, onFinished: recordCompact })
209
299
  ctx.effect(() => compactQueue.dispose, 'compression-tiers: compact queue')
@@ -215,17 +305,26 @@ export function apply(ctx) {
215
305
  // The official change-request bundle shells out to `gh`; a managed copy goes
216
306
  // first on PATH so the bundle finds the version this page installed.
217
307
  try {
218
- prependGhPath(homeDir())
308
+ prependGhPath(toolsRoot())
219
309
  } catch (error) {
220
310
  trace('gh:path-failed', error instanceof Error ? error.message : String(error))
221
311
  }
222
312
  // ffmpeg/ffprobe: the managed copy, when present, also goes first on PATH so
223
313
  // video tooling in this process finds the version this page installed.
224
314
  try {
225
- if (prependFfmpegPath(homeDir())) trace('ffmpeg:path-ready', '')
315
+ if (prependFfmpegPath(toolsRoot())) trace('ffmpeg:path-ready', '')
226
316
  } catch (error) {
227
317
  trace('ffmpeg:path-failed', error instanceof Error ? error.message : String(error))
228
318
  }
319
+ // git and Python behave the same way: a managed copy, when one was installed
320
+ // from the settings page, wins over whatever PATH already carries.
321
+ for (const id of COMPONENT_IDS) {
322
+ try {
323
+ if (prependComponentPath(toolsRoot(), id)) trace(`${id}:path-ready`, '')
324
+ } catch (error) {
325
+ trace(`${id}:path-failed`, error instanceof Error ? error.message : String(error))
326
+ }
327
+ }
229
328
 
230
329
  ctx.effect(() => ctx.systemPrompt.section({
231
330
  name: 'compression-tiers',
@@ -358,10 +457,13 @@ export function apply(ctx) {
358
457
  },
359
458
  output: toolOutput(),
360
459
  async execute(args, exec) {
361
- const settings = githubSettings()
460
+ // `sessionRepos` lives on the plugin settings; `githubSettings()` only
461
+ // returns the `github` block, so indexing it for a session id throws.
462
+ const stored = readSettings(homeDir()).settings
463
+ const settings = stored.github
362
464
  const sessionId = sessionIdOf(exec)
363
- const bound = sessionId ? settings.sessionRepos[sessionId] || null : null
364
- const target = bound ? `https://github.com/${bound}.git` : ''
465
+ const bound = sessionId ? sessionRepoBinding(sessionId, stored) : null
466
+ const target = sessionTarget(stored, sessionId)
365
467
  const explicit = typeof args.repo === 'string' ? args.repo.trim() : ''
366
468
  const resolved = resolvePushCwd({ explicit, sessionDirectory: sessionDirectory(ctx, exec) })
367
469
  if (!resolved.cwd) {
@@ -465,18 +567,18 @@ export function apply(ctx) {
465
567
  if (guard(child, req, res)) return
466
568
  try {
467
569
  if (req.method === 'GET') {
468
- sendJson(res, 200, { ok: true, gh: ghStatus(homeDir()), login: githubLoginStatus() })
570
+ sendJson(res, 200, { ok: true, gh: ghStatus(toolsRoot()), login: githubLoginStatus() })
469
571
  return
470
572
  }
471
573
  if (req.method === 'POST') {
472
574
  const body = await readBody(req)
473
575
  const action = typeof body.action === 'string' ? body.action : ''
474
576
  if (action === 'download') {
475
- sendJson(res, 202, { ok: true, gh: startGhDownload(homeDir()) })
577
+ sendJson(res, 202, { ok: true, gh: startGhDownload(toolsRoot()) })
476
578
  return
477
579
  }
478
580
  if (action === 'login') {
479
- sendJson(res, 200, { ok: true, ...beginGithubLogin(homeDir()) })
581
+ sendJson(res, 200, { ok: true, ...beginGithubLogin(toolsRoot()) })
480
582
  return
481
583
  }
482
584
  if (action === 'cancel') {
@@ -499,7 +601,7 @@ export function apply(ctx) {
499
601
  return
500
602
  }
501
603
  try {
502
- sendJson(res, 200, { ok: true, auth: await ghAuthStatus(homeDir()) })
604
+ sendJson(res, 200, { ok: true, auth: await ghAuthStatus(toolsRoot()) })
503
605
  } catch (error) {
504
606
  sendJson(res, errorStatus(error), { error: error instanceof Error ? error.message : String(error) })
505
607
  }
@@ -533,7 +635,7 @@ export function apply(ctx) {
533
635
  try {
534
636
  const settings = githubSettings()
535
637
  const detected = await detectProxy({ cwd: PLUGIN_ROOT, override: settings.proxy })
536
- const listed = await listRepos(homeDir(), { proxy: detected.proxy })
638
+ const listed = await listRepos(toolsRoot(), { proxy: detected.proxy })
537
639
  sendJson(res, 200, { ok: listed.ok, repos: listed.repos, error: listed.error, detail: listed.detail })
538
640
  } catch (error) {
539
641
  sendJson(res, errorStatus(error), { error: error instanceof Error ? error.message : String(error) })
@@ -584,19 +686,68 @@ export function apply(ctx) {
584
686
  }
585
687
  }, 'github binding route')
586
688
 
689
+ // Shared download location: one root for both managed tools, and the one
690
+ // place that moves them. A running download blocks the move (409), and a
691
+ // component already sitting at the target counts as migrated so a failed
692
+ // run can be retried.
693
+ register('/compression-tiers/api/tools', async (req, res) => {
694
+ if (guard(child, req, res)) return
695
+ try {
696
+ const status = () => toolsStatus(homeDir(), readSettings(homeDir()).settings, { running: toolsRunning() })
697
+ if (req.method === 'GET') {
698
+ sendJson(res, 200, { ok: true, ...status() })
699
+ return
700
+ }
701
+ if (req.method === 'POST') {
702
+ const body = await readBody(req)
703
+ const action = typeof body.action === 'string' ? body.action : ''
704
+ if (action !== 'migrate') {
705
+ sendJson(res, 400, { error: 'unknown action: migrate' })
706
+ return
707
+ }
708
+ const settings = readSettings(homeDir()).settings
709
+ let target
710
+ try {
711
+ target = parseToolsPath(body.path)
712
+ } catch (error) {
713
+ sendJson(res, 400, { error: error instanceof Error ? error.message : String(error) })
714
+ return
715
+ }
716
+ let report
717
+ try {
718
+ report = migrateTools({ home: homeDir(), settings, target, running: toolsRunning() })
719
+ } catch (error) {
720
+ sendJson(res, errorStatus(error, 500), {
721
+ error: error instanceof Error ? error.message : String(error),
722
+ report: error && error.report ? error.report : null,
723
+ })
724
+ return
725
+ }
726
+ writeSettings(homeDir(), { settings: { toolsPath: target } })
727
+ // PATH still points at the old directories; move it with the files.
728
+ repointToolsPath(report.from, report.to)
729
+ sendJson(res, 200, { ok: true, ...status(), report })
730
+ return
731
+ }
732
+ sendJson(res, 405, { error: 'GET or POST' })
733
+ } catch (error) {
734
+ sendJson(res, errorStatus(error), { error: error instanceof Error ? error.message : String(error) })
735
+ }
736
+ }, 'tools path route')
737
+
587
738
  // Managed ffmpeg + ffprobe: detection, resumable download, atomic install.
588
739
  register('/compression-tiers/api/ffmpeg', async (req, res) => {
589
740
  if (guard(child, req, res)) return
590
741
  try {
591
742
  if (req.method === 'GET') {
592
- sendJson(res, 200, { ok: true, ...(await ffmpegStatus(homeDir())) })
743
+ sendJson(res, 200, { ok: true, ...(await ffmpegStatus(toolsRoot())) })
593
744
  return
594
745
  }
595
746
  if (req.method === 'POST') {
596
747
  const body = await readBody(req)
597
748
  const action = typeof body.action === 'string' ? body.action : ''
598
749
  if (action === 'download') {
599
- sendJson(res, 202, { ok: true, ...(await startFfmpegDownload(homeDir())) })
750
+ sendJson(res, 202, { ok: true, ...(await startFfmpegDownload(toolsRoot())) })
600
751
  return
601
752
  }
602
753
  sendJson(res, 400, { error: 'unknown action: download' })
@@ -608,6 +759,34 @@ export function apply(ctx) {
608
759
  }
609
760
  }, 'ffmpeg route')
610
761
 
762
+ // Component management: every managed binary in one place (GitHub CLI, git,
763
+ // ffmpeg, Python) plus the shared download root they all install below. One
764
+ // GET feeds the whole panel and one POST starts any of the four installs.
765
+ register('/compression-tiers/api/components', async (req, res) => {
766
+ if (guard(child, req, res)) return
767
+ try {
768
+ const root = toolsRoot()
769
+ if (req.method === 'GET') {
770
+ sendJson(res, 200, { ok: true, ...(await componentsPayload(root)) })
771
+ return
772
+ }
773
+ if (req.method === 'POST') {
774
+ const body = await readBody(req)
775
+ const action = typeof body.action === 'string' ? body.action : ''
776
+ if (action !== 'download') {
777
+ sendJson(res, 400, { error: 'unknown action: download' })
778
+ return
779
+ }
780
+ await startManagedDownload(root, typeof body.id === 'string' ? body.id : '')
781
+ sendJson(res, 202, { ok: true, ...(await componentsPayload(root)) })
782
+ return
783
+ }
784
+ sendJson(res, 405, { error: 'GET or POST' })
785
+ } catch (error) {
786
+ sendJson(res, errorStatus(error), { error: error instanceof Error ? error.message : String(error) })
787
+ }
788
+ }, 'components route')
789
+
611
790
  })
612
791
 
613
792
  // Presets mount after this plugin in the official composition and live in
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Context compression tiers",
4
- "description": "Adds a Context compression page under Settings with five automatic compaction tiers (gentle, light, standard, aggressive, max). Picking a tier pushes its thresholdRatio and retainRatio into every mounted agent preset compaction engine immediately, so no restart is needed, and stores the choice in <DSH home>/compression-tiers/settings.json. The plugin also adds four agent tools: compression_tiers reads or changes the tier and accepts optional per-route headroom overrides; compression_context reports live occupancy, the tier threshold and the room left; compression_compact queues a proactive compaction that runs after the turn and resumes the conversation by itself; github_push publishes the current work — the session working directory by default — after a network probe and a secret scan, with a 60-second push deadline and a failure family plus whatever is still local when it fails. A [context] line at the conversation tail reports the same occupancy. Every tier keeps automatic pressure compaction on, and /compact remains available to the human. The lower half of the page also edits the global rules: it reads and atomically writes the official instruction file <DSH home>/AGENTS.md (the official dsh-agent-instructions plugin injects it into later sessions), and the system prompt carries the newest 2,000-character clip; agents get no tool to rewrite that file, only a save on the page writes it. The page also manages GitHub CLI: it detects a gh on PATH, downloads a managed pinned gh 2.76.2 copy (resumable, atomic install, rollback on failure), and runs the gh auth login --web device flow for the official change-request panel; the credential stays in gh's own store and the plugin never reads it. The page also manages the video tools: it detects ffmpeg and ffprobe on PATH and can download the managed build from gyan.dev (about 110 MB, resumable, probed before an atomic swap), which wins over PATH and is put first on this process's PATH. A repository selector beside the session title lists the account's repositories with gh repo list and binds one to the session; github_push then publishes to https://github.com/owner/name.git by default (it only changes the push target, never clones or edits the workspace), and the binding lives in sessionRepos in settings.json. Limitations: the tiers are designed for windows of at least 256k tokens (the official 65,536-token headroom caps smaller windows); the plugin updates preset-isolated engines and leaves the host-plane row alone; remove any other plugin that manages the same compaction engines or the two will fight over the policy; the 1.4.x sidebar repository panel is gone, and several repositories are published from each session through github_push; changing a tier updates the engines live, but a browser reload may be needed to see the page again.",
4
+ "description": "Adds a Context compression page under Settings with five automatic compaction tiers (gentle, light, standard, aggressive, max). Picking a tier pushes its thresholdRatio and retainRatio into every mounted agent preset compaction engine immediately, so no restart is needed, and stores the choice in <DSH home>/compression-tiers/settings.json. The plugin also adds four agent tools: compression_tiers reads or changes the tier and accepts optional per-route headroom overrides; compression_context reports live occupancy, the tier threshold and the room left; compression_compact queues a proactive compaction that runs after the turn and resumes the conversation by itself; github_push publishes the current work — the session working directory by default — after a network probe and a secret scan, with a 60-second push deadline and a failure family plus whatever is still local when it fails. A [context] line at the conversation tail reports the same occupancy. Every tier keeps automatic pressure compaction on, and /compact remains available to the human. The lower half of the page also edits the global rules: it reads and atomically writes the official instruction file <DSH home>/AGENTS.md (the official dsh-agent-instructions plugin injects it into later sessions), and the system prompt carries the newest 2,000-character clip; agents get no tool to rewrite that file, only a save on the page writes it. The page's Components panel manages GitHub CLI: it detects a gh on PATH and downloads a managed pinned gh 2.76.2 copy (resumable, atomic install, rollback on failure); a separate GitHub sign-in panel runs the gh auth login --web device flow for the official change-request panel, and the credential stays in gh's own store, which the plugin never reads. The Components panel keeps four managed components in one place: GitHub CLI 2.76.2, git 2.56.1 (MinGit), ffmpeg and ffprobe (the gyan.dev release build) and Python 3.11.18 (python-build-standalone). Each row detects the PATH copy and can download the managed build (unpacked into a staging directory, probed, then swapped in as a whole tree with rollback on failure); the managed copy wins and goes first on this process's PATH. All four share one configurable download root (default <DSH home>/compression-tiers) that the same panel can move as a whole. A repository selector beside the session title lists the account's repositories with gh repo list and binds one to the session; github_push then publishes to https://github.com/owner/name.git by default (it only changes the push target, never clones or edits the workspace), and the binding lives in sessionRepos in settings.json. Limitations: the tiers are designed for windows of at least 256k tokens (the official 65,536-token headroom caps smaller windows); the plugin updates preset-isolated engines and leaves the host-plane row alone; remove any other plugin that manages the same compaction engines or the two will fight over the policy; the 1.4.x sidebar repository panel is gone, and several repositories are published from each session through github_push; changing a tier updates the engines live, but a browser reload may be needed to see the page again.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "上下文压缩分档",
4
- "description": "在「设置 → 上下文压缩」里提供五档自动压缩策略(极轻、轻量、标准、积极、最大)。选中档位后立即把 thresholdRatio / retainRatio 写入每个已挂载的 Agent 预设压缩引擎,无需重启;选择保存在 <DSH home>/compression-tiers/settings.json。插件还提供四个智能体工具:compression_tiers 读取或切换档位,并接受可选的按路由 headroom 覆盖;compression_context 返回实时占用、本档阈值与剩余空间;compression_compact 排队一次主动压缩,本轮结束后执行并自动继续;github_push 发布当前工作区——默认取本会话的工作目录,先做网络体检与密钥扫描,再带 60 秒超时推送,失败时给出分类与仍在本地的东西。对话尾部的 [context] 行会报告同样的占用信息。每档都保留自动压力压缩,人类仍可使用 /compact。设置页下半部分还能编辑全局规则:直接读写官方指令文件 <DSH home>/AGENTS.md(官方 dsh-agent-instructions 会在之后的会话里注入它),保存是原子写入,系统提示里另带最新 2000 字符的摘要;智能体没有改写该文件的工具,只有你在设置页保存才会写入。设置页还管理 GitHub CLI:识别系统 PATH、下载固定版本 gh 2.76.2 的托管副本(断点续传、原子安装、失败回滚),并用 gh auth login --web 的设备码流程登录,供官方变更请求面板使用;凭据存在 gh 自己的存储里,插件不读取。设置页还管理音视频工具:检测系统 PATH 里的 ffmpeg / ffprobe,并可从 gyan.dev 下载托管版(约 110 MB,断点续传,解压后先自检再原子替换),托管版优先并插到本进程 PATH 最前。会话标题旁有一个在线仓库选择器:用 gh repo list 列出账号可写仓库,为当前会话绑定一个;绑定后 github_push 默认推到 https://github.com/owner/name.git(只改推送目标,不克隆也不改工作区),绑定保存在 settings.json 的 sessionRepos 里。限制:五档按 ≥256k tokens 窗口设计(官方 65,536 输出余量会限制更小的窗口);插件只更新预设隔离域里的引擎,不改宿主平面上的那一行;如果同时安装其他管理同一批压缩引擎或同名职责的插件,两者会互相覆盖策略;1.4.x 的左侧栏仓库面板已删除,多仓库由各会话里的 github_push 负责;切换档位后引擎立即生效,但设置页可能需要刷新浏览器才能重新读取。",
4
+ "description": "在「设置 → 上下文压缩」里提供五档自动压缩策略(极轻、轻量、标准、积极、最大)。选中档位后立即把 thresholdRatio / retainRatio 写入每个已挂载的 Agent 预设压缩引擎,无需重启;选择保存在 <DSH home>/compression-tiers/settings.json。插件还提供四个智能体工具:compression_tiers 读取或切换档位,并接受可选的按路由 headroom 覆盖;compression_context 返回实时占用、本档阈值与剩余空间;compression_compact 排队一次主动压缩,本轮结束后执行并自动继续;github_push 发布当前工作区——默认取本会话的工作目录,先做网络体检与密钥扫描,再带 60 秒超时推送,失败时给出分类与仍在本地的东西。对话尾部的 [context] 行会报告同样的占用信息。每档都保留自动压力压缩,人类仍可使用 /compact。设置页下半部分还能编辑全局规则:直接读写官方指令文件 <DSH home>/AGENTS.md(官方 dsh-agent-instructions 会在之后的会话里注入它),保存是原子写入,系统提示里另带最新 2000 字符的摘要;智能体没有改写该文件的工具,只有你在设置页保存才会写入。设置页的「组件管理」栏管理 GitHub CLI:识别系统 PATH、下载固定版本 gh 2.76.2 的托管副本(断点续传、原子安装、失败回滚);另有独立的 GitHub 登录栏,用 gh auth login --web 的设备码流程登录,供官方变更请求面板使用;凭据存在 gh 自己的存储里,插件不读取。设置页的「组件管理」栏把四套托管组件放在一起:GitHub CLI 2.76.2、git 2.56.1(MinGit)、ffmpeg / ffprobe(gyan.dev 的 release 构建)与 Python 3.11.18(python-build-standalone);逐个检测系统 PATH,并可断点续传下载托管版(解压到临时目录、先自检再原子替换整棵目录,失败回滚),托管版优先并插到本进程 PATH 最前;四套组件共用一个可配置的下载根目录(默认 <DSH home>/compression-tiers),可在同一栏整体迁移。会话标题旁有一个在线仓库选择器:用 gh repo list 列出账号可写仓库,为当前会话绑定一个;绑定后 github_push 默认推到 https://github.com/owner/name.git(只改推送目标,不克隆也不改工作区),绑定保存在 settings.json 的 sessionRepos 里。限制:五档按 ≥256k tokens 窗口设计(官方 65,536 输出余量会限制更小的窗口);插件只更新预设隔离域里的引擎,不改宿主平面上的那一行;如果同时安装其他管理同一批压缩引擎或同名职责的插件,两者会互相覆盖策略;1.4.x 的左侧栏仓库面板已删除,多仓库由各会话里的 github_push 负责;切换档位后引擎立即生效,但设置页可能需要刷新浏览器才能重新读取。",
5
5
  "detail": "docs/DETAIL.zh.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "dsh-harness-toolbox",
3
- "version": "1.6.4",
3
+ "version": "1.8.8",
4
4
  "private": false,
5
5
  "type": "module",
6
- "description": "Five-tier context compression policy for official DeepSeek Harness plus a global rules editor and GitHub publishing: settings page, agent tools (compression_tiers, compression_context, compression_compact, github_push), live occupancy meter, proactive compaction, $DSH_HOME/AGENTS.md, managed gh with device-code login, a per-session online repository binding in the session header, and a resumable managed ffmpeg/ffprobe install.",
6
+ "description": "Five-tier context compression policy for official DeepSeek Harness plus a global rules editor and GitHub publishing: settings page, agent tools (compression_tiers, compression_context, compression_compact, github_push), live occupancy meter, proactive compaction, /AGENTS.md, a component manager that installs and PATH-prefixes the GitHub CLI, git, ffmpeg/ffprobe and Python below one configurable download root (whole-directory migration), GitHub device-code login, and a per-session online repository binding in the session header.",
7
7
  "license": "MIT",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -19,12 +19,12 @@
19
19
  ],
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "git+https://github.com/Homer4033/dsh-compression-tiers.git"
22
+ "url": "git+https://github.com/Homer4033/dsh-harness-toolbox.git"
23
23
  },
24
24
  "bugs": {
25
- "url": "https://github.com/Homer4033/dsh-compression-tiers/issues"
25
+ "url": "https://github.com/Homer4033/dsh-harness-toolbox/issues"
26
26
  },
27
- "homepage": "https://github.com/Homer4033/dsh-compression-tiers#readme",
27
+ "homepage": "https://github.com/Homer4033/dsh-harness-toolbox#readme",
28
28
  "main": "./index.js",
29
29
  "exports": {
30
30
  ".": "./index.js",
@@ -0,0 +1,125 @@
1
+ import { ffmpegRoot } from './ffmpeg.js'
2
+
3
+ /**
4
+ * The settings page renders every managed component the same way: one row with
5
+ * a name, a pinned version, the version actually installed, a state, a path and
6
+ * one download / one re-check button. The modules that know a component
7
+ * (`src/gh.js`, `src/ffmpeg.js`, `src/components.js`) report three different
8
+ * shapes, so this module is the single place that turns them into that row.
9
+ */
10
+
11
+ /** Render order of the component panel. */
12
+ export const COMPONENT_ORDER = ['gh', 'git', 'ffmpeg', 'python']
13
+
14
+ /**
15
+ * The shared row shape:
16
+ *
17
+ * - `state`: one of `downloading` / `installed` / `system` / `error` /
18
+ * `partial` / `missing`, the same set `src/gh.js` already used.
19
+ * - `ready`: the component can be used right now (managed or PATH copy).
20
+ * - `managed` / `system`: where the used copy comes from.
21
+ * - `path`: the binary that is actually used, for the panel's path line.
22
+ * - `tools`: the individual binaries of a multi-binary component (ffmpeg +
23
+ * ffprobe), or null.
24
+ */
25
+ export function componentRow({ id, name, version, toolVersion, state, supported, managed, system, path, percent, error, installDir, tools }) {
26
+ return {
27
+ id,
28
+ name,
29
+ version: version || null,
30
+ toolVersion: toolVersion || null,
31
+ state,
32
+ supported: supported === true,
33
+ ready: state === 'installed' || state === 'system',
34
+ managed: managed === true,
35
+ system: system === true,
36
+ path: path || null,
37
+ percent: percent ?? null,
38
+ error: error || null,
39
+ running: state === 'downloading',
40
+ installDir: installDir || null,
41
+ tools: Array.isArray(tools) && tools.length > 0 ? tools : null,
42
+ }
43
+ }
44
+
45
+ /** `ghStatus` → row. `gh` never probes `--version`, so only the pin is known. */
46
+ export function ghComponentRow(status) {
47
+ return componentRow({
48
+ id: status.id,
49
+ name: status.name,
50
+ version: status.version,
51
+ state: status.state,
52
+ supported: status.supported,
53
+ managed: status.sourceKind === 'managed',
54
+ system: status.system,
55
+ path: status.binaryPath,
56
+ percent: status.percent,
57
+ error: status.error,
58
+ installDir: status.installDir,
59
+ })
60
+ }
61
+
62
+ /** `ffmpegStatus` → row, keeping ffmpeg and ffprobe as its two binaries. */
63
+ export function ffmpegComponentRow(root, status) {
64
+ // Both binaries are always listed, found or not: the pair is what the row is
65
+ // about, and "ffprobe is missing" has to stay visible.
66
+ const tools = ['ffmpeg', 'ffprobe'].map((name) => {
67
+ const info = status[name] || null
68
+ return {
69
+ name,
70
+ path: info && info.path ? info.path : null,
71
+ version: info && info.version ? info.version : null,
72
+ managed: Boolean(info && info.managed === true),
73
+ }
74
+ })
75
+ const found = tools.filter((tool) => tool.path)
76
+ const download = status.download || {}
77
+ // `ffmpegStatus` reports `installed` / `partial` / `missing` only, so a job in
78
+ // flight or a failed one has to win over the binary state here.
79
+ const state = download.running ? 'downloading' : download.error ? 'error' : status.state
80
+ return componentRow({
81
+ id: 'ffmpeg',
82
+ name: 'ffmpeg',
83
+ toolVersion: status.version,
84
+ state,
85
+ supported: status.supported,
86
+ // The managed copies are what make this a managed install; a PATH copy is
87
+ // reported as `system` so the page offers the same forced download.
88
+ managed: tools.some((tool) => tool.managed),
89
+ system: found.length > 0 && tools.every((tool) => tool.managed !== true),
90
+ path: found[0] ? found[0].path : null,
91
+ percent: download.percent,
92
+ error: download.error,
93
+ installDir: ffmpegRoot(root),
94
+ tools,
95
+ })
96
+ }
97
+
98
+ /** `componentStatus` (git, Python) → row: it already reports the managed shape. */
99
+ export function managedComponentRow(status) {
100
+ return componentRow({
101
+ id: status.id,
102
+ name: status.name,
103
+ version: status.version,
104
+ toolVersion: status.toolVersion,
105
+ state: status.state,
106
+ supported: status.supported,
107
+ managed: status.sourceKind === 'managed',
108
+ system: status.system,
109
+ path: status.binaryPath,
110
+ percent: status.percent,
111
+ error: status.error,
112
+ installDir: status.installDir,
113
+ })
114
+ }
115
+
116
+ /** All four rows, in render order; a missing status simply drops its row. */
117
+ export function componentRows(root, statuses) {
118
+ const rows = {
119
+ gh: statuses.gh ? ghComponentRow(statuses.gh) : null,
120
+ git: statuses.git ? managedComponentRow(statuses.git) : null,
121
+ ffmpeg: statuses.ffmpeg ? ffmpegComponentRow(root, statuses.ffmpeg) : null,
122
+ python: statuses.python ? managedComponentRow(statuses.python) : null,
123
+ }
124
+ return COMPONENT_ORDER.filter((id) => rows[id]).map((id) => rows[id])
125
+ }