work-rhythm 0.1.0 → 0.1.1
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 +3 -1
- package/.agents/notes/decisions/2026-11-30-no-workdir-offers-to-create-one-by-default.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-workdir-is-not-a-git-repository.md +25 -0
- package/.agents/skills/work-rhythm/SKILL.md +5 -4
- package/AGENTS.md +12 -24
- package/README.md +34 -70
- package/collectors/local.env.example +1 -1
- package/docs/channels.md +1 -1
- package/docs/formats.md +1 -1
- package/package.json +2 -4
- package/scripts/cli.js +8 -5
- package/scripts/cmd/check.js +74 -41
- package/scripts/cmd/init.js +3 -7
- package/scripts/cmd/pack.js +1 -2
- 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/check.test.js +63 -1
- package/scripts/test/config.test.js +6 -7
- package/scripts/test/goals.test.js +1 -1
- package/scripts/test/harness.js +3 -5
- package/scripts/test/init.test.js +9 -11
- package/scripts/test/pack.test.js +1 -1
- package/scripts/test/rhythm.test.js +11 -2
- package/scripts/test/workdir.test.js +2 -2
- package/{00-config → templates/00-config}/sources.yaml +8 -8
- package/templates/AGENTS.md +31 -0
- package/templates/README.md +73 -0
- /package/{00-config → templates/00-config}/profile.example.yaml +0 -0
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,10 @@ 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 { GENERATED_DIRS, templateProblems } = require('../lib/template');
|
|
15
16
|
|
|
16
17
|
const SKILL_KEYS = ['name', 'description', 'when_to_use', 'license', 'metadata'];
|
|
17
|
-
const SKIP_DIRS = new Set(['.git', '01-inbox', 'node_modules']);
|
|
18
|
+
const SKIP_DIRS = new Set(['.git', '01-inbox', 'node_modules', '.zcode']);
|
|
18
19
|
// 内置采集器各要什么:tools 是 PATH 上要有的命令,var 是 local.env 里一定要有的变量(源 id 不是采集器自己的名字时加 _<ID> 后缀)
|
|
19
20
|
const NEEDS = {
|
|
20
21
|
'im-yzj': { tools: [], var: 'YZJ_GROUP_IDS' },
|
|
@@ -79,11 +80,15 @@ function checkSyntax({ root, packageRoot, say }) {
|
|
|
79
80
|
return bad;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
// 2 文档内链:相对链接指向的文件在不在。代码块里的内容是示例,不检查;别的协议(http、mailto
|
|
83
|
+
// 2 文档内链:相对链接指向的文件在不在。代码块里的内容是示例,不检查;别的协议(http、mailto…)不管。
|
|
84
|
+
// 链接都是按工作目录里的位置写的。站在工作目录里查,找不到的再到包里找(脚本不在工作目录里);
|
|
85
|
+
// 站在仓库里查,按工作目录里的位置到包里找:共用的文件在包根下,工作目录独有的在 templates/ 下。
|
|
86
|
+
// templates/ 下的文件(AGENTS.md、README.md、03-carryover/…)铺进工作目录之后才在根上,所以它们的位置先换算成工作目录里的位置
|
|
83
87
|
function checkLinks({ root, packageRoot, say }) {
|
|
84
88
|
const broken = [];
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
90
|
+
const templates = path.join(packageRoot, 'templates');
|
|
91
|
+
for (const file of walkFiles(root, SKIP_DIRS, 0)) {
|
|
87
92
|
if (!file.endsWith('.md')) continue;
|
|
88
93
|
let fenced = false;
|
|
89
94
|
for (const line of readText(file).split('\n')) {
|
|
@@ -95,10 +100,22 @@ function checkLinks({ root, packageRoot, say }) {
|
|
|
95
100
|
for (const m of line.matchAll(/\]\(([^)]+)\)/g)) {
|
|
96
101
|
const link = m[1].trim().replace(/\s+"[^"]*"$/, '').replace(/#.*$/, '');
|
|
97
102
|
if (!link || /^[a-z][a-z0-9+.-]*:/i.test(link)) continue;
|
|
98
|
-
//
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
103
|
+
// 文件在工作目录里的位置:templates/ 下的按铺开之后算
|
|
104
|
+
const placed = file.startsWith(`${templates}${path.sep}`) ? path.join(packageRoot, path.relative(templates, file)) : file;
|
|
105
|
+
const target = path.resolve(path.dirname(placed), decodeURIComponent(link));
|
|
106
|
+
const rel = path.relative(dev ? packageRoot : root, target);
|
|
107
|
+
if (rel.startsWith('..')) {
|
|
108
|
+
broken.push(`断链 ./${path.relative(root, file)} -> ${link}`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const candidates = [target, path.resolve(packageRoot, rel)];
|
|
112
|
+
if (dev) {
|
|
113
|
+
candidates.push(path.resolve(templates, rel));
|
|
114
|
+
// profile.yaml、02-daily/、05-goals/ 是 init 现生成的(见 lib/template.js),仓库里只有模板那一份或者没有
|
|
115
|
+
if (rel === '00-config/profile.yaml') candidates.push(path.resolve(templates, '00-config', 'profile.example.yaml'));
|
|
116
|
+
if (GENERATED_DIRS.includes(rel)) continue;
|
|
117
|
+
}
|
|
118
|
+
if (!candidates.some((c) => fs.existsSync(c))) broken.push(`断链 ./${path.relative(root, file)} -> ${link}`);
|
|
102
119
|
}
|
|
103
120
|
}
|
|
104
121
|
}
|
|
@@ -106,12 +123,14 @@ function checkLinks({ root, packageRoot, say }) {
|
|
|
106
123
|
return broken.length;
|
|
107
124
|
}
|
|
108
125
|
|
|
109
|
-
// 3 预算:SKILL.md 不超过 500
|
|
126
|
+
// 3 预算:SKILL.md 不超过 500 个非空行;工作目录的 AGENTS.md 不超过 60 行、standing orders 不超过 10 条。
|
|
110
127
|
// skill 的头部:ZCode 只认 name、description、when_to_use、license、metadata 五个键,而且只把 description 的前约 250 个字符交给模型——
|
|
111
128
|
// skill 装上了不等于会被调用
|
|
112
|
-
function checkBudgets({ root, say }) {
|
|
129
|
+
function checkBudgets({ root, packageRoot, say }) {
|
|
113
130
|
const bad = [];
|
|
114
|
-
|
|
131
|
+
// skill 和工作目录的 AGENTS.md:在工作目录里就是它自己那份,在仓库里 skill 在包根下、AGENTS.md 在 templates/ 下
|
|
132
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
133
|
+
const skill = path.join(dev ? packageRoot : root, '.agents', 'skills', 'work-rhythm', 'SKILL.md');
|
|
115
134
|
if (fs.existsSync(skill)) {
|
|
116
135
|
if (filledLines(skill) >= 500) bad.push('SKILL.md 超过 500 个非空行');
|
|
117
136
|
const lines = readText(skill).split('\n');
|
|
@@ -134,7 +153,8 @@ function checkBudgets({ root, say }) {
|
|
|
134
153
|
const len = Array.from(desc).length;
|
|
135
154
|
if (len > 250) bad.push(`SKILL.md 的 description 超过 250 个字符(现在 ${len}),超出的部分模型看不到:把触发场景放到最前面`);
|
|
136
155
|
}
|
|
137
|
-
|
|
156
|
+
// 工作目录的 AGENTS.md:在工作目录里就是根目录那份,在仓库里是 templates/ 下那份
|
|
157
|
+
const agents = dev ? path.join(packageRoot, 'templates', 'AGENTS.md') : path.join(root, 'AGENTS.md');
|
|
138
158
|
if (fs.existsSync(agents)) {
|
|
139
159
|
if (filledLines(agents) > 60) bad.push('AGENTS.md 超过 60 个非空行');
|
|
140
160
|
const lines = readText(agents).split('\n');
|
|
@@ -150,9 +170,10 @@ function checkBudgets({ root, say }) {
|
|
|
150
170
|
return bad.length;
|
|
151
171
|
}
|
|
152
172
|
|
|
153
|
-
// 4
|
|
154
|
-
//
|
|
173
|
+
// 4 配置自检(只在工作目录里):profile 没缺字段、local.env 写得对、启用的源有采集器、变量和依赖、消息渠道和值守配好了。
|
|
174
|
+
// 定时任务是无人值守的,问题要在这里先暴露。仓库自己没有这些配置
|
|
155
175
|
function checkConfig({ root, packageRoot, env, say }) {
|
|
176
|
+
if (path.resolve(root) === path.resolve(packageRoot)) return 0;
|
|
156
177
|
const bad = [];
|
|
157
178
|
// profile.yaml 不能缺 profile.example.yaml(空白模板)里声明的字段:模板加了新字段,填好的那份要跟上。多出来的字段是个人加的,不管
|
|
158
179
|
const example = path.join(root, '00-config', 'profile.example.yaml');
|
|
@@ -199,19 +220,31 @@ function checkConfig({ root, packageRoot, env, say }) {
|
|
|
199
220
|
return bad.length;
|
|
200
221
|
}
|
|
201
222
|
|
|
202
|
-
// 5
|
|
223
|
+
// 5 疑似密钥:在工作目录里查会入库的六个目录(01-inbox/ 只是原料,不算);在仓库里查整个仓库。只报位置,不打印内容。
|
|
224
|
+
// 在工作目录里扫会入库的六个目录;在仓库里扫整个仓库(它全部都会入库,scripts/test/ 里故意的假样例除外)
|
|
203
225
|
// yzjtoken 是云之家机器人 Webhook 地址里的凭据;机器人会话的第一条消息里就有完整地址,容易被人顺手抄进备注或笔记
|
|
204
226
|
const SECRET = /sk-[A-Za-z0-9_-]{16,}|appSecret|accessToken|password\s*[:=]|BEGIN [A-Z ]*PRIVATE KEY|yzjtoken=[0-9A-Za-z]{8,}/;
|
|
205
227
|
|
|
206
|
-
function checkSecrets({ root, say }) {
|
|
228
|
+
function checkSecrets({ root, packageRoot, say }) {
|
|
207
229
|
const hits = [];
|
|
208
|
-
|
|
209
|
-
|
|
230
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
231
|
+
const scan = (file) => {
|
|
210
232
|
const text = readText(file);
|
|
211
|
-
if (text.includes('\0'))
|
|
233
|
+
if (text.includes('\0')) return; // 不是文本的不管
|
|
212
234
|
text.split('\n').forEach((line, n) => {
|
|
213
235
|
if (SECRET.test(line)) hits.push(`${path.relative(root, file)}:${n + 1}`);
|
|
214
236
|
});
|
|
237
|
+
};
|
|
238
|
+
if (dev) {
|
|
239
|
+
// 自测里的假 token 是故意写的样例,不扫;这条正则本身(写在这个文件里)也不扫
|
|
240
|
+
const tests = path.join(root, 'scripts', 'test');
|
|
241
|
+
for (const file of walkFiles(root, SKIP_DIRS, 0)) {
|
|
242
|
+
if (file.startsWith(`${tests}${path.sep}`) || file === __filename) continue;
|
|
243
|
+
scan(file);
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
for (const dir of ['00-config', '02-daily', '03-carryover', '04-patterns', '05-goals', '.agents']) {
|
|
247
|
+
for (const file of walkFiles(path.join(root, dir), SKIP_DIRS, 0)) scan(file);
|
|
215
248
|
}
|
|
216
249
|
}
|
|
217
250
|
if (hits.length) {
|
|
@@ -254,37 +287,37 @@ function checkNotes({ root, say }) {
|
|
|
254
287
|
return bad.length;
|
|
255
288
|
}
|
|
256
289
|
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
290
|
+
// 模板(只在仓库里查):templates/ 下每份都在、profile 是空白状态、数据源全关、记录里没有行
|
|
291
|
+
function checkTemplates({ packageRoot, say }) {
|
|
292
|
+
const bad = templateProblems(packageRoot);
|
|
293
|
+
bad.forEach(say);
|
|
294
|
+
return bad.length;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 仓库保持通用(只在仓库里查):这个仓库只放通用的 skill 和 CLI,不是工作目录——根目录不该出现工作目录才有的东西。
|
|
298
|
+
// 个人数据(身份、群、作息、渠道)只放进用户自己的工作目录;工作目录独有的文件只在 templates/ 下有
|
|
299
|
+
function genericProblems({ root, say }) {
|
|
261
300
|
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} 空白化之后不一致(改了表头或说明,两边要一起改)`);
|
|
301
|
+
for (const rel of ['00-config', '02-daily', '03-carryover', '04-patterns', '05-goals', 'CLAUDE.md']) {
|
|
302
|
+
if (fs.existsSync(path.join(root, rel))) bad.push(`仓库根目录里出现了 ${rel}:这个仓库只放 skill 和 CLI,不是工作目录。工作目录独有的文件在 templates/ 下;试跑请先用 work-rhythm init 建一个临时工作目录`);
|
|
266
303
|
}
|
|
267
|
-
if (
|
|
268
|
-
// 工作目录的 .gitignore 写在 lib/template.js 里(见那里的说明),要和根目录的一致
|
|
269
|
-
if (readText(path.join(root, '.gitignore')) !== GITIGNORE) bad.push('.gitignore 和 lib/template.js 里的 GITIGNORE 不一致(两边要一起改)');
|
|
304
|
+
if (fs.existsSync(path.join(root, 'collectors', 'local.env'))) bad.push('仓库里出现了个人配置 collectors/local.env:个人的 profile 和 local.env 只放在自己的工作目录里');
|
|
270
305
|
bad.forEach(say);
|
|
271
306
|
return bad.length;
|
|
272
307
|
}
|
|
273
308
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
['预算', checkBudgets],
|
|
278
|
-
['配置自检', checkConfig],
|
|
279
|
-
['疑似密钥', checkSecrets],
|
|
280
|
-
['笔记格式', checkNotes],
|
|
281
|
-
];
|
|
309
|
+
// 顺序:前三项两边都有;工作目录里接着查配置,仓库里接着查模板;最后两项两边都有,仓库里再多一项
|
|
310
|
+
const COMMON_HEAD = [['脚本语法', checkSyntax], ['文档内链', checkLinks], ['预算', checkBudgets]];
|
|
311
|
+
const COMMON_TAIL = [['疑似密钥', checkSecrets], ['笔记格式', checkNotes]];
|
|
282
312
|
|
|
283
313
|
async function run(args, ctx) {
|
|
284
314
|
if (args.length) throw new UsageError('用法: work-rhythm check');
|
|
285
315
|
const { root, packageRoot, stdout, env } = ctx;
|
|
286
316
|
const say = (text = '') => stdout.write(`${text}\n`);
|
|
287
|
-
const
|
|
317
|
+
const dev = path.resolve(root) === path.resolve(packageRoot);
|
|
318
|
+
const steps = dev
|
|
319
|
+
? [...COMMON_HEAD, ['模板', checkTemplates], ...COMMON_TAIL, ['仓库保持通用', genericProblems]]
|
|
320
|
+
: [...COMMON_HEAD, ['配置自检', checkConfig], ...COMMON_TAIL];
|
|
288
321
|
let bad = 0;
|
|
289
322
|
for (const [i, [title, check]] of steps.entries()) {
|
|
290
323
|
say(`== ${i + 1}/${steps.length} ${title} ==`);
|
|
@@ -294,4 +327,4 @@ async function run(args, ctx) {
|
|
|
294
327
|
return bad ? 1 : EXIT.OK;
|
|
295
328
|
}
|
|
296
329
|
|
|
297
|
-
module.exports = { usage: '用法: work-rhythm check 改完脚本、配置或文档后跑一遍,只读', run };
|
|
330
|
+
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
|
|
package/scripts/lib/log.js
CHANGED
package/scripts/lib/rhythm.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 3 推送:整理完把 agent 的总结经消息渠道(notify.js)发给我,附一个本机地址;
|
|
5
5
|
// 4 看页面:只绑 127.0.0.1 的网页服务,把工作目录里的 Markdown 现渲染成 HTML(markdown.js)。
|
|
6
6
|
// 任务是一个个子进程跑的,调度不被堵住;一次只跑一个,后面的排队。错过的任务在 5 分钟内还会补跑,再久就不追了。
|
|
7
|
-
// 只用 node 自带的能力。日志写 01-inbox/_rhythm.log,状态写 01-inbox/_rhythm/state.json
|
|
7
|
+
// 只用 node 自带的能力。日志写 01-inbox/_rhythm.log,状态写 01-inbox/_rhythm/state.json。
|
|
8
8
|
'use strict';
|
|
9
9
|
const { spawn } = require('node:child_process');
|
|
10
10
|
const fs = require('node:fs');
|
package/scripts/lib/template.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
// 新工作目录里的东西从哪来,以及怎么把一个用过的目录清成空白的。
|
|
2
|
-
//
|
|
3
|
-
// 共用的(SHARED):文档、任务指令、给 agent 的笔记和 skill
|
|
4
|
-
//
|
|
5
|
-
// 现生成的:profile.yaml(就是 profile.example.yaml)、sources.yaml
|
|
2
|
+
// 这个仓库不是工作目录:工作目录里独有的文件都在 templates/ 下,分两种:
|
|
3
|
+
// 共用的(SHARED):文档、任务指令、给 agent 的笔记和 skill、local.env 的样例——仓库里就有,工作目录和包里是同一份;
|
|
4
|
+
// 模板(TEMPLATE_FILES,在 templates/ 下):profile 的空白模板、sources.yaml 的清单、空白的遗留 / 决定 / 规律画像、工作目录的 AGENTS.md 和 README.md;
|
|
5
|
+
// 现生成的:profile.yaml(就是 profile.example.yaml)、sources.yaml(清单照搬,全部关着,引导时逐个确认再打开)、两个空目录 02-daily/ 和 05-goals/。
|
|
6
6
|
// 脚本和内置采集器不进工作目录:它们在包里,sources.yaml 用 id 引用。升级就是升级这个包
|
|
7
7
|
'use strict';
|
|
8
8
|
const fs = require('node:fs');
|
|
9
9
|
const path = require('node:path');
|
|
10
10
|
const { readText, walkFiles } = require('./run');
|
|
11
11
|
|
|
12
|
-
const SHARED = ['
|
|
13
|
-
|
|
14
|
-
const GITIGNORE = `# 各系统的原始快照:可重新拉取,且含聊天原文等细节,不入库
|
|
15
|
-
01-inbox/
|
|
16
|
-
|
|
17
|
-
# 本机的配置(订阅的会话 ID、让哪个 agent 回复等)
|
|
18
|
-
collectors/local.env
|
|
19
|
-
|
|
20
|
-
.DS_Store
|
|
21
|
-
`;
|
|
12
|
+
const SHARED = ['docs', 'tasks', '.agents', 'collectors/local.env.example'];
|
|
13
|
+
const TEMPLATE_FILES = ['00-config/profile.example.yaml', '00-config/sources.yaml', '03-carryover/CARRYOVER.md', '03-carryover/DECISIONS.md', '04-patterns/WORK_RHYTHM.md', 'AGENTS.md', 'README.md'];
|
|
22
14
|
const BLANK = ['03-carryover/CARRYOVER.md', '03-carryover/DECISIONS.md', '04-patterns/WORK_RHYTHM.md'];
|
|
23
|
-
|
|
15
|
+
// 空目录:init 现建(以前靠 .gitkeep 占位;工作目录不是 git 仓库,不用了)
|
|
16
|
+
const GENERATED_DIRS = ['02-daily', '05-goals'];
|
|
24
17
|
|
|
25
18
|
// 表里以日期开头的行是记录,表头和分隔线留着
|
|
26
19
|
const blankCarryover = (text) => text.split('\n').filter((line) => !/^\| \d/.test(line)).join('\n');
|
|
@@ -80,6 +73,23 @@ function blankProblems(dir) {
|
|
|
80
73
|
return problems;
|
|
81
74
|
}
|
|
82
75
|
|
|
76
|
+
// 包里的模板对不对:每份都在、profile 是空白状态、数据源全关、记录里没有行、规律画像没开始。
|
|
77
|
+
// 开发时 check 查它,writeWorkdir 铺新工作目录之前也靠它兜底。返回问题的列表
|
|
78
|
+
function templateProblems(packageRoot) {
|
|
79
|
+
const problems = [];
|
|
80
|
+
const text = (rel) => readText(path.join(packageRoot, 'templates', rel));
|
|
81
|
+
for (const rel of TEMPLATE_FILES) {
|
|
82
|
+
if (!text(rel)) problems.push(`templates/${rel} 不存在`);
|
|
83
|
+
}
|
|
84
|
+
if (!/^ status: new\b/m.test(text('00-config/profile.example.yaml'))) problems.push('templates/00-config/profile.example.yaml 不是空白状态(setup.status 应为 new)');
|
|
85
|
+
if (/^\s*enabled:\s*true\b/m.test(text('00-config/sources.yaml'))) problems.push('templates/00-config/sources.yaml 里有打开的源:模板里数据源一律关着,引导时再逐个打开');
|
|
86
|
+
for (const rel of BLANK) {
|
|
87
|
+
if (/^\| \d/m.test(text(rel))) problems.push(`templates/${rel} 里带了记录`);
|
|
88
|
+
}
|
|
89
|
+
if (!text('04-patterns/WORK_RHYTHM.md').includes('数据范围:尚未开始')) problems.push('templates/04-patterns/WORK_RHYTHM.md 的「数据范围」不是「尚未开始」');
|
|
90
|
+
return problems;
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
// 把一个目录清成空白的工作目录:个人信息换成空白模板、数据源全关、记录不留、本机配置和原始数据删掉。
|
|
84
94
|
// 只处理目录里已有的文件,缺的不补。返回退出码
|
|
85
95
|
function blank(dir) {
|
|
@@ -125,20 +135,15 @@ function copyEntry(from, to) {
|
|
|
125
135
|
|
|
126
136
|
// 用包里的模板铺出一个空白的工作目录(目录本身要先建好)。返回空白核对没通过的问题;空数组就是铺好了
|
|
127
137
|
function writeWorkdir(dir, packageRoot) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
fs.writeFileSync(path.join(dir, '.gitignore'), GITIGNORE);
|
|
134
|
-
for (const keep of KEEPS) {
|
|
135
|
-
fs.mkdirSync(path.dirname(path.join(dir, keep)), { recursive: true });
|
|
136
|
-
fs.writeFileSync(path.join(dir, keep), '');
|
|
137
|
-
}
|
|
138
|
+
const missing = templateProblems(packageRoot).filter((p) => p.endsWith(' 不存在'));
|
|
139
|
+
if (missing.length) throw new Error(`这个包不完整:${missing.join(';')}。重新安装一次 work-rhythm`);
|
|
140
|
+
for (const rel of SHARED) copyEntry(path.join(packageRoot, rel), path.join(dir, rel));
|
|
141
|
+
for (const rel of TEMPLATE_FILES) copyEntry(path.join(packageRoot, 'templates', rel), path.join(dir, rel));
|
|
142
|
+
for (const name of GENERATED_DIRS) fs.mkdirSync(path.join(dir, name), { recursive: true });
|
|
138
143
|
fs.writeFileSync(path.join(dir, '00-config', 'profile.yaml'), fs.readFileSync(path.join(dir, '00-config', 'profile.example.yaml')));
|
|
139
144
|
const sources = path.join(dir, '00-config', 'sources.yaml');
|
|
140
145
|
fs.writeFileSync(sources, blankSources(fs.readFileSync(sources, 'utf8')));
|
|
141
146
|
return blankProblems(dir);
|
|
142
147
|
}
|
|
143
148
|
|
|
144
|
-
module.exports = { SHARED,
|
|
149
|
+
module.exports = { SHARED, TEMPLATE_FILES, BLANK, GENERATED_DIRS, blankCarryover, blankRhythm, blankSources, blankText, blankProblems, templateProblems, blank, writeWorkdir };
|
package/scripts/lib/workdir.js
CHANGED
|
@@ -44,12 +44,21 @@ function findUp(start) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// 站在 work-rhythm 自己的仓库里(packageRoot 就是它):仓库不是工作目录,但 check 要能查它
|
|
48
|
+
function insidePackage(cwd, packageRoot) {
|
|
49
|
+
if (!packageRoot) return false;
|
|
50
|
+
const rel = path.relative(path.resolve(packageRoot), path.resolve(cwd));
|
|
51
|
+
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 命令作用在哪个目录:--workdir 指定的优先,其次从当前目录往上找;站在 work-rhythm 自己的仓库里就是仓库(source=package,
|
|
55
|
+
// 只有 check 用得上,别的命令会报「不是工作目录」);最后看登记。
|
|
56
|
+
// 返回 { root, source: 'option' | 'cwd' | 'package' | 'pointer' | 'none', problem };登记了但用不了时 problem 说明原因
|
|
57
|
+
function resolveRoot({ cwd = process.cwd(), option = '', env = process.env, packageRoot = '' } = {}) {
|
|
50
58
|
if (option) return { root: path.resolve(option), source: 'option', problem: '' };
|
|
51
59
|
const up = findUp(cwd);
|
|
52
60
|
if (up) return { root: up, source: 'cwd', problem: '' };
|
|
61
|
+
if (insidePackage(cwd, packageRoot)) return { root: path.resolve(packageRoot), source: 'package', problem: '' };
|
|
53
62
|
const reg = registered(env);
|
|
54
63
|
if (reg && isWorkdir(reg)) return { root: reg, source: 'pointer', problem: '' };
|
|
55
64
|
return {
|
|
@@ -86,4 +95,4 @@ function findAll(starts, home) {
|
|
|
86
95
|
return [...found.values()].sort((a, b) => (a.dir < b.dir ? -1 : 1));
|
|
87
96
|
}
|
|
88
97
|
|
|
89
|
-
module.exports = { MARKER, isWorkdir, configPath, registered, register, findUp, resolveRoot, findAll };
|
|
98
|
+
module.exports = { MARKER, isWorkdir, configPath, registered, register, findUp, insidePackage, resolveRoot, findAll };
|
|
@@ -3,7 +3,10 @@ const { test } = require('node:test');
|
|
|
3
3
|
const assert = require('node:assert/strict');
|
|
4
4
|
const fs = require('node:fs');
|
|
5
5
|
const path = require('node:path');
|
|
6
|
-
const { makeSandbox, read, write, setKey } = require('./harness');
|
|
6
|
+
const { PACKAGE_ROOT, makeSandbox, run: rawRun, read, write, setKey } = require('./harness');
|
|
7
|
+
const os = require('node:os');
|
|
8
|
+
const { genericProblems } = require('../cmd/check').__test;
|
|
9
|
+
const { templateProblems } = require('../lib/template');
|
|
7
10
|
|
|
8
11
|
// 搭工作目录(空白模板)。check 的退出码:0 全部通过,1 有未通过的项
|
|
9
12
|
function setup(t) {
|
|
@@ -211,6 +214,65 @@ test('check:值守配了 dsh 却找不到它的配置时报出来', (t) => {
|
|
|
211
214
|
assert.match(r.stdout, /找不到 DSH 的配置/);
|
|
212
215
|
});
|
|
213
216
|
|
|
217
|
+
test('check:这个包自己的仓库要全部通过——它不是工作目录,只放 skill 和 CLI,不带个人数据', (t) => {
|
|
218
|
+
// 站在仓库里跑:7 项,有「模板」「仓库保持通用」,没有「配置自检」
|
|
219
|
+
const r = rawRun(['check'], { cwd: PACKAGE_ROOT, env: { WORK_RHYTHM_CONFIG: path.join(os.tmpdir(), 'no-such-config.yaml') } });
|
|
220
|
+
assert.equal(r.code, 0, r.out);
|
|
221
|
+
assert.match(r.stdout, /== 1\/7 脚本语法 ==\n== 2\/7 文档内链 ==\n== 3\/7 预算 ==\n== 4\/7 模板 ==\n== 5\/7 疑似密钥 ==\n== 6\/7 笔记格式 ==\n== 7\/7 仓库保持通用 ==\n全部通过\n/);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('站在仓库里:check 查的是仓库,不是用户级登记的那个工作目录;别的命令说清这里不是工作目录', (t) => {
|
|
225
|
+
const box = makeSandbox(t);
|
|
226
|
+
box.workdir();
|
|
227
|
+
const cfg = path.join(box.root, 'cfg.yaml');
|
|
228
|
+
write(cfg, `workdir: ${box.work}\n`);
|
|
229
|
+
const env = { WORK_RHYTHM_CONFIG: cfg };
|
|
230
|
+
// 登记指向另一个工作目录,但人站在仓库里:check 查仓库(7 项),today 不偷偷落到登记的那个上
|
|
231
|
+
assert.equal(rawRun(['check'], { cwd: path.join(PACKAGE_ROOT, 'scripts'), env }).code, 0);
|
|
232
|
+
assert.match(rawRun(['check'], { cwd: path.join(PACKAGE_ROOT, 'scripts'), env }).stdout, /== 7\/7 仓库保持通用 ==/);
|
|
233
|
+
const today = rawRun(['today'], { cwd: PACKAGE_ROOT, env });
|
|
234
|
+
assert.equal(today.code, 3);
|
|
235
|
+
assert.match(today.stderr, /当前目录不是工作目录(这里是 work-rhythm 自己的仓库,不是工作目录)/);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('仓库保持通用:根目录出现工作目录才有的东西、个人配置,各报一条', (t) => {
|
|
239
|
+
const box = makeSandbox(t);
|
|
240
|
+
const repo = path.join(box.root, 'repo');
|
|
241
|
+
fs.cpSync(path.join(PACKAGE_ROOT, 'templates'), path.join(repo, 'templates'), { recursive: true });
|
|
242
|
+
const problems = () => {
|
|
243
|
+
const lines = [];
|
|
244
|
+
genericProblems({ root: repo, say: (l) => lines.push(l) });
|
|
245
|
+
return lines;
|
|
246
|
+
};
|
|
247
|
+
assert.deepEqual(problems(), []);
|
|
248
|
+
write(path.join(repo, '00-config', 'profile.yaml'), 'setup:\n status: done\n');
|
|
249
|
+
write(path.join(repo, '02-daily', '2026-01', '2026-01-01.md'), '# 2026-01-01\n');
|
|
250
|
+
write(path.join(repo, 'collectors', 'local.env'), 'A=1\n');
|
|
251
|
+
const found = problems();
|
|
252
|
+
assert.equal(found.length, 3);
|
|
253
|
+
assert.match(found.join('\n'), /仓库根目录里出现了 00-config:这个仓库只放 skill 和 CLI,不是工作目录/);
|
|
254
|
+
assert.match(found.join('\n'), /仓库根目录里出现了 02-daily/);
|
|
255
|
+
assert.match(found.join('\n'), /仓库里出现了个人配置 collectors\/local\.env/);
|
|
256
|
+
assert.ok(found.every((l) => !l.includes('templates/00-config')), 'templates/ 里的不算');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('模板:templates/ 下每份都在、profile 空白、源全关、记录没有行;坏了就报出来', (t) => {
|
|
260
|
+
const box = makeSandbox(t);
|
|
261
|
+
const pkg = path.join(box.root, 'pkg');
|
|
262
|
+
fs.cpSync(path.join(PACKAGE_ROOT, 'templates'), path.join(pkg, 'templates'), { recursive: true });
|
|
263
|
+
assert.deepEqual(templateProblems(pkg), []);
|
|
264
|
+
fs.rmSync(path.join(pkg, 'templates', 'README.md'));
|
|
265
|
+
write(path.join(pkg, 'templates', '00-config', 'sources.yaml'), read(path.join(pkg, 'templates', '00-config', 'sources.yaml')).replace('enabled: false', 'enabled: true'));
|
|
266
|
+
fs.appendFileSync(path.join(pkg, 'templates', '03-carryover', 'CARRYOVER.md'), '| 2026-01-01 | 旧 | 复盘 | P1 | 待开始 | 0 | |\n');
|
|
267
|
+
write(path.join(pkg, 'templates', '04-patterns', 'WORK_RHYTHM.md'), '# 我的规律\n\n数据范围:近 30 天\n');
|
|
268
|
+
const found = templateProblems(pkg);
|
|
269
|
+
assert.equal(found.length, 4);
|
|
270
|
+
assert.match(found.join('\n'), /templates\/README\.md 不存在/);
|
|
271
|
+
assert.match(found.join('\n'), /sources\.yaml 里有打开的源/);
|
|
272
|
+
assert.match(found.join('\n'), /CARRYOVER\.md 里带了记录/);
|
|
273
|
+
assert.match(found.join('\n'), /「数据范围」不是「尚未开始」/);
|
|
274
|
+
});
|
|
275
|
+
|
|
214
276
|
test('check:用法不对时退出码为 2', (t) => {
|
|
215
277
|
const s = setup(t);
|
|
216
278
|
assert.equal(s.box.run(['check', '什么']).code, 2);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { test } = require('node:test');
|
|
3
3
|
const assert = require('node:assert/strict');
|
|
4
4
|
const { parseYaml, parseLocalEnv, findWorkdir, loadProfile, loadSources } = require('../lib/config');
|
|
5
|
+
const path = require('node:path');
|
|
5
6
|
const { PACKAGE_ROOT, makeSandbox, write, read, exists } = require('./harness');
|
|
6
7
|
|
|
7
8
|
// 配置文件是用户会手改的 YAML,格式即契约:docs/formats.md 和两份 *.example 里的写法都要读得出来
|
|
@@ -62,12 +63,10 @@ sources:
|
|
|
62
63
|
assert.equal(doc.sources[1].enabled, false);
|
|
63
64
|
});
|
|
64
65
|
|
|
65
|
-
test('parseYaml
|
|
66
|
-
//
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
for (const name of names) {
|
|
70
|
-
const doc = parseYaml(read(`${PACKAGE_ROOT}/00-config/${name}`));
|
|
66
|
+
test('parseYaml:空白模板能读,要用的字段一个不少(仓库里的 profile.yaml 是它的副本,也读一遍)', () => {
|
|
67
|
+
// profile.yaml 只有开发时有(npm 包里不带它)
|
|
68
|
+
for (const name of ['profile.example.yaml']) {
|
|
69
|
+
const doc = parseYaml(read(`${PACKAGE_ROOT}/templates/00-config/${name}`));
|
|
71
70
|
assert.equal(typeof doc.identity.name, 'string', name);
|
|
72
71
|
assert.equal(Array.isArray(doc.im.groups), true, name);
|
|
73
72
|
assert.equal(typeof doc.preferences.notify, 'string', name);
|
|
@@ -77,7 +76,7 @@ test('parseYaml:空白模板和填好的实例都能读,要用的字段一
|
|
|
77
76
|
assert.equal(Array.isArray(doc.setup.skipped), true, name);
|
|
78
77
|
for (const p of doc.role.projects) assert.equal(typeof p.name, 'string', name);
|
|
79
78
|
}
|
|
80
|
-
const sources = loadSources(PACKAGE_ROOT);
|
|
79
|
+
const sources = loadSources(path.join(PACKAGE_ROOT, 'templates'));
|
|
81
80
|
assert.equal(sources.length, 8);
|
|
82
81
|
assert.equal(sources[0].id, 'git-activity');
|
|
83
82
|
assert.equal(typeof sources[0].extract, 'string');
|
|
@@ -105,5 +105,5 @@ test('goals:05-goals 里没有目标时只打表头;不在工作目录里退
|
|
|
105
105
|
assert.equal(list.code, 0);
|
|
106
106
|
assert.equal(list.stdout.trimEnd().split('\n').length, 1);
|
|
107
107
|
assert.equal(box.run(['goals', 'list'], { cwd: box.root }).code, 3);
|
|
108
|
-
assert.equal(exists(`${box.work}/05-goals
|
|
108
|
+
assert.equal(exists(`${box.work}/05-goals`), true);
|
|
109
109
|
});
|
package/scripts/test/harness.js
CHANGED
|
@@ -42,7 +42,7 @@ function run(args, { cwd = PACKAGE_ROOT, env = {}, input, timeout = 120000 } = {
|
|
|
42
42
|
|
|
43
43
|
// sources.yaml:只打开两个本机源(代码提交、文件改动),其余关着(假命令行跑不了云之家、Linky)
|
|
44
44
|
function cleanSources() {
|
|
45
|
-
const lines = read(path.join(PACKAGE_ROOT, '00-config', 'sources.yaml')).split('\n');
|
|
45
|
+
const lines = read(path.join(PACKAGE_ROOT, 'templates', '00-config', 'sources.yaml')).split('\n');
|
|
46
46
|
let keep = false;
|
|
47
47
|
return lines.map((line) => {
|
|
48
48
|
if (/^\s*-?\s*id:/.test(line)) {
|
|
@@ -157,14 +157,12 @@ function makeSandbox(t) {
|
|
|
157
157
|
return sandbox;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
// 搭一个工作目录,和 work-rhythm init 铺出来的一样(走同一个函数),只是 sources.yaml 换成 cleanSources()
|
|
161
|
-
|
|
162
|
-
function makeWorkdir(dir, { profile = 'example' } = {}) {
|
|
160
|
+
// 搭一个工作目录,和 work-rhythm init 铺出来的一样(走同一个函数),只是 sources.yaml 换成 cleanSources()(打开两个本机源)
|
|
161
|
+
function makeWorkdir(dir) {
|
|
163
162
|
fs.mkdirSync(dir, { recursive: true });
|
|
164
163
|
const problems = writeWorkdir(dir, PACKAGE_ROOT);
|
|
165
164
|
if (problems.length) throw new Error(`铺出来的工作目录不是空白的:${problems.join(';')}`);
|
|
166
165
|
fs.writeFileSync(path.join(dir, '00-config', 'sources.yaml'), cleanSources());
|
|
167
|
-
if (profile !== 'example') fs.writeFileSync(path.join(dir, '00-config', 'profile.yaml'), read(path.join(PACKAGE_ROOT, '00-config', 'profile.yaml')));
|
|
168
166
|
return dir;
|
|
169
167
|
}
|
|
170
168
|
|
|
@@ -13,14 +13,15 @@ const TODAY = () => {
|
|
|
13
13
|
|
|
14
14
|
// 新工作目录里该有什么:配置、文档、任务指令、记录、笔记和 skill;不该有脚本和内置采集器
|
|
15
15
|
const EXPECTED = [
|
|
16
|
-
'00-config/profile.yaml', '00-config/profile.example.yaml', '00-config/sources.yaml', 'AGENTS.md', 'README.md', '
|
|
16
|
+
'00-config/profile.yaml', '00-config/profile.example.yaml', '00-config/sources.yaml', 'AGENTS.md', 'README.md', 'CLAUDE.md',
|
|
17
17
|
'docs/formats.md', 'docs/channels.md', 'tasks/daily-plan.md', 'collectors/local.env.example',
|
|
18
18
|
'03-carryover/CARRYOVER.md', '03-carryover/DECISIONS.md', '04-patterns/WORK_RHYTHM.md',
|
|
19
|
-
'.agents/skills/work-rhythm/SKILL.md', '.agents/notes/AGENTS.md', '02-daily
|
|
19
|
+
'.agents/skills/work-rhythm/SKILL.md', '.agents/notes/AGENTS.md', '02-daily', '05-goals',
|
|
20
20
|
];
|
|
21
|
-
|
|
21
|
+
// 工作目录不是 git 仓库:没有 .git、.gitignore、.gitkeep
|
|
22
|
+
const NOT_EXPECTED = ['scripts', 'templates', 'collectors/git-activity.js', 'collectors/im-yzj.sh', '01-inbox', 'collectors/local.env', '.git', '.gitignore', '02-daily/.gitkeep'];
|
|
22
23
|
|
|
23
|
-
test('init
|
|
24
|
+
test('init:用包里的模板建出工作目录并登记;不 git init,不是 git 仓库', (t) => {
|
|
24
25
|
const box = makeSandbox(t);
|
|
25
26
|
const cfg = path.join(box.root, 'wr-config.yaml');
|
|
26
27
|
const target = path.join(box.root, 'home', 'new-wd');
|
|
@@ -28,7 +29,7 @@ test('init:用包里的模板建出工作目录,git init 一个不连远程
|
|
|
28
29
|
assert.equal(r.code, 0, r.out);
|
|
29
30
|
const real = fs.realpathSync(target);
|
|
30
31
|
assert.equal(r.stdout, `WORKDIR=${real}\n`);
|
|
31
|
-
assert.match(r.stderr, /init: 已新建 .*new-wd
|
|
32
|
+
assert.match(r.stderr, /init: 已新建 .*new-wd:个人信息是空白的、数据源全部关着、没有记录\n下一步:.*「开始引导」/);
|
|
32
33
|
for (const f of EXPECTED) assert.ok(exists(path.join(target, f)), `缺 ${f}`);
|
|
33
34
|
for (const f of NOT_EXPECTED) assert.ok(!exists(path.join(target, f)), `不该有 ${f}`);
|
|
34
35
|
assert.match(read(`${target}/00-config/profile.yaml`), /^ status: new\b/m);
|
|
@@ -36,10 +37,7 @@ test('init:用包里的模板建出工作目录,git init 一个不连远程
|
|
|
36
37
|
assert.ok(!/enabled:\s*true/.test(read(`${target}/00-config/sources.yaml`)), '数据源要全部关着');
|
|
37
38
|
assert.match(read(`${target}/03-carryover/DECISIONS.md`), /^\| 日期 \| 事项/m);
|
|
38
39
|
assert.ok(!/^\| \d/m.test(read(`${target}/03-carryover/DECISIONS.md`)), '模板里不带记录');
|
|
39
|
-
assert.match(read(`${target}/.gitignore`), /01-inbox\/\n[\s\S]*collectors\/local\.env/);
|
|
40
40
|
assert.ok(fs.lstatSync(`${target}/CLAUDE.md`).isSymbolicLink(), 'CLAUDE.md 是指向 AGENTS.md 的软链');
|
|
41
|
-
assert.ok(exists(`${target}/.git`));
|
|
42
|
-
assert.equal(git(target, ['remote'], GIT_ENV).stdout.trim(), '', '不连任何远程');
|
|
43
41
|
assert.equal(read(cfg), `workdir: ${real}\n`);
|
|
44
42
|
});
|
|
45
43
|
|
|
@@ -84,16 +82,17 @@ test('init:建出来的工作目录里 work-rhythm 的命令都能用:check
|
|
|
84
82
|
});
|
|
85
83
|
|
|
86
84
|
// ---------------------------------------------------------------- 模板本身
|
|
87
|
-
const { writeWorkdir, blankProblems, blankText
|
|
85
|
+
const { writeWorkdir, blankProblems, blankText } = require('../lib/template');
|
|
88
86
|
|
|
89
87
|
test('template:包不完整时说清缺哪份;空白核对认得出带记录、带配置、没关源的目录', (t) => {
|
|
90
88
|
const box = makeSandbox(t);
|
|
91
89
|
write(path.join(box.root, 'pkg', 'docs', 'a.md'), 'x');
|
|
92
|
-
assert.throws(() => writeWorkdir(path.join(box.root, 'w'), path.join(box.root, 'pkg')),
|
|
90
|
+
assert.throws(() => writeWorkdir(path.join(box.root, 'w'), path.join(box.root, 'pkg')), /这个包不完整:templates\/00-config\/profile\.example\.yaml 不存在;[\s\S]*重新安装一次 work-rhythm/);
|
|
93
91
|
// 真铺出来的是空白的(夹具为了跑采集会打开两个本机源,所以这里自己铺一份)
|
|
94
92
|
const dir = path.join(box.root, 'fresh');
|
|
95
93
|
fs.mkdirSync(dir);
|
|
96
94
|
assert.deepEqual(writeWorkdir(dir, PACKAGE_ROOT), []);
|
|
95
|
+
assert.deepEqual(fs.readdirSync(path.join(dir, '02-daily')), [], '02-daily 是空目录,不用 .gitkeep 占位');
|
|
97
96
|
assert.deepEqual(blankProblems(dir), []);
|
|
98
97
|
write(`${dir}/02-daily/2026-01/2026-01-01.md`, '# 2026-01-01\n');
|
|
99
98
|
write(`${dir}/05-goals/x.md`, '---\nid: x\n---\n');
|
|
@@ -111,7 +110,6 @@ test('template:包不完整时说清缺哪份;空白核对认得出带记录
|
|
|
111
110
|
'带了不该带的 collectors/local.env',
|
|
112
111
|
'带了不该带的 01-inbox',
|
|
113
112
|
]);
|
|
114
|
-
assert.match(GITIGNORE, /01-inbox\/\n[\s\S]*collectors\/local\.env/);
|
|
115
113
|
});
|
|
116
114
|
|
|
117
115
|
test('template:空白化的几条规则', () => {
|