work-rhythm 0.1.8 → 0.2.11
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 +12 -1
- package/.agents/notes/decisions/2026-12-01-agent-runs-the-login-for-the-user.md +30 -0
- package/.agents/notes/decisions/2026-12-01-interjections-batch-into-one-answer-and-interrupt-reruns.md +33 -0
- package/.agents/notes/decisions/2026-12-01-long-runs-are-bounded-by-silence-not-wall-clock.md +35 -0
- package/.agents/notes/decisions/2026-12-01-question-cards-via-cli-tool-on-todays-page-answers-return-to-router.md +40 -0
- package/.agents/notes/decisions/2026-12-01-router-and-worker-pass-content-in-handoff-docs.md +42 -0
- package/.agents/notes/decisions/2026-12-01-router-runs-on-a-flash-model-with-low-effort.md +33 -0
- package/.agents/notes/decisions/2026-12-01-sync-feeds-refine-then-events-to-the-router.md +38 -0
- package/.agents/notes/pitfalls/2026-12-01-replace-string-dollar-quote-expands.md +16 -0
- package/.agents/notes/pitfalls/2026-12-02-rhythm-start-in-the-foreground-displaces-the-launchd-service.md +27 -0
- package/.agents/skills/work-rhythm/SKILL.md +20 -12
- package/README.md +32 -4
- package/collectors/local.env.example +10 -1
- package/docs/agents.md +53 -13
- package/docs/channels.md +9 -6
- package/docs/router-worker.md +263 -0
- package/docs/scheduled-tasks.md +5 -5
- package/docs/sources.md +20 -0
- package/package.json +1 -1
- package/scripts/cli.js +5 -3
- package/scripts/cmd/agent.js +188 -49
- package/scripts/cmd/ask.js +104 -0
- package/scripts/cmd/check.js +4 -0
- package/scripts/cmd/listen.js +18 -4
- package/scripts/cmd/rhythm.js +6 -2
- package/scripts/cmd/sync.js +11 -3
- package/scripts/cmd/trigger.js +143 -0
- package/scripts/lib/agent.js +482 -30
- package/scripts/lib/asks.js +145 -0
- package/scripts/lib/bot.js +140 -35
- package/scripts/lib/engine.js +707 -0
- package/scripts/lib/handoff.js +167 -0
- package/scripts/lib/markdown.js +355 -36
- package/scripts/lib/rhythm.js +576 -38
- package/scripts/lib/router.js +208 -0
- package/scripts/lib/run.js +43 -0
- package/scripts/lib/view.js +736 -0
- package/scripts/lib/worker.js +98 -0
- package/scripts/test/agent.test.js +126 -9
- package/scripts/test/check.test.js +7 -2
- package/scripts/test/harness.js +15 -1
- package/scripts/test/listen.test.js +2 -2
- package/scripts/test/rhythm.test.js +109 -6
- package/scripts/test/router-helper.js +110 -0
- package/scripts/test/router.test.js +799 -0
- package/scripts/test/stubs.js +113 -12
- package/scripts/test/timeout.test.js +99 -0
- package/tasks/daily-plan.md +1 -2
- package/templates/00-config/profile.example.yaml +9 -0
- package/templates/AGENTS.md +3 -1
- package/templates/README.md +4 -1
package/scripts/cmd/agent.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// work-rhythm agent model <模型id> | agent model --clear 只换模型
|
|
7
7
|
// work-rhythm agent effort <强度> | agent effort --clear 只换思考强度
|
|
8
8
|
// work-rhythm agent test ["一句话"] 让绑定的 agent 答一句(自报模型),看模型和凭据通不通
|
|
9
|
+
// work-rhythm agent login [名字] 替用户登录:起那个 agent 的登录、把链接给用户点、等完成、验一句
|
|
9
10
|
// work-rhythm agent doctor 绑定的 agent、模型、强度有没有问题
|
|
10
11
|
// work-rhythm agent --json 打成 JSON,给 agent 读
|
|
11
12
|
// 预置:zcode、dsh、qoder、claude;其余值当成一条自己的命令。
|
|
@@ -14,37 +15,82 @@
|
|
|
14
15
|
'use strict';
|
|
15
16
|
const fs = require('node:fs');
|
|
16
17
|
const path = require('node:path');
|
|
18
|
+
const { spawn } = require('node:child_process');
|
|
17
19
|
const { EXIT, Fail, UsageError } = require('../lib/run');
|
|
18
|
-
const { settings } = require('../lib/config');
|
|
20
|
+
const { settings, loadProfile } = require('../lib/config');
|
|
19
21
|
const { createBot } = require('../lib/bot');
|
|
20
22
|
const read = (file) => { try { return fs.readFileSync(file, 'utf8'); } catch { return ''; } };
|
|
21
|
-
const
|
|
23
|
+
const tail = (text, max = 200) => { const s = String(text || '').trim(); return s.length > max ? s.slice(-max) : s; };
|
|
24
|
+
const { PRESETS, PRESET_NAMES, MODEL_SUPPORT, EFFORTS, LOGINS, ROUTER_EFFORT, modelTier, routerProblems, fastModels, fastModelsByAgent, invokingAgent, invokingSession, installedAgents, ideOnly, roles, bindAgent, createAgent, listModels, listSessions } = require('../lib/agent');
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
// 路由的模型和强度怎么说:模型带不带 flash、强度固定 low
|
|
27
|
+
function describeRouter(kind, model) {
|
|
28
|
+
const tier = modelTier(model);
|
|
29
|
+
const what = !model ? '模型没指定' : !tier ? `模型 ${model}(不是 flash 这类快模型)` : `模型 ${model}${tier === 'flash' ? '' : '(快)'}`;
|
|
30
|
+
return `${what},思考强度 ${ROUTER_EFFORT}(路由固定)`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 路由能用的快模型:不给名字就把本机每个装了的预置都列出来(引导时拿这张表让用户选)
|
|
34
|
+
function showFastModels(given, env, json, stdout) {
|
|
35
|
+
const list = fastModelsByAgent(env).filter((a) => !given || a.name === given);
|
|
36
|
+
if (!list.length) throw new Fail(EXIT.NOT_CONFIGURED, `没有 ${given} 这个预置`);
|
|
37
|
+
if (json) {
|
|
38
|
+
stdout.write(`${JSON.stringify({ routerEffort: ROUTER_EFFORT, agents: list.map((a) => ({ name: a.name, label: a.label, found: a.found, install: a.found ? undefined : a.install, models: a.models.map((m) => ({ id: m.id, full: m.full, tier: m.tier })), modelSupported: MODEL_SUPPORT[a.name].model, problem: a.problem })) }, null, 1)}\n`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
stdout.write(`路由只能用 flash 这类快模型,思考强度固定 ${ROUTER_EFFORT}(docs/agents.md 的「两个角色」)。\n`);
|
|
42
|
+
for (const a of list) {
|
|
43
|
+
if (!a.found) stdout.write(` ${a.name.padEnd(7)}没装:${a.install}\n`);
|
|
44
|
+
else if (!MODEL_SUPPORT[a.name].model) stdout.write(` ${a.name.padEnd(7)}配不了模型,保证不了用的是快模型:当不了路由\n`);
|
|
45
|
+
else if (a.problem) stdout.write(` ${a.name.padEnd(7)}列不出模型清单:${a.problem}\n`);
|
|
46
|
+
else if (!a.models.length) stdout.write(` ${a.name.padEnd(7)}没有快模型(清单里共 ${fastModels(a.name, env).total} 个):当不了路由\n`);
|
|
47
|
+
else stdout.write(` ${a.name.padEnd(7)}${a.models.map((m) => `${m.full}${m.tier === 'flash' ? '' : '(快)'}`).join('、')}\n`);
|
|
48
|
+
}
|
|
49
|
+
const usable = list.filter((a) => a.found && a.models.length);
|
|
50
|
+
if (!usable.length && list.some((a) => a.found && !a.models.length && MODEL_SUPPORT[a.name].model && !a.problem)) stdout.write('(装了的里面没有拿得出快模型的)\n');
|
|
51
|
+
stdout.write(usable.length ? `绑:${usable.map((a) => `work-rhythm agent bind router ${a.name} --model ${a.models[0].full}`).join(';')}\n` : '本机没有一个预置拿得出快模型:路由现在配不了。\n');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 一个角色现在用的是哪套键,一句话
|
|
55
|
+
const keysOf = (role) => (role === 'router' ? 'YZJ_ROUTER_AGENT / _MODEL / _EFFORT / _SESSION' : role === 'worker' ? 'YZJ_WORKER_AGENT / _MODEL / _EFFORT' : 'YZJ_BOT_AGENT / _MODEL / _EFFORT / _SESSION');
|
|
56
|
+
|
|
57
|
+
const USAGE = `work-rhythm agent [子命令] —— 路由、执行者、值守用哪个 agent、哪个模型、思考强度多少:检测本机的、绑定、试一句
|
|
24
58
|
|
|
25
59
|
用法: work-rhythm agent [子命令]
|
|
26
|
-
看本机装了哪些、现在是不是有 agent 正在调这个 skill
|
|
27
|
-
models [名字] 这个 agent 能用哪些模型(不给名字就是绑定的那个);dsh 读它的配置,qoder 问命令行,claude 给常见的别名
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[--
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
60
|
+
看本机装了哪些、现在是不是有 agent 正在调这个 skill、两个角色(路由、执行者)各用的是哪个、模型和强度是多少(--json 打成 JSON)
|
|
61
|
+
models [名字] 这个 agent 能用哪些模型(不给名字就是绑定的那个);dsh 读它的配置,qoder 问命令行,kimi 列它的 provider,claude 给常见的别名
|
|
62
|
+
models router [名字] 路由能用的快模型(flash 这类):不给名字就把本机每个装了的预置都列出来,引导时拿这张表让用户选路由用哪个
|
|
63
|
+
bind [router|worker] [名字|命令]
|
|
64
|
+
不带角色:两个角色共用,写进 collectors/local.env 的 YZJ_BOT_AGENT;不给名字就用正在调的这个,没有就装了的第一个
|
|
65
|
+
[--model <模型>] 一起写模型:dsh 写「provider/模型id」或模型id;qoder、claude、kimi 写它们认的模型名。不写不动原来的;
|
|
66
|
+
绑路由时不写就自动挑一个 flash 模型,写了别的会被拒——路由只许用快模型
|
|
67
|
+
[--effort <强度>] 一起写思考强度:none / low / medium / high / max。不写不动原来的;路由固定 low,写别的会被拒
|
|
68
|
+
[--session <id>] 一起绑会话(只有路由用得上):机器人在 IM 里说的话从这个会话接着走(上下文连着)。不写:绑的正好是正在调
|
|
69
|
+
这个 skill 的 agent 时,自动绑它当前这个会话;--no-session 不绑,路由用自己的专属会话
|
|
70
|
+
带 router 只写 YZJ_ROUTER_*,带 worker 只写 YZJ_WORKER_*:两个角色各选各的 agent、模型、强度,没单独配的落到 YZJ_BOT_*
|
|
71
|
+
session [id|--clear] 看 / 换 / 清掉路由的会话(YZJ_ROUTER_SESSION,没写时是 YZJ_BOT_SESSION)
|
|
72
|
+
sessions 这个工作区里路由用的那个 agent 的会话,新的在前(dsh、kimi 列得出)
|
|
35
73
|
model <模型id> 只换模型;model --clear 清掉,用 agent 自己的默认
|
|
36
74
|
effort <强度> 只换思考强度(none / low / medium / high / max);effort --clear 清掉
|
|
37
|
-
test ["一句话"] 让绑定的 agent
|
|
38
|
-
|
|
75
|
+
test ["一句话"] 让绑定的 agent 答一句(默认请它自报模型),只读;test router / test worker 试那一个角色
|
|
76
|
+
login [名字] [--timeout 秒]
|
|
77
|
+
替用户登录:起那个 agent 的登录(它会打出一个链接),把链接给用户在浏览器里点一下确认,等它完成,
|
|
78
|
+
再验一句。凭据由那个 agent 自己存,不经过对话。已经登录的什么都不做;不给名字就是绑定的那个
|
|
79
|
+
doctor 绑定的 agent、模型、强度有没有问题;不算问题的注意另起一行(比如路由用了无界面没有只读档的 kimi)
|
|
39
80
|
预置:${PRESET_NAMES.join('、')}。模型和强度只有 ${PRESET_NAMES.filter((n) => MODEL_SUPPORT[n].model).join('、')} 支持(zcode 的命令行没有这两个参数,用它自己的默认);
|
|
40
81
|
其余值当成一条自己的命令(消息作为最后一个参数,回复打到标准输出)。
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
82
|
+
退出码: 0;1 doctor 查出问题;2 用法不对;3 没绑或绑不上(本机找不到那个 agent、模型不在它的清单里、它不支持这个设置);5 test 没答上来,或 login 等了 timeout 秒没在浏览器里确认。
|
|
83
|
+
两个角色、路由和执行者怎么配合见 docs/router-worker.md,各家怎么被调用、权限模式见 docs/agents.md。`;
|
|
84
|
+
|
|
85
|
+
const ROLES = ['router', 'worker'];
|
|
86
|
+
const ROLE_NAME = { router: '路由', worker: '执行者' };
|
|
44
87
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
88
|
+
// 现在绑的是什么:role 为空是两个角色共用那套(YZJ_BOT_*),router / worker 是各自的(没单独配的落回共用的)
|
|
89
|
+
function binding(root, env, role = '') {
|
|
90
|
+
const r = roles(settings(root, env));
|
|
91
|
+
if (role === 'router') return { agent: r.router.agent, model: r.router.model, effort: r.router.effort, session: r.router.session };
|
|
92
|
+
if (role === 'worker') return { agent: r.worker.agent, model: r.worker.model, effort: r.worker.effort, session: '' };
|
|
93
|
+
return { agent: r.bot.agent, model: r.bot.model, effort: r.bot.effort, session: r.bot.session };
|
|
48
94
|
}
|
|
49
95
|
|
|
50
96
|
// 绑会话的一句话说明
|
|
@@ -63,6 +109,12 @@ function suggest(list) {
|
|
|
63
109
|
return first ? first.name : '';
|
|
64
110
|
}
|
|
65
111
|
|
|
112
|
+
// 绑路由时建议绑哪个:装了的里面第一个拿得出快模型的;都没有就空
|
|
113
|
+
function suggestRouter(env) {
|
|
114
|
+
const a = fastModelsByAgent(env).find((x) => x.found && x.models.length);
|
|
115
|
+
return a ? a.name : '';
|
|
116
|
+
}
|
|
117
|
+
|
|
66
118
|
// 模型和强度对这个 agent 意味着什么,一句话
|
|
67
119
|
function describeModel(kind, model, effort) {
|
|
68
120
|
if (kind === 'custom') return model || effort ? '自定义命令:模型和强度写在你的命令里,这里不传' : '';
|
|
@@ -120,9 +172,15 @@ module.exports = {
|
|
|
120
172
|
const list = installedAgents(env);
|
|
121
173
|
const json = args.includes('--json');
|
|
122
174
|
const rest = args.filter((a) => a !== '--json');
|
|
123
|
-
const [
|
|
124
|
-
|
|
175
|
+
const [verbGiven, ...paramsGiven] = rest;
|
|
176
|
+
// 子命令后面先写角色(router / worker)就是只管那一个角色
|
|
177
|
+
let role = '';
|
|
178
|
+
const params = [...paramsGiven];
|
|
179
|
+
if (['bind', 'test', 'model', 'effort', 'session', 'sessions', 'doctor', 'models'].includes(verbGiven) && ROLES.includes(params[0])) role = params.shift();
|
|
180
|
+
const verb = verbGiven;
|
|
181
|
+
const bound = binding(root, env, role);
|
|
125
182
|
const boundKind = kindOf(bound.agent);
|
|
183
|
+
const who = role ? ROLE_NAME[role] : '';
|
|
126
184
|
|
|
127
185
|
switch (verb) {
|
|
128
186
|
case undefined: {
|
|
@@ -130,6 +188,7 @@ module.exports = {
|
|
|
130
188
|
const invoking = invokingAgent(env);
|
|
131
189
|
const pick = suggest(list);
|
|
132
190
|
const support = boundKind && boundKind !== 'custom' ? MODEL_SUPPORT[boundKind] : null;
|
|
191
|
+
const r = roles(settings(root, env));
|
|
133
192
|
if (json) {
|
|
134
193
|
stdout.write(`${JSON.stringify({
|
|
135
194
|
invoking,
|
|
@@ -142,7 +201,10 @@ module.exports = {
|
|
|
142
201
|
modelSupported: support ? support.model : null,
|
|
143
202
|
effortSupported: support ? support.effort : null,
|
|
144
203
|
suggest: pick,
|
|
145
|
-
|
|
204
|
+
roles: { router: { ...r.router }, worker: { ...r.worker } },
|
|
205
|
+
// 路由的硬规矩:模型必须是 flash 这类快模型(按名字认),思考强度固定 low;各家的快模型用 agent models router 列
|
|
206
|
+
router: { effort: ROUTER_EFFORT, fastModelOnly: true },
|
|
207
|
+
agents: list.map((a) => ({ name: a.name, label: a.label, found: a.found, command: a.command, install: a.found ? undefined : a.install, invoking: a.invoking, modelSupported: MODEL_SUPPORT[a.name].model, effortSupported: MODEL_SUPPORT[a.name].effort, readOnly: PRESETS[a.name].readOnly !== false })),
|
|
146
208
|
ideOnly: ideOnly(env),
|
|
147
209
|
}, null, 1)}\n`);
|
|
148
210
|
return EXIT.OK;
|
|
@@ -150,10 +212,11 @@ module.exports = {
|
|
|
150
212
|
stdout.write('本机的 agent:\n');
|
|
151
213
|
for (const a of list) {
|
|
152
214
|
const how = a.found ? a.command : `没装:${a.problem}`;
|
|
153
|
-
|
|
215
|
+
const readOnly = PRESETS[a.name].readOnly !== false;
|
|
216
|
+
stdout.write(` ${a.name.padEnd(7)}${a.found ? '装了' : '没装'} ${a.label}${a.invoking ? ' ← 现在是它在调这个 skill' : ''}\n ${how}\n${a.found ? '' : ` 怎么装:${a.install}\n`} 模型和思考强度:${MODEL_SUPPORT[a.name].model ? `能配,work-rhythm agent models ${a.name} 看能用哪些` : '不能配,用它自己的默认'};无界面${readOnly ? '能只读' : '没有只读档(plan 也拦不住它改文件)'}\n`);
|
|
154
217
|
}
|
|
155
218
|
const ides = ideOnly(env);
|
|
156
|
-
for (const name of ides) stdout.write(`提醒:本机装着 ${name === 'qoder' ? 'Qoder 的 IDE' : name},但没装它的命令行——用户平时用它的话,带他装上(见上面的「怎么装」),别漏了这一项。\n`);
|
|
219
|
+
for (const name of ides) stdout.write(`提醒:本机装着 ${name === 'qoder' ? 'Qoder 的 IDE' : name === 'kimi' ? 'Kimi Code 的桌面版' : name},但没装它的命令行——用户平时用它的话,带他装上(见上面的「怎么装」),别漏了这一项。\n`);
|
|
157
220
|
stdout.write(`正在调这个 skill 的:${invoking || '认不出来(不是从 agent 的工具里跑的,或者它不留标记)'}\n`);
|
|
158
221
|
stdout.write(`现在绑定的:${bound.agent || '没绑'}${boundKind === 'custom' ? '(一条自定义命令)' : ''}\n`);
|
|
159
222
|
if (bound.agent) {
|
|
@@ -163,10 +226,32 @@ module.exports = {
|
|
|
163
226
|
if (sessionLine) stdout.write(` ${sessionLine}\n`);
|
|
164
227
|
}
|
|
165
228
|
if (!bound.agent) stdout.write(`没绑 agent 就没有定时任务,也不支持机器人响应。${pick ? `建议:work-rhythm agent bind ${pick}` : '本机一个预置的 agent 都没装,先装一个(docs/agents.md)'}\n`);
|
|
229
|
+
// 两个角色各用哪个
|
|
230
|
+
for (const name of ROLES) {
|
|
231
|
+
const b = binding(root, env, name);
|
|
232
|
+
const k = kindOf(b.agent);
|
|
233
|
+
stdout.write(`${ROLE_NAME[name]}:${b.agent || '没绑'}`);
|
|
234
|
+
if (b.agent) {
|
|
235
|
+
stdout.write(`${k === 'custom' ? '(一条自定义命令)' : ''},${name === 'router' ? describeRouter(k, b.model) : describeModel(k, b.model, b.effort)}${name === 'router' ? `;${describeSession(b.session, k) || '会话:自定义命令自己管'}` : ';每次都是新会话'}`);
|
|
236
|
+
// 路由的硬规矩有没守住(模型不是快模型、配置里写了别的强度)
|
|
237
|
+
// 路由的规矩只在路由真会用到时才查:路由开着,或者路由单独绑了
|
|
238
|
+
const routerWanted = name === 'router' && (((loadProfile(root).rhythm || {}).router === true) || String(settings(root, env).YZJ_ROUTER_AGENT || '').trim());
|
|
239
|
+
for (const p of routerWanted ? routerProblems({ agent: b.agent, model: b.model, effort: b.effort, env: settings(root, env) }) : []) stdout.write(`\n 问题:${p}`);
|
|
240
|
+
// 「没有只读档」只对路由有意义:执行者本来就要写
|
|
241
|
+
const notes = createAgent({ root, agent: b.agent, mode: name === 'router' ? 'plan' : 'edit', env: settings(root, env), model: b.model, effort: b.effort }).notes();
|
|
242
|
+
for (const n of notes) stdout.write(`\n 注意:${n}`);
|
|
243
|
+
}
|
|
244
|
+
stdout.write('\n');
|
|
245
|
+
}
|
|
166
246
|
return EXIT.OK;
|
|
167
247
|
}
|
|
168
248
|
case 'models': {
|
|
169
249
|
if (params.length > 1) throw new UsageError(USAGE);
|
|
250
|
+
// 只看路由能用的快模型;不给名字就把本机每个装了的预置都列出来
|
|
251
|
+
if (role === 'router') {
|
|
252
|
+
showFastModels(params[0], env, json, stdout);
|
|
253
|
+
return EXIT.OK;
|
|
254
|
+
}
|
|
170
255
|
const kind = params[0] || boundKind;
|
|
171
256
|
if (!kind) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent models <名字>,或先 work-rhythm agent bind');
|
|
172
257
|
if (kind === 'custom') throw new Fail(EXIT.NOT_CONFIGURED, '自定义命令的模型写在你自己的命令里,这里列不出来');
|
|
@@ -176,48 +261,51 @@ module.exports = {
|
|
|
176
261
|
}
|
|
177
262
|
case 'bind': {
|
|
178
263
|
const { name: given, opts } = parseBind(params);
|
|
179
|
-
const name = given || suggest(list);
|
|
180
|
-
if (!name) throw new Fail(EXIT.NOT_CONFIGURED, '本机没找到能用的 agent,也没指定要绑的命令:装一个预置的(docs/agents.md),或者 work-rhythm agent bind "<一条命令>"');
|
|
181
|
-
// 会话:没指定时,绑的正好是正在调这个 skill 的 agent 就把它当前这个会话绑上(它给工具留了会话 id
|
|
264
|
+
const name = given || (role === 'router' ? suggestRouter(env) : suggest(list));
|
|
265
|
+
if (!name) throw new Fail(EXIT.NOT_CONFIGURED, role === 'router' ? '本机没有一个预置拿得出 flash 这类快模型,路由配不了:work-rhythm agent models router 看每个 agent 的情况;装一个有的(docs/agents.md)' : '本机没找到能用的 agent,也没指定要绑的命令:装一个预置的(docs/agents.md),或者 work-rhythm agent bind "<一条命令>"');
|
|
266
|
+
// 会话:没指定时,绑的正好是正在调这个 skill 的 agent 就把它当前这个会话绑上(它给工具留了会话 id);执行者不绑会话;
|
|
182
267
|
// 换了别的 agent 就把原来绑的清掉——一个 agent 的会话 id 别的 agent 接不上
|
|
183
268
|
const bindingKind = kindOf(name);
|
|
184
269
|
if (opts.session === undefined) {
|
|
185
|
-
opts.session =
|
|
270
|
+
opts.session = role === 'worker' || bindingKind !== invokingAgent(env) ? '' : invokingSession(bindingKind, env);
|
|
186
271
|
}
|
|
187
|
-
const r = bindAgent(root, env, name, { model: opts.model, effort: opts.effort, session: opts.session });
|
|
188
|
-
if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `绑不了 ${name}:${r.problems.join(';')}`);
|
|
272
|
+
const r = bindAgent(root, env, name, { model: opts.model, effort: opts.effort, session: opts.session, role, pickModel: role === 'router' });
|
|
273
|
+
if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `绑不了 ${name}${role === 'router' ? ' 当路由' : ''}:${r.problems.join(';')}`);
|
|
189
274
|
createBot({ root, env: settings(root, env) }).forgetBoundLost(); // 换了会话,之前「接不上」的记录不算了
|
|
190
275
|
const kind = kindOf(name);
|
|
191
276
|
const support = kind !== 'custom' ? MODEL_SUPPORT[kind] : null;
|
|
192
|
-
const after = binding(root, env);
|
|
193
|
-
|
|
194
|
-
stdout.write(
|
|
195
|
-
|
|
277
|
+
const after = binding(root, env, role);
|
|
278
|
+
const notes = role === 'worker' ? [] : createAgent({ root, agent: name, mode: 'plan', env: settings(root, env), model: after.model, effort: after.effort }).notes();
|
|
279
|
+
stdout.write(`已绑定 ${name}${kind === 'custom' ? '(一条自定义命令)' : `(${PRESETS[kind].label})`}${who ? `,${who}用` : ',两个角色共用'},写进了 ${path.relative(root, r.file)} 的 ${r.keys[0]}。\n`);
|
|
280
|
+
stdout.write(` ${role === 'router' ? `${describeRouter(kind, after.model)}${r.picked ? '(刚自动挑的)' : ''}` : describeModel(kind, after.model, after.effort)}\n`);
|
|
281
|
+
if (role !== 'worker' && kind !== 'custom') stdout.write(` ${describeSession(after.session, kind)}${opts.session ? '(刚绑上)' : ''}\n`);
|
|
282
|
+
for (const n of notes) stdout.write(` 注意:${n}\n`);
|
|
196
283
|
if (support && !after.model && !after.effort) {
|
|
197
|
-
stdout.write(` 模型和思考强度还没配:work-rhythm agent models ${name} 看能用哪些,work-rhythm agent model <模型> / agent effort <强度> 配上;不配就用它自己的默认。\n`);
|
|
284
|
+
stdout.write(` 模型和思考强度还没配:work-rhythm agent models ${name} 看能用哪些,work-rhythm agent model ${role ? `${role} ` : ''}<模型> / agent effort ${role ? `${role} ` : ''}<强度> 配上;不配就用它自己的默认。\n`);
|
|
198
285
|
}
|
|
199
286
|
stdout.write('下一步:work-rhythm agent test 让它答一句(会自报模型);定时任务用 work-rhythm rhythm doctor 查配置,机器人值守用 work-rhythm listen doctor。\n');
|
|
200
287
|
return EXIT.OK;
|
|
201
288
|
}
|
|
202
289
|
case 'sessions': {
|
|
203
290
|
if (params.length) throw new UsageError(USAGE);
|
|
204
|
-
if (!bound.agent) throw new Fail(EXIT.NOT_CONFIGURED, '
|
|
291
|
+
if (!bound.agent) throw new Fail(EXIT.NOT_CONFIGURED, `还没绑 ${who ? `${who}用的 ` : ''}agent:work-rhythm agent bind ${role ? `${role} ` : ''}<名字>`);
|
|
205
292
|
const r = listSessions(boundKind, env, root);
|
|
206
293
|
if (r.problem) throw new Fail(EXIT.NOT_CONFIGURED, r.problem);
|
|
207
294
|
if (!r.sessions.length) {
|
|
208
|
-
stdout.write(`${boundKind} 在这个工作区里还没有会话${boundKind === 'dsh' ? '' : '(这个 agent 的会话存储没查到公开的布局,列不出来)'}。\n`);
|
|
295
|
+
stdout.write(`${boundKind} 在这个工作区里还没有会话${boundKind === 'dsh' || boundKind === 'kimi' ? '' : '(这个 agent 的会话存储没查到公开的布局,列不出来)'}。\n`);
|
|
209
296
|
return EXIT.OK;
|
|
210
297
|
}
|
|
211
298
|
stdout.write(`${boundKind} 在这个工作区的会话,新的在前:\n`);
|
|
212
299
|
for (const s of r.sessions) {
|
|
213
300
|
const when = new Date(s.mtime).toLocaleString('zh-CN', { hour12: false });
|
|
214
301
|
const marks = [s.id === bound.session ? '绑着的' : '', s.id === read(`${root}/01-inbox/_bot/session-id`).trim() ? '值守自己的' : ''].filter(Boolean);
|
|
215
|
-
stdout.write(` ${s.id} ${when}${marks.length ? ` ${marks.join(' · ')}` : ''}\n`);
|
|
302
|
+
stdout.write(` ${s.id} ${when}${s.title ? ` ${s.title.slice(0, 40)}` : ''}${marks.length ? ` ${marks.join(' · ')}` : ''}\n`);
|
|
216
303
|
}
|
|
217
|
-
stdout.write('绑哪个:work-rhythm agent session <id
|
|
304
|
+
stdout.write('绑哪个:work-rhythm agent session <id>;路由就从那个会话接着走。\n');
|
|
218
305
|
return EXIT.OK;
|
|
219
306
|
}
|
|
220
307
|
case 'session': {
|
|
308
|
+
if (role === 'worker') throw new UsageError('执行者每次都是新会话,不绑会话');
|
|
221
309
|
if (!bound.agent) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent bind <名字>');
|
|
222
310
|
if (boundKind === 'custom') throw new Fail(EXIT.NOT_CONFIGURED, '自定义命令的会话由你的命令自己管,这里不绑');
|
|
223
311
|
let session;
|
|
@@ -229,10 +317,10 @@ module.exports = {
|
|
|
229
317
|
stdout.write(`${describeSession(bound.session, boundKind)}。当前这个会话(如果是从 ${boundKind} 里跑的):${invokingSession(boundKind, env) || '认不出来'}\n`);
|
|
230
318
|
return EXIT.OK;
|
|
231
319
|
}
|
|
232
|
-
const r = bindAgent(root, env, bound.agent, { session });
|
|
320
|
+
const r = bindAgent(root, env, bound.agent, { session, role });
|
|
233
321
|
if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `写不了:${r.problems.join(';')}`);
|
|
234
322
|
createBot({ root, env: settings(root, env) }).forgetBoundLost();
|
|
235
|
-
stdout.write(session ? `会话已绑为 ${session},写进了 ${path.relative(root, r.file)}
|
|
323
|
+
stdout.write(session ? `会话已绑为 ${session},写进了 ${path.relative(root, r.file)}。路由下一句从这个会话接着走。\n` : `会话已清掉,路由用自己的专属会话。\n`);
|
|
236
324
|
return EXIT.OK;
|
|
237
325
|
}
|
|
238
326
|
case 'model':
|
|
@@ -243,17 +331,18 @@ module.exports = {
|
|
|
243
331
|
else if (params.length === 1 && !params[0].startsWith('--')) value = params[0];
|
|
244
332
|
else throw new UsageError(USAGE);
|
|
245
333
|
if (!isModel && value && !EFFORTS.includes(value)) throw new UsageError(`思考强度写的是「${value}」,只能是 ${EFFORTS.join(' / ')}`);
|
|
334
|
+
if (!isModel && role === 'router' && value && value !== ROUTER_EFFORT) throw new UsageError(`路由的思考强度固定 ${ROUTER_EFFORT}:它只做判断,快就够了。要改执行者的强度:work-rhythm agent effort worker <强度>`);
|
|
246
335
|
if (!bound.agent) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent bind <名字>');
|
|
247
336
|
const support = boundKind !== 'custom' ? MODEL_SUPPORT[boundKind] : null;
|
|
248
337
|
const what = isModel ? '模型' : '思考强度';
|
|
249
338
|
if (value && support && !support[isModel ? 'model' : 'effort']) {
|
|
250
339
|
throw new Fail(EXIT.NOT_CONFIGURED, `${boundKind} 不支持指定${what}(${boundKind === 'zcode' ? 'ZCode 的命令行没有这个参数' : '见 docs/agents.md'}):换一个支持的 agent,或者不配、用它自己的默认`);
|
|
251
340
|
}
|
|
252
|
-
const r = bindAgent(root, env, bound.agent, isModel ? { model: value } : { effort: value });
|
|
253
|
-
if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `写不了:${r.problems.join(';')}`);
|
|
254
|
-
const after = binding(root, env);
|
|
255
|
-
stdout.write(value ? `${what}已设为 ${value},写进了 ${path.relative(root, r.file)}。\n` : `${what}
|
|
256
|
-
stdout.write(` ${describeModel(boundKind, after.model, after.effort)}\n下一步:work-rhythm agent test 让它答一句,看自报的模型对不对。\n`);
|
|
341
|
+
const r = bindAgent(root, env, bound.agent, isModel ? { model: value, role } : { effort: value, role });
|
|
342
|
+
if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, role === 'router' ? r.problems.join(';') : `写不了:${r.problems.join(';')}`);
|
|
343
|
+
const after = binding(root, env, role);
|
|
344
|
+
stdout.write(value ? `${what}已设为 ${value},写进了 ${path.relative(root, r.file)}${who ? `(${who})` : ''}。\n` : `${what}已清掉${role === 'router' ? ',路由必须指定一个快模型:work-rhythm agent bind router <名字> 重绑一次' : `,用 ${boundKind} 自己的默认`}。\n`);
|
|
345
|
+
stdout.write(` ${role === 'router' ? describeRouter(boundKind, after.model) : describeModel(boundKind, after.model, after.effort)}\n下一步:work-rhythm agent test 让它答一句,看自报的模型对不对。\n`);
|
|
257
346
|
return EXIT.OK;
|
|
258
347
|
}
|
|
259
348
|
case 'test': {
|
|
@@ -268,11 +357,61 @@ module.exports = {
|
|
|
268
357
|
stdout.write(`${r.reply.trim()}\n(${bound.agent}${bound.model ? `,配置的模型 ${bound.model}` : ''}${bound.effort ? `,思考强度 ${bound.effort}` : ''};只读模式,用时 ${Math.round((Date.now() - started) / 1000)} 秒)\n`);
|
|
269
358
|
return EXIT.OK;
|
|
270
359
|
}
|
|
360
|
+
case 'login': {
|
|
361
|
+
// 替用户登录:起那个 agent 的登录、把链接给用户点、等完成、验一句(docs/agents.md 的「登录」)
|
|
362
|
+
let timeout = 300;
|
|
363
|
+
const names = [];
|
|
364
|
+
for (let i = 0; i < params.length; i += 1) {
|
|
365
|
+
if (params[i] === '--timeout' && params[i + 1]) {
|
|
366
|
+
timeout = Number(params[++i]);
|
|
367
|
+
if (!Number.isInteger(timeout) || timeout < 1) throw new UsageError('--timeout 要是正整数(秒)');
|
|
368
|
+
} else if (params[i].startsWith('--')) throw new UsageError(USAGE);
|
|
369
|
+
else names.push(params[i]);
|
|
370
|
+
}
|
|
371
|
+
if (names.length > 1) throw new UsageError(USAGE);
|
|
372
|
+
const name = names[0] || bound.agent;
|
|
373
|
+
if (!name) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent login <名字>,或先 work-rhythm agent bind');
|
|
374
|
+
const kind = kindOf(name);
|
|
375
|
+
if (kind === 'custom') throw new Fail(EXIT.NOT_CONFIGURED, '自定义命令的登录写在你自己的命令里,这里管不了');
|
|
376
|
+
const found = PRESETS[kind].find(env);
|
|
377
|
+
if (found.problem) throw new Fail(EXIT.NOT_CONFIGURED, `${found.problem}(怎么装:${PRESETS[kind].install})`);
|
|
378
|
+
const login = LOGINS[kind];
|
|
379
|
+
if (!login.args) {
|
|
380
|
+
stdout.write(`${login.hint}。\n`);
|
|
381
|
+
return EXIT.OK;
|
|
382
|
+
}
|
|
383
|
+
const settingsEnv = settings(root, env);
|
|
384
|
+
const checked = login.check(found, settingsEnv);
|
|
385
|
+
if (login.ok(checked)) {
|
|
386
|
+
stdout.write(`${name} 已经登录了,不用再登。\n`);
|
|
387
|
+
return EXIT.OK;
|
|
388
|
+
}
|
|
389
|
+
stdout.write(`替你起 ${name} 的登录。它打出一个链接,在浏览器里打开、确认一下;我在这儿最多等 ${timeout} 秒。\n`);
|
|
390
|
+
const child = spawn(found.command, login.args, { stdio: 'inherit', env: settingsEnv });
|
|
391
|
+
let timedOut = false;
|
|
392
|
+
const timer = setTimeout(() => {
|
|
393
|
+
timedOut = true;
|
|
394
|
+
child.kill('SIGTERM');
|
|
395
|
+
}, timeout * 1000);
|
|
396
|
+
const code = await new Promise((resolve) => child.on('close', resolve));
|
|
397
|
+
clearTimeout(timer);
|
|
398
|
+
if (timedOut) throw new Fail(EXIT.FAILED, `等了 ${timeout} 秒还没在浏览器里确认:再来一次 work-rhythm agent login ${name},--timeout 可以给长一点`);
|
|
399
|
+
const after = login.check(found, settingsEnv);
|
|
400
|
+
if (!login.ok(after)) throw new Fail(EXIT.FAILED, `登录没成(${name} login 退出码 ${code}):${tail(after.stderr || after.stdout, 200) || '再试一次,浏览器里要点确认'}`);
|
|
401
|
+
// 它现在是哪个角色在用:用它的那个角色试一句
|
|
402
|
+
const using = ROLES.filter((r) => binding(root, env, r).agent === name);
|
|
403
|
+
const next = using.length ? `${using.map((r) => `work-rhythm agent test ${r}`).join('、')} 让它答一句` : `work-rhythm agent bind <router|worker> ${name} 绑上,再 agent test 让它答一句`;
|
|
404
|
+
stdout.write(`${name} 登录成功(验证过 ${kind === 'qoder' ? '--list-models' : 'provider list'})。下一步:${next}。\n`);
|
|
405
|
+
return EXIT.OK;
|
|
406
|
+
}
|
|
271
407
|
case 'doctor': {
|
|
272
408
|
if (params.length) throw new UsageError(USAGE);
|
|
273
|
-
const
|
|
409
|
+
const agent = createAgent({ root, agent: bound.agent, mode: role === 'worker' ? 'edit' : 'plan', env: settings(root, env), model: bound.model, effort: bound.effort });
|
|
410
|
+
const problems = role === 'router' ? [...agent.doctor(), ...routerProblems({ agent: bound.agent, model: bound.model, effort: bound.effort, env: settings(root, env) })] : agent.doctor();
|
|
411
|
+
const notes = agent.notes();
|
|
274
412
|
if (problems.length) stdout.write(`${problems.join('\n')}\n`);
|
|
275
|
-
else stdout.write(`${bound.agent} 没有问题${bound.model || bound.effort ? `(${describeModel(boundKind, bound.model, bound.effort)})` : ''}。\n`);
|
|
413
|
+
else stdout.write(`${bound.agent}${who ? `(${who})` : ''} 没有问题${bound.model || bound.effort ? `(${describeModel(boundKind, bound.model, bound.effort)})` : ''}。\n`);
|
|
414
|
+
for (const n of notes) stdout.write(`注意:${n}\n`);
|
|
276
415
|
return problems.length ? 1 : EXIT.OK;
|
|
277
416
|
}
|
|
278
417
|
default:
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// work-rhythm ask:执行者问我一句话。把问题以 JSON 丢出来,页面上「今日 · 待你定」成一张卡(实时刷新),我在页面上答,
|
|
2
|
+
// 回答变成一条触发回到路由,路由带着原问题派人接着做(docs/router-worker.md 的「问用户:待你定」)。
|
|
3
|
+
// 也给桌面上的 agent 用:同一套。实现(校验、落盘、记 DECISIONS.md)在 lib/asks.js。
|
|
4
|
+
'use strict';
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const { EXIT, Fail, UsageError } = require('../lib/run');
|
|
7
|
+
const { settings } = require('../lib/config');
|
|
8
|
+
const decisions = require('./decisions');
|
|
9
|
+
const asks = require('../lib/asks');
|
|
10
|
+
|
|
11
|
+
const USAGE = `work-rhythm ask —— 问我一句话:问题以 JSON 丢出来,今日页的「待你定」成一张卡(实时刷新),我答了之后回到路由
|
|
12
|
+
|
|
13
|
+
用法: work-rhythm ask - 从标准输入读 JSON
|
|
14
|
+
work-rhythm ask --json '<JSON>' 直接给 JSON
|
|
15
|
+
work-rhythm ask --question "<问题>" --option "<选项>" [--option …] [--suggest <选项>] [--context "<背景>"] [--record "<记到哪>"] [--item "<短事项>"]
|
|
16
|
+
work-rhythm ask list [--json] 全部的卡,没答的在前
|
|
17
|
+
work-rhythm ask show <卡号> 看一张卡
|
|
18
|
+
JSON 的样子(只有 question 必填):
|
|
19
|
+
{"question": "导出边界要不要发上游?",
|
|
20
|
+
"context": "测试说今天下午前给答复,不然要等下周", 给我看的背景,几句
|
|
21
|
+
"options": [{"label": "发上游", "detail": "今天就能发,风险是回滚麻烦"},
|
|
22
|
+
{"label": "周会提", "suggested": true}], 2–4 个;suggested 标建议的那个
|
|
23
|
+
"record": "03-carryover/CARRYOVER.md 的未了结", 我答了之后,总结记到哪
|
|
24
|
+
"item": "导出边界要不要发上游", 记进 DECISIONS.md 的短事项(不超过 30 字,缺省用问题)}
|
|
25
|
+
执行者跑的时候服务给它留了 WRJ_TRIGGER(是哪条触发),不用自己写 from。
|
|
26
|
+
退出码: 0;2 用法不对(JSON 不合法、缺 question、item 太长);3 不在工作目录里;5 DECISIONS.md 没记上。
|
|
27
|
+
我答了之后:回答是一条触发给路由,路由带着原问题派人接着做(续原来那个执行者的会话,或新派一个),把结果记到 record。`;
|
|
28
|
+
|
|
29
|
+
const parseFlags = (args) => {
|
|
30
|
+
const out = { question: '', options: [], suggested: undefined, context: '', record: '', item: '' };
|
|
31
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
32
|
+
const a = args[i];
|
|
33
|
+
const value = () => {
|
|
34
|
+
const v = args[i + 1];
|
|
35
|
+
if (v === undefined || v.startsWith('--')) throw new UsageError(`${a} 后面要跟一个值\n${USAGE}`);
|
|
36
|
+
i += 1;
|
|
37
|
+
return v;
|
|
38
|
+
};
|
|
39
|
+
if (a === '--question') out.question = value();
|
|
40
|
+
else if (a === '--option') out.options.push(value());
|
|
41
|
+
else if (a === '--suggest') out.suggested = value();
|
|
42
|
+
else if (a === '--context') out.context = value();
|
|
43
|
+
else if (a === '--record') out.record = value();
|
|
44
|
+
else if (a === '--item') out.item = value();
|
|
45
|
+
else throw new UsageError(`不认识的选项 ${a}\n${USAGE}`);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
usage: USAGE,
|
|
52
|
+
async run(args, ctx) {
|
|
53
|
+
const { root, stdout, env, packageRoot, stdin } = ctx;
|
|
54
|
+
const settingsEnv = settings(root, env);
|
|
55
|
+
const [verb, ...rest] = args;
|
|
56
|
+
if (verb === 'list') {
|
|
57
|
+
if (rest.some((a) => a !== '--json')) throw new UsageError(USAGE);
|
|
58
|
+
const list = asks.listAsks(root);
|
|
59
|
+
if (rest.includes('--json')) {
|
|
60
|
+
stdout.write(`${JSON.stringify(list, null, 1)}\n`);
|
|
61
|
+
return EXIT.OK;
|
|
62
|
+
}
|
|
63
|
+
stdout.write('id\tat\tstatus\tquestion\toptions\tanswer\tfrom\n');
|
|
64
|
+
for (const a of list) {
|
|
65
|
+
const cells = [a.id, a.at, a.answer ? '已答' : '待答', a.question, asks.optionsText(a.options || []), a.answer ? a.answer.choice : '', a.from && a.from.trigger ? a.from.trigger : ''];
|
|
66
|
+
stdout.write(`${cells.map((c) => String(c).replace(/\t/g, ' ')).join('\t')}\n`);
|
|
67
|
+
}
|
|
68
|
+
return EXIT.OK;
|
|
69
|
+
}
|
|
70
|
+
if (verb === 'show') {
|
|
71
|
+
if (rest.length !== 1) throw new UsageError(USAGE);
|
|
72
|
+
const ask = asks.readAsk(root, rest[0]);
|
|
73
|
+
if (!ask) throw new Fail(EXIT.USAGE, `没有 ${rest[0]} 这张卡`);
|
|
74
|
+
stdout.write(`${JSON.stringify(ask, null, 1)}\n`);
|
|
75
|
+
return EXIT.OK;
|
|
76
|
+
}
|
|
77
|
+
let input;
|
|
78
|
+
if (verb === '-') {
|
|
79
|
+
if (rest.length) throw new UsageError(USAGE);
|
|
80
|
+
input = await new Promise((resolve) => {
|
|
81
|
+
let data = '';
|
|
82
|
+
stdin.on('data', (c) => {
|
|
83
|
+
data += c;
|
|
84
|
+
});
|
|
85
|
+
stdin.on('end', () => resolve(data));
|
|
86
|
+
});
|
|
87
|
+
} else if (verb === '--json') {
|
|
88
|
+
if (rest.length !== 1) throw new UsageError(USAGE);
|
|
89
|
+
input = rest[0];
|
|
90
|
+
} else {
|
|
91
|
+
input = parseFlags(args);
|
|
92
|
+
}
|
|
93
|
+
if (typeof input === 'string') {
|
|
94
|
+
try {
|
|
95
|
+
input = JSON.parse(input);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw new UsageError(`JSON 解析不了:${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const ask = await asks.createAsk(root, input, { env: settingsEnv, packageRoot, decisions });
|
|
101
|
+
stdout.write(`已登记 ${ask.id}:${asks.askSummary(ask)}\n它会出现在今日页的「待你定」里(实时刷新);我答了之后回到路由。\n`);
|
|
102
|
+
return EXIT.OK;
|
|
103
|
+
},
|
|
104
|
+
};
|
package/scripts/cmd/check.js
CHANGED
|
@@ -317,6 +317,10 @@ function genericProblems({ root, say }) {
|
|
|
317
317
|
if (fs.existsSync(path.join(root, rel))) bad.push(`仓库根目录里出现了 ${rel}:这个仓库只放 skill 和 CLI,不是工作目录。工作目录独有的文件在 templates/ 下;试跑请先用 work-rhythm init 建一个临时工作目录`);
|
|
318
318
|
}
|
|
319
319
|
if (fs.existsSync(path.join(root, 'collectors', 'local.env'))) bad.push('仓库里出现了个人配置 collectors/local.env:个人的 profile 和 local.env 只放在自己的工作目录里');
|
|
320
|
+
// 交接文档是工作目录运行时才有的(路由写给执行者的任务书、执行者的回执,里面有用户原话):init 和 pack 会把 .agents/ 整个带走,
|
|
321
|
+
// 仓库里混进一份就等于发给了所有人
|
|
322
|
+
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:那是工作目录里路由和执行者之间的任务书与回执,含用户原话,init 和 pack 会把它带走。删掉,要试跑先用 work-rhythm init 建一个临时工作目录');
|
|
320
324
|
bad.forEach(say);
|
|
321
325
|
return bad.length;
|
|
322
326
|
}
|
package/scripts/cmd/listen.js
CHANGED
|
@@ -20,7 +20,8 @@ const USAGE = `work-rhythm listen <子命令> —— 值守:消息渠道的收
|
|
|
20
20
|
用法: work-rhythm listen <子命令>
|
|
21
21
|
probe [--seconds N] 连上去看握手和收到的每一帧,不调 agent,到时退出(默认 60 秒)。第一次验证用
|
|
22
22
|
run 值守:一直连着,收到消息就处理
|
|
23
|
-
handle "<消息>"
|
|
23
|
+
handle "<消息>" [--push] 不连云之家,走一遍「交给 agent → 打印回复」,调试 agent 配置。路由开着时走全流程
|
|
24
|
+
(路由 → 执行者 → 路由),把要发给用户的话打到屏幕上;带 --push 才真发
|
|
24
25
|
handle-frame '<JSON>' 把一帧当作刚收到的处理一遍,回复照发(自测用)
|
|
25
26
|
reset 丢掉机器人的专属会话,下一句从新会话开始(在聊天里发 /new 也一样)
|
|
26
27
|
doctor 检查值守的配置和依赖,有问题逐条报出来
|
|
@@ -66,10 +67,21 @@ module.exports = {
|
|
|
66
67
|
if (rest.length) throw new UsageError(USAGE);
|
|
67
68
|
await bot.run();
|
|
68
69
|
return EXIT.OK; // 循环退出后可能还挂着重连的定时器,命令到这里就结束
|
|
69
|
-
case 'handle':
|
|
70
|
+
case 'handle': {
|
|
70
71
|
if (!rest.length) throw new UsageError(USAGE);
|
|
71
|
-
|
|
72
|
+
const really = rest.includes('--push');
|
|
73
|
+
const text = rest.filter((a) => a !== '--push').join(' ');
|
|
74
|
+
// 路由开着:在命令行的进程里走一遍全流程(路由 → 执行者 → 路由),要发的话打到屏幕上
|
|
75
|
+
const r = await service.handle(text, { push: really });
|
|
76
|
+
if (r) {
|
|
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) stdout.write(`${really ? '' : '\n(没有:路由没有要发给用户的话。work-rhythm trigger show 看任务书和回执)'}\n`);
|
|
80
|
+
return EXIT.OK;
|
|
81
|
+
}
|
|
82
|
+
stdout.write(`${bot.handle(text)}\n`);
|
|
72
83
|
return EXIT.OK;
|
|
84
|
+
}
|
|
73
85
|
case 'handle-frame': {
|
|
74
86
|
if (!rest.length) throw new UsageError(USAGE);
|
|
75
87
|
const r = await bot.processFrame(rest.join(' '), true);
|
|
@@ -83,8 +95,10 @@ module.exports = {
|
|
|
83
95
|
return EXIT.OK;
|
|
84
96
|
case 'doctor': {
|
|
85
97
|
if (rest.length) throw new UsageError(USAGE);
|
|
86
|
-
const problems = bot.doctorProblems();
|
|
98
|
+
const problems = [...bot.doctorProblems(), ...(service.cfg.router ? service.doctorProblems({ strict: false, bot: false }).filter((p) => !p.startsWith('任务 ')) : [])];
|
|
99
|
+
const notes = service.doctorNotes({ mentionOff: false });
|
|
87
100
|
if (problems.length) stdout.write(`${problems.join('\n')}\n`);
|
|
101
|
+
for (const n of notes) stdout.write(`注意:${n}\n`);
|
|
88
102
|
return problems.length ? 1 : EXIT.OK;
|
|
89
103
|
}
|
|
90
104
|
case 'install': {
|
package/scripts/cmd/rhythm.js
CHANGED
|
@@ -18,13 +18,15 @@ const USAGE = `work-rhythm rhythm <子命令> —— 本地服务:定时采集
|
|
|
18
18
|
start [--tick 秒] 前台跑:到点跑采集和任务,起网页服务。要常驻用 install;--tick 是多久看一次表(默认 20,调试用)
|
|
19
19
|
stop | status | restart 停掉;看在不在跑、下次什么时候跑什么、值守开着没;重启常驻(改了配置用)
|
|
20
20
|
due [--at 时间] [--days 天数] 从某个时间起,列出什么时候跑什么
|
|
21
|
-
run <任务id|sync> [--push] 立刻跑一次,不等时间;带 --push
|
|
21
|
+
run <任务id|sync> [--push] 立刻跑一次,不等时间;带 --push 才推送(不经路由,调试和兜底)
|
|
22
22
|
serve [--port 端口] 只起网页服务
|
|
23
23
|
render <文件.md> 把一份 Markdown 渲染成页面,打到标准输出(自测、调试用)
|
|
24
|
-
doctor
|
|
24
|
+
doctor 检查配置和依赖,有问题逐条报出来;不算问题的注意事项另起一行(路由没开、路由没有只读档)
|
|
25
25
|
install | uninstall macOS launchd 常驻:开机自启、挂了拉起
|
|
26
26
|
定时任务只建在这个服务上,要先绑 agent(work-rhythm agent bind)。任务到点后:把 tasks/<id>.md 的指令交给 agent 跑一遍
|
|
27
27
|
(它会同步数据、整理事件流、写每日文件),agent 最后写的总结经消息渠道推给我,并附本机页面地址。
|
|
28
|
+
profile 的 rhythm.router 为 true 时多一步:到点的任务和 IM 里的话先变成触发交给路由判断,再派给执行者(docs/router-worker.md);
|
|
29
|
+
没写就是上面的直通做法。网页多一页监控中心 /monitor(服务、路由、执行者、定时任务、触发、配置、日志),/status.json 是同一份数据。
|
|
28
30
|
退出码: 0 完成;2 用法不对;3 没配置好(没绑 agent、配置有问题、已经在跑);4 缺依赖;5 运行失败;doctor 查出问题时是 1。
|
|
29
31
|
定义和用法见 docs/scheduled-tasks.md,agent 见 docs/agents.md。`;
|
|
30
32
|
|
|
@@ -92,7 +94,9 @@ module.exports = {
|
|
|
92
94
|
case 'doctor': {
|
|
93
95
|
if (rest.length) throw new UsageError(USAGE);
|
|
94
96
|
const problems = service.doctorProblems();
|
|
97
|
+
const notes = service.doctorNotes();
|
|
95
98
|
if (problems.length) stdout.write(`${problems.join('\n')}\n`);
|
|
99
|
+
for (const n of notes) stdout.write(`注意:${n}\n`);
|
|
96
100
|
return problems.length ? 1 : EXIT.OK;
|
|
97
101
|
}
|
|
98
102
|
case 'install': {
|