@stardustlc/dsh-docker 0.5.7 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # 更新记录
2
2
 
3
+ ## 0.5.8 (2026-11-03)
4
+
5
+ - 按 daemon、权限、CLI、无容器、端口冲突、超时区分失败并给下一步;空容器与空日志补指引。
6
+ - Failures distinguish daemon, permission, CLI, missing container, port conflict and timeout with next steps; empty containers and logs are explained.
7
+
3
8
  ## 0.5.7 (2026-10-30)
4
9
 
5
10
  - 重整中英文首页:用途、三步流程图、安装入口与操作示例;详细配置与边界集中到完整说明。
package/docs/USAGE.en.md CHANGED
@@ -78,6 +78,20 @@ pnpm install
78
78
  pnpm test # build + 35 tests
79
79
  ```
80
80
 
81
+ ## Troubleshooting
82
+
83
+ Run `docker_health` first: it checks `docker version`, the exec/manage approval gates, and timeout settings, and each failing check carries the next step.
84
+
85
+ | Symptom | Usual cause | What to do |
86
+ | :-- | :-- | :-- |
87
+ | `Cannot connect to the Docker daemon` | Daemon not running | Start Docker Desktop / dockerd; on Windows use the WSL2 or Hyper-V backend |
88
+ | `permission denied … docker.sock` | Current user is not in the docker group | Add the user to the docker group and re-login (Linux/macOS); on Windows run Docker Desktop as administrator |
89
+ | `docker: command not found` | docker is not on PATH | Install the Docker CLI, or point `dockerPath` at the full executable path |
90
+ | `No such container` / `No such image` | Wrong name/ID, or the object was removed | Use `docker_ps all=true` / `docker_images` to find the real name |
91
+ | `port is already allocated` | Another container holds the port | Find it with `docker_ps` and stop it, or map a different port |
92
+ | `docker logs` returns nothing | No output yet, or a non-json-file logging driver | Check state and start time with `docker_inspect`, then raise `tail` |
93
+ | Command times out | Busy target or slow network | Verify the container/host, then raise `timeoutMs` and retry |
94
+
81
95
  ## License
82
96
 
83
97
  MIT
package/docs/USAGE.md CHANGED
@@ -78,6 +78,20 @@ pnpm install
78
78
  pnpm test # 构建并执行测试
79
79
  ```
80
80
 
81
+ ## 故障排查
82
+
83
+ 先运行 `docker_health`:它检查 `docker version`、exec/manage 审批门与超时配置,失败项后面会直接给出下一步。
84
+
85
+ | 现象 | 常见原因 | 处理 |
86
+ | :-- | :-- | :-- |
87
+ | `Cannot connect to the Docker daemon` | 守护进程没启动 | 启动 Docker Desktop / dockerd;Windows 需要 WSL2 或 Hyper-V 后端 |
88
+ | `permission denied … docker.sock` | 当前用户不在 docker 组 | Linux/macOS 加入 docker 组后重新登录;Windows 以管理员身份启动 Docker Desktop |
89
+ | `docker: command not found` | PATH 里没有 docker | 安装 Docker CLI,或在插件配置里用 `dockerPath` 指定完整路径 |
90
+ | `No such container` / `No such image` | 名字或 ID 写错,对象已被删除 | 用 `docker_ps all=true` / `docker_images` 查真实名字 |
91
+ | `port is already allocated` | 端口被其它容器占用 | 先 `docker_ps` 找到占用者并停止,或改用其它端口 |
92
+ | `docker logs` 输出为空 | 进程还没输出,或日志驱动不是 json-file | 用 `docker_inspect` 看状态与启动时间,再调大 `tail` |
93
+ | 命令超时 | 目标繁忙或网络慢 | 确认容器/主机状态后调大 `timeoutMs` 重试 |
94
+
81
95
  ## License
82
96
 
83
97
  MIT
package/lib/tools.d.ts CHANGED
@@ -20,5 +20,13 @@ export interface DockerToolDefinition {
20
20
  execute(args: unknown, exec: unknown): Promise<unknown>;
21
21
  timeoutMs?: number;
22
22
  }
