work-rhythm 0.1.0 → 0.1.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/.agents/notes/AGENTS.md +4 -1
- package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md +1 -0
- package/.agents/notes/decisions/2026-11-30-no-workdir-offers-to-create-one-by-default.md +1 -0
- package/.agents/notes/decisions/2026-11-30-scheduling-moves-to-a-local-service.md +1 -0
- package/.agents/notes/decisions/2026-12-01-everything-is-js-behind-work-rhythm.md +1 -0
- package/.agents/notes/decisions/2026-12-01-repo-is-not-a-workdir-templates-hold-workdir-files.md +29 -0
- package/.agents/notes/decisions/2026-12-01-repo-stays-generic-personal-data-lives-in-workdirs.md +32 -0
- package/.agents/notes/decisions/2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md +31 -0
- package/.agents/notes/decisions/2026-12-01-workdir-is-not-a-git-repository.md +25 -0
- package/.agents/skills/work-rhythm/SKILL.md +16 -13
- package/AGENTS.md +12 -24
- package/README.md +35 -70
- package/collectors/local.env.example +5 -3
- package/docs/agents.md +49 -0
- package/docs/channels.md +2 -2
- package/docs/formats.md +1 -1
- package/docs/scheduled-tasks.md +2 -12
- package/package.json +2 -4
- package/scripts/cli.js +9 -5
- package/scripts/cmd/agent.js +110 -0
- package/scripts/cmd/check.js +90 -43
- package/scripts/cmd/init.js +3 -7
- package/scripts/cmd/pack.js +1 -2
- package/scripts/lib/agent.js +156 -17
- package/scripts/lib/bot.js +1 -1
- package/scripts/lib/log.js +1 -1
- package/scripts/lib/rhythm.js +1 -1
- package/scripts/lib/template.js +31 -26
- package/scripts/lib/workdir.js +13 -4
- package/scripts/test/agent.test.js +199 -0
- package/scripts/test/check.test.js +94 -10
- package/scripts/test/config.test.js +6 -9
- package/scripts/test/goals.test.js +1 -1
- package/scripts/test/harness.js +7 -6
- package/scripts/test/init.test.js +9 -11
- package/scripts/test/listen.test.js +2 -2
- package/scripts/test/pack.test.js +1 -1
- package/scripts/test/rhythm.test.js +13 -4
- package/scripts/test/stubs.js +19 -1
- package/scripts/test/workdir.test.js +2 -2
- package/{00-config → templates/00-config}/profile.example.yaml +0 -1
- package/{00-config → templates/00-config}/sources.yaml +8 -8
- package/templates/AGENTS.md +31 -0
- package/templates/README.md +73 -0
package/scripts/lib/agent.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
// 让本地的 agent 跑一句话、拿回它的回复。值守(bot.js)和本地服务(rhythm.js
|
|
2
|
-
// agent
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// 让本地的 agent 跑一句话、拿回它的回复。值守(bot.js)和本地服务(rhythm.js)共用,定时任务和机器人都靠它。
|
|
2
|
+
// agent 的值:zcode、dsh、qoder、claude 是预置(PRESETS,各家的无界面调用方式、续会话、权限模式都写在那里);
|
|
3
|
+
// 其余当成一条命令(按空白拆开,引号里的算一个参数;消息作为最后一个参数传给它,回复打到标准输出,退出码 0 算成功。
|
|
4
|
+
// 不支持管道、重定向这类 shell 写法——要的话包一层脚本)。
|
|
5
|
+
// 这里还管「本机装了哪些 agent」「现在是哪个 agent 在调这个 skill」(它给工具留的环境变量)、「把选定的 agent 绑进 local.env」,
|
|
6
|
+
// 给 work-rhythm agent 用。只用 node 自带的能力。找预置的命令行时返回 { problem } 而不是抛错,doctor 和真正运行时共用这一段。
|
|
5
7
|
'use strict';
|
|
6
8
|
const { spawnSync } = require('node:child_process');
|
|
7
9
|
const fs = require('node:fs');
|
|
@@ -65,6 +67,12 @@ function newestSubdir(dir, pick) {
|
|
|
65
67
|
return best;
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
// 在 PATH 上找一个命令。返回完整路径,找不到返回空串(不用 lib/run 的 which,免得和这里的 spawnSync 写法打架)
|
|
71
|
+
function onPath(name, env) {
|
|
72
|
+
const r = spawnSync('/usr/bin/which', [name], { encoding: 'utf8', env });
|
|
73
|
+
return r.status === 0 ? r.stdout.trim() : '';
|
|
74
|
+
}
|
|
75
|
+
|
|
68
76
|
function findZcode(env) {
|
|
69
77
|
const explicit = env.ZCODE_CLI;
|
|
70
78
|
if (explicit) {
|
|
@@ -77,6 +85,107 @@ function findZcode(env) {
|
|
|
77
85
|
return { problem: '找不到 ZCode 的命令行:装了 ZCode 桌面版的话它自带;也可以用 ZCODE_CLI 指定路径' };
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
// Qoder CLI(命令叫 qoder,老的 npm 包叫 qodercli):官方安装脚本 curl -fsSL https://qoder.com/install | bash,
|
|
89
|
+
// 或者 npm install -g @qoder-ai/qodercli。装了 Qoder 的 IDE 不等于装了它的命令行,找不到时提示一下
|
|
90
|
+
function findQoder(env) {
|
|
91
|
+
const explicit = env.QODER_CLI;
|
|
92
|
+
if (explicit) {
|
|
93
|
+
if (fs.existsSync(explicit)) return { command: path.resolve(explicit) };
|
|
94
|
+
return { problem: `QODER_CLI 指的文件不存在:${explicit}` };
|
|
95
|
+
}
|
|
96
|
+
for (const name of ['qoder', 'qodercli']) {
|
|
97
|
+
const found = onPath(name, env);
|
|
98
|
+
if (found) return { command: found };
|
|
99
|
+
}
|
|
100
|
+
for (const candidate of [path.join(os.homedir(), '.qoder', 'bin', 'qoder'), path.join(os.homedir(), '.local', 'bin', 'qoder')]) {
|
|
101
|
+
if (fs.existsSync(candidate)) return { command: candidate };
|
|
102
|
+
}
|
|
103
|
+
const ide = fs.existsSync('/Applications/Qoder.app') ? '本机装了 Qoder 的 IDE,但它的命令行是另装的:' : '';
|
|
104
|
+
return { problem: `找不到 Qoder 的命令行。${ide}安装:curl -fsSL https://qoder.com/install | bash(或 npm install -g @qoder-ai/qodercli),装完 qoder login;也可以用 QODER_CLI 指定路径` };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Claude Code 的命令行。ZCode 的命令行和它是同一套参数,但 ZCode 跑工具时也会留 CLAUDE_CODE_* 变量,所以认「谁在调用」时先看 ZCODE_*
|
|
108
|
+
function findClaude(env) {
|
|
109
|
+
const explicit = env.CLAUDE_CLI;
|
|
110
|
+
if (explicit) {
|
|
111
|
+
if (fs.existsSync(explicit)) return { command: path.resolve(explicit) };
|
|
112
|
+
return { problem: `CLAUDE_CLI 指的文件不存在:${explicit}` };
|
|
113
|
+
}
|
|
114
|
+
const found = onPath('claude', env);
|
|
115
|
+
if (found) return { command: found };
|
|
116
|
+
const local = path.join(os.homedir(), '.claude', 'local', 'claude');
|
|
117
|
+
if (fs.existsSync(local)) return { command: local };
|
|
118
|
+
return { problem: '找不到 Claude Code 的命令行:装了的话 claude 在 PATH 上;也可以用 CLAUDE_CLI 指定路径' };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Qoder 和 Claude Code 的 --output-format json 都是一个 JSON:回答在 result,会话在 session_id,出错时 is_error / subtype 会说。
|
|
122
|
+
// 字段名按各家文档写的;多认几个常见名字,免得版本之间改名就解析不出
|
|
123
|
+
function parseResultJson(stdout) {
|
|
124
|
+
let out;
|
|
125
|
+
try {
|
|
126
|
+
out = JSON.parse(stdout);
|
|
127
|
+
} catch {
|
|
128
|
+
return { failed: `输出不是 JSON:${tail(stdout)}` };
|
|
129
|
+
}
|
|
130
|
+
if (!out || typeof out !== 'object') return { failed: '输出不是 JSON' };
|
|
131
|
+
const reply = [out.result, out.response, out.text].find((v) => typeof v === 'string') ?? '';
|
|
132
|
+
const subtype = typeof out.subtype === 'string' ? out.subtype : '';
|
|
133
|
+
if (out.is_error === true || /error|cancel|max_turns/.test(subtype)) return { failed: `没跑完:${subtype || 'is_error'}:${tail(reply || out.error_message || '', 200)}` };
|
|
134
|
+
if (!reply.trim()) return { failed: '输出里没有回答' };
|
|
135
|
+
return { reply, sessionId: typeof out.session_id === 'string' ? out.session_id : typeof out.sessionId === 'string' ? out.sessionId : '' };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 预置。find 找命令行;plan 拼出一次无界面运行的参数;modes 是我们的权限名(plan 只读 / edit 可写工作目录)换成各家的叫法
|
|
139
|
+
const PRESETS = {
|
|
140
|
+
zcode: { label: 'ZCode 自带的命令行', modes: { plan: 'plan', edit: 'edit' }, find: findZcode },
|
|
141
|
+
dsh: { label: 'DSH(DeepSeek Harness)的 headless 模式', modes: { plan: 'read-only', edit: 'workspace-write' }, find: findDsh },
|
|
142
|
+
// Qoder:edit 用 accept_edits(改文件自动放行,shell 命令在无界面下会被拒);任务里要跑命令的话把 YZJ_BOT_AGENT_MODE 写成 auto
|
|
143
|
+
qoder: { label: 'Qoder CLI', modes: { plan: 'plan', edit: 'accept_edits' }, find: findQoder },
|
|
144
|
+
claude: { label: 'Claude Code 的命令行', modes: { plan: 'plan', edit: 'acceptEdits' }, find: findClaude },
|
|
145
|
+
};
|
|
146
|
+
const PRESET_NAMES = Object.keys(PRESETS);
|
|
147
|
+
const presetKind = (name) => (PRESET_NAMES.includes(name) ? name : 'custom');
|
|
148
|
+
|
|
149
|
+
// 现在是哪个 agent 在调这个 skill:看它给工具留的环境变量。ZCode 也留 CLAUDE_CODE_*,所以先认 ZCODE_*;
|
|
150
|
+
// Qoder 的变量名没有文档,按前缀认(QODER_CLI 是我们自己指定的路径,不算)
|
|
151
|
+
function invokingAgent(env) {
|
|
152
|
+
if (env.ZCODE_SESSION_ID || env.ZCODE_ENV || env.ZCODE_APP_VERSION) return 'zcode';
|
|
153
|
+
if (env.DSH_SESSION_ID || env.DSH_SHELL) return 'dsh';
|
|
154
|
+
if (Object.keys(env).some((k) => /^QODER_/.test(k) && k !== 'QODER_CLI')) return 'qoder';
|
|
155
|
+
if (env.CLAUDECODE === '1' || env.CLAUDE_CODE_SESSION_ID || env.CLAUDE_CODE_ENTRYPOINT) return 'claude';
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 本机装了哪些预置。每个是 { name, label, found, command, problem, invoking }
|
|
160
|
+
function installedAgents(env) {
|
|
161
|
+
const invoking = invokingAgent(env);
|
|
162
|
+
return PRESET_NAMES.map((name) => {
|
|
163
|
+
const found = PRESETS[name].find(env);
|
|
164
|
+
return { name, label: PRESETS[name].label, found: !found.problem, command: found.command || found.cli || '', problem: found.problem || '', invoking: invoking === name };
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 把选定的 agent 写进 collectors/local.env 的 YZJ_BOT_AGENT(没有这个文件就从样例复制一份)。
|
|
169
|
+
// 先确认它在本机找得到。返回 { name, kind, file } 或 { problems }
|
|
170
|
+
function bindAgent(root, env, name) {
|
|
171
|
+
const problems = createAgent({ root, agent: name, env }).doctor();
|
|
172
|
+
if (problems.length) return { problems };
|
|
173
|
+
const dir = path.join(root, 'collectors');
|
|
174
|
+
const file = path.join(dir, 'local.env');
|
|
175
|
+
if (!fs.existsSync(file)) {
|
|
176
|
+
const example = path.join(dir, 'local.env.example');
|
|
177
|
+
if (fs.existsSync(example)) fs.copyFileSync(example, file);
|
|
178
|
+
else fs.writeFileSync(file, '');
|
|
179
|
+
}
|
|
180
|
+
const value = /[\s"'$`]/.test(name) ? `'${name.replace(/'/g, `'\\''`)}'` : `"${name}"`;
|
|
181
|
+
const lines = fs.readFileSync(file, 'utf8').split('\n');
|
|
182
|
+
const at = lines.findIndex((l) => /^#?\s*YZJ_BOT_AGENT=/.test(l));
|
|
183
|
+
if (at >= 0) lines[at] = `YZJ_BOT_AGENT=${value}`;
|
|
184
|
+
else lines.push(`YZJ_BOT_AGENT=${value}`);
|
|
185
|
+
fs.writeFileSync(file, `${lines.join('\n').replace(/\n*$/, '')}\n`);
|
|
186
|
+
return { name, kind: presetKind(name), file };
|
|
187
|
+
}
|
|
188
|
+
|
|
80
189
|
// DSH 的命令行要用它自带的 Node 跑(设 ELECTRON_RUN_AS_NODE 当普通 node 用),入口是 @deepseek-ai/dsh 的 bin.js
|
|
81
190
|
function findDsh(env) {
|
|
82
191
|
const home = env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
@@ -158,19 +267,19 @@ function parseDsh(stdout) {
|
|
|
158
267
|
// doctor() → 配置和依赖的问题,一条一个字符串;没有就是空数组
|
|
159
268
|
function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = '', log = () => {}, env = process.env }) {
|
|
160
269
|
const name = String(agent || '').trim();
|
|
161
|
-
const kind = name
|
|
270
|
+
const kind = presetKind(name);
|
|
162
271
|
|
|
163
272
|
function doctor() {
|
|
164
|
-
if (!name) return ['
|
|
165
|
-
if (kind
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return
|
|
273
|
+
if (!name) return [`没绑 agent:定时任务和机器人值守都要一个 agent 来跑。先 work-rhythm agent detect 看本机有哪些,再 work-rhythm agent bind <${PRESET_NAMES.join('|')}|命令>(写进 collectors/local.env 的 YZJ_BOT_AGENT)`];
|
|
274
|
+
if (kind !== 'custom') {
|
|
275
|
+
const found = PRESETS[kind].find(env);
|
|
276
|
+
if (found.problem) return [found.problem];
|
|
277
|
+
// dsh 还要用桌面应用里配好的模型
|
|
278
|
+
if (kind === 'dsh') {
|
|
279
|
+
const entries = readDshPatchEntries(found.home);
|
|
280
|
+
if (entries.problem) return [entries.problem];
|
|
281
|
+
}
|
|
282
|
+
return [];
|
|
174
283
|
}
|
|
175
284
|
// 带斜杠的按工作目录里的相对路径找,其余在 PATH 上找
|
|
176
285
|
const [first] = splitCommand(name);
|
|
@@ -212,6 +321,36 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
|
|
|
212
321
|
};
|
|
213
322
|
}
|
|
214
323
|
|
|
324
|
+
// qoder:qoder --cwd <工作目录> --permission-mode <模式> [--resume <会话>] --output-format json --print <这句话>
|
|
325
|
+
// 模型和登录跟着 Qoder CLI 自己的配置走(~/.qoder)。无界面模式下它不弹确认,要确认的操作一律被拒,
|
|
326
|
+
// 所以 edit 对应 accept_edits(改文件自动放行);任务里要跑 shell 的话得用 auto(写在 YZJ_BOT_AGENT_MODE 里)
|
|
327
|
+
function planQoder(prompt) {
|
|
328
|
+
const q = findQoder(env);
|
|
329
|
+
if (q.problem) return q;
|
|
330
|
+
const permission = PRESETS.qoder.modes[mode] || mode;
|
|
331
|
+
const base = ['--cwd', root, '--permission-mode', permission];
|
|
332
|
+
return {
|
|
333
|
+
command: q.command,
|
|
334
|
+
env,
|
|
335
|
+
withSession: (sid) => [...base, ...(sid ? ['--resume', sid] : []), '--output-format', 'json', '--print', prompt],
|
|
336
|
+
parse: parseResultJson,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// claude:参数和 ZCode 那套一样,只是模式名和 JSON 的字段不同
|
|
341
|
+
function planClaude(prompt) {
|
|
342
|
+
const c = findClaude(env);
|
|
343
|
+
if (c.problem) return c;
|
|
344
|
+
const permission = PRESETS.claude.modes[mode] || mode;
|
|
345
|
+
const base = ['--cwd', root, '--permission-mode', permission];
|
|
346
|
+
return {
|
|
347
|
+
command: c.command,
|
|
348
|
+
env,
|
|
349
|
+
withSession: (sid) => [...base, ...(sid ? ['--resume', sid] : []), '--output-format', 'json', '-p', prompt],
|
|
350
|
+
parse: parseResultJson,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
215
354
|
// dsh:用 headless 模式答一句就退出。工作目录就是当前目录,所以 tsx 用绝对路径导入;回答在 --json 事件的 final 里。
|
|
216
355
|
// 模型和凭据跟着 DSH 桌面应用里的配置走。plan → read-only,edit → workspace-write,别的值原样传给它
|
|
217
356
|
function planDsh(prompt, stateDir) {
|
|
@@ -246,7 +385,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
|
|
|
246
385
|
return reply ? { reply } : { failed: '它没有输出任何回复' };
|
|
247
386
|
}
|
|
248
387
|
const prompt = preamble ? `${message}\n\n${preamble}` : message;
|
|
249
|
-
const plan =
|
|
388
|
+
const plan = { zcode: planZcode, dsh: planDsh, qoder: planQoder, claude: planClaude }[kind](prompt, stateDir);
|
|
250
389
|
if (plan.problem) return { failed: plan.problem, config: true }; // 配置问题:调用方按「没配置好」处理
|
|
251
390
|
let used = session;
|
|
252
391
|
let r = runProcess(plan.command, plan.withSession(used), plan.env);
|
|
@@ -267,4 +406,4 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, preamble = ''
|
|
|
267
406
|
return { kind, run, doctor };
|
|
268
407
|
}
|
|
269
408
|
|
|
270
|
-
module.exports = { createAgent, splitCommand };
|
|
409
|
+
module.exports = { createAgent, splitCommand, PRESETS, PRESET_NAMES, invokingAgent, installedAgents, bindAgent, findZcode, findDsh, findQoder, findClaude };
|
package/scripts/lib/bot.js
CHANGED
|
@@ -185,7 +185,7 @@ function createBot({ root, env }) {
|
|
|
185
185
|
if (found.problem) throw new Fail(found.code, found.problem);
|
|
186
186
|
if (needAgent) {
|
|
187
187
|
if (!OWNER) throw new Fail(EXIT.NOT_CONFIGURED, '取不到我的 openId:在 collectors/local.env 里写 YZJ_MY_OPEN_ID,值守只处理我本人的消息');
|
|
188
|
-
if (!AGENT) throw new Fail(EXIT.NOT_CONFIGURED, '
|
|
188
|
+
if (!AGENT) throw new Fail(EXIT.NOT_CONFIGURED, '没绑 agent,值守开不了:先 work-rhythm agent detect 看本机有哪些,再 work-rhythm agent bind <名字>(写进 collectors/local.env 的 YZJ_BOT_AGENT);也可以手写它,值是预置的名字或一条把回复打到标准输出的命令');
|
|
189
189
|
}
|
|
190
190
|
return deriveWsUrl(found.webhook);
|
|
191
191
|
}
|
package/scripts/lib/log.js
CHANGED
package/scripts/lib/rhythm.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 3 推送:整理完把 agent 的总结经消息渠道(notify.js)发给我,附一个本机地址;
|
|
5
5
|
// 4 看页面:只绑 127.0.0.1 的网页服务,把工作目录里的 Markdown 现渲染成 HTML(markdown.js)。
|
|
6
6
|
// 任务是一个个子进程跑的,调度不被堵住;一次只跑一个,后面的排队。错过的任务在 5 分钟内还会补跑,再久就不追了。
|
|
7
|
-
// 只用 node 自带的能力。日志写 01-inbox/_rhythm.log,状态写 01-inbox/_rhythm/state.json
|
|
7
|
+
// 只用 node 自带的能力。日志写 01-inbox/_rhythm.log,状态写 01-inbox/_rhythm/state.json。
|
|
8
8
|
'use strict';
|
|
9
9
|
const { spawn } = require('node:child_process');
|
|
10
10
|
const fs = require('node:fs');
|
package/scripts/lib/template.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
// 新工作目录里的东西从哪来,以及怎么把一个用过的目录清成空白的。
|
|
2
|
-
//
|
|
3
|
-
// 共用的(SHARED):文档、任务指令、给 agent 的笔记和 skill
|
|
4
|
-
//
|
|
5
|
-
// 现生成的:profile.yaml(就是 profile.example.yaml)、sources.yaml
|
|
2
|
+
// 这个仓库不是工作目录:工作目录里独有的文件都在 templates/ 下,分两种:
|
|
3
|
+
// 共用的(SHARED):文档、任务指令、给 agent 的笔记和 skill、local.env 的样例——仓库里就有,工作目录和包里是同一份;
|
|
4
|
+
// 模板(TEMPLATE_FILES,在 templates/ 下):profile 的空白模板、sources.yaml 的清单、空白的遗留 / 决定 / 规律画像、工作目录的 AGENTS.md 和 README.md;
|
|
5
|
+
// 现生成的:profile.yaml(就是 profile.example.yaml)、sources.yaml(清单照搬,全部关着,引导时逐个确认再打开)、两个空目录 02-daily/ 和 05-goals/。
|
|
6
6
|
// 脚本和内置采集器不进工作目录:它们在包里,sources.yaml 用 id 引用。升级就是升级这个包
|
|
7
7
|
'use strict';
|
|
8
8
|
const fs = require('node:fs');
|
|
9
9
|
const path = require('node:path');
|
|
10
10
|
const { readText, walkFiles } = require('./run');
|
|
11
11
|
|
|
12
|
-
const SHARED = ['
|
|
13
|
-
|
|
14
|
-
const GITIGNORE = `# 各系统的原始快照:可重新拉取,且含聊天原文等细节,不入库
|
|
15
|
-
01-inbox/
|
|
16
|
-
|
|
17
|
-
# 本机的配置(订阅的会话 ID、让哪个 agent 回复等)
|
|
18
|
-
collectors/local.env
|
|
19
|
-
|
|
20
|
-
.DS_Store
|
|
21
|
-
`;
|
|
12
|
+
const SHARED = ['docs', 'tasks', '.agents', 'collectors/local.env.example'];
|
|
13
|
+
const TEMPLATE_FILES = ['00-config/profile.example.yaml', '00-config/sources.yaml', '03-carryover/CARRYOVER.md', '03-carryover/DECISIONS.md', '04-patterns/WORK_RHYTHM.md', 'AGENTS.md', 'README.md'];
|
|
22
14
|
const BLANK = ['03-carryover/CARRYOVER.md', '03-carryover/DECISIONS.md', '04-patterns/WORK_RHYTHM.md'];
|
|
23
|
-
|
|
15
|
+
// 空目录:init 现建(以前靠 .gitkeep 占位;工作目录不是 git 仓库,不用了)
|
|
16
|
+
const GENERATED_DIRS = ['02-daily', '05-goals'];
|
|
24
17
|
|
|
25
18
|
// 表里以日期开头的行是记录,表头和分隔线留着
|
|
26
19
|
const blankCarryover = (text) => text.split('\n').filter((line) => !/^\| \d/.test(line)).join('\n');
|
|
@@ -80,6 +73,23 @@ function blankProblems(dir) {
|
|
|
80
73
|
return problems;
|
|
81
74
|
}
|
|
82
75
|
|
|
76
|
+
// 包里的模板对不对:每份都在、profile 是空白状态、数据源全关、记录里没有行、规律画像没开始。
|
|
77
|
+
// 开发时 check 查它,writeWorkdir 铺新工作目录之前也靠它兜底。返回问题的列表
|
|
78
|
+
function templateProblems(packageRoot) {
|
|
79
|
+
const problems = [];
|
|
80
|
+
const text = (rel) => readText(path.join(packageRoot, 'templates', rel));
|
|
81
|
+
for (const rel of TEMPLATE_FILES) {
|
|
82
|
+
if (!text(rel)) problems.push(`templates/${rel} 不存在`);
|
|
83
|
+
}
|
|
84
|
+
if (!/^ status: new\b/m.test(text('00-config/profile.example.yaml'))) problems.push('templates/00-config/profile.example.yaml 不是空白状态(setup.status 应为 new)');
|
|
85
|
+
if (/^\s*enabled:\s*true\b/m.test(text('00-config/sources.yaml'))) problems.push('templates/00-config/sources.yaml 里有打开的源:模板里数据源一律关着,引导时再逐个打开');
|
|
86
|
+
for (const rel of BLANK) {
|
|
87
|
+
if (/^\| \d/m.test(text(rel))) problems.push(`templates/${rel} 里带了记录`);
|
|
88
|
+
}
|
|
89
|
+
if (!text('04-patterns/WORK_RHYTHM.md').includes('数据范围:尚未开始')) problems.push('templates/04-patterns/WORK_RHYTHM.md 的「数据范围」不是「尚未开始」');
|
|
90
|
+
return problems;
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
// 把一个目录清成空白的工作目录:个人信息换成空白模板、数据源全关、记录不留、本机配置和原始数据删掉。
|
|
84
94
|
// 只处理目录里已有的文件,缺的不补。返回退出码
|
|
85
95
|
function blank(dir) {
|
|
@@ -125,20 +135,15 @@ function copyEntry(from, to) {
|
|
|
125
135
|
|
|
126
136
|
// 用包里的模板铺出一个空白的工作目录(目录本身要先建好)。返回空白核对没通过的问题;空数组就是铺好了
|
|
127
137
|
function writeWorkdir(dir, packageRoot) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
fs.writeFileSync(path.join(dir, '.gitignore'), GITIGNORE);
|
|
134
|
-
for (const keep of KEEPS) {
|
|
135
|
-
fs.mkdirSync(path.dirname(path.join(dir, keep)), { recursive: true });
|
|
136
|
-
fs.writeFileSync(path.join(dir, keep), '');
|
|
137
|
-
}
|
|
138
|
+
const missing = templateProblems(packageRoot).filter((p) => p.endsWith(' 不存在'));
|
|
139
|
+
if (missing.length) throw new Error(`这个包不完整:${missing.join(';')}。重新安装一次 work-rhythm`);
|
|
140
|
+
for (const rel of SHARED) copyEntry(path.join(packageRoot, rel), path.join(dir, rel));
|
|
141
|
+
for (const rel of TEMPLATE_FILES) copyEntry(path.join(packageRoot, 'templates', rel), path.join(dir, rel));
|
|
142
|
+
for (const name of GENERATED_DIRS) fs.mkdirSync(path.join(dir, name), { recursive: true });
|
|
138
143
|
fs.writeFileSync(path.join(dir, '00-config', 'profile.yaml'), fs.readFileSync(path.join(dir, '00-config', 'profile.example.yaml')));
|
|
139
144
|
const sources = path.join(dir, '00-config', 'sources.yaml');
|
|
140
145
|
fs.writeFileSync(sources, blankSources(fs.readFileSync(sources, 'utf8')));
|
|
141
146
|
return blankProblems(dir);
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
module.exports = { SHARED,
|
|
149
|
+
module.exports = { SHARED, TEMPLATE_FILES, BLANK, GENERATED_DIRS, blankCarryover, blankRhythm, blankSources, blankText, blankProblems, templateProblems, blank, writeWorkdir };
|
package/scripts/lib/workdir.js
CHANGED
|
@@ -44,12 +44,21 @@ function findUp(start) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// 站在 work-rhythm 自己的仓库里(packageRoot 就是它):仓库不是工作目录,但 check 要能查它
|
|
48
|
+
function insidePackage(cwd, packageRoot) {
|
|
49
|
+
if (!packageRoot) return false;
|
|
50
|
+
const rel = path.relative(path.resolve(packageRoot), path.resolve(cwd));
|
|
51
|
+
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 命令作用在哪个目录:--workdir 指定的优先,其次从当前目录往上找;站在 work-rhythm 自己的仓库里就是仓库(source=package,
|
|
55
|
+
// 只有 check 用得上,别的命令会报「不是工作目录」);最后看登记。
|
|
56
|
+
// 返回 { root, source: 'option' | 'cwd' | 'package' | 'pointer' | 'none', problem };登记了但用不了时 problem 说明原因
|
|
57
|
+
function resolveRoot({ cwd = process.cwd(), option = '', env = process.env, packageRoot = '' } = {}) {
|
|
50
58
|
if (option) return { root: path.resolve(option), source: 'option', problem: '' };
|
|
51
59
|
const up = findUp(cwd);
|
|
52
60
|
if (up) return { root: up, source: 'cwd', problem: '' };
|
|
61
|
+
if (insidePackage(cwd, packageRoot)) return { root: path.resolve(packageRoot), source: 'package', problem: '' };
|
|
53
62
|
const reg = registered(env);
|
|
54
63
|
if (reg && isWorkdir(reg)) return { root: reg, source: 'pointer', problem: '' };
|
|
55
64
|
return {
|
|
@@ -86,4 +95,4 @@ function findAll(starts, home) {
|
|
|
86
95
|
return [...found.values()].sort((a, b) => (a.dir < b.dir ? -1 : 1));
|
|
87
96
|
}
|
|
88
97
|
|
|
89
|
-
module.exports = { MARKER, isWorkdir, configPath, registered, register, findUp, resolveRoot, findAll };
|
|
98
|
+
module.exports = { MARKER, isWorkdir, configPath, registered, register, findUp, insidePackage, resolveRoot, findAll };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { test } = require('node:test');
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { makeSandbox, read, exists, write } = require('./harness');
|
|
7
|
+
const { invokingAgent, installedAgents } = require('../lib/agent');
|
|
8
|
+
|
|
9
|
+
// 四个预置都装上假的;PATH 上另放一个 qoder 和一个 claude,测「在 PATH 上找」那条路
|
|
10
|
+
function setup(t) {
|
|
11
|
+
const box = makeSandbox(t);
|
|
12
|
+
box.workdir();
|
|
13
|
+
const stubs = box.stubs();
|
|
14
|
+
const fake = (name, source) => {
|
|
15
|
+
const file = path.join(box.bin, name);
|
|
16
|
+
fs.writeFileSync(file, `#!/usr/bin/env node\n${source}\n`);
|
|
17
|
+
fs.chmodSync(file, 0o755);
|
|
18
|
+
};
|
|
19
|
+
const { fakeQoder, fakeClaude } = require('./stubs');
|
|
20
|
+
fake('qoder', fakeQoder);
|
|
21
|
+
fake('claude', fakeClaude);
|
|
22
|
+
// 假的 ZCode 桌面版(自带的命令行)不在 PATH 上也能找到
|
|
23
|
+
const bundled = '/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs';
|
|
24
|
+
if (!fs.existsSync(bundled)) fake('zcode', require('./stubs').fakeZcode);
|
|
25
|
+
const s = { box, stubs, env: { ...stubs, STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: 'http://127.0.0.1:1/send?yzjtoken=stubtoken0123456789abcd' } };
|
|
26
|
+
s.run = (args, env = {}) => box.run(args, { env: { ...s.env, ...env } });
|
|
27
|
+
s.bindEnv = () => ({ ...s.env, ZCODE_CLI: stubs.ZCODE_CLI, DSH_HOME: stubs.DSH_HOME, DSH_NODE: stubs.DSH_NODE, DSH_CLI: stubs.DSH_CLI });
|
|
28
|
+
// 什么都没装的环境:PATH 上没有假的,ZCode 和 DSH 也指到不存在的地方
|
|
29
|
+
s.nothing = () => ({ ...s.bindEnv(), PATH: path.join(box.root, 'nothing'), ZCODE_CLI: '/nonexistent', DSH_CLI: '', DSH_NODE: '', DSH_DESKTOP_DIR: path.join(box.root, 'nothing') });
|
|
30
|
+
return s;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------- 认「谁在调用」
|
|
34
|
+
test('invokingAgent:按各家公司给工具留的环境变量认;ZCode 也留 CLAUDE_CODE_*,所以先认 ZCODE_*', () => {
|
|
35
|
+
assert.equal(invokingAgent({}), '');
|
|
36
|
+
assert.equal(invokingAgent({ ZCODE_SESSION_ID: 's' }), 'zcode');
|
|
37
|
+
assert.equal(invokingAgent({ ZCODE_APP_VERSION: '1' }), 'zcode');
|
|
38
|
+
assert.equal(invokingAgent({ DSH_SESSION_ID: 's' }), 'dsh');
|
|
39
|
+
assert.equal(invokingAgent({ DSH_SHELL: '/bin/zsh' }), 'dsh');
|
|
40
|
+
assert.equal(invokingAgent({ QODER_SESSION_ID: 's' }), 'qoder');
|
|
41
|
+
assert.equal(invokingAgent({ QODER_CLI: '/x/qoder' }), '', 'QODER_CLI 是我们指定路径用的,不算标记');
|
|
42
|
+
assert.equal(invokingAgent({ CLAUDECODE: '1' }), 'claude');
|
|
43
|
+
assert.equal(invokingAgent({ CLAUDE_CODE_SESSION_ID: 's' }), 'claude');
|
|
44
|
+
assert.equal(invokingAgent({ ZCODE_SESSION_ID: 's', CLAUDE_CODE_SESSION_ID: 's' }), 'zcode');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------- detect
|
|
48
|
+
test('agent:列出本机装了哪些、谁在调、绑了什么;不给标记就说认不出来', (t) => {
|
|
49
|
+
const s = setup(t);
|
|
50
|
+
const env = s.bindEnv();
|
|
51
|
+
const r = s.run(['agent'], env);
|
|
52
|
+
assert.equal(r.code, 0, r.out);
|
|
53
|
+
assert.match(r.stdout, /zcode +装了 +ZCode 自带的命令行/);
|
|
54
|
+
assert.match(r.stdout, /dsh +装了 +DSH(DeepSeek Harness)的 headless 模式/);
|
|
55
|
+
assert.match(r.stdout, /qoder +装了 +Qoder CLI\n +.*\/bin\/qoder/);
|
|
56
|
+
assert.match(r.stdout, /claude +装了/);
|
|
57
|
+
assert.match(r.stdout, /正在调这个 skill 的:认不出来/);
|
|
58
|
+
assert.match(r.stdout, /现在绑定的:没绑\n没绑 agent 就没有定时任务,也不支持机器人响应。建议:work-rhythm agent bind zcode/);
|
|
59
|
+
// 现在是 DSH 在调:标出来,建议也变成 dsh
|
|
60
|
+
const dsh = s.run(['agent'], { ...env, DSH_SESSION_ID: 'sess-1' });
|
|
61
|
+
assert.match(dsh.stdout, /dsh +装了 .*← 现在是它在调这个 skill\n/);
|
|
62
|
+
assert.match(dsh.stdout, /正在调这个 skill 的:dsh\n/);
|
|
63
|
+
assert.match(dsh.stdout, /建议:work-rhythm agent bind dsh/);
|
|
64
|
+
// 没装的给安装提示(把 DSH 的目录也指到不存在的地方)
|
|
65
|
+
const none = s.run(['agent'], s.nothing());
|
|
66
|
+
assert.match(none.stdout, /zcode +没装/);
|
|
67
|
+
assert.match(none.stdout, /dsh +没装/);
|
|
68
|
+
assert.match(none.stdout, /qoder +没装 +Qoder CLI\n +没装:找不到 Qoder 的命令行。.*qoder\.com\/install/);
|
|
69
|
+
assert.match(none.stdout, /本机一个预置的 agent 都没装/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('agent --json:给 agent 读的结构', (t) => {
|
|
73
|
+
const s = setup(t);
|
|
74
|
+
const r = s.run(['agent', '--json'], { ...s.bindEnv(), QODER_SESSION_ID: 'q' });
|
|
75
|
+
assert.equal(r.code, 0, r.out);
|
|
76
|
+
const doc = JSON.parse(r.stdout);
|
|
77
|
+
assert.equal(doc.invoking, 'qoder');
|
|
78
|
+
assert.equal(doc.invokingFound, true);
|
|
79
|
+
assert.equal(doc.bound, '');
|
|
80
|
+
assert.equal(doc.suggest, 'qoder');
|
|
81
|
+
assert.deepEqual(doc.agents.map((a) => [a.name, a.found]), [['zcode', true], ['dsh', true], ['qoder', true], ['claude', true]]);
|
|
82
|
+
assert.match(s.run(['agent', '--json'], s.bindEnv()).stdout, /"invoking": ""/);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// ---------------------------------------------------------------- bind
|
|
86
|
+
test('agent bind:不给名字就绑正在调的这个;没标记就绑装了的第一个;写进 local.env 的 YZJ_BOT_AGENT', (t) => {
|
|
87
|
+
const s = setup(t);
|
|
88
|
+
const env = s.bindEnv();
|
|
89
|
+
assert.equal(exists(`${s.box.work}/collectors/local.env`), false);
|
|
90
|
+
const r = s.run(['agent', 'bind'], { ...env, DSH_SESSION_ID: 'sess-1' });
|
|
91
|
+
assert.equal(r.code, 0, r.out);
|
|
92
|
+
assert.match(r.stdout, /已绑定 dsh(DSH(DeepSeek Harness)的 headless 模式),写进了 collectors\/local\.env 的 YZJ_BOT_AGENT。\n下一步:work-rhythm agent test/);
|
|
93
|
+
// local.env 原来没有:从样例复制一份,再把样例里注释掉的那行换成真的
|
|
94
|
+
const text = read(`${s.box.work}/collectors/local.env`);
|
|
95
|
+
assert.match(text, /^YZJ_BOT_AGENT="dsh"$/m);
|
|
96
|
+
assert.equal(text.split('\n').filter((l) => /^#?\s*YZJ_BOT_AGENT=/.test(l)).length, 1, '样例里注释掉的那行要被换掉,不留两行');
|
|
97
|
+
assert.match(text, /# 消息渠道/);
|
|
98
|
+
// 再绑一次:只改那一行
|
|
99
|
+
const again = s.run(['agent', 'bind', 'qoder'], env);
|
|
100
|
+
assert.equal(again.code, 0, again.out);
|
|
101
|
+
assert.match(read(`${s.box.work}/collectors/local.env`), /^YZJ_BOT_AGENT="qoder"$/m);
|
|
102
|
+
assert.match(s.run(['agent'], env).stdout, /现在绑定的:qoder\n/);
|
|
103
|
+
// 一条自定义命令:命令存在才让绑;有空格的值用单引号包($ 不展开)
|
|
104
|
+
const custom = `${path.join(s.box.bin, 'fake-agent')} --flag`;
|
|
105
|
+
assert.equal(s.run(['agent', 'bind'], env).code, 0);
|
|
106
|
+
assert.equal(s.run(['agent', 'bind', custom], env).code, 0);
|
|
107
|
+
assert.match(read(`${s.box.work}/collectors/local.env`), /^YZJ_BOT_AGENT='.*\/fake-agent --flag'$/m);
|
|
108
|
+
const shown = s.run(['agent'], env);
|
|
109
|
+
assert.match(shown.stdout, /现在绑定的:.*\/fake-agent --flag(一条自定义命令,zcode\/dsh\/qoder\/claude 以外)/);
|
|
110
|
+
assert.equal(shown.stdout.includes('建议:'), false, '绑了就不再建议');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('agent bind:绑不了的拒绝(退出码 3)并说清原因——预置没装、命令找不到;一个都没有时给安装指引', (t) => {
|
|
114
|
+
const s = setup(t);
|
|
115
|
+
const env = s.bindEnv();
|
|
116
|
+
const qoder = s.run(['agent', 'bind', 'qoder'], { ...env, PATH: path.join(s.box.root, 'nothing') });
|
|
117
|
+
assert.equal(qoder.code, 3);
|
|
118
|
+
assert.match(qoder.stderr, /绑不了 qoder:找不到 Qoder 的命令行。/);
|
|
119
|
+
assert.equal(exists(`${s.box.work}/collectors/local.env`), false, '绑不了就不写文件');
|
|
120
|
+
const bad = s.run(['agent', 'bind', '/no/such/agent'], env);
|
|
121
|
+
assert.equal(bad.code, 3);
|
|
122
|
+
assert.match(bad.stderr, /绑不了 \/no\/such\/agent:YZJ_BOT_AGENT 的命令找不到: \/no\/such\/agent/);
|
|
123
|
+
const none = s.run(['agent', 'bind'], s.nothing());
|
|
124
|
+
assert.equal(none.code, 3);
|
|
125
|
+
assert.match(none.stderr, /本机没找到能用的 agent,也没指定要绑的命令/);
|
|
126
|
+
assert.equal(s.run(['agent', 'bind', 'a', 'b'], env).code, 2);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// ---------------------------------------------------------------- test / doctor / 各家的调用方式
|
|
130
|
+
test('agent test:让绑定的 agent 只读答一句;没绑就退出码 3', (t) => {
|
|
131
|
+
const s = setup(t);
|
|
132
|
+
const env = s.bindEnv();
|
|
133
|
+
const none = s.run(['agent', 'test'], env);
|
|
134
|
+
assert.equal(none.code, 3);
|
|
135
|
+
assert.match(none.stderr, /还没绑 agent:work-rhythm agent detect/);
|
|
136
|
+
assert.equal(s.run(['agent', 'bind', 'qoder'], env).code, 0);
|
|
137
|
+
const r = s.run(['agent', 'test', '今天周几'], env);
|
|
138
|
+
assert.equal(r.code, 0, r.out);
|
|
139
|
+
assert.match(r.stdout, /^回复:今天周几\n(qoder,只读模式,用时 \d+ 秒)\n$/);
|
|
140
|
+
// Qoder 的参数:工作目录、只读模式、JSON 输出、--print 后面跟这句话
|
|
141
|
+
const args = read(s.stubs.STUB_QODER_ARGS);
|
|
142
|
+
assert.equal(args, `--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --output-format json --print 今天周几\n`);
|
|
143
|
+
// 默认那句话
|
|
144
|
+
s.run(['agent', 'test'], env);
|
|
145
|
+
assert.match(read(s.stubs.STUB_QODER_ARGS), /--print 你好,用一句话介绍你自己,并说出你用的是哪个模型。$/m);
|
|
146
|
+
assert.equal(s.run(['agent', 'test', 'a', 'b'], env).code, 2);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('qoder 预置:值守里第二轮用 --resume 接上;edit 模式换成 accept_edits;没跑完按失败处理', (t) => {
|
|
150
|
+
const s = setup(t);
|
|
151
|
+
s.run(['agent', 'bind', 'qoder'], s.bindEnv());
|
|
152
|
+
// 值守走的是 listen:要渠道和 openId 才肯跑
|
|
153
|
+
const profile = `${s.box.work}/00-config/profile.yaml`;
|
|
154
|
+
write(profile, read(profile).replace('notify: ""', 'notify: "yzj-robot"'));
|
|
155
|
+
// 假的 qoder 把整段提示原样回出来,所以关掉随每句话带给 agent 的那句提示
|
|
156
|
+
const env = { ...s.bindEnv(), YZJ_MY_OPEN_ID: 'me-0001', YZJ_BOT_PREAMBLE: '' };
|
|
157
|
+
const first = s.run(['listen', 'handle', '第一句'], env);
|
|
158
|
+
assert.equal(first.code, 0, first.out);
|
|
159
|
+
assert.equal(first.stdout, '回复:第一句\n');
|
|
160
|
+
const second = s.run(['listen', 'handle', '第二句'], { ...env, YZJ_BOT_AGENT_MODE: 'edit' });
|
|
161
|
+
assert.equal(second.stdout, '回复:第二句\n');
|
|
162
|
+
const args = read(s.stubs.STUB_QODER_ARGS).trim();
|
|
163
|
+
assert.ok(args.startsWith(`--cwd ${fs.realpathSync(s.box.work)} --permission-mode accept_edits --resume sess_q --output-format json --print 第二句`), args);
|
|
164
|
+
assert.equal(read(`${s.box.work}/01-inbox/_bot/session-id`).trim(), 'sess_q');
|
|
165
|
+
const failed = s.run(['listen', 'handle', '出错'], { ...env, STUB_QODER_FINAL: 'error_max_turns' });
|
|
166
|
+
assert.equal(failed.code, 5);
|
|
167
|
+
assert.match(failed.stderr, /没处理成功:没跑完:error_max_turns/);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('claude 预置:在 PATH 上找到 claude,参数是 Claude Code 那一套', (t) => {
|
|
171
|
+
const s = setup(t);
|
|
172
|
+
s.run(['agent', 'bind', 'claude'], s.bindEnv());
|
|
173
|
+
const r = s.run(['agent', 'test', '在吗'], s.bindEnv());
|
|
174
|
+
assert.equal(r.code, 0, r.out);
|
|
175
|
+
assert.equal(r.stdout, '回复:在吗\n(claude,只读模式,用时 0 秒)\n');
|
|
176
|
+
assert.equal(read(s.stubs.STUB_CLAUDE_ARGS).trim(), `--cwd ${fs.realpathSync(s.box.work)} --permission-mode plan --output-format json -p 在吗`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('agent doctor:绑定的 agent 有没有问题;用法不对退出码为 2', (t) => {
|
|
180
|
+
const s = setup(t);
|
|
181
|
+
const env = s.bindEnv();
|
|
182
|
+
assert.equal(s.run(['agent', 'doctor'], env).code, 1);
|
|
183
|
+
assert.match(s.run(['agent', 'doctor'], env).stdout, /没绑 agent:定时任务和机器人值守都要一个 agent 来跑/);
|
|
184
|
+
s.run(['agent', 'bind', 'dsh'], env);
|
|
185
|
+
const ok = s.run(['agent', 'doctor'], env);
|
|
186
|
+
assert.equal(ok.code, 0, ok.out);
|
|
187
|
+
assert.equal(ok.stdout, 'dsh 没有问题。\n');
|
|
188
|
+
const broken = s.run(['agent', 'doctor'], { ...env, DSH_HOME: path.join(s.box.root, 'no-such-home') });
|
|
189
|
+
assert.equal(broken.code, 1);
|
|
190
|
+
assert.match(broken.stdout, /找不到 DSH 的配置/);
|
|
191
|
+
assert.equal(s.run(['agent', 'nope'], env).code, 2);
|
|
192
|
+
assert.match(s.run(['agent', '--help'], env).stderr, /work-rhythm agent: 用法: work-rhythm agent \[子命令\]/);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('installedAgents:本机真有什么就报什么,不编造', () => {
|
|
196
|
+
const list = installedAgents(process.env);
|
|
197
|
+
assert.deepEqual(list.map((a) => a.name), ['zcode', 'dsh', 'qoder', 'claude']);
|
|
198
|
+
for (const a of list) assert.equal(typeof a.found, 'boolean');
|
|
199
|
+
});
|