@dsh-workbench/shared 0.1.2 → 0.1.4

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 (99) hide show
  1. package/dist/api/host-write.d.ts +1 -0
  2. package/dist/api/host-write.js +7 -1
  3. package/dist/api/workbench-contract.d.ts +1 -1
  4. package/dist/components/ApprovalDetail.css +4 -0
  5. package/dist/components/ApprovalDetail.d.ts +1 -0
  6. package/dist/components/ApprovalDetail.js +5 -1
  7. package/dist/components/CardHead.css +92 -0
  8. package/dist/components/CardHead.d.ts +1 -0
  9. package/dist/components/CardHead.js +9 -7
  10. package/dist/components/ChoiceGroup.css +75 -0
  11. package/dist/components/ChoiceGroup.d.ts +1 -0
  12. package/dist/components/ChoiceGroup.js +1 -0
  13. package/dist/components/LongTaskRow.css +53 -0
  14. package/dist/components/LongTaskRow.d.ts +3 -0
  15. package/dist/components/LongTaskRow.js +11 -11
  16. package/dist/components/MockStrip.css +39 -0
  17. package/dist/components/MockStrip.d.ts +1 -0
  18. package/dist/components/MockStrip.js +1 -0
  19. package/dist/components/ResourceStates.css +111 -0
  20. package/dist/components/ResourceStates.d.ts +2 -1
  21. package/dist/components/ResourceStates.js +1 -0
  22. package/dist/components/SaveBar.css +7 -0
  23. package/dist/components/SaveBar.d.ts +1 -0
  24. package/dist/components/SaveBar.js +4 -2
  25. package/dist/components/TextField.css +22 -0
  26. package/dist/components/TextField.d.ts +6 -0
  27. package/dist/components/TextField.js +5 -0
  28. package/dist/components/icons.d.ts +0 -12
  29. package/dist/components/icons.js +0 -61
  30. package/dist/host/http.js +5 -29
  31. package/dist/host/provision.d.ts +18 -1
  32. package/dist/host/provision.js +73 -0
  33. package/dist/host.d.ts +8 -0
  34. package/dist/host.js +8 -0
  35. package/dist/i18n/en.js +126 -1
  36. package/dist/i18n/index.d.ts +129 -4
  37. package/dist/i18n/zh.d.ts +128 -3
  38. package/dist/i18n/zh.js +128 -3
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.js +1 -1
  41. package/package.json +5 -3
  42. package/src/api/__tests__/host-write.test.ts +20 -0
  43. package/src/api/host-write.ts +17 -3
  44. package/src/api/workbench-contract.ts +5 -1
  45. package/src/components/ApprovalDetail.css +4 -0
  46. package/src/components/ApprovalDetail.tsx +11 -1
  47. package/src/components/CardHead.css +92 -0
  48. package/src/components/CardHead.tsx +43 -31
  49. package/src/components/ChoiceGroup.css +75 -0
  50. package/src/components/ChoiceGroup.tsx +1 -0
  51. package/src/components/LongTaskRow.css +53 -0
  52. package/src/components/LongTaskRow.tsx +52 -13
  53. package/src/components/MockStrip.css +39 -0
  54. package/src/components/MockStrip.tsx +1 -0
  55. package/src/components/ResourceStates.css +111 -0
  56. package/src/components/ResourceStates.tsx +2 -1
  57. package/src/components/SaveBar.css +7 -0
  58. package/src/components/SaveBar.tsx +8 -5
  59. package/src/components/TextField.css +22 -0
  60. package/src/components/TextField.tsx +17 -0
  61. package/src/components/icons.tsx +0 -164
  62. package/src/host/__tests__/provision.test.ts +90 -0
  63. package/src/host/http.ts +5 -33
  64. package/src/host/provision.ts +87 -0
  65. package/src/host.ts +8 -0
  66. package/src/i18n/en.ts +127 -1
  67. package/src/i18n/zh.ts +128 -4
  68. package/src/index.ts +1 -1
  69. package/dist/components/StateDot.d.ts +0 -5
  70. package/dist/components/StateDot.js +0 -10
  71. package/dist/host/__tests__/fakes.d.ts +0 -41
  72. package/dist/host/__tests__/fakes.js +0 -76
  73. package/dist/host/__tests__/preflight-fixtures.d.ts +0 -19
  74. package/dist/host/__tests__/preflight-fixtures.js +0 -47
  75. package/dist/host/context-inject.d.ts +0 -24
  76. package/dist/host/context-inject.js +0 -74
  77. package/dist/host/events.d.ts +0 -9
  78. package/dist/host/events.js +0 -70
  79. package/dist/host/mount-units.d.ts +0 -52
  80. package/dist/host/mount-units.js +0 -186
  81. package/dist/host/preflight.d.ts +0 -58
  82. package/dist/host/preflight.js +0 -233
  83. package/dist/host/probe-cache.d.ts +0 -6
  84. package/dist/host/probe-cache.js +0 -19
  85. package/dist/host/probe-libs.d.ts +0 -45
  86. package/dist/host/probe-libs.js +0 -61
  87. package/dist/host/probe-units.d.ts +0 -17
  88. package/dist/host/probe-units.js +0 -102
  89. package/dist/host/probe-verdict.d.ts +0 -7
  90. package/dist/host/probe-verdict.js +0 -143
  91. package/dist/host/tool-scope.d.ts +0 -32
  92. package/dist/host/tool-scope.js +0 -84
  93. package/dist/host/unit-readiness.d.ts +0 -7
  94. package/dist/host/unit-readiness.js +0 -5
  95. package/dist/host/unit-registry.d.ts +0 -9
  96. package/dist/host/unit-registry.js +0 -33
  97. package/dist/host/version-range.d.ts +0 -2
  98. package/dist/host/version-range.js +0 -73
  99. package/src/components/StateDot.tsx +0 -31
