@yiyi_zhang/laoshi 0.2.0-beta.3 → 0.3.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.
- package/CHANGELOG.md +39 -0
- package/README.md +3 -2
- package/adapters/dsh/adapter.ts +22 -1
- package/adapters/dsh/dsh-runtime.ts +14 -3
- package/adapters/dsh/install.mjs +16 -4
- package/adapters/dsh/plugin/index.mjs +197 -18
- package/adapters/dsh/plugin/package.json +1 -1
- package/adapters/mogao/adapter.ts +10 -1
- package/adapters/mogao/mogao-runtime.ts +58 -23
- package/adapters/mogao/skill/setup.md +6 -0
- package/adapters/paseo/install.mjs +13 -4
- package/adapters/paseo/plugin/client/data.ts +13 -2
- package/adapters/paseo/plugin/client/detail.tsx +244 -4
- package/adapters/paseo/plugin/client/format.ts +25 -117
- package/adapters/paseo/plugin/client/overview.tsx +3 -3
- package/adapters/paseo/plugin/index.server.ts +2 -1
- package/adapters/paseo/plugin/package.json +1 -1
- package/adapters/paseo/plugin/paseo-plugin.json +1 -1
- package/adapters/paseo/plugin/server/handlers.ts +22 -4
- package/adapters/paseo/plugin/server/req.ts +17 -4
- package/adapters/paseo/plugin/shared/contracts.ts +28 -2
- package/adapters/paseo/plugin/shared/view-model.ts +425 -0
- package/bin/ensure-version.mjs +60 -0
- package/bin/req-doctor.mjs +5 -0
- package/bin/req.mjs +18 -0
- package/bin/start-pipeline.mjs +5 -0
- package/contracts/cli-json.md +3 -1
- package/docs/design/builtin-capabilities.md +2 -2
- package/docs/design/cli-adapter.md +1 -1
- package/docs/design/dsh-adapter.md +11 -11
- package/docs/design/shared-ui.md +43 -0
- package/docs/guide//345/234/250/346/221/270/351/253/230/344/270/212/344/275/277/347/224/250.md +2 -1
- package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +13 -8
- package/docs/guide//347/234/237/345/256/236/347/216/257/345/242/203/350/265/260/346/237/245.md +78 -0
- package/docs/guide//347/273/264/346/212/244/350/200/205/346/214/207/345/215/227.md +36 -6
- package/engine/prompts/00-shared-context.md +7 -0
- package/engine/prompts/03-design.md +2 -0
- package/engine/prompts/04-design-review.md +5 -1
- package/engine/skill-fragments/defaults.md +5 -0
- package/engine/src/api.ts +11 -2
- package/engine/src/board.ts +435 -0
- package/engine/src/config.ts +23 -0
- package/engine/src/diagnose.ts +238 -0
- package/engine/src/doctor.ts +25 -0
- package/engine/src/estimate.ts +11 -0
- package/engine/src/extensions.ts +271 -0
- package/engine/src/handover-cmd.ts +47 -0
- package/engine/src/handover.ts +89 -0
- package/engine/src/history.ts +102 -0
- package/engine/src/joint.ts +49 -4
- package/engine/src/launch.ts +20 -5
- package/engine/src/main.ts +1 -1
- package/engine/src/messages.ts +58 -0
- package/engine/src/pipeline.ts +121 -5
- package/engine/src/platform.ts +6 -0
- package/engine/src/reply.ts +27 -6
- package/engine/src/semver.ts +21 -0
- package/engine/src/skills-render.ts +10 -1
- package/package.json +5 -2
- package/site-dist/404.html +2 -2
- package/site-dist/assets/{app.CXydUhZx.js → app.DZpVs0VH.js} +1 -1
- package/site-dist/assets/changelog.md.CdUYbro4.js +1 -0
- package/site-dist/assets/{changelog.md.BU-CvyJ1.lean.js → changelog.md.CdUYbro4.lean.js} +1 -1
- package/site-dist/assets/chunks/@localSearchIndexroot.CHr-ITwS.js +1 -0
- package/site-dist/assets/chunks/{VPLocalSearchBox.CIjDV0ax.js → VPLocalSearchBox.BHkmziy1.js} +1 -1
- package/site-dist/assets/chunks/{theme.CWtC1Kby.js → theme.BsPChbDE.js} +2 -2
- package/site-dist/assets/guide_dsh.md.D0XhcUHz.js +7 -0
- package/site-dist/assets/guide_dsh.md.D0XhcUHz.lean.js +7 -0
- package/site-dist/assets/{guide_getting-started.md.BxOxfic_.js → guide_getting-started.md.BDd3nU5n.js} +1 -1
- package/site-dist/assets/{guide_install.md.By4WxsJG.js → guide_install.md.SsIHMfUu.js} +7 -5
- package/site-dist/assets/{guide_install.md.By4WxsJG.lean.js → guide_install.md.SsIHMfUu.lean.js} +7 -5
- package/site-dist/assets/guide_maintainer.md.CvqvRle1.js +1 -0
- package/site-dist/assets/guide_maintainer.md.CvqvRle1.lean.js +1 -0
- package/site-dist/assets/{guide_mogao.md.S0eln1Pr.js → guide_mogao.md.TCu3lgE9.js} +2 -2
- package/site-dist/assets/{guide_mogao.md.S0eln1Pr.lean.js → guide_mogao.md.TCu3lgE9.lean.js} +2 -2
- package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.js +5 -0
- package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.lean.js +5 -0
- package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.js +1 -0
- package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.lean.js +1 -0
- package/site-dist/assets/{reference_design_builtin-capabilities.md.CZYtjo_v.js → reference_design_builtin-capabilities.md.k5NXkESv.js} +2 -2
- package/site-dist/assets/{reference_design_builtin-capabilities.md.CZYtjo_v.lean.js → reference_design_builtin-capabilities.md.k5NXkESv.lean.js} +2 -2
- package/site-dist/assets/{reference_design_cli-adapter.md.pJy3x6Un.js → reference_design_cli-adapter.md.C1lcDATP.js} +1 -1
- package/site-dist/assets/{reference_design_cli-adapter.md.pJy3x6Un.lean.js → reference_design_cli-adapter.md.C1lcDATP.lean.js} +1 -1
- package/site-dist/changelog.html +5 -5
- package/site-dist/guide/cli.html +4 -4
- package/site-dist/guide/dsh.html +8 -6
- package/site-dist/guide/getting-started.html +5 -5
- package/site-dist/guide/how-it-works.html +4 -4
- package/site-dist/guide/index.html +4 -4
- package/site-dist/guide/install.html +11 -9
- package/site-dist/guide/intranet.html +4 -4
- package/site-dist/guide/maintainer.html +5 -5
- package/site-dist/guide/mogao.html +7 -7
- package/site-dist/guide/phases.html +4 -4
- package/site-dist/guide/project.html +4 -4
- package/site-dist/guide/user.html +4 -4
- package/site-dist/guide/walkthrough.html +34 -0
- package/site-dist/hashmap.json +1 -1
- package/site-dist/index.html +4 -4
- package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +4 -4
- package/site-dist/reference/adr/0002-two-orchestration-modes.html +4 -4
- package/site-dist/reference/adr/0003-generate-once-then-lock.html +4 -4
- package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +4 -4
- package/site-dist/reference/adr/0005-skill-names.html +4 -4
- package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +4 -4
- package/site-dist/reference/adr/0007-one-install-many-repos.html +4 -4
- package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +4 -4
- package/site-dist/reference/adr/index.html +4 -4
- package/site-dist/reference/commands.html +4 -4
- package/site-dist/reference/config.html +4 -4
- package/site-dist/reference/contracts/agent-runtime.html +4 -4
- package/site-dist/reference/contracts/cli-json.html +5 -5
- package/site-dist/reference/contracts/feature-files.html +4 -4
- package/site-dist/reference/contracts/index.html +4 -4
- package/site-dist/reference/contracts/notifier-event.html +4 -4
- package/site-dist/reference/contracts/result-file.html +4 -4
- package/site-dist/reference/contracts/spec.html +4 -4
- package/site-dist/reference/contracts/state.html +4 -4
- package/site-dist/reference/contracts/usage-record.html +4 -4
- package/site-dist/reference/contracts/verify.html +4 -4
- package/site-dist/reference/design/adapter-guide.html +4 -4
- package/site-dist/reference/design/architecture.html +4 -4
- package/site-dist/reference/design/builtin-capabilities.html +6 -6
- package/site-dist/reference/design/cli-adapter.html +5 -5
- package/site-dist/reference/design/platform-vocabulary.html +4 -4
- package/site-dist/reference/scope.html +4 -4
- package/skills/laoshi/SKILL.md +1 -3
- package/skills/laoshi-setup/SKILL.md +1 -1
- package/ui/shared/view-model.ts +424 -0
- package/ui/web/board.ts +1126 -0
- package/site-dist/assets/changelog.md.BU-CvyJ1.js +0 -1
- package/site-dist/assets/chunks/@localSearchIndexroot.CfgJeQRO.js +0 -1
- package/site-dist/assets/guide_dsh.md.0X-eYB87.js +0 -5
- package/site-dist/assets/guide_dsh.md.0X-eYB87.lean.js +0 -5
- package/site-dist/assets/guide_maintainer.md.Da1ffqxm.js +0 -1
- package/site-dist/assets/guide_maintainer.md.Da1ffqxm.lean.js +0 -1
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +0 -1
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +0 -1
- /package/site-dist/assets/{guide_getting-started.md.BxOxfic_.lean.js → guide_getting-started.md.BDd3nU5n.lean.js} +0 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
// `laoshi board [--port <端口>] [--repo <目录>] [--read-only] [--no-open]`:
|
|
2
|
+
// serves the shared Web requirement board (`ui/web/board.ts`) backed by `engine/src/api.ts`,
|
|
3
|
+
// usable standalone or embedded by a platform's web UI plugin.
|
|
4
|
+
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import crypto from "node:crypto";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import http from "node:http";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { apiFile, apiList, apiRun, apiStatus, type ListItem } from "./api.js";
|
|
12
|
+
import { acceptanceText, type Answer, buildChecklist, type Checklist, recordAcceptance, verdictOf } from "./checklist.js";
|
|
13
|
+
import { DEFAULT_CONFIG, loadConfig, type PipelineConfig } from "./config.js";
|
|
14
|
+
import { apiHistory, type RequirementHistory } from "./history.js";
|
|
15
|
+
import { defaultConfigPath } from "./locations.js";
|
|
16
|
+
import { loadRuntimeFactory, wordsFor } from "./runtime-loader.js";
|
|
17
|
+
import { howToTry, tryRequirement, type TryResult } from "./try.js";
|
|
18
|
+
import type { RequirementView } from "../../ui/shared/view-model.js";
|
|
19
|
+
import { renderBoardHtml } from "../../ui/web/board.js";
|
|
20
|
+
|
|
21
|
+
const ALLOWED_ACTIONS = new Set(["approve", "stop", "resume", "verify", "sync", "start", "reply", "change", "handover"]);
|
|
22
|
+
|
|
23
|
+
export function toRequirementView(item: ListItem): RequirementView {
|
|
24
|
+
return {
|
|
25
|
+
key: item.key,
|
|
26
|
+
repo: item.repo,
|
|
27
|
+
sourceRepo: item.sourceRepo,
|
|
28
|
+
project: item.project,
|
|
29
|
+
featureDir: item.featureDir,
|
|
30
|
+
title: item.title,
|
|
31
|
+
branch: item.branch,
|
|
32
|
+
type: item.type,
|
|
33
|
+
profile: item.profile,
|
|
34
|
+
stage: item.stage,
|
|
35
|
+
status: item.status,
|
|
36
|
+
attention: item.attention,
|
|
37
|
+
running: item.running,
|
|
38
|
+
updatedAt: item.updatedAt,
|
|
39
|
+
startedBy: item.startedBy,
|
|
40
|
+
owner: item.owner ?? null,
|
|
41
|
+
hasPrototype: item.hasPrototype,
|
|
42
|
+
current: item.current,
|
|
43
|
+
waiting: item.waiting,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface AcceptanceView {
|
|
48
|
+
checklist: Checklist;
|
|
49
|
+
howTo: string[];
|
|
50
|
+
hasAcceptanceRecord: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface AcceptanceSubmitResult {
|
|
54
|
+
ok: boolean;
|
|
55
|
+
verdict?: "通过" | "不通过";
|
|
56
|
+
committed?: boolean;
|
|
57
|
+
missing?: string[];
|
|
58
|
+
message: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface BoardHandlers {
|
|
62
|
+
list: () => RequirementView[];
|
|
63
|
+
detail: (repo: string, feature: string) => unknown;
|
|
64
|
+
file: (repo: string, feature: string, file: string) => unknown;
|
|
65
|
+
run: (input: { action: string; repo: string; featureDir: string; text?: string; to?: string; note?: string; verifyEnv?: string }) => { ok: boolean; message: string };
|
|
66
|
+
history?: (repo: string, feature: string) => RequirementHistory | unknown;
|
|
67
|
+
acceptance?: (repo: string, feature: string) => AcceptanceView;
|
|
68
|
+
submitAcceptance?: (input: { repo: string; featureDir: string; reviewer: string; answers: Answer[] }) => AcceptanceSubmitResult;
|
|
69
|
+
tryRun?: (input: { repo: string; featureDir: string; stop?: boolean }) => Promise<TryResult>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface BoardServerOptions {
|
|
73
|
+
handlers: BoardHandlers;
|
|
74
|
+
platformName?: string;
|
|
75
|
+
readOnly?: boolean;
|
|
76
|
+
csrfToken?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function readJsonBody(req: http.IncomingMessage, maxBytes = 64 * 1024): Promise<Record<string, unknown>> {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const chunks: Buffer[] = [];
|
|
82
|
+
let total = 0;
|
|
83
|
+
req.on("data", (chunk: Buffer) => {
|
|
84
|
+
total += chunk.length;
|
|
85
|
+
if (total > maxBytes) {
|
|
86
|
+
reject(new Error("请求体过大"));
|
|
87
|
+
req.destroy();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
chunks.push(chunk);
|
|
91
|
+
});
|
|
92
|
+
req.on("end", () => {
|
|
93
|
+
try {
|
|
94
|
+
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
95
|
+
resolve(raw ? (JSON.parse(raw) as Record<string, unknown>) : {});
|
|
96
|
+
} catch {
|
|
97
|
+
reject(new Error("无效的 JSON 请求体"));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
req.on("error", reject);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function sendJson(res: http.ServerResponse, status: number, body: unknown): void {
|
|
105
|
+
res.writeHead(status, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" });
|
|
106
|
+
res.end(JSON.stringify(body));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Creates an HTTP server for the shared requirement board and its local JSON API. */
|
|
110
|
+
export function createBoardServer(options: BoardServerOptions): { server: http.Server; csrfToken: string } {
|
|
111
|
+
const csrfToken = options.csrfToken ?? crypto.randomBytes(16).toString("hex");
|
|
112
|
+
const readOnly = Boolean(options.readOnly);
|
|
113
|
+
const platformName = options.platformName ?? "laoshi";
|
|
114
|
+
|
|
115
|
+
const server = http.createServer(async (req, res) => {
|
|
116
|
+
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
117
|
+
try {
|
|
118
|
+
if (req.method === "GET" && url.pathname === "/") {
|
|
119
|
+
const items = options.handlers.list();
|
|
120
|
+
const html = renderBoardHtml(items, {
|
|
121
|
+
title: "laoshi · 需求看板",
|
|
122
|
+
platformName,
|
|
123
|
+
readOnly,
|
|
124
|
+
apiBase: "/api",
|
|
125
|
+
csrfToken,
|
|
126
|
+
});
|
|
127
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
|
|
128
|
+
res.end(html);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (req.method === "GET" && url.pathname === "/api/list") {
|
|
132
|
+
sendJson(res, 200, { items: options.handlers.list() });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (req.method === "GET" && url.pathname === "/api/detail") {
|
|
136
|
+
const repo = url.searchParams.get("repo") ?? "";
|
|
137
|
+
const feature = url.searchParams.get("feature") ?? "";
|
|
138
|
+
if (!repo || !feature) {
|
|
139
|
+
sendJson(res, 400, { error: "缺少 repo 或 feature 参数" });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
sendJson(res, 200, options.handlers.detail(repo, feature));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (req.method === "GET" && url.pathname === "/api/file") {
|
|
146
|
+
const repo = url.searchParams.get("repo") ?? "";
|
|
147
|
+
const feature = url.searchParams.get("feature") ?? "";
|
|
148
|
+
const file = url.searchParams.get("file") ?? "";
|
|
149
|
+
if (!repo || !feature || !file) {
|
|
150
|
+
sendJson(res, 400, { error: "缺少 repo、feature 或 file 参数" });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
sendJson(res, 200, options.handlers.file(repo, feature, file));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (req.method === "GET" && url.pathname === "/api/acceptance") {
|
|
157
|
+
const repo = url.searchParams.get("repo") ?? "";
|
|
158
|
+
const feature = url.searchParams.get("feature") ?? "";
|
|
159
|
+
if (!repo || !feature) {
|
|
160
|
+
sendJson(res, 400, { error: "缺少 repo 或 feature 参数" });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (!options.handlers.acceptance) {
|
|
164
|
+
sendJson(res, 404, { error: "当前看板未启用验收工作台" });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
sendJson(res, 200, options.handlers.acceptance(repo, feature));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (req.method === "GET" && url.pathname === "/api/history") {
|
|
171
|
+
const repo = url.searchParams.get("repo") ?? "";
|
|
172
|
+
const feature = url.searchParams.get("feature") ?? "";
|
|
173
|
+
if (!repo || !feature) {
|
|
174
|
+
sendJson(res, 400, { error: "缺少 repo 或 feature 参数" });
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (!options.handlers.history) {
|
|
178
|
+
sendJson(res, 404, { error: "当前看板未启用变更历史" });
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
sendJson(res, 200, options.handlers.history(repo, feature));
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (req.method === "POST" && url.pathname === "/api/try") {
|
|
185
|
+
if (readOnly) {
|
|
186
|
+
sendJson(res, 403, { ok: false, error: "看板当前为只读模式" });
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (req.headers["x-laoshi-token"] !== csrfToken) {
|
|
190
|
+
sendJson(res, 403, { ok: false, error: "缺少或无效的令牌" });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!options.handlers.tryRun) {
|
|
194
|
+
sendJson(res, 404, { ok: false, error: "当前看板未启用一键试用" });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const body = await readJsonBody(req);
|
|
198
|
+
const repo = typeof body.repo === "string" ? body.repo : "";
|
|
199
|
+
const featureDir = typeof body.featureDir === "string" ? body.featureDir : "";
|
|
200
|
+
if (!repo || !featureDir) {
|
|
201
|
+
sendJson(res, 400, { ok: false, error: "缺少目标需求" });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const result = await options.handlers.tryRun({ repo, featureDir, stop: Boolean(body.stop) });
|
|
205
|
+
sendJson(res, 200, result);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (req.method === "POST" && url.pathname === "/api/acceptance") {
|
|
209
|
+
if (readOnly) {
|
|
210
|
+
sendJson(res, 403, { ok: false, error: "看板当前为只读模式" });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (req.headers["x-laoshi-token"] !== csrfToken) {
|
|
214
|
+
sendJson(res, 403, { ok: false, error: "缺少或无效的令牌" });
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (!options.handlers.submitAcceptance) {
|
|
218
|
+
sendJson(res, 404, { ok: false, error: "当前看板未启用验收提交" });
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const body = await readJsonBody(req);
|
|
222
|
+
const repo = typeof body.repo === "string" ? body.repo : "";
|
|
223
|
+
const featureDir = typeof body.featureDir === "string" ? body.featureDir : "";
|
|
224
|
+
const reviewer = typeof body.reviewer === "string" && body.reviewer.trim() ? body.reviewer.trim() : "需求方";
|
|
225
|
+
const answers = Array.isArray(body.answers)
|
|
226
|
+
? (body.answers as Array<Record<string, unknown>>)
|
|
227
|
+
.filter((a) => typeof a?.id === "string" && ["pass", "fail", "skip"].includes(String(a?.mark)))
|
|
228
|
+
.map((a) => ({ id: String(a.id), mark: String(a.mark) as Answer["mark"], note: typeof a.note === "string" ? a.note : undefined }))
|
|
229
|
+
: [];
|
|
230
|
+
if (!repo || !featureDir) {
|
|
231
|
+
sendJson(res, 400, { ok: false, error: "缺少目标需求" });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const result = options.handlers.submitAcceptance({ repo, featureDir, reviewer, answers });
|
|
235
|
+
sendJson(res, result.ok ? 200 : 400, result);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (req.method === "POST" && url.pathname === "/api/action") {
|
|
239
|
+
if (readOnly) {
|
|
240
|
+
sendJson(res, 403, { ok: false, error: "看板当前为只读模式" });
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (req.headers["x-laoshi-token"] !== csrfToken) {
|
|
244
|
+
sendJson(res, 403, { ok: false, error: "缺少或无效的令牌" });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const body = await readJsonBody(req);
|
|
248
|
+
const action = typeof body.action === "string" ? body.action : "";
|
|
249
|
+
const repo = typeof body.repo === "string" ? body.repo : "";
|
|
250
|
+
const featureDir = typeof body.featureDir === "string" ? body.featureDir : "";
|
|
251
|
+
const text = typeof body.text === "string" ? body.text : undefined;
|
|
252
|
+
const to = typeof body.to === "string" ? body.to : undefined;
|
|
253
|
+
const note = typeof body.note === "string" ? body.note : undefined;
|
|
254
|
+
const verifyEnv = typeof body.verifyEnv === "string" ? body.verifyEnv : undefined;
|
|
255
|
+
if (!ALLOWED_ACTIONS.has(action) || !repo || !featureDir) {
|
|
256
|
+
sendJson(res, 400, { ok: false, error: "无效的操作或缺少目标需求" });
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (action === "change" && !text?.trim()) {
|
|
260
|
+
sendJson(res, 400, { ok: false, error: "改动内容是空的", message: "改动内容是空的" });
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (action === "handover" && !to?.trim()) {
|
|
264
|
+
sendJson(res, 400, { ok: false, error: "接手人不能为空", message: "接手人不能为空" });
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const result = options.handlers.run({
|
|
268
|
+
action,
|
|
269
|
+
repo,
|
|
270
|
+
featureDir,
|
|
271
|
+
text,
|
|
272
|
+
to,
|
|
273
|
+
note,
|
|
274
|
+
verifyEnv,
|
|
275
|
+
});
|
|
276
|
+
sendJson(res, 200, result);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
sendJson(res, 404, { error: "未找到路径" });
|
|
280
|
+
} catch (error) {
|
|
281
|
+
sendJson(res, 500, { ok: false, error: (error as Error).message });
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
return { server, csrfToken };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function openBrowser(url: string): void {
|
|
289
|
+
const [cmd, args] =
|
|
290
|
+
process.platform === "darwin"
|
|
291
|
+
? ["open", [url]]
|
|
292
|
+
: process.platform === "win32"
|
|
293
|
+
? ["cmd", ["/c", "start", "", url]]
|
|
294
|
+
: ["xdg-open", [url]];
|
|
295
|
+
try {
|
|
296
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
297
|
+
child.unref();
|
|
298
|
+
} catch {
|
|
299
|
+
// Best effort only.
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function parseArgs(argv: string[]): { port: number; repo: string | null; readOnly: boolean; noOpen: boolean; help: boolean } {
|
|
304
|
+
let port = 0;
|
|
305
|
+
let repo: string | null = null;
|
|
306
|
+
let readOnly = false;
|
|
307
|
+
let noOpen = false;
|
|
308
|
+
let help = false;
|
|
309
|
+
for (let i = 0; i < argv.length; i++) {
|
|
310
|
+
const a = argv[i];
|
|
311
|
+
if (a === "-h" || a === "--help") help = true;
|
|
312
|
+
else if (a === "--read-only") readOnly = true;
|
|
313
|
+
else if (a === "--no-open") noOpen = true;
|
|
314
|
+
else if (a === "--port" && argv[i + 1]) port = Number(argv[++i]) || 0;
|
|
315
|
+
else if (a.startsWith("--port=")) port = Number(a.slice(7)) || 0;
|
|
316
|
+
else if (a === "--repo" && argv[i + 1]) repo = path.resolve(argv[++i]);
|
|
317
|
+
else if (a.startsWith("--repo=")) repo = path.resolve(a.slice(7));
|
|
318
|
+
}
|
|
319
|
+
return { port, repo, readOnly, noOpen, help };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function main(argv: string[]): Promise<number> {
|
|
323
|
+
const args = parseArgs(argv);
|
|
324
|
+
if (args.help) {
|
|
325
|
+
console.log("用法:laoshi board [--port <端口>] [--repo <目录>] [--read-only] [--no-open]");
|
|
326
|
+
console.log("在本机打开需求看板网页(展示所有待处理、进行中、待测试与已完成需求,支持查看产物与执行操作)。");
|
|
327
|
+
return 0;
|
|
328
|
+
}
|
|
329
|
+
let platformName = "laoshi";
|
|
330
|
+
try {
|
|
331
|
+
const loaded = loadConfig(defaultConfigPath(), args.repo ?? process.cwd());
|
|
332
|
+
platformName = wordsFor(loaded.config).name;
|
|
333
|
+
} catch {
|
|
334
|
+
platformName = wordsFor(DEFAULT_CONFIG).name;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const handlers: BoardHandlers = {
|
|
338
|
+
list: () => apiList({ repo: args.repo ?? process.cwd(), all: !args.repo }).map(toRequirementView),
|
|
339
|
+
detail: (repo, feature) => apiStatus(repo, feature),
|
|
340
|
+
file: (repo, feature, file) => apiFile(repo, feature, file),
|
|
341
|
+
history: (repo, feature) => apiHistory(repo, feature),
|
|
342
|
+
run: ({ action, repo, featureDir, text, to, note, verifyEnv }) => {
|
|
343
|
+
if (action === "change") {
|
|
344
|
+
const msg = text?.trim() ?? "";
|
|
345
|
+
if (!msg) return { ok: false, message: "改动内容是空的" };
|
|
346
|
+
return apiRun("reply", repo, featureDir, ["--change", msg]);
|
|
347
|
+
}
|
|
348
|
+
if (action === "handover") {
|
|
349
|
+
const target = to?.trim() ?? "";
|
|
350
|
+
if (!target) return { ok: false, message: "接手人不能为空" };
|
|
351
|
+
return apiRun("handover", repo, featureDir, [target, ...(note?.trim() ? ["--note", note.trim()] : [])]);
|
|
352
|
+
}
|
|
353
|
+
const extra: string[] = [];
|
|
354
|
+
if (verifyEnv) extra.push("--verify-env", verifyEnv);
|
|
355
|
+
if (text) extra.push(text);
|
|
356
|
+
return apiRun(action, repo, featureDir, extra);
|
|
357
|
+
},
|
|
358
|
+
acceptance: (repo, feature) => {
|
|
359
|
+
const featureAbs = path.join(repo, feature);
|
|
360
|
+
return {
|
|
361
|
+
checklist: buildChecklist(featureAbs),
|
|
362
|
+
howTo: howToTry(featureAbs),
|
|
363
|
+
hasAcceptanceRecord: fs.existsSync(path.join(featureAbs, "acceptance.md")),
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
submitAcceptance: ({ repo, featureDir, reviewer, answers }) => {
|
|
367
|
+
const featureAbs = path.join(repo, featureDir);
|
|
368
|
+
const list = buildChecklist(featureAbs);
|
|
369
|
+
const v = verdictOf(list, answers);
|
|
370
|
+
if (v.verdict === "通过" && v.missing.length > 0) {
|
|
371
|
+
return {
|
|
372
|
+
ok: false,
|
|
373
|
+
missing: v.missing.map((i) => i.id),
|
|
374
|
+
message: `还有 ${v.missing.length} 条必验项未勾选(${v.missing.map((i) => i.id).join("、")}),全部核对后才能提交通过。`,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
const prevPath = path.join(featureAbs, "acceptance.md");
|
|
378
|
+
const previous = fs.existsSync(prevPath) ? fs.readFileSync(prevPath, "utf8") : undefined;
|
|
379
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
380
|
+
const text = acceptanceText(list, answers, { verdict: v.verdict, reviewer, date, previous });
|
|
381
|
+
const { committed } = recordAcceptance(repo, featureDir, text);
|
|
382
|
+
return {
|
|
383
|
+
ok: true,
|
|
384
|
+
verdict: v.verdict,
|
|
385
|
+
committed,
|
|
386
|
+
message: `验收结论「${v.verdict}」已写入 acceptance.md${committed ? "并提交" : ""}。`,
|
|
387
|
+
};
|
|
388
|
+
},
|
|
389
|
+
tryRun: async ({ repo, featureDir, stop }) => {
|
|
390
|
+
let config: PipelineConfig = DEFAULT_CONFIG;
|
|
391
|
+
try {
|
|
392
|
+
config = loadConfig(defaultConfigPath(), repo).config;
|
|
393
|
+
} catch {
|
|
394
|
+
// Fallback to default config.
|
|
395
|
+
}
|
|
396
|
+
const runtime = await (await loadRuntimeFactory())({ config, log: () => undefined });
|
|
397
|
+
try {
|
|
398
|
+
return await tryRequirement({ repo, featureDir, stop, runtime, config });
|
|
399
|
+
} finally {
|
|
400
|
+
await runtime.close().catch(() => undefined);
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const { server } = createBoardServer({ handlers, platformName, readOnly: args.readOnly });
|
|
406
|
+
await new Promise<void>((resolve, reject) => {
|
|
407
|
+
server.once("error", reject);
|
|
408
|
+
server.listen(args.port, "127.0.0.1", () => resolve());
|
|
409
|
+
});
|
|
410
|
+
const addr = server.address();
|
|
411
|
+
const actualPort = typeof addr === "object" && addr ? addr.port : args.port;
|
|
412
|
+
const url = `http://127.0.0.1:${actualPort}/`;
|
|
413
|
+
console.log(`需求看板已启动:${url}${args.readOnly ? "(只读模式)" : ""}`);
|
|
414
|
+
console.log("按 Ctrl+C 停止。");
|
|
415
|
+
if (!args.noOpen) openBrowser(url);
|
|
416
|
+
|
|
417
|
+
await new Promise<void>((resolve) => {
|
|
418
|
+
const stop = () => {
|
|
419
|
+
server.close(() => resolve());
|
|
420
|
+
};
|
|
421
|
+
process.once("SIGINT", stop);
|
|
422
|
+
process.once("SIGTERM", stop);
|
|
423
|
+
});
|
|
424
|
+
return 0;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
428
|
+
main(process.argv.slice(2)).then(
|
|
429
|
+
(code) => process.exit(code),
|
|
430
|
+
(error: Error) => {
|
|
431
|
+
console.error(`启动需求看板失败:${error.message}`);
|
|
432
|
+
process.exit(1);
|
|
433
|
+
},
|
|
434
|
+
);
|
|
435
|
+
}
|
package/engine/src/config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { type ExtensionStep, mergeExtensions, validateExtensions } from "./extensions.js";
|
|
4
5
|
import { type IntegrationConfig, validateIntegrations } from "./integrations.js";
|
|
5
6
|
import { NOTIFIER_EVENT_TYPES, type NotifierConfig } from "./notifiers.js";
|
|
6
7
|
import type { StepId } from "./steps.js";
|
|
@@ -316,6 +317,8 @@ export interface PipelineConfig {
|
|
|
316
317
|
slices: { profiles: ProfileName[]; max: number };
|
|
317
318
|
/** Repositories the steps may read for reference, never change. */
|
|
318
319
|
relatedRepos: RelatedRepo[];
|
|
320
|
+
/** Maximum number of additional joint repositories in one requirement (default 2, up to 10). */
|
|
321
|
+
maxJointRepos: number;
|
|
319
322
|
/**
|
|
320
323
|
* Design confirmation point (1.8): after the design review, show the requester what they
|
|
321
324
|
* will get (preview.md, a prototype for UI changes) and wait for "yes" before writing code.
|
|
@@ -329,6 +332,11 @@ export interface PipelineConfig {
|
|
|
329
332
|
* in parallel; the reviewer consolidates. A configured review panel takes precedence.
|
|
330
333
|
*/
|
|
331
334
|
reviewAxes: { enabled: boolean; profiles: ProfileName[] };
|
|
335
|
+
/**
|
|
336
|
+
* Controlled flow extensions (M3): custom AI/skill or shell script steps attached after
|
|
337
|
+
* fixed core stages, without altering the core pipeline skeleton.
|
|
338
|
+
*/
|
|
339
|
+
extensions: ExtensionStep[];
|
|
332
340
|
}
|
|
333
341
|
|
|
334
342
|
export const DEFAULT_CONFIG: PipelineConfig = {
|
|
@@ -404,8 +412,10 @@ export const DEFAULT_CONFIG: PipelineConfig = {
|
|
|
404
412
|
qualityGate: { fixAttempts: 2, timeoutMinutes: 20 },
|
|
405
413
|
slices: { profiles: ["standard"], max: 6 },
|
|
406
414
|
relatedRepos: [],
|
|
415
|
+
maxJointRepos: 2,
|
|
407
416
|
designApproval: { mode: "ui", profiles: ["standard"], autoContinueHours: 0 },
|
|
408
417
|
reviewAxes: { enabled: true, profiles: ["standard"] },
|
|
418
|
+
extensions: [],
|
|
409
419
|
};
|
|
410
420
|
|
|
411
421
|
/** Project file, at the repository root, that overrides the install-level configuration (laoshi M2c). */
|
|
@@ -547,6 +557,14 @@ function merge(base: PipelineConfig, raw: Record<string, unknown>): PipelineConf
|
|
|
547
557
|
...(isRecord(raw.designApproval) ? (raw.designApproval as Partial<PipelineConfig["designApproval"]>) : {}),
|
|
548
558
|
};
|
|
549
559
|
merged.reviewAxes = { ...base.reviewAxes, ...(isRecord(raw.reviewAxes) ? (raw.reviewAxes as Partial<PipelineConfig["reviewAxes"]>) : {}) };
|
|
560
|
+
if (raw.extensions !== undefined) {
|
|
561
|
+
if (Array.isArray(raw.extensions) && Array.isArray(base.extensions)) {
|
|
562
|
+
const checked = validateExtensions(raw.extensions);
|
|
563
|
+
merged.extensions = checked.errors.length === 0 ? mergeExtensions(base.extensions, checked.extensions) : (raw.extensions as ExtensionStep[]);
|
|
564
|
+
} else {
|
|
565
|
+
merged.extensions = raw.extensions as ExtensionStep[];
|
|
566
|
+
}
|
|
567
|
+
}
|
|
550
568
|
delete (merged as unknown as Record<string, unknown>).rounds;
|
|
551
569
|
return merged;
|
|
552
570
|
}
|
|
@@ -644,6 +662,9 @@ function validateChecks(config: PipelineConfig): void {
|
|
|
644
662
|
if (typeof r.path !== "string" || r.path.trim() === "") throw new ConfigError(`relatedRepos[${i}].path 必须是这台机器上的目录`);
|
|
645
663
|
if (r.role !== undefined && typeof r.role !== "string") throw new ConfigError(`relatedRepos[${i}].role 必须是字符串`);
|
|
646
664
|
});
|
|
665
|
+
if (!Number.isInteger(config.maxJointRepos) || config.maxJointRepos < 1 || config.maxJointRepos > 10) {
|
|
666
|
+
throw new ConfigError("maxJointRepos 必须是 1 到 10 之间的整数");
|
|
667
|
+
}
|
|
647
668
|
}
|
|
648
669
|
|
|
649
670
|
/** Where a related repository is on this machine; relative paths start from the project's checkout. */
|
|
@@ -772,6 +793,8 @@ function validate(config: PipelineConfig): void {
|
|
|
772
793
|
}
|
|
773
794
|
validatePhases(config.phases);
|
|
774
795
|
validateChecks(config);
|
|
796
|
+
const extCheck = validateExtensions(config.extensions);
|
|
797
|
+
if (extCheck.errors.length > 0) throw new ConfigError(extCheck.errors.join(";"));
|
|
775
798
|
for (const key of ["waitChunkSeconds", "permissionPollSeconds", "serviceReadySeconds", "queuePollSeconds"] as const) {
|
|
776
799
|
if (typeof config[key] !== "number" || config[key] <= 0) throw new ConfigError(`${key} 必须是正数`);
|
|
777
800
|
}
|