23
+ /**
24
+ * 把 docker 的原始 stderr 映射成一行可执行的「下一步」。
25
+ *
26
+ * 原来非零退出只提示「请确认 docker 可用(docker version)」,守护进程没起、
27
+ * 权限不足、容器名写错、端口冲突看起来都一样,用户只能反复试。原始输出保留,
28
+ * 这里只追加一条最可能的原因与动作。
29
+ */
30
+ export declare function dockerErrorHint(text: string): string | undefined;
23
31
  /** 构建七个工具定义。 */
24
32
  export declare function buildDockerTools(config: ResolvedDockerConfig, runner: ProcessRunner, policyOf?: (execution: unknown) => DockerApprovalPolicy): DockerToolDefinition[];
package/lib/tools.js CHANGED
@@ -44,13 +44,40 @@ function executionSignal(exec) {
44
44
  const signal = exec.signal;
45
45
  return signal instanceof AbortSignal ? signal : undefined;
46
46
  }
47
+ /**
48
+ * 把 docker 的原始 stderr 映射成一行可执行的「下一步」。
49
+ *
50
+ * 原来非零退出只提示「请确认 docker 可用(docker version)」,守护进程没起、
51
+ * 权限不足、容器名写错、端口冲突看起来都一样,用户只能反复试。原始输出保留,
52
+ * 这里只追加一条最可能的原因与动作。
53
+ */
54
+ export function dockerErrorHint(text) {
55
+ if (/Cannot connect to the Docker daemon|Is the docker daemon running|docker\.sock: connect|open .*docker\.sock/i.test(text))
56
+ return '守护进程不可达:请启动 Docker Desktop / dockerd(Windows 需 WSL2 或 Hyper-V 后端),再运行 docker_health 复查。';
57
+ if (/permission denied/i.test(text))
58
+ return '权限不足:Linux/macOS 把用户加入 docker 组并重新登录,Windows 以管理员身份启动 Docker Desktop 后重试。';
59
+ if (/command not found|not recognized as the name|ENOENT|no such file or directory/i.test(text))
60
+ return '找不到 docker 命令:请安装 Docker CLI,或在插件配置里用 dockerPath 指定完整可执行文件路径。';
61
+ if (/[Nn]o such container/i.test(text))
62
+ return '容器不存在:用 docker_ps all=true 查真实容器名或 ID(注意大小写),再重试。';
63
+ if (/[Nn]o such image/i.test(text))
64
+ return '镜像不存在:用 docker_images 查看本地镜像,或先 docker pull 该镜像。';
65
+ if (/context deadline exceeded|i\/o timeout|timed out|timeout/i.test(text))
66
+ return '命令超时:确认目标机器与容器状态,必要时调大插件配置里的 timeoutMs 后重试。';
67
+ if (/port is already allocated|address already in use/i.test(text))
68
+ return '端口已被占用:先用 docker_ps 找到占用端口的容器并停止,或改用其它端口。';
69
+ if (/Conflict\. The container name/i.test(text))
70
+ return '容器名冲突:已有同名容器,请改名,或用 docker_ps 找到现有容器先停掉/删除。';
71
+ return undefined;
72
+ }
47
73
  async function runChecked(runner, argv, timeoutMs, label, signal) {
48
74
  signal?.throwIfAborted();
49
75
  const result = await runner.run(argv, { timeoutMs, ...(signal === undefined ? {} : { signal }) });
50
76
  signal?.throwIfAborted();
51
77
  if (result.exitCode !== 0) {
52
78
  const tail = result.stderr.trim().split(/\r?\n/).slice(-6).join(' | ');
53
- throw new Error(label + '失败(退出码 ' + String(result.exitCode ?? 'null') + '):' + (tail || '无错误输出') + '。请确认 docker 可用(docker version)。');
79
+ const next = dockerErrorHint(result.stderr) ?? '请确认 docker 可用(docker version)。';
80
+ throw new Error(label + '失败(退出码 ' + String(result.exitCode ?? 'null') + '):' + (tail || '无错误输出') + '。' + next);
54
81
  }
55
82
  return result;
56
83
  }
