work-rhythm 0.2.21 → 0.2.22
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 +10 -3
- 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-skill-ships-with-its-template-in-a-zip.md +1 -0
- package/.agents/notes/decisions/2026-12-01-agent-binding-asks-for-model-and-effort.md +1 -0
- package/.agents/notes/decisions/2026-12-01-interjections-batch-into-one-answer-and-interrupt-reruns.md +1 -0
- package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +1 -0
- package/.agents/notes/decisions/2026-12-01-router-runs-on-a-flash-model-with-low-effort.md +1 -0
- package/.agents/notes/decisions/2026-12-03-codex-cli-joins-as-a-preset-verified-against-its-own-binary.md +45 -0
- package/.agents/notes/decisions/2026-12-03-fewer-scheduled-tasks-silent-refine-no-question-cards.md +1 -0
- package/.agents/notes/decisions/2026-12-03-playbook-distills-handoffs-into-ws-tool-and-skill-know-how.md +43 -0
- package/.agents/notes/decisions/2026-12-03-related-work-comes-back-as-one-reply.md +49 -0
- package/.agents/notes/decisions/2026-12-03-roster-of-worker-groups-router-picks-the-group.md +33 -0
- package/.agents/notes/decisions/2026-12-03-router-model-and-effort-are-configurable.md +28 -0
- package/.agents/notes/decisions/2026-12-03-router-only-direct-mode-removed.md +27 -0
- package/.agents/notes/decisions/2026-12-03-unattended-runs-decide-on-their-own.md +32 -0
- package/.agents/notes/decisions/2026-12-03-update-upgrades-package-and-refreshes-shipped-files.md +30 -0
- package/.agents/notes/decisions/2026-12-03-workers-leave-a-status-trail-that-joins-the-receipt.md +31 -0
- package/.agents/notes/pitfalls/2026-12-01-replace-string-dollar-quote-expands.md +2 -0
- package/.agents/notes/pitfalls/2026-12-03-judging-a-symlink-by-realpath-ignores-parent-links.md +18 -0
- package/.agents/skills/work-rhythm/SKILL.md +20 -16
- package/README.md +13 -10
- package/collectors/local.env.example +31 -36
- package/docs/agents.md +61 -60
- package/docs/channels.md +15 -19
- package/docs/formats.md +27 -0
- package/docs/router-worker.md +60 -41
- package/docs/scheduled-tasks.md +9 -9
- package/package.json +1 -1
- package/scripts/cli.js +9 -5
- package/scripts/cmd/agent.js +348 -235
- package/scripts/cmd/check.js +14 -7
- package/scripts/cmd/listen.js +33 -32
- package/scripts/cmd/pack.js +6 -6
- package/scripts/cmd/rhythm.js +13 -10
- package/scripts/cmd/trigger.js +23 -14
- package/scripts/cmd/update.js +92 -0
- package/scripts/lib/agent.js +235 -142
- package/scripts/lib/agents.js +179 -0
- package/scripts/lib/bot.js +44 -263
- package/scripts/lib/engine.js +327 -110
- package/scripts/lib/handoff.js +54 -8
- package/scripts/lib/markdown.js +19 -0
- package/scripts/lib/playbook.js +123 -0
- package/scripts/lib/rhythm.js +405 -170
- package/scripts/lib/router.js +45 -29
- package/scripts/lib/template.js +3 -3
- package/scripts/lib/update.js +279 -0
- package/scripts/lib/worker.js +11 -5
- package/scripts/test/agent.test.js +410 -257
- package/scripts/test/check.test.js +17 -6
- package/scripts/test/harness.js +5 -2
- package/scripts/test/listen.test.js +190 -158
- package/scripts/test/playbook.test.js +106 -0
- package/scripts/test/rhythm.test.js +164 -54
- package/scripts/test/roster.test.js +155 -0
- package/scripts/test/router-helper.js +17 -2
- package/scripts/test/router.test.js +468 -194
- package/scripts/test/stubs.js +51 -4
- package/scripts/test/timeout.test.js +160 -59
- package/scripts/test/update.test.js +384 -0
- package/tasks/daily-persona.md +30 -11
- package/tasks/daily-plan.md +2 -1
- package/tasks/noon-checkin.md +2 -1
- package/templates/00-config/profile.example.yaml +9 -6
- package/templates/04-patterns/PERSONA.md +4 -1
- package/templates/04-patterns/PLAYBOOK.md +13 -0
- package/templates/AGENTS.md +6 -2
- package/templates/README.md +10 -9
package/scripts/cmd/check.js
CHANGED
|
@@ -14,6 +14,7 @@ const { resolveCollector } = require('./sync');
|
|
|
14
14
|
const { createBot } = require('../lib/bot');
|
|
15
15
|
const launchd = require('../lib/launchd');
|
|
16
16
|
const { PRESET_NAMES } = require('../lib/agent');
|
|
17
|
+
const rosterLib = require('../lib/agents');
|
|
17
18
|
const { loadProfile } = require('../lib/config');
|
|
18
19
|
const { GENERATED_DIRS, templateProblems } = require('../lib/template');
|
|
19
20
|
|
|
@@ -217,18 +218,24 @@ function checkConfig({ root, packageRoot, env, say }) {
|
|
|
217
218
|
if (!which('security', env)) bad.push(`消息渠道 ${channel} 需要 security,本机没有`);
|
|
218
219
|
else if (!hasWebhook(env)) bad.push(`消息渠道 ${channel}:钥匙串里没有 ${serviceName(env)}(开通步骤见 docs/channels.md「云之家」)`);
|
|
219
220
|
}
|
|
220
|
-
// 值守(work-rhythm listen,渠道的收消息一半):装了(launchd 里有它)才检查——agent
|
|
221
|
+
// 值守(work-rhythm listen,渠道的收消息一半):装了(launchd 里有它)才检查——agent 是路由和执行者的前提,
|
|
221
222
|
// 只绑了 agent 跑任务的人不该被报「值守没配渠道」。查什么由它自己的 doctor 说了算,这里不重复一遍
|
|
222
|
-
if (!envProblems.length && fs.existsSync(launchd.plistPath('bot', root))) bad.push(...createBot({ root, env: values }).doctorProblems());
|
|
223
|
-
//
|
|
223
|
+
if (!envProblems.length && fs.existsSync(launchd.plistPath('bot', root))) bad.push(...createBot({ root, env: values, onMessage: () => null, doctorAgent: () => rosterLib.inspect(root, values, rosterLib.loadRoster(root, values)).problems }).doctorProblems());
|
|
224
|
+
// 定时任务走引擎:schedule 里开着任务(指令文件也在)却没绑好路由和执行者的 agent,到点一个也跑不了
|
|
224
225
|
const profileDoc = loadProfile(root);
|
|
225
226
|
const schedule = profileDoc.schedule && typeof profileDoc.schedule === 'object' ? profileDoc.schedule : {};
|
|
226
227
|
const scheduled = Object.keys(schedule).filter((id) => String(schedule[id] || '').trim() && !['ask-decisions'].includes(id));
|
|
227
228
|
// 引导走到第 6 步(status 是 scheduled 或 done)之后才算数:之前 schedule 里是模板的默认时间,agent 是第 6 步才绑的
|
|
228
229
|
const status = profileDoc.setup && profileDoc.setup.status;
|
|
229
|
-
if (scheduled.length && ['scheduled', 'done'].includes(status) && !envProblems.length
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
230
|
+
if (scheduled.length && ['scheduled', 'done'].includes(status) && !envProblems.length) {
|
|
231
|
+
const team = rosterLib.loadRoster(root, values);
|
|
232
|
+
if (!team.router.agent || !team.workers.some((w) => w.agent)) {
|
|
233
|
+
const withPrompt = scheduled.filter((id) => fs.existsSync(path.join(root, 'tasks', `${id}.md`)));
|
|
234
|
+
if (withPrompt.length) bad.push(`schedule 里有任务(${withPrompt.join('、')})却没绑好 agent,到点一个也跑不了:work-rhythm agent bind <${PRESET_NAMES.join('|')}>(路由和执行者都绑上)`);
|
|
235
|
+
} else {
|
|
236
|
+
// 绑了但配得不对(命令找不到、dsh 没配置、模型它不认):到点一样跑不了
|
|
237
|
+
bad.push(...rosterLib.inspect(root, values, team).problems);
|
|
238
|
+
}
|
|
232
239
|
}
|
|
233
240
|
bad.forEach(say);
|
|
234
241
|
return bad.length;
|
|
@@ -320,7 +327,7 @@ function genericProblems({ root, say }) {
|
|
|
320
327
|
// 交接文档是工作目录运行时才有的(路由写给执行者的任务书、执行者的回执,里面有用户原话):init 和 pack 会把 .agents/ 整个带走,
|
|
321
328
|
// 仓库里混进一份就等于发给了所有人
|
|
322
329
|
const handoff = path.join(root, '.agents', 'handoff');
|
|
323
|
-
if (fs.existsSync(handoff) && fs.readdirSync(handoff).some((n) => /^t-\d+(\.result)?\.md$/.test(n))) bad.push('仓库里出现了交接文档 .agents/handoff/t-*.md
|
|
330
|
+
if (fs.existsSync(handoff) && fs.readdirSync(handoff).some((n) => /^t-\d+(\.result|\.status)?\.md$/.test(n))) bad.push('仓库里出现了交接文档 .agents/handoff/t-*.md:那是工作目录里路由和执行者之间的任务书、过程记录与回执,含用户原话,init 和 pack 会把它带走。删掉,要试跑先用 work-rhythm init 建一个临时工作目录');
|
|
324
331
|
bad.forEach(say);
|
|
325
332
|
return bad.length;
|
|
326
333
|
}
|
package/scripts/cmd/listen.js
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
// 值守:消息渠道的收消息一半。实现在 lib/bot.js,这里只管子命令、输出和退出码。
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// 不是它时拒绝运行。消息一到先回「收到,正在处理」(YZJ_BOT_ACK=0 关掉)。
|
|
6
|
-
// 日志写 01-inbox/_bot.log,只记时间、msgId
|
|
2
|
+
// 它只管收:本人校验、去重、/new。我的一句话交给引擎(路由判断 → 执行者 → 路由),回复由引擎经消息渠道发回来。
|
|
3
|
+
// 配置在 collectors/local.env(说明见 local.env.example):YZJ_MY_OPEN_ID 只认我本人;路由和执行者用哪个 agent 在名册里
|
|
4
|
+
// (00-config/agents.json,work-rhythm agent bind 或本机网页 /agents 配)。机器人的 Webhook 地址和推送共用,取自系统钥匙串。
|
|
5
|
+
// 值守属于 yzj-robot 渠道,preferences.notify 不是它时拒绝运行。消息一到先回「收到,正在处理」(YZJ_BOT_ACK=0 关掉)。
|
|
6
|
+
// 日志写 01-inbox/_bot.log,只记时间、msgId、发消息人,不记消息内容。步骤见 docs/channels.md「收消息:值守」。
|
|
7
7
|
'use strict';
|
|
8
8
|
const path = require('node:path');
|
|
9
9
|
const fs = require('node:fs');
|
|
10
|
-
const { EXIT, UsageError, readText } = require('../lib/run');
|
|
11
|
-
const { settings } = require('../lib/config');
|
|
10
|
+
const { EXIT, Fail, UsageError, readText } = require('../lib/run');
|
|
11
|
+
const { settings, writeLocalEnv } = require('../lib/config');
|
|
12
12
|
const { createBot } = require('../lib/bot');
|
|
13
13
|
const { createRhythm } = require('../lib/rhythm');
|
|
14
|
-
const { writeLocalEnv } = require('../lib/config');
|
|
15
14
|
const launchd = require('../lib/launchd');
|
|
16
15
|
|
|
17
|
-
const USAGE = `work-rhythm listen <子命令> —— 值守:消息渠道的收消息一半。在 IM
|
|
16
|
+
const USAGE = `work-rhythm listen <子命令> —— 值守:消息渠道的收消息一半。在 IM 里说的话交给路由判断、派给执行者,回复发回来。
|
|
18
17
|
它跑在本地服务那一个进程里(work-rhythm rhythm),不再单独常驻
|
|
19
18
|
|
|
20
19
|
用法: work-rhythm listen <子命令>
|
|
21
|
-
probe [--seconds N]
|
|
22
|
-
run
|
|
23
|
-
handle "<消息>" [--push]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
reset 丢掉机器人的专属会话,下一句从新会话开始(在聊天里发 /new 也一样)
|
|
20
|
+
probe [--seconds N] 连上去看握手和收到的每一帧,不交给路由,到时退出(默认 60 秒)。第一次验证用
|
|
21
|
+
run 值守:一直连着,收到消息就走路由 → 执行者 → 路由。单独的进程,停了就没了
|
|
22
|
+
handle "<消息>" [--push] 不连云之家,走一遍全流程(路由 → 执行者 → 路由),把要发给用户的话打到屏幕上;带 --push 才真发
|
|
23
|
+
handle-frame '<JSON>' 把一帧当作刚收到的处理一遍,等它走完全流程(自测用)
|
|
24
|
+
reset 丢掉路由自己的专属会话,下一句从绑定的那个会话接着走(在聊天里发 /new 也一样)
|
|
27
25
|
doctor 检查值守的配置和依赖,有问题逐条报出来
|
|
28
26
|
install | uninstall 开 / 关值守的常驻:它跑在本地服务(work-rhythm rhythm)那个进程里,和定时任务、推送、网页是同一个后台;
|
|
29
27
|
没装服务的话顺手装上,装了就重启一次让改动生效
|
|
30
28
|
status 本地服务在不在跑、值守开着没、最近一条值守日志
|
|
31
|
-
|
|
32
|
-
日志 01-inbox/_bot.log 只记时间、msgId
|
|
29
|
+
前提:先绑好路由和执行者的 agent(work-rhythm agent bind router / worker,见 docs/agents.md)。消息一到先回「收到,正在处理」,路由的话随后到。
|
|
30
|
+
日志 01-inbox/_bot.log 只记时间、msgId,不记消息内容。
|
|
33
31
|
退出码: 0 完成;2 用法不对;3 没配置好(没绑 agent、钥匙串里没有地址、不是 yzj-robot 渠道);4 缺依赖;5 连不上或没处理成功。
|
|
34
32
|
步骤见 docs/channels.md「收消息:值守」。`;
|
|
35
33
|
|
|
@@ -44,8 +42,10 @@ module.exports = {
|
|
|
44
42
|
const { root, stdout, env, packageRoot } = ctx;
|
|
45
43
|
const [cmd, ...rest] = args;
|
|
46
44
|
const settingsEnv = settings(root, env);
|
|
47
|
-
const bot = createBot({ root, env: settingsEnv });
|
|
48
45
|
const service = createRhythm({ root, env: settingsEnv, packageRoot });
|
|
46
|
+
// 值守收到的话交给引擎:在命令行的进程里也建一份(listen run、handle-frame 用得上)
|
|
47
|
+
const eng = service.makeEngine();
|
|
48
|
+
const bot = createBot({ root, env: settingsEnv, onMessage: (m) => eng.message(m), resetSession: () => eng.resetSession(), say: (text) => eng.say(text), doctorAgent: () => eng.doctorProblems() });
|
|
49
49
|
const lastBotLog = () => {
|
|
50
50
|
const lines = readText(path.join(root, '01-inbox', '_bot.log')).trim().split('\n');
|
|
51
51
|
return lines[lines.length - 1] || '';
|
|
@@ -69,34 +69,35 @@ module.exports = {
|
|
|
69
69
|
return EXIT.OK; // 循环退出后可能还挂着重连的定时器,命令到这里就结束
|
|
70
70
|
case 'handle': {
|
|
71
71
|
if (!rest.length) throw new UsageError(USAGE);
|
|
72
|
+
bot.requireConfig();
|
|
72
73
|
const really = rest.includes('--push');
|
|
73
74
|
const text = rest.filter((a) => a !== '--push').join(' ');
|
|
74
|
-
//
|
|
75
|
+
// 在命令行的进程里走一遍全流程(路由 → 执行者 → 路由),要发的话打到屏幕上
|
|
75
76
|
const r = await service.handle(text, { push: really });
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!r.texts.length) stdout.write(`${really ? '' : '\n(没有:路由没有要发给用户的话。work-rhythm trigger show 看任务书和回执)'}\n`);
|
|
80
|
-
return EXIT.OK;
|
|
81
|
-
}
|
|
82
|
-
stdout.write(`${bot.handle(text)}\n`);
|
|
77
|
+
stdout.write(`触发 ${r.id}:路由 → 执行者 → 路由走完了。${really ? '要发的话已经发了。' : '要发给用户的话(没发;带 --push 才真发):'}\n`);
|
|
78
|
+
for (const t of r.texts) stdout.write(`\n${t}\n`);
|
|
79
|
+
if (!r.texts.length && !really) stdout.write(`\n(没有:路由没有要发给用户的话。work-rhythm trigger show 看任务书和回执)\n`);
|
|
83
80
|
return EXIT.OK;
|
|
84
81
|
}
|
|
85
82
|
case 'handle-frame': {
|
|
86
83
|
if (!rest.length) throw new UsageError(USAGE);
|
|
87
|
-
|
|
84
|
+
bot.requireConfig();
|
|
85
|
+
const r = await bot.processFrame(rest.join(' '));
|
|
88
86
|
stdout.write(`${r.result}\n`);
|
|
87
|
+
// 防抖里压着的先放出来,再等这一句走完(路由 → 执行者 → 路由),回复也发完了才结束
|
|
88
|
+
eng.flushMessages();
|
|
89
|
+
await eng.waitIdle();
|
|
89
90
|
return r.code;
|
|
90
91
|
}
|
|
91
92
|
case 'reset':
|
|
92
93
|
if (rest.length) throw new UsageError(USAGE);
|
|
93
|
-
|
|
94
|
-
stdout.write('
|
|
94
|
+
eng.resetSession();
|
|
95
|
+
stdout.write('已丢掉路由自己的专属会话,下一句从绑定的那个会话接着走。\n');
|
|
95
96
|
return EXIT.OK;
|
|
96
97
|
case 'doctor': {
|
|
97
98
|
if (rest.length) throw new UsageError(USAGE);
|
|
98
|
-
const problems = [...bot.doctorProblems(), ...
|
|
99
|
-
const notes = service.doctorNotes(
|
|
99
|
+
const problems = [...new Set([...bot.doctorProblems(), ...service.doctorProblems({ strict: false, bot: false }).filter((p) => !p.startsWith('任务 '))])];
|
|
100
|
+
const notes = service.doctorNotes();
|
|
100
101
|
if (problems.length) stdout.write(`${problems.join('\n')}\n`);
|
|
101
102
|
for (const n of notes) stdout.write(`注意:${n}\n`);
|
|
102
103
|
return problems.length ? 1 : EXIT.OK;
|
|
@@ -104,7 +105,7 @@ module.exports = {
|
|
|
104
105
|
case 'install': {
|
|
105
106
|
// 开值守:先把配置查一遍(agent、钥匙串、我的 openId、渠道),再打开开关;值守跑在本地服务那个进程里
|
|
106
107
|
if (rest.length) throw new UsageError(USAGE);
|
|
107
|
-
bot.requireConfig(
|
|
108
|
+
bot.requireConfig();
|
|
108
109
|
const file = writeLocalEnv(root, { YZJ_BOT_LISTEN: '1' });
|
|
109
110
|
// 以前值守是单独一个常驻,把它收掉,只留服务那一个
|
|
110
111
|
launchd.uninstall('bot', root);
|
package/scripts/cmd/pack.js
CHANGED
|
@@ -39,20 +39,20 @@ const README = (version, tgz) => `# work-rhythm skill:安装和开始
|
|
|
39
39
|
1. 装 npm 包(要 node 22 以上)。在这个目录里运行:
|
|
40
40
|
\`npm install -g ./${tgz}\`
|
|
41
41
|
装好后 \`work-rhythm --help\` 能跑。
|
|
42
|
-
2.
|
|
43
|
-
-
|
|
44
|
-
-
|
|
42
|
+
2. 把 skill 装到 AI 助手读的 skills 目录。两种都行,软链更好——包升级了它跟着走,不用再管:
|
|
43
|
+
- 软链(推荐):\`mkdir -p ~/.agents/skills && ln -sfn "$(npm root -g)/work-rhythm/.agents/skills/work-rhythm" ~/.agents/skills/work-rhythm\`
|
|
44
|
+
- 拷贝:把整个 \`work-rhythm/\` 目录拷进去——只在某个项目里用就放到那个项目的 \`.agents/skills/\` 下,在任何目录里都能用就放到 \`~/.agents/skills/\` 下。\`work-rhythm update\` 升级时会把它换成新版
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
用任意能读本地文件的 AI 助手(Qoder、ZCode、DeepSeek Harness、Claude Code、Kimi Code 等,手头有啥用啥)打开任意项目。
|
|
47
47
|
|
|
48
48
|
## 开始
|
|
49
49
|
|
|
50
|
-
对 AI 说「开始引导」。它会问你想把工作目录放在哪(默认 \`~/workspace/my-work\`),用 \`work-rhythm init\` 建好、登记,再一步步问你:用哪个 IM
|
|
50
|
+
对 AI 说「开始引导」。它会问你想把工作目录放在哪(默认 \`~/workspace/my-work\`),用 \`work-rhythm init\` 建好、登记,再一步步问你:用哪个 IM、接哪些数据源、路由和执行者用哪个 agent、作息和定时任务。
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
## 升级
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
跑 \`work-rhythm update\`(先 \`--check\` 看有没有新版):它升级 npm 包,顺手把这个 skill 换成新版(拷贝的那份;软链的本来就跟着包走),工作目录里随包带来的文档和任务指令也一起更新。你自己改过的文件先备份再覆盖,\`00-config/\` 里你填的配置和自己的记录都不用动。
|
|
56
56
|
`;
|
|
57
57
|
|
|
58
58
|
module.exports = {
|
package/scripts/cmd/rhythm.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// 配置:
|
|
4
4
|
// profile.yaml 的 schedule 各任务的时间(已有的那一节);任务的指令在 tasks/<id>.md,一个任务一个文件
|
|
5
5
|
// profile.yaml 的 rhythm 采集的时间 sync、网页端口 port、推送开关 push、不推送的任务 quiet
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// 00-config/agents.json 路由和每组执行者用哪个 agent、模型、强度、同时跑几个(work-rhythm agent,或者本机网页 /agents)
|
|
7
|
+
// 任务到点变成触发,走引擎:路由判断 → 派给执行者 → 回执交回路由,由它写给我的话经消息渠道推过来。
|
|
8
|
+
// 推送走消息渠道(work-rhythm notify),所以 preferences.notify 要配好。任务要写文件,执行者以可写工作目录的权限跑。
|
|
8
9
|
// 说明见 docs/scheduled-tasks.md。
|
|
9
10
|
'use strict';
|
|
10
11
|
const { EXIT, Fail, UsageError } = require('../lib/run');
|
|
@@ -12,21 +13,22 @@ const { settings } = require('../lib/config');
|
|
|
12
13
|
const { createRhythm } = require('../lib/rhythm');
|
|
13
14
|
const launchd = require('../lib/launchd');
|
|
14
15
|
|
|
15
|
-
const USAGE = `work-rhythm rhythm <子命令> ——
|
|
16
|
+
const USAGE = `work-rhythm rhythm <子命令> —— 本地服务:定时采集、定时把任务交给路由派给执行者、经消息渠道推送、本机网页
|
|
16
17
|
|
|
17
18
|
用法: work-rhythm rhythm <子命令>
|
|
18
19
|
start [--tick 秒] 前台跑:到点跑采集和任务,起网页服务。要常驻用 install;--tick 是多久看一次表(默认 20,调试用)
|
|
19
20
|
stop | status | restart 停掉;看在不在跑、下次什么时候跑什么、值守开着没;重启常驻(改了配置用)
|
|
20
21
|
due [--at 时间] [--days 天数] 从某个时间起,列出什么时候跑什么
|
|
21
|
-
run <任务id|sync> [--push]
|
|
22
|
+
run <任务id|sync> [--push] 立刻跑一次,不等时间。任务和到点的一样走路由(路由 → 执行者 → 路由);不带 --push 时
|
|
23
|
+
要发给用户的话打到屏幕上,不真发
|
|
22
24
|
serve [--port 端口] 只起网页服务
|
|
23
25
|
render <文件.md> 把一份 Markdown 渲染成页面,打到标准输出(自测、调试用)
|
|
24
|
-
doctor
|
|
26
|
+
doctor 检查配置和依赖,有问题逐条报出来;不算问题的注意事项另起一行(比如路由用了没有只读档的 kimi)
|
|
25
27
|
install | uninstall macOS launchd 常驻:开机自启、挂了拉起
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
定时任务只建在这个服务上,要先绑好路由和执行者的 agent(work-rhythm agent bind router / worker)。任务到点后:变成触发交给路由,
|
|
29
|
+
由它挑一组执行者把 tasks/<id>.md 的指令跑一遍(它会同步数据、整理事件流、写每日文件),回执交回路由,路由写的话经消息渠道推给我,
|
|
30
|
+
并附本机页面地址。网页多两页:监控中心 /monitor(服务、路由、执行者、定时任务、触发、配置、日志)、配置 agent 的 /agents;
|
|
31
|
+
/status.json 是监控那一份数据的 JSON。
|
|
30
32
|
退出码: 0 完成;2 用法不对;3 没配置好(没绑 agent、配置有问题、已经在跑);4 缺依赖;5 运行失败;doctor 查出问题时是 1。
|
|
31
33
|
定义和用法见 docs/scheduled-tasks.md,agent 见 docs/agents.md。`;
|
|
32
34
|
|
|
@@ -85,7 +87,8 @@ module.exports = {
|
|
|
85
87
|
case 'run': {
|
|
86
88
|
const id = rest[0];
|
|
87
89
|
if (!id || rest.slice(1).some((a) => a !== '--push')) throw new UsageError(USAGE);
|
|
88
|
-
|
|
90
|
+
const code = await service.runJob(id, rest.includes('--push'));
|
|
91
|
+
return typeof code === 'number' ? code : code.ok ? EXIT.OK : EXIT.FAILED;
|
|
89
92
|
}
|
|
90
93
|
case 'render':
|
|
91
94
|
if (rest.length !== 1) throw new UsageError(USAGE);
|
package/scripts/cmd/trigger.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// work-rhythm trigger
|
|
1
|
+
// work-rhythm trigger:看处理过的触发,手动塞一条进去。
|
|
2
2
|
// 实现(排队、决定、执行者、汇报)在 lib/engine.js,交接文档在 lib/handoff.js。说明见 docs/router-worker.md。
|
|
3
3
|
'use strict';
|
|
4
4
|
const fs = require('node:fs');
|
|
@@ -9,16 +9,16 @@ const { createRhythm } = require('../lib/rhythm');
|
|
|
9
9
|
const { fire, queueDir } = require('../lib/engine');
|
|
10
10
|
const handoff = require('../lib/handoff');
|
|
11
11
|
|
|
12
|
-
const USAGE = `work-rhythm trigger <子命令> —— 触发:到点的任务、IM
|
|
12
|
+
const USAGE = `work-rhythm trigger <子命令> —— 触发:到点的任务、IM 里的话、执行者的汇报都从这条路走
|
|
13
13
|
|
|
14
14
|
用法: work-rhythm trigger <子命令>
|
|
15
|
-
list [--days 1] [--json]
|
|
16
|
-
show <短号> 打印这条的任务书和回执(工作目录的 .agents/handoff/
|
|
15
|
+
list [--days 1] [--json] 最近处理过的触发,新的在前:时间、短号、来源、决定、派给了哪组执行者、状态和用时(在跑的带最近一步)、发没发、任务书、过程、回执在不在
|
|
16
|
+
show <短号> 打印这条的任务书和回执(工作目录的 .agents/handoff/ 下);还在做、回执还没出来的,先打它到此刻的过程记录
|
|
17
17
|
fire "<一句话>" [--mode plan|edit] [--wait [--timeout 秒]]
|
|
18
|
-
|
|
18
|
+
手动塞一条触发进队列:本地服务在跑就交给路由,由它挑一组执行者派出去。--mode 是路由没出决定时执行者的权限
|
|
19
19
|
(默认 plan)。--wait 等它做完,把路由的决定和执行者的回执打到屏幕上
|
|
20
20
|
路由先判一下再派人:这句话是闲聊它可能不回,是一句话能答的它直接答,要动手的才派执行者。
|
|
21
|
-
退出码: 0;2 用法不对;3
|
|
21
|
+
退出码: 0;2 用法不对;3 服务没在跑、没有这条触发,或 --wait 没等到;5 运行失败。
|
|
22
22
|
详见 docs/router-worker.md。`;
|
|
23
23
|
|
|
24
24
|
const STATUS_CN = { queued: '排队中', running: '在跑', ok: '成功', failed: '失败', stopped: '叫停' };
|
|
@@ -37,8 +37,13 @@ const nonEmpty = (file) => {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
//
|
|
41
|
-
const docsOf = (root, t) => ({ task: nonEmpty(handoff.taskPath(root, t.id)), result: nonEmpty(handoff.resultPath(root, t.id)) });
|
|
40
|
+
// 一条触发的任务书、过程记录、回执在不在
|
|
41
|
+
const docsOf = (root, t) => ({ task: nonEmpty(handoff.taskPath(root, t.id)), status: nonEmpty(handoff.statusPath(root, t.id)), result: nonEmpty(handoff.resultPath(root, t.id)) });
|
|
42
|
+
// 一句话的长度上限(表格的一格)
|
|
43
|
+
const brief = (text, max = 80) => {
|
|
44
|
+
const chars = Array.from(String(text || '').trim());
|
|
45
|
+
return chars.length > max ? `${chars.slice(0, max).join('')}…` : chars.join('');
|
|
46
|
+
};
|
|
42
47
|
|
|
43
48
|
module.exports = {
|
|
44
49
|
usage: USAGE,
|
|
@@ -64,13 +69,15 @@ module.exports = {
|
|
|
64
69
|
const since = `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
|
|
65
70
|
const list = Object.values(service.store.data.triggers || {}).filter((t) => t.at >= since).sort((a, b) => b.at.localeCompare(a.at) || b.id.localeCompare(a.id));
|
|
66
71
|
if (json) {
|
|
67
|
-
stdout.write(`${JSON.stringify(list.map((t) => ({ ...t, docs: docsOf(root, t) })), null, 1)}\n`);
|
|
72
|
+
stdout.write(`${JSON.stringify(list.map((t) => ({ ...t, step: handoff.lastStatus(root, t.id).line, docs: docsOf(root, t) })), null, 1)}\n`);
|
|
68
73
|
return EXIT.OK;
|
|
69
74
|
}
|
|
70
75
|
stdout.write(`${FIELDS.join('\t')}\n`);
|
|
71
76
|
for (const t of list) {
|
|
72
77
|
const w = t.worker || {};
|
|
73
78
|
const docs = docsOf(root, t);
|
|
79
|
+
// 在跑的带上执行者最近记的一步过程(它边做边追加的)
|
|
80
|
+
const step = w.status === 'running' ? handoff.lastStatus(root, t.id).line : '';
|
|
74
81
|
const cells = {
|
|
75
82
|
at: t.at,
|
|
76
83
|
id: t.id,
|
|
@@ -78,16 +85,16 @@ module.exports = {
|
|
|
78
85
|
task: t.task || '',
|
|
79
86
|
of: t.of || '',
|
|
80
87
|
decision: t.decision || '',
|
|
81
|
-
worker: w.status ? `${STATUS_CN[w.status] || w.status}${w.status === 'failed' && w.reason ? `(${w.reason})` : ''}` : '',
|
|
88
|
+
worker: w.status ? `${STATUS_CN[w.status] || w.status}${w.status === 'failed' && w.reason ? `(${w.reason})` : ''}${step ? `|最近一步:${brief(step)}` : ''}` : '',
|
|
82
89
|
seconds: w.seconds === undefined ? '' : String(w.seconds),
|
|
83
90
|
agent: w.agent || '',
|
|
84
91
|
mode: w.mode || '',
|
|
85
92
|
notified: t.notified ? 'yes' : '',
|
|
86
|
-
docs: [docs.task ? '任务书' : '', docs.result ? '回执' : ''].filter(Boolean).join('+'),
|
|
93
|
+
docs: [docs.task ? '任务书' : '', docs.status ? '过程' : '', docs.result ? '回执' : ''].filter(Boolean).join('+'),
|
|
87
94
|
};
|
|
88
95
|
stdout.write(`${FIELDS.map((f) => String(cells[f]).replace(/\t/g, ' ')).join('\t')}\n`);
|
|
89
96
|
}
|
|
90
|
-
if (!list.length) stdout.write(`(最近 ${days}
|
|
97
|
+
if (!list.length) stdout.write(`(最近 ${days} 天没有触发)\n`);
|
|
91
98
|
return EXIT.OK;
|
|
92
99
|
}
|
|
93
100
|
case 'show': {
|
|
@@ -95,8 +102,11 @@ module.exports = {
|
|
|
95
102
|
const id = rest[0];
|
|
96
103
|
const task = handoff.readText(handoff.taskPath(root, id));
|
|
97
104
|
const result = handoff.readText(handoff.resultPath(root, id));
|
|
98
|
-
|
|
105
|
+
const trail = handoff.readStatus(root, id);
|
|
106
|
+
if (!task && !result && !trail.length) throw new Fail(EXIT.NOT_CONFIGURED, `没有 ${id} 这条的交接文档(.agents/handoff/):可能过期清掉了,work-rhythm trigger list 看还有哪些`);
|
|
99
107
|
if (task) stdout.write(`${task.trimEnd()}\n`);
|
|
108
|
+
// 回执还没出来(还在做):先打它到此刻的过程记录。回执出来之后过程已经并进去了
|
|
109
|
+
if (!result && trail.length) stdout.write(`\n${'─'.repeat(40)}\n\n(还没做完,过程记录到此为止 ${trail.length} 步)\n${trail.map((l) => `- ${l}`).join('\n')}\n`);
|
|
100
110
|
if (result) stdout.write(`\n${'─'.repeat(40)}\n\n${result.trimEnd()}\n`);
|
|
101
111
|
return EXIT.OK;
|
|
102
112
|
}
|
|
@@ -115,7 +125,6 @@ module.exports = {
|
|
|
115
125
|
}
|
|
116
126
|
if (!text) throw new UsageError(USAGE);
|
|
117
127
|
if (!['plan', 'edit'].includes(mode)) throw new UsageError('--mode 只能是 plan 或 edit');
|
|
118
|
-
if (!service.cfg.router) throw new Fail(EXIT.NOT_CONFIGURED, '路由没开(profile 的 rhythm 没写 router):触发塞进去没人取。要走「触发 → 路由 → 执行者」在 00-config/profile.yaml 的 rhythm 一节写上 router: true,再 work-rhythm rhythm restart');
|
|
119
128
|
if (!service.serviceAlive()) throw new Fail(EXIT.NOT_CONFIGURED, '本地服务没在跑:先 work-rhythm rhythm start(或 install 装成常驻),再 fire');
|
|
120
129
|
const key = fire(root, { text, mode });
|
|
121
130
|
stdout.write(`已塞进队列(${path.relative(root, queueDir(root))}),服务下一次看表(最多 20 秒)取走交给路由。\n`);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// work-rhythm update:升级这个包,顺手把 skill 和工作目录里随包带来的文件更新到新版本。
|
|
2
|
+
// 核心在 lib/update.js(怎么问 registry、怎么同步、改过的怎么备份都在那儿),这里只管参数、报告和退出码。
|
|
3
|
+
// 不需要站在工作目录里:站在里面(或 --workdir 指定)才顺带同步工作目录的文件。
|
|
4
|
+
// 用法: work-rhythm update [--check] [--dry-run]
|
|
5
|
+
// 退出码: 0 完成(已是最新也是 0);2 用法不对;3 registry 上有新版但升不了(全局的是软链到仓库,或者没装);4 本机没有 npm;5 升级没成。
|
|
6
|
+
'use strict';
|
|
7
|
+
const { EXIT, UsageError } = require('../lib/run');
|
|
8
|
+
const { settings } = require('../lib/config');
|
|
9
|
+
const { isWorkdir } = require('../lib/workdir');
|
|
10
|
+
const { createRhythm } = require('../lib/rhythm');
|
|
11
|
+
const { update, newer, NAME, SKILL_DIRS } = require('../lib/update');
|
|
12
|
+
|
|
13
|
+
const ACTION_CN = { add: '新增', update: '更新', replace: '改过,备份后更新', remove: '上一版有、新版没了,删除', kept: '上一版有、新版没了,但你改过,留着' };
|
|
14
|
+
|
|
15
|
+
const USAGE = `work-rhythm update —— 升级这个包,顺手把 skill 和工作目录里随包带来的文件更新到新版本
|
|
16
|
+
|
|
17
|
+
用法:
|
|
18
|
+
work-rhythm update [--workdir <目录>] 升级,然后同步随包带来的文件
|
|
19
|
+
work-rhythm update --check 只看 registry 上有没有新版本,什么都不改
|
|
20
|
+
work-rhythm update --dry-run 走一遍但只报告会改什么:不升级包,不写文件
|
|
21
|
+
做什么:
|
|
22
|
+
1. 问 registry 最新的版本(npm view),比装着的新就 npm install -g work-rhythm@<版本>
|
|
23
|
+
2. 用户级 skills 目录(${SKILL_DIRS.slice(0, 2).join('、')} 等)里的 work-rhythm:软链指向包的不用动;拷贝的换成新包里那份
|
|
24
|
+
3. 站在工作目录里(或 --workdir 指定):把 init 时从包里复制过去的 docs、tasks、.agents、collectors/local.env.example
|
|
25
|
+
和 00-config/profile.example.yaml 更新到新版
|
|
26
|
+
随包带来的文件改过怎么办:和上一版包里一模一样的直接覆盖;你改过的(或是更早的版本留下的)先备份再覆盖,报告里逐个点名。
|
|
27
|
+
备份在工作目录的 01-inbox/_update/<时间>/ 下;没有工作目录就在 ~/.config/work-rhythm/backups/<时间>/ 下。
|
|
28
|
+
只属于你的文件不碰:profile.yaml、sources.yaml、每日文件、遗留、决定、规律、目标、local.env、交接文档、自己写的任务。
|
|
29
|
+
全局的 work-rhythm 不是 npm 装的(软链到仓库,或者全局根本没装):包不动,只同步文件——那种装法升级是更新那边的代码;
|
|
30
|
+
registry 上有新版而这里升不了时退出码 3,已经是最新就是 0。
|
|
31
|
+
本地服务在跑时,任务指令和路由提示词的新版要重启才全部生效:work-rhythm rhythm restart(这里不替你重启)。
|
|
32
|
+
退出码: 0 完成(已是最新也是 0);2 用法不对;3 registry 上有新版,但全局的不是 npm 装的(软链、没装),升不了;4 本机没有 npm;5 升级没成(离线、npm 报错)。`;
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
usage: USAGE,
|
|
36
|
+
async run(args, ctx) {
|
|
37
|
+
const { root, stdout, env, packageRoot } = ctx;
|
|
38
|
+
let dryRun = false;
|
|
39
|
+
let checkOnly = false;
|
|
40
|
+
for (const a of args) {
|
|
41
|
+
if (a === '--dry-run') dryRun = true;
|
|
42
|
+
else if (a === '--check') checkOnly = true;
|
|
43
|
+
else throw new UsageError(USAGE);
|
|
44
|
+
}
|
|
45
|
+
const say = (text = '') => stdout.write(`${text}\n`);
|
|
46
|
+
const workdir = isWorkdir(root) ? root : '';
|
|
47
|
+
const r = update({ packageRoot, home: env.HOME || '', workdir, env, dryRun, checkOnly });
|
|
48
|
+
// 包没升成、文件也没同步(没有 npm、问不到 registry、npm install 报错):只报原因
|
|
49
|
+
const fail = { missing: EXIT.MISSING_DEP, failed: EXIT.FAILED };
|
|
50
|
+
if (r.problem && fail[r.problemCode]) {
|
|
51
|
+
say(r.problem);
|
|
52
|
+
return fail[r.problemCode];
|
|
53
|
+
}
|
|
54
|
+
const hasNew = newer(r.latest, r.from);
|
|
55
|
+
if (checkOnly) {
|
|
56
|
+
if (!r.installed) say(`全局没有用 npm 装过 ${NAME}(现在运行的这份是 ${r.from || '认不出版本'});registry 上最新的是 ${r.latest}。装一份:npm install -g ${NAME}`);
|
|
57
|
+
else if (hasNew) say(`有新版本:装着的是 ${r.from},registry 上最新的是 ${r.latest}。${r.linked ? `全局的是软链(${r.installed}),要升到 ${r.latest} 得更新它指向的那份代码。` : '升级:work-rhythm update'}`);
|
|
58
|
+
else say(`已是最新:装着的 ${r.from} 就是 registry 上最新的。`);
|
|
59
|
+
return EXIT.OK;
|
|
60
|
+
}
|
|
61
|
+
// 1 包
|
|
62
|
+
if (r.upgraded) say(`${NAME} 已升级:${r.from} → ${r.to}(${r.installed})。新打开的 work-rhythm 命令才是新版。`);
|
|
63
|
+
else if (!r.installed) say(`全局没有用 npm 装过 ${NAME}:包没动,随包带来的文件按现在运行的这份(${r.from || '认不出版本'})同步。`);
|
|
64
|
+
else if (r.linked && hasNew) say(`${NAME} 没升级(${r.from}):全局的是软链。随包带来的文件按它指向的那份同步。`);
|
|
65
|
+
else say(`${NAME} 已是最新(${r.from})。`);
|
|
66
|
+
const list = (changed) => changed.forEach((c) => say(` ${ACTION_CN[c.action]} ${c.rel}`));
|
|
67
|
+
// 2 skill
|
|
68
|
+
if (!r.skills.length) say(`skill:${SKILL_DIRS[0]} 等用户级目录里没有 work-rhythm,没动。装它是软链,跟着包走:ln -sfn "$(npm root -g)/${NAME}/.agents/skills/work-rhythm" ~/${SKILL_DIRS[0]}/work-rhythm`);
|
|
69
|
+
for (const s of r.skills) {
|
|
70
|
+
if (s.kind === 'link') say(`skill ${s.where}:软链,指向 ${s.target},跟着包走,不用动。`);
|
|
71
|
+
else if (s.kind === 'broken') say(`skill ${s.where}:软链坏了(指向的目标不在了),没动。重新链一次:ln -sfn "$(npm root -g)/${NAME}/.agents/skills/work-rhythm" ~/${s.where}`);
|
|
72
|
+
else {
|
|
73
|
+
say(`skill ${s.where}:拷贝的一份,${s.changed.length ? (dryRun ? '会改成新版:' : '已换成新版:') : '和包里的一样。'}`);
|
|
74
|
+
list(s.changed);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// 3 工作目录
|
|
78
|
+
if (!r.workdir) say('工作目录:没有指定(站在工作目录里跑,或者 work-rhythm update --workdir <目录>),里面的文件没动。');
|
|
79
|
+
else {
|
|
80
|
+
const w = r.workdir;
|
|
81
|
+
say(`工作目录 ${workdir}:${w.changed.length ? (dryRun ? '随包带来的文件会改成新版:' : '随包带来的文件已同步:') : '随包带来的文件都和包里的一样。'}`);
|
|
82
|
+
list(w.changed);
|
|
83
|
+
for (const rel of w.newTemplates) say(` 新版本多了一个模板 ${rel}:没有替你放进去(工作目录独有的文件是引导时填出来的);要看它长什么样,work-rhythm init 建个新目录`);
|
|
84
|
+
if (w.profileMissing.length) say(` 00-config/profile.yaml 缺了新版的字段:${w.profileMissing.join('、')}(对照 00-config/profile.example.yaml 补上;work-rhythm check 也会报)`);
|
|
85
|
+
}
|
|
86
|
+
if (r.backupDir) say(`改过的文件备份在 ${r.backupDir}(要找回你的改动就去那儿看)。`);
|
|
87
|
+
if (dryRun) say('(试跑:包没升级,文件没改)');
|
|
88
|
+
else if (workdir && createRhythm({ root: workdir, env: settings(workdir, env), packageRoot }).serviceAlive()) say('本地服务在跑:任务指令和路由提示词的新版要重启才全部生效——work-rhythm rhythm restart。');
|
|
89
|
+
// 软链、全局没装:包没升成,按「没配置好」报
|
|
90
|
+
return r.problemCode ? EXIT.NOT_CONFIGURED : EXIT.OK;
|
|
91
|
+
},
|
|
92
|
+
};
|