@ihupoo/solmet 0.0.0-stage → 0.2.0

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +154 -2
  3. package/README.zh.md +155 -0
  4. package/bin/solmet.js +11 -0
  5. package/package.json +39 -4
  6. package/skills/archive/SKILL.md +15 -0
  7. package/skills/check/SKILL.md +20 -0
  8. package/skills/grill/SKILL.md +23 -0
  9. package/skills/grilling/SKILL.md +22 -0
  10. package/skills/implement/SKILL.md +18 -0
  11. package/skills/map/SKILL.md +42 -0
  12. package/skills/memory-recording/SKILL.md +40 -0
  13. package/skills/spec/SKILL.md +24 -0
  14. package/skills/spec-writing/SKILL.md +17 -0
  15. package/skills/start/SKILL.md +25 -0
  16. package/skills/tdd/SKILL.md +14 -0
  17. package/src/cli.js +83 -0
  18. package/src/commands/archive.js +35 -0
  19. package/src/commands/brief.js +14 -0
  20. package/src/commands/check.js +71 -0
  21. package/src/commands/common.js +65 -0
  22. package/src/commands/doctor.js +208 -0
  23. package/src/commands/gate.js +148 -0
  24. package/src/commands/init.js +87 -0
  25. package/src/commands/map.js +64 -0
  26. package/src/commands/recall.js +41 -0
  27. package/src/commands/remember.js +98 -0
  28. package/src/commands/skill.js +26 -0
  29. package/src/commands/start.js +49 -0
  30. package/src/commands/status.js +76 -0
  31. package/src/lib/agents.js +79 -0
  32. package/src/lib/brief.js +78 -0
  33. package/src/lib/catalog.js +71 -0
  34. package/src/lib/check.js +360 -0
  35. package/src/lib/config.js +55 -0
  36. package/src/lib/detect.js +58 -0
  37. package/src/lib/fsx.js +117 -0
  38. package/src/lib/labels.js +92 -0
  39. package/src/lib/map.js +261 -0
  40. package/src/lib/memory.js +273 -0
  41. package/src/lib/paths.js +10 -0
  42. package/src/lib/router.js +49 -0
  43. package/src/lib/task.js +189 -0
  44. package/src/lib/title.js +43 -0
  45. package/src/lib/version.js +7 -0
  46. package/templates/NOTES.md +17 -0
  47. package/templates/PRD.md +25 -0
  48. package/templates/PROJECT-CONTEXT.md +25 -0
  49. package/templates/TASK.md +7 -0