@@ -105,10 +132,17 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
105
132
  render: (_args, value) => {
106
133
  const rec = asRecord(value);
107
134
  const containers = Array.isArray(rec.containers) ? rec.containers : [];
135
+ if (containers.length === 0) {
136
+ const onlyRunning = rec.all !== true;
137
+ return [{ type: 'text', text: onlyRunning
138
+ ? '没有正在运行的容器。下一步:用 docker_ps all=true 查看已停止的容器;确认 Docker 已启动的话也可以运行 docker_health。'
139
+ : '没有任何容器(含已停止)。下一步:用 docker_images 确认镜像是否已拉到本地,或用 docker_health 检查守护进程。' }];
140
+ }
108
141
  const lines = ['共 ' + containers.length + ' 个容器:'];
109
142
  for (const item of containers) {
110
143
  const c = asRecord(item);
111
- lines.push('- ' + c.name + '(' + c.image + ',' + c.state + ')');
144
+ const detail = typeof c.status === 'string' && c.status !== '' ? c.status : c.state;
145
+ lines.push('- ' + c.name + '(' + c.image + ',' + detail + ')');
112
146
  }
113
147
  return [{ type: 'text', text: lines.join('\n') }];
114
148
  },
@@ -134,7 +168,11 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
134
168
  schema: logsSchema,
135
169
  render: (_args, value) => {
136
170
  const rec = asRecord(value);
137
- return [{ type: 'text', text: '容器 ' + rec.container + ' 最近日志:\n' + rec.text }];
171
+ const text = typeof rec.text === 'string' ? rec.text : '';
172
+ if (text.trim() === '') {
173
+ return [{ type: 'text', text: '容器 ' + rec.container + ' 最近 ' + String(rec.tail ?? '') + ' 行日志为空:进程可能还没输出、日志驱动不是 json-file,或该时间段内没有写入。下一步:用 docker_inspect 看状态与启动时间,或调大 tail 再取一次。' }];
174
+ }
175
+ return [{ type: 'text', text: '容器 ' + rec.container + ' 最近日志:\n' + text }];
138
176
  },
139
177
  },
140
178
  async execute(rawArgs, exec) {
@@ -187,7 +225,10 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
187
225
  render: (_args, value) => {
188
226
  const rec = asRecord(value);
189
227
  const info = asRecord(rec.info);
190
- return [{ type: 'text', text: '容器 ' + info.name + '(' + info.image + '):' + (info.running === true ? '运行中' : '已停止') + ',端口:' + (Array.isArray(info.ports) ? info.ports.join(', ') : '无') }];
228
+ const ports = Array.isArray(info.ports) && info.ports.length > 0 ? info.ports.join(', ') : '无端口映射';
229
+ const started = typeof info.startedAt === 'string' && info.startedAt !== '' ? ',启动于 ' + info.startedAt : '';
230
+ const state = typeof info.state === 'string' && info.state !== '' ? info.state : (info.running === true ? 'running' : 'exited');
231
+ return [{ type: 'text', text: '容器 ' + info.name + '(' + info.image + '):' + state + started + ',端口:' + ports + '。下一步:docker_logs 看日志,docker_exec 进容器排查。' }];
191
232
  },
192
233
  },
193
234
  async execute(rawArgs, exec) {
@@ -237,7 +278,8 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
237
278
  schema: manageSchema,
238
279
  render: (_args, value) => {
239
280
  const rec = asRecord(value);
240
- return [{ type: 'text', text: '容器 ' + rec.container + ' 已执行 ' + rec.action + '。' }];
281
+ const output = typeof rec.output === 'string' && rec.output.trim() !== '' ? '\n' + rec.output : '';
282
+ return [{ type: 'text', text: '容器 ' + rec.container + ' 已执行 ' + rec.action + '。下一步:用 docker_ps 确认当前状态。' + output }];
241
283
  },
242
284
  },
