work-rhythm 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/notes/AGENTS.md +4 -1
- package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md +1 -0
- package/.agents/notes/decisions/2026-11-30-no-workdir-offers-to-create-one-by-default.md +1 -0
- package/.agents/notes/decisions/2026-11-30-scheduling-moves-to-a-local-service.md +1 -0
- package/.agents/notes/decisions/2026-12-01-everything-is-js-behind-work-rhythm.md +1 -0
- package/.agents/notes/decisions/2026-12-01-repo-is-not-a-workdir-templates-hold-workdir-files.md +29 -0
- package/.agents/notes/decisions/2026-12-01-repo-stays-generic-personal-data-lives-in-workdirs.md +32 -0
- package/.agents/notes/decisions/2026-12-01-scheduling-is-cli-only-and-needs-a-bound-agent.md +31 -0
- package/.agents/notes/decisions/2026-12-01-workdir-is-not-a-git-repository.md +25 -0
- package/.agents/skills/work-rhythm/SKILL.md +16 -13
- package/AGENTS.md +12 -24
- package/README.md +35 -70
- package/collectors/local.env.example +5 -3
- package/docs/agents.md +49 -0
- package/docs/channels.md +2 -2
- package/docs/formats.md +1 -1
- package/docs/scheduled-tasks.md +2 -12
- package/package.json +2 -4
- package/scripts/cli.js +9 -5
- package/scripts/cmd/agent.js +110 -0
- package/scripts/cmd/check.js +90 -43
- package/scripts/cmd/init.js +3 -7
- package/scripts/cmd/pack.js +1 -2
- package/scripts/lib/agent.js +156 -17
- package/scripts/lib/bot.js +1 -1
- package/scripts/lib/log.js +1 -1
- package/scripts/lib/rhythm.js +1 -1
- package/scripts/lib/template.js +31 -26
- package/scripts/lib/workdir.js +13 -4
- package/scripts/test/agent.test.js +199 -0
- package/scripts/test/check.test.js +94 -10
- package/scripts/test/config.test.js +6 -9
- package/scripts/test/goals.test.js +1 -1
- package/scripts/test/harness.js +7 -6
- package/scripts/test/init.test.js +9 -11
- package/scripts/test/listen.test.js +2 -2
- package/scripts/test/pack.test.js +1 -1
- package/scripts/test/rhythm.test.js +13 -4
- package/scripts/test/stubs.js +19 -1
- package/scripts/test/workdir.test.js +2 -2
- package/{00-config → templates/00-config}/profile.example.yaml +0 -1
- package/{00-config → templates/00-config}/sources.yaml +8 -8
- package/templates/AGENTS.md +31 -0
- package/templates/README.md +73 -0
package/docs/scheduled-tasks.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 定时任务
|
|
2
2
|
|
|
3
|
-
运转的中心是本地服务 `work-rhythm rhythm`:到点采集,到点把任务交给 agent
|
|
3
|
+
运转的中心是本地服务 `work-rhythm rhythm`:到点采集,到点把任务交给 agent 跑一遍,跑完经消息渠道把总结推给我,再在本机起一个网页服务给我看页面。定时任务只建在这个服务上,不建在 agent 运行时自带的调度器上;换运行时也不用重建。服务要先绑一个 agent(`work-rhythm agent bind`,见 [agents.md](agents.md)),没绑就不起。Markdown 仍是唯一的记录,任务写的东西都在每日文件和那几个固定文件里;页面只是同一份内容的视图。
|
|
4
4
|
|
|
5
5
|
长期目标不单独占任务:每日工作计划负责提醒到期的检查、安排当天的一个最小动作,晚间工作复盘负责收集进展。目标文件的格式见 [formats.md](formats.md) 的「长期目标」。
|
|
6
6
|
|
|
@@ -95,21 +95,11 @@ work-rhythm rhythm install # macOS:装成常驻(开机自启、挂了拉
|
|
|
95
95
|
|
|
96
96
|
在云之家里做这件事,需要值守的 agent 有写权限(`YZJ_BOT_AGENT_MODE=edit`),不然它只能问、不能记录。
|
|
97
97
|
|
|
98
|
-
## 备选:绑到 agent 运行时的调度器
|
|
99
|
-
|
|
100
|
-
跑不了本地服务的时候(机器上没有 node 22、或者不方便常驻),可以把任务绑到 agent 运行时自带的调度器上:指令用 `tasks/<id>.md` 的全文,推送由任务最后一步自己调用 `work-rhythm notify -` 完成。
|
|
101
|
-
|
|
102
|
-
- **ZCode**:用 `CronCreate`。先用 `CronList` 查重;时间换算成 5 字段的 cron(`08:20` 工作日是 `20 8 * * 1-5`);prompt 用任务文件的全文,占位符 `<DATE>` 这类保持原样;创建前把任务名、时间给我看;建好把任务名记到 `profile.yaml` 的 `automations` 里。
|
|
103
|
-
- **DSH**:`schedule_create` 落在会话的工作目录,做法相同。
|
|
104
|
-
- 定时任务绑定在创建它的会话所在的工作区,所以必须站在 WORKDIR 里创建。
|
|
105
|
-
|
|
106
|
-
两条路只能开一条:两边同时开会重复写文件、重复推送。
|
|
107
|
-
|
|
108
98
|
## 已知限制
|
|
109
99
|
|
|
110
100
|
- 任务是一次完整的 agent 运行,推送到得比任务时间晚:`deepseek-v4.1-flash` 下每日计划约一分半。
|
|
111
101
|
- 调度器只认星期和 `work-rhythm today` 的判断:调休上班的日子加进 `workdays`,放假的日子加进 `holidays`,每年更新一次。
|
|
112
|
-
- agent 要能在工作目录里读写文件、跑脚本;`dsh` 用 `workspace-write`,`zcode` 用 `edit
|
|
102
|
+
- agent 要能在工作目录里读写文件、跑脚本;`dsh` 用 `workspace-write`,`zcode` 用 `edit`,各家见 [agents.md](agents.md)。
|
|
113
103
|
- 网页服务只在本机的浏览器里看得见。
|
|
114
104
|
- 复盘里并着遗留整理,所以它比别的任务长。
|
|
115
105
|
- 服务只在 macOS 上能装成常驻(launchd);别的系统把 `work-rhythm rhythm start` 交给 systemd 之类。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "work-rhythm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "个人工作目录:记录每天的工作事件、按订阅源采集数据、做计划和复盘;带本地服务(定时采集、定时整理、经消息渠道推送、本机网页)",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -25,9 +25,7 @@
|
|
|
25
25
|
".agents",
|
|
26
26
|
"AGENTS.md",
|
|
27
27
|
"README.md",
|
|
28
|
-
"templates"
|
|
29
|
-
"00-config/profile.example.yaml",
|
|
30
|
-
"00-config/sources.yaml"
|
|
28
|
+
"templates"
|
|
31
29
|
],
|
|
32
30
|
"keywords": [
|
|
33
31
|
"work",
|
package/scripts/cli.js
CHANGED
|
@@ -23,8 +23,9 @@ const COMMANDS = {
|
|
|
23
23
|
check: 'check 改完脚本、配置或文档后跑一遍:语法、内链、预算、配置、密钥、笔记',
|
|
24
24
|
listen: 'listen probe|run|handle|handle-frame|reset|doctor|install|uninstall|status 值守:收我在 IM 里说的话,交给本地 agent 回复',
|
|
25
25
|
rhythm: 'rhythm start|stop|status|due|run|serve|render|doctor|install|uninstall 本地服务:定时采集、定时整理、推送、网页',
|
|
26
|
+
agent: 'agent [bind [名字]|test|doctor] 定时任务和机器人值守用哪个 agent:检测本机的、绑定、试一句',
|
|
26
27
|
workdir: 'workdir [register|find|config|blank] 工作目录在哪:找、登记、扫描本机;不带子命令是找',
|
|
27
|
-
init: 'init <目录>
|
|
28
|
+
init: 'init <目录> 新建一个工作目录(空白模板、登记)',
|
|
28
29
|
pack: 'pack [--out <目录>] 把 skill 和这个包打成可分发的目录',
|
|
29
30
|
selftest: 'selftest [--test-name-pattern=…] 自测:跑一遍 scripts/test/ 下的用例',
|
|
30
31
|
};
|
|
@@ -76,11 +77,14 @@ async function main(argv) {
|
|
|
76
77
|
stderr.write(`work-rhythm: 不认识的子命令「${name}」\n\n${usage()}\n`);
|
|
77
78
|
return EXIT.USAGE;
|
|
78
79
|
}
|
|
79
|
-
// 作用在哪个目录:--workdir
|
|
80
|
-
const found = resolveRoot({ cwd: process.cwd(), option: rootOption, env: process.env });
|
|
80
|
+
// 作用在哪个目录:--workdir 指定的,或从当前目录往上找;站在这个包自己的仓库里就是仓库(只有 check 查它);最后看用户级的登记
|
|
81
|
+
const found = resolveRoot({ cwd: process.cwd(), option: rootOption, env: process.env, packageRoot: PACKAGE_ROOT });
|
|
81
82
|
const ctx = { root: found.root, rootSource: found.source, cwd: process.cwd(), stdin: process.stdin, stdout, stderr, env: process.env, packageRoot: PACKAGE_ROOT };
|
|
82
|
-
if (NEED_ROOT.has(name) && !found.root) {
|
|
83
|
-
|
|
83
|
+
if (NEED_ROOT.has(name) && (!found.root || (found.source === 'package' && name !== 'check'))) {
|
|
84
|
+
const why = found.source === 'package'
|
|
85
|
+
? '这里是 work-rhythm 自己的仓库,不是工作目录'
|
|
86
|
+
: `往上找不到 00-config/profile.yaml${found.problem ? `;${found.problem}` : ',也没有登记'}`;
|
|
87
|
+
stderr.write(`work-rhythm ${name}: 当前目录不是工作目录(${why});用 --workdir 指定,或先用 work-rhythm init 新建\n`);
|
|
84
88
|
return EXIT.NOT_CONFIGURED;
|
|
85
89
|
}
|
|
86
90
|
try {
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// work-rhythm agent:定时任务和机器人值守都要一个 agent 来跑,这里管「用哪个」。
|
|
2
|
+
// 用法: work-rhythm agent 看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个
|
|
3
|
+
// work-rhythm agent bind <名字|命令> 绑定:写进 collectors/local.env 的 YZJ_BOT_AGENT。不给名字就用正在调的这个,没有就装了的第一个
|
|
4
|
+
// work-rhythm agent test ["一句话"] 让绑定的 agent 答一句,看模型和凭据通不通(默认「你好,用一句话介绍你自己」)
|
|
5
|
+
// work-rhythm agent doctor 绑定的 agent 配置和依赖有没有问题
|
|
6
|
+
// work-rhythm agent --json detect 的结果打成 JSON,给 agent 读
|
|
7
|
+
// 预置:zcode(ZCode 自带的命令行)、dsh(DSH 的 headless 模式)、qoder(Qoder CLI)、claude(Claude Code);其余值当成一条自己的命令。
|
|
8
|
+
// 「正在调这个 skill 的是哪个」看的是它给工具留的环境变量:ZCODE_*、DSH_SESSION_ID、QODER_*、CLAUDECODE / CLAUDE_CODE_*。
|
|
9
|
+
// 没绑 agent 就没有定时任务(rhythm 拒绝起)和机器人响应(listen 拒绝跑)。各家的调用方式和权限见 docs/agents.md
|
|
10
|
+
'use strict';
|
|
11
|
+
const fs = require('node:fs');
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
const { EXIT, Fail, UsageError } = require('../lib/run');
|
|
14
|
+
const { settings } = require('../lib/config');
|
|
15
|
+
const { PRESETS, PRESET_NAMES, invokingAgent, installedAgents, bindAgent, createAgent } = require('../lib/agent');
|
|
16
|
+
|
|
17
|
+
const USAGE = `用法: work-rhythm agent [子命令]
|
|
18
|
+
看本机装了哪些、现在是不是有 agent 正在调这个 skill、现在绑的是哪个(--json 打成 JSON)
|
|
19
|
+
bind [名字|命令] 绑定,写进 collectors/local.env 的 YZJ_BOT_AGENT;不给名字就用正在调的这个,没有就装了的第一个
|
|
20
|
+
test ["一句话"] 让绑定的 agent 答一句
|
|
21
|
+
doctor 绑定的 agent 配置和依赖有没有问题
|
|
22
|
+
预置:${PRESET_NAMES.join('、')};其余值当成一条自己的命令`;
|
|
23
|
+
|
|
24
|
+
function binding(root, env) {
|
|
25
|
+
return (settings(root, env).YZJ_BOT_AGENT || '').trim();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 建议绑哪个:正在调这个 skill 的那个(它装了的话);否则装了的第一个;都没有就空
|
|
29
|
+
function suggest(list) {
|
|
30
|
+
const invoking = list.find((a) => a.invoking && a.found);
|
|
31
|
+
if (invoking) return invoking.name;
|
|
32
|
+
const first = list.find((a) => a.found);
|
|
33
|
+
return first ? first.name : '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
usage: USAGE,
|
|
38
|
+
async run(args, ctx) {
|
|
39
|
+
const { root, stdout, stderr, env } = ctx;
|
|
40
|
+
const list = installedAgents(env);
|
|
41
|
+
const json = args.includes('--json');
|
|
42
|
+
const rest = args.filter((a) => a !== '--json');
|
|
43
|
+
const [verb, ...params] = rest;
|
|
44
|
+
const bound = binding(root, env);
|
|
45
|
+
|
|
46
|
+
switch (verb) {
|
|
47
|
+
case undefined: {
|
|
48
|
+
if (params.length) throw new UsageError(USAGE);
|
|
49
|
+
const invoking = invokingAgent(env);
|
|
50
|
+
const pick = suggest(list);
|
|
51
|
+
const report = {
|
|
52
|
+
invoking,
|
|
53
|
+
invokingFound: invoking ? list.find((a) => a.name === invoking).found : false,
|
|
54
|
+
bound: presetKindOf(bound),
|
|
55
|
+
boundValue: bound,
|
|
56
|
+
suggest: pick,
|
|
57
|
+
agents: list.map((a) => ({ name: a.name, label: a.label, found: a.found, command: a.command, problem: a.problem || undefined, invoking: a.invoking })),
|
|
58
|
+
};
|
|
59
|
+
if (json) {
|
|
60
|
+
stdout.write(`${JSON.stringify(report, null, 1)}\n`);
|
|
61
|
+
return EXIT.OK;
|
|
62
|
+
}
|
|
63
|
+
stdout.write('本机的 agent:\n');
|
|
64
|
+
for (const a of list) {
|
|
65
|
+
const how = a.found ? a.command : `没装:${a.problem}`;
|
|
66
|
+
stdout.write(` ${a.name.padEnd(7)}${a.found ? '装了' : '没装'} ${a.label}${a.invoking ? ' ← 现在是它在调这个 skill' : ''}\n ${how}\n`);
|
|
67
|
+
}
|
|
68
|
+
stdout.write(`正在调这个 skill 的:${invoking || '认不出来(不是从 agent 的工具里跑的,或者它不留标记)'}\n`);
|
|
69
|
+
stdout.write(`现在绑定的:${bound || '没绑'}${bound && presetKindOf(bound) === 'custom' ? `(一条自定义命令,${PRESET_NAMES.join('/')} 以外)` : ''}\n`);
|
|
70
|
+
if (!bound) stdout.write(`没绑 agent 就没有定时任务,也不支持机器人响应。${pick ? `建议:work-rhythm agent bind ${pick}` : '本机一个预置的 agent 都没装,先装一个(docs/agents.md)'}\n`);
|
|
71
|
+
return EXIT.OK;
|
|
72
|
+
}
|
|
73
|
+
case 'bind': {
|
|
74
|
+
if (params.length > 1) throw new UsageError(USAGE);
|
|
75
|
+
const name = params[0] || suggest(list);
|
|
76
|
+
if (!name) throw new Fail(EXIT.NOT_CONFIGURED, '本机没找到能用的 agent,也没指定要绑的命令:装一个预置的(docs/agents.md),或者 work-rhythm agent bind "<一条命令>"');
|
|
77
|
+
const r = bindAgent(root, env, name);
|
|
78
|
+
if (r.problems) throw new Fail(EXIT.NOT_CONFIGURED, `绑不了 ${name}:${r.problems.join(';')}`);
|
|
79
|
+
stdout.write(`已绑定 ${name}${r.kind === 'custom' ? '(一条自定义命令)' : `(${PRESETS[r.kind].label})`},写进了 ${path.relative(root, r.file)} 的 YZJ_BOT_AGENT。\n`);
|
|
80
|
+
stdout.write(`下一步:work-rhythm agent test 让它答一句;定时任务用 work-rhythm rhythm doctor 查配置,机器人值守用 work-rhythm listen doctor。\n`);
|
|
81
|
+
return EXIT.OK;
|
|
82
|
+
}
|
|
83
|
+
case 'test': {
|
|
84
|
+
if (params.length > 1) throw new UsageError(USAGE);
|
|
85
|
+
if (!bound) throw new Fail(EXIT.NOT_CONFIGURED, '还没绑 agent:work-rhythm agent detect 看本机有哪些,work-rhythm agent bind <名字> 绑定');
|
|
86
|
+
const started = Date.now();
|
|
87
|
+
// 只读模式跑一句;会话落在 01-inbox/_agent/ 下,不碰值守和定时任务各自的专属会话
|
|
88
|
+
const agent = createAgent({ root, agent: bound, mode: 'plan', timeoutS: 180, env: settings(root, env), log: (event, fields) => stderr.write(`${event} ${fields}\n`) });
|
|
89
|
+
const r = agent.run(params[0] || '你好,用一句话介绍你自己,并说出你用的是哪个模型。', { stateDir: path.join(root, '01-inbox', '_agent') });
|
|
90
|
+
if (r.config) throw new Fail(EXIT.NOT_CONFIGURED, r.failed);
|
|
91
|
+
if (r.failed) throw new Fail(EXIT.FAILED, `没答上来:${r.failed}`);
|
|
92
|
+
stdout.write(`${r.reply.trim()}\n(${bound},只读模式,用时 ${Math.round((Date.now() - started) / 1000)} 秒)\n`);
|
|
93
|
+
return EXIT.OK;
|
|
94
|
+
}
|
|
95
|
+
case 'doctor': {
|
|
96
|
+
if (params.length) throw new UsageError(USAGE);
|
|
97
|
+
const problems = createAgent({ root, agent: bound, env: settings(root, env) }).doctor();
|
|
98
|
+
if (problems.length) stdout.write(`${problems.join('\n')}\n`);
|
|
99
|
+
else stdout.write(`${bound} 没有问题。\n`);
|
|
100
|
+
return problems.length ? 1 : EXIT.OK;
|
|
101
|
+
}
|
|
102
|
+
default:
|
|
103
|
+
throw new UsageError(USAGE);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
function presetKindOf(name) {
|
|
109
|
+
return PRESET_NAMES.includes(name) ? name : name ? 'custom' : '';
|
|
110
|
+
}
|
package/scripts/cmd/check.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// 改完脚本、配置或文档后跑一遍:脚本语法、文档内链、预算、配置自检、疑似密钥、笔记格式。
|
|
2
2
|
// 全部通过时退出码为 0;有未通过的项退出码为 1,每项都指出来。只读,不修改任何文件。
|
|
3
3
|
// 用法: work-rhythm check
|
|
4
|
+
// 站在工作目录里是 6 项;站在这个包自己的仓库里(它不是工作目录)换成另一套:没有「配置自检」,多「模板」和「仓库保持通用」。
|
|
4
5
|
'use strict';
|
|
5
6
|
const fs = require('node:fs');
|
|
6
7
|
const path = require('node:path');
|
|
@@ -11,10 +12,13 @@ const { notifyChannel } = require('../lib/notify');
|
|
|
11
12
|
const { hasWebhook, serviceName } = require('../lib/robot');
|
|
12
13
|
const { resolveCollector } = require('./sync');
|
|
13
14
|
const { createBot } = require('../lib/bot');
|
|
14
|
-
const
|
|
15
|
+
const launchd = require('../lib/launchd');
|
|
16
|
+
const { PRESET_NAMES } = require('../lib/agent');
|
|
17
|
+
const { loadProfile } = require('../lib/config');
|
|
18
|
+
const { GENERATED_DIRS, templateProblems } = require('../lib/template');
|
|
15
19
|
|
|
16
20
|
const SKILL_KEYS = ['name', 'description', 'when_to_use', 'license', 'metadata'];
|
|
17
|
-
const SKIP_DIRS = new Set(['.git', '01-inbox', 'node_modules']);
|
|
21
|
+
const SKIP_DIRS = new Set(['.git', '01-inbox', 'node_modules', '.zcode']);
|
|
18
22
|
// 内置采集器各要什么:tools 是 PATH 上要有的命令,var 是 local.env 里一定要有的变量(源 id 不是采集器自己的名字时加 _<ID> 后缀)
|
|
19
23
|
const NEEDS = {
|
|
20
24
|
'im-yzj': { tools: [], var: 'YZJ_GROUP_IDS' },
|
|
@@ -79,11 +83,15 @@ function checkSyntax({ root, packageRoot, say }) {
|
|
|
79
83
|
return bad;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
// 2 文档内链:相对链接指向的文件在不在。代码块里的内容是示例,不检查;别的协议(http、mailto
|
|
86
|
+
// 2 文档内链:相对链接指向的文件在不在。代码块里的内容是示例,不检查;别的协议(http、mailto…)不管。
|
|
87
|
+
// 链接都是按工作目录里的位置写的。站在工作目录里查,找不到的再到包里找(脚本不在工作目录里);
|
|
88
|
+
// 站在仓库里查,按工作目录里的位置到包里找:共用的文件在包根下,工作目录独有的在 templates/ 下。
|
|
89
|
+
// templates/ 下的文件(AGENTS.md、README.md、03-carryover/…)铺进工作目录之后才在根上,所以它们的位置先换算成工作目录里的位置
|
|
83
90
|
function checkLinks({ root, packageRoot, say }) {
|
|
84
91
|
const broken = [];
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
93
|
+
const templates = path.join(packageRoot, 'templates');
|
|
94
|
+
for (const file of walkFiles(root, SKIP_DIRS, 0)) {
|
|
87
95
|
if (!file.endsWith('.md')) continue;
|
|
88
96
|
let fenced = false;
|
|
89
97
|
for (const line of readText(file).split('\n')) {
|
|
@@ -95,10 +103,22 @@ function checkLinks({ root, packageRoot, say }) {
|
|
|
95
103
|
for (const m of line.matchAll(/\]\(([^)]+)\)/g)) {
|
|
96
104
|
const link = m[1].trim().replace(/\s+"[^"]*"$/, '').replace(/#.*$/, '');
|
|
97
105
|
if (!link || /^[a-z][a-z0-9+.-]*:/i.test(link)) continue;
|
|
98
|
-
//
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
106
|
+
// 文件在工作目录里的位置:templates/ 下的按铺开之后算
|
|
107
|
+
const placed = file.startsWith(`${templates}${path.sep}`) ? path.join(packageRoot, path.relative(templates, file)) : file;
|
|
108
|
+
const target = path.resolve(path.dirname(placed), decodeURIComponent(link));
|
|
109
|
+
const rel = path.relative(dev ? packageRoot : root, target);
|
|
110
|
+
if (rel.startsWith('..')) {
|
|
111
|
+
broken.push(`断链 ./${path.relative(root, file)} -> ${link}`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const candidates = [target, path.resolve(packageRoot, rel)];
|
|
115
|
+
if (dev) {
|
|
116
|
+
candidates.push(path.resolve(templates, rel));
|
|
117
|
+
// profile.yaml、02-daily/、05-goals/ 是 init 现生成的(见 lib/template.js),仓库里只有模板那一份或者没有
|
|
118
|
+
if (rel === '00-config/profile.yaml') candidates.push(path.resolve(templates, '00-config', 'profile.example.yaml'));
|
|
119
|
+
if (GENERATED_DIRS.includes(rel)) continue;
|
|
120
|
+
}
|
|
121
|
+
if (!candidates.some((c) => fs.existsSync(c))) broken.push(`断链 ./${path.relative(root, file)} -> ${link}`);
|
|
102
122
|
}
|
|
103
123
|
}
|
|
104
124
|
}
|
|
@@ -106,12 +126,14 @@ function checkLinks({ root, packageRoot, say }) {
|
|
|
106
126
|
return broken.length;
|
|
107
127
|
}
|
|
108
128
|
|
|
109
|
-
// 3 预算:SKILL.md 不超过 500
|
|
129
|
+
// 3 预算:SKILL.md 不超过 500 个非空行;工作目录的 AGENTS.md 不超过 60 行、standing orders 不超过 10 条。
|
|
110
130
|
// skill 的头部:ZCode 只认 name、description、when_to_use、license、metadata 五个键,而且只把 description 的前约 250 个字符交给模型——
|
|
111
131
|
// skill 装上了不等于会被调用
|
|
112
|
-
function checkBudgets({ root, say }) {
|
|
132
|
+
function checkBudgets({ root, packageRoot, say }) {
|
|
113
133
|
const bad = [];
|
|
114
|
-
|
|
134
|
+
// skill 和工作目录的 AGENTS.md:在工作目录里就是它自己那份,在仓库里 skill 在包根下、AGENTS.md 在 templates/ 下
|
|
135
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
136
|
+
const skill = path.join(dev ? packageRoot : root, '.agents', 'skills', 'work-rhythm', 'SKILL.md');
|
|
115
137
|
if (fs.existsSync(skill)) {
|
|
116
138
|
if (filledLines(skill) >= 500) bad.push('SKILL.md 超过 500 个非空行');
|
|
117
139
|
const lines = readText(skill).split('\n');
|
|
@@ -134,7 +156,8 @@ function checkBudgets({ root, say }) {
|
|
|
134
156
|
const len = Array.from(desc).length;
|
|
135
157
|
if (len > 250) bad.push(`SKILL.md 的 description 超过 250 个字符(现在 ${len}),超出的部分模型看不到:把触发场景放到最前面`);
|
|
136
158
|
}
|
|
137
|
-
|
|
159
|
+
// 工作目录的 AGENTS.md:在工作目录里就是根目录那份,在仓库里是 templates/ 下那份
|
|
160
|
+
const agents = dev ? path.join(packageRoot, 'templates', 'AGENTS.md') : path.join(root, 'AGENTS.md');
|
|
138
161
|
if (fs.existsSync(agents)) {
|
|
139
162
|
if (filledLines(agents) > 60) bad.push('AGENTS.md 超过 60 个非空行');
|
|
140
163
|
const lines = readText(agents).split('\n');
|
|
@@ -150,9 +173,10 @@ function checkBudgets({ root, say }) {
|
|
|
150
173
|
return bad.length;
|
|
151
174
|
}
|
|
152
175
|
|
|
153
|
-
// 4
|
|
154
|
-
//
|
|
176
|
+
// 4 配置自检(只在工作目录里):profile 没缺字段、local.env 写得对、启用的源有采集器、变量和依赖、消息渠道和值守配好了。
|
|
177
|
+
// 定时任务是无人值守的,问题要在这里先暴露。仓库自己没有这些配置
|
|
155
178
|
function checkConfig({ root, packageRoot, env, say }) {
|
|
179
|
+
if (path.resolve(root) === path.resolve(packageRoot)) return 0;
|
|
156
180
|
const bad = [];
|
|
157
181
|
// profile.yaml 不能缺 profile.example.yaml(空白模板)里声明的字段:模板加了新字段,填好的那份要跟上。多出来的字段是个人加的,不管
|
|
158
182
|
const example = path.join(root, '00-config', 'profile.example.yaml');
|
|
@@ -193,25 +217,48 @@ function checkConfig({ root, packageRoot, env, say }) {
|
|
|
193
217
|
if (!which('security', env)) bad.push(`消息渠道 ${channel} 需要 security,本机没有`);
|
|
194
218
|
else if (!hasWebhook(env)) bad.push(`消息渠道 ${channel}:钥匙串里没有 ${serviceName(env)}(开通步骤见 docs/channels.md「云之家」)`);
|
|
195
219
|
}
|
|
196
|
-
// 值守(work-rhythm listen
|
|
197
|
-
|
|
220
|
+
// 值守(work-rhythm listen,渠道的收消息一半):装了(launchd 里有它)才检查——agent 现在也是定时任务的前提,
|
|
221
|
+
// 只绑了 agent 跑任务的人不该被报「值守没配渠道」。查什么由它自己的 doctor 说了算,这里不重复一遍
|
|
222
|
+
if (!envProblems.length && fs.existsSync(launchd.plistPath('bot', root))) bad.push(...createBot({ root, env: values }).doctorProblems());
|
|
223
|
+
// 定时任务只能建在 agent 上:schedule 里开着任务(指令文件也在)却没绑 agent,到点一个也跑不了
|
|
224
|
+
const profileDoc = loadProfile(root);
|
|
225
|
+
const schedule = profileDoc.schedule && typeof profileDoc.schedule === 'object' ? profileDoc.schedule : {};
|
|
226
|
+
const scheduled = Object.keys(schedule).filter((id) => String(schedule[id] || '').trim() && !['ask-decisions'].includes(id));
|
|
227
|
+
// 引导走到第 6 步(status 是 scheduled 或 done)之后才算数:之前 schedule 里是模板的默认时间,agent 是第 6 步才绑的
|
|
228
|
+
const status = profileDoc.setup && profileDoc.setup.status;
|
|
229
|
+
if (scheduled.length && ['scheduled', 'done'].includes(status) && !envProblems.length && !(values.YZJ_BOT_AGENT || '').trim()) {
|
|
230
|
+
const withPrompt = scheduled.filter((id) => fs.existsSync(path.join(root, 'tasks', `${id}.md`)));
|
|
231
|
+
if (withPrompt.length) bad.push(`schedule 里有任务(${withPrompt.join('、')})却没绑 agent,到点一个也跑不了:work-rhythm agent bind <${PRESET_NAMES.join('|')}>`);
|
|
232
|
+
}
|
|
198
233
|
bad.forEach(say);
|
|
199
234
|
return bad.length;
|
|
200
235
|
}
|
|
201
236
|
|
|
202
|
-
// 5
|
|
237
|
+
// 5 疑似密钥:在工作目录里查会入库的六个目录(01-inbox/ 只是原料,不算);在仓库里查整个仓库。只报位置,不打印内容。
|
|
238
|
+
// 在工作目录里扫会入库的六个目录;在仓库里扫整个仓库(它全部都会入库,scripts/test/ 里故意的假样例除外)
|
|
203
239
|
// yzjtoken 是云之家机器人 Webhook 地址里的凭据;机器人会话的第一条消息里就有完整地址,容易被人顺手抄进备注或笔记
|
|
204
240
|
const SECRET = /sk-[A-Za-z0-9_-]{16,}|appSecret|accessToken|password\s*[:=]|BEGIN [A-Z ]*PRIVATE KEY|yzjtoken=[0-9A-Za-z]{8,}/;
|
|
205
241
|
|
|
206
|
-
function checkSecrets({ root, say }) {
|
|
242
|
+
function checkSecrets({ root, packageRoot, say }) {
|
|
207
243
|
const hits = [];
|
|
208
|
-
|
|
209
|
-
|
|
244
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
245
|
+
const scan = (file) => {
|
|
210
246
|
const text = readText(file);
|
|
211
|
-
if (text.includes('\0'))
|
|
247
|
+
if (text.includes('\0')) return; // 不是文本的不管
|
|
212
248
|
text.split('\n').forEach((line, n) => {
|
|
213
249
|
if (SECRET.test(line)) hits.push(`${path.relative(root, file)}:${n + 1}`);
|
|
214
250
|
});
|
|
251
|
+
};
|
|
252
|
+
if (dev) {
|
|
253
|
+
// 自测里的假 token 是故意写的样例,不扫;这条正则本身(写在这个文件里)也不扫
|
|
254
|
+
const tests = path.join(root, 'scripts', 'test');
|
|
255
|
+
for (const file of walkFiles(root, SKIP_DIRS, 0)) {
|
|
256
|
+
if (file.startsWith(`${tests}${path.sep}`) || file === __filename) continue;
|
|
257
|
+
scan(file);
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
for (const dir of ['00-config', '02-daily', '03-carryover', '04-patterns', '05-goals', '.agents']) {
|
|
261
|
+
for (const file of walkFiles(path.join(root, dir), SKIP_DIRS, 0)) scan(file);
|
|
215
262
|
}
|
|
216
263
|
}
|
|
217
264
|
if (hits.length) {
|
|
@@ -254,37 +301,37 @@ function checkNotes({ root, say }) {
|
|
|
254
301
|
return bad.length;
|
|
255
302
|
}
|
|
256
303
|
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
304
|
+
// 模板(只在仓库里查):templates/ 下每份都在、profile 是空白状态、数据源全关、记录里没有行
|
|
305
|
+
function checkTemplates({ packageRoot, say }) {
|
|
306
|
+
const bad = templateProblems(packageRoot);
|
|
307
|
+
bad.forEach(say);
|
|
308
|
+
return bad.length;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 仓库保持通用(只在仓库里查):这个仓库只放通用的 skill 和 CLI,不是工作目录——根目录不该出现工作目录才有的东西。
|
|
312
|
+
// 个人数据(身份、群、作息、渠道)只放进用户自己的工作目录;工作目录独有的文件只在 templates/ 下有
|
|
313
|
+
function genericProblems({ root, say }) {
|
|
261
314
|
const bad = [];
|
|
262
|
-
for (const rel of
|
|
263
|
-
|
|
264
|
-
if (!template) bad.push(`templates/${rel} 不存在`);
|
|
265
|
-
else if (template !== blankText(rel, readText(path.join(root, rel)))) bad.push(`templates/${rel} 和 ${rel} 空白化之后不一致(改了表头或说明,两边要一起改)`);
|
|
315
|
+
for (const rel of ['00-config', '02-daily', '03-carryover', '04-patterns', '05-goals', 'CLAUDE.md']) {
|
|
316
|
+
if (fs.existsSync(path.join(root, rel))) bad.push(`仓库根目录里出现了 ${rel}:这个仓库只放 skill 和 CLI,不是工作目录。工作目录独有的文件在 templates/ 下;试跑请先用 work-rhythm init 建一个临时工作目录`);
|
|
266
317
|
}
|
|
267
|
-
if (
|
|
268
|
-
// 工作目录的 .gitignore 写在 lib/template.js 里(见那里的说明),要和根目录的一致
|
|
269
|
-
if (readText(path.join(root, '.gitignore')) !== GITIGNORE) bad.push('.gitignore 和 lib/template.js 里的 GITIGNORE 不一致(两边要一起改)');
|
|
318
|
+
if (fs.existsSync(path.join(root, 'collectors', 'local.env'))) bad.push('仓库里出现了个人配置 collectors/local.env:个人的 profile 和 local.env 只放在自己的工作目录里');
|
|
270
319
|
bad.forEach(say);
|
|
271
320
|
return bad.length;
|
|
272
321
|
}
|
|
273
322
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
['预算', checkBudgets],
|
|
278
|
-
['配置自检', checkConfig],
|
|
279
|
-
['疑似密钥', checkSecrets],
|
|
280
|
-
['笔记格式', checkNotes],
|
|
281
|
-
];
|
|
323
|
+
// 顺序:前三项两边都有;工作目录里接着查配置,仓库里接着查模板;最后两项两边都有,仓库里再多一项
|
|
324
|
+
const COMMON_HEAD = [['脚本语法', checkSyntax], ['文档内链', checkLinks], ['预算', checkBudgets]];
|
|
325
|
+
const COMMON_TAIL = [['疑似密钥', checkSecrets], ['笔记格式', checkNotes]];
|
|
282
326
|
|
|
283
327
|
async function run(args, ctx) {
|
|
284
328
|
if (args.length) throw new UsageError('用法: work-rhythm check');
|
|
285
329
|
const { root, packageRoot, stdout, env } = ctx;
|
|
286
330
|
const say = (text = '') => stdout.write(`${text}\n`);
|
|
287
|
-
const
|
|
331
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
332
|
+
const steps = dev
|
|
333
|
+
? [...COMMON_HEAD, ['模板', checkTemplates], ...COMMON_TAIL, ['仓库保持通用', genericProblems]]
|
|
334
|
+
: [...COMMON_HEAD, ['配置自检', checkConfig], ...COMMON_TAIL];
|
|
288
335
|
let bad = 0;
|
|
289
336
|
for (const [i, [title, check]] of steps.entries()) {
|
|
290
337
|
say(`== ${i + 1}/${steps.length} ${title} ==`);
|
|
@@ -294,4 +341,4 @@ async function run(args, ctx) {
|
|
|
294
341
|
return bad ? 1 : EXIT.OK;
|
|
295
342
|
}
|
|
296
343
|
|
|
297
|
-
module.exports = { usage: '用法: work-rhythm check 改完脚本、配置或文档后跑一遍,只读', run };
|
|
344
|
+
module.exports = { usage: '用法: work-rhythm check 改完脚本、配置或文档后跑一遍,只读', run, __test: { genericProblems, checkTemplates } };
|
package/scripts/cmd/init.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// 新建一个工作目录:用包里带的模板铺出来(个人信息是空白的、数据源全部关着、没有记录),然后登记为工作目录。
|
|
2
|
+
// 建好之后对 AI 说「开始引导」。工作目录是个人数据,只是用户机器上的一个目录:这里不做 git init,也不往任何仓库同步。
|
|
3
3
|
// 用法: work-rhythm init <目录>
|
|
4
4
|
// 退出码: 0 建好;2 用法不对,或目录已经存在;5 包不完整、铺出来的不是空白的(会把建了一半的目录删掉)。
|
|
5
5
|
// 目录可以写相对路径,按当前目录算(work-rhythm init my-work → ./my-work)。
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
const fs = require('node:fs');
|
|
9
9
|
const path = require('node:path');
|
|
10
|
-
const { spawnSync } = require('node:child_process');
|
|
11
10
|
const { EXIT, Fail, UsageError } = require('../lib/run');
|
|
12
11
|
const { register } = require('../lib/workdir');
|
|
13
12
|
const { writeWorkdir } = require('../lib/template');
|
|
@@ -34,9 +33,6 @@ module.exports = {
|
|
|
34
33
|
fs.rmSync(target, { recursive: true, force: true });
|
|
35
34
|
throw new Fail(EXIT.FAILED, `铺出来的不是空白的工作目录,已经撤掉:${problems.join(';')}`);
|
|
36
35
|
}
|
|
37
|
-
// 一个不连任何远程的本地仓库:记录有版本可回溯,又不会推到别人的仓库去。没有 git 就跳过
|
|
38
|
-
const git = spawnSync('git', ['init', '-q'], { cwd: target, env, encoding: 'utf8' });
|
|
39
|
-
if (git.status !== 0) stderr.write(`init: 本机没有 git,${target} 没有初始化成 git 仓库\n`);
|
|
40
36
|
// 有些助手只认 CLAUDE.md
|
|
41
37
|
try {
|
|
42
38
|
fs.symlinkSync('AGENTS.md', path.join(target, 'CLAUDE.md'));
|
|
@@ -46,7 +42,7 @@ module.exports = {
|
|
|
46
42
|
const dir = fs.realpathSync(target);
|
|
47
43
|
register(dir, env);
|
|
48
44
|
stdout.write(`WORKDIR=${dir}\n`);
|
|
49
|
-
stderr.write(`init: 已新建 ${dir}
|
|
45
|
+
stderr.write(`init: 已新建 ${dir}:个人信息是空白的、数据源全部关着、没有记录\n`);
|
|
50
46
|
stderr.write('下一步:用能读到这个目录的 AI 打开它,对 AI 说「开始引导」。\n');
|
|
51
47
|
return EXIT.OK;
|
|
52
48
|
},
|
package/scripts/cmd/pack.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 把 skill 和 npm 包打成一个可分发的目录(本机有 zip 就顺手压一下):别人不需要这个仓库的访问权也能装上、开始引导
|
|
2
2
|
// 用法: work-rhythm pack [--out <目录>]
|
|
3
3
|
// 生成 <out>/work-rhythm-skill-<版本>/:SKILL.md、README.md(安装说明)、VERSION、这个包的 tgz(npm pack 打出来的,名字是 npm 定的)。
|
|
4
|
-
// 不带 --out 时放在当前工作目录的 01-inbox/outbox
|
|
4
|
+
// 不带 --out 时放在当前工作目录的 01-inbox/outbox/。
|
|
5
5
|
// 模板是 init 现铺的,包里只有空白的记录(templates/),个人信息和记录一律不带
|
|
6
6
|
'use strict';
|
|
7
7
|
const fs = require('node:fs');
|
|
@@ -43,7 +43,6 @@ const README = (version, tgz) => `# work-rhythm skill:安装和开始
|
|
|
43
43
|
|
|
44
44
|
对 AI 说「开始引导」。它会问你想把工作目录放在哪(默认 \`~/workspace/my-work\`),用 \`work-rhythm init\` 建好、登记,再一步步问你:用哪个 IM、接哪些数据源、作息和定时任务。
|
|
45
45
|
|
|
46
|
-
建出来的工作目录是一个不连任何远程的本地 git 仓库(本机有 git 的话)。想备份到自己的私有仓库,进去 \`git remote add origin <地址>\` 再推。
|
|
47
46
|
|
|
48
47
|
## 升级
|
|
49
48
|
|