package/src/i18n/zh.ts CHANGED
@@ -66,19 +66,24 @@ export const zh = {
66
66
  'panels.market.install': '安装',
67
67
  'panels.market.update': '更新',
68
68
  'panels.market.uninstall': '卸载',
69
+ 'panels.market.uninstallLabel': '卸载 {name}',
69
70
  'panels.market.installing': '正在安装…',
70
71
  'panels.market.updating': '正在更新…',
71
72
  'panels.market.uninstalling': '正在卸载…',
72
- 'panels.market.confirmUninstall': '要卸载吗?',
73
- 'panels.market.confirmUninstallDetail':
74
- '卸载后这台机器上就没有它了,所有项目的面板也会把它一起拿掉(绑定与设置不会丢)。',
75
- 'panels.market.confirmYes': '确定卸载',
73
+ 'panels.market.confirmUninstallTitle': '卸载「{name}」?',
74
+ 'panels.market.confirmUninstallDetail': '卸载后它提供的功能会消失。',
75
+ 'panels.market.confirmUninstallAck': '我明白:卸载后想再用,得重新装一遍。',
76
+ 'panels.market.confirmYes': '卸载',
76
77
  'panels.market.confirmNo': '取消',
77
78
  'panels.market.failed': '没成功:{reason}',
78
79
  'panels.market.needEnv': '先在启动工作台的终端里设 {env}',
79
80
  'panels.market.noSource': '这个模块没声明怎么装,只能自己动手',
80
81
  'panels.market.badSource': '安装方式没写全,只能自己动手',
81
82
  'panels.market.empty': '暂无可用模块',
83
+ 'panels.market.installedSection': '已装',
84
+ 'panels.market.moduleOutdated': '有新版',
85
+ 'panels.market.moduleRestartHint': '安装完成后可能需要重启才生效',
86
+ 'panels.market.restartNeeded': '新版装好了,重启一次才生效。',
82
87
  'panels.market.foot': '装好后到那个项目的面板页勾选它,模块才会出现。',
83
88
  'panels.market.recheck': '重新检查更新',
84
89
  'panels.market.checkUpdates': '检查更新',
@@ -86,6 +91,125 @@ export const zh = {
86
91
  'panels.market.justNow': '刚刚',
87
92
  'panels.market.minutesAgo': '{n} 分钟前',
88
93
  'panels.market.hoursAgo': '{n} 小时前',
94
+ 'panels.market.add.description': '输入模块的包名、Git 仓库地址或本地目录路径。',
95
+ 'panels.market.add.specPlaceholder': '例如 @dsh-workbench/module-hello',
96
+ 'panels.market.add.guideToggle': '模块安装引导和示例',
97
+ 'panels.market.add.guideHide': '收起引导',
98
+ 'panels.market.add.guideIdTitle': '包名',
99
+ 'panels.market.add.guideIdExample': '@dsh-workbench/module-hello',
100
+ 'panels.market.add.guideIdHint': '模块包名即 npm 包名(如 dsh-workbench-module-xxx 或 @作者/模块名),社区模块的 README 安装命令中 dsh plugin add 或 pnpm add 之后的部分。',
101
+ 'panels.market.add.guideGitTitle': 'Git 仓库地址',
102
+ 'panels.market.add.guideGitExample': 'https://github.com/author/dsh-workbench-module-x',
103
+ 'panels.market.add.guideGitHint': '模块在 GitHub 上的开源仓库地址,也支持其他 Git 仓库。',
104
+ 'panels.market.add.guidePathTitle': '本地模块目录',
105
+ 'panels.market.add.guidePathExample': '/Users/name/my-workbench-module',
106
+ 'panels.market.add.guidePathHint': '本机上模块目录的绝对路径,适用于自行开发或已下载的模块。',
107
+ 'panels.market.add.guideExampleLabel': '示例:',
108
+ 'panels.market.add.guideFill': '填入示例',
109
+ 'panels.market.add.guideSafety': '请确认模块来源可信。模块在本机以你的权限运行,来源不明的模块可能损坏工作台,或读取和泄露你的数据。',
110
+ 'panels.market.add.registryLegend': '从哪个 npm 源下载模块',
111
+ 'panels.market.add.registryOfficial': 'npm 官方源',
112
+ 'panels.market.add.registryMirror': '中国大陆镜像源',
113
+ 'panels.market.add.registryWithHost': '{name}({host})',
114
+ 'panels.market.add.registryToggle': '安装源',
115
+ 'panels.market.add.installVersion': '版本 {version}',
116
+ 'panels.market.add.registryDefault': '默认安装源',
117
+ 'panels.market.add.registryCustom': '自定义地址',
118
+ 'panels.market.add.registryCustomPlaceholder': 'https://npm.example.com/',
119
+ 'panels.market.add.registryCustomHint': '公司内网或私有 npm 源;需要登录的源,把凭据放在本机的 ~/.npmrc 里',
120
+ 'panels.market.add.registryCustomInvalid': '请输入以 http:// 或 https:// 开头的地址',
121
+ 'panels.market.add.run': '安装',
122
+ 'panels.market.add.edit': '编辑',
123
+ 'panels.market.add.changeRegistry': '更换安装源',
124
+ 'panels.market.add.installingTitle': '模块安装中…',
125
+ 'panels.market.add.installedTitle': '已安装',
126
+ 'panels.market.add.failedTitle': '模块安装失败',
127
+ 'panels.market.add.cancelledTitle': '已取消',
128
+ 'panels.market.add.failureNetworkHost': '无法连接 {host}。Git 地址和 .tgz 直链不经过安装源,需要本机能直接访问它或配置代理;如果这个模块也发布到了 npm,请改填包名。',
129
+ 'panels.market.add.problemInvalid': '无法识别这个包名或地址:{reason}',
130
+ 'panels.market.add.problemInstalled': '该模块已安装',
131
+ 'panels.market.add.problemNotFound': '未找到相关模块',
132
+ 'panels.market.add.problemNotPackage': '该路径不存在或不是有效的模块包',
133
+ 'panels.market.add.problemNotBundle': '这个包没有声明组合包,无法作为模块安装:{reason}',
134
+ 'panels.market.add.problemNetwork': '无法连接模块源,请检查网络后重试',
135
+ 'panels.market.add.problemUnknown': '无法获取模块信息:{reason}',
136
+ 'panels.market.add.failureNetwork': '网络连接失败',
137
+ 'panels.market.add.failureNotFound': '未找到相关模块',
138
+ 'panels.market.add.failureNoMatchingVersion': '没有匹配的版本',
139
+ 'panels.market.add.failureDiskFull': '磁盘空间不足,安装已停止',
140
+ 'panels.market.add.failurePermission': '没有写入权限,无法安装',
141
+ 'panels.market.add.failureBuildBlocked': '有依赖的安装脚本需要你允许后才能继续',
142
+ 'panels.market.add.failureIntegrity': '下载的安装包校验失败',
143
+ 'panels.market.add.failureTimeout': '安装超时',
144
+ 'panels.market.add.failurePnpmMissing': '没有找到 pnpm,无法安装',
145
+ 'panels.market.add.failureGeneric': '安装过程中出错,原因见安装详情',
146
+ 'panels.market.add.approveTitle': '需要你允许安装脚本',
147
+ 'panels.market.add.approveCaution': '只允许你信得过的包:安装脚本会以你的权限在这台机器上运行。',
148
+ 'panels.market.add.approveRun': '允许并继续安装',
149
+ 'panels.market.add.restart': '装好了,重启一次才生效。',
150
+ 'panels.market.add.tookEffect': '已生效。',
151
+ 'panels.market.add.details': '安装详情',
152
+ 'panels.market.add.open': '添加模块',
153
+ 'panels.market.add.title': '添加模块',
154
+ 'panels.market.add.intro': '按包名装工作台模块。装在这台机器上,所有项目共用。',
155
+ 'panels.market.add.specLabel': '包名',
156
+ 'panels.market.add.specHint': '就是命令里 `dsh plugin add` 后面那一段:包名(可带 @版本)、git 地址、压缩包或本地绝对路径。',
157
+ 'panels.market.add.exampleTitle': '示例',
158
+ 'panels.market.add.exampleFill': '填入示例',
159
+ 'panels.market.add.registryLabel': '安装源',
160
+ 'panels.market.add.registryProfile': '这个 profile 配的源',
161
+ 'panels.market.add.registryPnpm': 'pnpm 自己配的源',
162
+ 'panels.market.add.check': '预检',
163
+ 'panels.market.add.checking': '正在预检…',
164
+ 'panels.market.add.change': '改一下',
165
+ 'panels.market.add.previewTitle': '将要安装',
166
+ 'panels.market.add.fieldName': '包名',
167
+ 'panels.market.add.fieldVersion': '版本',
168
+ 'panels.market.add.fieldDescription': '简介',
169
+ 'panels.market.add.fieldSource': '来源',
170
+ 'panels.market.add.install': '安装',
171
+ 'panels.market.add.installing': '正在安装…',
172
+ 'panels.market.add.cancel': '取消安装',
173
+ 'panels.market.add.close': '关闭',
174
+ 'panels.market.add.retry': '重试',
175
+ 'panels.market.add.changeSource': '换源',
176
+ 'panels.market.add.approveBuilds': '允许这些脚本并重试',
177
+ 'panels.market.add.approveHint': '这几个包要跑安装脚本:{packages}',
178
+ 'panels.market.add.doneApplied': '装好了,已经生效。',
179
+ 'panels.market.add.doneRestart': '装好了,重启一次才生效。',
180
+ 'panels.market.add.cancelled': '已取消。',
181
+ 'panels.market.add.failed': '没成功:{reason}',
182
+ 'panels.market.add.removed': '已经移除了。',
183
+ 'panels.market.add.supplyPending': '它要的插件重启后再装。',
184
+ 'panels.market.add.supplyFailed': '它要的插件没装上:{reason}',
185
+ 'panels.market.add.notModule': '这不是工作台模块(没有 dsh.workbench 声明),不会出现在面板上。',
186
+ 'panels.market.add.removedRestart': '卸掉了,重启一次才彻底生效。',
187
+ 'panels.market.add.remove': '移除它',
188
+ 'panels.market.add.problem.invalidSpec': '这个写法不认:不能是空的,也不能以横杠开头。',
189
+ 'panels.market.add.problem.alreadyInstalled': '这个包已经在 profile 里了(要换版本请带上 @版本)。',
190
+ 'panels.market.add.problem.notFound': '源上没有这个包。',
191
+ 'panels.market.add.problem.notAPackage': '这个位置没有包。',
192
+ 'panels.market.add.problem.notABundle': '它是一个 npm 包,但不是 dsh 插件包(没有 bundle patch)。',
193
+ 'panels.market.add.problem.network': '源连不上。',
194
+ 'panels.market.add.problem.unknown': '预检没通过(原因未知)。',
195
+ 'panels.market.add.reason.invalidSpec': '写法不认',
196
+ 'panels.market.add.reason.incompatible': '它要的 dsh 版本和这台机器上的不一致',
197
+ 'panels.market.add.reason.notBundle': '它不是一个 dsh 插件包',
198
+ 'panels.market.add.reason.notRemovable': '它是安装自带的组合包,不能卸',
199
+ 'panels.market.add.reason.bundleInUse': '还有东西在用它,卸不掉',
200
+ 'panels.market.add.reason.stopProfile': '这个 profile 没开热更新,得先停掉进程',
201
+ 'panels.market.add.reason.staleApproval': '要允许的安装脚本已经变了,重新来一次',
202
+ 'panels.market.add.reason.operationError': 'pnpm 执行出错(详情见安装输出)',
203
+ 'panels.market.add.reason.buildBlocked': 'pnpm 拦下了安装脚本',
204
+ 'panels.market.add.reason.pnpmMissing': '这台机器上没有 pnpm',
205
+ 'panels.market.add.reason.noMatchingVersion': '源上没有符合这个版本范围的版本',
206
+ 'panels.market.add.reason.diskFull': '磁盘满了',
207
+ 'panels.market.add.reason.permission': '没有写权限',
208
+ 'panels.market.add.reason.integrity': '下载内容校验不过',
209
+ 'panels.market.add.reason.timeout': '太久没有输出,被中断了',
210
+ 'panels.market.add.reason.network': '网络不通',
211
+ 'panels.market.add.reason.notFound': '源上没有这个包',
212
+ 'panels.market.add.reason.unknown': '没成功,但它没说是为什么(详情见安装输出的那一行)',
89
213
  'blocker.fix.install': '帮我安装',
90
214
  'blocker.fix.update': '帮我升级',
91
215
  'blocker.fix.running': '正在执行…',
package/src/index.ts CHANGED
@@ -17,7 +17,7 @@ export * from './components/LongTaskRow.js';
17
17
  export * from './components/MockStrip.js';
18
18
  export * from './components/ResourceStates.js';
19
19
  export * from './components/SaveBar.js';
20
- export * from './components/StateDot.js';
20
+ export * from './components/TextField.js';
21
21
  export * from './components/board-module.js';
22
22
  export * from './components/icons.js';
23
23
  export * from './config/constants.js';
@@ -1,5 +0,0 @@
1
- export type DotState = 'ongoing' | 'warning' | 'done' | 'idle' | string;
2
- export declare function StateDot({ state, size }: {
3
- state: DotState;
4
- size: number;
5
- }): JSX.Element;
@@ -1,10 +0,0 @@
1
- import { h } from '../lib/react.js';
2
- export function StateDot({ state, size }) {
3
- if (state === 'ongoing') {
4
- return (h("svg", { className: "wb-loading", viewBox: "0 0 24 24", width: size, height: size, "aria-hidden": "true", style: { display: 'block' } },
5
- h("g", { className: "wb-loadingMotion" },
6
- h("circle", { className: "wb-loadingTrack", cx: 12, cy: 12, r: 9.5 }),
7
- h("circle", { className: "wb-loadingArc", cx: 12, cy: 12, r: 9.5 }))));
8
- }
9
- return (h("span", { className: "wb-stateDot", "data-state": state, style: { width: size, height: size }, "aria-hidden": "true" }));
10
- }
@@ -1,41 +0,0 @@
1
- import type { DshShell } from '../../api/dsh.js';
2
- import type { Opencli } from '../../host/opencli.js';
3
- export interface ShellCall {
4
- command: string;
5
- workdir?: string;
6
- timeoutMs?: number;
7
- onExpiry?: string;
8
- stdoutMaxBytes?: number;
9
- }
10
- export interface ShellReply {
11
- stdout?: string;
12
- stderr?: string;
13
- exitCode?: number | null;
14
- timedOut?: boolean;
15
- aborted?: boolean;
16
- failWith?: Error;
17
- }
18
- export declare function createFakeShell(replies?: ShellReply[] | ((call: ShellCall, index: number) => ShellReply)): {
19
- shell: DshShell;
20
- calls: ShellCall[];
21
- peak: () => number;
22
- commands: () => string[];
23
- };
24
- export interface OpencliCall {
25
- args: readonly string[];
26
- key?: string;
27
- workdir?: string;
28
- refresh?: boolean;
29
- }
30
- export declare function createFakeOpencli(replies?: Array<unknown | Error> | ((call: OpencliCall, index: number) => unknown | Error)): {
31
- opencli: Opencli;
32
- calls: OpencliCall[];
33
- keys: () => (string | undefined)[];
34
- };
35
- export declare function createFakeLogger(): {
36
- logger: {
37
- info: () => void;
38
- warn: (message: string) => void;
39
- };
40
- warnings: string[];
41
- };
@@ -1,76 +0,0 @@
1
- import { setTimeout as delay } from 'node:timers/promises';
2
- const tick = () => delay(0);
3
- export function createFakeShell(replies = []) {
4
- const calls = [];
5
- let running = 0;
6
- let peak = 0;
7
- const replyAt = (index) => typeof replies === 'function' ? replies(calls[index], index) : (replies[index] ?? {});
8
- const shell = {
9
- resolve(request) {
10
- calls.push(request);
11
- return request;
12
- },
13
- async execute() {
14
- const index = calls.length - 1;
15
- const reply = replyAt(index);
16
- if (reply.failWith !== undefined)
17
- throw reply.failWith;
18
- running += 1;
19
- peak = Math.max(peak, running);
20
- return {
21
- async result() {
22
- await tick();
23
- running -= 1;
24
- return {
25
- exitCode: reply.exitCode ?? 0,
26
- timedOut: reply.timedOut ?? false,
27
- aborted: reply.aborted ?? false,
28
- stdout: { text: reply.stdout ?? '', truncated: false },
29
- stderr: { text: reply.stderr ?? '', truncated: false },
30
- };
31
- },
32
- };
33
- },
34
- };
35
- return {
36
- shell,
37
- calls,
38
- peak: () => peak,
39
- commands: () => calls.map((call) => call.command),
40
- };
41
- }
42
- export function createFakeOpencli(replies = []) {
43
- const calls = [];
44
- const opencli = {
45
- async json(args, options = {}) {
46
- const call = {
47
- args,
48
- ...(options.key === undefined ? {} : { key: options.key }),
49
- ...(options.workdir === undefined ? {} : { workdir: options.workdir }),
50
- };
51
- calls.push(call);
52
- const index = calls.length - 1;
53
- const reply = typeof replies === 'function' ? replies(call, index) : (replies[index] ?? []);
54
- if (reply instanceof Error)
55
- throw reply;
56
- return { value: reply, at: Date.now() };
57
- },
58
- };
59
- return {
60
- opencli,
61
- calls,
62
- keys: () => calls.map((call) => call.key),
63
- };
64
- }
65
- export function createFakeLogger() {
66
- const warnings = [];
67
- return {
68
- logger: {
69
- info: () => { },
70
- warn: (message) => {
71
- warnings.push(message);
72
- },
73
- },
74
- warnings,
75
- };
76
- }
@@ -1,19 +0,0 @@
1
- import { createFakeShell } from './fakes';
2
- export declare const GOOD_BRIDGE_REPORT: string;
3
- export declare const ALL_OK: {
4
- stdout: string;
5
- }[];
6
- export declare const STALE_DAEMON_BRIDGE: string;
7
- export declare const BROKEN_BRIDGE: string;
8
- export declare function build(replies: Parameters<typeof createFakeShell>[0], install?: () => Promise<{
9
- ok: boolean;
10
- detail: string;
11
- }>, warmReads?: () => readonly (readonly string[])[]): {
12
- fake: {
13
- shell: import("../..").DshShell;
14
- calls: import("./fakes").ShellCall[];
15
- peak: () => number;
16
- commands: () => string[];
17
- };
18
- preflight: import("../preflight").Preflight;
19
- };
@@ -1,47 +0,0 @@
1
- import { createPreflight } from '../preflight';
2
- import { createFakeShell } from './fakes';
3
- export const GOOD_BRIDGE_REPORT = [
4
- 'opencli v1.8.7 doctor (node v24.15.0)',
5
- '',
6
- '[OK] Daemon: running on port 19825 (v1.8.7)',
7
- '[OK] Extension: connected (v1.0.24)',
8
- '[OK] Connectivity: connected in 0.0s',
9
- '',
10
- 'Everything looks good!',
11
- ].join('\n');
12
- export const ALL_OK = [{ stdout: '1.8.8\n' }, { stdout: GOOD_BRIDGE_REPORT }];
13
- export const STALE_DAEMON_BRIDGE = [
14
- 'opencli v1.8.7 doctor (node v24.15.0)',
15
- '',
16
- '[STALE] Daemon: running on port 19825 (v1.8.8 != CLI v1.8.7)',
17
- '[OK] Extension: connected (v1.0.24)',
18
- '[OK] Connectivity: connected in 0.0s',
19
- '',
20
- 'Issues:',
21
- ' • Stale daemon detected: daemon v1.8.8 != CLI v1.8.7.',
22
- ' Run: opencli daemon restart',
23
- ].join('\n');
24
- export const BROKEN_BRIDGE = [
25
- 'opencli v1.8.7 doctor (node v24.15.0)',
26
- '',
27
- '[MISSING] Daemon: not running',
28
- '[MISSING] Extension: not connected',
29
- '[FAIL] Connectivity: failed (daemon not reachable)',
30
- '',
31
- 'Issues:',
32
- " • Daemon is not running. It should start automatically when you run an opencli browser command.",
33
- ' • Daemon is running but the Chrome/Chromium extension is not connected.',
34
- 'If the extension is not installed:',
35
- ' 1. Download from https://github.com/jackwener/opencli/releases',
36
- ' 2. Open chrome://extensions/ → Enable Developer Mode',
37
- ' 3. Click "Load unpacked" → select the extension folder',
38
- ].join('\n');
39
- export function build(replies, install, warmReads) {
40
- const fake = createFakeShell(replies);
41
- const preflight = createPreflight({
42
- shell: fake.shell,
43
- ...(install === undefined ? {} : { install }),
44
- ...(warmReads === undefined ? {} : { warmReads }),
45
- });
46
- return { fake, preflight };
47
- }
@@ -1,24 +0,0 @@
1
- import { type ContextRef } from '@dsh-workbench/shared';
2
- import type { ContextRenderer } from './unit-face';
3
- export declare const CONTEXT_SOURCE_KIND = "workbench";
4
- export interface ScannableMessage {
5
- readonly source?: {
6
- readonly kind?: string;
7
- };
8
- readonly content?: readonly {
9
- readonly type?: string;
10
- readonly text?: string;
11
- }[];
12
- }
13
- export type { ContextRenderer };
14
- export declare function collectContextRefs(messages: readonly ScannableMessage[]): ContextRef[];
15
- export declare function buildContextMessage(text: string, summary: string): unknown;
16
- export interface ContextInjector {
17
- inject(messages: readonly ScannableMessage[], agent: unknown): Promise<unknown | undefined>;
18
- }
19
- export declare function createContextInjector(options: {
20
- renderers: ReadonlyMap<string, ContextRenderer>;
21
- logger?: {
22
- warn?(message: string): void;
23
- } | undefined;
24
- }): ContextInjector;
@@ -1,74 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { encodeRef, parseMarkers } from '@dsh-workbench/shared';
3
- export const CONTEXT_SOURCE_KIND = 'workbench';
4
- export function collectContextRefs(messages) {
5
- const seen = new Set();
6
- const refs = [];
7
- for (const message of messages) {
8
- if (message.source?.kind !== 'user')
9
- continue;
10
- for (const block of message.content ?? []) {
11
- if (block.type !== 'text' || typeof block.text !== 'string')
12
- continue;
13
- for (const ref of parseMarkers(block.text)) {
14
- const key = encodeRef(ref);
15
- if (seen.has(key))
16
- continue;
17
- seen.add(key);
18
- refs.push(ref);
19
- }
20
- }
21
- }
22
- return refs;
23
- }
24
- export function buildContextMessage(text, summary) {
25
- return {
26
- role: 'user',
27
- id: randomUUID(),
28
- content: [{ type: 'text', text }],
29
- source: { kind: CONTEXT_SOURCE_KIND, form: 'notice', summary },
30
- };
31
- }
32
- export function createContextInjector(options) {
33
- const done = new WeakMap();
34
- return {
35
- async inject(messages, agent) {
36
- const refs = collectContextRefs(messages);
37
- if (refs.length === 0)
38
- return undefined;
39
- const key = typeof agent === 'object' && agent !== null ? agent : undefined;
40
- const seen = key === undefined ? undefined : (done.get(key) ?? new Set());
41
- if (key !== undefined && seen !== undefined)
42
- done.set(key, seen);
43
- const fresh = [];
44
- for (const ref of refs) {
45
- const encoded = encodeRef(ref);
46
- if (seen?.has(encoded) === true)
47
- continue;
48
- seen?.add(encoded);
49
- fresh.push(ref);
50
- }
51
- if (fresh.length === 0)
52
- return undefined;
53
- const texts = [];
54
- for (const ref of fresh) {
55
- const render = options.renderers.get(ref.kind);
56
- if (render === undefined)
57
- continue;
58
- let text;
59
- try {
60
- text = await render(ref);
61
- }
62
- catch (error) {
63
- options.logger?.warn?.(`[dsh-workbench] 渲染对话引用失败:${String(error)}`);
64
- text = `工作台面板引用了一条内容(${encodeRef(ref)}),但当前渲染不出来(项目未选中或数据源不可用)。`;
65
- }
66
- if (text !== '')
67
- texts.push(text);
68
- }
69
- if (texts.length === 0)
70
- return undefined;
71
- return buildContextMessage(texts.join('\n\n'), `工作台引用:${fresh.length} 条`);
72
- },
73
- };
74
- }
@@ -1,9 +0,0 @@
1
- import type { DshHostContext, DshRequest, DshResponse } from '@dsh-workbench/shared';
2
- import type { FactLog } from './facts';
3
- export interface FactStream {
4
- handler(req: DshRequest, res: DshResponse): void;
5
- closeAll(): void;
6
- size(): number;
7
- }
8
- export declare function createFactStream(log: FactLog): FactStream;
9
- export declare function registerFactStream(ctx: DshHostContext, log: FactLog): () => void;
@@ -1,70 +0,0 @@
1
- import { EVENTS_PATH } from '@dsh-workbench/shared';
2
- const HEARTBEAT_MS = 25_000;
3
- function frame(payload) {
4
- return `data: ${JSON.stringify(payload)}\n\n`;
5
- }
6
- export function createFactStream(log) {
7
- const connections = new Set();
8
- const cleanups = new Map();
9
- const drop = (res) => {
10
- cleanups.get(res)?.();
11
- cleanups.delete(res);
12
- connections.delete(res);
13
- };
14
- return {
15
- size: () => connections.size,
16
- closeAll() {
17
- for (const res of [...connections]) {
18
- drop(res);
19
- res.end?.();
20
- }
21
- },
22
- handler(req, res) {
23
- if (req.method !== undefined && req.method !== 'GET') {
24
- res.statusCode = 405;
25
- res.end();
26
- return;
27
- }
28
- const url = req.url ?? '/';
29
- const cut = url.indexOf('?');
30
- const since = Number(new URLSearchParams(cut === -1 ? '' : url.slice(cut + 1)).get('since') ?? 0) || 0;
31
- const opening = log.since(since);
32
- if (typeof res.write !== 'function') {
33
- res.statusCode = 200;
34
- res.setHeader('content-type', 'application/json; charset=utf-8');
35
- res.end(JSON.stringify({ ok: true, ...opening }));
36
- return;
37
- }
38
- const headers = {
39
- 'content-type': 'text/event-stream; charset=utf-8',
40
- 'cache-control': 'no-store, no-transform',
41
- connection: 'keep-alive',
42
- };
43
- if (typeof res.writeHead === 'function')
44
- res.writeHead(200, headers);
45
- else {
46
- res.statusCode = 200;
47
- for (const [name, value] of Object.entries(headers))
48
- res.setHeader(name, value);
49
- }
50
- res.write(': connected\n\n');
51
- res.write(frame({ type: 'sync', ...opening }));
52
- connections.add(res);
53
- const timer = setInterval(() => res.write?.(': ping\n\n'), HEARTBEAT_MS);
54
- const unsubscribe = log.subscribe((change) => res.write?.(frame({ type: 'bump', ...change })));
55
- cleanups.set(res, () => {
56
- clearInterval(timer);
57
- unsubscribe();
58
- });
59
- res.on?.('close', () => drop(res));
60
- },
61
- };
62
- }
63
- export function registerFactStream(ctx, log) {
64
- const stream = createFactStream(log);
65
- const unregister = ctx.webServer.register({ kind: 'exact', path: EVENTS_PATH, handler: stream.handler });
66
- return () => {
67
- stream.closeAll();
68
- unregister();
69
- };
70
- }
@@ -1,52 +0,0 @@
1
- import type { DshHostContext } from '@dsh-workbench/shared';
2
- import type { UnitManifest } from '@dsh-workbench/shared';
3
- import { type RouteTable } from './http';
4
- import type { ContextRenderer, UnitHostFace, UnitMountDeps, UnitMountResult, UnitCall } from './unit-face';
5
- import { type UnitReadiness } from './unit-readiness';
6
- export interface MountedUnit {
7
- readonly face: UnitHostFace;
8
- readonly result: UnitMountResult;
9
- readonly readiness: UnitReadiness;
10
- }
11
- export interface UnitsPlan {
12
- readonly mounted: readonly MountedUnit[];
13
- readonly routes: RouteTable;
14
- readonly gate: UnitMountResult['gate'];
15
- readonly prefs: ReadonlyArray<{
16
- readonly resource: string;
17
- readonly unit: string;
18
- handle(payload: unknown): unknown;
19
- }>;
20
- readonly actions: ReadonlyArray<{
21
- readonly resource: string;
22
- readonly unit: string;
23
- handle(payload: unknown): unknown;
24
- }>;
25
- readonly provision: UnitMountResult['provision'];
26
- readonly contextRenderers: ReadonlyMap<string, ContextRenderer>;
27
- readonly owners: ReadonlyMap<string, string>;
28
- readonly routesOfUnit: ReadonlyMap<string, readonly string[]>;
29
- readonly factsOf: ReadonlyMap<string, (call: UnitCall) => readonly string[] | undefined>;
30
- readonly skipped: ReadonlyArray<{
31
- readonly id: string;
32
- readonly missing: readonly string[];
33
- }>;
34
- readonly warmReads: () => readonly (readonly string[])[];
35
- readonly disposeLongTasks: () => void;
36
- }
37
- export declare function mountUnits(faces: readonly UnitHostFace[], deps: {
38
- ctx: DshHostContext;
39
- logger?: {
40
- info?(m: string): void;
41
- warn?(m: string): void;
42
- } | undefined;
43
- manifests: () => readonly UnitManifest[];
44
- opencliCommand?: string;
45
- probe?: UnitMountDeps['probe'];
46
- store?: UnitMountDeps['store'];
47
- values?: UnitMountDeps['values'];
48
- longTasks?: {
49
- readonly scope: string;
50
- readonly bump: (facts: readonly string[]) => void;
51
- } | undefined;
52
- }): UnitsPlan;