@dsh-workbench/shared 1.5.2-alpha.4 → 1.5.2-rc.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 (344) hide show
  1. package/dist/components/Activity.css +69 -0
  2. package/dist/components/Activity.d.ts +56 -0
  3. package/dist/components/Activity.js +47 -0
  4. package/dist/components/ApprovalDetail.css +3 -0
  5. package/dist/components/ApprovalDetail.d.ts +42 -0
  6. package/dist/components/ApprovalDetail.js +53 -0
  7. package/dist/components/ApprovalPlan.css +39 -0
  8. package/dist/components/ApprovalPlan.d.ts +27 -0
  9. package/dist/components/ApprovalPlan.js +19 -0
  10. package/dist/components/Card.css +19 -0
  11. package/dist/components/Card.d.ts +26 -0
  12. package/dist/components/Card.js +18 -0
  13. package/dist/components/CardAnchor.d.ts +21 -0
  14. package/dist/components/CardAnchor.js +19 -0
  15. package/dist/components/CardAnchor.module.css +3 -0
  16. package/dist/components/CardBoundary.d.ts +42 -0
  17. package/dist/components/CardBoundary.js +58 -0
  18. package/dist/components/CardBoundary.module.css +5 -0
  19. package/dist/components/CardHead.css +87 -0
  20. package/dist/components/CardHead.d.ts +30 -0
  21. package/dist/components/CardHead.js +27 -0
  22. package/dist/components/ChoiceGroup.css +182 -0
  23. package/dist/components/ChoiceGroup.d.ts +54 -0
  24. package/dist/components/ChoiceGroup.js +63 -0
  25. package/dist/components/ConfirmBar.css +26 -0
  26. package/dist/components/ConfirmBar.d.ts +36 -0
  27. package/dist/components/ConfirmBar.js +26 -0
  28. package/dist/components/EmptyIllustration.d.ts +12 -0
  29. package/dist/components/EmptyIllustration.js +32 -0
  30. package/dist/components/Field.css +20 -0
  31. package/dist/components/Field.d.ts +18 -0
  32. package/dist/components/Field.js +15 -0
  33. package/dist/components/Form.css +6 -0
  34. package/dist/components/Form.d.ts +22 -0
  35. package/dist/components/Form.js +60 -0
  36. package/dist/components/FormActions.css +13 -0
  37. package/dist/components/FormActions.d.ts +29 -0
  38. package/dist/components/FormActions.js +43 -0
  39. package/dist/components/FormNodes.d.ts +107 -0
  40. package/dist/components/FormNodes.js +165 -0
  41. package/dist/components/FormRows.css +107 -0
  42. package/dist/components/FormRows.d.ts +36 -0
  43. package/dist/components/FormRows.js +26 -0
  44. package/dist/components/FormTypes.d.ts +84 -0
  45. package/dist/components/FormTypes.js +1 -0
  46. package/dist/components/Link.css +22 -0
  47. package/dist/components/Link.d.ts +22 -0
  48. package/dist/components/Link.js +17 -0
  49. package/dist/components/LongTaskRow.css +171 -0
  50. package/dist/components/LongTaskRow.d.ts +94 -0
  51. package/dist/components/LongTaskRow.js +103 -0
  52. package/dist/components/Note.css +13 -0
  53. package/dist/components/Note.d.ts +20 -0
  54. package/dist/components/Note.js +14 -0
  55. package/dist/components/ResourceStates.css +114 -0
  56. package/dist/components/ResourceStates.d.ts +44 -0
  57. package/dist/components/ResourceStates.js +41 -0
  58. package/dist/components/Rows.css +42 -0
  59. package/dist/components/Rows.d.ts +28 -0
  60. package/dist/components/Rows.js +21 -0
  61. package/dist/components/SaveBar.d.ts +24 -0
  62. package/dist/components/SaveBar.js +25 -0
  63. package/dist/components/SelectField.css +182 -0
  64. package/dist/components/SelectField.d.ts +89 -0
  65. package/dist/components/SelectField.js +260 -0
  66. package/dist/components/SelectFieldNodes.d.ts +49 -0
  67. package/dist/components/SelectFieldNodes.js +43 -0
  68. package/dist/components/SettingsSection.css +25 -0
  69. package/dist/components/SettingsSection.d.ts +20 -0
  70. package/dist/components/SettingsSection.js +17 -0
  71. package/dist/components/SetupShell.d.ts +93 -0
  72. package/dist/components/SetupShell.js +64 -0
  73. package/dist/components/SetupShell.module.css +81 -0
  74. package/dist/components/Spinner.css +5 -0
  75. package/dist/components/Spinner.d.ts +15 -0
  76. package/dist/components/Spinner.js +13 -0
  77. package/dist/components/Stack.css +6 -0
  78. package/dist/components/Stack.d.ts +14 -0
  79. package/dist/components/Stack.js +10 -0
  80. package/dist/components/StateBlock.css +38 -0
  81. package/dist/components/StateBlock.d.ts +24 -0
  82. package/dist/components/StateBlock.js +22 -0
  83. package/dist/components/TextField.css +32 -0
  84. package/dist/components/TextField.d.ts +14 -0
  85. package/dist/components/TextField.js +10 -0
  86. package/dist/components/board-module.d.ts +307 -0
  87. package/dist/components/board-module.js +1 -0
  88. package/dist/components/card-view-validate.d.ts +5 -0
  89. package/dist/components/card-view-validate.js +256 -0
  90. package/dist/components/icons.d.ts +63 -0
  91. package/dist/components/icons.js +107 -0
  92. package/dist/components/layout/icon-command.d.ts +8 -0
  93. package/dist/components/layout/icon-command.js +21 -0
  94. package/dist/contract/capture.d.ts +16 -0
  95. package/dist/contract/capture.js +1 -0
  96. package/dist/contract/diagnostics.d.ts +34 -0
  97. package/dist/contract/diagnostics.js +124 -0
  98. package/dist/contract/needs.d.ts +3 -1
  99. package/dist/contract/needs.js +4 -2
  100. package/dist/contract/protocol/bundle-install.d.ts +1 -1
  101. package/dist/contract/protocol/unit-manager.d.ts +50 -0
  102. package/dist/contract/protocol/unit-manager.js +2 -0
  103. package/dist/contract/unit.js +2 -1
  104. package/dist/host/adapter-contract.d.ts +3 -0
  105. package/dist/host/adapter-contract.js +95 -0
  106. package/dist/host/adapter-set.d.ts +27 -0
  107. package/dist/host/adapter-set.js +258 -0
  108. package/dist/host/adapter-types.d.ts +87 -0
  109. package/dist/host/adapter-types.js +23 -0
  110. package/dist/host/adapters/platform.d.ts +14 -0
  111. package/dist/host/adapters/platform.js +40 -0
  112. package/dist/host/adapters.d.ts +28 -0
  113. package/dist/host/adapters.js +9 -0
  114. package/dist/host/auth-loss.d.ts +33 -0
  115. package/dist/host/auth-loss.js +107 -0
  116. package/dist/host/board-fact.d.ts +8 -0
  117. package/dist/host/board-fact.js +16 -0
  118. package/dist/host/boot-record.d.ts +11 -0
  119. package/dist/host/boot-record.js +31 -0
  120. package/dist/host/browser.d.ts +3 -0
  121. package/dist/host/browser.js +3 -0
  122. package/dist/host/bundle-manager.d.ts +4 -0
  123. package/dist/host/bundle-manager.js +338 -0
  124. package/dist/host/changelog.d.ts +28 -0
  125. package/dist/host/changelog.js +201 -0
  126. package/dist/host/cli-error.d.ts +8 -0
  127. package/dist/host/cli-error.js +70 -0
  128. package/dist/host/cli.d.ts +4 -0
  129. package/dist/host/cli.js +9 -0
  130. package/dist/host/config-sync.d.ts +40 -0
  131. package/dist/host/config-sync.js +267 -0
  132. package/dist/host/context-ref.d.ts +13 -0
  133. package/dist/host/context-ref.js +41 -0
  134. package/dist/host/data-error.d.ts +15 -0
  135. package/dist/host/data-error.js +23 -0
  136. package/dist/host/data-plan-check.d.ts +10 -0
  137. package/dist/host/data-plan-check.js +315 -0
  138. package/dist/host/data-plan.d.ts +15 -0
  139. package/dist/host/data-plan.js +283 -0
  140. package/dist/host/data-root.d.ts +5 -0
  141. package/dist/host/data-root.js +23 -0
  142. package/dist/host/diy-debug.d.ts +80 -0
  143. package/dist/host/diy-debug.js +89 -0
  144. package/dist/host/diy-preset.d.ts +26 -0
  145. package/dist/host/diy-preset.js +115 -0
  146. package/dist/host/diy-record.d.ts +135 -0
  147. package/dist/host/diy-record.js +163 -0
  148. package/dist/host/dsh-compat.d.ts +27 -0
  149. package/dist/host/dsh-compat.js +75 -0
  150. package/dist/host/dsh-plugins.d.ts +5 -0
  151. package/dist/host/dsh-plugins.js +51 -0
  152. package/dist/host/env-policy.d.ts +82 -0
  153. package/dist/host/env-policy.js +181 -0
  154. package/dist/host/extension.d.ts +7 -0
  155. package/dist/host/extension.js +40 -0
  156. package/dist/host/facts.d.ts +31 -0
  157. package/dist/host/facts.js +58 -0
  158. package/dist/host/fs-write.d.ts +96 -0
  159. package/dist/host/fs-write.js +183 -0
  160. package/dist/host/git.d.ts +5 -0
  161. package/dist/host/git.js +1 -0
  162. package/dist/host/host-actions.d.ts +2 -0
  163. package/dist/host/host-actions.js +5 -0
  164. package/dist/host/host-kit.d.ts +37 -0
  165. package/dist/host/host-kit.js +27 -0
  166. package/dist/host/http.d.ts +47 -0
  167. package/dist/host/http.js +289 -0
  168. package/dist/host/install-failure.d.ts +50 -0
  169. package/dist/host/install-failure.js +184 -0
  170. package/dist/host/installed-module.d.ts +25 -0
  171. package/dist/host/installed-module.js +289 -0
  172. package/dist/host/installed-sources.d.ts +10 -0
  173. package/dist/host/installed-sources.js +63 -0
  174. package/dist/host/lease.d.ts +70 -0
  175. package/dist/host/lease.js +264 -0
  176. package/dist/host/lib-capabilities.d.ts +22 -0
  177. package/dist/host/lib-capabilities.js +37 -0
  178. package/dist/host/lib-install.d.ts +19 -0
  179. package/dist/host/lib-install.js +40 -0
  180. package/dist/host/lib-runners.d.ts +18 -0
  181. package/dist/host/lib-runners.js +46 -0
  182. package/dist/host/local-declaration.d.ts +7 -0
  183. package/dist/host/local-declaration.js +33 -0
  184. package/dist/host/long-task.d.ts +97 -0
  185. package/dist/host/long-task.js +297 -0
  186. package/dist/host/market-index-claim.d.ts +19 -0
  187. package/dist/host/market-index-claim.js +87 -0
  188. package/dist/host/market-index-doc.d.ts +12 -0
  189. package/dist/host/market-index-doc.js +1 -0
  190. package/dist/host/market-index-parse.d.ts +28 -0
  191. package/dist/host/market-index-parse.js +413 -0
  192. package/dist/host/market-index.d.ts +13 -0
  193. package/dist/host/market-index.js +105 -0
  194. package/dist/host/module-root.d.ts +1 -0
  195. package/dist/host/module-root.js +5 -0
  196. package/dist/host/needs.d.ts +4 -0
  197. package/dist/host/needs.js +2 -0
  198. package/dist/host/npm-registry.d.ts +10 -0
  199. package/dist/host/npm-registry.js +16 -0
  200. package/dist/host/package-content.d.ts +8 -0
  201. package/dist/host/package-content.js +90 -0
  202. package/dist/host/package-kind.d.ts +13 -0
  203. package/dist/host/package-kind.js +51 -0
  204. package/dist/host/package-route.d.ts +33 -0
  205. package/dist/host/package-route.js +68 -0
  206. package/dist/host/panel-state.d.ts +120 -0
  207. package/dist/host/panel-state.js +177 -0
  208. package/dist/host/patch-blocks.d.ts +13 -0
  209. package/dist/host/patch-blocks.js +52 -0
  210. package/dist/host/patch.d.ts +4 -0
  211. package/dist/host/patch.js +7 -0
  212. package/dist/host/paths.d.ts +12 -0
  213. package/dist/host/paths.js +20 -0
  214. package/dist/host/payload.d.ts +12 -0
  215. package/dist/host/payload.js +16 -0
  216. package/dist/host/plan-results.d.ts +5 -0
  217. package/dist/host/plan-results.js +71 -0
  218. package/dist/host/plan-run.d.ts +41 -0
  219. package/dist/host/plan-run.js +87 -0
  220. package/dist/host/platform.d.ts +14 -0
  221. package/dist/host/platform.js +40 -0
  222. package/dist/host/plugin-ledger.d.ts +32 -0
  223. package/dist/host/plugin-ledger.js +106 -0
  224. package/dist/host/plugin.d.ts +3 -0
  225. package/dist/host/plugin.js +38 -0
  226. package/dist/host/port-types.d.ts +233 -0
  227. package/dist/host/port-types.js +1 -0
  228. package/dist/host/preflight.d.ts +32 -0
  229. package/dist/host/preflight.js +1 -0
  230. package/dist/host/process-alive.d.ts +6 -0
  231. package/dist/host/process-alive.js +16 -0
  232. package/dist/host/profile-bundles.d.ts +20 -0
  233. package/dist/host/profile-bundles.js +48 -0
  234. package/dist/host/profile-create.d.ts +19 -0
  235. package/dist/host/profile-create.js +124 -0
  236. package/dist/host/profile-port.d.ts +4 -0
  237. package/dist/host/profile-port.js +4 -0
  238. package/dist/host/profile-registries.d.ts +10 -0
  239. package/dist/host/profile-registries.js +149 -0
  240. package/dist/host/provision.d.ts +32 -0
  241. package/dist/host/provision.js +105 -0
  242. package/dist/host/read-json.d.ts +1 -0
  243. package/dist/host/read-json.js +11 -0
  244. package/dist/host/recipe-rules.d.ts +5 -0
  245. package/dist/host/recipe-rules.js +412 -0
  246. package/dist/host/recipe.d.ts +14 -0
  247. package/dist/host/recipe.js +332 -0
  248. package/dist/host/registry-declaration.d.ts +21 -0
  249. package/dist/host/registry-declaration.js +42 -0
  250. package/dist/host/reinstall-record.d.ts +16 -0
  251. package/dist/host/reinstall-record.js +54 -0
  252. package/dist/host/release-age.d.ts +24 -0
  253. package/dist/host/release-age.js +92 -0
  254. package/dist/host/release-packages.generated.d.ts +1 -0
  255. package/dist/host/release-packages.generated.js +10 -0
  256. package/dist/host/release-probe.d.ts +37 -0
  257. package/dist/host/release-probe.js +156 -0
  258. package/dist/host/runtime/browser-argv.d.ts +1 -0
  259. package/dist/host/runtime/browser-argv.js +9 -0
  260. package/dist/host/runtime/dsh-compat.d.ts +4 -0
  261. package/dist/host/runtime/dsh-compat.js +32 -16
  262. package/dist/host/runtime/front-app.d.ts +6 -0
  263. package/dist/host/runtime/front-app.js +70 -0
  264. package/dist/host/runtime/verified-dsh.d.ts +5 -0
  265. package/dist/host/runtime/verified-dsh.js +20 -0
  266. package/dist/host/shell-render.d.ts +52 -0
  267. package/dist/host/shell-render.js +117 -0
  268. package/dist/host/shell-text.d.ts +30 -0
  269. package/dist/host/shell-text.js +40 -0
  270. package/dist/host/shell.d.ts +25 -0
  271. package/dist/host/shell.js +55 -0
  272. package/dist/host/site.d.ts +45 -0
  273. package/dist/host/site.js +182 -0
  274. package/dist/host/spec.d.ts +8 -0
  275. package/dist/host/spec.js +24 -0
  276. package/dist/host/submit-confirm.d.ts +19 -0
  277. package/dist/host/submit-confirm.js +45 -0
  278. package/dist/host/supply/builtin-catalog.d.ts +3 -0
  279. package/dist/host/supply/builtin-catalog.js +38 -0
  280. package/dist/host/supply/preflight.d.ts +14 -1
  281. package/dist/host/supply/supply-index.js +6 -0
  282. package/dist/host/supply-index.d.ts +38 -0
  283. package/dist/host/supply-index.js +209 -0
  284. package/dist/host/supply-port.d.ts +5 -0
  285. package/dist/host/supply-port.js +50 -0
  286. package/dist/host/time.d.ts +22 -0
  287. package/dist/host/time.js +33 -0
  288. package/dist/host/tokens.d.ts +26 -0
  289. package/dist/host/tokens.js +154 -0
  290. package/dist/host/tool-approval.d.ts +86 -0
  291. package/dist/host/tool-approval.js +118 -0
  292. package/dist/host/tool-kit.d.ts +8 -0
  293. package/dist/host/tool-kit.js +22 -0
  294. package/dist/host/toolbox-port.d.ts +16 -0
  295. package/dist/host/toolbox-port.js +1 -0
  296. package/dist/host/unit-config.d.ts +34 -0
  297. package/dist/host/unit-config.js +28 -0
  298. package/dist/host/unit-data.d.ts +3 -0
  299. package/dist/host/unit-data.js +127 -0
  300. package/dist/host/unit-face.d.ts +95 -0
  301. package/dist/host/unit-face.js +1 -0
  302. package/dist/host/unit-plugin.d.ts +24 -0
  303. package/dist/host/unit-plugin.js +25 -0
  304. package/dist/host/update-journal-manifest.d.ts +19 -0
  305. package/dist/host/update-journal-manifest.js +134 -0
  306. package/dist/host/update-journal-types.d.ts +33 -0
  307. package/dist/host/update-journal-types.js +2 -0
  308. package/dist/host/update-journal.d.ts +43 -0
  309. package/dist/host/update-journal.js +409 -0
  310. package/dist/host/value-handoff.d.ts +16 -0
  311. package/dist/host/value-handoff.js +22 -0
  312. package/dist/host/version-range.d.ts +2 -0
  313. package/dist/host/version-range.js +13 -0
  314. package/dist/host/version.d.ts +4 -0
  315. package/dist/host/version.js +32 -0
  316. package/dist/host/workspace-store.d.ts +19 -0
  317. package/dist/host/workspace-store.js +133 -0
  318. package/dist/host/write-result.d.ts +1 -0
  319. package/dist/host/write-result.js +18 -0
  320. package/dist/host.d.ts +2 -0
  321. package/dist/host.js +2 -0
  322. package/dist/i18n/en.js +14 -3
  323. package/dist/i18n/index.d.ts +15 -4
  324. package/dist/i18n/zh.d.ts +14 -3
  325. package/dist/i18n/zh.js +14 -3
  326. package/dist/lib/bundle-requirements.d.ts +1 -0
  327. package/dist/lib/bundle-requirements.js +9 -0
  328. package/package.json +1 -1
  329. package/src/contract/__tests__/unit.test.ts +7 -0
  330. package/src/contract/needs.ts +5 -3
  331. package/src/contract/protocol/bundle-install.ts +1 -0
  332. package/src/contract/unit.ts +2 -1
  333. package/src/host/runtime/__tests__/dsh-compat.test.ts +19 -1
  334. package/src/host/runtime/__tests__/verified-dsh.test.ts +55 -0
  335. package/src/host/runtime/dsh-compat.ts +36 -12
  336. package/src/host/runtime/verified-dsh.ts +22 -0
  337. package/src/host/supply/__tests__/builtin-catalog.test.ts +44 -0
  338. package/src/host/supply/builtin-catalog.ts +38 -0
  339. package/src/host/supply/preflight.ts +16 -1
  340. package/src/host/supply/supply-index.ts +3 -0
  341. package/src/host.ts +2 -0
  342. package/src/i18n/en.ts +17 -3
  343. package/src/i18n/zh.ts +16 -3
  344. package/src/lib/bundle-requirements.ts +11 -0
