work-rhythm 0.2.13 → 0.2.20
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/collectors/local.env.example +1 -1
- package/docs/formats.md +11 -11
- package/docs/scheduled-tasks.md +1 -0
- package/package.json +1 -1
- package/scripts/cli.js +1 -0
- package/scripts/cmd/events.js +6 -6
- package/scripts/cmd/listen.js +1 -1
- package/scripts/cmd/rhythm.js +1 -1
- package/scripts/cmd/workspace.js +72 -0
- package/scripts/lib/agent.js +3 -3
- package/scripts/lib/bot.js +1 -1
- package/scripts/lib/engine.js +95 -20
- package/scripts/lib/handoff.js +4 -2
- package/scripts/lib/rhythm.js +5 -4
- package/scripts/lib/router.js +20 -12
- package/scripts/lib/view.js +2 -1
- package/scripts/lib/workdir.js +2 -0
- package/scripts/lib/worker.js +14 -8
- package/scripts/lib/workspace.js +144 -0
- package/scripts/test/check.test.js +1 -1
- package/scripts/test/events.test.js +19 -9
- package/scripts/test/listen.test.js +1 -1
- package/scripts/test/rhythm.test.js +2 -2
- package/scripts/test/router.test.js +77 -8
- package/tasks/daily-persona.md +23 -0
- package/templates/00-config/profile.example.yaml +1 -0
- package/templates/04-patterns/PERSONA.md +13 -0
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
# 会话:绑的正好是正在调 skill 的那个 agent 时,work-rhythm agent bind 会把它当前这个会话绑上(YZJ_BOT_SESSION),
|
|
67
67
|
# 机器人在 IM 里说的话从这个会话接着走。换绑 work-rhythm agent session <id>(agent sessions 列出 dsh 在这个工作区的会话),--clear 清掉
|
|
68
68
|
# YZJ_BOT_SESSION=""
|
|
69
|
-
# 值守跑在本地服务(work-rhythm rhythm
|
|
69
|
+
# 值守跑在本地服务(work-rhythm rhythm)那一个进程里,默认开启;写 YZJ_BOT_LISTEN="0" 或 work-rhythm listen uninstall 关掉
|
|
70
70
|
# YZJ_BOT_LISTEN="1"
|
|
71
71
|
# 配完跑 work-rhythm agent test 让它答一句;开值守后 work-rhythm listen status 看它在不在听
|
|
72
72
|
# YZJ_BOT_AGENT="dsh"
|
package/docs/formats.md
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
## 事件流
|
|
21
21
|
|
|
22
|
-
| 时间 | 类型 | 事项 | 来源 | 项目 |
|
|
23
|
-
|
|
22
|
+
| 时间 | 类型 | 事项 | 来源 | 项目 | 索引 |
|
|
23
|
+
|------|------|------|------|------|------|
|
|
24
24
|
|
|
25
25
|
## 备注
|
|
26
26
|
|
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
|
|
64
64
|
## 事件流
|
|
65
65
|
|
|
66
|
-
| 时间 | 类型 | 事项 | 来源 | 项目 |
|
|
67
|
-
|
|
68
|
-
| 09:05 | 沟通 | 在「导出项目群」同步接口联调进度 | im-yzj | 导出 |
|
|
69
|
-
| 09:20 | 文档 | 写导出接口文档,改了 3 个文件 | file-activity | 导出 |
|
|
70
|
-
| 10:00 | 会议 | 需求评审(150min,超时 90min) | calendar-yzj | |
|
|
71
|
-
| 13:45 | 沟通 | 在「导出项目群」发周会进展材料 | 口述 | 导出 |
|
|
72
|
-
| 14:00 | 会议 | 导出项目周会(30min,组织者) | calendar-yzj | 导出 |
|
|
73
|
-
| 14:40 | 编码 | 在 report-service 提交 3 次:导出接口联调修复 | git-activity | 导出 |
|
|
74
|
-
| 16:20 | 沟通 | 把试点数据发给平台负责人 | 口述 | work-rhythm-rollout |
|
|
66
|
+
| 时间 | 类型 | 事项 | 来源 | 项目 | 索引 |
|
|
67
|
+
|------|------|------|------|------|------|
|
|
68
|
+
| 09:05 | 沟通 | 在「导出项目群」同步接口联调进度 | im-yzj | 导出 | 01-inbox/im-yzj/2026-11-30/messages-export.json |
|
|
69
|
+
| 09:20 | 文档 | 写导出接口文档,改了 3 个文件 | file-activity | 导出 | docs/export-api.md |
|
|
70
|
+
| 10:00 | 会议 | 需求评审(150min,超时 90min) | calendar-yzj | | 01-inbox/calendar-yzj/2026-11-30/events.json |
|
|
71
|
+
| 13:45 | 沟通 | 在「导出项目群」发周会进展材料 | 口述 | 导出 | |
|
|
72
|
+
| 14:00 | 会议 | 导出项目周会(30min,组织者) | calendar-yzj | 导出 | 01-inbox/calendar-yzj/2026-11-30/events.json |
|
|
73
|
+
| 14:40 | 编码 | 在 report-service 提交 3 次:导出接口联调修复 | git-activity | 导出 | ws=report-service main@a1b2c3d |
|
|
74
|
+
| 16:20 | 沟通 | 把试点数据发给平台负责人 | 口述 | work-rhythm-rollout | |
|
|
75
75
|
|
|
76
76
|
## 备注
|
|
77
77
|
|
package/docs/scheduled-tasks.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
| `daily-plan` | 每日工作计划 | 工作日上班前 10 分钟 | [tasks/daily-plan.md](../tasks/daily-plan.md) | 今日的「计划」 |
|
|
14
14
|
| `noon-checkin` | 中午工作进展 | 工作日午休开始 | [tasks/noon-checkin.md](../tasks/noon-checkin.md) | 今日的「进展」「事件流」「备注」 |
|
|
15
15
|
| `evening-review` | 晚间工作复盘 | 工作日下班前 15 分钟 | [tasks/evening-review.md](../tasks/evening-review.md) | 今日的「复盘」「事件流」,各长期目标的「进展记录」,以及遗留清单 |
|
|
16
|
+
| `daily-persona` | 每日归档与个人分身 | 工作日下班后 | [tasks/daily-persona.md](../tasks/daily-persona.md) | 归档已完结决定与遗留,增量更新 `04-patterns/PERSONA.md` 与工作习惯 |
|
|
16
17
|
| `weekly-rhythm` | 每周工作规律 | 周五 | [tasks/weekly-rhythm.md](../tasks/weekly-rhythm.md) | [04-patterns/WORK_RHYTHM.md](../04-patterns/WORK_RHYTHM.md) |
|
|
17
18
|
| `alerts-morning` | 告警跟进晨报(本目录自定义) | 工作日早上 | [tasks/alerts-morning.md](../tasks/alerts-morning.md) | `01-inbox/reports/` 下的 Markdown 和 HTML,今日的「备注」 |
|
|
18
19
|
| `linky-cost-fill` | 录下周的耗费(本目录自定义) | 周一 | [tasks/linky-cost-fill.md](../tasks/linky-cost-fill.md) | Linky 里下周的耗费格子,今日的「备注」 |
|
package/package.json
CHANGED
package/scripts/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ const COMMANDS = {
|
|
|
26
26
|
rhythm: 'rhythm start|stop|status|due|run|serve|render|doctor|install|uninstall 本地服务:定时采集、定时整理、推送、网页、监控中心',
|
|
27
27
|
trigger: 'trigger list|show|fire 触发:看路由和执行者处理过的事,手动塞一条进去(rhythm.router 开着时)',
|
|
28
28
|
ask: 'ask - | --json … | list | show 问我一句话:问题以 JSON 丢出来,今日页「待你定」成一张卡;我答了之后回到路由',
|
|
29
|
+
workspace: 'workspace list | scan | add | remove 管理路由可用的工作区(代码库/工程目录)',
|
|
29
30
|
agent: 'agent [bind [router|worker] [名字]|test|doctor] 路由、执行者、值守用哪个 agent:检测本机的、绑定、试一句',
|
|
30
31
|
workdir: 'workdir [register|find|config|blank] 工作目录在哪:找、登记、扫描本机;不带子命令是找',
|
|
31
32
|
init: 'init <目录> 新建一个工作目录(空白模板、登记)',
|
package/scripts/cmd/events.js
CHANGED
|
@@ -16,12 +16,12 @@ const USAGE = `work-rhythm events [选项] —— 列出每日文件「## 事件
|
|
|
16
16
|
work-rhythm events --source calendar-yzj 只看这些来源(订阅源的 id,或「口述」)
|
|
17
17
|
work-rhythm events --project 导出 只看这些项目标签(和长期目标相关的事件,项目列是目标 id)
|
|
18
18
|
work-rhythm events --json 每条一个对象,给程序读
|
|
19
|
-
输出是 TSV(制表符分隔),第一行表头 date、time、type、item、source、project,按日期、时间排好序。
|
|
20
|
-
|
|
19
|
+
输出是 TSV(制表符分隔),第一行表头 date、time、type、item、source、project、ref,按日期、时间排好序。
|
|
20
|
+
事件是「一行一事」的记录,不含细节;ref(索引列)指向原始工作现场(如 01-inbox 快照路径、工作区/提交、工作项号、文档路径),方便 agent 一跳回到现场。
|
|
21
21
|
退出码: 0(没有事件也是 0,只有表头);2 选项或日期不对;3 不在工作目录里。`;
|
|
22
22
|
|
|
23
|
-
const FIELDS = ['date', 'time', 'type', 'item', 'source', 'project'];
|
|
24
|
-
const COLUMNS = { 时间: 'time', 类型: 'type', 事项: 'item', 来源: 'source', 项目: 'project' };
|
|
23
|
+
const FIELDS = ['date', 'time', 'type', 'item', 'source', 'project', 'ref'];
|
|
24
|
+
const COLUMNS = { 时间: 'time', 类型: 'type', 事项: 'item', 来源: 'source', 项目: 'project', 索引: 'ref' };
|
|
25
25
|
|
|
26
26
|
// 「## 事件流」那一节里的表:表头给出列名,分隔线跳过。格子里转义的竖线先换成占位符再切。后面几格缺的留空
|
|
27
27
|
function parseEvents(markdown, date) {
|
|
@@ -41,7 +41,7 @@ function parseEvents(markdown, date) {
|
|
|
41
41
|
}
|
|
42
42
|
// 至少要有时间和类型两格;只有一格的(写坏的行、夹在表里的说明)不算事件
|
|
43
43
|
if (cells.length < 2) continue;
|
|
44
|
-
const event = { date, time: '', type: '', item: '', source: '', project: '' };
|
|
44
|
+
const event = { date, time: '', type: '', item: '', source: '', project: '', ref: '' };
|
|
45
45
|
columns.forEach((field, n) => {
|
|
46
46
|
if (field) event[field] = cells[n] || '';
|
|
47
47
|
});
|
|
@@ -96,7 +96,7 @@ async function run(args, ctx) {
|
|
|
96
96
|
return EXIT.OK;
|
|
97
97
|
}
|
|
98
98
|
stdout.write(`${FIELDS.join('\t')}\n`);
|
|
99
|
-
for (const e of list) stdout.write(`${[e.date, e.time, e.type, e.item.replace(/\t/g, ' '), e.source, e.project].join('\t')}\n`);
|
|
99
|
+
for (const e of list) stdout.write(`${[e.date, e.time, e.type, e.item.replace(/\t/g, ' '), e.source, e.project, (e.ref || '').replace(/\t/g, ' ')].join('\t')}\n`);
|
|
100
100
|
return EXIT.OK;
|
|
101
101
|
}
|
|
102
102
|
|
package/scripts/cmd/listen.js
CHANGED
|
@@ -51,7 +51,7 @@ module.exports = {
|
|
|
51
51
|
return lines[lines.length - 1] || '';
|
|
52
52
|
};
|
|
53
53
|
// 值守开着没(跑在服务里的那个开关);改了之后让服务重新读:launchd 管的重启,手动起的提示一下
|
|
54
|
-
const listenWanted = () => (settingsEnv.YZJ_BOT_LISTEN || '').trim()
|
|
54
|
+
const listenWanted = () => (settingsEnv.YZJ_BOT_LISTEN || '').trim() !== '0';
|
|
55
55
|
const applyToService = () => {
|
|
56
56
|
if (!service.serviceAlive()) return '';
|
|
57
57
|
return launchd.kickstart('service', root) ? '本地服务已重启,值守的改动生效。' : '本地服务在跑但不是 launchd 管的(在终端里起的):停了再 start 才生效。';
|
package/scripts/cmd/rhythm.js
CHANGED
|
@@ -108,7 +108,7 @@ module.exports = {
|
|
|
108
108
|
launchd.uninstall('bot', root);
|
|
109
109
|
// 装完看一眼真的起来了:launchd 拉起失败时 bootstrap 也是成功的
|
|
110
110
|
const problem = launchd.startupProblem('service', root, `${root}/01-inbox/_rhythm.launchd.log`);
|
|
111
|
-
stdout.write(`已装成常驻:${plist}\n页面:${service.baseUrl()} 日志:${root}/01-inbox/_rhythm.log\n
|
|
111
|
+
stdout.write(`已装成常驻:${plist}\n页面:${service.baseUrl()} 日志:${root}/01-inbox/_rhythm.log\n值守默认跟着服务一起跑(collectors/local.env 写 YZJ_BOT_LISTEN=0 或 work-rhythm listen uninstall 关掉)。\n`);
|
|
112
112
|
if (problem) throw new Fail(EXIT.FAILED, problem);
|
|
113
113
|
return EXIT.OK;
|
|
114
114
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// 工作区(ws)管理命令:work-rhythm workspace list | scan | add <id> <路径> [--note …] [--agent …] | remove <id>
|
|
2
|
+
'use strict';
|
|
3
|
+
const { EXIT, UsageError } = require('../lib/run');
|
|
4
|
+
const { settings } = require('../lib/config');
|
|
5
|
+
const ws = require('../lib/workspace');
|
|
6
|
+
|
|
7
|
+
const USAGE = `work-rhythm workspace <子命令> —— 管理路由可用的工作区(代码库/工程目录)
|
|
8
|
+
|
|
9
|
+
用法:
|
|
10
|
+
work-rhythm workspace list [--json]
|
|
11
|
+
列出已登记的工作区(00-config/workspaces.json)
|
|
12
|
+
work-rhythm workspace scan [--json]
|
|
13
|
+
扫描本机候选工作区(GIT_ACTIVITY_WORKSPACES 与 ~/workspace 下的 git 仓库,按最近活跃排序)
|
|
14
|
+
work-rhythm workspace add <id> <路径> [--note <说明>] [--agent <agent>]
|
|
15
|
+
登记或更新一个工作区
|
|
16
|
+
work-rhythm workspace remove <id>
|
|
17
|
+
移除一个已登记的工作区
|
|
18
|
+
|
|
19
|
+
退出码: 0 完成;2 用法不对;3 找不到工作目录。`;
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
usage: USAGE,
|
|
23
|
+
async run(args, ctx) {
|
|
24
|
+
const { root, stdout, env } = ctx;
|
|
25
|
+
const [sub, ...rest] = args;
|
|
26
|
+
const json = rest.includes('--json');
|
|
27
|
+
const clean = rest.filter((x) => x !== '--json');
|
|
28
|
+
if (sub === 'list') {
|
|
29
|
+
const list = ws.loadRegistered(root);
|
|
30
|
+
if (json) {
|
|
31
|
+
stdout.write(`${JSON.stringify(list, null, 2)}\n`);
|
|
32
|
+
return EXIT.OK;
|
|
33
|
+
}
|
|
34
|
+
stdout.write('id\tpath\tagent\tnote\n');
|
|
35
|
+
for (const w of list) stdout.write(`${w.id}\t${w.path}\t${w.agent}\t${w.note}\n`);
|
|
36
|
+
return EXIT.OK;
|
|
37
|
+
}
|
|
38
|
+
if (sub === 'scan') {
|
|
39
|
+
const { registered, scanned } = ws.discoverWorkspaces(root, settings(root, env));
|
|
40
|
+
if (json) {
|
|
41
|
+
stdout.write(`${JSON.stringify({ registered, scanned }, null, 2)}\n`);
|
|
42
|
+
return EXIT.OK;
|
|
43
|
+
}
|
|
44
|
+
stdout.write('status\tid\tpath\tnote\n');
|
|
45
|
+
for (const w of registered) stdout.write(`已登记\t${w.id}\t${w.path}\t${w.note}\n`);
|
|
46
|
+
for (const w of scanned) stdout.write(`候选\t${w.id}\t${w.path}\t${w.note}\n`);
|
|
47
|
+
return EXIT.OK;
|
|
48
|
+
}
|
|
49
|
+
if (sub === 'add') {
|
|
50
|
+
const [id, dir, ...flags] = clean;
|
|
51
|
+
if (!id || !dir) throw new UsageError(USAGE);
|
|
52
|
+
let note = '';
|
|
53
|
+
let agent = '';
|
|
54
|
+
for (let i = 0; i < flags.length; i += 1) {
|
|
55
|
+
if (flags[i] === '--note' && flags[i + 1] !== undefined) { note = flags[++i]; }
|
|
56
|
+
else if (flags[i] === '--agent' && flags[i + 1] !== undefined) { agent = flags[++i]; }
|
|
57
|
+
else throw new UsageError(USAGE);
|
|
58
|
+
}
|
|
59
|
+
const item = ws.addWorkspace(root, { id, dir, note, agent });
|
|
60
|
+
stdout.write(`已登记工作区 ${item.id} → ${item.path}${item.note ? `(${item.note})` : ''}\n`);
|
|
61
|
+
return EXIT.OK;
|
|
62
|
+
}
|
|
63
|
+
if (sub === 'remove') {
|
|
64
|
+
const [id] = clean;
|
|
65
|
+
if (!id) throw new UsageError(USAGE);
|
|
66
|
+
const ok = ws.removeWorkspace(root, id);
|
|
67
|
+
stdout.write(ok ? `已移除工作区 ${id}\n` : `没有登记过工作区 ${id}\n`);
|
|
68
|
+
return EXIT.OK;
|
|
69
|
+
}
|
|
70
|
+
throw new UsageError(USAGE);
|
|
71
|
+
},
|
|
72
|
+
};
|
package/scripts/lib/agent.js
CHANGED
|
@@ -656,7 +656,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, idleS = 0, pr
|
|
|
656
656
|
let r;
|
|
657
657
|
try {
|
|
658
658
|
r = spawnSync(command, args, {
|
|
659
|
-
cwd: root, env: extraEnv, encoding: 'utf8', timeout: timeoutS * 1000, killSignal: 'SIGTERM', maxBuffer: 64 * 1024 * 1024,
|
|
659
|
+
cwd: root, env: extraEnv, encoding: 'utf8', ...(timeoutS > 0 ? { timeout: timeoutS * 1000 } : {}), killSignal: 'SIGTERM', maxBuffer: 64 * 1024 * 1024,
|
|
660
660
|
});
|
|
661
661
|
} catch (error) {
|
|
662
662
|
return { failed: `起不来 ${path.basename(command)}:${error.message}` };
|
|
@@ -829,7 +829,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, idleS = 0, pr
|
|
|
829
829
|
const finish = (r) => {
|
|
830
830
|
if (settled) return;
|
|
831
831
|
settled = r;
|
|
832
|
-
clearTimeout(maxTimer);
|
|
832
|
+
if (maxTimer) clearTimeout(maxTimer);
|
|
833
833
|
if (idleTimer) clearTimeout(idleTimer);
|
|
834
834
|
wake(r);
|
|
835
835
|
};
|
|
@@ -844,7 +844,7 @@ function createAgent({ root, agent, mode = 'plan', timeoutS = 300, idleS = 0, pr
|
|
|
844
844
|
if (idleTimer) clearTimeout(idleTimer);
|
|
845
845
|
idleTimer = setTimeout(() => giveUp(`超过 ${idleS} 秒没有任何输出`, 'idle'), idleS * 1000);
|
|
846
846
|
};
|
|
847
|
-
const maxTimer = setTimeout(() => giveUp(`超过 ${maxS} 秒没做完`, 'max'), maxS * 1000);
|
|
847
|
+
const maxTimer = maxS > 0 ? setTimeout(() => giveUp(`超过 ${maxS} 秒没做完`, 'max'), maxS * 1000) : null;
|
|
848
848
|
bump();
|
|
849
849
|
child.stdout.on('data', (chunk) => {
|
|
850
850
|
if (settled) return;
|
package/scripts/lib/bot.js
CHANGED
|
@@ -21,7 +21,7 @@ const RECONNECT_DELAYS_MS = [1000, 2000, 5000, 10000, 30000, 60000];
|
|
|
21
21
|
const ACK_TEXT = '收到,正在处理,稍等。';
|
|
22
22
|
// 上一句还没答完又来一句:先回这句,告诉他会和上一句一起考虑
|
|
23
23
|
const ACK_MORE_TEXT = '收到,上一句还在答,这句会和它一起考虑。';
|
|
24
|
-
const DEFAULT_PREAMBLE = '
|
|
24
|
+
const DEFAULT_PREAMBLE = '(这句来自云之家:你的回复会原样以纯文本私聊发给人类看。务必简洁明了、直说结论,去掉背景铺垫和内部过程,不用表格,以一眼看懂为准;要查很久就先说大概要多久。)';
|
|
25
25
|
|
|
26
26
|
const positiveInt = (value, fallback) => {
|
|
27
27
|
const n = Number(value);
|
package/scripts/lib/engine.js
CHANGED
|
@@ -15,10 +15,11 @@ const { createRouter } = require('./router');
|
|
|
15
15
|
const { createPool, runWorker } = require('./worker');
|
|
16
16
|
const { parseEvents } = require('../cmd/events');
|
|
17
17
|
const asks = require('./asks');
|
|
18
|
+
const ws = require('./workspace');
|
|
18
19
|
|
|
19
20
|
const ACK_TEXT = '收到,正在处理,稍等。'; // 和值守(bot.js)那句一样
|
|
20
21
|
// 上一句还没答完又来一句(插话):先回这句,告诉他会和上一句一起考虑
|
|
21
|
-
const ACK_MORE_TEXT = '
|
|
22
|
+
const ACK_MORE_TEXT = '收到,正在处理,稍等。';
|
|
22
23
|
const TRIGGER_KEEP_DAYS = 2;
|
|
23
24
|
const OPEN_MAX = 10;
|
|
24
25
|
const OPEN_MS = 24 * 3600 * 1000;
|
|
@@ -132,7 +133,7 @@ function refineBody(file) {
|
|
|
132
133
|
'',
|
|
133
134
|
'1. 读 00-config/sources.yaml:每个启用的源有「提炼成什么事件」的规则(extract)。',
|
|
134
135
|
'2. 读 01-inbox/<源id>/<今天>/ 下各源的输出(刚同步过;哪个源没有目录就跳过)。',
|
|
135
|
-
'3. 按各源的规则提炼事件,对照 docs/formats.md
|
|
136
|
+
'3. 按各源的规则提炼事件,对照 docs/formats.md 的「事件流」:类型用词表里的词,一行一事、不记内容细节;项目能归就归;「索引」列填能回到工作现场的指针(如 01-inbox/<源id>/<今天>/具体文件名、ws=<工作区id> <分支>@<短hash>、工作项编号、文件路径或交接回执路径),没有就留空。',
|
|
136
137
|
`4. 合并进今天每日文件(${file})的「## 事件流」:替换同来源同时段的旧事件,保留来源是「口述」的行,按时间排序;文件不存在就按格式创建。只改这一节。`,
|
|
137
138
|
'5. 回执里写:各源分别提炼出几条、合并后事件流一共几条;哪个源的数据读不到就写「未取到」,不要编。',
|
|
138
139
|
'',
|
|
@@ -213,6 +214,52 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
213
214
|
let busy = false;
|
|
214
215
|
let closing = false; // 服务在停:不再交给路由
|
|
215
216
|
let pumpScheduled = false; // 这个 tick 里已经排了一轮
|
|
217
|
+
let msgBuf = null;
|
|
218
|
+
let msgTimer = null;
|
|
219
|
+
const activeProgress = new Map(); // id → { t, started }
|
|
220
|
+
let progressTimer = null;
|
|
221
|
+
let progressStepMs = 0;
|
|
222
|
+
const MAX_PROGRESS_STEP_MS = 30 * 60 * 1000; // 指数退避封顶 30 分钟
|
|
223
|
+
function stopProgressTimer() {
|
|
224
|
+
if (progressTimer) { clearTimeout(progressTimer); progressTimer = null; }
|
|
225
|
+
progressStepMs = 0;
|
|
226
|
+
}
|
|
227
|
+
function scheduleNextProgress() {
|
|
228
|
+
if (closing || !activeProgress.size || !cfg.progress || cfg.progress <= 0) { stopProgressTimer(); return; }
|
|
229
|
+
const delay = progressStepMs || Math.max(200, cfg.progress * 1000);
|
|
230
|
+
progressTimer = setTimeout(() => {
|
|
231
|
+
progressTimer = null;
|
|
232
|
+
if (closing || !activeProgress.size) { stopProgressTimer(); return; }
|
|
233
|
+
const now = Date.now();
|
|
234
|
+
const all = [...activeProgress.values()];
|
|
235
|
+
if (all.length === 1) {
|
|
236
|
+
const { t, started } = all[0];
|
|
237
|
+
send(t, `还在做(已经 ${humanDuration((now - started) / 1000)} · 工作区 ${t.ws || '工作目录'}):${t.title || t.id}。做完汇报。`, { mark: false });
|
|
238
|
+
} else {
|
|
239
|
+
const lines = ['手头有 ' + all.length + ' 件事还在做(做完汇报):'];
|
|
240
|
+
all.forEach(({ t, started }, i) => {
|
|
241
|
+
lines.push(`${i + 1}. [工作区 ${t.ws || '工作目录'}] ${t.title || t.id}(已 ${humanDuration((now - started) / 1000)})`);
|
|
242
|
+
});
|
|
243
|
+
send(null, lines.join('\n'), { mark: false });
|
|
244
|
+
}
|
|
245
|
+
// 指数退避:前期密(90s → 3m → 6m → 12m → 24m),后期慢(封顶 30m),超长任务不再刷屏也不截断
|
|
246
|
+
progressStepMs = Math.min(delay * 2, MAX_PROGRESS_STEP_MS);
|
|
247
|
+
scheduleNextProgress();
|
|
248
|
+
}, delay);
|
|
249
|
+
if (progressTimer.unref) progressTimer.unref();
|
|
250
|
+
}
|
|
251
|
+
function ensureProgressTimer() {
|
|
252
|
+
if (progressTimer || !cfg.progress || cfg.progress <= 0) return;
|
|
253
|
+
progressStepMs = Math.max(200, cfg.progress * 1000);
|
|
254
|
+
scheduleNextProgress();
|
|
255
|
+
}
|
|
256
|
+
function flushMessages() {
|
|
257
|
+
if (msgTimer) { clearTimeout(msgTimer); msgTimer = null; }
|
|
258
|
+
if (!msgBuf) return null;
|
|
259
|
+
const b = msgBuf;
|
|
260
|
+
msgBuf = null;
|
|
261
|
+
return enqueue('message', { key: b.keys[0], text: b.texts.join('\n'), mode: cfg.botMode });
|
|
262
|
+
}
|
|
216
263
|
let sink = null;
|
|
217
264
|
const pool = createPool({ limit: cfg.workers });
|
|
218
265
|
const router = cfg.router ? createRouter({ root, env, role: routerSpec, timeoutS: cfg.routerTimeout, preamble: cfg.botPreamble || '', log }) : null;
|
|
@@ -242,7 +289,7 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
242
289
|
function openItems() {
|
|
243
290
|
const now = Date.now();
|
|
244
291
|
const act = [...pool.running().map((e) => e.id), ...pool.queued()];
|
|
245
|
-
const row = (x) => ({ id: x.id, status: STATUS_CN[x.worker.status] || '在跑', at: x.at, title: x.title || '' });
|
|
292
|
+
const row = (x) => ({ id: x.id, status: STATUS_CN[x.worker.status] || '在跑', at: x.at, title: x.title || '', ws: x.ws || '' });
|
|
246
293
|
const done = Object.values(triggers()).filter((x) => x.worker && ['ok', 'failed', 'stopped'].includes(x.worker.status) && now - stampMs(x.worker.endedAt || x.at) < OPEN_MS).sort((a, b) => b.at.localeCompare(a.at));
|
|
247
294
|
return [...act.map((id) => triggers()[id]).filter(Boolean).map(row), ...done.map(row)].slice(0, OPEN_MAX);
|
|
248
295
|
}
|
|
@@ -351,8 +398,9 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
351
398
|
}
|
|
352
399
|
|
|
353
400
|
// 排一个执行者。after 给了就等那件事做完再起(续做一件还在跑的事)
|
|
354
|
-
function launch(t, { mode, timeoutS, resume = '', after = '' }) {
|
|
355
|
-
|
|
401
|
+
function launch(t, { mode, timeoutS, resume = '', after = '', cwd = '', agentOverride = '' }) {
|
|
402
|
+
const spec = agentOverride ? { ...workerSpec, agent: agentOverride } : workerSpec;
|
|
403
|
+
t.worker = { status: 'queued', mode, timeoutS, agent: spec.agent, model: spec.model, effort: spec.effort, sessionId: resume || '', ws: t.ws || '' };
|
|
356
404
|
save();
|
|
357
405
|
const start = () => {
|
|
358
406
|
// 续做排在后面起:起的时候再读原来那件的会话 id(它可能到做完才有)
|
|
@@ -362,16 +410,16 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
362
410
|
t.worker.status = 'running';
|
|
363
411
|
t.worker.startedAt = fmtStamp();
|
|
364
412
|
save();
|
|
365
|
-
//
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
413
|
+
// 我这边直接派出去的(消息、手动)跑得久就统一汇总说一声;定时任务的汇报本来就会来,不额外打扰
|
|
414
|
+
const trackProgress = t.kind !== 'schedule' && !t.quiet && cfg.progress > 0;
|
|
415
|
+
if (trackProgress) {
|
|
416
|
+
activeProgress.set(t.id, { t, started: Date.now(), count: 0 });
|
|
417
|
+
ensureProgressTimer();
|
|
418
|
+
}
|
|
371
419
|
let r;
|
|
372
420
|
try {
|
|
373
421
|
r = await runWorker({
|
|
374
|
-
root, env, log, id: t.id, mode, timeoutS, idleS: cfg.workerIdle, spec
|
|
422
|
+
root, cwd: cwd || root, env, log, id: t.id, mode, timeoutS, idleS: cfg.workerIdle, spec, resume: sid, extraEnv: { WRJ_TRIGGER: t.id, WRJ_ROLE: 'worker' },
|
|
375
423
|
onSession: (sid) => {
|
|
376
424
|
if (t.worker.sessionId !== sid) {
|
|
377
425
|
t.worker.sessionId = sid;
|
|
@@ -381,7 +429,10 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
381
429
|
onKill: (fn) => ctrl.setKill(fn),
|
|
382
430
|
});
|
|
383
431
|
} finally {
|
|
384
|
-
|
|
432
|
+
if (trackProgress) {
|
|
433
|
+
activeProgress.delete(t.id);
|
|
434
|
+
if (!activeProgress.size) stopProgressTimer();
|
|
435
|
+
}
|
|
385
436
|
}
|
|
386
437
|
return finishWorker(t, r);
|
|
387
438
|
}, { kind: t.kind, task: t.task || '' });
|
|
@@ -401,9 +452,14 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
401
452
|
}
|
|
402
453
|
|
|
403
454
|
// 交给执行者:写任务书、起运行。路由没给任务书的(或者退路),拿原话或指令文件当任务书
|
|
404
|
-
function dispatch(t, c, handoffBody, byRouter = false) {
|
|
455
|
+
function dispatch(t, c, handoffBody, byRouter = false, wsId = '') {
|
|
405
456
|
let body = s(handoffBody);
|
|
406
457
|
const { mode, timeoutS } = terms(t, { byRouter });
|
|
458
|
+
const resolvedWs = wsId ? ws.discoverWorkspaces(root, env).resolve(wsId) : null;
|
|
459
|
+
if (resolvedWs) {
|
|
460
|
+
t.ws = resolvedWs.id;
|
|
461
|
+
t.wsPath = resolvedWs.path;
|
|
462
|
+
}
|
|
407
463
|
if (t.kind === 'schedule') body = `${s(c.taskBody)}${body ? `\n\n## 路由的补充\n\n${body}` : ''}\n\n${NOTE_BY_SERVICE}`;
|
|
408
464
|
else if (t.kind === 'events') body = `${focusBody({ ...c, root })}${body ? `\n## 路由的补充\n\n${body}` : ''}\n\n${NOTE_BY_SERVICE}`;
|
|
409
465
|
else if (t.kind === 'answer') body = `${answerBody(c)}${body ? `\n## 路由的补充\n\n${body}` : ''}\n\n${NOTE_BY_SERVICE}`;
|
|
@@ -415,7 +471,7 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
415
471
|
// 消息一来先回一句「收到」,路由慢的话我不用干等
|
|
416
472
|
if (t.kind === 'message' && cfg.ack && !t.acked) send(null, ACK_TEXT, { mark: false });
|
|
417
473
|
// 派出去就接着派下一条,不等它做完(汇报会自己排回来)
|
|
418
|
-
launch(t, { mode, timeoutS });
|
|
474
|
+
launch(t, { mode, timeoutS, cwd: t.wsPath || root, agentOverride: resolvedWs && resolvedWs.agent ? resolvedWs.agent : '' });
|
|
419
475
|
return undefined;
|
|
420
476
|
}
|
|
421
477
|
|
|
@@ -432,9 +488,10 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
432
488
|
const timeoutS = (target.worker && target.worker.timeoutS) || cfg.taskTimeout;
|
|
433
489
|
t.title = `${target.title || targetId}(续)`;
|
|
434
490
|
t.of = targetId;
|
|
491
|
+
if (target.ws) { t.ws = target.ws; t.wsPath = target.wsPath || ''; }
|
|
435
492
|
handoff.writeTask(root, { ...t, text: c.text }, body, { mode, timeoutS, continueOf: targetId });
|
|
436
493
|
save();
|
|
437
|
-
launch(t, { mode, timeoutS, resume: (target.worker && target.worker.sessionId) || '', after: isActive(targetId) ? targetId : '' });
|
|
494
|
+
launch(t, { mode, timeoutS, resume: (target.worker && target.worker.sessionId) || '', after: isActive(targetId) ? targetId : '', cwd: t.wsPath || root });
|
|
438
495
|
return undefined;
|
|
439
496
|
}
|
|
440
497
|
|
|
@@ -450,12 +507,13 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
450
507
|
const resume = target.worker.sessionId || '';
|
|
451
508
|
t.title = `${target.title || targetId}(插话)`;
|
|
452
509
|
t.of = targetId;
|
|
510
|
+
if (target.ws) { t.ws = target.ws; t.wsPath = target.wsPath || ''; }
|
|
453
511
|
target.suppressReport = true;
|
|
454
512
|
pool.stop(targetId, '用户插话,改了要求');
|
|
455
513
|
handoff.writeTask(root, { ...t, text: c.text }, body, { mode, timeoutS, continueOf: targetId });
|
|
456
514
|
save();
|
|
457
515
|
log('插话', `${t.id} 停掉 ${targetId} 带着新要求重跑`);
|
|
458
|
-
launch(t, { mode, timeoutS, resume });
|
|
516
|
+
launch(t, { mode, timeoutS, resume, cwd: t.wsPath || root });
|
|
459
517
|
return undefined;
|
|
460
518
|
}
|
|
461
519
|
|
|
@@ -493,7 +551,7 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
493
551
|
|
|
494
552
|
async function act(t, c, d) {
|
|
495
553
|
t.decision = d.action;
|
|
496
|
-
if (d.action === 'dispatch') return dispatch(t, c, d.handoff, true);
|
|
554
|
+
if (d.action === 'dispatch') return dispatch(t, c, d.handoff, true, d.ws || '');
|
|
497
555
|
if (d.action === 'continue') return continueWith(t, c, d.target);
|
|
498
556
|
if (d.action === 'interrupt') return interruptWith(t, c, d.target);
|
|
499
557
|
if (d.action === 'stop') return stopTask(t, d.target);
|
|
@@ -529,7 +587,7 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
529
587
|
let result = null;
|
|
530
588
|
if (router) {
|
|
531
589
|
const batch = ids.map((id) => triggers()[id]).filter(Boolean);
|
|
532
|
-
result = await router.decide(batch.map(view), openItems());
|
|
590
|
+
result = await router.decide(batch.map(view), openItems(), ws.discoverWorkspaces(root, env));
|
|
533
591
|
state.data.rounds = [...(state.data.rounds || []), { at: fmtStamp(), uid: uid(), ok: result.ok, n: batch.length, seconds: (router.last() || {}).seconds || 0 }];
|
|
534
592
|
log(result.ok ? '路由出决定' : '路由没出决定', `${batch.length} 条${result.ok ? '' : `:${result.failed}`}`);
|
|
535
593
|
}
|
|
@@ -615,6 +673,10 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
615
673
|
// 服务要停了:在跑的执行者是子进程,得收掉(最多等 3 秒)。之后不再交给路由
|
|
616
674
|
async function shutdown() {
|
|
617
675
|
closing = true;
|
|
676
|
+
if (msgTimer) { clearTimeout(msgTimer); msgTimer = null; }
|
|
677
|
+
msgBuf = null;
|
|
678
|
+
activeProgress.clear();
|
|
679
|
+
stopProgressTimer();
|
|
618
680
|
for (const id of pool.queued()) pool.stop(id, '服务停止时中断');
|
|
619
681
|
for (const e of pool.running()) pool.stop(e.id, '服务停止时中断');
|
|
620
682
|
const pending = [...dones.values()];
|
|
@@ -671,7 +733,20 @@ function createEngine({ root, env, cfg, log = () => {}, push = async () => false
|
|
|
671
733
|
|
|
672
734
|
return {
|
|
673
735
|
enqueue,
|
|
674
|
-
message: (m) =>
|
|
736
|
+
message: (m) => {
|
|
737
|
+
const key = `msg-${m.msgId}`;
|
|
738
|
+
const text = s(m.content);
|
|
739
|
+
const debounceS = Number(cfg.messageDebounce) || 0;
|
|
740
|
+
if (!debounceS || !router) return enqueue('message', { key, text, mode: cfg.botMode });
|
|
741
|
+
if (Object.values(triggers()).some((x) => x.key === key) || (msgBuf && msgBuf.keys.includes(key))) return null;
|
|
742
|
+
if (!msgBuf) msgBuf = { keys: [key], texts: [text], firstAt: Date.now() };
|
|
743
|
+
else { msgBuf.keys.push(key); msgBuf.texts.push(text); }
|
|
744
|
+
if (msgTimer) clearTimeout(msgTimer);
|
|
745
|
+
const waitMs = Math.min(debounceS * 1000, Math.max(0, 20000 - (Date.now() - msgBuf.firstAt)));
|
|
746
|
+
msgTimer = setTimeout(flushMessages, waitMs);
|
|
747
|
+
return null;
|
|
748
|
+
},
|
|
749
|
+
flushMessages,
|
|
675
750
|
schedule: (job, taskBody, taskTitle) => enqueue('schedule', { key: job.key, task: job.id, taskFile: `tasks/${job.id}.md`, taskBody, taskTitle, quiet: cfg.quiet.includes(job.id) }),
|
|
676
751
|
recover,
|
|
677
752
|
shutdown,
|
package/scripts/lib/handoff.js
CHANGED
|
@@ -10,7 +10,7 @@ const DIR = '.agents/handoff';
|
|
|
10
10
|
const NAME_RE = /^(t-\d+)(\.result)?\.md$/;
|
|
11
11
|
const ACTIONS = ['dispatch', 'continue', 'stop', 'interrupt', 'reply', 'ignore', 'notify'];
|
|
12
12
|
const SECTION_RE = /^##[ \t]+(reply|ignore|handoff|notify)[ \t]+(t-\d+)[ \t]*.*$/;
|
|
13
|
-
const DECISION_RE = /^[ \t]*-?[ \t]*(t-\d+)[ \t]+(dispatch|continue|stop|interrupt|reply|ignore|notify)(?:[ \t]+(t-\d+))?[ \t]*$/;
|
|
13
|
+
const DECISION_RE = /^[ \t]*-?[ \t]*(t-\d+)[ \t]+(dispatch|continue|stop|interrupt|reply|ignore|notify)(?:[ \t]+(t-\d+))?(?:[ \t]+ws=([A-Za-z0-9._-]+))?[ \t]*$/;
|
|
14
14
|
const MARKER = '【work-rhythm 路由】';
|
|
15
15
|
const DAY_MS = 24 * 3600 * 1000;
|
|
16
16
|
|
|
@@ -70,7 +70,7 @@ function taskText(t, body, extra = {}) {
|
|
|
70
70
|
`# 任务书 ${t.id}`,
|
|
71
71
|
'',
|
|
72
72
|
`- 来源:${source}`,
|
|
73
|
-
`- 派给:执行者 · 权限 ${extra.mode || 'plan'} ·
|
|
73
|
+
`- 派给:执行者 · 权限 ${extra.mode || 'plan'} · ${extra.timeoutS > 0 ? `最多 ${extra.timeoutS} 秒` : '不限时'}`,
|
|
74
74
|
`- ${t.kind === 'report' ? '重做自' : '续做自'}:${t.kind === 'report' ? t.of || '' : extra.continueOf || '无'}`,
|
|
75
75
|
'',
|
|
76
76
|
'## 要求',
|
|
@@ -148,6 +148,7 @@ function parseRouterReply(text) {
|
|
|
148
148
|
const it = pick(d[1]);
|
|
149
149
|
it.action = d[2];
|
|
150
150
|
if (d[3]) it.target = d[3];
|
|
151
|
+
if (d[4]) it.ws = d[4];
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
for (const s of sections) {
|
|
@@ -159,6 +160,7 @@ function parseRouterReply(text) {
|
|
|
159
160
|
id: it.id,
|
|
160
161
|
action: ACTIONS.includes(it.action) ? it.action : '',
|
|
161
162
|
target: it.target || '',
|
|
163
|
+
ws: it.ws || '',
|
|
162
164
|
handoff: it.handoff || '',
|
|
163
165
|
text: it.reply || it.notify || it.ignore || '',
|
|
164
166
|
}));
|
package/scripts/lib/rhythm.js
CHANGED
|
@@ -75,7 +75,7 @@ function loadConfig(root) {
|
|
|
75
75
|
// 定时任务用的模型和思考强度(可选项,profile 里不写也行):不配就和值守一样,用 local.env 的 YZJ_BOT_MODEL / YZJ_BOT_EFFORT
|
|
76
76
|
agentModel: typeof rhythm['agent-model'] === 'string' ? rhythm['agent-model'].trim() : '',
|
|
77
77
|
agentEffort: typeof rhythm['agent-effort'] === 'string' ? rhythm['agent-effort'].trim() : '',
|
|
78
|
-
taskTimeout:
|
|
78
|
+
taskTimeout: seconds(rhythm['task-timeout'], 0),
|
|
79
79
|
syncTimeout: positiveInt(rhythm['sync-timeout'], 600),
|
|
80
80
|
notifyChannel: typeof preferences.notify === 'string' ? preferences.notify.trim() : '',
|
|
81
81
|
schedule,
|
|
@@ -146,6 +146,7 @@ function createRhythm({ root, env, packageRoot }) {
|
|
|
146
146
|
workerIdle: idle === 0 ? 0 : Math.max(600, idle),
|
|
147
147
|
progress: seconds(env.YZJ_BOT_PROGRESS, 90),
|
|
148
148
|
progressMax: positiveInt(env.YZJ_BOT_PROGRESS_MAX, 3),
|
|
149
|
+
messageDebounce: seconds(env.YZJ_BOT_DEBOUNCE, 8),
|
|
149
150
|
replyMax: positiveInt(env.YZJ_BOT_REPLY_MAX, 2000),
|
|
150
151
|
botPreamble: (env.YZJ_BOT_PREAMBLE || '').trim(),
|
|
151
152
|
links: LINKS,
|
|
@@ -797,7 +798,7 @@ ${sourcesCard(d)}
|
|
|
797
798
|
<span class="pill">workers: ${d.config.workers}</span>
|
|
798
799
|
<span class="pill">refine: ${d.config.refine}</span>
|
|
799
800
|
<span class="pill">refine-interval: ${d.config.refineInterval}m</span>
|
|
800
|
-
<span class="pill">task-timeout: ${d.config.taskTimeout}s</span>
|
|
801
|
+
<span class="pill">task-timeout: ${d.config.taskTimeout ? `${d.config.taskTimeout}s` : '不限'}</span>
|
|
801
802
|
<span class="pill">agent-mode: ${esc(d.config.agentMode)}</span>
|
|
802
803
|
<span class="pill">handoff-keep: ${d.config.handoffKeep}d</span>
|
|
803
804
|
<span class="pill">history-keep: ${d.config.historyKeep}d</span>
|
|
@@ -896,7 +897,7 @@ ${sourcesCard(d)}
|
|
|
896
897
|
log('服务开始', `pid=${process.pid} 页面=${baseUrl()} agent=${env.YZJ_BOT_AGENT || '(没配)'}`);
|
|
897
898
|
process.stdout.write(`页面:${baseUrl()} 停:work-rhythm rhythm stop\n`);
|
|
898
899
|
|
|
899
|
-
//
|
|
900
|
+
// 值守(机器人的收消息一半)也在这里跑:一个后台进程管定时任务、推送、网页和值守。默认开着(collectors/local.env 写 YZJ_BOT_LISTEN=0 才关);
|
|
900
901
|
// 配置有问题不拦着服务起,只记一笔——定时任务和网页照常
|
|
901
902
|
let bot = null;
|
|
902
903
|
let botTask = null;
|
|
@@ -1046,7 +1047,7 @@ ${sourcesCard(d)}
|
|
|
1046
1047
|
|
|
1047
1048
|
// 值守要不要跟着服务一起开
|
|
1048
1049
|
function botWanted() {
|
|
1049
|
-
return (env.YZJ_BOT_LISTEN || '').trim()
|
|
1050
|
+
return (env.YZJ_BOT_LISTEN || '').trim() !== '0';
|
|
1050
1051
|
}
|
|
1051
1052
|
|
|
1052
1053
|
function statusText() {
|
package/scripts/lib/router.js
CHANGED
|
@@ -23,12 +23,12 @@ const PROMPT = `${handoff.MARKER}下面是到达的触发,前面是「手头
|
|
|
23
23
|
- message 里是在回答某张待办卡片(「1 选 2」这种):dispatch,task 写清是哪一条事项、选了第几个选项;执行者会 work-rhythm decisions answer 并照选项做。
|
|
24
24
|
|
|
25
25
|
二、七种决定(每条触发只能选一种)
|
|
26
|
-
- dispatch:派人做。要写一个「## handoff
|
|
26
|
+
- dispatch:派人做。要写一个「## handoff <短号>」小节当任务书。日常事默认在工作目录跑;如果明确要在某个代码库/工程里干活且能从「可用工作区」里挑出,写成「- <短号> dispatch ws=<id>」。如果必须确定工作区但拿不准,不写 ws=,在任务书里让执行者用 work-rhythm ask 问用户(选项带上候选工作区和工作目录),确认后记进 work-rhythm workspace add 和今日事件流。
|
|
27
27
|
- reply:不用动手、一句话直接答。写「## reply <短号>」。只用于 message / manual。
|
|
28
28
|
- ignore:不用处理。写「## ignore <短号>」和一句原因。
|
|
29
29
|
- notify:给用户的话。写「## notify <短号>」。只用于 report。
|
|
30
|
-
- continue
|
|
31
|
-
- interrupt
|
|
30
|
+
- continue <短号>:这句话是接着「手头的事」里某一件做完的事继续追问,或者顺便再做一件相关事(不打断正在跑的,排在它后面单独回一次)。不用写任务书,CLI 会把原话交给原来那个执行者。
|
|
31
|
+
- interrupt <短号>:某件事还在跑,用户又补充了条件、想法或改了要求,希望合在一起只回一次。CLI 会停掉它、带着新话重跑并压掉上一轮汇报。正在跑的事收到补充时优先选 interrupt,不要选 continue。
|
|
32
32
|
- stop <短号>:用户不要某件正在跑的事了。
|
|
33
33
|
|
|
34
34
|
三、任务书怎么写(dispatch 的时候)
|
|
@@ -44,17 +44,18 @@ const PROMPT = `${handoff.MARKER}下面是到达的触发,前面是「手头
|
|
|
44
44
|
任务书正文……
|
|
45
45
|
|
|
46
46
|
## reply <短号>
|
|
47
|
-
|
|
47
|
+
给人类在 IM 里看的回复:简洁明了,直说结论,不铺垫、不啰嗦……
|
|
48
48
|
|
|
49
49
|
## notify <短号>
|
|
50
|
-
|
|
50
|
+
给人类在 IM 里看的话:纯文本、不用表格、不放链接。务必简洁明了、说清结论——先给结论和要做的事,去掉背景铺垫、内部过程和重复解释;一条一件事,以一眼看懂为准,要用户拍板的事简短列在最后……
|
|
51
51
|
|
|
52
52
|
五、硬规则
|
|
53
53
|
1. 每条触发都要有、且只有一个决定,写在最前面的「决定:」下面。
|
|
54
54
|
2. 决定行写成「- <短号> <决定>」;小节标题严格是「## <决定> <短号>」。
|
|
55
55
|
3. 任务书正文里不要出现「## reply / ignore / handoff / notify <短号>」这样的标题。
|
|
56
56
|
4. continue / interrupt / stop 后面的短号,必须是「手头的事」里列出来的。
|
|
57
|
-
5. 标了「不推送」的汇报不能 notify
|
|
57
|
+
5. 标了「不推送」的汇报不能 notify。
|
|
58
|
+
6. reply 和 notify 是直接发给人类看的,必须简洁明了、说得清晰:能三行说清不写十行,不汇报内部机制(如任务书、超时细节、重试次数),除非影响结论。`;
|
|
58
59
|
|
|
59
60
|
const short = (stamp) => String(stamp || '').slice(5, 16);
|
|
60
61
|
const readText = (file) => {
|
|
@@ -74,7 +75,7 @@ function triggerLine(t) {
|
|
|
74
75
|
if (t.kind === 'events') {
|
|
75
76
|
const health = (t.sources || []).map((x) => `${x.id} ${x.ok ? '成功' : `失败:${x.detail || `退出码 ${x.code}`}`}`).join('、');
|
|
76
77
|
const head = `[${t.id}] 来源=events 时间=${when} ${t.ok ? `新事件 ${(t.events || []).length} 条` : `提炼没成:${t.reason}`};这次采集:${health || '(没跑)'}`;
|
|
77
|
-
const list = (t.events || []).slice(0, 40).map((e) => ` - ${e.time} ${e.type} ${e.item}(${[e.source, e.project].filter(Boolean).join(',')})`);
|
|
78
|
+
const list = (t.events || []).slice(0, 40).map((e) => ` - ${e.time} ${e.type} ${e.item}(${[e.source, e.project, e.ref].filter(Boolean).join(',')})`);
|
|
78
79
|
return [head, ...list].join('\n');
|
|
79
80
|
}
|
|
80
81
|
if (t.kind === 'answer') {
|
|
@@ -86,13 +87,20 @@ function triggerLine(t) {
|
|
|
86
87
|
return t.ok ? `${head}\n 开头:${t.opening}` : head;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
// 一轮的提示词:固定的说明 + 手头的事 + 这一批触发。extra 是重试时的一句提醒
|
|
90
|
-
function turnPrompt(triggers, open, extra = '') {
|
|
90
|
+
// 一轮的提示词:固定的说明 + 可用工作区(有的话)+ 手头的事 + 这一批触发。extra 是重试时的一句提醒
|
|
91
|
+
function turnPrompt(triggers, open, extra = '', workspaces = null) {
|
|
91
92
|
const lines = [PROMPT];
|
|
92
93
|
if (extra) lines.push('', extra);
|
|
94
|
+
const reg = (workspaces && workspaces.registered) || [];
|
|
95
|
+
const scan = (workspaces && workspaces.scanned) || [];
|
|
96
|
+
if (reg.length || scan.length) {
|
|
97
|
+
lines.push('', '可用工作区(日常事默认在工作目录跑,不写 ws=;明确要进代码库/工程时在 dispatch 行加 ws=<id>;不确定选哪个时在任务书里让执行者用 work-rhythm ask 问用户并记录到工作目录):');
|
|
98
|
+
for (const w of reg) lines.push(`- ${w.id}(已登记,${w.path})${w.note ? `:${w.note}` : ''}`);
|
|
99
|
+
for (const w of scan) lines.push(`- ${w.id}(候选,${w.path})`);
|
|
100
|
+
}
|
|
93
101
|
lines.push('', '手头的事(在跑的和今天做完的):');
|
|
94
102
|
if (!open.length) lines.push('- (没有)');
|
|
95
|
-
for (const o of open) lines.push(`- ${o.id} ${o.status},${short(o.at)}:${o.title || '(没写标题)'}`);
|
|
103
|
+
for (const o of open) lines.push(`- ${o.id} ${o.status},${short(o.at)}:${o.title || '(没写标题)'}${o.ws ? ` [ws=${o.ws}]` : ''}`);
|
|
96
104
|
lines.push('', '触发:');
|
|
97
105
|
for (const t of triggers) lines.push(triggerLine(t));
|
|
98
106
|
return lines.join('\n');
|
|
@@ -161,13 +169,13 @@ function createRouter({ root, env, role, timeoutS = 120, preamble = '', log = ()
|
|
|
161
169
|
}
|
|
162
170
|
|
|
163
171
|
// 对一批触发出决定。解析不出来、或者漏了触发,带着一句提醒再来一轮;再不行返回 ok 为 false(missing 是漏掉的短号)
|
|
164
|
-
async function decide(triggers, open) {
|
|
172
|
+
async function decide(triggers, open, workspaces = null) {
|
|
165
173
|
const started = Date.now();
|
|
166
174
|
const ids = triggers.map((t) => t.id);
|
|
167
175
|
let extra = '';
|
|
168
176
|
let lastReply = '';
|
|
169
177
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
170
|
-
const r = await turn(turnPrompt(triggers, open, extra));
|
|
178
|
+
const r = await turn(turnPrompt(triggers, open, extra, workspaces));
|
|
171
179
|
if (r.failed) {
|
|
172
180
|
last = { at: fmtStamp(), seconds: Math.round((Date.now() - started) / 1000), ok: false };
|
|
173
181
|
return { ok: false, failed: r.failed, config: r.config, decisions: {}, missing: ids };
|
package/scripts/lib/view.js
CHANGED
|
@@ -303,11 +303,12 @@ function renderEventsSection(section) {
|
|
|
303
303
|
? `<div class="filter-bar" role="group" aria-label="按类型筛选"><button type="button" class="filter-pill is-active" data-filter="all">全部 ${parsed.rows.length}</button>${typeEntries.map(([k, v]) => `<button type="button" class="filter-pill" data-filter="${esc(k)}">${esc(k)} ${v}</button>`).join('')}</div>`
|
|
304
304
|
: '';
|
|
305
305
|
const rowsHtml = parsed.rows.map((r) => {
|
|
306
|
-
const [time = '', type = '', desc = '', source = '', project = ''] = r;
|
|
306
|
+
const [time = '', type = '', desc = '', source = '', project = '', ref = ''] = r;
|
|
307
307
|
const cls = eventTypeClass(type, desc);
|
|
308
308
|
const meta = [
|
|
309
309
|
project ? `<span class="meta-tag is-proj">${esc(project)}</span>` : '',
|
|
310
310
|
source ? `<span class="meta-tag">${esc(source)}</span>` : '',
|
|
311
|
+
ref ? `<span class="meta-tag" title="工作现场索引">${esc(ref)}</span>` : '',
|
|
311
312
|
].filter(Boolean).join('');
|
|
312
313
|
return `<div class="tl-row" data-type="${esc(type || '其他')}"><span class="tl-time">${esc(time)}</span><span class="tl-type${cls ? ` ${cls}` : ''}">${esc(type)}</span><div class="tl-desc">${md.inline(desc, MD_OPTS)}</div><div class="tl-meta">${meta}</div></div>`;
|
|
313
314
|
}).join('\n');
|
package/scripts/lib/workdir.js
CHANGED
|
@@ -58,6 +58,8 @@ function resolveRoot({ cwd = process.cwd(), option = '', env = process.env, pack
|
|
|
58
58
|
if (option) return { root: path.resolve(option), source: 'option', problem: '' };
|
|
59
59
|
const up = findUp(cwd);
|
|
60
60
|
if (up) return { root: up, source: 'cwd', problem: '' };
|
|
61
|
+
const fromEnv = env && env.WRJ_WORKDIR ? path.resolve(String(env.WRJ_WORKDIR).trim()) : '';
|
|
62
|
+
if (fromEnv && isWorkdir(fromEnv)) return { root: fromEnv, source: 'env', problem: '' };
|
|
61
63
|
if (insidePackage(cwd, packageRoot)) return { root: path.resolve(packageRoot), source: 'package', problem: '' };
|
|
62
64
|
const reg = registered(env);
|
|
63
65
|
if (reg && isWorkdir(reg)) return { root: reg, source: 'pointer', problem: '' };
|
package/scripts/lib/worker.js
CHANGED
|
@@ -8,19 +8,25 @@ const handoff = require('./handoff');
|
|
|
8
8
|
|
|
9
9
|
const WORKER_STATE_DIR = ['01-inbox', '_rhythm', 'workers'];
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
function workerPrompt(id) {
|
|
13
|
-
|
|
11
|
+
// 给执行者的那一句:在工作目录里跑用相对路径,跨工作区跑用绝对路径(交接文档仍在工作目录里)
|
|
12
|
+
function workerPrompt(id, { root = '', cwd = '' } = {}) {
|
|
13
|
+
const cross = root && cwd && path.resolve(cwd) !== path.resolve(root);
|
|
14
|
+
const task = cross ? handoff.taskPath(root, id) : handoff.relTask(id);
|
|
15
|
+
const result = cross ? handoff.resultPath(root, id) : handoff.relResult(id);
|
|
16
|
+
return `读 ${task}(任务书),照它做完,把回执写到 ${result};没有写权限就把回执作为你最后一段话输出。不要向我提问,不要等待确认,不要自己发消息。`;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
// 跑一个执行者。spec 是 { agent, model, effort };
|
|
19
|
+
// 跑一个执行者。spec 是 { agent, model, effort };cwd 是运行目录(默认工作目录 root,指定工作区时切过去);
|
|
20
|
+
// resume 给了就接着那个会话跑(续做),接不上时自动改开新会话(上下文在任务书里)。
|
|
17
21
|
// 返回 { ok, failed, stopped, reply, sessionId, seconds, config, partial };onSession 在拿到会话 id 时调(监控页上一开始就能看到),onKill 把停它的办法交出去。
|
|
18
22
|
// idleS 是静默闸:执行者可能长时间不出声(跑构建、跑测试),给得比值守宽
|
|
19
|
-
async function runWorker({ root, env, log = () => {}, id, mode, timeoutS, idleS = 0, spec, resume = '', onSession = () => {}, onKill = () => {}, extraEnv = {} }) {
|
|
20
|
-
const
|
|
23
|
+
async function runWorker({ root, cwd = '', env, log = () => {}, id, mode, timeoutS, idleS = 0, spec, resume = '', onSession = () => {}, onKill = () => {}, extraEnv = {} }) {
|
|
24
|
+
const runDir = cwd ? path.resolve(cwd) : root;
|
|
25
|
+
const agent = createAgent({ root: runDir, agent: spec.agent, mode, timeoutS, idleS, log, env, model: spec.model, effort: spec.effort });
|
|
21
26
|
const started = Date.now();
|
|
22
|
-
// extraEnv:执行者的环境里多带几样(WRJ_TRIGGER
|
|
23
|
-
const
|
|
27
|
+
// extraEnv:执行者的环境里多带几样(WRJ_TRIGGER 是哪条触发的;WRJ_WORKDIR 指向工作目录,跨 ws 时调 work-rhythm ask/decisions/workspace 找得到)
|
|
28
|
+
const mergedEnv = { WRJ_WORKDIR: root, ...extraEnv };
|
|
29
|
+
const handle = agent.start(workerPrompt(id, { root, cwd: runDir }), { session: resume, onSession, stateDir: path.join(root, ...WORKER_STATE_DIR), extraEnv: mergedEnv });
|
|
24
30
|
onKill(handle.kill);
|
|
25
31
|
const r = await handle.done;
|
|
26
32
|
return {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// 工作区(ws)管理与扫描:让路由知道本机有哪些代码库/工程目录,派执行者时可以直接切到对应目录干活。
|
|
2
|
+
// 已登记的存 00-config/workspaces.json(结构简单、程序读写不碰 profile.yaml 的手写格式);
|
|
3
|
+
// 扫描从 GIT_ACTIVITY_WORKSPACES、~/workspace 下的 git 仓库取候选,按最近活跃时间排。
|
|
4
|
+
'use strict';
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { writeFileAtomic, UsageError } = require('./run');
|
|
8
|
+
|
|
9
|
+
const WS_FILE = ['00-config', 'workspaces.json'];
|
|
10
|
+
const ID_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
11
|
+
const SCAN_LIMIT = 20;
|
|
12
|
+
|
|
13
|
+
const wsFile = (root) => path.join(root, ...WS_FILE);
|
|
14
|
+
|
|
15
|
+
function loadRegistered(root) {
|
|
16
|
+
try {
|
|
17
|
+
const data = JSON.parse(fs.readFileSync(wsFile(root), 'utf8'));
|
|
18
|
+
if (!Array.isArray(data)) return [];
|
|
19
|
+
return data
|
|
20
|
+
.filter((x) => x && typeof x === 'object' && x.id && x.path)
|
|
21
|
+
.map((x) => ({
|
|
22
|
+
id: String(x.id).trim(),
|
|
23
|
+
path: path.resolve(String(x.path).trim()),
|
|
24
|
+
note: String(x.note || '').trim(),
|
|
25
|
+
agent: String(x.agent || '').trim(),
|
|
26
|
+
}));
|
|
27
|
+
} catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function saveRegistered(root, list) {
|
|
33
|
+
writeFileAtomic(wsFile(root), `${JSON.stringify(list, null, 2)}\n`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function addWorkspace(root, { id, dir, note = '', agent = '' }) {
|
|
37
|
+
const cleanId = String(id || '').trim();
|
|
38
|
+
if (!ID_RE.test(cleanId)) throw new UsageError(`工作区 id 不合法(只用字母、数字、._-,1–64 字):${cleanId || '(空)'}`);
|
|
39
|
+
const full = path.resolve(String(dir || '').trim());
|
|
40
|
+
if (!full || !fs.existsSync(full) || !fs.statSync(full).isDirectory()) {
|
|
41
|
+
throw new UsageError(`目录不存在:${dir || '(空)'}`);
|
|
42
|
+
}
|
|
43
|
+
const list = loadRegistered(root);
|
|
44
|
+
const item = { id: cleanId, path: full, note: String(note || '').trim(), agent: String(agent || '').trim() };
|
|
45
|
+
const idx = list.findIndex((x) => x.id === cleanId);
|
|
46
|
+
if (idx >= 0) list[idx] = item;
|
|
47
|
+
else list.push(item);
|
|
48
|
+
saveRegistered(root, list);
|
|
49
|
+
return item;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function removeWorkspace(root, id) {
|
|
53
|
+
const cleanId = String(id || '').trim();
|
|
54
|
+
const list = loadRegistered(root);
|
|
55
|
+
const next = list.filter((x) => x.id !== cleanId);
|
|
56
|
+
if (next.length === list.length) return false;
|
|
57
|
+
saveRegistered(root, next);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 扫描本机候选工作区:GIT_ACTIVITY_WORKSPACES + ~/workspace(或 env.WRJ_WS_SCAN_DIRS)下的 git 仓库
|
|
62
|
+
function scanCandidates(root, env = process.env) {
|
|
63
|
+
const home = env.HOME || '';
|
|
64
|
+
const roots = new Set();
|
|
65
|
+
const addDirs = (raw) => {
|
|
66
|
+
for (const part of String(raw || '').split(/[:\n,;]+/)) {
|
|
67
|
+
const p = part.trim().replace(/^~(?=\/|$)/, home);
|
|
68
|
+
if (p) roots.add(path.resolve(p));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
if (env.WRJ_WS_SCAN_DIRS) addDirs(env.WRJ_WS_SCAN_DIRS);
|
|
72
|
+
else {
|
|
73
|
+
addDirs(env.GIT_ACTIVITY_WORKSPACES);
|
|
74
|
+
if (home) roots.add(path.join(home, 'workspace'));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const rootResolved = path.resolve(root);
|
|
78
|
+
const registered = loadRegistered(root);
|
|
79
|
+
const byPath = new Map(registered.map((w) => [w.path, w]));
|
|
80
|
+
const byId = new Set(registered.map((w) => w.id));
|
|
81
|
+
const found = [];
|
|
82
|
+
|
|
83
|
+
const consider = (dir) => {
|
|
84
|
+
const full = path.resolve(dir);
|
|
85
|
+
if (full === rootResolved || byPath.has(full)) return;
|
|
86
|
+
const gitDir = path.join(full, '.git');
|
|
87
|
+
if (!fs.existsSync(gitDir)) return;
|
|
88
|
+
let mtime = 0;
|
|
89
|
+
try {
|
|
90
|
+
mtime = Math.max(fs.statSync(full).mtimeMs, fs.statSync(gitDir).mtimeMs);
|
|
91
|
+
} catch {
|
|
92
|
+
mtime = 0;
|
|
93
|
+
}
|
|
94
|
+
const base = path.basename(full);
|
|
95
|
+
if (!ID_RE.test(base) || byId.has(base)) return;
|
|
96
|
+
byPath.set(full, { id: base, path: full });
|
|
97
|
+
byId.add(base);
|
|
98
|
+
found.push({ id: base, path: full, note: '', agent: '', mtime });
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
for (const dir of roots) {
|
|
102
|
+
if (!fs.existsSync(dir)) continue;
|
|
103
|
+
let stat;
|
|
104
|
+
try {
|
|
105
|
+
stat = fs.statSync(dir);
|
|
106
|
+
} catch {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!stat.isDirectory()) continue;
|
|
110
|
+
if (fs.existsSync(path.join(dir, '.git'))) {
|
|
111
|
+
consider(dir);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
let entries;
|
|
115
|
+
try {
|
|
116
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
117
|
+
} catch {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
for (const e of entries) {
|
|
121
|
+
if (!e.isDirectory() || e.name.startsWith('.')) continue;
|
|
122
|
+
consider(path.join(dir, e.name));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
found.sort((a, b) => b.mtime - a.mtime);
|
|
127
|
+
return found.slice(0, SCAN_LIMIT).map(({ id, path: p, note, agent }) => ({ id, path: p, note, agent }));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 给路由用的合并视图:{ registered, scanned, resolve(id) }
|
|
131
|
+
function discoverWorkspaces(root, env = process.env) {
|
|
132
|
+
const registered = loadRegistered(root);
|
|
133
|
+
const scanned = scanCandidates(root, env);
|
|
134
|
+
const all = new Map();
|
|
135
|
+
for (const w of registered) all.set(w.id, { ...w, registered: true });
|
|
136
|
+
for (const w of scanned) if (!all.has(w.id)) all.set(w.id, { ...w, registered: false });
|
|
137
|
+
return {
|
|
138
|
+
registered,
|
|
139
|
+
scanned,
|
|
140
|
+
resolve: (id) => (id ? all.get(String(id).trim()) || null : null),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = { WS_FILE, ID_RE, loadRegistered, saveRegistered, addWorkspace, removeWorkspace, scanCandidates, discoverWorkspaces };
|
|
@@ -193,7 +193,7 @@ test('check:只绑了 agent 跑定时任务、没装值守,不报值守的
|
|
|
193
193
|
s.localEnv('# YZJ_BOT_AGENT="dsh"\n');
|
|
194
194
|
const r2 = s.check({ ...s.stubs });
|
|
195
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\|kimi>/);
|
|
196
|
+
assert.match(r2.stdout, /schedule 里有任务(daily-plan、noon-checkin、evening-review、carryover、daily-persona、weekly-rhythm)却没绑 agent,到点一个也跑不了:work-rhythm agent bind <zcode\|dsh\|qoder\|claude\|kimi>/);
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
test('check:值守装了之后,配的命令找不到时报出来', (t) => {
|
|
@@ -25,11 +25,11 @@ test('events:把 7 天内的每日文件里的事件流按日期、时间列
|
|
|
25
25
|
const r = box.run(['events']);
|
|
26
26
|
assert.equal(r.code, 0, r.out);
|
|
27
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}
|
|
28
|
+
`date${T}time${T}type${T}item${T}source${T}project${T}ref`,
|
|
29
|
+
`${DAY(-6)}${T}10:00${T}文档${T}写接口文档${T}file-activity${T}导出${T}`,
|
|
30
|
+
`${DAY(-1)}${T}14:00${T}会议${T}周会(30min)${T}calendar-yzj${T}${T}`,
|
|
31
|
+
`${DAY(0)}${T}08:30${T}编码${T}提交 3 次${T}git-activity${T}导出${T}`,
|
|
32
|
+
`${DAY(0)}${T}09:05${T}沟通${T}同步接口联调进度${T}im-yzj${T}导出${T}`,
|
|
33
33
|
'',
|
|
34
34
|
].join('\n'));
|
|
35
35
|
});
|
|
@@ -60,20 +60,30 @@ test('events:按类型、来源、项目筛,可以逗号分隔写多个;--
|
|
|
60
60
|
assert.deepEqual(items(['--project', 'demo-goal']), ['发材料']);
|
|
61
61
|
assert.deepEqual(items(['--project', '导出,demo-goal']), ['同步进度', '发材料']);
|
|
62
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' });
|
|
63
|
+
assert.deepEqual(json[2], { date: DAY(0), time: '13:45', type: '沟通', item: '发材料', source: '口述', project: 'demo-goal', ref: '' });
|
|
64
64
|
assert.equal(json.length, 3);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
test('events:支持第 6 列「索引」(ref)指向工作现场,老的 5 列表格向后兼容', (t) => {
|
|
68
|
+
const box = makeSandbox(t);
|
|
69
|
+
const dir = box.workdir();
|
|
70
|
+
const date = DAY(0);
|
|
71
|
+
write(path.join(dir, '02-daily', date.slice(0, 7), `${date}.md`), `# ${date}\n\n## 事件流\n\n| 时间 | 类型 | 事项 | 来源 | 项目 | 索引 |\n|------|------|------|------|------|------|\n| 09:30 | 编码 | 修导出边界 | git-activity | 导出 | ws=report-service main@a1b2c3d |\n| 10:00 | 沟通 | 群里对齐 | im-yzj | 导出 | 01-inbox/im-yzj/${date}/messages-g1.json |\n`);
|
|
72
|
+
const json = JSON.parse(box.run(['events', '--today', '--json']).stdout);
|
|
73
|
+
assert.equal(json[0].ref, 'ws=report-service main@a1b2c3d');
|
|
74
|
+
assert.equal(json[1].ref, `01-inbox/im-yzj/${date}/messages-g1.json`);
|
|
75
|
+
});
|
|
76
|
+
|
|
67
77
|
test('events:没有文件、没有事件流、空表都只有表头;看不懂的行跳过;格子里转义的竖线算一个格子', (t) => {
|
|
68
78
|
const box = makeSandbox(t);
|
|
69
79
|
const dir = box.workdir();
|
|
70
|
-
assert.equal(box.run(['events']).stdout, `date${T}time${T}type${T}item${T}source${T}project\n`);
|
|
80
|
+
assert.equal(box.run(['events']).stdout, `date${T}time${T}type${T}item${T}source${T}project${T}ref\n`);
|
|
71
81
|
const date = DAY(0);
|
|
72
82
|
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`);
|
|
83
|
+
assert.equal(box.run(['events', '--today']).stdout, `date${T}time${T}type${T}item${T}source${T}project${T}ref\n${date}${T}10:00${T}文档${T}带 | 竖线的事项${T}file-activity${T}${T}\n`);
|
|
74
84
|
// 事项里混进制表符时换成空格,表不会串列
|
|
75
85
|
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,
|
|
86
|
+
assert.equal(box.run(['events', '--today']).stdout.split('\n')[1].split(T).length, 7);
|
|
77
87
|
});
|
|
78
88
|
|
|
79
89
|
test('events:选项不对、日期不对、起始晚于结束时退出码为 2', (t) => {
|
|
@@ -421,7 +421,7 @@ test('listen install / uninstall / status:值守跑在本地服务那一个进
|
|
|
421
421
|
// 老的单独常驻还在:install 要把它收掉
|
|
422
422
|
write(path.join(agents, 'work-rhythm.bot.work.plist'), '<plist/>');
|
|
423
423
|
assert.equal(s.listen(['status'], env).code, 1);
|
|
424
|
-
assert.match(s.listen(['status'], env).stdout, /本地服务没在跑(work-rhythm rhythm status
|
|
424
|
+
assert.match(s.listen(['status'], env).stdout, /本地服务没在跑(work-rhythm rhythm status 看详情);值守开着,但服务没在跑,所以没在听。\n提醒:还有一个老的单独常驻/);
|
|
425
425
|
const r = s.listen(['install'], env);
|
|
426
426
|
assert.equal(r.code, 0, r.out);
|
|
427
427
|
assert.match(r.stdout, /值守已打开(collectors\/local.env 的 YZJ_BOT_LISTEN=1),跑在本地服务里。本地服务已装成常驻/);
|
|
@@ -481,8 +481,8 @@ test('rhythm:YZJ_BOT_LISTEN=1 时值守在服务的同一个进程里跑;配
|
|
|
481
481
|
const fine = s.rhythm(['doctor'], { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: 'me-0001' });
|
|
482
482
|
assert.equal(fine.code, 0, fine.out);
|
|
483
483
|
assert.match(fine.stdout, /^注意:路由没开(profile 的 rhythm\.router 没写)[\s\S]*\n$/);
|
|
484
|
-
//
|
|
485
|
-
assert.match(s.rhythm(['status'], botEnv).stdout, /值守:关着/);
|
|
484
|
+
// 显式写 0 关掉的时候
|
|
485
|
+
assert.match(s.rhythm(['status'], { ...botEnv, YZJ_BOT_LISTEN: '0' }).stdout, /值守:关着/);
|
|
486
486
|
// 配置不齐(没写我的 openId):doctor 报出来;服务照样起,只记「值守没开」
|
|
487
487
|
const bad = s.rhythm(['doctor'], { ...botEnv, YZJ_BOT_LISTEN: '1', YZJ_MY_OPEN_ID: '' });
|
|
488
488
|
assert.equal(bad.code, 1);
|
|
@@ -21,7 +21,7 @@ function setup(t) {
|
|
|
21
21
|
const profile = `${box.work}/00-config/profile.yaml`;
|
|
22
22
|
write(profile, setKey(read(profile), 'notify', '"yzj-robot"'));
|
|
23
23
|
const stubs = box.stubs();
|
|
24
|
-
const s = { box, profile, stubs, env: { ...stubs, STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: DUMMY_URL, YZJ_MY_OPEN_ID: 'me-0001' } };
|
|
24
|
+
const s = { box, profile, stubs, env: { ...stubs, STUB_KEYCHAIN: 'ok', STUB_ROBOT_URL: DUMMY_URL, YZJ_MY_OPEN_ID: 'me-0001', YZJ_BOT_DEBOUNCE: '0' } };
|
|
25
25
|
s.run = (args, env = {}) => box.run(args, { env: { ...s.env, ...env } });
|
|
26
26
|
s.set = (key, value) => write(profile, setKey(read(profile), key, value));
|
|
27
27
|
s.routerOn = () => write(profile, read(profile).replace(/^( quiet:.*)$/m, '$1\n router: true'));
|
|
@@ -68,7 +68,7 @@ test('路由开着:listen handle 走全流程——路由写任务书、执行
|
|
|
68
68
|
assert.match(calls[1], /^【work-rhythm 路由】[\s\S]*\n- t-000001 做完,\d\d-\d\d \d\d:\d\d:任务:转述\n\n触发:\n\[t-000002\] 来源=report 时间=\S+ \S+ 对应=t-000001 结果=成功 用时=\d+s 回执=\.agents\/handoff\/t-000001\.result\.md\n 开头:记一下:刚和测试对完导出边界$/, calls[1]);
|
|
69
69
|
assert.ok(!calls[1].includes('把这句话原样回复给我'), '汇报里只给路径和开头,不塞任务书的正文');
|
|
70
70
|
// 任务书是路由写的小节,带着来源、权限和回执要求
|
|
71
|
-
assert.match(s.task('t-000001'), /^# 任务书 t-000001\n\n- 来源:message(云之家,\d\d-\d\d \d\d:\d\d)· 原话:「记一下:刚和测试对完导出边界」\n- 派给:执行者 · 权限 edit ·
|
|
71
|
+
assert.match(s.task('t-000001'), /^# 任务书 t-000001\n\n- 来源:message(云之家,\d\d-\d\d \d\d:\d\d)· 原话:「记一下:刚和测试对完导出边界」\n- 派给:执行者 · 权限 edit · 不限时\n- 续做自:无\n\n## 要求\n\n# 任务:转述\n\n把这句话原样回复给我:「记一下:刚和测试对完导出边界」\n\n## 回执\n\n做完把结果写到 `\.agents\/handoff\/t-000001\.result\.md`:[\s\S]*没有写权限就把同样内容作为最后一段话输出。[\s\S]*\n$/);
|
|
72
72
|
// 执行者的提示词只有一句话,内容都在任务书里
|
|
73
73
|
const workerCalls = read(s.env.STUB_AGENT_ALL).split('\n').filter((l) => l.startsWith('读 .agents/handoff/'));
|
|
74
74
|
assert.deepEqual(workerCalls, ['读 .agents/handoff/t-000001.md(任务书),照它做完,把回执写到 .agents/handoff/t-000001.result.md;没有写权限就把回执作为你最后一段话输出。不要向我提问,不要等待确认,不要自己发消息。']);
|
|
@@ -188,7 +188,7 @@ test('续做与叫停:continue 接着原来那个执行者的会话、排在
|
|
|
188
188
|
assert.equal(cont.decision, 'continue');
|
|
189
189
|
assert.equal(cont.of, 't-000001');
|
|
190
190
|
assert.equal(cont.worker.status, 'ok');
|
|
191
|
-
assert.match(s.task('t-000002'), /^# 任务书 t-000002\n\n- 来源:message(云之家,[^)]*)· 原话:「刚才那条,项目改成导出改造」\n- 派给:执行者 · 权限 edit ·
|
|
191
|
+
assert.match(s.task('t-000002'), /^# 任务书 t-000002\n\n- 来源:message(云之家,[^)]*)· 原话:「刚才那条,项目改成导出改造」\n- 派给:执行者 · 权限 edit · 不限时\n- 续做自:t-000001\n\n## 要求\n\n接着 t-000001 那件事做。旧任务书在 \.agents\/handoff\/t-000001\.md,旧回执在 \.agents\/handoff\/t-000001\.result\.md,先读它们。\n\n用户追加:「刚才那条,项目改成导出改造」\n/);
|
|
192
192
|
// 续做的执行者接着原来那个的会话(假的 zcode 每次回 sess_fake),并且排在它做完之后
|
|
193
193
|
const workerCalls = read(s.env.STUB_ZCODE_ALL).split('\n').filter((l) => l.includes(' 读 .agents/handoff/'));
|
|
194
194
|
assert.equal(workerCalls.length, 2);
|
|
@@ -278,7 +278,7 @@ test('服务里:到点的任务变成触发走路由,推送带页面地址
|
|
|
278
278
|
assert.equal(sent, `做了:每日工作计划\n\n→ 今天的文件:http://127.0.0.1:${port}/day/${today}`);
|
|
279
279
|
// 任务书就是指令文件的全文,后面带着回执要求;路由没写任务书(定时任务默认照指令跑)
|
|
280
280
|
const task = s.task('t-000001');
|
|
281
|
-
assert.match(task, /^# 任务书 t-000001\n\n- 来源:schedule(到点 [^)]*)· 任务:daily-plan(tasks\/daily-plan\.md)\n- 派给:执行者 · 权限 edit ·
|
|
281
|
+
assert.match(task, /^# 任务书 t-000001\n\n- 来源:schedule(到点 [^)]*)· 任务:daily-plan(tasks\/daily-plan\.md)\n- 派给:执行者 · 权限 edit · 不限时\n/);
|
|
282
282
|
assert.match(task, /## 要求\n\n你是我的个人工作助理。[\s\S]*任务:每日工作计划。[\s\S]*(这次运行由 work-rhythm rhythm 发起:你最后写的那段总结写进回执[\s\S]*## 回执\n/);
|
|
283
283
|
assert.match(proc.text(), /引擎开始 路由=dsh 执行者=dsh 并发=3/);
|
|
284
284
|
// 监控中心:页面和 JSON
|
|
@@ -518,7 +518,7 @@ test('路由模式插话:有执行者在跑时新来的话立刻回「收到
|
|
|
518
518
|
write(reply, '决定:\n- t-000002 interrupt t-000001\n');
|
|
519
519
|
eng.message({ msgId: 'm2', content: '等等,项目名改成导出改造' });
|
|
520
520
|
await wait(300);
|
|
521
|
-
assert.deepEqual(hook.contents(), ['收到,正在处理,稍等。',
|
|
521
|
+
assert.deepEqual(hook.contents(), ['收到,正在处理,稍等。', '收到,正在处理,稍等。'], '执行者还在跑,这句的「收到」立刻到');
|
|
522
522
|
assert.ok(await eng.waitIdle(30000), '没等到做完');
|
|
523
523
|
const st = svc.store.data.triggers;
|
|
524
524
|
assert.equal(st['t-000001'].worker.status, 'stopped');
|
|
@@ -528,7 +528,7 @@ test('路由模式插话:有执行者在跑时新来的话立刻回「收到
|
|
|
528
528
|
assert.equal(st['t-000002'].title, '任务:转述(插话)');
|
|
529
529
|
assert.equal(st['t-000002'].worker.status, 'ok');
|
|
530
530
|
assert.equal(st['t-000002'].worker.sessionId, 'session_fake', '接着被停那次的会话跑');
|
|
531
|
-
assert.match(s.task('t-000002'), /^# 任务书 t-000002\n\n- 来源:message(云之家,[^)]*)· 原话:「等等,项目名改成导出改造」\n- 派给:执行者 · 权限 edit ·
|
|
531
|
+
assert.match(s.task('t-000002'), /^# 任务书 t-000002\n\n- 来源:message(云之家,[^)]*)· 原话:「等等,项目名改成导出改造」\n- 派给:执行者 · 权限 edit · 不限时\n- 续做自:t-000001\n\n## 要求\n\n接着 t-000001 那件事做,但要求变了。旧任务书在 \.agents\/handoff\/t-000001\.md,先读它;上一次做到一半被用户叫停,回执在 \.agents\/handoff\/t-000001\.result\.md。\n\n用户插话:「等等,项目名改成导出改造」\n/);
|
|
532
532
|
// 被停的那次不汇报:只有插话那次的一条汇报;也没给用户发「没做成」
|
|
533
533
|
const reports = Object.values(st).filter((x) => x.kind === 'report');
|
|
534
534
|
assert.deepEqual(reports.map((x) => x.of), ['t-000002']);
|
|
@@ -621,14 +621,14 @@ test('采集之后:有新数据就起一轮提炼,新增的事件打包成 e
|
|
|
621
621
|
assert.match(s.routerCalls()[0], /\n触发:\n\[t-000001\] 来源=events 时间=\d\d-\d\d \d\d:\d\d 新事件 0 条;这次采集:im-yzj 失败:errorCode 10000429$/);
|
|
622
622
|
// 派出去的任务书是固定的那份(路由没写任务书),带着采集故障
|
|
623
623
|
// 任务书用的是这条触发自己的短号
|
|
624
|
-
assert.match(s.task('t-000001'), /^# 任务书 t-000001\n\n- 来源:events([^)]*)· 定时采集之后新到的一批事件\n- 派给:执行者 · 权限 edit ·
|
|
624
|
+
assert.match(s.task('t-000001'), /^# 任务书 t-000001\n\n- 来源:events([^)]*)· 定时采集之后新到的一批事件\n- 派给:执行者 · 权限 edit · 不限时\n- 续做自:无\n\n## 要求\n\n# 任务:根据新到的事件更新今日重点和待办\n\n今天新到的事件(0 条):\n(没有新事件)\n\n这次采集有源没取到数据(回执里说清,涉及的事标「未取到」):im-yzj:errorCode 10000429\n\n1\. 读今天每日文件(\S+\/02-daily\/\d{4}-\d{2}\/\d{4}-\d{2}-\d{2}\.md)的「## 计划」/);
|
|
625
625
|
// 有新数据:起一轮提炼(假的执行者往今天的事件流里加两条),CLI 比出新增的两条,打包给路由
|
|
626
626
|
const date = todayStr();
|
|
627
627
|
const r = await eng.afterSync({ results: [{ id: 'calendar-yzj', ok: true, code: 3, seconds: 3, detail: '' }], changed: true });
|
|
628
628
|
assert.ok(r && r.ok, JSON.stringify(r));
|
|
629
629
|
const refine = Object.values(triggers()).find((x) => x.kind === 'refine');
|
|
630
630
|
assert.deepEqual([refine.decision, refine.title, refine.worker.status, refine.worker.mode], ['refine', '把今天新采到的数据提炼成事件', 'ok', 'edit']);
|
|
631
|
-
assert.match(s.task(refine.id), /^# 任务书 t-000003\n\n- 来源:refine([^)]*)· 定时采集之后提炼新数据\n- 派给:执行者 · 权限 edit ·
|
|
631
|
+
assert.match(s.task(refine.id), /^# 任务书 t-000003\n\n- 来源:refine([^)]*)· 定时采集之后提炼新数据\n- 派给:执行者 · 权限 edit · 不限时\n- 续做自:无\n\n## 要求\n\n# 任务:把今天新采到的数据提炼成事件\n\n1\. 读 00-config\/sources\.yaml[\s\S]*4\. 合并进今天每日文件(\S+\/02-daily\/\d{4}-\d{2}\/\d{4}-\d{2}-\d{2}\.md)的「## 事件流」/);
|
|
632
632
|
assert.deepEqual(engineLib.dayEvents(s.box.work, date).map((e) => `${e.date} ${e.time} ${e.type} ${e.item} ${e.source} ${e.project}`), [`${date} 09:00 会议 需求评审 calendar-yzj 导出`, `${date} 10:30 沟通 和测试对完导出边界 im-yzj 导出`]);
|
|
633
633
|
assert.ok(await eng.waitIdle(30000));
|
|
634
634
|
const ev = Object.values(triggers()).find((x) => x.kind === 'events' && x.of === refine.id);
|
|
@@ -847,3 +847,72 @@ test('今日页「待你定」实时更新:页面点选项后记入卡片与 D
|
|
|
847
847
|
assert.equal(JSON.parse(read(`${s.box.work}/01-inbox/_rhythm/asks/${ownId}.json`)).answer.choice, ownWords);
|
|
848
848
|
assert.match(read(file), new RegExp(`\\| 导出边界怎么处理 \\| ①发上游 ②周会提 \\| ${ownWords} \\|`));
|
|
849
849
|
});
|
|
850
|
+
|
|
851
|
+
test('IM 连发防抖合批:短时间内连发两句合成一条 message 触发,只进一轮路由、回一次', async (t) => {
|
|
852
|
+
const s = setup(t);
|
|
853
|
+
s.routerOn();
|
|
854
|
+
s.bind(`YZJ_BOT_AGENT="${CUSTOM(s.box)}"\n`);
|
|
855
|
+
const svc = s.service({ YZJ_BOT_DEBOUNCE: '1' });
|
|
856
|
+
const eng = svc.makeEngine();
|
|
857
|
+
const sent = [];
|
|
858
|
+
eng.setSink((text) => sent.push(text));
|
|
859
|
+
eng.message({ msgId: 'd1', content: '有没有什么体验比较好的办法?' });
|
|
860
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
861
|
+
eng.message({ msgId: 'd2', content: '过程中就开始识别并且过滤?' });
|
|
862
|
+
// 防抖窗口还没到,触发还没入队
|
|
863
|
+
assert.equal(Object.keys(svc.store.data.triggers).length, 0);
|
|
864
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
865
|
+
assert.ok(await eng.waitIdle(20000));
|
|
866
|
+
const msgs = Object.values(svc.store.data.triggers).filter((x) => x.kind === 'message');
|
|
867
|
+
assert.equal(msgs.length, 1, '两句合成了一条触发');
|
|
868
|
+
assert.match(s.task(msgs[0].id), /有没有什么体验比较好的办法?\n过程中就开始识别并且过滤?/);
|
|
869
|
+
assert.equal(sent.filter((x) => !x.startsWith('收到')).length, 1, '只回了一次');
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
test('工作区扫描、登记与跨 ws 路由:路由看到候选工作区并选 ws=<id>,执行者在目标目录跑,进度提示带工作区', async (t) => {
|
|
873
|
+
const s = setup(t);
|
|
874
|
+
s.routerOn();
|
|
875
|
+
s.bind(`YZJ_BOT_AGENT="${CUSTOM(s.box)}"\n`);
|
|
876
|
+
const baseDir = path.dirname(s.box.work);
|
|
877
|
+
const repoDir = path.join(baseDir, 'demo-repo');
|
|
878
|
+
fs.mkdirSync(path.join(repoDir, '.git'), { recursive: true });
|
|
879
|
+
// workspace scan 能扫到候选,add / list / remove 正常
|
|
880
|
+
const scan = s.run(['workspace', 'scan', '--json'], { WRJ_WS_SCAN_DIRS: baseDir });
|
|
881
|
+
assert.equal(scan.code, 0, scan.out);
|
|
882
|
+
assert.ok(JSON.parse(scan.stdout).scanned.some((w) => w.id === 'demo-repo'));
|
|
883
|
+
assert.equal(s.run(['workspace', 'add', 'demo-repo', repoDir, '--note', '示例仓库']).code, 0);
|
|
884
|
+
assert.match(s.run(['workspace', 'list']).stdout, /demo-repo\t.*demo-repo\t\t示例仓库/);
|
|
885
|
+
// parseRouterReply 认 ws=
|
|
886
|
+
const parsed = parseRouterReply('决定:\n- t-000001 dispatch ws=demo-repo\n\n## handoff t-000001\n# 任务:查仓库\n\n检查仓库。\n');
|
|
887
|
+
assert.equal(parsed[0].ws, 'demo-repo');
|
|
888
|
+
// 跑一轮:路由提示词里带着 demo-repo,选了 ws=demo-repo 后执行者记录 ws 且进度提示带工作区
|
|
889
|
+
const reply = `${baseDir}/ws-reply.txt`;
|
|
890
|
+
write(reply, '决定:\n- t-000001 dispatch ws=demo-repo\n\n## handoff t-000001\n# 任务:查仓库\n\n把这句话原样回复给我:「在 demo-repo 里跑完了」\n');
|
|
891
|
+
const svc = s.service({ STUB_ROUTER_REPLY: reply, WRJ_WS_SCAN_DIRS: baseDir, YZJ_BOT_PROGRESS: '1', STUB_WORKER_DELAY: '2' });
|
|
892
|
+
const eng = svc.makeEngine();
|
|
893
|
+
const sent = [];
|
|
894
|
+
eng.setSink((text) => sent.push(text));
|
|
895
|
+
eng.message({ msgId: 'w1', content: '去 demo-repo 查一下' });
|
|
896
|
+
assert.ok(await eng.waitIdle(20000));
|
|
897
|
+
assert.match(s.routerCalls()[0], /可用工作区[\s\S]*demo-repo(已登记/);
|
|
898
|
+
const trig = svc.store.data.triggers['t-000001'];
|
|
899
|
+
assert.equal(trig.ws, 'demo-repo');
|
|
900
|
+
assert.equal(trig.worker.ws, 'demo-repo');
|
|
901
|
+
assert.ok(sent.some((x) => x.includes('工作区 demo-repo')), `进度提示应带工作区,实际:${JSON.stringify(sent)}`);
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
test('并发任务进度汇总:同时跑 2 个执行者时,进度提示合成一条消息,不刷屏', async (t) => {
|
|
905
|
+
const s = setup(t);
|
|
906
|
+
s.routerOn();
|
|
907
|
+
s.bind(`YZJ_BOT_AGENT="${CUSTOM(s.box)}"\n`);
|
|
908
|
+
const svc = s.service({ YZJ_BOT_PROGRESS: '1', YZJ_BOT_PROGRESS_MAX: '1', STUB_WORKER_DELAY: '2' });
|
|
909
|
+
const eng = svc.makeEngine();
|
|
910
|
+
const sent = [];
|
|
911
|
+
eng.setSink((text) => sent.push(text));
|
|
912
|
+
eng.message({ msgId: 'p1', content: '第一件事' });
|
|
913
|
+
eng.message({ msgId: 'p2', content: '第二件事' });
|
|
914
|
+
assert.ok(await eng.waitIdle(20000));
|
|
915
|
+
const summary = sent.filter((x) => x.startsWith('手头有 2 件事还在做'));
|
|
916
|
+
assert.equal(summary.length, 1, `应汇总成 1 条进度消息,实际:${JSON.stringify(sent)}`);
|
|
917
|
+
assert.match(summary[0], /1\. \[工作区 工作目录\][\s\S]*2\. \[工作区 工作目录\]/);
|
|
918
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
你是我的个人工作助理。当前工作目录就是我的个人工作目录,流程以 AGENTS.md 为准,
|
|
2
|
+
文件格式以 docs/formats.md 为准。这次是无人值守的定时运行:不要向我提问,不要等待确认;
|
|
3
|
+
遇到数据取不到、命令失败,就如实注明并继续,把结果写进文件后结束。
|
|
4
|
+
|
|
5
|
+
任务:每日归档与个人分身更新。收尾当天记录,把今天沉淀出的工作习惯、决策风格和角色变化更新到个人分身档案里。
|
|
6
|
+
1. 运行 work-rhythm today。IS_WORKDAY 为 0 时直接结束,不写任何文件。
|
|
7
|
+
2. 归档收尾:
|
|
8
|
+
- 运行 work-rhythm decisions archive,归档已落实或过期的老决定。
|
|
9
|
+
- 读 03-carryover/CARRYOVER.md,把已明确完结或失效的条目清理/归档到「已完成」区域,保持未了结列表干净。
|
|
10
|
+
3. 收集今天的分身信号:
|
|
11
|
+
- 读今天及最近 2 个工作日的每日文件(事件流、复盘、备注)。
|
|
12
|
+
- 运行 work-rhythm decisions list 7,看最近 7 天我亲自拍板的决定和理由(「未答」「过期未答」不算决定)。
|
|
13
|
+
- 读 00-config/profile.yaml、04-patterns/WORK_RHYTHM.md 和 04-patterns/PERSONA.md(不存在就新建)。
|
|
14
|
+
4. 增量更新 04-patterns/PERSONA.md(个人分身档案,供所有 agent 干活前快速对齐「我是谁、我怎么做事」):
|
|
15
|
+
- 分五节维护:角色与职责边界、决策原则与风格、沟通与表达偏好、工作习惯与节奏、近期核心关注点。
|
|
16
|
+
- 只写有证据支撑的内容,每条新沉淀注明日期;推测性的判断标「?」。不要编造,也不要删掉仍然有效的旧条目。
|
|
17
|
+
- 如有新的工作习惯线索,同步增量补充到 04-patterns/WORK_RHYTHM.md 的「做事的习惯」。
|
|
18
|
+
5. 检查角色身份变化:
|
|
19
|
+
- 对照 00-config/profile.yaml 里的角色、项目和偏好;**不要直接修改 profile.yaml**。
|
|
20
|
+
- 如果今天有明确信号表明角色职责或常驻项目发生了变化,用 `work-rhythm ask --json '…'` 丢一张确认卡,等我拍板后再改。
|
|
21
|
+
6. 最后一步,写完文件之后:用三行以内的纯文本写下今天归档了什么、分身档案更新了哪几条、有没有需要我确认的卡。
|
|
22
|
+
这是发给人类看的,务必简洁明了、直说结论,不用表格、不放链接,不要提内部细节。
|
|
23
|
+
如果指令的末尾没有人注明「会替你推送」,就把这段话经管道交给 `work-rhythm notify -` 自己发出去。
|
|
@@ -42,6 +42,7 @@ schedule: # 标准定时任务的时间,定义见 docs/schedul
|
|
|
42
42
|
noon-checkin: "12:30"
|
|
43
43
|
evening-review: "17:30" # 下班前 15 分钟
|
|
44
44
|
carryover: "17:40" # 遗留的输入是复盘的结论,紧随其后
|
|
45
|
+
daily-persona: "18:30" # 每日归档、整理工作习惯与个人分身档案(04-patterns/PERSONA.md)
|
|
45
46
|
weekly-rhythm: "Fri 16:30"
|
|
46
47
|
# 待决的事不做定时巡查:推送里会提醒有几件等我定,我对任何一个能读到这个工作目录的 agent 说「有什么要我定」就开始逐件问
|
|
47
48
|
|