work-rhythm 0.1.1 → 0.1.3
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 +1 -0
- 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-scheduling-moves-to-a-local-service.md +1 -0
- package/.agents/notes/decisions/2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md +31 -0
- package/.agents/skills/work-rhythm/SKILL.md +23 -10
- package/README.md +2 -1
- package/collectors/local.env.example +4 -2
- package/docs/agents.md +49 -0
- package/docs/channels.md +1 -1
- package/docs/formats.md +4 -0
- package/docs/scheduled-tasks.md +2 -12
- package/package.json +1 -1
- package/scripts/cli.js +15 -4
- package/scripts/cmd/agent.js +114 -0
- package/scripts/cmd/check.js +25 -3
- package/scripts/cmd/collect.js +10 -1
- package/scripts/cmd/decisions.js +17 -6
- package/scripts/cmd/events.js +103 -0
- package/scripts/cmd/goals.js +16 -20
- package/scripts/cmd/init.js +7 -1
- package/scripts/cmd/listen.js +7 -2
- package/scripts/cmd/notify.js +9 -1
- package/scripts/cmd/pack.js +7 -1
- package/scripts/cmd/rhythm.js +7 -2
- package/scripts/cmd/selftest.js +7 -1
- package/scripts/cmd/sync.js +12 -1
- package/scripts/cmd/today.js +13 -1
- package/scripts/cmd/workdir.js +5 -2
- package/scripts/lib/agent.js +156 -17
- package/scripts/lib/bot.js +1 -1
- package/scripts/test/agent.test.js +201 -0
- package/scripts/test/check.test.js +31 -9
- package/scripts/test/config.test.js +0 -2
- package/scripts/test/events.test.js +89 -0
- package/scripts/test/harness.js +4 -1
- package/scripts/test/help.test.js +71 -0
- package/scripts/test/listen.test.js +10 -6
- package/scripts/test/rhythm.test.js +2 -2
- package/scripts/test/stubs.js +19 -1
- package/templates/00-config/profile.example.yaml +0 -1
- package/templates/AGENTS.md +1 -1
- package/templates/README.md +2 -1
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
const help = s.run(['agent', '--help'], env);
|
|
193
|
+
assert.equal(help.code, 0);
|
|
194
|
+
assert.match(help.stdout, /work-rhythm agent \[子命令\] —— 定时任务和机器人值守用哪个 agent/);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('installedAgents:本机真有什么就报什么,不编造', () => {
|
|
198
|
+
const list = installedAgents(process.env);
|
|
199
|
+
assert.deepEqual(list.map((a) => a.name), ['zcode', 'dsh', 'qoder', 'claude']);
|
|
200
|
+
for (const a of list) assert.equal(typeof a.found, 'boolean');
|
|
201
|
+
});
|
|
@@ -22,6 +22,13 @@ function setup(t) {
|
|
|
22
22
|
sources,
|
|
23
23
|
setNotify: (value) => write(profile, setKey(read(profile), 'notify', value)),
|
|
24
24
|
localEnv: (text) => write(`${box.work}/collectors/local.env`, text),
|
|
25
|
+
// 值守装成常驻(launchd 里有它的 plist)check 才核对值守;plist 在 HOME 下,所以把 HOME 指到临时目录
|
|
26
|
+
botInstalled: () => {
|
|
27
|
+
const home = path.join(box.root, 'home');
|
|
28
|
+
fs.mkdirSync(path.join(home, 'Library', 'LaunchAgents'), { recursive: true });
|
|
29
|
+
write(path.join(home, 'Library', 'LaunchAgents', `work-rhythm.bot.${path.basename(box.work)}.plist`), '<?xml version="1.0"?><plist/>');
|
|
30
|
+
return { HOME: home };
|
|
31
|
+
},
|
|
25
32
|
check: (env = { STUB_KEYCHAIN: 'no' }) => box.run(['check'], { env }),
|
|
26
33
|
};
|
|
27
34
|
}
|
|
@@ -175,41 +182,56 @@ test('check:没装 security 时报出来', (t) => {
|
|
|
175
182
|
assert.match(r.stdout, /消息渠道 yzj-robot 需要 security,本机没有/);
|
|
176
183
|
});
|
|
177
184
|
|
|
178
|
-
test('check
|
|
185
|
+
test('check:只绑了 agent 跑定时任务、没装值守,不报值守的事;schedule 有任务没绑 agent 才报', (t) => {
|
|
186
|
+
const s = setup(t);
|
|
187
|
+
s.localEnv('YZJ_BOT_AGENT="dsh"\n');
|
|
188
|
+
const r = s.check({ ...s.stubs });
|
|
189
|
+
assert.equal(r.code, 0, r.out);
|
|
190
|
+
assert.ok(!r.out.includes('值守'), r.out);
|
|
191
|
+
// 引导做完(status: done)、把绑定的那行去掉:schedule 里有任务(模板的默认时间)却没绑 agent,就报;引导没走到第 6 步时不报
|
|
192
|
+
write(`${s.box.work}/00-config/profile.yaml`, read(`${s.box.work}/00-config/profile.yaml`).replace('status: new', 'status: done'));
|
|
193
|
+
s.localEnv('# YZJ_BOT_AGENT="dsh"\n');
|
|
194
|
+
const r2 = s.check({ ...s.stubs });
|
|
195
|
+
assert.equal(r2.code, 1, r2.out);
|
|
196
|
+
assert.match(r2.stdout, /schedule 里有任务(daily-plan、noon-checkin、evening-review、carryover、weekly-rhythm)却没绑 agent,到点一个也跑不了:work-rhythm agent bind <zcode\|dsh\|qoder\|claude>/);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('check:值守装了之后,配的命令找不到时报出来', (t) => {
|
|
179
200
|
const s = setup(t);
|
|
180
201
|
s.setNotify('yzj-robot');
|
|
181
202
|
s.localEnv('YZJ_BOT_AGENT="/nonexistent/agent x"\nYZJ_MY_OPEN_ID="me-0001"\n');
|
|
182
|
-
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
203
|
+
const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
|
|
183
204
|
assert.equal(r.code, 1);
|
|
184
205
|
assert.match(r.stdout, /YZJ_BOT_AGENT 的命令找不到: \/nonexistent\/agent/);
|
|
185
206
|
assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
|
|
186
207
|
});
|
|
187
208
|
|
|
188
|
-
test('check
|
|
209
|
+
test('check:值守装了之后,没写我的 openId 时报出来', (t) => {
|
|
189
210
|
const s = setup(t);
|
|
190
211
|
s.setNotify('yzj-robot');
|
|
191
212
|
s.localEnv('YZJ_BOT_AGENT="zcode"\n');
|
|
192
|
-
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
213
|
+
const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
|
|
193
214
|
assert.match(r.stdout, /要写 YZJ_MY_OPEN_ID/);
|
|
194
215
|
assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
|
|
195
216
|
});
|
|
196
217
|
|
|
197
|
-
test('check
|
|
218
|
+
test('check:值守装了之后,notify 不是 yzj-robot 时报出来;配好之后不再报它', (t) => {
|
|
198
219
|
const s = setup(t);
|
|
220
|
+
const home = s.botInstalled();
|
|
199
221
|
s.localEnv(`YZJ_BOT_AGENT="zcode"\nYZJ_MY_OPEN_ID="me-0001"\nZCODE_CLI="${s.stubs.ZCODE_CLI}"\n`);
|
|
200
222
|
s.setNotify('""');
|
|
201
|
-
assert.match(s.check({ STUB_KEYCHAIN: 'ok' }).stdout, /值守属于 yzj-robot 渠道:preferences\.notify 要设成 yzj-robot/);
|
|
223
|
+
assert.match(s.check({ ...home, STUB_KEYCHAIN: 'ok' }).stdout, /值守属于 yzj-robot 渠道:preferences\.notify 要设成 yzj-robot/);
|
|
202
224
|
s.setNotify('yzj-robot');
|
|
203
|
-
const ok = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
225
|
+
const ok = s.check({ ...home, STUB_KEYCHAIN: 'ok' });
|
|
204
226
|
assert.equal(ok.code, 0, ok.out);
|
|
205
227
|
assert.ok(!ok.stdout.includes('值守'));
|
|
206
228
|
});
|
|
207
229
|
|
|
208
|
-
test('check
|
|
230
|
+
test('check:值守装了之后,配了 dsh 却找不到它的配置时报出来', (t) => {
|
|
209
231
|
const s = setup(t);
|
|
210
232
|
s.setNotify('yzj-robot');
|
|
211
233
|
s.localEnv(`YZJ_BOT_AGENT="dsh"\nYZJ_MY_OPEN_ID="me-0001"\nDSH_HOME="${s.box.root}/no-such-home"\nDSH_NODE="${path.join(s.box.bin, 'fake-dsh-node')}"\nDSH_CLI="${path.join(s.box.bin, 'fake-dsh')}"\n`);
|
|
212
|
-
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
234
|
+
const r = s.check({ ...s.botInstalled(), STUB_KEYCHAIN: 'ok' });
|
|
213
235
|
assert.equal(r.code, 1);
|
|
214
236
|
assert.match(r.stdout, /找不到 DSH 的配置/);
|
|
215
237
|
});
|
|
@@ -32,7 +32,6 @@ rhythm:
|
|
|
32
32
|
port: 8787
|
|
33
33
|
push: true
|
|
34
34
|
quiet: [linky-cost-fill, linky-cost-check]
|
|
35
|
-
automations: {}
|
|
36
35
|
sources:
|
|
37
36
|
- id: git-activity
|
|
38
37
|
name: 本机代码提交
|
|
@@ -57,7 +56,6 @@ sources:
|
|
|
57
56
|
assert.equal(doc.rhythm.port, 8787);
|
|
58
57
|
assert.equal(doc.rhythm.push, true);
|
|
59
58
|
assert.deepEqual(doc.rhythm.quiet, ['linky-cost-fill', 'linky-cost-check']);
|
|
60
|
-
assert.deepEqual(doc.automations, {});
|
|
61
59
|
assert.equal(doc.sources[0].extract, '第一行\n第二行\n');
|
|
62
60
|
assert.equal(doc.sources[1].id, 'noted');
|
|
63
61
|
assert.equal(doc.sources[1].enabled, false);
|
|
@@ -0,0 +1,89 @@
|
|
|
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, run: rawRun, read, write, addDaysHelper } = require('./harness');
|
|
7
|
+
const { addDays, today } = require('../lib/run');
|
|
8
|
+
|
|
9
|
+
const T = '\t';
|
|
10
|
+
const DAY = (offset) => addDays(today(), offset);
|
|
11
|
+
// 一份每日文件:事件流前后有别的小节,表里有一行格子里带转义的竖线
|
|
12
|
+
function daily(dir, offset, rows, extra = '') {
|
|
13
|
+
const date = DAY(offset);
|
|
14
|
+
const table = rows.length ? `| 时间 | 类型 | 事项 | 来源 | 项目 |\n|------|------|------|------|------|\n${rows.join('\n')}\n` : '| 时间 | 类型 | 事项 | 来源 | 项目 |\n|------|------|------|------|------|\n';
|
|
15
|
+
write(path.join(dir, '02-daily', date.slice(0, 7), `${date}.md`), `# ${date}\n\n## 计划\n\n- **今日重点**:\n\n## 事件流\n\n${table}${extra}\n## 备注\n\n| 09:05 | 沟通 | 备注里的表不算 | x | x |\n\n## 事件流补充\n\n| 10:00 | 其他 | 别的小节里的也不算 | x | x |\n`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('events:把 7 天内的每日文件里的事件流按日期、时间列成一张表;别的小节里的表不算', (t) => {
|
|
19
|
+
const box = makeSandbox(t);
|
|
20
|
+
const dir = box.workdir();
|
|
21
|
+
daily(dir, 0, ['| 09:05 | 沟通 | 同步接口联调进度 | im-yzj | 导出 |', '| 08:30 | 编码 | 提交 3 次 | git-activity | 导出 |']);
|
|
22
|
+
daily(dir, -1, ['| 14:00 | 会议 | 周会(30min) | calendar-yzj | |']);
|
|
23
|
+
daily(dir, -6, ['| 10:00 | 文档 | 写接口文档 | file-activity | 导出 |']);
|
|
24
|
+
daily(dir, -7, ['| 10:00 | 文档 | 八天前的,不在 7 天里 | file-activity | 旧 |']);
|
|
25
|
+
const r = box.run(['events']);
|
|
26
|
+
assert.equal(r.code, 0, r.out);
|
|
27
|
+
assert.equal(r.stdout, [
|
|
28
|
+
`date${T}time${T}type${T}item${T}source${T}project`,
|
|
29
|
+
`${DAY(-6)}${T}10:00${T}文档${T}写接口文档${T}file-activity${T}导出`,
|
|
30
|
+
`${DAY(-1)}${T}14:00${T}会议${T}周会(30min)${T}calendar-yzj${T}`,
|
|
31
|
+
`${DAY(0)}${T}08:30${T}编码${T}提交 3 次${T}git-activity${T}导出`,
|
|
32
|
+
`${DAY(0)}${T}09:05${T}沟通${T}同步接口联调进度${T}im-yzj${T}导出`,
|
|
33
|
+
'',
|
|
34
|
+
].join('\n'));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('events:--today、--days、--from/--to 各定一个范围,两头都含', (t) => {
|
|
38
|
+
const box = makeSandbox(t);
|
|
39
|
+
const dir = box.workdir();
|
|
40
|
+
for (const offset of [0, -1, -2, -3]) daily(dir, offset, [`| 09:00 | 其他 | 第 ${offset} 天 | x | |`]);
|
|
41
|
+
const dates = (args) => box.run(['events', ...args]).stdout.trim().split('\n').slice(1).map((l) => l.split(T)[0]);
|
|
42
|
+
assert.deepEqual(dates(['--today']), [DAY(0)]);
|
|
43
|
+
assert.deepEqual(dates(['--days', '3']), [DAY(-2), DAY(-1), DAY(0)]);
|
|
44
|
+
assert.deepEqual(dates(['--from', DAY(-3), '--to', DAY(-2)]), [DAY(-3), DAY(-2)]);
|
|
45
|
+
assert.deepEqual(dates(['--from', DAY(-2)]), [DAY(-2), DAY(-1), DAY(0)]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('events:按类型、来源、项目筛,可以逗号分隔写多个;--json 每条一个对象', (t) => {
|
|
49
|
+
const box = makeSandbox(t);
|
|
50
|
+
const dir = box.workdir();
|
|
51
|
+
daily(dir, 0, [
|
|
52
|
+
'| 09:05 | 沟通 | 同步进度 | im-yzj | 导出 |',
|
|
53
|
+
'| 10:00 | 会议 | 需求评审 | calendar-yzj | |',
|
|
54
|
+
'| 13:45 | 沟通 | 发材料 | 口述 | demo-goal |',
|
|
55
|
+
]);
|
|
56
|
+
const items = (args) => box.run(['events', '--today', ...args]).stdout.trim().split('\n').slice(1).map((l) => l.split(T)[3]);
|
|
57
|
+
assert.deepEqual(items(['--type', '沟通,会议']), ['同步进度', '需求评审', '发材料']);
|
|
58
|
+
assert.deepEqual(items(['--type', '会议']), ['需求评审']);
|
|
59
|
+
assert.deepEqual(items(['--source', '口述']), ['发材料']);
|
|
60
|
+
assert.deepEqual(items(['--project', 'demo-goal']), ['发材料']);
|
|
61
|
+
assert.deepEqual(items(['--project', '导出,demo-goal']), ['同步进度', '发材料']);
|
|
62
|
+
const json = JSON.parse(box.run(['events', '--today', '--json']).stdout);
|
|
63
|
+
assert.deepEqual(json[2], { date: DAY(0), time: '13:45', type: '沟通', item: '发材料', source: '口述', project: 'demo-goal' });
|
|
64
|
+
assert.equal(json.length, 3);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('events:没有文件、没有事件流、空表都只有表头;看不懂的行跳过;格子里转义的竖线算一个格子', (t) => {
|
|
68
|
+
const box = makeSandbox(t);
|
|
69
|
+
const dir = box.workdir();
|
|
70
|
+
assert.equal(box.run(['events']).stdout, `date${T}time${T}type${T}item${T}source${T}project\n`);
|
|
71
|
+
const date = DAY(0);
|
|
72
|
+
write(path.join(dir, '02-daily', date.slice(0, 7), `${date}.md`), `# ${date}\n\n## 事件流\n\n| 时间 | 类型 | 事项 | 来源 | 项目 |\n|------|------|------|------|------|\n这行不是表格\n| 10:00 | 文档 | 带 \\| 竖线的事项 | file-activity | |\n| 没有时间的行 |\n\n## 备注\n`);
|
|
73
|
+
assert.equal(box.run(['events', '--today']).stdout, `date${T}time${T}type${T}item${T}source${T}project\n${date}${T}10:00${T}文档${T}带 | 竖线的事项${T}file-activity${T}\n`);
|
|
74
|
+
// 事项里混进制表符时换成空格,表不会串列
|
|
75
|
+
write(path.join(dir, '02-daily', date.slice(0, 7), `${date}.md`), `# ${date}\n\n## 事件流\n\n| 时间 | 类型 | 事项 | 来源 | 项目 |\n|---|---|---|---|---|\n| 11:00 | 其他 | a\tb | x | |\n`);
|
|
76
|
+
assert.equal(box.run(['events', '--today']).stdout.split('\n')[1].split(T).length, 6);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('events:选项不对、日期不对、起始晚于结束时退出码为 2', (t) => {
|
|
80
|
+
const box = makeSandbox(t);
|
|
81
|
+
box.workdir();
|
|
82
|
+
assert.equal(box.run(['events', '--nope']).code, 2);
|
|
83
|
+
assert.equal(box.run(['events', '--days']).code, 2);
|
|
84
|
+
assert.equal(box.run(['events', '--days', '0']).code, 2);
|
|
85
|
+
assert.equal(box.run(['events', '--from', '不是日期']).code, 2);
|
|
86
|
+
assert.equal(box.run(['events', '--from', DAY(1), '--to', DAY(0)]).code, 2);
|
|
87
|
+
assert.match(box.run(['events', '--from', DAY(1), '--to', DAY(0)]).stderr, /起始日期 .* 晚于结束日期/);
|
|
88
|
+
assert.equal(rawRun(['events'], { cwd: box.root }).code, 3);
|
|
89
|
+
});
|
package/scripts/test/harness.js
CHANGED
|
@@ -16,7 +16,8 @@ const BIN = path.join(PACKAGE_ROOT, 'scripts', 'work-rhythm.js');
|
|
|
16
16
|
const T = '\t';
|
|
17
17
|
|
|
18
18
|
// 这些变量是各命令的配置,本机环境里如果碰巧有,会让用例的结果跟着变。跑命令时一律不带
|
|
19
|
-
|
|
19
|
+
// CLAUDE、QODER 也抹掉:调用这个测试的 agent 会留自己的标记(ZCODE_*、CLAUDE_CODE_*、DSH_SESSION_ID),用例不能被它带偏
|
|
20
|
+
const STRIP = /^(YZJ_|GIT_ACTIVITY_|FILE_ACTIVITY_|DSH_|STUB_|ZCODE_|WORK_RHYTHM_|DECISIONS_TODAY|LINKY_TYPES|CLAUDE|QODER)/;
|
|
20
21
|
const { writeWorkdir } = require('../lib/template');
|
|
21
22
|
|
|
22
23
|
// 用户级登记指向一个不存在的文件:用例不能被本机登记的工作目录带偏
|
|
@@ -141,6 +142,8 @@ function makeSandbox(t) {
|
|
|
141
142
|
STUB_ROBOT_TOKEN: 'stubtoken0123456789abcd',
|
|
142
143
|
STUB_AGENT_CALLS: file('agent.calls'),
|
|
143
144
|
STUB_ZCODE_ARGS: file('zcode.args'),
|
|
145
|
+
STUB_QODER_ARGS: file('qoder.args'),
|
|
146
|
+
STUB_CLAUDE_ARGS: file('claude.args'),
|
|
144
147
|
STUB_DSH_ARGS: file('dsh.args'),
|
|
145
148
|
STUB_DSH_ENV: file('dsh.env'),
|
|
146
149
|
STUB_APPROVAL_NEW_MS: String(Date.UTC(2026, 10, 27, 10, 0, 0)),
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { test } = require('node:test');
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { BIN, run, makeSandbox, webhook } = require('./harness');
|
|
8
|
+
|
|
9
|
+
const COMMANDS = ['today', 'goals', 'decisions', 'sync', 'collect', 'notify', 'check', 'listen', 'rhythm', 'agent', 'workdir', 'init', 'pack', 'selftest'];
|
|
10
|
+
|
|
11
|
+
// agent 顺手就会敲「work-rhythm notify --help」:以前这会把「--help」当成要发的文字发出去。现在任何位置的 --help 都只打用法
|
|
12
|
+
test('--help:每个子命令都能问,退出码 0,第一行是「work-rhythm <子命令> … —— 做什么」,并写了退出码', async (t) => {
|
|
13
|
+
const hook = await webhook(t);
|
|
14
|
+
const box = makeSandbox(t);
|
|
15
|
+
box.workdir();
|
|
16
|
+
// 钥匙串指向假 webhook、渠道开着:要是 --help 被当成文字发出去,这里就会收到
|
|
17
|
+
writeProfile(box.work, 'notify: "yzj-robot"');
|
|
18
|
+
for (const name of COMMANDS) {
|
|
19
|
+
const r = box.run([name, '--help'], { env: { STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: hook.url } });
|
|
20
|
+
assert.equal(r.code, 0, `${name} --help: ${r.out}`);
|
|
21
|
+
assert.match(r.stdout, new RegExp(`^work-rhythm ${name}[ \\[]`), name);
|
|
22
|
+
assert.match(r.stdout, /—— /, `${name} 的第一行要说清做什么`);
|
|
23
|
+
assert.match(r.stdout, /退出码/, `${name} 的用法里要写退出码`);
|
|
24
|
+
assert.equal(r.stderr, '', name);
|
|
25
|
+
}
|
|
26
|
+
assert.deepEqual(hook.requests(), [], '--help 不能发出任何消息');
|
|
27
|
+
assert.equal(fs.existsSync(path.join(box.work, '--help')), false, 'init --help 不能建出一个叫 --help 的目录');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('--help:写在任何位置、几种写法都认;不在工作目录里也能问', (t) => {
|
|
31
|
+
const box = makeSandbox(t);
|
|
32
|
+
const outside = path.join(box.root, 'elsewhere');
|
|
33
|
+
fs.mkdirSync(outside);
|
|
34
|
+
const forms = [['today', '-h'], ['help', 'today'], ['--help', 'today'], ['rhythm', 'run', '--help'], ['decisions', 'add', '-h'], ['goals', 'list', '--help']];
|
|
35
|
+
for (const args of forms) {
|
|
36
|
+
const r = run(args, { cwd: outside });
|
|
37
|
+
assert.equal(r.code, 0, args.join(' '));
|
|
38
|
+
assert.match(r.stdout, /^work-rhythm (today|rhythm|decisions|goals)\b/);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('--help:顶层用法列出全部子命令、退出码约定,以及「每个子命令的详细用法」;不认识的子命令退出码 2 并带出用法', (t) => {
|
|
43
|
+
const box = makeSandbox(t);
|
|
44
|
+
const top = run(['--help'], { cwd: box.root });
|
|
45
|
+
assert.equal(top.code, 0);
|
|
46
|
+
for (const name of COMMANDS) assert.match(top.stdout, new RegExp(`\\n ${name} `), name);
|
|
47
|
+
assert.match(top.stdout, /每个子命令的详细用法: work-rhythm <子命令> --help/);
|
|
48
|
+
assert.match(top.stdout, /退出码约定: 0 成功 · 2 用法不对 · 3 没配置好/);
|
|
49
|
+
assert.match(top.stdout, /work-rhythm skill/);
|
|
50
|
+
const bad = run(['nope', '--help'], { cwd: box.root });
|
|
51
|
+
assert.equal(bad.code, 2);
|
|
52
|
+
assert.match(bad.stderr, /不认识的子命令「nope」/);
|
|
53
|
+
assert.match(bad.stderr, /用法: work-rhythm <子命令>/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('用法不对的时候,错误信息后面带一句用法在哪', (t) => {
|
|
57
|
+
const box = makeSandbox(t);
|
|
58
|
+
box.workdir();
|
|
59
|
+
const r = box.run(['today', '2026-13-40']);
|
|
60
|
+
assert.equal(r.code, 2);
|
|
61
|
+
assert.match(r.stderr, /work-rhythm today: 无法识别日期「2026-13-40」/);
|
|
62
|
+
assert.match(r.stderr, /(用法: work-rhythm today --help)/);
|
|
63
|
+
const goals = box.run(['goals', 'nope']);
|
|
64
|
+
assert.equal(goals.code, 2);
|
|
65
|
+
assert.match(goals.stderr, /(用法: work-rhythm goals --help)/);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function writeProfile(dir, line) {
|
|
69
|
+
const file = path.join(dir, '00-config', 'profile.yaml');
|
|
70
|
+
fs.writeFileSync(file, fs.readFileSync(file, 'utf8').replace(/^ notify:.*$/m, ` ${line}`));
|
|
71
|
+
}
|
|
@@ -177,12 +177,12 @@ test('listen:日志里不记消息内容', async (t) => {
|
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
// ---------------------------------------------------------------- 配置
|
|
180
|
-
test('listen
|
|
180
|
+
test('listen:没绑 agent 时退出码为 3,说清怎么绑', async (t) => {
|
|
181
181
|
const s = setup(t);
|
|
182
182
|
const { env } = await withHook(t, s);
|
|
183
183
|
const r = s.listen(['handle', 'x'], { ...env, YZJ_BOT_AGENT: '' });
|
|
184
184
|
assert.equal(r.code, 3);
|
|
185
|
-
assert.match(r.stderr,
|
|
185
|
+
assert.match(r.stderr, /没绑 agent,值守开不了:先 work-rhythm agent detect/);
|
|
186
186
|
});
|
|
187
187
|
|
|
188
188
|
test('listen:没配 YZJ_MY_OPEN_ID 时退出码为 3', async (t) => {
|
|
@@ -244,13 +244,17 @@ test('listen doctor:问题逐条报出来,退出码为 1;配好了什么
|
|
|
244
244
|
assert.equal(ok.stdout, '');
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
-
test('listen:用法不对时退出码为 2
|
|
247
|
+
test('listen:用法不对时退出码为 2,并告诉它用法在哪;--help 打完整用法、退出码 0', async (t) => {
|
|
248
248
|
const s = setup(t);
|
|
249
|
-
|
|
249
|
+
const nope = s.listen(['nope']);
|
|
250
|
+
assert.equal(nope.code, 2);
|
|
251
|
+
assert.match(nope.stderr, /work-rhythm listen: work-rhythm listen <子命令> —— 值守/);
|
|
252
|
+
assert.match(nope.stderr, /(用法: work-rhythm listen --help)/);
|
|
250
253
|
assert.equal(s.listen([]).code, 2);
|
|
251
254
|
const r = s.listen(['--help']);
|
|
252
|
-
assert.
|
|
253
|
-
assert.match(r.
|
|
255
|
+
assert.equal(r.code, 0);
|
|
256
|
+
assert.match(r.stdout, /work-rhythm listen <子命令> —— 值守/);
|
|
257
|
+
assert.match(r.stdout, /handle-frame/);
|
|
254
258
|
});
|
|
255
259
|
|
|
256
260
|
test('listen reset:丢掉机器人的专属会话', async (t) => {
|
|
@@ -136,7 +136,7 @@ test('rhythm doctor:配置齐了时退出码为 0;时间写了却缺指令
|
|
|
136
136
|
// 推送开着却没配消息渠道、agent 没配,都报出来
|
|
137
137
|
s.set('notify', '""');
|
|
138
138
|
assert.match(s.rhythm(['doctor']).stdout, /rhythm.push 开着,但 preferences.notify 没配消息渠道/);
|
|
139
|
-
assert.match(s.rhythm(['doctor'], { ...s.env, YZJ_BOT_AGENT: '' }).stdout,
|
|
139
|
+
assert.match(s.rhythm(['doctor'], { ...s.env, YZJ_BOT_AGENT: '' }).stdout, /没绑 agent:定时任务和机器人值守都要一个 agent 来跑/);
|
|
140
140
|
// 端口不在范围里
|
|
141
141
|
s.set('port', '80');
|
|
142
142
|
assert.match(s.rhythm(['doctor']).stdout, /rhythm.port 要是 1024 到 65535 之间的整数(现在是 80)/);
|
|
@@ -150,7 +150,7 @@ test('rhythm start:配置有问题时不起,退出码为 3,缺指令文件
|
|
|
150
150
|
s.set('notify', '""');
|
|
151
151
|
const r = s.rhythm(['start'], { ...s.env, YZJ_BOT_AGENT: '' });
|
|
152
152
|
assert.equal(r.code, 3);
|
|
153
|
-
assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n
|
|
153
|
+
assert.match(r.stderr, /配置有问题,先跑 work-rhythm rhythm doctor:\n没绑 agent/);
|
|
154
154
|
assert.match(r.stderr, /rhythm.push 开着/);
|
|
155
155
|
assert.ok(!r.stderr.includes('weekly-rhythm'), '缺指令文件的任务到点跳过就行,不该拦着不起');
|
|
156
156
|
});
|
package/scripts/test/stubs.js
CHANGED
|
@@ -98,6 +98,24 @@ fs.writeFileSync(process.env.STUB_ZCODE_ARGS || '/dev/null', args.join(' ') + '\
|
|
|
98
98
|
process.stdout.write(JSON.stringify({ sessionId: 'sess_fake', response: '回复:' + args[args.length - 1], usage: {} }) + '\\n');
|
|
99
99
|
`;
|
|
100
100
|
|
|
101
|
+
// 假的 Qoder CLI:记下参数,照官方文档 --output-format json 的样子回一个 JSON(回答在 result,会话在 session_id)。
|
|
102
|
+
// STUB_QODER_FINAL 不为空时 subtype 用它(error_max_turns 之类),is_error 置真
|
|
103
|
+
const fakeQoder = `
|
|
104
|
+
const fs = require('node:fs');
|
|
105
|
+
const args = process.argv.slice(2);
|
|
106
|
+
fs.writeFileSync(process.env.STUB_QODER_ARGS || '/dev/null', args.join(' ') + '\\n');
|
|
107
|
+
const final = process.env.STUB_QODER_FINAL || '';
|
|
108
|
+
process.stdout.write(JSON.stringify({ type: 'result', subtype: final || 'success', is_error: Boolean(final), result: final ? '出了点问题' : '回复:' + args[args.length - 1], session_id: 'sess_q' }) + '\\n');
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
// 假的 Claude Code 命令行:和 Qoder 那个一样,只是会话 ID 不同
|
|
112
|
+
const fakeClaude = `
|
|
113
|
+
const fs = require('node:fs');
|
|
114
|
+
const args = process.argv.slice(2);
|
|
115
|
+
fs.writeFileSync(process.env.STUB_CLAUDE_ARGS || '/dev/null', args.join(' ') + '\\n');
|
|
116
|
+
process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', is_error: false, result: '回复:' + args[args.length - 1], session_id: 'sess_c' }) + '\\n');
|
|
117
|
+
`;
|
|
118
|
+
|
|
101
119
|
// 假的 DSH 自带 Node:记下调用时的环境,丢掉「--import <路径>」两个参数,用真正的 node 把剩下的交给入口脚本
|
|
102
120
|
const fakeDshNode = `
|
|
103
121
|
const fs = require('node:fs');
|
|
@@ -137,4 +155,4 @@ process.stdout.write(JSON.stringify({ type: 'session', sessionId: 'session_fake'
|
|
|
137
155
|
process.stdout.write(JSON.stringify({ type: 'final', sessionId: 'session_fake', reason: { kind: process.env.STUB_DSH_FINAL || 'completed' }, text: '回复:' + args[args.length - 1] }) + '\\n');
|
|
138
156
|
`;
|
|
139
157
|
|
|
140
|
-
module.exports = { yzjCli, linky, security, fakeAgent, fakeZcode, fakeDshNode, fakeDsh, mdfind, mdls };
|
|
158
|
+
module.exports = { yzjCli, linky, security, fakeAgent, fakeZcode, fakeQoder, fakeClaude, fakeDshNode, fakeDsh, mdfind, mdls };
|
package/templates/AGENTS.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
- [03-carryover/DECISIONS.md](03-carryover/DECISIONS.md) — 每次我怎么决定一件事;只是以后的参考。
|
|
18
18
|
- [04-patterns/WORK_RHYTHM.md](04-patterns/WORK_RHYTHM.md) — 工作规律画像。
|
|
19
19
|
- [05-goals/](05-goals/) — 长期目标,一个文件一个,进行中的不超过 3 个。
|
|
20
|
-
- [collectors/](collectors/) — 自己写的采集器和本机配置(`local.env`,只放本机);内置采集器在 `work-rhythm` 包里。整个目录靠 `work-rhythm <子命令>` 运转:`sync` 同步,`today` 给出今天的路径和是否工作日,`goals` 列出目标、找出到期该检查的,`decisions` 记决定、查以前的决定、归档,`notify` 按 profile 的 `notify` 把计划、复盘推给我,`rhythm` 是本地服务(定时采集、定时整理、推送、本机网页),`listen` 值守着收我在 IM
|
|
20
|
+
- [collectors/](collectors/) — 自己写的采集器和本机配置(`local.env`,只放本机);内置采集器在 `work-rhythm` 包里。整个目录靠 `work-rhythm <子命令>` 运转:`sync` 同步,`today` 给出今天的路径和是否工作日,`goals` 列出目标、找出到期该检查的,`decisions` 记决定、查以前的决定、归档,`events` 列出事件流,`notify` 按 profile 的 `notify` 把计划、复盘推给我,`rhythm` 是本地服务(定时采集、定时整理、推送、本机网页),`agent` 绑定定时任务和值守用哪个 agent,`listen` 值守着收我在 IM 里说的话、交给绑定的 agent 回复,`check` 自检,`selftest` 自测;每个命令的用法看 `work-rhythm <子命令> --help`。
|
|
21
21
|
- [.agents/notes/](.agents/notes/AGENTS.md) — 给 agent 的踩坑笔记和设计取舍。改脚本、配置或文档格式之前,先按它的「动手之前先看哪几篇」过一遍;踩了新坑就记进去。
|
|
22
22
|
|
|
23
23
|
## Standing orders
|
package/templates/README.md
CHANGED
|
@@ -50,8 +50,9 @@ tasks/ 定时任务的指令,一个任务一个文件,是交给 a
|
|
|
50
50
|
- 订阅源在 [00-config/sources.yaml](00-config/sources.yaml):每个源是一个可以独立运行的采集脚本,加一条「提炼成什么事件」的规则。候选有哪些、怎么新增见 [docs/sources.md](docs/sources.md),各 IM 的接法见 [docs/im-adapters.md](docs/im-adapters.md)。
|
|
51
51
|
- 内置的采集器:本机代码提交(含子模块)、文件改动、云之家日程、云之家消息、云之家告警与发布通知、云之家里等我审批的流程、Linky 上分配给我的未完成工作项。要登录的几个默认关着,配好后再到 `sources.yaml` 打开。
|
|
52
52
|
- 不用 AI 也能同步:`work-rhythm sync`,可以直接放进 cron 或 launchd。
|
|
53
|
+
- 问 AI「今天都发生了什么」「我最近在忙什么」,它先 `work-rhythm events` 取事件流再答,不凭印象。
|
|
53
54
|
- 改完配置或文档跑一遍 `work-rhythm check`:语法、内链、预算、配置、疑似密钥、笔记格式,只读不改。
|
|
54
|
-
- 定时任务靠本地服务 `work-rhythm rhythm
|
|
55
|
+
- 定时任务靠本地服务 `work-rhythm rhythm`,不建在 agent 运行时自带的调度器上。服务要先绑一个 agent(`work-rhythm agent bind`,见 [docs/agents.md](docs/agents.md)),没绑就不起,也不支持机器人值守:到点跑采集,到点把 [tasks/](tasks/) 里的指令交给 agent 跑一遍,跑完经消息渠道把总结推给我并附一个本机页面的地址,本机还能打开网页看每日文件、遗留、规律和目标。定义和用法见 [docs/scheduled-tasks.md](docs/scheduled-tasks.md);待决的事不做定时巡查,我对任何一个 agent 说「有什么要我定」就逐件来问。
|
|
55
56
|
- 提醒推送走「消息渠道」,见 [docs/channels.md](docs/channels.md):`profile` 的 `notify` 写渠道名,`work-rhythm notify` 负责发,只发给我本人。预置的是云之家个人机器人(`yzj-robot`):在网页端建一个机器人,把它的 Webhook 地址存进系统钥匙串,就配好了。别的 IM 按「新增一个渠道」接。
|
|
56
57
|
- 渠道还能反过来收:`work-rhythm listen` 和同一个机器人保持长连接,我在云之家里说的话交给本地的 agent 处理并回复。agent 预置了 DSH(模型跟着 DSH 里的配置走)和 ZCode 的命令行,也可以写一条自己的命令。它要常驻、每条消息跑一次 agent,所以默认不开;要开按 `docs/channels.md` 的「收消息:值守」。
|
|
57
58
|
|