@@ -0,0 +1,23 @@
1
+ import { homedir } from 'node:os';
2
+ import { join } from 'node:path';
3
+ export function dshHome() {
4
+ const configured = process.env.DSH_HOME?.trim();
5
+ if (configured !== undefined && configured !== '')
6
+ return configured;
7
+ return join(homedir(), '.dsh');
8
+ }
9
+ export function workbenchRoot() {
10
+ const configured = process.env.DSH_WORKBENCH_HOME?.trim();
11
+ if (configured !== undefined && configured !== '')
12
+ return configured;
13
+ return join(dshHome(), 'workbench');
14
+ }
15
+ export function workbenchHostLock() {
16
+ return join(workbenchRoot(), 'host.lock');
17
+ }
18
+ export function workbenchSelfUpdateMarker() {
19
+ return join(workbenchRoot(), 'self-update.json');
20
+ }
21
+ export function workspacesRoot() {
22
+ return join(workbenchRoot(), 'workspaces');
23
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * 调试约定的两个相位:`debugging` 正占着用户的屏,`paused` 已暂停但仍持着约定。
3
+ */
4
+ export type DebugPhase = 'debugging' | 'paused';
5
+ /**
6
+ * 调试约定收得下的三个人话动作:暂停 / 继续 / 结束。
7
+ */
8
+ export type DebugIntent = 'pause' | 'resume' | 'stop';
9
+ /**
10
+ * 把工具入参收成人话动作。
11
+ * @param value - 任意入参值。
12
+ * @returns `'pause'` / `'resume'` / `'stop'` 原样;别的值(含 `undefined`、多余空白、大小写不同)给 `null`,由调用方拒。
13
+ */
14
+ export declare function parseDebugIntent(value: unknown): DebugIntent | null;
15
+ /**
16
+ * 调试约定的有效期(4 小时,毫秒):超过它没动静的约定算过期、当场让人。
17
+ */
18
+ export declare const DEBUG_STALE_MS: number;
19
+ /**
20
+ * 一份活着的调试约定:相位 + 谁的会话 + 哪个工作区 / 板 / 单元 + 起于何时(`at` 是最后一次动作)。
21
+ */
22
+ export interface DebugState {
23
+ readonly phase: DebugPhase;
24
+ readonly sessionId: string;
25
+ readonly workspacePath: string;
26
+ readonly title: string;
27
+ readonly board: string;
28
+ readonly unit: string;
29
+ readonly name: string;
30
+ readonly startedAt: number;
31
+ readonly at: number;
32
+ }
33
+ /**
34
+ * 建立约定要交的那几件:会话、工作区、板、单元、名字,以及此刻的时间戳。
35
+ */
36
+ export interface DebugPact {
37
+ readonly sessionId: string;
38
+ readonly workspacePath: string;
39
+ readonly title: string;
40
+ readonly board: string;
41
+ readonly unit: string;
42
+ readonly name: string;
43
+ readonly now: number;
44
+ }
45
+ /**
46
+ * 约定被拒的原因码:自己已持有 / 别人持着 / 不是持有者 / 没有约定 / 已暂停 / 已在调试。
47
+ */
48
+ export type DebugRefusal = 'already-held' | 'held-by-other' | 'not-owner' | 'none' | 'already-paused' | 'already-debugging';
49
+ /**
50
+ * 一次约定动作的结果:成功带新状态,失败带拒绝码。
51
+ */
52
+ export type DebugMove = {
53
+ readonly ok: true;
54
+ readonly state: DebugState;
55
+ } | {
56
+ readonly ok: false;
57
+ readonly code: DebugRefusal;
58
+ };
59
+ /**
60
+ * 调试约定的存取口(外壳持有一份):`live` 取当前有效的约定,`begin` / `pause` / `resume` / `stop` 推相位。
61
+ */
62
+ export interface DebugStore {
63
+ live(now: number): DebugState | null;
64
+ begin(pact: DebugPact): DebugMove;
65
+ pause(sessionId: string, now: number): DebugMove;
66
+ resume(sessionId: string, now: number): DebugMove;
67
+ stop(sessionId: string, now: number): DebugMove;
68
+ settle?(): Promise<void>;
69
+ }
70
+ /**
71
+ * 造一份新的调试约定存储(进程内存,同一时刻只可能有一份有效约定)。
72
+ * @returns 存取口;动作成不成都在返回的 `DebugMove` 里,不抛异常。
73
+ */
74
+ export declare function createDebugStore(): DebugStore;
75
+ /**
76
+ * 「谁还占着」的一句话,用于别人来抢时说清现况。
77
+ * @param state - 当前有效的那份约定。
78
+ * @returns 形如「会话 x(自 HH:mm:ssZ 起在调试 y)」的中文串。
79
+ */
80
+ export declare function debugOwnerText(state: DebugState): string;
@@ -0,0 +1,89 @@
1
+ import { clockOf } from './time.js';
2
+ /**
3
+ * 把工具入参收成人话动作。
4
+ * @param value - 任意入参值。
5
+ * @returns `'pause'` / `'resume'` / `'stop'` 原样;别的值(含 `undefined`、多余空白、大小写不同)给 `null`,由调用方拒。
6
+ */
7
+ export function parseDebugIntent(value) {
8
+ return value === 'pause' || value === 'resume' || value === 'stop' ? value : null;
9
+ }
10
+ /**
11
+ * 调试约定的有效期(4 小时,毫秒):超过它没动静的约定算过期、当场让人。
12
+ */
13
+ export const DEBUG_STALE_MS = 4 * 60 * 60 * 1000;
14
+ function alive(state, now) {
15
+ if (state === null)
16
+ return null;
17
+ return now - state.at <= DEBUG_STALE_MS ? state : null;
18
+ }
19
+ function ownerOf(state, sessionId, now) {
20
+ const held = alive(state, now);
21
+ if (held === null)
22
+ return 'none';
23
+ return held.sessionId === sessionId ? held : 'not-owner';
24
+ }
25
+ /**
26
+ * 造一份新的调试约定存储(进程内存,同一时刻只可能有一份有效约定)。
27
+ * @returns 存取口;动作成不成都在返回的 `DebugMove` 里,不抛异常。
28
+ */
29
+ export function createDebugStore() {
30
+ let held = null;
31
+ const live = (now) => alive(held, now);
32
+ return {
33
+ live,
34
+ begin(pact) {
35
+ const current = alive(held, pact.now);
36
+ if (current !== null) {
37
+ return { ok: false, code: current.sessionId === pact.sessionId ? 'already-held' : 'held-by-other' };
38
+ }
39
+ const state = {
40
+ phase: 'debugging',
41
+ sessionId: pact.sessionId,
42
+ workspacePath: pact.workspacePath,
43
+ title: pact.title,
44
+ board: pact.board,
45
+ unit: pact.unit,
46
+ name: pact.name,
47
+ startedAt: pact.now,
48
+ at: pact.now,
49
+ };
50
+ held = state;
51
+ return { ok: true, state };
52
+ },
53
+ pause(sessionId, now) {
54
+ const found = ownerOf(held, sessionId, now);
55
+ if (typeof found === 'string')
56
+ return { ok: false, code: found };
57
+ if (found.phase === 'paused')
58
+ return { ok: false, code: 'already-paused' };
59
+ const state = { ...found, phase: 'paused', at: now };
60
+ held = state;
61
+ return { ok: true, state };
62
+ },
63
+ resume(sessionId, now) {
64
+ const found = ownerOf(held, sessionId, now);
65
+ if (typeof found === 'string')
66
+ return { ok: false, code: found };
67
+ if (found.phase === 'debugging')
68
+ return { ok: false, code: 'already-debugging' };
69
+ const state = { ...found, phase: 'debugging', at: now };
70
+ held = state;
71
+ return { ok: true, state };
72
+ },
73
+ stop(sessionId, now) {
74
+ const found = ownerOf(held, sessionId, now);
75
+ if (typeof found === 'string')
76
+ return { ok: false, code: found };
77
+ held = null;
78
+ return { ok: true, state: found };
79
+ },
80
+ };
81
+ }
82
+ /**
83
+ * 「谁还占着」的一句话,用于别人来抢时说清现况。
84
+ * @param state - 当前有效的那份约定。
85
+ * @returns 形如「会话 x(自 HH:mm:ssZ 起在调试 y)」的中文串。
86
+ */
87
+ export function debugOwnerText(state) {
88
+ return `会话 ${state.sessionId}(自 ${clockOf(state.startedAt)}Z 起在调试 ${state.unit})`;
89
+ }
@@ -0,0 +1,26 @@
1
+ import type { DshAgentPresetDefinition, DshLoaderEntry } from '../api/dsh.js';
2
+ /** DIY preset 在模式菜单里的名字。 */
3
+ export declare const DIY_PRESET_NAME = "\u5DE5\u4F5C\u53F0 DIY \u6A21\u5F0F";
4
+ /** DIY preset 在模式菜单里的说明。 */
5
+ export declare const DIY_PRESET_DESCRIPTION = "\u770B / \u8C03\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u7684\u9762\u677F\uFF0C\u6216\u8005\u7ED9\u5B83\u9020\u4E00\u5757\u65B0\u5185\u5BB9 \u2014\u2014 \u7528\u5927\u767D\u8BDD\u8BF4\u5C31\u884C\u3002\u4EFB\u4F55\u5DE5\u4F5C\u533A\u90FD\u80FD\u7528\uFF08\u7A7A\u9879\u76EE\u4E5F\u7B97\uFF09\uFF1Bagent \u4F1A\u770B\u9762\u677F\u3001\u6293\u8BF7\u6C42\uFF0C\u5FC5\u8981\u65F6\u628A\u6A21\u5757\u9020\u51FA\u6765\u88C5\u4E0A\u3002\u4E0D\u7528\u5199\u4EE3\u7801\u3002";
6
+ /** DIY preset 在模式菜单里的排序(排在 dsh 出厂的几个模式之后)。 */
7
+ export declare const DIY_PRESET_ORDER = 9;
8
+ /** 这一轮 dsh 的 standard preset 没法派生时抛的错:带上哪一段锚点变了。 */
9
+ export declare class DiyPresetSourceError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ /**
13
+ * 从这一轮 dsh 的 `standard` preset 配置派生 `workbench-diy`。
14
+ *
15
+ * 差分只有三处:`skill-filesystem` 与 `tool-skill` 一起搬到末尾(前者加 `customSkillDirs` 指向工作台的
16
+ * `skills/`)、末尾补 `tool-cordis`、`tool-plugin-manager` 打开(工作台只活在 profile 里)。
17
+ * 其余行原样跟着 dsh 走,所以 dsh 加工具 / 改 config 时不需要重新生成任何文件。
18
+ * @param standard dsh loader 里 `preset-standard` 那一行收到的 config。
19
+ * @param skillsDir 工作台的 `skills/` 绝对路径。
20
+ */
21
+ export declare function diyPresetFrom(standard: unknown, skillsDir: string): DshAgentPresetDefinition;
22
+ /**
23
+ * 在 loader 的行里找这一轮 dsh 的 `standard` preset 配置;没有(或那一行被关掉)就算不知道。
24
+ * @param entries loader 的 `entries()`(递归给全部行)。
25
+ */
26
+ export declare function standardPresetConfigOf(entries: Iterable<DshLoaderEntry>): unknown;
@@ -0,0 +1,115 @@
1
+ import { DIY_PRESET_ID } from '../contract/protocol/diy.js';
2
+ const AGENT_PRESET_PLUGIN = '@deepseek-ai/dsh-agent-preset';
3
+ const STANDARD_PRESET_ID = 'standard';
4
+ /** DIY preset 在模式菜单里的名字。 */
5
+ export const DIY_PRESET_NAME = '工作台 DIY 模式';
6
+ /** DIY preset 在模式菜单里的说明。 */
7
+ export const DIY_PRESET_DESCRIPTION = '看 / 调这个工作区的面板,或者给它造一块新内容 —— 用大白话说就行。任何工作区都能用(空项目也算);agent 会看面板、抓请求,必要时把模块造出来装上。不用写代码。';
8
+ /** DIY preset 在模式菜单里的排序(排在 dsh 出厂的几个模式之后)。 */
9
+ export const DIY_PRESET_ORDER = 9;
10
+ /** 这一轮 dsh 的 standard preset 没法派生时抛的错:带上哪一段锚点变了。 */
11
+ export class DiyPresetSourceError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = 'DiyPresetSourceError';
15
+ }
16
+ }
17
+ function isRow(value) {
18
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ }
20
+ function rowAt(value, at) {
21
+ if (!isRow(value))
22
+ throw new DiyPresetSourceError(`${at} 不是一行插件配置`);
23
+ return value;
24
+ }
25
+ function standardConfigOf(value) {
26
+ const standard = rowAt(value, 'dsh 的 standard preset');
27
+ if (!Array.isArray(standard.plugins)) {
28
+ throw new DiyPresetSourceError('dsh 的 standard preset 没有 plugins 表 —— 派生不出 DIY 那一份');
29
+ }
30
+ return standard;
31
+ }
32
+ function clonedPluginsOf(standard) {
33
+ let cloned;
34
+ try {
35
+ cloned = structuredClone(standard);
36
+ }
37
+ catch (error) {
38
+ throw new DiyPresetSourceError(`dsh 的 standard preset 配置复制不了:${String(error)}`);
39
+ }
40
+ const rows = rowAt(cloned, 'dsh 的 standard preset').plugins;
41
+ if (!Array.isArray(rows)) {
42
+ throw new DiyPresetSourceError('dsh 的 standard preset 没有 plugins 表 —— 派生不出 DIY 那一份');
43
+ }
44
+ return rows.map((row, index) => {
45
+ const parsed = rowAt(row, `dsh 的 standard preset 第 ${index + 1} 行`);
46
+ if (typeof parsed.name !== 'string' || parsed.name === '') {
47
+ throw new DiyPresetSourceError(`dsh 的 standard preset 第 ${index + 1} 行没有插件名`);
48
+ }
49
+ return parsed;
50
+ });
51
+ }
52
+ function takeRow(plugins, id) {
53
+ const index = plugins.findIndex((row) => row.id === id);
54
+ if (index < 0) {
55
+ throw new DiyPresetSourceError(`dsh 的 standard preset 里找不到 \`${id}\` 那一行 —— DIY 的差分锚点变了`);
56
+ }
57
+ return plugins.splice(index, 1)[0];
58
+ }
59
+ /**
60
+ * 从这一轮 dsh 的 `standard` preset 配置派生 `workbench-diy`。
61
+ *
62
+ * 差分只有三处:`skill-filesystem` 与 `tool-skill` 一起搬到末尾(前者加 `customSkillDirs` 指向工作台的
63
+ * `skills/`)、末尾补 `tool-cordis`、`tool-plugin-manager` 打开(工作台只活在 profile 里)。
64
+ * 其余行原样跟着 dsh 走,所以 dsh 加工具 / 改 config 时不需要重新生成任何文件。
65
+ * @param standard dsh loader 里 `preset-standard` 那一行收到的 config。
66
+ * @param skillsDir 工作台的 `skills/` 绝对路径。
67
+ */
68
+ export function diyPresetFrom(standard, skillsDir) {
69
+ const plugins = clonedPluginsOf(standardConfigOf(standard));
70
+ const skillFilesystem = takeRow(plugins, 'skill-filesystem');
71
+ const toolSkill = takeRow(plugins, 'tool-skill');
72
+ skillFilesystem.config = {
73
+ ...(isRow(skillFilesystem.config) ? skillFilesystem.config : {}),
74
+ customSkillDirs: [skillsDir],
75
+ };
76
+ const manager = plugins.find((row) => row.id === 'tool-plugin-manager');
77
+ if (manager !== undefined)
78
+ manager.disabled = false;
79
+ if (!plugins.some((row) => row.id === 'tool-cordis')) {
80
+ plugins.push({ id: 'tool-cordis', name: '@deepseek-ai/dsh-tool-cordis' });
81
+ }
82
+ plugins.push(skillFilesystem, toolSkill);
83
+ const seen = new Set();
84
+ for (const row of plugins) {
85
+ if (typeof row.id !== 'string' || row.id === '')
86
+ continue;
87
+ if (seen.has(row.id)) {
88
+ throw new DiyPresetSourceError(`dsh 的 standard preset 里出现重复的 id:${row.id}`);
89
+ }
90
+ seen.add(row.id);
91
+ }
92
+ return {
93
+ id: DIY_PRESET_ID,
94
+ name: DIY_PRESET_NAME,
95
+ description: DIY_PRESET_DESCRIPTION,
96
+ order: DIY_PRESET_ORDER,
97
+ plugins: plugins,
98
+ };
99
+ }
100
+ /**
101
+ * 在 loader 的行里找这一轮 dsh 的 `standard` preset 配置;没有(或那一行被关掉)就算不知道。
102
+ * @param entries loader 的 `entries()`(递归给全部行)。
103
+ */
104
+ export function standardPresetConfigOf(entries) {
105
+ for (const entry of entries) {
106
+ if (entry.disabled === true)
107
+ continue;
108
+ if (entry.options?.name !== AGENT_PRESET_PLUGIN)
109
+ continue;
110
+ const config = entry.options.config;
111
+ if (isRow(config) && config.id === STANDARD_PRESET_ID)
112
+ return config;
113
+ }
114
+ return undefined;
115
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * 录制交接的三个相位:`armed` 等用户在外站页面上动手,`recording` 正在录,`finished` 录完待取。
3
+ */
4
+ export type RecordPhase = 'armed' | 'recording' | 'finished';
5
+ /**
6
+ * 录制约定的有效期(15 分钟,毫秒):超过它没动静的约定算过期、当场让人。
7
+ */
8
+ export declare const RECORD_STALE_MS: number;
9
+ /**
10
+ * 这次录制要找的那一次写:HTTP 方法 + URL 里必须含的一段(不填就是只认方法)。
11
+ */
12
+ export interface RecordExpect {
13
+ readonly method: string;
14
+ readonly urlContains: string;
15
+ }
16
+ /**
17
+ * 一次「截图」在宿主台账里的那一行:页面上的计数、落图那一刻、落盘路径;没落下来时带 `error` 原文(落成的那条没有它)。
18
+ */
19
+ export interface RecordShot {
20
+ readonly n: number;
21
+ readonly at: number;
22
+ readonly path: string;
23
+ readonly error?: string;
24
+ }
25
+ /**
26
+ * 某个页面计数已经试过几次:初拍算一次,失败再试一次;计数一换就从头数。
27
+ */
28
+ export interface RecordShotTries {
29
+ readonly n: number;
30
+ readonly tries: number;
31
+ }
32
+ /**
33
+ * 一张图最多试几次(初拍 + 一次重试):失败如实报过就停,不每拍重试到底。
34
+ */
35
+ export declare const RECORD_SHOT_TRIES = 2;
36
+ /**
37
+ * 一份活着的录制约定:相位 + 谁的会话 + 哪个工作区 / 单元 + 页面 URL 与标题 + 要找的那一次写 +
38
+ * 落盘文件 + 三个时间戳,以及两份台账:按计数落图的 `shots`(`shotsSeen` 只记落成的那个计数)
39
+ * 与门铃的 `beats` / `beatMs`(命中几次、最近一次等了多久)。
40
+ */
41
+ export interface RecordState {
42
+ readonly phase: RecordPhase;
43
+ readonly sessionId: string;
44
+ readonly workspace: string;
45
+ readonly unit: string;
46
+ readonly name: string;
47
+ readonly url: string;
48
+ readonly title: string;
49
+ readonly action: string;
50
+ readonly expect: RecordExpect | null;
51
+ readonly captureFile: string;
52
+ readonly startedAt: number;
53
+ readonly t0: number | null;
54
+ readonly t1: number | null;
55
+ readonly shots: readonly RecordShot[];
56
+ readonly shotsSeen: number;
57
+ readonly shotTries: RecordShotTries | null;
58
+ readonly beats: number;
59
+ readonly beatMs: number;
60
+ readonly at: number;
61
+ }
62
+ /**
63
+ * 开一次录制要交的那几件:会话、工作区、单元、名字、页面 URL 与标题、动作名、期望、落盘文件,以及此刻时间。
64
+ */
65
+ export interface RecordPact {
66
+ readonly sessionId: string;
67
+ readonly workspace: string;
68
+ readonly unit: string;
69
+ readonly name: string;
70
+ readonly url: string;
71
+ readonly title: string;
72
+ readonly action: string;
73
+ readonly expect: RecordExpect | null;
74
+ readonly captureFile: string;
75
+ readonly now: number;
76
+ }
77
+ /**
78
+ * 录制被拒的原因码:自己已持有 / 别人持着 / 不是持有者 / 没有约定 / 已在录 / 还没 arm / 不在录 / 还没录完。
79
+ */
80
+ export type RecordRefusal = 'already-held' | 'held-by-other' | 'not-owner' | 'none' | 'already-recording' | 'not-armed' | 'not-recording' | 'not-finished';
81
+ /**
82
+ * 一次录制动作的结果:成功带新状态,失败带拒绝码。
83
+ */
84
+ export type RecordMove = {
85
+ readonly ok: true;
86
+ readonly state: RecordState;
87
+ } | {
88
+ readonly ok: false;
89
+ readonly code: RecordRefusal;
90
+ };
91
+ /**
92
+ * 录制约定收得下的三个人话动作:看看进度 / 停手 / 结束并取回。
93
+ */
94
+ export type RecordIntent = 'peek' | 'halt' | 'stop';
95
+ /**
96
+ * 把工具入参收成人话动作。
97
+ * @param raw - 任意入参值。
98
+ * @returns `'peek'` / `'halt'` / `'stop'` 原样;别的值(含 `undefined`、多余空白)给 `null`,由调用方拒。
99
+ */
100
+ export declare function parseRecordIntent(raw: unknown): RecordIntent | null;
101
+ /**
102
+ * 录制约定的存取口(外壳持有一份):相位随 `begin → started → finished` 推进,`release` 是收尾时放掉浏览器那一跳。
103
+ */
104
+ export interface RecordStore {
105
+ readonly release?: ((state: RecordState) => Promise<{
106
+ readonly tab: boolean;
107
+ readonly capture: boolean;
108
+ }>) | undefined;
109
+ live(now: number): RecordState | null;
110
+ begin(pact: RecordPact): RecordMove;
111
+ started(sessionId: string, at: number, now: number): RecordMove;
112
+ finished(sessionId: string, at: number, now: number): RecordMove;
113
+ shotTaken(sessionId: string, shot: RecordShot, now: number): RecordMove;
114
+ shotFailed(sessionId: string, shot: RecordShot, now: number): RecordMove;
115
+ beat(sessionId: string, ms: number, now: number): RecordMove;
116
+ stop(sessionId: string, now: number): RecordMove;
117
+ }
118
+ /**
119
+ * 这一拍该不该落图:页面计数涨过 `shotsSeen` 才算;同一个计数已经试满就先放下,等他自己再按。
120
+ * @param state - 当前有效的那份约定。
121
+ * @param pageShots - 页面浮条上那个「已拍」计数。
122
+ * @returns 该落的那个计数;不该落给 `null`(没涨 / 试满了 / 不是个正经数)。
123
+ */
124
+ export declare function shotDueOf(state: RecordState, pageShots: number): number | null;
125
+ /**
126
+ * 造一份新的录制约定存储(进程内存,同一时刻只可能有一份有效约定)。
127
+ * @returns 存取口;动作成不成都在返回的 `RecordMove` 里,不抛异常。
128
+ */
129
+ export declare function createRecordStore(): RecordStore;
130
+ /**
131
+ * 「谁还占着、在录哪个动作」的一句话,用于别人来抢时说清现况。
132
+ * @param state - 当前有效的那份约定。
133
+ * @returns 形如「会话 x(自 HH:mm:ssZ 起在录 y 的「动作」)」的中文串。
134
+ */
135
+ export declare function recordOwnerText(state: RecordState): string;
@@ -0,0 +1,163 @@
1
+ import { clockOf } from './time.js';
2
+ /**
3
+ * 录制约定的有效期(15 分钟,毫秒):超过它没动静的约定算过期、当场让人。
4
+ */
5
+ export const RECORD_STALE_MS = 15 * 60 * 1000;
6
+ /**
7
+ * 一张图最多试几次(初拍 + 一次重试):失败如实报过就停,不每拍重试到底。
8
+ */
9
+ export const RECORD_SHOT_TRIES = 2;
10
+ /**
11
+ * 把工具入参收成人话动作。
12
+ * @param raw - 任意入参值。
13
+ * @returns `'peek'` / `'halt'` / `'stop'` 原样;别的值(含 `undefined`、多余空白)给 `null`,由调用方拒。
14
+ */
15
+ export function parseRecordIntent(raw) {
16
+ return raw === 'peek' || raw === 'halt' || raw === 'stop' ? raw : null;
17
+ }
18
+ /**
19
+ * 这一拍该不该落图:页面计数涨过 `shotsSeen` 才算;同一个计数已经试满就先放下,等他自己再按。
20
+ * @param state - 当前有效的那份约定。
21
+ * @param pageShots - 页面浮条上那个「已拍」计数。
22
+ * @returns 该落的那个计数;不该落给 `null`(没涨 / 试满了 / 不是个正经数)。
23
+ */
24
+ export function shotDueOf(state, pageShots) {
25
+ if (!Number.isFinite(pageShots))
26
+ return null;
27
+ const n = Math.floor(pageShots);
28
+ if (n <= state.shotsSeen)
29
+ return null;
30
+ if (state.shotTries !== null && state.shotTries.n === n && state.shotTries.tries >= RECORD_SHOT_TRIES)
31
+ return null;
32
+ return n;
33
+ }
34
+ function alive(state, now) {
35
+ if (state === null)
36
+ return null;
37
+ return now - state.at <= RECORD_STALE_MS ? state : null;
38
+ }
39
+ function ownerOf(state, sessionId, now) {
40
+ const held = alive(state, now);
41
+ if (held === null)
42
+ return 'none';
43
+ return held.sessionId === sessionId ? held : 'not-owner';
44
+ }
45
+ /**
46
+ * 造一份新的录制约定存储(进程内存,同一时刻只可能有一份有效约定)。
47
+ * @returns 存取口;动作成不成都在返回的 `RecordMove` 里,不抛异常。
48
+ */
49
+ export function createRecordStore() {
50
+ let held = null;
51
+ const live = (now) => alive(held, now);
52
+ const withShot = (found, shot, now, error) => {
53
+ const row = error === undefined ? shot : { n: shot.n, at: shot.at, path: shot.path, error };
54
+ const kept = found.shots.filter((one) => one.n !== shot.n);
55
+ const tries = found.shotTries !== null && found.shotTries.n === shot.n ? found.shotTries.tries : 0;
56
+ return {
57
+ ...found,
58
+ shots: [...kept, row].sort((one, two) => one.n - two.n),
59
+ shotsSeen: error === undefined ? Math.max(found.shotsSeen, shot.n) : found.shotsSeen,
60
+ shotTries: error === undefined ? null : { n: shot.n, tries: tries + 1 },
61
+ at: now,
62
+ };
63
+ };
64
+ return {
65
+ live,
66
+ begin(pact) {
67
+ const current = alive(held, pact.now);
68
+ if (current !== null) {
69
+ return { ok: false, code: current.sessionId === pact.sessionId ? 'already-held' : 'held-by-other' };
70
+ }
71
+ const state = {
72
+ phase: 'armed',
73
+ sessionId: pact.sessionId,
74
+ workspace: pact.workspace,
75
+ unit: pact.unit,
76
+ name: pact.name,
77
+ url: pact.url,
78
+ title: pact.title,
79
+ action: pact.action,
80
+ expect: pact.expect,
81
+ captureFile: pact.captureFile,
82
+ startedAt: pact.now,
83
+ t0: null,
84
+ t1: null,
85
+ shots: [],
86
+ shotsSeen: 0,
87
+ shotTries: null,
88
+ beats: 0,
89
+ beatMs: 0,
90
+ at: pact.now,
91
+ };
92
+ held = state;
93
+ return { ok: true, state };
94
+ },
95
+ started(sessionId, at, now) {
96
+ const found = ownerOf(held, sessionId, now);
97
+ if (typeof found === 'string')
98
+ return { ok: false, code: found };
99
+ if (found.phase === 'recording')
100
+ return { ok: false, code: 'already-recording' };
101
+ if (found.phase !== 'armed')
102
+ return { ok: false, code: 'not-armed' };
103
+ const state = { ...found, phase: 'recording', t0: at, at: now };
104
+ held = state;
105
+ return { ok: true, state };
106
+ },
107
+ finished(sessionId, at, now) {
108
+ const found = ownerOf(held, sessionId, now);
109
+ if (typeof found === 'string')
110
+ return { ok: false, code: found };
111
+ if (found.phase !== 'recording')
112
+ return { ok: false, code: 'not-recording' };
113
+ const state = { ...found, phase: 'finished', t1: at, at: now };
114
+ held = state;
115
+ return { ok: true, state };
116
+ },
117
+ shotTaken(sessionId, shot, now) {
118
+ const found = ownerOf(held, sessionId, now);
119
+ if (typeof found === 'string')
120
+ return { ok: false, code: found };
121
+ const state = withShot(found, shot, now, undefined);
122
+ held = state;
123
+ return { ok: true, state };
124
+ },
125
+ shotFailed(sessionId, shot, now) {
126
+ const found = ownerOf(held, sessionId, now);
127
+ if (typeof found === 'string')
128
+ return { ok: false, code: found };
129
+ const state = withShot(found, shot, now, shot.error === undefined ? '落图失败' : shot.error);
130
+ held = state;
131
+ return { ok: true, state };
132
+ },
133
+ beat(sessionId, ms, now) {
134
+ const found = ownerOf(held, sessionId, now);
135
+ if (typeof found === 'string')
136
+ return { ok: false, code: found };
137
+ const state = {
138
+ ...found,
139
+ beats: found.beats + 1,
140
+ beatMs: Math.max(0, Math.floor(ms)),
141
+ at: now,
142
+ };
143
+ held = state;
144
+ return { ok: true, state };
145
+ },
146
+ stop(sessionId, now) {
147
+ const found = ownerOf(held, sessionId, now);
148
+ if (typeof found === 'string')
149
+ return { ok: false, code: found };
150
+ held = null;
151
+ return { ok: true, state: found };
152
+ },
153
+ };
154
+ }
155
+ /**
156
+ * 「谁还占着、在录哪个动作」的一句话,用于别人来抢时说清现况。
157
+ * @param state - 当前有效的那份约定。
158
+ * @returns 形如「会话 x(自 HH:mm:ssZ 起在录 y 的「动作」)」的中文串。
159
+ */
160
+ export function recordOwnerText(state) {
161
+ const at = clockOf(state.startedAt);
162
+ return `会话 ${state.sessionId}(自 ${at}Z 起在录 ${state.unit} 的「${state.action}」)`;
163
+ }
@@ -0,0 +1,27 @@
1
+ export type DshRequirementSource = 'engines' | 'peer';
2
+ export interface DshRequirement {
3
+ readonly pkg: string;
4
+ readonly range: string;
5
+ readonly source: DshRequirementSource;
6
+ }
7
+ export interface DshManifestFields {
8
+ readonly name?: string | undefined;
9
+ readonly engines?: Readonly<Record<string, unknown>> | undefined;
10
+ readonly peerDependencies?: Readonly<Record<string, unknown>> | undefined;
11
+ }
12
+ export type DshCompatibility = {
13
+ readonly verdict: 'compatible';
14
+ } | {
15
+ readonly verdict: 'incompatible';
16
+ readonly requirements: readonly DshRequirement[];
17
+ } | {
18
+ readonly verdict: 'unknown';
19
+ readonly reason: 'no-requirement' | 'missing-dsh-version' | 'malformed';
20
+ readonly requirements: readonly DshRequirement[];
21
+ };
22
+ export declare function dshRequirementsOf(manifest: DshManifestFields): readonly DshRequirement[];
23
+ export declare function dshCompatibilityOf(input: {
24
+ readonly requirements: readonly DshRequirement[];
25
+ readonly dshVersion?: string | undefined;
26
+ }): DshCompatibility;
27
+ export declare function dshVersionIn(profileDir: string): string | undefined;