@loviusc/sa-spec 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +72 -1
- package/src/cli.js +220 -4
- package/templates/AGENTS.md +1 -0
- package/templates/readme.md +72 -1
- package/templates/skills/system-analysis/SKILL.md +1 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -237,7 +237,9 @@ sa-spec init --full
|
|
|
237
237
|
|---|---|
|
|
238
238
|
| `sa-spec init` | 建立最小文件骨架。 |
|
|
239
239
|
| `sa-spec init --full` | 建立文件骨架與完整規則文件。 |
|
|
240
|
-
| `sa-spec new --id REQ-001 --name login` |
|
|
240
|
+
| `sa-spec new [--id REQ-001] --name login [--branch]` | 建立需求資料夾與空白文件模板(未帶 `--id` 時啟用多人草稿模式,可選 `--branch` 自動建立並切換至 `feat/<name>` 分支)。 |
|
|
241
|
+
| `sa-spec finalize --name login` | 將草稿需求定號歸檔為最新序號(自動計算最新號碼、重命名目錄、批次置換 `{{REQ_ID}}` 並重建索引)。 |
|
|
242
|
+
| `sa-spec reindex` | 掃描 `project/REQ-*` 目錄,依序號重新生成乾淨無衝突的 `project/index.md`。 |
|
|
241
243
|
| `sa-spec check` | 檢查基本文件是否存在。 |
|
|
242
244
|
| `sa-spec status` | 顯示系統規格與需求索引狀態。 |
|
|
243
245
|
| `sa-spec doctor` | 檢查必要檔案是否存在。 |
|
|
@@ -349,6 +351,64 @@ docs(REQ-001): 番茄時鐘 - 新增專注與休息計時需求
|
|
|
349
351
|
|
|
350
352
|
只有在使用者明確要求推送 remote,或專案設定啟用 auto-push 時,才會執行 `git push`。如果 push 失敗,只回報認證或網路問題,不會回滾已完成的文件歸檔與本機 commit。
|
|
351
353
|
|
|
354
|
+
## 多人協作解決方案(Git-Flow 與延遲綁定 ID)
|
|
355
|
+
|
|
356
|
+
在單人開發時,循序流水號(`REQ-001`、`REQ-002`)簡單直覺;但在多人平行協作時,容易引發兩大痛點:
|
|
357
|
+
1. **序號競爭撞車**:Alice 與 Bob 同時在各自的分支開發,雙方本機都取了 `REQ-003`,合併回主幹時發生目錄重名衝突。
|
|
358
|
+
2. **中心化檔案衝突**:每次歸檔都要修改 `project/index.md`,導致頻繁的 Git merge conflict。
|
|
359
|
+
|
|
360
|
+
`sa-spec v0.2.0` 引進 **「Feature Branch 隔離 + 延遲綁定序號(Late-Binding ID)」** 完整解決方案:
|
|
361
|
+
|
|
362
|
+
```mermaid
|
|
363
|
+
flowchart TD
|
|
364
|
+
A[開新需求: sa-spec new --name cart --branch] --> B[建立並切換至 feat/cart 分支<br/>以 project/cart/ 建立草稿目錄]
|
|
365
|
+
B --> C[AI 分析與起草: sca<br/>內部使用 {{REQ_ID}} 佔位<br/>自動同步 master 規格防護]
|
|
366
|
+
C --> D{使用者確認通過<br/>執行 scc 或 finalize}
|
|
367
|
+
D --> E[查詢 master 最新序號 N]
|
|
368
|
+
E --> F[重命名為 project/REQ-N+1-cart/<br/>批次置換 {{REQ_ID}} 為正式號碼]
|
|
369
|
+
F --> G[sa-spec reindex: 動態重構 index.md]
|
|
370
|
+
G --> H[合併回 master: 零衝突、序號永遠連續!]
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### 多人協作四步流程
|
|
374
|
+
|
|
375
|
+
#### 1. 提出需求(草稿與分支隔離)
|
|
376
|
+
開需求時**不搶序號**,直接以語意名稱建立分支與草稿目錄:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
# 自動建立並切換至 feat/cart-checkout 分支,建立 project/cart-checkout/ 草稿目錄
|
|
380
|
+
sa-spec new --name cart-checkout --branch
|
|
381
|
+
```
|
|
382
|
+
在 VS Code 側邊欄輸入:
|
|
383
|
+
```text
|
|
384
|
+
scp 購物車結帳需求
|
|
385
|
+
```
|
|
386
|
+
* **特點**:目錄名稱為 `project/cart-checkout/`,內部所有檔案皆使用 `{{REQ_ID}}` 佔位符。多人同時提出需求互不干擾、零衝突。即使需求中途放棄,直接刪除分支即可,絕不留下幽靈跳號。
|
|
387
|
+
|
|
388
|
+
#### 2. 分析與衝突檢查(規格基線同步)
|
|
389
|
+
在分支上執行 `spec:analyze`(或 `sca`)前,工具會確認已取得 `master`(或 `origin/master`)的最新規格,確保是以全專案最新基準進行影響評估,避免因分支落後而漏檢權限、API 或資料表衝突。
|
|
390
|
+
|
|
391
|
+
#### 3. 確認歸檔與延遲定號(Late-Binding)
|
|
392
|
+
當需求規格確認無誤,準備歸檔時:
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
# 自動向 master 查詢最新可用序號(例如 REQ-006)
|
|
396
|
+
sa-spec finalize --name cart-checkout
|
|
397
|
+
```
|
|
398
|
+
* **自動化執行**:
|
|
399
|
+
1. 取得最新序號(例如目前最大是 `REQ-005`,自動取得 `REQ-006`)。
|
|
400
|
+
2. 使用 `git mv` 將目錄重命名為 `project/REQ-006-cart-checkout`。
|
|
401
|
+
3. 自動掃描並將目錄內所有檔案的 `{{REQ_ID}}` 批次置換為 `REQ-006`。
|
|
402
|
+
4. 自動執行 `reindex` 重建需求總表。
|
|
403
|
+
|
|
404
|
+
#### 4. 消除索引合併衝突(`sa-spec reindex`)
|
|
405
|
+
`project/index.md` 改為由目錄動態生成的「衍生清單」,不再依賴脆弱的手動 append:
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
sa-spec reindex
|
|
409
|
+
```
|
|
410
|
+
* 任何時候若有 PR 合併產生 index 衝突,只要執行 `sa-spec reindex`,即可依序號重新排序生成乾淨的總表,無需人工手動解 conflict。
|
|
411
|
+
|
|
352
412
|
## 完整範例:番茄時鐘
|
|
353
413
|
|
|
354
414
|
以下示範從空資料夾開始,建立一個「番茄時鐘」需求。
|
|
@@ -597,6 +657,17 @@ git push origin master
|
|
|
597
657
|
|
|
598
658
|
## 更新紀錄
|
|
599
659
|
|
|
660
|
+
### v0.2.0
|
|
661
|
+
- **多人協作 Git-Flow 解決方案(延遲綁定序號與零衝突索引)**:
|
|
662
|
+
- **解決痛點**:多人平行開發時,傳統流水號(`REQ-001`)容易在各自分支撞車,且中心化的 `project/index.md` 容易造成 Git merge conflict。
|
|
663
|
+
- **延遲綁定序號(Late-Binding ID)**:開需求時不搶號,在 feature branch 上以語意名稱建立草稿需求(如 `project/cart`),內部使用 `{{REQ_ID}}` 佔位;只有在 `spec:commit` 最終歸檔時,才向 master/遠端確認最新可用序號並定號(如 `REQ-003`),自動批次置換佔位符,徹底避免幽靈跳號與序號競爭。
|
|
664
|
+
- **動態重建需求索引(`sa-spec reindex`)**:將 `project/index.md` 改為根據 `project/REQ-*` 目錄動態掃描並依序號排序生成,消除手動 append 造成的 Git 合併衝突。
|
|
665
|
+
- **CLI 指令升級**:
|
|
666
|
+
- `sa-spec new [--id REQ-001] --name login [--branch]`:支援草稿模式與自動切換 feature 分支。
|
|
667
|
+
- `sa-spec finalize --name login`:自動定號、重命名目錄、置換佔位符並重建索引。
|
|
668
|
+
- `sa-spec reindex`:一鍵掃描並重新排序生成乾淨的 `project/index.md`。
|
|
669
|
+
- **分析前防護**:`spec:analyze` 執行前確保取得 master/遠端最新規格,避免分支規格落後導致漏檢衝突。
|
|
670
|
+
|
|
600
671
|
### v0.1.3
|
|
601
672
|
- **支援指令簡寫別名(同時保留完整指令)**:
|
|
602
673
|
- `sci` = `spec:init`
|
package/src/cli.js
CHANGED
|
@@ -17,6 +17,12 @@ function main() {
|
|
|
17
17
|
case "new":
|
|
18
18
|
createReqTemplate(args.slice(1));
|
|
19
19
|
return;
|
|
20
|
+
case "finalize":
|
|
21
|
+
finalizeReq(args.slice(1));
|
|
22
|
+
return;
|
|
23
|
+
case "reindex":
|
|
24
|
+
reindexProject();
|
|
25
|
+
return;
|
|
20
26
|
case "check":
|
|
21
27
|
runCheck();
|
|
22
28
|
return;
|
|
@@ -32,6 +38,11 @@ function main() {
|
|
|
32
38
|
case "template":
|
|
33
39
|
runTemplate(args.slice(1));
|
|
34
40
|
return;
|
|
41
|
+
case "version":
|
|
42
|
+
case "--version":
|
|
43
|
+
case "-v":
|
|
44
|
+
showVersion();
|
|
45
|
+
return;
|
|
35
46
|
case "help":
|
|
36
47
|
case "--help":
|
|
37
48
|
case "-h":
|
|
@@ -215,12 +226,46 @@ function createReqTemplate(args, label = "new") {
|
|
|
215
226
|
const id = getOption(args, "--id");
|
|
216
227
|
const name = getOption(args, "--name");
|
|
217
228
|
|
|
218
|
-
if (!
|
|
219
|
-
fail("Usage: sa-spec
|
|
229
|
+
if (!name) {
|
|
230
|
+
fail("Usage: sa-spec new [--id REQ-001] --name login [--branch]");
|
|
220
231
|
return;
|
|
221
232
|
}
|
|
222
233
|
|
|
223
234
|
const slug = slugify(name);
|
|
235
|
+
|
|
236
|
+
// 草稿模式(Git-Flow 多人協作):未指定 id 時建立草稿目錄,以 {{REQ_ID}} 佔位
|
|
237
|
+
if (!id) {
|
|
238
|
+
if (args.includes("--branch")) {
|
|
239
|
+
const branchName = `feat/${slug}`;
|
|
240
|
+
const branchRes = spawnSync("git", ["checkout", "-b", branchName], { cwd, encoding: "utf8" });
|
|
241
|
+
if (branchRes.status === 0) {
|
|
242
|
+
console.log(`已建立並切換至分支: ${branchName}`);
|
|
243
|
+
} else {
|
|
244
|
+
console.log(`提示: 分支切換略過 (${(branchRes.stderr || "").trim() || "可能是已有同名分支或未在 git 目錄"})`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const reqDir = path.join("project", slug);
|
|
249
|
+
const umlDir = path.join(reqDir, "uml");
|
|
250
|
+
const replacements = { REQ_ID: "{{REQ_ID}}", REQ_NAME: name };
|
|
251
|
+
const results = [
|
|
252
|
+
ensureDir(reqDir),
|
|
253
|
+
ensureDir(umlDir),
|
|
254
|
+
ensureFileFromTemplate(path.join("project", "req", "srs.md"), path.join(reqDir, "srs.md"), replacements),
|
|
255
|
+
ensureFileFromTemplate(path.join("project", "req", "uml", "main.puml"), path.join(umlDir, "main.puml"), replacements),
|
|
256
|
+
ensureFileFromTemplate(path.join("project", "req", "openapi.yaml"), path.join(reqDir, "openapi.yaml"), replacements),
|
|
257
|
+
ensureFileFromTemplate(path.join("project", "req", "db-schema.md"), path.join(reqDir, "db-schema.md"), replacements),
|
|
258
|
+
ensureFileFromTemplate(path.join("project", "req", "handoff.md"), path.join(reqDir, "handoff.md"), replacements),
|
|
259
|
+
ensureFileFromTemplate(path.join("project", "req", "history.md"), path.join(reqDir, "history.md"), replacements)
|
|
260
|
+
];
|
|
261
|
+
|
|
262
|
+
printResultList(label, results);
|
|
263
|
+
console.log(`\n已建立草稿需求:${reqDir}(內部使用 {{REQ_ID}} 佔位符)`);
|
|
264
|
+
console.log(`分析確認後,可使用 sa-spec finalize --name ${slug} 定號歸檔。`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// 傳統模式:指定序號
|
|
224
269
|
const reqDir = path.join("project", `${id}-${slug}`);
|
|
225
270
|
const umlDir = path.join(reqDir, "uml");
|
|
226
271
|
const replacements = { REQ_ID: id, REQ_NAME: name };
|
|
@@ -239,6 +284,166 @@ function createReqTemplate(args, label = "new") {
|
|
|
239
284
|
printResultList(label, results);
|
|
240
285
|
}
|
|
241
286
|
|
|
287
|
+
function finalizeReq(args) {
|
|
288
|
+
const name = getOption(args, "--name") || getOption(args, "--draft") || args[0];
|
|
289
|
+
if (!name) {
|
|
290
|
+
fail("Usage: sa-spec finalize --name <name-or-slug>");
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const slug = slugify(name);
|
|
295
|
+
const projectDir = path.join(cwd, "project");
|
|
296
|
+
let draftRelDir = path.join("project", slug);
|
|
297
|
+
let draftAbsDir = path.join(cwd, draftRelDir);
|
|
298
|
+
|
|
299
|
+
if (!fs.existsSync(draftAbsDir)) {
|
|
300
|
+
const altRelDir = path.join("project", `draft-${slug}`);
|
|
301
|
+
if (fs.existsSync(path.join(cwd, altRelDir))) {
|
|
302
|
+
draftRelDir = altRelDir;
|
|
303
|
+
draftAbsDir = path.join(cwd, altRelDir);
|
|
304
|
+
} else {
|
|
305
|
+
fail(`找不到草稿需求目錄: ${draftRelDir}`);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// 掃描既有最大 REQ 編號
|
|
311
|
+
let maxIdNum = 0;
|
|
312
|
+
if (fs.existsSync(projectDir)) {
|
|
313
|
+
const entries = fs.readdirSync(projectDir, { withFileTypes: true });
|
|
314
|
+
for (const entry of entries) {
|
|
315
|
+
if (entry.isDirectory() && entry.name.startsWith("REQ-")) {
|
|
316
|
+
const m = entry.name.match(/^REQ-(\d+)/i);
|
|
317
|
+
if (m) {
|
|
318
|
+
const num = parseInt(m[1], 10);
|
|
319
|
+
if (num > maxIdNum) {
|
|
320
|
+
maxIdNum = num;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const nextIdNum = maxIdNum + 1;
|
|
328
|
+
const nextId = `REQ-${String(nextIdNum).padStart(3, "0")}`;
|
|
329
|
+
const finalDirName = `${nextId}-${slug}`;
|
|
330
|
+
const finalRelDir = path.join("project", finalDirName);
|
|
331
|
+
const finalAbsDir = path.join(cwd, finalRelDir);
|
|
332
|
+
|
|
333
|
+
if (fs.existsSync(finalAbsDir)) {
|
|
334
|
+
fail(`目標目錄 ${finalRelDir} 已存在,請確認序號或目錄名稱。`);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// 重命名目錄 (優先嘗試 git mv)
|
|
339
|
+
const gitMv = spawnSync("git", ["mv", draftRelDir, finalRelDir], { cwd, encoding: "utf8" });
|
|
340
|
+
if (gitMv.status === 0) {
|
|
341
|
+
console.log(`[Git] 已將目錄重命名為: ${finalRelDir}`);
|
|
342
|
+
} else {
|
|
343
|
+
fs.renameSync(draftAbsDir, finalAbsDir);
|
|
344
|
+
console.log(`已將目錄重命名為: ${finalRelDir}`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// 替換目錄內檔案的 {{REQ_ID}} 佔位符
|
|
348
|
+
const files = listFilesRecursive(finalAbsDir);
|
|
349
|
+
for (const filePath of files) {
|
|
350
|
+
try {
|
|
351
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
352
|
+
if (content.includes("{{REQ_ID}}")) {
|
|
353
|
+
const updated = content.split("{{REQ_ID}}").join(nextId);
|
|
354
|
+
fs.writeFileSync(filePath, updated, "utf8");
|
|
355
|
+
}
|
|
356
|
+
} catch (_) {
|
|
357
|
+
// 略過無法以文字讀取之檔案
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// 自動重新整理 index.md
|
|
362
|
+
reindexProject();
|
|
363
|
+
|
|
364
|
+
console.log(`\n 需求已成功定號歸檔為: ${nextId} (${finalDirName})`);
|
|
365
|
+
console.log(`建議接下來執行:`);
|
|
366
|
+
console.log(` git add project/`);
|
|
367
|
+
console.log(` git commit -m "docs(${nextId}): ${name} - 規格確認歸檔"`);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function reindexProject() {
|
|
371
|
+
const projectDir = path.join(cwd, "project");
|
|
372
|
+
const indexPath = path.join(projectDir, "index.md");
|
|
373
|
+
if (!fs.existsSync(projectDir)) {
|
|
374
|
+
fail("project/ directory not found.");
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// 讀取現有索引
|
|
379
|
+
const existingMap = new Map();
|
|
380
|
+
if (fs.existsSync(indexPath)) {
|
|
381
|
+
const existingRows = parseIndexRows(fs.readFileSync(indexPath, "utf8"));
|
|
382
|
+
for (const row of existingRows) {
|
|
383
|
+
existingMap.set(row.id, row);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const entries = fs.readdirSync(projectDir, { withFileTypes: true });
|
|
388
|
+
const reqDirs = entries.filter((e) => e.isDirectory() && e.name.startsWith("REQ-"));
|
|
389
|
+
|
|
390
|
+
const rows = [];
|
|
391
|
+
for (const entry of reqDirs) {
|
|
392
|
+
const dirName = entry.name;
|
|
393
|
+
const match = dirName.match(/^(REQ-\d+)(?:-(.*))?$/i);
|
|
394
|
+
if (!match) continue;
|
|
395
|
+
const id = match[1].toUpperCase();
|
|
396
|
+
const fallbackTitle = match[2] || dirName;
|
|
397
|
+
|
|
398
|
+
const reqDirPath = path.join(projectDir, dirName);
|
|
399
|
+
const srsPath = path.join(reqDirPath, "srs.md");
|
|
400
|
+
|
|
401
|
+
let title = fallbackTitle;
|
|
402
|
+
let description = "待補充";
|
|
403
|
+
let status = "待確認";
|
|
404
|
+
let createdAt = formatLocalDateTime(new Date());
|
|
405
|
+
let updatedAt = createdAt;
|
|
406
|
+
|
|
407
|
+
if (existingMap.has(id)) {
|
|
408
|
+
const prev = existingMap.get(id);
|
|
409
|
+
title = prev.title || title;
|
|
410
|
+
description = prev.description || description;
|
|
411
|
+
status = prev.status || status;
|
|
412
|
+
createdAt = prev.createdAt || createdAt;
|
|
413
|
+
updatedAt = prev.updatedAt || updatedAt;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (fs.existsSync(srsPath)) {
|
|
417
|
+
const srsContent = fs.readFileSync(srsPath, "utf8");
|
|
418
|
+
const titleMatch = srsContent.match(/^# 需求規格[::]\s*(?:REQ-\d+\s*)?(.*)$/m);
|
|
419
|
+
if (titleMatch && titleMatch[1].trim()) {
|
|
420
|
+
title = titleMatch[1].trim();
|
|
421
|
+
}
|
|
422
|
+
const statusMatch = srsContent.match(/^-\s*狀態[::]\s*(.+)$/m);
|
|
423
|
+
if (statusMatch && statusMatch[1].trim()) {
|
|
424
|
+
status = statusMatch[1].trim();
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const numMatch = id.match(/\d+/);
|
|
429
|
+
const num = numMatch ? parseInt(numMatch[0], 10) : 0;
|
|
430
|
+
|
|
431
|
+
rows.push({ num, id, title, description, status, createdAt, updatedAt });
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// 依數字循序排序
|
|
435
|
+
rows.sort((a, b) => a.num - b.num);
|
|
436
|
+
|
|
437
|
+
const header = `# 需求索引\n\n| 編號 | 標題 | 敘述 | 狀態 | 建立時間 | 更新時間 |\n|---|---|---|---|---|---|\n`;
|
|
438
|
+
const tableRows = rows
|
|
439
|
+
.map((r) => `| ${r.id} | ${r.title} | ${r.description} | ${r.status} | ${r.createdAt} | ${r.updatedAt} |`)
|
|
440
|
+
.join("\n");
|
|
441
|
+
const nextContent = rows.length > 0 ? `${header}${tableRows}\n` : `${header}\n`;
|
|
442
|
+
|
|
443
|
+
fs.writeFileSync(indexPath, nextContent, "utf8");
|
|
444
|
+
console.log(`sa-spec reindex: 已重新索引 ${rows.length} 個需求至 project/index.md`);
|
|
445
|
+
}
|
|
446
|
+
|
|
242
447
|
function ensureIndexRow(id, name) {
|
|
243
448
|
const indexPath = path.join(cwd, "project", "index.md");
|
|
244
449
|
if (!fs.existsSync(indexPath)) {
|
|
@@ -324,7 +529,10 @@ function parseIndexRows(content) {
|
|
|
324
529
|
.map((parts) => ({
|
|
325
530
|
id: parts[1],
|
|
326
531
|
title: parts[2],
|
|
327
|
-
|
|
532
|
+
description: parts[3],
|
|
533
|
+
status: parts[4],
|
|
534
|
+
createdAt: parts[5],
|
|
535
|
+
updatedAt: parts[6]
|
|
328
536
|
}));
|
|
329
537
|
}
|
|
330
538
|
|
|
@@ -477,12 +685,20 @@ function showHelp() {
|
|
|
477
685
|
|
|
478
686
|
Usage:
|
|
479
687
|
sa-spec init [--full]
|
|
480
|
-
sa-spec new --id REQ-001 --name login
|
|
688
|
+
sa-spec new [--id REQ-001] --name login [--branch]
|
|
689
|
+
sa-spec finalize --name login
|
|
690
|
+
sa-spec reindex
|
|
481
691
|
sa-spec check
|
|
482
692
|
sa-spec upgrade [--dry-run]
|
|
693
|
+
sa-spec --version
|
|
483
694
|
`);
|
|
484
695
|
}
|
|
485
696
|
|
|
697
|
+
function showVersion() {
|
|
698
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
|
699
|
+
console.log(pkg.version);
|
|
700
|
+
}
|
|
701
|
+
|
|
486
702
|
function fail(message) {
|
|
487
703
|
console.error(message);
|
|
488
704
|
process.exitCode = 1;
|
package/templates/AGENTS.md
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
- 交給 OpenSpec 或其他 AI 開發工具時,必須指定它先閱讀 `handoff.md`,並以 `handoff.md` 作為開發入口與限制摘要;其他規格文件作為詳細來源。
|
|
40
40
|
- `spec:commit` 完成文件歸檔後,必須自動建立本機 Git commit;commit message 以需求編號與需求名稱為主,並加上簡短需求說明,格式為 `docs(REQ-001): 需求名稱 - 簡短需求說明`。
|
|
41
41
|
- `spec:commit` 只有在使用者明確要求推送 remote,或專案設定啟用 auto-push 時,才可執行 `git push`;push 失敗時只回報認證或網路問題,不得回滾已完成的文件歸檔與本機 commit。
|
|
42
|
+
- 多人協作與 Git-Flow 模式(延遲綁定序號):支援多人平行開發。提出需求時可於 feature branch(如 `feat/<name>`)建立草稿目錄,內部使用 `{{REQ_ID}}` 佔位;執行 `spec:analyze` 前應先確保取得 master 最新規格以防漏檢衝突;執行 `spec:commit` 歸檔時向 master 確認最新可用序號並定號,自動將目錄定名為正式 `REQ-xxx`、替換內部佔位符、重新生成 `project/index.md`,避免多人合併時的序號競爭與索引衝突。
|
|
42
43
|
- 文件未經使用者確認,不得標示為 `已審核`。
|
|
43
44
|
- `uml/` 內的 UML 圖不限單一 UML 圖型;`spec:analyze` 必須依需求選擇最能說明流程、互動、狀態或資料關係的 UML 圖,例如活動圖、循序圖、使用案例圖、狀態圖或類別圖,不可為了固定格式硬產生活動圖。**嚴禁將多張圖混在同一個檔案中**,必須在需求資料夾下的 `uml/` 目錄拆分成獨立的 `.puml` 檔案(例如 `uml/main.puml`、`uml/sequence.puml`、`uml/state.puml`),且每個檔案只能包含一組 `@startuml` 與 `@enduml`,以避免 PlantUML 渲染或預覽失敗。
|
|
44
45
|
- 一次最多問 3 個待確認問題,優先詢問會影響範圍、資料、權限、API、DB 或驗收的問題。
|
package/templates/readme.md
CHANGED
|
@@ -237,7 +237,9 @@ sa-spec init --full
|
|
|
237
237
|
|---|---|
|
|
238
238
|
| `sa-spec init` | 建立最小文件骨架。 |
|
|
239
239
|
| `sa-spec init --full` | 建立文件骨架與完整規則文件。 |
|
|
240
|
-
| `sa-spec new --id REQ-001 --name login` |
|
|
240
|
+
| `sa-spec new [--id REQ-001] --name login [--branch]` | 建立需求資料夾與空白文件模板(未帶 `--id` 時啟用多人草稿模式,可選 `--branch` 自動建立並切換至 `feat/<name>` 分支)。 |
|
|
241
|
+
| `sa-spec finalize --name login` | 將草稿需求定號歸檔為最新序號(自動計算最新號碼、重命名目錄、批次置換 `{{REQ_ID}}` 並重建索引)。 |
|
|
242
|
+
| `sa-spec reindex` | 掃描 `project/REQ-*` 目錄,依序號重新生成乾淨無衝突的 `project/index.md`。 |
|
|
241
243
|
| `sa-spec check` | 檢查基本文件是否存在。 |
|
|
242
244
|
| `sa-spec status` | 顯示系統規格與需求索引狀態。 |
|
|
243
245
|
| `sa-spec doctor` | 檢查必要檔案是否存在。 |
|
|
@@ -349,6 +351,64 @@ docs(REQ-001): 番茄時鐘 - 新增專注與休息計時需求
|
|
|
349
351
|
|
|
350
352
|
只有在使用者明確要求推送 remote,或專案設定啟用 auto-push 時,才會執行 `git push`。如果 push 失敗,只回報認證或網路問題,不會回滾已完成的文件歸檔與本機 commit。
|
|
351
353
|
|
|
354
|
+
## 多人協作解決方案(Git-Flow 與延遲綁定 ID)
|
|
355
|
+
|
|
356
|
+
在單人開發時,循序流水號(`REQ-001`、`REQ-002`)簡單直覺;但在多人平行協作時,容易引發兩大痛點:
|
|
357
|
+
1. **序號競爭撞車**:Alice 與 Bob 同時在各自的分支開發,雙方本機都取了 `REQ-003`,合併回主幹時發生目錄重名衝突。
|
|
358
|
+
2. **中心化檔案衝突**:每次歸檔都要修改 `project/index.md`,導致頻繁的 Git merge conflict。
|
|
359
|
+
|
|
360
|
+
`sa-spec v0.2.0` 引進 **「Feature Branch 隔離 + 延遲綁定序號(Late-Binding ID)」** 完整解決方案:
|
|
361
|
+
|
|
362
|
+
```mermaid
|
|
363
|
+
flowchart TD
|
|
364
|
+
A[開新需求: sa-spec new --name cart --branch] --> B[建立並切換至 feat/cart 分支<br/>以 project/cart/ 建立草稿目錄]
|
|
365
|
+
B --> C[AI 分析與起草: sca<br/>內部使用 {{REQ_ID}} 佔位<br/>自動同步 master 規格防護]
|
|
366
|
+
C --> D{使用者確認通過<br/>執行 scc 或 finalize}
|
|
367
|
+
D --> E[查詢 master 最新序號 N]
|
|
368
|
+
E --> F[重命名為 project/REQ-N+1-cart/<br/>批次置換 {{REQ_ID}} 為正式號碼]
|
|
369
|
+
F --> G[sa-spec reindex: 動態重構 index.md]
|
|
370
|
+
G --> H[合併回 master: 零衝突、序號永遠連續!]
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### 多人協作四步流程
|
|
374
|
+
|
|
375
|
+
#### 1. 提出需求(草稿與分支隔離)
|
|
376
|
+
開需求時**不搶序號**,直接以語意名稱建立分支與草稿目錄:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
# 自動建立並切換至 feat/cart-checkout 分支,建立 project/cart-checkout/ 草稿目錄
|
|
380
|
+
sa-spec new --name cart-checkout --branch
|
|
381
|
+
```
|
|
382
|
+
在 VS Code 側邊欄輸入:
|
|
383
|
+
```text
|
|
384
|
+
scp 購物車結帳需求
|
|
385
|
+
```
|
|
386
|
+
* **特點**:目錄名稱為 `project/cart-checkout/`,內部所有檔案皆使用 `{{REQ_ID}}` 佔位符。多人同時提出需求互不干擾、零衝突。即使需求中途放棄,直接刪除分支即可,絕不留下幽靈跳號。
|
|
387
|
+
|
|
388
|
+
#### 2. 分析與衝突檢查(規格基線同步)
|
|
389
|
+
在分支上執行 `spec:analyze`(或 `sca`)前,工具會確認已取得 `master`(或 `origin/master`)的最新規格,確保是以全專案最新基準進行影響評估,避免因分支落後而漏檢權限、API 或資料表衝突。
|
|
390
|
+
|
|
391
|
+
#### 3. 確認歸檔與延遲定號(Late-Binding)
|
|
392
|
+
當需求規格確認無誤,準備歸檔時:
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
# 自動向 master 查詢最新可用序號(例如 REQ-006)
|
|
396
|
+
sa-spec finalize --name cart-checkout
|
|
397
|
+
```
|
|
398
|
+
* **自動化執行**:
|
|
399
|
+
1. 取得最新序號(例如目前最大是 `REQ-005`,自動取得 `REQ-006`)。
|
|
400
|
+
2. 使用 `git mv` 將目錄重命名為 `project/REQ-006-cart-checkout`。
|
|
401
|
+
3. 自動掃描並將目錄內所有檔案的 `{{REQ_ID}}` 批次置換為 `REQ-006`。
|
|
402
|
+
4. 自動執行 `reindex` 重建需求總表。
|
|
403
|
+
|
|
404
|
+
#### 4. 消除索引合併衝突(`sa-spec reindex`)
|
|
405
|
+
`project/index.md` 改為由目錄動態生成的「衍生清單」,不再依賴脆弱的手動 append:
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
sa-spec reindex
|
|
409
|
+
```
|
|
410
|
+
* 任何時候若有 PR 合併產生 index 衝突,只要執行 `sa-spec reindex`,即可依序號重新排序生成乾淨的總表,無需人工手動解 conflict。
|
|
411
|
+
|
|
352
412
|
## 完整範例:番茄時鐘
|
|
353
413
|
|
|
354
414
|
以下示範從空資料夾開始,建立一個「番茄時鐘」需求。
|
|
@@ -597,6 +657,17 @@ git push origin master
|
|
|
597
657
|
|
|
598
658
|
## 更新紀錄
|
|
599
659
|
|
|
660
|
+
### v0.2.0
|
|
661
|
+
- **多人協作 Git-Flow 解決方案(延遲綁定序號與零衝突索引)**:
|
|
662
|
+
- **解決痛點**:多人平行開發時,傳統流水號(`REQ-001`)容易在各自分支撞車,且中心化的 `project/index.md` 容易造成 Git merge conflict。
|
|
663
|
+
- **延遲綁定序號(Late-Binding ID)**:開需求時不搶號,在 feature branch 上以語意名稱建立草稿需求(如 `project/cart`),內部使用 `{{REQ_ID}}` 佔位;只有在 `spec:commit` 最終歸檔時,才向 master/遠端確認最新可用序號並定號(如 `REQ-003`),自動批次置換佔位符,徹底避免幽靈跳號與序號競爭。
|
|
664
|
+
- **動態重建需求索引(`sa-spec reindex`)**:將 `project/index.md` 改為根據 `project/REQ-*` 目錄動態掃描並依序號排序生成,消除手動 append 造成的 Git 合併衝突。
|
|
665
|
+
- **CLI 指令升級**:
|
|
666
|
+
- `sa-spec new [--id REQ-001] --name login [--branch]`:支援草稿模式與自動切換 feature 分支。
|
|
667
|
+
- `sa-spec finalize --name login`:自動定號、重命名目錄、置換佔位符並重建索引。
|
|
668
|
+
- `sa-spec reindex`:一鍵掃描並重新排序生成乾淨的 `project/index.md`。
|
|
669
|
+
- **分析前防護**:`spec:analyze` 執行前確保取得 master/遠端最新規格,避免分支規格落後導致漏檢衝突。
|
|
670
|
+
|
|
600
671
|
### v0.1.3
|
|
601
672
|
- **支援指令簡寫別名(同時保留完整指令)**:
|
|
602
673
|
- `sci` = `spec:init`
|
|
@@ -43,6 +43,7 @@ description: 用 init、propose、analyze、commit 四段流程整理需求,
|
|
|
43
43
|
- 交給 OpenSpec 或其他 AI 開發工具時,必須指定它先閱讀 `handoff.md`,並以 `handoff.md` 作為開發入口與限制摘要;其他規格文件作為詳細來源。
|
|
44
44
|
- `spec:commit` 完成文件歸檔後,必須自動建立本機 Git commit;commit message 以需求編號與需求名稱為主,並加上簡短需求說明,格式為 `docs(REQ-001): 需求名稱 - 簡短需求說明`。
|
|
45
45
|
- `spec:commit` 只有在使用者明確要求推送 remote,或專案設定啟用 auto-push 時,才可執行 `git push`;push 失敗時只回報認證或網路問題,不得回滾已完成的文件歸檔與本機 commit。
|
|
46
|
+
- 多人協作與 Git-Flow 模式(延遲綁定序號):支援多人平行開發。提出需求時可於 feature branch(如 `feat/<name>`)建立草稿目錄,內部使用 `{{REQ_ID}}` 佔位;執行 `spec:analyze` 前應先確保取得 master 最新規格以防漏檢衝突;執行 `spec:commit` 歸檔時向 master 確認最新可用序號並定號,自動將目錄定名為正式 `REQ-xxx`、替換內部佔位符、重新生成 `project/index.md`,避免多人合併時的序號競爭與索引衝突。
|
|
46
47
|
- 文件未經使用者確認,不得標示為 `已審核`。
|
|
47
48
|
- `uml/` 內的 UML 圖不限單一 UML 圖型;`spec:analyze` 必須依需求選擇最能說明流程、互動、狀態或資料關係的 UML 圖,例如活動圖、循序圖、使用案例圖、狀態圖或類別圖,不可為了固定格式硬產生活動圖。**嚴禁將多張圖混在同一個檔案中**,必須在需求資料夾下的 `uml/` 目錄拆分成獨立的 `.puml` 檔案(例如 `uml/main.puml`、`uml/sequence.puml`、`uml/state.puml`),且每個檔案只能包含一組 `@startuml` 與 `@enduml`,以避免 PlantUML 渲染或預覽失敗。
|
|
48
49
|
- 一次最多問 3 個待確認問題,優先詢問會影響範圍、資料、權限、API、DB 或驗收的問題。
|