dsh-config-manager 0.9.0 → 0.10.0

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.
Files changed (150) hide show
  1. package/lib/adapters/mcp.js +9 -2
  2. package/lib/adapters/plugins.js +65 -10
  3. package/lib/adapters/prompts.js +15 -4
  4. package/lib/adapters/test-helpers.d.ts +15 -1
  5. package/lib/adapters/test-helpers.js +11 -0
  6. package/lib/cli/help.d.ts +1 -1
  7. package/lib/cli/help.js +21 -14
  8. package/lib/cli/index.js +118 -104
  9. package/lib/cli/sessions-repair.js +58 -22
  10. package/lib/cli/web/client-script.d.ts +1 -1
  11. package/lib/cli/web/client-script.js +71 -5
  12. package/lib/cli/web/page.d.ts +9 -19
  13. package/lib/cli/web/page.js +277 -173
  14. package/lib/cli/web/routes.js +85 -25
  15. package/lib/client.d.ts +93 -27
  16. package/lib/client.js +11461 -11339
  17. package/lib/core/messages.d.ts +10 -0
  18. package/lib/core/messages.js +20 -0
  19. package/lib/core/model-tools.js +7 -1
  20. package/lib/core/patch-chain.d.ts +65 -0
  21. package/lib/core/patch-chain.js +100 -0
  22. package/lib/core/patch-document.d.ts +32 -4
  23. package/lib/core/patch-document.js +48 -17
  24. package/lib/core/patch-secret-guard.d.ts +1 -1
  25. package/lib/core/patch-secret-guard.js +1 -1
  26. package/lib/core/types.d.ts +16 -1
  27. package/lib/index.d.ts +9 -4
  28. package/lib/index.js +42 -47
  29. package/lib/routes/sync.js +6 -0
  30. package/lib/sync/autosync-scheduler.d.ts +13 -1
  31. package/lib/sync/autosync-scheduler.js +73 -17
  32. package/lib/sync/local-changes.d.ts +15 -0
  33. package/lib/sync/local-changes.js +39 -0
  34. package/lib/sync/merge-keyed.d.ts +68 -0
  35. package/lib/sync/merge-keyed.js +124 -0
  36. package/lib/sync/patch-line-identity.d.ts +19 -0
  37. package/lib/sync/patch-line-identity.js +99 -0
  38. package/lib/sync/pending-merge.d.ts +8 -1
  39. package/lib/sync/pending-merge.js +13 -5
  40. package/lib/sync/plugin-removals.d.ts +15 -15
  41. package/lib/sync/plugin-removals.js +134 -83
  42. package/lib/sync/push-skip.d.ts +55 -0
  43. package/lib/sync/push-skip.js +70 -0
  44. package/lib/sync/sync-engine.d.ts +22 -12
  45. package/lib/sync/sync-engine.js +53 -70
  46. package/lib/sync/workspace-merge.d.ts +8 -2
  47. package/lib/ui/artifact-view.d.ts +1 -1
  48. package/lib/ui/foreign-view.d.ts +14 -0
  49. package/lib/ui/foreign-view.js +34 -0
  50. package/lib/ui/i18n.d.ts +5 -0
  51. package/lib/ui/i18n.js +11 -0
  52. package/lib/ui/selection-model.d.ts +2 -2
  53. package/lib/ui/selection-model.js +7 -3
  54. package/lib/utils/async-once.d.ts +11 -0
  55. package/lib/utils/async-once.js +15 -0
  56. package/lib/utils/patch-chain-read.d.ts +51 -0
  57. package/lib/utils/patch-chain-read.js +240 -0
  58. package/package.json +2 -2
  59. package/src/adapters/mcp.ts +9 -2
  60. package/src/adapters/plugins.test.ts +115 -0
  61. package/src/adapters/plugins.ts +64 -11
  62. package/src/adapters/prompts.ts +15 -4
  63. package/src/adapters/test-helpers.ts +15 -1
  64. package/src/cli/help.ts +21 -14
  65. package/src/cli/index.ts +105 -107
  66. package/src/cli/sessions-repair.ts +55 -22
  67. package/src/cli/web/client-script.ts +71 -5
  68. package/src/cli/web/page.ts +327 -208
  69. package/src/cli/web/routes.ts +85 -25
  70. package/src/cli/web/web.test.ts +38 -0
  71. package/src/client/ConfigManagerSection.tsx +8 -4
  72. package/src/client/about/AboutPanel.tsx +2 -6
  73. package/src/client/api.ts +2 -1
  74. package/src/client/common/ContentPicker.tsx +11 -12
  75. package/src/client/common/plan-text-redaction.test.ts +2 -2
  76. package/src/client/config-manager.module.css +10 -0
  77. package/src/client/environment/EnvironmentPanel.tsx +2 -4
  78. package/src/client/environment/maintenance/DiskUsageCard.tsx +4 -5
  79. package/src/client/home/BackupScheduleCard.tsx +52 -49
  80. package/src/client/home/HomePanel.tsx +2 -2
  81. package/src/client/import/ForeignImportView.tsx +60 -3
  82. package/src/client/import/ImportWizardView.tsx +2 -1
  83. package/src/client/import/PathMappingForm.tsx +32 -5
  84. package/src/client/import/import-wizard-split.test.ts +1 -1
  85. package/src/client/library/BackupInspectView.tsx +4 -2
  86. package/src/client/library/LibraryActions.tsx +60 -12
  87. package/src/client/library/LibraryPanel.tsx +9 -10
  88. package/src/client/locales/backup.ts +5 -0
  89. package/src/client/locales/foreign.ts +2 -0
  90. package/src/client/locales/import.ts +2 -0
  91. package/src/client/locales/restore.ts +2 -0
  92. package/src/client/market/MarketImportReview.tsx +4 -4
  93. package/src/client/market/MarketPanel.tsx +20 -36
  94. package/src/client/market/MyConfigsView.tsx +3 -10
  95. package/src/client/recovery/RecoveryPanel.tsx +4 -6
  96. package/src/client/recovery/RollbackCard.tsx +74 -59
  97. package/src/client/recovery/rollback-enabled.ts +29 -0
  98. package/src/client/recovery/use-recovery-write.ts +5 -0
  99. package/src/client/sync/AutosyncCard.tsx +3 -1
  100. package/src/client/sync/MergePreviewView.tsx +2 -2
  101. package/src/client/sync/PushPreviewCard.tsx +2 -1
  102. package/src/client/sync/SyncConfirmView.tsx +127 -130
  103. package/src/client/sync/SyncLogList.tsx +14 -10
  104. package/src/client/sync/SyncPanel.tsx +37 -28
  105. package/src/client/sync/SyncSettingsDialog.tsx +10 -21
  106. package/src/client/sync/history-model.ts +2 -0
  107. package/src/client/sync/sync-api.ts +1 -1
  108. package/src/client/sync/sync-locales.ts +8 -0
  109. package/src/client/sync/sync-push-preview.test.ts +9 -0
  110. package/src/client/sync/sync-view.ts +34 -0
  111. package/src/core/messages.ts +20 -0
  112. package/src/core/model-tools.ts +7 -1
  113. package/src/core/patch-chain.test.ts +83 -0
  114. package/src/core/patch-chain.ts +150 -0
  115. package/src/core/patch-document.test.ts +48 -1
  116. package/src/core/patch-document.ts +66 -15
  117. package/src/core/patch-layers.test.ts +1 -1
  118. package/src/core/patch-secret-guard.ts +1 -1
  119. package/src/core/smoke.test.ts +2 -1
  120. package/src/core/types.ts +16 -1
  121. package/src/index.facade.test.ts +186 -6
  122. package/src/index.ts +53 -47
  123. package/src/routes/sync.ts +6 -0
  124. package/src/security/security.test.ts +1 -1
  125. package/src/sync/autosync-scheduler.test.ts +98 -0
  126. package/src/sync/autosync-scheduler.ts +78 -17
  127. package/src/sync/local-changes.ts +40 -0
  128. package/src/sync/merge-keyed.test.ts +167 -0
  129. package/src/sync/merge-keyed.ts +160 -0
  130. package/src/sync/messages.ts +1 -0
  131. package/src/sync/patch-line-identity.test.ts +73 -0
  132. package/src/sync/patch-line-identity.ts +105 -0
  133. package/src/sync/pending-merge.test.ts +41 -0
  134. package/src/sync/pending-merge.ts +13 -5
  135. package/src/sync/plugin-removals.test.ts +199 -39
  136. package/src/sync/plugin-removals.ts +150 -64
  137. package/src/sync/push-skip.test.ts +326 -0
  138. package/src/sync/push-skip.ts +102 -0
  139. package/src/sync/sync-engine.ts +68 -67
  140. package/src/sync/workspace-merge.ts +9 -2
  141. package/src/ui/artifact-view.ts +1 -1
  142. package/src/ui/foreign-view.test.ts +49 -0
  143. package/src/ui/foreign-view.ts +47 -0
  144. package/src/ui/i18n.ts +11 -0
  145. package/src/ui/selection-model.test.ts +14 -0
  146. package/src/ui/selection-model.ts +7 -4
  147. package/src/utils/async-once.ts +14 -0
  148. package/src/utils/patch-chain-read.test.ts +171 -0
  149. package/src/utils/patch-chain-read.ts +259 -0
  150. package/src/utils/patch-yaml.test.ts +8 -2