243
285
  async execute(rawArgs, exec) {
@@ -261,9 +303,21 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
261
303
  const rec = asRecord(value);
262
304
  const checks = Array.isArray(rec.checks) ? rec.checks : [];
263
305
  const lines = ['dsh-docker 自检' + (rec.ok === true ? ':正常。' : ':发现问题。')];
306
+ const failed = [];
264
307
  for (const item of checks) {
265
308
  const c = asRecord(item);
266
309
  lines.push('- ' + c.name + ':' + (c.ok === true ? '✅ ' : '❌ ') + String(c.detail ?? ''));
310
+ if (c.ok !== true)
311
+ failed.push(String(c.name));
312
+ }
313
+ if (failed.length > 0) {
314
+ lines.push('', '下一步:');
315
+ if (failed.includes('docker daemon'))
316
+ lines.push(' · 启动 Docker Desktop / dockerd 后重新运行 docker_health;命令找不到时在插件配置里用 dockerPath 指定完整路径。');
317
+ if (failed.some(name => name.includes('审批门')))
318
+ lines.push(' · 审批门不可用时,把会话审批策略切到可询问(ask),或由用户明确设置 execApproval / manageApproval = false(之后不再询问,慎用)。');
319
+ if (!failed.some(name => name.includes('审批门')) && !failed.includes('docker daemon'))
320
+ lines.push(' · 按上面 ❌ 项的说明处理后重新运行 docker_health 复查。');
267
321
  }
268
322
  return [{ type: 'text', text: lines.join('\n') }];
269
323
  },
@@ -285,6 +339,7 @@ export function buildDockerTools(config, runner, policyOf = () => 'unknown') {
285
339
  checks.push({ name: 'exec 审批门', ...dockerApprovalCheck(cfg.execApproval, policy, 'execApproval') });
286
340
  checks.push({ name: 'manage 审批门', ...dockerApprovalCheck(cfg.manageApproval, policy, 'manageApproval') });
287
341
  checks.push({ name: '超时配置', ok: true, detail: 'timeoutMs=' + cfg.timeoutMs + ', graceMs=' + cfg.graceMs });
342
+ checks.push({ name: 'docker 命令', ok: true, detail: cfg.dockerPath + '(可用 dockerPath 配置覆盖)' });
288
343
  return { ok: ok && checks.every(check => check.ok === true), plugin: 'dsh-docker', approvalPolicy: policy, checks };
289
344
  },
290
345
  timeoutMs: 20000,
@@ -437,7 +437,7 @@ function __stardustUpdatesClient(ctx, React, require, shared) {
437
437
  }
438
438
 
439
439
  /* STARDUSTLC_UPDATE_CLIENT_BODY_START */
440
- window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"@stardustlc/dsh-docker",factory:require=>({apply(){}})},{"name":"@stardustlc/dsh-docker","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.5.7","label":"Docker","labelEn":"Docker","suiteComponent":true}));
440
+ window.__ModuleLoader__.load(__stardustUpdatesWrap({id:"@stardustlc/dsh-docker",factory:require=>({apply(){}})},{"name":"@stardustlc/dsh-docker","version":"0.1.0","hasWorkbench":false,"packageVersion":"0.5.8","label":"Docker","labelEn":"Docker","suiteComponent":true}));
441
441
 
442
442
  /* STARDUSTLC_UPDATE_CLIENT_BODY_END */
443
443
  })();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stardustlc/dsh-docker",
3
- "version": "0.5.7",
4
- "description": "在 DSH 里看容器状态、读日志、处理问题。 需要已运行且当前用户可访问的 Docker Engine 欢迎提交 issues 和 PR。",
3
+ "version": "0.5.8",
4
+ "description": "DSH Docker 工具:容器与镜像管理、日志、状态检查及操作确认;清楚报告权限原因。欢迎提交 issues 和 PR。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -26,8 +26,8 @@
26
26
  "scripts": {
27
27
  "build": "tsc -p tsconfig.json && node scripts/build-updates.mjs",
28
28
  "typecheck": "tsc -p tsconfig.json --noEmit",
29
- "test": "pnpm run build && node --test \"test/*.test.mjs\"",
30
- "prepublishOnly": "pnpm run build"
29
+ "test": "npm run build && node --test \"test/*.test.mjs\"",
30
+ "prepublishOnly": "npm run build"
31
31
  },
32
32
  "dsh": {
33
33
  "bundle": {