@@ -0,0 +1,189 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { readText, writeText, nowIso, relative, today } from "./fsx.js";
5
+ import { ACTIVE_DIR, ARCHIVE_DIR, TASKS_DIR } from "./paths.js";
6
+
7
+ const META_START = "<!-- solmet";
8
+ const META_END = "-->";
9
+
10
+ export function slugify(value) {
11
+ const base = String(value || "")
12
+ .trim()
13
+ .toLowerCase()
14
+ .replace(/[^\p{L}\p{N}]+/gu, "-")
15
+ .replace(/^-+|-+$/g, "")
16
+ .slice(0, 48);
17
+ return base || `task-${Date.now()}`;
18
+ }
19
+
20
+ export function taskRoot(root) {
21
+ return path.join(root, ".solmet", TASKS_DIR);
22
+ }
23
+
24
+ export function activeRoot(root) {
25
+ return path.join(taskRoot(root), ACTIVE_DIR);
26
+ }
27
+
28
+ export function archiveRoot(root) {
29
+ return path.join(taskRoot(root), ARCHIVE_DIR);
30
+ }
31
+
32
+ export function readTask(file) {
33
+ const text = readText(file);
34
+ const start = text.indexOf(META_START);
35
+ const end = text.indexOf(META_END, start);
36
+ if (start < 0 || end < 0) throw new Error(`TASK.md 缺少 solmet 元数据:${file}`);
37
+ const raw = text.slice(start + META_START.length, end).trim();
38
+ let meta;
39
+ try {
40
+ meta = JSON.parse(raw);
41
+ } catch (error) {
42
+ throw new Error(`TASK.md 元数据不是合法 JSON:${error.message}`);
43
+ }
44
+ const body = (text.slice(0, start) + text.slice(end + META_END.length)).trim() + "\n";
45
+ return { meta, body, file, dir: path.dirname(file) };
46
+ }
47
+
48
+ export function writeTask(task, meta, body) {
49
+ meta.updated_at = nowIso();
50
+ const text = `${body.trim()}\n\n${META_START}\n${JSON.stringify(meta, null, 2)}\n${META_END}\n`;
51
+ writeText(task.file, text);
52
+ }
53
+
54
+ export function newTaskMeta({ id, title, request, root }) {
55
+ const now = nowIso();
56
+ return {
57
+ schema: 1,
58
+ id,
59
+ title,
60
+ request,
61
+ status: "draft",
62
+ created_at: now,
63
+ updated_at: now,
64
+ project_root: root,
65
+ artifacts: {
66
+ prd: "PRD.md",
67
+ notes: "NOTES.md",
68
+ changes: "CHANGES.md",
69
+ },
70
+ gates: {
71
+ spec: { status: "pending" },
72
+ verified: { status: "pending" },
73
+ },
74
+ checks: [],
75
+ spec_sha256: null,
76
+ };
77
+ }
78
+
79
+ export function sha256File(file) {
80
+ return crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
81
+ }
82
+
83
+ export function sha256Text(text) {
84
+ return crypto.createHash("sha256").update(text).digest("hex");
85
+ }
86
+
87
+ export function taskFile(dir) {
88
+ return path.join(dir, "TASK.md");
89
+ }
90
+
91
+ export function findTask(root, explicit = "") {
92
+ if (explicit) {
93
+ const resolved = path.resolve(root, explicit);
94
+ const file = fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()
95
+ ? taskFile(resolved)
96
+ : resolved;
97
+ if (!fs.existsSync(file)) throw new Error(`TASK.md 不存在:${file}`);
98
+ return readTask(file);
99
+ }
100
+ const dirs = fs.existsSync(activeRoot(root))
101
+ ? fs.readdirSync(activeRoot(root), { withFileTypes: true })
102
+ .filter((entry) => entry.isDirectory())
103
+ .map((entry) => path.join(activeRoot(root), entry.name))
104
+ .filter((dir) => fs.existsSync(taskFile(dir)))
105
+ : [];
106
+ if (dirs.length === 0) throw new Error("没有进行中的任务;仅当用户要求代码变更(新功能、修改、修复)时才运行 solmet start");
107
+ if (dirs.length > 1) {
108
+ throw new Error(
109
+ `有多个进行中的任务,请用 --task 指定:\n${dirs
110
+ .map((dir) => `- ${relative(root, dir)}`)
111
+ .join("\n")}`
112
+ );
113
+ }
114
+ return readTask(taskFile(dirs[0]));
115
+ }
116
+
117
+ export function refreshTaskState(task) {
118
+ const meta = task.meta;
119
+ let changed = false;
120
+ const prd = path.join(task.dir, meta.artifacts?.prd || "PRD.md");
121
+ const spec = meta.gates?.spec;
122
+ if (spec?.status === "approved") {
123
+ if (!fs.existsSync(prd) || sha256File(prd) !== spec.prd_sha256) {
124
+ spec.status = "stale";
125
+ meta.status = "draft";
126
+ changed = true;
127
+ }
128
+ if (changed) {
129
+ meta.gates.verified = { status: "pending" };
130
+ }
131
+ }
132
+ const verified = meta.gates?.verified;
133
+ if (verified?.status === "approved") {
134
+ const changes = path.join(task.dir, meta.artifacts?.changes || "CHANGES.md");
135
+ const currentChecks = sha256Text(JSON.stringify(meta.checks || []));
136
+ const stale =
137
+ !fs.existsSync(prd) ||
138
+ sha256File(prd) !== verified.prd_sha256 ||
139
+ !fs.existsSync(changes) ||
140
+ sha256File(changes) !== verified.changes_sha256 ||
141
+ currentChecks !== verified.checks_sha256;
142
+ if (stale) {
143
+ verified.status = "stale";
144
+ meta.status = "verifying";
145
+ changed = true;
146
+ }
147
+ }
148
+ if (changed) writeTask(task, meta, task.body);
149
+ return task;
150
+ }
151
+
152
+ export function setStatus(task, status) {
153
+ task.meta.status = status;
154
+ writeTask(task, task.meta, task.body);
155
+ }
156
+
157
+ export function statusLabel(status) {
158
+ return {
159
+ draft: "draft",
160
+ "spec-ready": "spec-ready",
161
+ implementing: "implementing",
162
+ verifying: "verifying",
163
+ verified: "verified",
164
+ archived: "archived",
165
+ }[status] || status;
166
+ }
167
+
168
+ export function nextAction(meta) {
169
+ if (meta.status === "draft") {
170
+ return "编写 PRD 与人工验收清单(`solmet skill spec`);确认后记录规格门禁(`solmet gate spec --approve --confirmation \"<原话>\"`)";
171
+ }
172
+ if (meta.status === "spec-ready") {
173
+ return "按规格实现(`solmet skill implement`);实现前跑基线(`solmet doctor --baseline`),完成后运行检查(`solmet check`)";
174
+ }
175
+ if (meta.status === "implementing") {
176
+ return "修复检查失败项,再运行检查(`solmet check`);不要放宽断言";
177
+ }
178
+ if (meta.status === "verifying") {
179
+ return "按 PRD 的人工验收清单核对;确认后记录验收门禁(`solmet gate verified --approve --confirmation \"<原话>\"`)";
180
+ }
181
+ if (meta.status === "verified") {
182
+ return "任务已验收;归档(`solmet archive`)";
183
+ }
184
+ return "已完成(archived)";
185
+ }
186
+
187
+ export function makeTaskId(title) {
188
+ return `${today()}-${slugify(title)}`;
189
+ }
@@ -0,0 +1,43 @@
1
+ export function shortTitle(meta, prd = "") {
2
+ const heading = String(prd || "").match(/^#\s+(.+?)\s*$/m)?.[1] || "";
3
+ const cleaned = heading.replace(/^PRD\s*[·::-]\s*/i, "").trim();
4
+ if (cleaned && !/^prd$/i.test(cleaned)) return cleaned;
5
+ return String(meta?.title || "").trim();
6
+ }
7
+
8
+ const MAX_TITLE = 24;
9
+
10
+ function clipTitle(value) {
11
+ const text = String(value || "").trim();
12
+ if (text.length <= MAX_TITLE) return text;
13
+ const head = text.slice(0, MAX_TITLE);
14
+ const boundary = Math.max(
15
+ head.lastIndexOf(","),
16
+ head.lastIndexOf("、"),
17
+ head.lastIndexOf(";"),
18
+ head.lastIndexOf(" ")
19
+ );
20
+ const clipped = boundary >= 12 ? head.slice(0, boundary) : head;
21
+ return clipped.replace(/[,、;::\s]+$/g, "").trim();
22
+ }
23
+
24
+ export function deriveTitle(request, explicit = "") {
25
+ const raw = String(explicit || "").trim();
26
+ if (raw) return raw.slice(0, 80);
27
+ const text = String(request || "").replace(/\s+/g, " ").trim();
28
+ if (!text) return "未命名任务";
29
+ const sentence = text.split(/[。;;\n]/)[0].trim();
30
+ const clause = sentence.split(/[,,]/)[0].trim();
31
+ let title = clause
32
+ .replace(/^在(.+?)中/, (_, where) => `${where}:`)
33
+ .replace(/^在(.+?)里/, (_, where) => `${where}:`)
34
+ .replace(/:为/g, ":")
35
+ .replace(/^为/, "")
36
+ .replace(/^给/, "")
37
+ .replace(/^对/, "")
38
+ .replace(/^[“”"'《》]+|[“”"'《》]+$/g, "")
39
+ .replace(/[::\s]+$/g, "")
40
+ .trim();
41
+ if (!title) title = clause;
42
+ return clipTitle(title) || text.slice(0, MAX_TITLE);
43
+ }
@@ -0,0 +1,7 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { PACKAGE_ROOT } from "./paths.js";
4
+
5
+ export const VERSION = JSON.parse(
6
+ fs.readFileSync(path.join(PACKAGE_ROOT, "package.json"), "utf8")
7
+ ).version;
@@ -0,0 +1,17 @@
1
+ # 实现笔记 · <任务标题>
2
+
3
+ ## 决策
4
+
5
+ - 待补充
6
+
7
+ ## 例外
8
+
9
+ - 待补充(条件、补偿检查、责任人、到期时间)
10
+
11
+ ## 风险
12
+
13
+ - 待补充(blast radius、可逆性、回滚方式)
14
+
15
+ ## 后续
16
+
17
+ - 待补充
@@ -0,0 +1,25 @@
1
+ # PRD · <任务标题>
2
+
3
+ <!-- solmet:draft 填写完成后删除本行 -->
4
+
5
+ > 最小合同:问题、方案、人工验收、非目标。单行为、可逆的小改动写 5 行即可;跨模块、改权限/数据/公共接口或不可逆的改动再补用户故事、实现决策、测试 seam、风险。
6
+
7
+ ## 问题
8
+
9
+ <!-- 从用户视角描述现在的问题,不要先写实现方案。 -->
10
+
11
+ ## 方案
12
+
13
+ <!-- 从用户视角描述目标行为,说明用户能观察到什么变化。 -->
14
+
15
+ ## 人工验收
16
+
17
+ <!-- 列 1–3 条可观察项:入口、操作、预期结果;复杂改动可增加。 -->
18
+
19
+ 1. 待补充
20
+
21
+ ## 非目标
22
+
23
+ <!-- 本次明确不做的事情。 -->
24
+
25
+ <!-- 可选小节:用户故事、实现决策、测试决策(含 seam)、风险。按需追加,没有信息就不写。 -->
@@ -0,0 +1,25 @@
1
+ # 项目上下文
2
+
3
+ <!-- solmet:map
4
+ {
5
+ "source_commit": "",
6
+ "updated_at": "",
7
+ "scope": [],
8
+ "confidence": "unknown",
9
+ "unknowns": [
10
+ "尚未探索"
11
+ ]
12
+ }
13
+ -->
14
+
15
+ > 派生缓存,不是事实源。只保留当前结构事实,不保留返工历史。
16
+
17
+ <!-- solmet:skeleton:start -->
18
+ ## 结构骨架(自动生成,可选)
19
+
20
+ 尚未生成。仅在大仓库需要全局导航时运行 `solmet map --skeleton`。
21
+ <!-- solmet:skeleton:end -->
22
+
23
+ ## 当前事实
24
+
25
+ <!-- 只写:覆盖范围、入口/调用链、可复用 seam、约定与不变量、风险区、未覆盖。未填写的行删除;未覆盖的区域必须写明。 -->
@@ -0,0 +1,7 @@
1
+ ## 请求
2
+
3
+ <任务请求>
4
+
5
+ ## 备注
6
+
7
+ 当前状态与下一步:运行 `solmet status`。