@@ -50,6 +50,41 @@ export const CONSOLE_SCRIPT = `(function () {
50
50
  node = node.parentNode;
51
51
  }
52
52
  });
53
+ function copyText(text, btn) {
54
+ var done = function () {
55
+ var orig = btn.getAttribute('data-dcm-orig') || btn.textContent || '复制';
56
+ if (!btn.getAttribute('data-dcm-orig')) btn.setAttribute('data-dcm-orig', orig);
57
+ btn.setAttribute('data-copied', '1');
58
+ btn.textContent = '已复制 ✓';
59
+ if (typeof window.setTimeout === 'function') {
60
+ window.setTimeout(function () {
61
+ btn.removeAttribute('data-copied');
62
+ btn.textContent = orig;
63
+ }, 1200);
64
+ }
65
+ };
66
+ if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
67
+ navigator.clipboard.writeText(text).then(done, function () { fallbackCopy(text, done); });
68
+ return;
69
+ }
70
+ fallbackCopy(text, done);
71
+ }
72
+ function fallbackCopy(text, done) {
73
+ try {
74
+ var ta = document.createElement('textarea');
75
+ ta.value = text;
76
+ ta.setAttribute('readonly', '');
77
+ ta.style.position = 'fixed';
78
+ ta.style.opacity = '0';
79
+ document.body.appendChild(ta);
80
+ ta.select();
81
+ document.execCommand('copy');
82
+ document.body.removeChild(ta);
83
+ done();
84
+ } catch (e) {
85
+ // 剪贴板不可用时静默退出,不打断页面交互
86
+ }
87
+ }
53
88
  // 离线救急台的**唯一**客户端脚本:只做两件事 —— ① 会话内状态恢复(sessionStorage,dcm: 前缀)
54
89
  // ② 把确认表单从 details 升级成原生 dialog 元素。禁用 JS 时两者都不参与,页面回落到纯 HTML。
55
90
  var PREFIX = 'dcm:';
@@ -113,12 +148,30 @@ export const CONSOLE_SCRIPT = `(function () {
113
148
  }
114
149
  function onField(event) {
115
150
  var el = event.target;
151
+ if (el && el.required && typeof el.setAttribute === 'function') {
152
+ el.setAttribute('aria-invalid', String(el.value || '').trim() === '' ? 'true' : 'false');
153
+ }
116
154
  if (!persistable(el)) return;
117
155
  if (el.type === 'checkbox' || el.type === 'radio') writeJson(fieldKey(el), { checked: el.checked === true });
118
156
  else writeJson(fieldKey(el), { value: String(el.value) });
119
157
  }
120
158
  document.addEventListener('change', onField, true);
121
159
  document.addEventListener('input', onField, true);
160
+ document.addEventListener('submit', function (event) {
161
+ var form = event.target;
162
+ if (!form || form.tagName !== 'FORM') return;
163
+ form.setAttribute('aria-busy', 'true');
164
+ if (typeof form.querySelector !== 'function') return;
165
+ var btn = form.querySelector('button[type="submit"]');
166
+ if (!btn || btn.disabled) return;
167
+ btn.disabled = true;
168
+ var spin = document.createElement('span');
169
+ spin.className = 'btnSpinner';
170
+ spin.setAttribute('aria-hidden', 'true');
171
+ btn.textContent = '';
172
+ btn.appendChild(spin);
173
+ btn.appendChild(document.createTextNode('执行中…'));
174
+ }, true);
122
175
  function detailsState() {
123
176
  var list = document.querySelectorAll('details[data-dcm-persist]');
124
177
  for (var i = 0; i < list.length; i++) {
@@ -216,14 +269,27 @@ export const CONSOLE_SCRIPT = `(function () {
216
269
  for (var i = 0; i < list.length; i++) enhanceOne(list[i]);
217
270
  }
218
271
  document.addEventListener('click', function (event) {
272
+ var menus = document.querySelectorAll('details[data-dcm-nav-group][open]');
273
+ for (var m = 0; m < menus.length; m++) {
274
+ var menu = menus[m];
275
+ if (typeof menu.contains === 'function' && (!menu.contains(event.target) || (event.target && event.target.tagName === 'A'))) {
276
+ menu.open = false;
277
+ }
278
+ }
219
279
  var node = event.target;
220
280
  while (node !== null && node !== document) {
221
- if (typeof node.hasAttribute === 'function' && node.hasAttribute('data-dcm-back')) {
222
- if (window.history.length > 1) {
223
- event.preventDefault();
224
- window.history.back();
281
+ if (typeof node.hasAttribute === 'function') {
282
+ if (node.hasAttribute('data-dcm-copy')) {
283
+ copyText(String(node.getAttribute('data-dcm-copy') || ''), node);
284
+ return;
285
+ }
286
+ if (node.hasAttribute('data-dcm-back')) {
287
+ if (window.history.length > 1) {
288
+ event.preventDefault();
289
+ window.history.back();
290
+ }
291
+ return;
225
292
  }
226
- return;
227
293
  }
228
294
  node = node.parentNode;
229
295
  }
@@ -11,29 +11,23 @@ export interface PageChrome {
11
11
  }
12
12
  export declare function esc(value: string): string;
13
13
  /**
14
- * **只转义、不脱敏**的展示出口:唯一用途是救急台**有意**回传给终端用户的「能力 URL」
15
- * (启动器从子进程日志抓到的带 token 的认证 URL)。
16
- *
17
- * 为什么必须与 esc() 分开(cli-F1):esc() 先过安全侧 redact(),而 redact 的 URL_QUERY_RE
18
- * 会把 `?token=…` 的值抹成 ***REDACTED*** —— 那正是认证 URL 的形态,于是页面给出一条必然
19
- * 401 的死链(/profiles 的「打开实例」入口 + 启动结果页)。这些 URL 与终端里打印的 bootstrap
20
- * URL 同一性质:只给拿到会话 cookie 的人,本来就该原样可见。
21
- * 纪律:**只允许**用于本层自己签发/抓取的能力 URL;其余一切文本仍走 esc()。
14
+ * **只转义、不脱敏**的展示出口:唯一用途是救急台**有意**回传给终端用户的「能力 URL」。
22
15
  */
23
16
  export declare function escCapability(value: string): string;
24
17
  export declare function formatBytes(bytes: number): string;
25
18
  type Cell = string | {
26
19
  html: string;
27
20
  };
21
+ export type NavGroupId = 'status' | 'rescue' | 'inspect';
28
22
  /**
29
- * 救急台的**页面导航表(唯一事实源)**:头部导航与 404 / 405 / 错误页的「可用页面」清单
30
- * 全部由它派生 —— 此前那三处各写一份、且与现实不一致(把 JSON 自述的 `/healthz` 说成页面,
31
- * 又漏掉 `/restore` / `/export`)。`/healthz` 是 JSON 自述、不是页面,故不在表内。
23
+ * 救急台的**页面导航表(唯一事实源)**:处境分组导航与 404 / 405 / 错误页的「可用页面」清单
24
+ * 全部由它派生 —— 绝不另建第二份页面清单。
32
25
  */
33
26
  export declare const CONSOLE_PAGE_NAV: ReadonlyArray<{
34
27
  key: PageChrome['active'];
35
28
  href: string;
36
29
  label: string;
30
+ groups: readonly NavGroupId[];
37
31
  }>;
38
32
  /** 「可用页面」提示行(404 / 405 / 错误页共用这一份派生结果,不再各写一份)。 */
39
33
  export declare function consolePagesHint(): string;
@@ -98,18 +92,12 @@ export interface ActionCard {
98
92
  id: string;
99
93
  title: string;
100
94
  description: string;
95
+ /** 什么情况下点它(首页建议卡必现一行) */
96
+ when?: string;
101
97
  href: string;
102
98
  disabled: boolean;
103
99
  disabledReason?: string;
104
100
  }
105
- /**
106
- * 「确认后执行」表单:放宽的是**展示层**,不是提交语义。
107
- *
108
- * 服务端直出的是 `<details open>` + 原始 `<form method="post">`(一次性 token、副作用说明、勾选项
109
- * 全都在表单里):禁用 JS 时它就是今天那份可直接提交的纯 HTML。有 JS 且浏览器支持 showModal 时,
110
- * 客户端脚本才把 details 升级成原生 `<dialog>` —— 提交仍然 POST 到同一个 action、带同一个 token,
111
- * token 校验顺序(token → 安全门)在服务端一字未改。客户端校验/弹窗只算 UX,不构成任何边界。
112
- */
113
101
  export declare function renderConfirmForm(options: {
114
102
  action: string;
115
103
  token: string;
@@ -117,6 +105,8 @@ export declare function renderConfirmForm(options: {
117
105
  consequence: string;
118
106
  submitLabel: string;
119
107
  danger: boolean;
108
+ /** 列表页同屏多个非危险按钮时,除首个外设 true 退为中性次要样式,保单屏唯一主色 */
109
+ neutral?: boolean;
120
110
  checklist?: ReadonlyArray<{
121
111
  name: string;
122
112
  label: string;