@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.
- package/LICENSE +21 -0
- package/README.md +154 -2
- package/README.zh.md +155 -0
- package/bin/solmet.js +11 -0
- package/package.json +39 -4
- package/skills/archive/SKILL.md +15 -0
- package/skills/check/SKILL.md +20 -0
- package/skills/grill/SKILL.md +23 -0
- package/skills/grilling/SKILL.md +22 -0
- package/skills/implement/SKILL.md +18 -0
- package/skills/map/SKILL.md +42 -0
- package/skills/memory-recording/SKILL.md +40 -0
- package/skills/spec/SKILL.md +24 -0
- package/skills/spec-writing/SKILL.md +17 -0
- package/skills/start/SKILL.md +25 -0
- package/skills/tdd/SKILL.md +14 -0
- package/src/cli.js +83 -0
- package/src/commands/archive.js +35 -0
- package/src/commands/brief.js +14 -0
- package/src/commands/check.js +71 -0
- package/src/commands/common.js +65 -0
- package/src/commands/doctor.js +208 -0
- package/src/commands/gate.js +148 -0
- package/src/commands/init.js +87 -0
- package/src/commands/map.js +64 -0
- package/src/commands/recall.js +41 -0
- package/src/commands/remember.js +98 -0
- package/src/commands/skill.js +26 -0
- package/src/commands/start.js +49 -0
- package/src/commands/status.js +76 -0
- package/src/lib/agents.js +79 -0
- package/src/lib/brief.js +78 -0
- package/src/lib/catalog.js +71 -0
- package/src/lib/check.js +360 -0
- package/src/lib/config.js +55 -0
- package/src/lib/detect.js +58 -0
- package/src/lib/fsx.js +117 -0
- package/src/lib/labels.js +92 -0
- package/src/lib/map.js +261 -0
- package/src/lib/memory.js +273 -0
- package/src/lib/paths.js +10 -0
- package/src/lib/router.js +49 -0
- package/src/lib/task.js +189 -0
- package/src/lib/title.js +43 -0
- package/src/lib/version.js +7 -0
- package/templates/NOTES.md +17 -0
- package/templates/PRD.md +25 -0
- package/templates/PROJECT-CONTEXT.md +25 -0
- package/templates/TASK.md +7 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: solmet-tdd
|
|
3
|
+
description: Red-green-refactor at the agreed seam, one vertical slice at a time.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TDD discipline
|
|
7
|
+
|
|
8
|
+
- Work one vertical slice at a time.
|
|
9
|
+
- Start with the smallest failing check at the agreed seam.
|
|
10
|
+
- Make it pass with the simplest change.
|
|
11
|
+
- Refactor while keeping the check green.
|
|
12
|
+
- Do not change acceptance criteria or the PRD manual acceptance list to make the check pass.
|
|
13
|
+
- If the seam is wrong, stop and revisit the spec; do not invent a new seam mid-implementation.
|
|
14
|
+
- Keep tests at external behavior; avoid coupling to private helpers.
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { runInit } from "./commands/init.js";
|
|
2
|
+
import { runStart } from "./commands/start.js";
|
|
3
|
+
import { runStatus } from "./commands/status.js";
|
|
4
|
+
import { runBrief } from "./commands/brief.js";
|
|
5
|
+
import { runGate } from "./commands/gate.js";
|
|
6
|
+
import { runCheck } from "./commands/check.js";
|
|
7
|
+
import { runArchive } from "./commands/archive.js";
|
|
8
|
+
import { runRecall } from "./commands/recall.js";
|
|
9
|
+
import { runRemember } from "./commands/remember.js";
|
|
10
|
+
import { runDoctor } from "./commands/doctor.js";
|
|
11
|
+
import { runSkill } from "./commands/skill.js";
|
|
12
|
+
import { runMap } from "./commands/map.js";
|
|
13
|
+
import { VERSION } from "./lib/version.js";
|
|
14
|
+
|
|
15
|
+
const HELP = `solmet ${VERSION}
|
|
16
|
+
|
|
17
|
+
用法:
|
|
18
|
+
solmet init [--agent qoder] [--vcs git|svn|none] [--force] [--json]
|
|
19
|
+
solmet start "<任务描述>" [--title ...] [--json]
|
|
20
|
+
solmet status [--task <path>] [--json]
|
|
21
|
+
solmet brief [--task <path>] [--json]
|
|
22
|
+
solmet gate spec --approve [--by <人>] --confirmation "<用户原话>"
|
|
23
|
+
solmet gate spec --reject [--by <人>] --reason "..."
|
|
24
|
+
solmet gate verified --approve [--app-url <URL>] [--by <人>] --confirmation "<用户原话>" [--allow-pre-existing]
|
|
25
|
+
solmet check [--task <path>] [--json]
|
|
26
|
+
solmet recall "<查询>" [--source memory|archive|all] [--limit N] [--max-chars N] [--json]
|
|
27
|
+
solmet remember --title "<主题>" --summary "<结论与依据>" [--topic <research文件>] [--spec <spec文件>] [--json]
|
|
28
|
+
solmet archive [--task <path>] [--force] [--json]
|
|
29
|
+
solmet map [--init|--skeleton] [--json]
|
|
30
|
+
solmet doctor [--root <path>] [--deep] [--baseline [--only <名称>|--all]] [--json]
|
|
31
|
+
solmet skill <name>
|
|
32
|
+
|
|
33
|
+
流程:
|
|
34
|
+
start → grill → spec(PRD + 人工验收)→ gate spec → implement → check → 人工验收 → gate verified → archive
|
|
35
|
+
|
|
36
|
+
规则:
|
|
37
|
+
- 纯咨询、解释代码、只读排查不建任务;只有产生代码/文件变更才 start。
|
|
38
|
+
- 所有任务走同一流程。人工门只记录用户明确确认。
|
|
39
|
+
- check 运行 build/typecheck/lint/test,记录日志与失败分类;changes 是变更说明草稿,不自动提交。
|
|
40
|
+
- 不执行任何 git/svn 写操作;VCS 只读用于基线溯源。
|
|
41
|
+
- 可选:solmet map 是惰性项目地图,默认不预生成,不参与门禁。
|
|
42
|
+
- 用户只需要 init、描述任务和两次确认;其余由 agent 按 brief 执行。
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
export async function main(argv) {
|
|
46
|
+
const [command, ...rest] = argv;
|
|
47
|
+
if (!command || command === "--help" || command === "-h" || command === "help") {
|
|
48
|
+
process.stdout.write(HELP);
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
if (command === "--version" || command === "-v") {
|
|
52
|
+
process.stdout.write(`solmet ${VERSION}\n`);
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
switch (command) {
|
|
56
|
+
case "init":
|
|
57
|
+
return runInit(rest);
|
|
58
|
+
case "start":
|
|
59
|
+
return runStart(rest);
|
|
60
|
+
case "status":
|
|
61
|
+
return runStatus(rest);
|
|
62
|
+
case "brief":
|
|
63
|
+
return runBrief(rest);
|
|
64
|
+
case "gate":
|
|
65
|
+
return runGate(rest);
|
|
66
|
+
case "check":
|
|
67
|
+
return runCheck(rest);
|
|
68
|
+
case "archive":
|
|
69
|
+
return runArchive(rest);
|
|
70
|
+
case "recall":
|
|
71
|
+
return runRecall(rest);
|
|
72
|
+
case "remember":
|
|
73
|
+
return runRemember(rest);
|
|
74
|
+
case "map":
|
|
75
|
+
return runMap(rest);
|
|
76
|
+
case "doctor":
|
|
77
|
+
return runDoctor(rest);
|
|
78
|
+
case "skill":
|
|
79
|
+
return runSkill(rest);
|
|
80
|
+
default:
|
|
81
|
+
throw new Error(`未知命令:${command}\n\n${HELP}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { loadTask, parseArgs, printJson } from "./common.js";
|
|
3
|
+
import { writeChanges } from "../lib/check.js";
|
|
4
|
+
import { refreshAgents } from "../lib/agents.js";
|
|
5
|
+
import { archiveTask } from "../lib/memory.js";
|
|
6
|
+
import { relative } from "../lib/fsx.js";
|
|
7
|
+
import { sha256File } from "../lib/task.js";
|
|
8
|
+
|
|
9
|
+
export function runArchive(args) {
|
|
10
|
+
const { flags } = parseArgs(args);
|
|
11
|
+
const { root, task } = loadTask(flags);
|
|
12
|
+
if (task.meta.status !== "verified" && !flags.force) {
|
|
13
|
+
throw new Error(`任务状态(status)是 ${task.meta.status},只有已验收(verified)后才能归档(archive);测试时可加 --force`);
|
|
14
|
+
}
|
|
15
|
+
if (task.meta.gates?.verified?.status === "approved") {
|
|
16
|
+
writeChanges(task);
|
|
17
|
+
task.meta.gates.verified.changes_sha256 = sha256File(
|
|
18
|
+
path.join(task.dir, task.meta.artifacts?.changes || "CHANGES.md")
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const result = archiveTask(root, task);
|
|
22
|
+
refreshAgents(root);
|
|
23
|
+
if (flags.json) {
|
|
24
|
+
printJson({
|
|
25
|
+
ok: true,
|
|
26
|
+
task: relative(root, result.target),
|
|
27
|
+
journal: relative(root, result.journal),
|
|
28
|
+
});
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
console.log(`已归档(archived):${relative(root, result.target)}`);
|
|
32
|
+
console.log(`已写日志(journal):${relative(root, result.journal)}`);
|
|
33
|
+
console.log("如有可复用知识:先运行 `solmet skill memory-recording` 再写入 .solmet/spec 或 .solmet/research;不要凭印象直接写。");
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { loadTask, parseArgs, printJson } from "./common.js";
|
|
2
|
+
import { buildBrief } from "../lib/brief.js";
|
|
3
|
+
|
|
4
|
+
export function runBrief(args) {
|
|
5
|
+
const { flags } = parseArgs(args);
|
|
6
|
+
const { root, config, task } = loadTask(flags);
|
|
7
|
+
const brief = buildBrief(root, task, config);
|
|
8
|
+
if (flags.json) {
|
|
9
|
+
printJson({ ok: true, task: task.dir, status: task.meta.status, brief });
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
console.log(brief);
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { loadTask, parseArgs, printJson } from "./common.js";
|
|
4
|
+
import { classifyCheck, collectProvenance, runChecks, writeChanges } from "../lib/check.js";
|
|
5
|
+
import { writeTask } from "../lib/task.js";
|
|
6
|
+
import { checkBi, checkResultBi, classificationBi } from "../lib/labels.js";
|
|
7
|
+
|
|
8
|
+
export async function runCheck(args) {
|
|
9
|
+
const { flags } = parseArgs(args);
|
|
10
|
+
const { root, config, task } = loadTask(flags);
|
|
11
|
+
const meta = task.meta;
|
|
12
|
+
if (meta.status === "archived") throw new Error("任务已归档(archived),不能再检查");
|
|
13
|
+
if (meta.gates?.spec?.status !== "approved") {
|
|
14
|
+
throw new Error("规格门禁(spec)尚未通过;先确认 PRD,再写代码");
|
|
15
|
+
}
|
|
16
|
+
if (meta.gates?.verified?.status === "approved") {
|
|
17
|
+
meta.gates.verified = { status: "pending" };
|
|
18
|
+
}
|
|
19
|
+
const results = runChecks(meta.project_root || root, config, task.dir);
|
|
20
|
+
const provenance = collectProvenance(meta.project_root || root, config);
|
|
21
|
+
const checks = results.map((result) => ({
|
|
22
|
+
...result,
|
|
23
|
+
classification: classifyCheck(result, meta.baseline, provenance),
|
|
24
|
+
provenance,
|
|
25
|
+
}));
|
|
26
|
+
meta.checks = checks;
|
|
27
|
+
const allPassed = checks.length > 0 && checks.every((check) => check.exit_code === 0);
|
|
28
|
+
const blocking = checks.filter((check) => (
|
|
29
|
+
check.exit_code !== 0 && !["pre-existing", "unrelated"].includes(check.classification)
|
|
30
|
+
));
|
|
31
|
+
const canVerify = blocking.length === 0;
|
|
32
|
+
meta.status = canVerify ? "verifying" : "implementing";
|
|
33
|
+
writeTask(task, meta, task.body);
|
|
34
|
+
let changes = "";
|
|
35
|
+
if (canVerify) {
|
|
36
|
+
changes = writeChanges(task);
|
|
37
|
+
} else {
|
|
38
|
+
const staleChanges = path.join(task.dir, meta.artifacts?.changes || "CHANGES.md");
|
|
39
|
+
if (fs.existsSync(staleChanges)) fs.unlinkSync(staleChanges);
|
|
40
|
+
}
|
|
41
|
+
if (flags.json) {
|
|
42
|
+
printJson({
|
|
43
|
+
ok: canVerify,
|
|
44
|
+
all_passed: allPassed,
|
|
45
|
+
blocking: blocking.map((check) => check.name),
|
|
46
|
+
checks,
|
|
47
|
+
changes,
|
|
48
|
+
status: meta.status,
|
|
49
|
+
});
|
|
50
|
+
return canVerify ? 0 : 1;
|
|
51
|
+
}
|
|
52
|
+
for (const result of checks) {
|
|
53
|
+
const suffix = result.exit_code === 0 ? "" : `(${classificationBi(result.classification)})`;
|
|
54
|
+
console.log(`[${checkResultBi(result.exit_code)}] ${checkBi(result.name)}:\`${result.command}\`${suffix}`);
|
|
55
|
+
console.log(` 日志(log):${result.log}`);
|
|
56
|
+
if (result.exit_code !== 0 && result.stderr_tail) console.log(result.stderr_tail);
|
|
57
|
+
}
|
|
58
|
+
if (canVerify) {
|
|
59
|
+
if (allPassed) {
|
|
60
|
+
console.log(`检查全部通过(all checks passed);变更说明(CHANGES):${changes}`);
|
|
61
|
+
} else {
|
|
62
|
+
console.log(`没有本次引入的失败(no new failures);既有/无关失败(pre-existing/unrelated)需要在验收时记录例外。变更说明(CHANGES):${changes}`);
|
|
63
|
+
}
|
|
64
|
+
const allow = allPassed ? "" : " --allow-pre-existing";
|
|
65
|
+
console.log(`下一步技能(Next skill):检查与验收(\`solmet skill check\`)。`);
|
|
66
|
+
console.log(`下一步(Next action):按 PRD 的人工验收清单核对;确认后记录验收门禁(\`solmet gate verified --approve [--app-url <URL>]${allow} --confirmation "<原话>"\`)。`);
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
console.log(`检查未通过(checks failed);本次引入失败(blocking):${blocking.map((check) => check.name).join("、")};修复后重跑检查(\`solmet check\`)。不要放宽断言或删除验收项。`);
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readConfig, requireProjectRoot } from "../lib/config.js";
|
|
3
|
+
import { findTask, refreshTaskState } from "../lib/task.js";
|
|
4
|
+
|
|
5
|
+
const BOOLEAN = new Set([
|
|
6
|
+
"json",
|
|
7
|
+
"force",
|
|
8
|
+
"help",
|
|
9
|
+
"deep",
|
|
10
|
+
"init",
|
|
11
|
+
"skeleton",
|
|
12
|
+
"baseline",
|
|
13
|
+
"all",
|
|
14
|
+
"allow-pre-existing",
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
export function parseArgs(args) {
|
|
18
|
+
const positional = [];
|
|
19
|
+
const flags = {};
|
|
20
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
21
|
+
const arg = args[i];
|
|
22
|
+
if (!arg.startsWith("--")) {
|
|
23
|
+
positional.push(arg);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const body = arg.slice(2);
|
|
27
|
+
const eq = body.indexOf("=");
|
|
28
|
+
if (eq >= 0) {
|
|
29
|
+
flags[body.slice(0, eq)] = body.slice(eq + 1);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (BOOLEAN.has(body)) {
|
|
33
|
+
flags[body] = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const next = args[i + 1];
|
|
37
|
+
if (next !== undefined && !next.startsWith("--")) {
|
|
38
|
+
flags[body] = next;
|
|
39
|
+
i += 1;
|
|
40
|
+
} else {
|
|
41
|
+
flags[body] = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return { positional, flags };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function projectRoot(flags) {
|
|
48
|
+
return flags.root ? path.resolve(process.cwd(), flags.root) : requireProjectRoot(process.cwd());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function loadTask(flags) {
|
|
52
|
+
const root = projectRoot(flags);
|
|
53
|
+
const config = readConfig(root);
|
|
54
|
+
const task = findTask(root, flags.task || "");
|
|
55
|
+
refreshTaskState(task);
|
|
56
|
+
return { root, config, task };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function printJson(value) {
|
|
60
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function fail(message) {
|
|
64
|
+
throw new Error(message);
|
|
65
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { configFile, findProjectRoot, readConfig } from "../lib/config.js";
|
|
5
|
+
import { hasAgentsBlock } from "../lib/agents.js";
|
|
6
|
+
import { CATALOG_END, CATALOG_LIMIT, CATALOG_START, memoryTopics } from "../lib/catalog.js";
|
|
7
|
+
import { activeTasks } from "../lib/memory.js";
|
|
8
|
+
import { ROUTER_AGENT, ROUTER_FILE, ROUTER_SCHEMA, readRouterSchema, routerPath } from "../lib/router.js";
|
|
9
|
+
import { VERSION } from "../lib/version.js";
|
|
10
|
+
import { mapFile, parseMapMeta } from "../lib/map.js";
|
|
11
|
+
import { detectVcsInfo } from "../lib/detect.js";
|
|
12
|
+
import { readJson, readText, relative } from "../lib/fsx.js";
|
|
13
|
+
import { SKILL_ROOT } from "../lib/paths.js";
|
|
14
|
+
import { parseArgs, printJson } from "./common.js";
|
|
15
|
+
import { levelBi } from "../lib/labels.js";
|
|
16
|
+
import { writeBaseline } from "../lib/check.js";
|
|
17
|
+
import { findTask } from "../lib/task.js";
|
|
18
|
+
|
|
19
|
+
function checkNode() {
|
|
20
|
+
const [major, minor] = process.versions.node.split(".").map(Number);
|
|
21
|
+
return major > 18 || (major === 18 && minor >= 17)
|
|
22
|
+
? { level: "PASS", message: `Node ${process.versions.node}` }
|
|
23
|
+
: { level: "FAIL", message: `Node ${process.versions.node},需要 >=18.17` };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function checkCommand(command) {
|
|
27
|
+
if (!command) return { level: "WARN", message: "未配置命令" };
|
|
28
|
+
const result = spawnSync(command, {
|
|
29
|
+
shell: true,
|
|
30
|
+
encoding: "utf8",
|
|
31
|
+
timeout: 15000,
|
|
32
|
+
windowsHide: true,
|
|
33
|
+
});
|
|
34
|
+
return result.status === 0
|
|
35
|
+
? { level: "PASS", message: command }
|
|
36
|
+
: { level: "FAIL", message: `${command}(exit ${result.status})` };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function probeVcs(root, vcs) {
|
|
40
|
+
const [command, args] = vcs === "git"
|
|
41
|
+
? ["git", ["rev-parse", "--show-toplevel"]]
|
|
42
|
+
: ["svn", ["info", "--show-item", "wc-root"]];
|
|
43
|
+
// SVN 不会从版本库外的普通子目录向上找工作副本,探测要落在实际工作副本根。
|
|
44
|
+
const detected = detectVcsInfo(root);
|
|
45
|
+
const cwd = vcs === "svn" && detected.vcs === "svn" ? detected.root : root;
|
|
46
|
+
const result = spawnSync(command, args, {
|
|
47
|
+
cwd,
|
|
48
|
+
encoding: "utf8",
|
|
49
|
+
timeout: 15000,
|
|
50
|
+
windowsHide: true,
|
|
51
|
+
});
|
|
52
|
+
return result.status === 0 ? String(result.stdout || "").trim() : "";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function checkConfigured(root, command) {
|
|
56
|
+
if (!command) return { level: "WARN", message: "未配置命令" };
|
|
57
|
+
const match = command.match(/^(?:npm|pnpm|yarn|bun)(?:\s+run)?\s+([A-Za-z0-9:_-]+)/);
|
|
58
|
+
if (!match) return { level: "PASS", message: `${command}(已配置,未执行)` };
|
|
59
|
+
const scripts = readJson(path.join(root, "package.json"), {})?.scripts || {};
|
|
60
|
+
return scripts[match[1]]
|
|
61
|
+
? { level: "PASS", message: `${command}(script 存在)` }
|
|
62
|
+
: { level: "FAIL", message: `${command}(package.json 缺少 script)` };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function runDoctor(args) {
|
|
66
|
+
const { flags } = parseArgs(args);
|
|
67
|
+
const root = flags.root
|
|
68
|
+
? path.resolve(process.cwd(), flags.root)
|
|
69
|
+
: findProjectRoot(process.cwd());
|
|
70
|
+
const rows = [];
|
|
71
|
+
rows.push(checkNode());
|
|
72
|
+
rows.push({ level: "PASS", message: `CLI ${VERSION}` });
|
|
73
|
+
if (!root) {
|
|
74
|
+
rows.push({ level: "FAIL", message: "未找到 .solmet/config.json;先运行 solmet init" });
|
|
75
|
+
return finish(rows, flags.json);
|
|
76
|
+
}
|
|
77
|
+
rows.push({ level: "PASS", message: `项目根:${root}` });
|
|
78
|
+
let config;
|
|
79
|
+
try {
|
|
80
|
+
config = readConfig(root);
|
|
81
|
+
rows.push({ level: "PASS", message: `.solmet/config.json` });
|
|
82
|
+
} catch (error) {
|
|
83
|
+
rows.push({ level: "FAIL", message: error.message });
|
|
84
|
+
return finish(rows, flags.json);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for (const [name, command] of Object.entries(config.commands || {})) {
|
|
88
|
+
if (command) rows.push(flags.deep ? checkCommand(command) : checkConfigured(root, command));
|
|
89
|
+
}
|
|
90
|
+
if (!Object.values(config.commands || {}).some(Boolean)) {
|
|
91
|
+
rows.push({ level: "FAIL", message: "没有可执行的检查命令" });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (config.vcs === "git" || config.vcs === "svn") {
|
|
95
|
+
const vcsRoot = probeVcs(root, config.vcs);
|
|
96
|
+
if (!vcsRoot) {
|
|
97
|
+
rows.push({ level: "WARN", message: `配置为 ${config.vcs},但当前目录不是 ${config.vcs} 工作副本(探测命令失败)` });
|
|
98
|
+
} else if (config.vcs === "svn") {
|
|
99
|
+
rows.push({ level: "PASS", message: `svn 工作区:${vcsRoot}(只读;solmet 不提交)` });
|
|
100
|
+
} else {
|
|
101
|
+
rows.push({ level: "PASS", message: `git 仓库:${vcsRoot}(只读;solmet 不提交)` });
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
rows.push({ level: "WARN", message: "未检测到 git/svn;不影响使用,基线不记录 VCS 溯源" });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
rows.push(hasAgentsBlock(root)
|
|
108
|
+
? { level: "PASS", message: "AGENTS.md 托管块" }
|
|
109
|
+
: { level: "WARN", message: "AGENTS.md 缺少 solmet 托管块" });
|
|
110
|
+
|
|
111
|
+
const agentsText = readText(path.join(root, "AGENTS.md"));
|
|
112
|
+
const catalogStart = agentsText.indexOf(CATALOG_START);
|
|
113
|
+
const catalogEnd = agentsText.indexOf(CATALOG_END, catalogStart);
|
|
114
|
+
if (catalogStart >= 0 && catalogEnd > catalogStart) {
|
|
115
|
+
const bytes = Buffer.byteLength(agentsText.slice(catalogStart, catalogEnd + CATALOG_END.length), "utf8");
|
|
116
|
+
rows.push(bytes <= CATALOG_LIMIT
|
|
117
|
+
? { level: "PASS", message: `AGENTS 记忆目录:${bytes} B` }
|
|
118
|
+
: { level: "WARN", message: `AGENTS 记忆目录 ${bytes} B 超过 ${CATALOG_LIMIT} B(重跑 solmet init 或精简摘要)` });
|
|
119
|
+
} else if (hasAgentsBlock(root)) {
|
|
120
|
+
rows.push({ level: "WARN", message: "AGENTS 记忆目录缺失(重跑 solmet init)" });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const largeTopics = memoryTopics(root, Number.MAX_SAFE_INTEGER)
|
|
124
|
+
.map((topic) => ({ ...topic, bytes: Buffer.byteLength(readText(topic.file), "utf8") }))
|
|
125
|
+
.filter((topic) => topic.bytes > 4096);
|
|
126
|
+
if (largeTopics.length) {
|
|
127
|
+
const names = largeTopics.slice(0, 3).map((topic) => relative(root, topic.file)).join(", ");
|
|
128
|
+
rows.push({
|
|
129
|
+
level: "WARN",
|
|
130
|
+
message: `记忆主题超过 4KB:${names}${largeTopics.length > 3 ? ` 等 ${largeTopics.length} 个` : ""};建议拆分或压缩`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (config.agent === ROUTER_AGENT) {
|
|
135
|
+
if (!fs.existsSync(routerPath(root))) {
|
|
136
|
+
rows.push({ level: "WARN", message: `缺少 Qoder 路由技能:${ROUTER_FILE}(重跑 solmet init)` });
|
|
137
|
+
} else {
|
|
138
|
+
const version = readRouterSchema(root);
|
|
139
|
+
if (!version) {
|
|
140
|
+
rows.push({ level: "WARN", message: `Qoder 路由技能缺少版本标记:${ROUTER_FILE}(重跑 solmet init)` });
|
|
141
|
+
} else if (version !== ROUTER_SCHEMA) {
|
|
142
|
+
rows.push({ level: "WARN", message: `Qoder 路由技能模板 ${version} 与当前 ${ROUTER_SCHEMA} 不一致(重跑 solmet init)` });
|
|
143
|
+
} else {
|
|
144
|
+
rows.push({ level: "PASS", message: "Qoder 路由技能已生成" });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
rows.push({ level: "PASS", message: `路由技能:agent=${config.agent},使用 AGENTS.md` });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const skills = ["start", "grill", "spec", "implement", "check", "archive", "map"];
|
|
152
|
+
const missingSkills = skills.filter((name) => !fs.existsSync(path.join(SKILL_ROOT, name, "SKILL.md")));
|
|
153
|
+
rows.push(missingSkills.length
|
|
154
|
+
? { level: "FAIL", message: `包内缺少技能:${missingSkills.join(", ")}` }
|
|
155
|
+
: { level: "PASS", message: "工作流技能随包提供(solmet skill <name>)" });
|
|
156
|
+
|
|
157
|
+
const map = mapFile(root);
|
|
158
|
+
if (fs.existsSync(map)) {
|
|
159
|
+
const text = readText(map);
|
|
160
|
+
const meta = parseMapMeta(text);
|
|
161
|
+
rows.push(meta
|
|
162
|
+
? { level: "PASS", message: `项目地图:存在(${Buffer.byteLength(text, "utf8")} B,缓存)` }
|
|
163
|
+
: { level: "WARN", message: "项目地图:元数据无法解析" });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const activeCount = activeTasks(root).length;
|
|
167
|
+
rows.push({ level: "PASS", message: `进行中任务:${activeCount}` });
|
|
168
|
+
try {
|
|
169
|
+
const probe = path.join(root, ".solmet", ".doctor");
|
|
170
|
+
fs.writeFileSync(probe, "ok", "utf8");
|
|
171
|
+
fs.unlinkSync(probe);
|
|
172
|
+
rows.push({ level: "PASS", message: ".solmet 可写" });
|
|
173
|
+
} catch {
|
|
174
|
+
rows.push({ level: "FAIL", message: ".solmet 不可写" });
|
|
175
|
+
}
|
|
176
|
+
if (flags.baseline) {
|
|
177
|
+
const task = findTask(root);
|
|
178
|
+
const configured = Object.entries(config.commands || {})
|
|
179
|
+
.filter(([, command]) => String(command || "").trim())
|
|
180
|
+
.map(([name]) => name);
|
|
181
|
+
let names;
|
|
182
|
+
if (flags.all) names = configured;
|
|
183
|
+
else if (flags.only) names = [String(flags.only)];
|
|
184
|
+
else names = configured.includes("build") ? ["build"] : configured.slice(0, 1);
|
|
185
|
+
if (!names.length) throw new Error("没有可运行的基线命令(no baseline command);请配置 commands");
|
|
186
|
+
const { results, file } = writeBaseline(root, config, task, names);
|
|
187
|
+
for (const result of results) {
|
|
188
|
+
rows.push({
|
|
189
|
+
level: result.exit_code === 0 ? "PASS" : "WARN",
|
|
190
|
+
message: `基线(baseline)${result.name}:exit ${result.exit_code}(只记录,不阻塞)`,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
rows.push({ level: "PASS", message: `基线证据(baseline evidence):${path.relative(root, file).replaceAll(path.sep, "/")}` });
|
|
194
|
+
}
|
|
195
|
+
rows.push({ level: "PASS", message: `配置:${configFile(root)}` });
|
|
196
|
+
return finish(rows, flags.json);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function finish(rows, json) {
|
|
200
|
+
const failed = rows.some((row) => row.level === "FAIL");
|
|
201
|
+
if (json) {
|
|
202
|
+
printJson({ ok: !failed, rows });
|
|
203
|
+
return failed ? 1 : 0;
|
|
204
|
+
}
|
|
205
|
+
for (const row of rows) console.log(`[${levelBi(row.level)}] ${row.message}`);
|
|
206
|
+
console.log(failed ? "诊断未通过(doctor failed);按失败(FAIL)项修复。" : "诊断通过(doctor passed)。");
|
|
207
|
+
return failed ? 1 : 0;
|
|
208
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { loadTask, parseArgs, printJson } from "./common.js";
|
|
5
|
+
import { validateDocs, writeChanges } from "../lib/check.js";
|
|
6
|
+
import { sha256File, sha256Text, writeTask } from "../lib/task.js";
|
|
7
|
+
import { gateBi } from "../lib/labels.js";
|
|
8
|
+
|
|
9
|
+
function defaultBy() {
|
|
10
|
+
try {
|
|
11
|
+
return os.userInfo().username || "user";
|
|
12
|
+
} catch {
|
|
13
|
+
return "user";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function humanBy(flags) {
|
|
18
|
+
return String(flags.by || defaultBy()).trim() || "user";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function requireConfirmation(flags) {
|
|
22
|
+
if (!flags.confirmation) {
|
|
23
|
+
throw new Error("批准需要 --confirmation <用户原话>(例如:solmet gate verified --approve --confirmation \"验收通过\")");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function runGate(args) {
|
|
28
|
+
const { positional, flags } = parseArgs(args);
|
|
29
|
+
const name = positional[0];
|
|
30
|
+
if (!["spec", "verified"].includes(name)) {
|
|
31
|
+
throw new Error("门禁名称必须是 spec 或 verified(规格门禁 / 验收门禁)");
|
|
32
|
+
}
|
|
33
|
+
if (!flags.approve && !flags.reject) {
|
|
34
|
+
throw new Error("需要 --approve 或 --reject(例如:solmet gate verified --approve --confirmation \"验收通过\")");
|
|
35
|
+
}
|
|
36
|
+
const { task } = loadTask(flags);
|
|
37
|
+
const meta = task.meta;
|
|
38
|
+
const by = humanBy(flags);
|
|
39
|
+
|
|
40
|
+
if (flags.reject) {
|
|
41
|
+
if (!flags.reason) throw new Error("驳回需要 --reason");
|
|
42
|
+
meta.gates[name] = {
|
|
43
|
+
status: "rejected",
|
|
44
|
+
by,
|
|
45
|
+
at: new Date().toISOString(),
|
|
46
|
+
reason: flags.reason,
|
|
47
|
+
};
|
|
48
|
+
if (name === "spec") {
|
|
49
|
+
meta.status = "draft";
|
|
50
|
+
meta.gates.verified = { status: "pending" };
|
|
51
|
+
} else {
|
|
52
|
+
meta.status = "implementing";
|
|
53
|
+
meta.gates.verified = { status: "pending" };
|
|
54
|
+
}
|
|
55
|
+
writeTask(task, meta, task.body);
|
|
56
|
+
if (flags.json) {
|
|
57
|
+
printJson({ ok: true, gate: name, status: "rejected" });
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
console.log(`已驳回${gateBi(name)}(rejected):${flags.reason}`);
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
requireConfirmation(flags);
|
|
65
|
+
const now = new Date().toISOString();
|
|
66
|
+
|
|
67
|
+
if (name === "spec") {
|
|
68
|
+
const errors = validateDocs(task);
|
|
69
|
+
if (errors.length) throw new Error(errors.join("\n"));
|
|
70
|
+
const prd = path.join(task.dir, meta.artifacts?.prd || "PRD.md");
|
|
71
|
+
meta.gates.spec = {
|
|
72
|
+
status: "approved",
|
|
73
|
+
by,
|
|
74
|
+
at: now,
|
|
75
|
+
confirmation: flags.confirmation,
|
|
76
|
+
prd_sha256: sha256File(prd),
|
|
77
|
+
};
|
|
78
|
+
meta.spec_sha256 = meta.gates.spec.prd_sha256;
|
|
79
|
+
meta.gates.verified = { status: "pending" };
|
|
80
|
+
meta.checks = [];
|
|
81
|
+
const staleChanges = path.join(task.dir, meta.artifacts?.changes || "CHANGES.md");
|
|
82
|
+
if (fs.existsSync(staleChanges)) fs.unlinkSync(staleChanges);
|
|
83
|
+
meta.status = "spec-ready";
|
|
84
|
+
} else {
|
|
85
|
+
if (meta.gates?.spec?.status !== "approved") {
|
|
86
|
+
throw new Error("规格门禁(spec)尚未通过;先确认 PRD");
|
|
87
|
+
}
|
|
88
|
+
if (!meta.checks?.length) throw new Error("没有检查记录(checks);先运行检查(solmet check)");
|
|
89
|
+
const failed = meta.checks.filter((check) => check.exit_code !== 0);
|
|
90
|
+
const blocking = failed.filter((check) => !["pre-existing", "unrelated"].includes(check.classification));
|
|
91
|
+
if (blocking.length) {
|
|
92
|
+
throw new Error(`仍有本次引入的检查失败(blocking):${blocking.map((check) => check.name).join(", ")};修复后再验收`);
|
|
93
|
+
}
|
|
94
|
+
if (failed.length && !flags["allow-pre-existing"]) {
|
|
95
|
+
throw new Error(`存在既有/无关失败(pre-existing/unrelated):${failed.map((check) => check.name).join(", ")};确认例外后加 --allow-pre-existing 重新验收`);
|
|
96
|
+
}
|
|
97
|
+
const appUrl = String(flags["app-url"] || "").trim();
|
|
98
|
+
if (appUrl) {
|
|
99
|
+
let parsed;
|
|
100
|
+
try {
|
|
101
|
+
parsed = new URL(appUrl);
|
|
102
|
+
} catch {
|
|
103
|
+
throw new Error("--app-url 必须是 http(s) 地址");
|
|
104
|
+
}
|
|
105
|
+
if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password) {
|
|
106
|
+
throw new Error("--app-url 必须是不含账号密码的 http(s) 地址");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const prd = path.join(task.dir, meta.artifacts?.prd || "PRD.md");
|
|
110
|
+
const changes = path.join(task.dir, meta.artifacts?.changes || "CHANGES.md");
|
|
111
|
+
meta.exceptions = failed.map((check) => {
|
|
112
|
+
const baseline = (meta.baseline?.commands || []).find((item) => item.name === check.name);
|
|
113
|
+
return {
|
|
114
|
+
name: check.name,
|
|
115
|
+
classification: check.classification || "unknown",
|
|
116
|
+
signature: baseline?.signature || "",
|
|
117
|
+
reason: "用户确认的既有/无关失败(pre-existing/unrelated)",
|
|
118
|
+
by,
|
|
119
|
+
at: now,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
meta.gates.verified = {
|
|
123
|
+
status: "approved",
|
|
124
|
+
by,
|
|
125
|
+
at: now,
|
|
126
|
+
confirmation: flags.confirmation,
|
|
127
|
+
app_url: appUrl,
|
|
128
|
+
prd_sha256: sha256File(prd),
|
|
129
|
+
checks_sha256: sha256Text(JSON.stringify(meta.checks)),
|
|
130
|
+
exceptions: meta.exceptions,
|
|
131
|
+
};
|
|
132
|
+
meta.status = "verified";
|
|
133
|
+
writeChanges(task);
|
|
134
|
+
meta.gates.verified.changes_sha256 = sha256File(changes);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
writeTask(task, meta, task.body);
|
|
138
|
+
if (flags.json) {
|
|
139
|
+
printJson({ ok: true, gate: name, status: "approved", task: task.dir });
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
console.log(`已记录${gateBi(name)}批准(approved)(${by})。`);
|
|
143
|
+
if (meta.exceptions?.length) {
|
|
144
|
+
console.log(`已记录例外(exceptions):${meta.exceptions.map((item) => `${item.name}(${item.classification})`).join("、")}`);
|
|
145
|
+
}
|
|
146
|
+
console.log(`下一步(Next action):${name === "spec" ? "实现代码并运行检查(`solmet check`)" : "归档(`solmet archive`)"}`);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|