@ihupoo/solmet 0.0.0-stage → 0.2.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.
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,87 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { defaultConfig, configFile, writeConfig } from "../lib/config.js";
4
+ import { detectProject } from "../lib/detect.js";
5
+ import { ensureDir, readJson, relative } from "../lib/fsx.js";
6
+ import { buildAgentsBlock, upsertAgentsBlock } from "../lib/agents.js";
7
+ import { shouldInstallRouter, writeRouterSkill } from "../lib/router.js";
8
+ import { writeIndex } from "../lib/memory.js";
9
+ import { parseArgs, printJson } from "./common.js";
10
+
11
+ const VCS_VALUES = ["git", "svn", "none"];
12
+
13
+ export function runInit(args) {
14
+ const { flags } = parseArgs(args);
15
+ const root = path.resolve(process.cwd(), flags.root || ".");
16
+ if (!fs.existsSync(root)) throw new Error(`项目根不存在:${root}`);
17
+ const explicitVcs = flags.vcs ? String(flags.vcs).toLowerCase() : "";
18
+ if (explicitVcs && !VCS_VALUES.includes(explicitVcs)) {
19
+ throw new Error(`--vcs 只支持 git、svn、none:${flags.vcs}`);
20
+ }
21
+ const detected = detectProject(root, { agent: flags.agent || "" });
22
+ const existing = readJson(configFile(root), null);
23
+ let config;
24
+ if (existing && !flags.force) {
25
+ const mergedCommands = {};
26
+ for (const key of new Set([...Object.keys(detected.commands), ...Object.keys(existing.commands || {})])) {
27
+ mergedCommands[key] = (existing.commands || {})[key] || detected.commands[key] || "";
28
+ }
29
+ const vcs = explicitVcs || (existing.vcs && existing.vcs !== "none" ? existing.vcs : detected.vcs);
30
+ config = {
31
+ ...existing,
32
+ agent: flags.agent || existing.agent || detected.agent,
33
+ vcs,
34
+ vcs_root: vcs === "none" ? "" : (vcs === detected.vcs ? detected.vcsRoot : existing.vcs_root || ""),
35
+ package_manager: existing.package_manager || detected.packageManager,
36
+ commands: mergedCommands,
37
+ };
38
+ } else {
39
+ config = defaultConfig(root, detected);
40
+ if (explicitVcs) {
41
+ config.vcs = explicitVcs;
42
+ config.vcs_root = explicitVcs === detected.vcs ? detected.vcsRoot : "";
43
+ }
44
+ }
45
+
46
+ const statePath = path.join(root, ".solmet");
47
+ for (const dir of ["spec", "research", "journal", "tasks/active", "tasks/archive"]) {
48
+ ensureDir(path.join(statePath, dir));
49
+ }
50
+ writeConfig(root, config);
51
+ upsertAgentsBlock(root, buildAgentsBlock(config, root));
52
+ const router = shouldInstallRouter(config) ? writeRouterSkill(root) : "";
53
+ const index = writeIndex(root);
54
+
55
+ const summary = {
56
+ ok: true,
57
+ root,
58
+ config: configFile(root),
59
+ index,
60
+ router: router ? relative(root, router) : "",
61
+ agent: config.agent,
62
+ vcs: config.vcs,
63
+ vcs_root: config.vcs_root || "",
64
+ package_manager: config.package_manager,
65
+ commands: config.commands,
66
+ warnings: [
67
+ !config.package_manager && "未检测到 package.json;build/check 命令需要手动配置。",
68
+ !Object.values(config.commands || {}).some(Boolean) && "未检测到检查命令;请编辑 .solmet/config.json。",
69
+ (!config.vcs || config.vcs === "none") && "未检测到 git/svn;不影响使用,只是基线不记录 VCS 溯源。",
70
+ ].filter(Boolean),
71
+ };
72
+ if (flags.json) {
73
+ printJson(summary);
74
+ return 0;
75
+ }
76
+ console.log(`solmet 已初始化:${root}`);
77
+ console.log(`agent: ${config.agent} · vcs: ${config.vcs}${config.vcs_root && config.vcs_root !== root ? ` (${config.vcs_root})` : ""} · package manager: ${config.package_manager || "-"}`);
78
+ console.log("commands:");
79
+ for (const [name, command] of Object.entries(config.commands || {})) {
80
+ if (command) console.log(` ${name}: ${command}`);
81
+ }
82
+ if (router) console.log(`router: ${relative(root, router)}`);
83
+ else console.log(`router: 跳过(agent=${config.agent};当前只生成 Qoder 路由技能)`);
84
+ for (const warning of summary.warnings) console.log(`[WARN] ${warning}`);
85
+ console.log('下一步:solmet start "你的任务"');
86
+ return 0;
87
+ }
@@ -0,0 +1,64 @@
1
+ import { readConfig } from "../lib/config.js";
2
+ import { createMap, mapStatus, writeSkeleton } from "../lib/map.js";
3
+ import { parseArgs, printJson, projectRoot } from "./common.js";
4
+
5
+ function printStatus(status) {
6
+ if (!status.exists) {
7
+ console.log(`项目地图:未建立(${status.path})`);
8
+ console.log(status.guidance);
9
+ return;
10
+ }
11
+ console.log(`项目地图:${status.path}`);
12
+ console.log(`状态:存在 · ${status.bytes} B · 骨架=${status.skeleton ? "yes" : "no"}`);
13
+ if (!status.meta) {
14
+ console.log("元数据:无法解析;使用前请修复");
15
+ } else {
16
+ const scope = Array.isArray(status.meta.scope) ? status.meta.scope : [];
17
+ const unknowns = Array.isArray(status.meta.unknowns) ? status.meta.unknowns : [];
18
+ console.log(
19
+ `依据:${status.meta.source_commit || "-"} · 更新:${status.meta.updated_at || "-"}`
20
+ );
21
+ console.log(
22
+ `覆盖:${scope.join(", ") || "-"} · 置信:${status.meta.confidence || "unknown"}`
23
+ );
24
+ if (unknowns.length) {
25
+ console.log(`未覆盖:${unknowns.join(", ")}`);
26
+ }
27
+ }
28
+ if (status.changed_since_map) {
29
+ console.log(`提示:当前 HEAD 是 ${status.head},地图依据的 commit 已变化,使用前核对代码。`);
30
+ }
31
+ console.log(status.guidance);
32
+ }
33
+
34
+ export function runMap(args) {
35
+ const { flags } = parseArgs(args);
36
+ if (flags.init && flags.skeleton) {
37
+ throw new Error("--init 与 --skeleton 不能同时使用");
38
+ }
39
+ const root = projectRoot(flags);
40
+ readConfig(root);
41
+ let status;
42
+ let action = "status";
43
+ let created = null;
44
+ if (flags.skeleton) {
45
+ action = "skeleton";
46
+ created = writeSkeleton(root).created;
47
+ } else if (flags.init) {
48
+ action = "init";
49
+ created = createMap(root).created;
50
+ }
51
+ status = mapStatus(root);
52
+ const payload = { ok: true, action, created, ...status };
53
+ if (flags.json) {
54
+ printJson(payload);
55
+ return 0;
56
+ }
57
+ if (action === "init") {
58
+ console.log(created ? "已创建项目地图模板。" : "项目地图已存在,未覆盖。");
59
+ } else if (action === "skeleton") {
60
+ console.log(created ? "已创建项目地图并生成结构骨架。" : "已更新结构骨架,当前事实未改动。");
61
+ }
62
+ printStatus(status);
63
+ return 0;
64
+ }
@@ -0,0 +1,41 @@
1
+ import { parseArgs, printJson, projectRoot } from "./common.js";
2
+ import { recall } from "../lib/memory.js";
3
+
4
+ const SOURCES = ["memory", "archive", "all"];
5
+
6
+ export function runRecall(args) {
7
+ const { positional, flags } = parseArgs(args);
8
+ const root = projectRoot(flags);
9
+ const query = positional.join(" ").trim();
10
+ if (!query) throw new Error('必须提供查询词,例如:solmet recall "关键词" 或 solmet recall \'"精确短语"\'');
11
+ const source = String(flags.source || "memory").toLowerCase();
12
+ if (!SOURCES.includes(source)) throw new Error(`--source 只支持 memory、archive、all:${flags.source}`);
13
+ const limit = Number.parseInt(flags.limit, 10) || 5;
14
+ const maxChars = Number.parseInt(flags["max-chars"], 10) || 300;
15
+ const results = recall(root, query, { source, limit, maxChars });
16
+ const note = "历史记录,需核对代码;代码优先。research/decisions/ 默认不召回。";
17
+ if (flags.json) {
18
+ printJson({ ok: true, query, source, results, note });
19
+ return 0;
20
+ }
21
+ console.log(`召回(recall):“${query}” · 来源(source):${source} · 结果(results):${results.length}`);
22
+ if (!results.length) {
23
+ console.log("未命中(no match);换关键词、去掉引号或扩大 --source 再试。");
24
+ return 0;
25
+ }
26
+ for (const item of results) {
27
+ console.log("");
28
+ console.log(`- [${item.source}] ${item.title}`);
29
+ console.log(` 路径(path):${item.path} · 更新(updated):${String(item.updated_at).slice(0, 10)}`);
30
+ if (item.task) {
31
+ console.log(
32
+ ` 任务(task):${item.task.task} · 状态(status):${item.task.status} · ` +
33
+ `检查(checks):${item.task.checks} · 日期(date):${item.task.date}`
34
+ );
35
+ }
36
+ console.log(` 摘录(excerpt):${item.snippet}`);
37
+ }
38
+ console.log("");
39
+ console.log(note);
40
+ return 0;
41
+ }
@@ -0,0 +1,98 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { refreshAgents } from "../lib/agents.js";
4
+ import { ensureDir, nowIso, readText, relative, today, writeText } from "../lib/fsx.js";
5
+ import { parseArgs, printJson, projectRoot } from "./common.js";
6
+
7
+ const MAX_SUMMARY = 600;
8
+
9
+ function memoryTarget(root, kind, value) {
10
+ if (value === true) throw new Error(`--${kind === "spec" ? "spec" : "topic"} 需要文件名`);
11
+ const base = path.join(root, ".solmet", kind === "spec" ? "spec" : "research");
12
+ let name = String(value || "").trim();
13
+ if (!name) throw new Error("文件名不能为空");
14
+ if (!name.toLowerCase().endsWith(".md")) name += ".md";
15
+ const file = path.resolve(base, name);
16
+ const rel = path.relative(base, file);
17
+ if (!rel || rel.startsWith("..") || path.isAbsolute(rel)) {
18
+ throw new Error(`路径越界:${value}`);
19
+ }
20
+ return file;
21
+ }
22
+
23
+ function upsertSection(text, title, body) {
24
+ const lines = String(text || "").replace(/\r\n/g, "\n").split("\n");
25
+ const section = (heading, level) => {
26
+ const start = lines.findIndex((line) => line.trim() === heading);
27
+ if (start < 0) return "";
28
+ let end = lines.length;
29
+ for (let index = start + 1; index < lines.length; index += 1) {
30
+ const match = lines[index].match(/^(#{1,6})\s+/);
31
+ if (match && match[1].length <= level) {
32
+ end = index;
33
+ break;
34
+ }
35
+ }
36
+ return [...lines.slice(0, start), heading, "", body.trimEnd(), "", ...lines.slice(end)]
37
+ .join("\n")
38
+ .replace(/\n{3,}/g, "\n\n")
39
+ .trimEnd() + "\n";
40
+ };
41
+ const h2 = section(`## ${title}`, 2);
42
+ if (h2) return h2;
43
+ const h1 = section(`# ${title}`, 1);
44
+ if (h1) return h1;
45
+ return `${String(text || "").trimEnd()}\n\n## ${title}\n\n${body.trimEnd()}\n`;
46
+ }
47
+
48
+ function appendJournal(root, { title, summary, target }) {
49
+ const file = path.join(root, ".solmet", "journal", `${today()}.md`);
50
+ ensureDir(path.dirname(file));
51
+ const lines = ["", `## ${nowIso()} · ${title}`, ""];
52
+ if (target) lines.push(`- Memory: \`${relative(root, target)}\``);
53
+ else lines.push(`- Summary: ${summary.replace(/\r?\n/g, "\n ")}`);
54
+ lines.push("");
55
+ fs.appendFileSync(file, lines.join("\n"), "utf8");
56
+ return file;
57
+ }
58
+
59
+ export function runRemember(args) {
60
+ const { flags } = parseArgs(args);
61
+ const root = projectRoot(flags);
62
+ const title = String(flags.title || "").replace(/\s+/g, " ").trim().slice(0, 80);
63
+ const summary = String(flags.summary || "").trim();
64
+ if (!title) throw new Error('必须提供 --title "<主题>"');
65
+ if (!summary) throw new Error('必须提供 --summary "<结论与依据>"');
66
+ if (summary.length > MAX_SUMMARY) {
67
+ throw new Error(`--summary 过长(${summary.length} 字符);上限 ${MAX_SUMMARY},请先压缩,不自动截断`);
68
+ }
69
+ if (flags.topic && flags.spec) {
70
+ throw new Error("同一事实只能写入一个位置:--topic 或 --spec");
71
+ }
72
+ const target = flags.topic
73
+ ? memoryTarget(root, "research", flags.topic)
74
+ : flags.spec
75
+ ? memoryTarget(root, "spec", flags.spec)
76
+ : "";
77
+ if (target) {
78
+ const body = `> 更新:${today()} · 来源:solmet remember\n\n${summary}`;
79
+ writeText(target, fs.existsSync(target) ? upsertSection(readText(target), title, body) : `# ${title}\n\n${body}\n`);
80
+ }
81
+ const journal = appendJournal(root, { title, summary, target });
82
+ refreshAgents(root);
83
+
84
+ if (flags.json) {
85
+ printJson({
86
+ ok: true,
87
+ title,
88
+ journal: relative(root, journal),
89
+ memory: target ? relative(root, target) : "",
90
+ });
91
+ return 0;
92
+ }
93
+ console.log(`已记录(remembered):${title}`);
94
+ console.log(`日志(journal):${relative(root, journal)}`);
95
+ console.log(target ? `记忆主题(memory):${relative(root, target)}` : "记忆主题(memory):未指定;摘要只写入 journal");
96
+ console.log("记忆目录(catalog)已刷新。");
97
+ return 0;
98
+ }
@@ -0,0 +1,26 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { SKILL_ROOT } from "../lib/paths.js";
4
+ import { parseArgs, printJson } from "./common.js";
5
+
6
+ export function runSkill(args) {
7
+ const { positional, flags } = parseArgs(args);
8
+ const name = positional[0];
9
+ if (!name) throw new Error("用法:solmet skill <name>");
10
+ const dirs = fs
11
+ .readdirSync(SKILL_ROOT, { withFileTypes: true })
12
+ .filter((entry) => entry.isDirectory())
13
+ .map((entry) => entry.name)
14
+ .sort();
15
+ if (!dirs.includes(name)) {
16
+ throw new Error(`未知技能:${name}\n可用技能:${dirs.join(", ")}`);
17
+ }
18
+ const file = path.join(SKILL_ROOT, name, "SKILL.md");
19
+ const text = fs.readFileSync(file, "utf8");
20
+ if (flags.json) {
21
+ printJson({ name, path: file, text });
22
+ return 0;
23
+ }
24
+ process.stdout.write(text.endsWith("\n") ? text : `${text}\n`);
25
+ return 0;
26
+ }
@@ -0,0 +1,49 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { projectRoot, parseArgs, printJson } from "./common.js";
4
+ import { readConfig } from "../lib/config.js";
5
+ import { activeRoot, makeTaskId, newTaskMeta, taskFile, writeTask } from "../lib/task.js";
6
+ import { buildBrief } from "../lib/brief.js";
7
+ import { writeIndex } from "../lib/memory.js";
8
+ import { ensureDir, readText, writeText } from "../lib/fsx.js";
9
+ import { TEMPLATE_ROOT } from "../lib/paths.js";
10
+ import { deriveTitle } from "../lib/title.js";
11
+
12
+ function template(root, name) {
13
+ const projectTemplate = path.join(root, ".solmet", "templates", name);
14
+ return readText(fs.existsSync(projectTemplate) ? projectTemplate : path.join(TEMPLATE_ROOT, name));
15
+ }
16
+
17
+ export function runStart(args) {
18
+ const { positional, flags } = parseArgs(args);
19
+ const root = projectRoot(flags);
20
+ const config = readConfig(root);
21
+ const request = positional.join(" ").trim();
22
+ if (!request) throw new Error('必须提供任务描述,例如:solmet start "列表筛选"');
23
+ const title = deriveTitle(request, flags.title);
24
+ const id = makeTaskId(title);
25
+ let taskDir = path.join(activeRoot(root), id);
26
+ let counter = 2;
27
+ while (fs.existsSync(taskDir)) {
28
+ taskDir = path.join(activeRoot(root), `${id}-${counter}`);
29
+ counter += 1;
30
+ }
31
+ ensureDir(taskDir);
32
+ const prd = template(root, "PRD.md").replaceAll("<任务标题>", title);
33
+ writeText(path.join(taskDir, "PRD.md"), prd);
34
+ const body = template(root, "TASK.md")
35
+ .replaceAll("<任务标题>", title)
36
+ .replaceAll("<任务请求>", request);
37
+ const meta = newTaskMeta({ id, title, request, root });
38
+ const task = { meta, body, file: taskFile(taskDir), dir: taskDir };
39
+ writeTask(task, meta, body);
40
+ writeIndex(root);
41
+ const brief = buildBrief(root, task, config);
42
+ if (flags.json) {
43
+ printJson({ ok: true, task: taskDir, meta, brief });
44
+ return 0;
45
+ }
46
+ console.log(`已创建任务:${taskDir}`);
47
+ console.log(brief);
48
+ return 0;
49
+ }
@@ -0,0 +1,76 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { projectRoot, parseArgs, printJson } from "./common.js";
4
+ import { readConfig } from "../lib/config.js";
5
+ import { activeTasks } from "../lib/memory.js";
6
+ import { findTask, nextAction, refreshTaskState } from "../lib/task.js";
7
+ import { artifactBi, gateStatusBi, statusBi } from "../lib/labels.js";
8
+
9
+ function artifactState(task, name) {
10
+ const relative = task.meta.artifacts?.[name];
11
+ if (!relative) return "no";
12
+ return fs.existsSync(path.join(task.dir, relative)) ? "yes" : "no";
13
+ }
14
+
15
+ function checksSummary(meta) {
16
+ if (!meta.checks?.length) return "none";
17
+ const passed = meta.checks.filter((check) => check.exit_code === 0).length;
18
+ return `${passed}/${meta.checks.length} passed`;
19
+ }
20
+
21
+ export function runStatus(args) {
22
+ const { flags } = parseArgs(args);
23
+ const root = projectRoot(flags);
24
+ const config = readConfig(root);
25
+ let task;
26
+ try {
27
+ task = findTask(root, flags.task || "");
28
+ } catch (error) {
29
+ const tasks = activeTasks(root);
30
+ if (tasks.length > 1) {
31
+ if (flags.json) {
32
+ printJson({ ok: true, tasks: tasks.map((item) => item.meta) });
33
+ } else {
34
+ console.log("有多个进行中的任务,请用 --task 指定:");
35
+ for (const item of tasks) {
36
+ console.log(`- ${item.meta.title} · ${item.meta.status} · ${path.relative(root, item.dir)}`);
37
+ }
38
+ }
39
+ return 0;
40
+ }
41
+ throw error;
42
+ }
43
+ refreshTaskState(task);
44
+ const meta = task.meta;
45
+ const payload = {
46
+ ok: true,
47
+ task: task.dir,
48
+ title: meta.title,
49
+ status: meta.status,
50
+ gates: {
51
+ spec: meta.gates?.spec?.status || "pending",
52
+ verified: meta.gates?.verified?.status || "pending",
53
+ },
54
+ checks: checksSummary(meta),
55
+ artifacts: {
56
+ prd: artifactState(task, "prd"),
57
+ notes: artifactState(task, "notes"),
58
+ changes: artifactState(task, "changes"),
59
+ },
60
+ next: nextAction(meta),
61
+ commands: config.commands,
62
+ };
63
+ if (flags.json) {
64
+ printJson(payload);
65
+ return 0;
66
+ }
67
+ const checks = payload.checks === "none"
68
+ ? "无(none)"
69
+ : payload.checks.replace(/\bpassed\b/, "通过(passed)");
70
+ console.log(`任务(Task):${meta.title}`);
71
+ console.log(`状态(Status):${statusBi(meta.status)}`);
72
+ console.log(`门禁(Gates):规格门禁(spec):${gateStatusBi(payload.gates.spec)} · 验收门禁(verified):${gateStatusBi(payload.gates.verified)}`);
73
+ console.log(`检查(Checks):${checks} · 规格(PRD):${artifactBi(payload.artifacts.prd)} · 笔记(NOTES):${artifactBi(payload.artifacts.notes)} · 变更说明(CHANGES):${artifactBi(payload.artifacts.changes)}`);
74
+ console.log(`下一步(Next action):${payload.next}`);
75
+ return 0;
76
+ }
@@ -0,0 +1,79 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { buildCatalog } from "./catalog.js";
4
+ import { readConfig } from "./config.js";
5
+ import { readText, writeText } from "./fsx.js";
6
+
7
+ const START = "<!-- solmet:start -->";
8
+ const END = "<!-- solmet:end -->";
9
+
10
+ const CHECK_LABELS = {
11
+ build: "构建",
12
+ typecheck: "类型检查",
13
+ lint: "静态检查",
14
+ test: "测试",
15
+ };
16
+
17
+ export function buildAgentsBlock(config, root = "") {
18
+ const commands = config.commands || {};
19
+ const commandLines = Object.entries(commands)
20
+ .filter(([, value]) => value)
21
+ .map(([name, value]) => `- ${CHECK_LABELS[name] || name}(${name}):\`${value}\``)
22
+ .join("\n") || "- 尚未检测到命令;请编辑 .solmet/config.json";
23
+ return `${START}
24
+ # solmet
25
+
26
+ 本项目使用 solmet 管理任务与记忆:任务状态只在 \`.solmet/tasks/active/<task>/TASK.md\`,长期知识在 \`.solmet/spec/\`、\`.solmet/research/\`、\`.solmet/journal/\`。
27
+
28
+ ## 工作方式
29
+
30
+ 1. 无进行中任务时先分类本轮请求:纯咨询(问流程/用法、解释代码、看日志只读排查且不改文件)直接回答,不运行 \`solmet start\`,不在 \`.solmet\` 写任务状态;trivial 改动(单文件、单行为、可逆、无接口/数据/权限/依赖变化、1–10 行)先一句话提议直接改,用户同意才跳过,改变行为或决定时用 \`solmet remember\` 留痕;其余变更(新功能、修改、修复)一律进入任务流程,不要问是否建任务;意图模糊或范围不清时先澄清或给方案,排查或澄清后确定要改的,仍必须 start;用户表示本轮不走任务流程时,尊重并只跳过本轮。
31
+ 2. 进入任务流程时用用户原话运行 \`solmet start "<需求>"\`;标题由 CLI 自动派生,不需要手动传 \`--title\`。再读它打印的 brief,按输出的“下一步技能(Next skill)”运行 \`solmet skill <name>\` 并执行;**每次状态变化后重新运行 \`solmet brief\`**。建任务不等于开始实现:先完成 grill/spec 和人工确认再写代码。
32
+ 3. 已有进行中任务时,询问进度或继续任务先运行 \`solmet brief\`(多个任务用 \`--task\`),按 Next skill 执行。
33
+ 4. 人工门只记录用户明确原话;检查结果由 \`solmet check\` 记录。
34
+ 5. \`verifying\` 阶段必须加载 \`solmet skill check\`,按 PRD 的人工验收清单核对;\`--app-url\` 可选。未记录人工确认前不得运行 \`gate verified\`。
35
+ 6. 用户可见回复用“中文(English/原命令)”,命令放在代码格式中。
36
+ 7. 实现前运行基线(\`solmet doctor --baseline\`);检查失败在未改动文件且基线同样失败时,最多一次诊断就停下来问。
37
+ 8. 不要修改人工验收预期或放宽断言来通过检查;不要在没有人工确认时运行 gate 或 archive,也不要创建第二套任务状态。
38
+ 9. 不用 sed/perl 改配置,不切换全局 Node;共享构建配置的改动必须经用户同意并记录例外。
39
+ 10. 问“上次/之前怎么定的”先运行 \`solmet recall "<关键词>"\`;结果是历史记录,以代码为准。
40
+ 11. 没有任务的讨论、调试结论或架构决定用 \`solmet remember --title "<主题>" --summary "<结论与依据>"\` 记录,可加 \`--topic\` 或 \`--spec\`;任务内知识仍由 archive 与 \`solmet skill memory-recording\` 负责。
41
+
42
+ ## 检查命令
43
+
44
+ ${commandLines}
45
+ ${root ? `\n${buildCatalog(root)}\n` : ""}
46
+ <!-- solmet:end -->`;
47
+ }
48
+
49
+ export function upsertAgentsBlock(root, block) {
50
+ const file = path.join(root, "AGENTS.md");
51
+ const existing = readText(file, "");
52
+ if (!existing.trim()) {
53
+ writeText(file, block + "\n");
54
+ return file;
55
+ }
56
+ const start = existing.indexOf(START);
57
+ const end = existing.indexOf(END, start);
58
+ if (start >= 0 && end >= 0) {
59
+ const next = existing.slice(0, start) + block + existing.slice(end + END.length);
60
+ writeText(file, next);
61
+ } else {
62
+ writeText(file, existing.trimEnd() + "\n\n" + block + "\n");
63
+ }
64
+ return file;
65
+ }
66
+
67
+ export function refreshAgents(root) {
68
+ const config = readConfig(root);
69
+ return upsertAgentsBlock(root, buildAgentsBlock(config, root));
70
+ }
71
+
72
+ export function hasAgentsBlock(root) {
73
+ const text = readText(path.join(root, "AGENTS.md"), "");
74
+ return text.includes(START) && text.includes(END);
75
+ }
76
+
77
+ export function agentsFileExists(root) {
78
+ return fs.existsSync(path.join(root, "AGENTS.md"));
79
+ }
@@ -0,0 +1,78 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { mapFile } from "./map.js";
4
+ import { recall } from "./memory.js";
5
+ import { nextAction } from "./task.js";
6
+ import { relative } from "./fsx.js";
7
+ import { nextSkillBi, statusBi } from "./labels.js";
8
+
9
+ function fileState(file) {
10
+ return fs.existsSync(file) ? "exists" : "missing";
11
+ }
12
+
13
+ export function nextSkill(meta) {
14
+ if (meta.status === "draft") return "spec";
15
+ if (meta.status === "spec-ready" || meta.status === "implementing") return "implement";
16
+ if (meta.status === "verifying") return "check";
17
+ if (meta.status === "verified") return "archive";
18
+ return "archive";
19
+ }
20
+
21
+ export function buildBrief(root, task, config) {
22
+ const meta = task.meta;
23
+ const prd = path.join(task.dir, meta.artifacts?.prd || "PRD.md");
24
+ const notes = path.join(task.dir, meta.artifacts?.notes || "NOTES.md");
25
+ const skill = nextSkill(meta);
26
+ const memory = recall(root, `${meta.title} ${meta.request || ""}`);
27
+ const lines = [
28
+ `# 任务简报(brief)· ${meta.title}`,
29
+ "",
30
+ `- 任务(Task):${meta.id}`,
31
+ `- 状态(Status):${statusBi(meta.status)}`,
32
+ `- 下一步(Next action):${nextAction(meta)}`,
33
+ `- 下一步技能(Next skill):\`solmet skill ${skill}\`(${nextSkillBi(skill)})`,
34
+ "",
35
+ "## 必读",
36
+ `- PRD.md: ${fileState(prd)}`,
37
+ `- NOTES.md: ${fs.existsSync(notes) ? "exists" : "可选(scope 例外时创建)"}`,
38
+ `- TASK.md: ${path.join(task.dir, "TASK.md")}`,
39
+ ];
40
+ const map = mapFile(root);
41
+ if (fs.existsSync(map)) {
42
+ lines.push("", "## 项目地图", `- ${relative(root, map)}(按需读相关段落;代码优先)`);
43
+ }
44
+ lines.push(
45
+ "",
46
+ "## 规则",
47
+ "- 代码前必须有已确认的 PRD;不要先写业务代码再补。",
48
+ "- 不要为了让检查变绿而修改人工验收预期或放宽断言。",
49
+ "- 人工门只记录用户明确确认;沉默/含糊/未回复不放行。",
50
+ "- 检查结果由 solmet check 记录;不要手填通过。",
51
+ );
52
+ if (memory.length) {
53
+ lines.push("", "## 相关记忆");
54
+ for (const item of memory) {
55
+ lines.push(`- ${item.path}: ${item.snippet}`);
56
+ }
57
+ }
58
+ lines.push("", "## 给用户的确认句", `“${gateQuestion(meta)}”`);
59
+ let text = lines.join("\n");
60
+ if (Buffer.byteLength(text, "utf8") > 2048) {
61
+ const clipped = lines.slice(0, 20).join("\n");
62
+ text = clipped.slice(0, 1900) + "\n...(brief 已截断,详见 TASK.md)";
63
+ }
64
+ return text;
65
+ }
66
+
67
+ export function gateQuestion(meta) {
68
+ if (meta.status === "draft") {
69
+ return "请确认 PRD 的范围、验收标准和人工验收清单;确认后我再开始写代码。";
70
+ }
71
+ if (meta.status === "verifying") {
72
+ return "请按 PRD 的人工验收清单核对;确认后我再记录验收门禁。";
73
+ }
74
+ if (meta.status === "verified") {
75
+ return "任务已验收;确认后我归档。";
76
+ }
77
+ return "当前没有待确认的问题。";
78
+ }
@@ -0,0 +1,71 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { listFilesDeep, readText, relative } from "./fsx.js";
4
+
5
+ export const CATALOG_START = "<!-- solmet:catalog:start -->";
6
+ export const CATALOG_END = "<!-- solmet:catalog:end -->";
7
+ export const CATALOG_LIMIT = 1536;
8
+
9
+ const EXCLUDED = new Set(["index.md", "readme.md", "project-context.md"]);
10
+
11
+ function titleOf(text, file) {
12
+ const heading = text.match(/^#\s+(.+?)\s*$/m);
13
+ return heading ? heading[1].trim() : path.basename(file, ".md");
14
+ }
15
+
16
+ function summaryOf(text) {
17
+ const lines = String(text || "").replace(/\r\n/g, "\n").split("\n");
18
+ for (const line of lines) {
19
+ const value = line.trim();
20
+ if (!value || /^#{1,6}\s/.test(value) || /^<!--/.test(value) || /^>/.test(value)) continue;
21
+ const cleaned = value.replace(/^[-*]\s+/, "").trim();
22
+ if (!cleaned) continue;
23
+ return cleaned.length > 88 ? `${cleaned.slice(0, 87)}…` : cleaned;
24
+ }
25
+ return "(无摘要)";
26
+ }
27
+
28
+ function topicFiles(root) {
29
+ const state = path.join(root, ".solmet");
30
+ return [...listFilesDeep(path.join(state, "spec"), ".md"), ...listFilesDeep(path.join(state, "research"), ".md")]
31
+ .filter((file) => {
32
+ if (relative(root, file).toLowerCase().includes("/decisions/")) return false;
33
+ return !EXCLUDED.has(path.basename(file).toLowerCase());
34
+ });
35
+ }
36
+
37
+ export function memoryTopics(root, limit = 10) {
38
+ return topicFiles(root)
39
+ .map((file) => {
40
+ const stat = fs.statSync(file);
41
+ const text = readText(file);
42
+ return {
43
+ file,
44
+ title: titleOf(text, file),
45
+ summary: summaryOf(text),
46
+ updated_at: stat.mtime.toISOString(),
47
+ mtime: stat.mtimeMs,
48
+ };
49
+ })
50
+ .sort((a, b) => b.mtime - a.mtime)
51
+ .slice(0, limit);
52
+ }
53
+
54
+ export function buildCatalog(root, limit = 10) {
55
+ const topics = memoryTopics(root, limit);
56
+ const lines = [
57
+ CATALOG_START,
58
+ "## 记忆目录",
59
+ "",
60
+ "> 生成视图,正文以文件为准;问“上次/之前怎么定的”先 `solmet recall \"<关键词>\"`。",
61
+ "",
62
+ ];
63
+ if (!topics.length) lines.push("- 暂无 spec/research 主题。");
64
+ for (const topic of topics) {
65
+ const line = `- ${topic.title}:${topic.summary}(\`${relative(root, topic.file)}\`)`;
66
+ if (Buffer.byteLength([...lines, line, CATALOG_END].join("\n"), "utf8") > CATALOG_LIMIT) break;
67
+ lines.push(line);
68
+ }
69
+ lines.push(CATALOG_END);
70
+ return lines.join("\n");
71
+ }