@online-tools/work-agent-runner 0.0.5-alpha-1 → 0.1.0-alpha-2
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 +65 -0
- package/README.md +289 -116
- package/bin/main.mjs +1948 -436
- package/lib/check.mjs +391 -0
- package/lib/claude-cli.mjs +8 -0
- package/lib/claude-install.mjs +221 -0
- package/lib/config.mjs +48 -4
- package/lib/connection.mjs +87 -4
- package/lib/control.mjs +330 -0
- package/lib/diagnose.mjs +82 -0
- package/lib/doctor.mjs +19 -3
- package/lib/errors.mjs +43 -0
- package/lib/jobs.mjs +428 -91
- package/lib/log.mjs +100 -7
- package/lib/maintenance.mjs +394 -0
- package/lib/sandbox.mjs +55 -6
- package/lib/service.mjs +42 -6
- package/lib/setup-state.mjs +119 -0
- package/lib/setup.mjs +4 -1
- package/lib/state.mjs +145 -0
- package/lib/uninstall.mjs +122 -0
- package/lib/views.mjs +260 -0
- package/lib/work-agent.mjs +27 -6
- package/package.json +2 -2
package/lib/doctor.mjs
CHANGED
|
@@ -8,7 +8,8 @@ import fs from 'node:fs';
|
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import readline from 'node:readline';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { readApparmor, readUserns, sandboxProblem } from './check.mjs';
|
|
12
|
+
import { VERIFIED_CLAUDE_VERSION, claudeArgs, claudeEnv } from './claude-cli.mjs';
|
|
12
13
|
import { removeTree } from './fs-safe.mjs';
|
|
13
14
|
import { SANDBOX_TOOLS, SKILL_TOOLS, detectPackageManager } from './packages.mjs';
|
|
14
15
|
import { PROBE_MARKER, PROBE_TOOL_ID, startProbeModel } from './probe-model.mjs';
|
|
@@ -256,7 +257,8 @@ export async function probeSandbox({
|
|
|
256
257
|
/**
|
|
257
258
|
* Full check. `probe: false` skips the sandbox probe (it then reads as not
|
|
258
259
|
* checked). `workAgent`: a WorkAgent, whose clone and pool are reported as
|
|
259
|
-
* capabilities and mounted into the probe exactly as into a job.
|
|
260
|
+
* capabilities and mounted into the probe exactly as into a job. `apparmorFacts`
|
|
261
|
+
* / `usernsFacts` read the system (injected by tests). Returns
|
|
260
262
|
* { capabilities, tools, claude, claudeVersion, packageManager, workAgent }.
|
|
261
263
|
*/
|
|
262
264
|
export async function runDoctor({
|
|
@@ -269,6 +271,9 @@ export async function runDoctor({
|
|
|
269
271
|
workAgent = null,
|
|
270
272
|
probe = true,
|
|
271
273
|
probeTimeoutMs = PROBE_TIMEOUT_MS,
|
|
274
|
+
apparmorFacts = readApparmor,
|
|
275
|
+
usernsFacts = readUserns,
|
|
276
|
+
managedDir = '',
|
|
272
277
|
}) {
|
|
273
278
|
const pathEnv = env.PATH || '';
|
|
274
279
|
const tools = checkTools({ platform, pathEnv });
|
|
@@ -291,9 +296,15 @@ export async function runDoctor({
|
|
|
291
296
|
timeoutMs: probeTimeoutMs,
|
|
292
297
|
});
|
|
293
298
|
if (!sandbox.ok && platform === 'linux') {
|
|
294
|
-
// The common
|
|
299
|
+
// The common cases, in words the user can act on: missing tools (setup
|
|
300
|
+
// installs them), AppArmor's user-namespace restriction (E1402, an
|
|
301
|
+
// administrator's call). Claude Code's own words stay in `raw` for `check`.
|
|
295
302
|
const missing = SANDBOX_TOOLS.filter((name) => !tools[name]?.ok).map((name) => (name === 'bwrap' ? 'bubblewrap' : name));
|
|
296
303
|
if (missing.length) sandbox = { ok: false, reason: `缺少 ${missing.join('、')}` };
|
|
304
|
+
else {
|
|
305
|
+
const problem = sandboxProblem({ reason: sandbox.reason, platform, apparmor: apparmorFacts(), userns: usernsFacts() });
|
|
306
|
+
if (problem.code === 'E1402') sandbox = { ok: false, reason: 'AppArmor 限制了非特权 user namespace(E1402,运行 work-agent-runner check 查看)', raw: sandbox.reason };
|
|
307
|
+
}
|
|
297
308
|
}
|
|
298
309
|
}
|
|
299
310
|
return {
|
|
@@ -308,6 +319,11 @@ export async function runDoctor({
|
|
|
308
319
|
// This program runs 交互执行 jobs (lib/interaction.mjs, since 0.0.3); the
|
|
309
320
|
// website only sends `interactive: true` to machines that say so.
|
|
310
321
|
interactive: true,
|
|
322
|
+
// Jobs report their phases (machine_status lines, POST …/started; 0.1.0-alpha-2).
|
|
323
|
+
jobPhases: true,
|
|
324
|
+
// Installed by this program (claude/<version>/claude) or by the user; the version it was tested with?
|
|
325
|
+
claudeSource: claude.path ? (managedDir && claude.path.startsWith(`${managedDir}${path.sep}`) ? 'managed' : 'external') : '',
|
|
326
|
+
claudeVerified: Boolean(version) && version === VERIFIED_CLAUDE_VERSION,
|
|
311
327
|
workAgent: repo
|
|
312
328
|
? { commit: repo.commit, committedAt: repo.committedAt, repos: repo.repos, ascend: repo.ascend }
|
|
313
329
|
: { commit: '', committedAt: '', repos: 0, ascend: false },
|
package/lib/errors.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Error codes (docs/design.md 附录 B) the program writes into its job history,
|
|
2
|
+
// its status and the messages it sends: one code per kind of failure, so a
|
|
3
|
+
// report can be matched to its explanation. Only what the program reports so
|
|
4
|
+
// far; the catalog grows with it.
|
|
5
|
+
|
|
6
|
+
export const ERROR_CODES = {
|
|
7
|
+
E1103: '以 root 运行',
|
|
8
|
+
E1105: '工作目录路径过长(沙箱 socket)',
|
|
9
|
+
E1112: '本机管理接口无法启动(socket 路径太长或目录不安全)',
|
|
10
|
+
E1115: 'work-agent 克隆目录不是本程序创建的',
|
|
11
|
+
E1201: '缺少依赖',
|
|
12
|
+
E1301: 'Claude Code 未安装或无法运行',
|
|
13
|
+
E1302: 'Claude Code 下载或校验失败',
|
|
14
|
+
E1402: 'AppArmor 限制了非特权 user namespace',
|
|
15
|
+
E2101: '无法连接网站',
|
|
16
|
+
E2201: '接入令牌无效或已删除',
|
|
17
|
+
E2202: '机器已被封禁',
|
|
18
|
+
E3101: '任务参数不合法',
|
|
19
|
+
E3201: '等待执行条件超时',
|
|
20
|
+
E3301: '工作目录磁盘空间不足',
|
|
21
|
+
E3401: '准备任务失败',
|
|
22
|
+
E3501: '输出无法送达网站',
|
|
23
|
+
E4101: '沙箱不可用',
|
|
24
|
+
E5101: 'work-agent 仓库刷新失败',
|
|
25
|
+
E5201: '知识仓更新失败',
|
|
26
|
+
E5202: '知识仓长时间未能更新',
|
|
27
|
+
E5301: '清理失败(已移入回收站)',
|
|
28
|
+
E9000: '本机管理接口:操作失败',
|
|
29
|
+
E9001: '本机管理接口:令牌不正确',
|
|
30
|
+
E9002: '本机管理接口:已被另一个进程占用',
|
|
31
|
+
E9003: '本机管理接口:请求格式不正确',
|
|
32
|
+
E9004: '本机管理接口:两端版本不一致',
|
|
33
|
+
E9005: '本机管理接口:不支持的操作',
|
|
34
|
+
E9006: '本机管理接口:程序没有响应',
|
|
35
|
+
E9007: '仓名不正确',
|
|
36
|
+
E9008: '知识仓正被另一个进程下载或更新',
|
|
37
|
+
E9009: '任务 ID 对应多个任务',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** "message(E3201)": the code goes last, so the sentence still reads first. */
|
|
41
|
+
export function withCode(code, message) {
|
|
42
|
+
return code ? `${message}(${code})` : message;
|
|
43
|
+
}
|