specthread 0.1.1 → 0.1.3
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/README.md +27 -25
- package/dist/bin/check.js +4 -6
- package/dist/checks/changelog.js +2 -2
- package/dist/checks/links.js +2 -2
- package/dist/checks/markers.js +1 -1
- package/dist/checks/sections.js +2 -2
- package/dist/commands/init.js +3 -3
- package/dist/config.schema.d.ts +20 -5
- package/dist/config.schema.js +38 -0
- package/dist/gen/summary.js +1 -1
- package/dist/types.d.ts +2 -4
- package/dist/utils/parse.d.ts +6 -6
- package/dist/utils/parse.js +36 -35
- package/dist/utils/resolve.js +5 -5
- package/dist/utils/scan.js +22 -15
- package/dist/utils/scope.js +1 -1
- package/package.json +4 -1
- package/scaffold/config.jsonc +11 -2
package/README.md
CHANGED
|
@@ -5,11 +5,13 @@ Spec-Driven Development (SDD) 도구. 문서가 단일 진실 원천이고, 검
|
|
|
5
5
|
## 시작하기
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install -
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
npm install -g specthread
|
|
9
|
+
specthread init
|
|
10
|
+
specthread check
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
프로젝트 로컬로 쓰려면 `npm install -D specthread` 후 `npx specthread`로 실행한다.
|
|
14
|
+
|
|
13
15
|
`init`이 프로젝트에 SDD 체계를 세팅한다:
|
|
14
16
|
|
|
15
17
|
```
|
|
@@ -18,9 +20,9 @@ specthread/ ← 문서 규칙·설정·미확정 사항
|
|
|
18
20
|
rules.md
|
|
19
21
|
project.md
|
|
20
22
|
pending.md
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
templates/ ← 문서 골격 (수정 가능, check 대상)
|
|
24
|
+
spec.md
|
|
25
|
+
plan.md
|
|
24
26
|
AGENTS.md ← AI 도구 진입점
|
|
25
27
|
CLAUDE.md ← Claude Code용 (@AGENTS.md)
|
|
26
28
|
.claude/skills/ ← Claude Code 스킬
|
|
@@ -59,14 +61,14 @@ specthread/config.local.jsonc (개인)
|
|
|
59
61
|
|
|
60
62
|
설정이 없으면 기본값으로 동작한다. init이 생성하는 `config.jsonc`에 모든 옵션이 주석으로 설명되어 있다.
|
|
61
63
|
|
|
62
|
-
| 키
|
|
63
|
-
|
|
64
|
-
| `path`
|
|
65
|
-
| `features`
|
|
66
|
-
| `markers`
|
|
67
|
-
| `docTypes`
|
|
68
|
-
| `skipCheck` | 검사 건너뛸 경로
|
|
69
|
-
| `skipRefs`
|
|
64
|
+
| 키 | 역할 |
|
|
65
|
+
| ----------- | ----------------------------------------------- |
|
|
66
|
+
| `path` | 스캔 대상 경로 (자유 KV) |
|
|
67
|
+
| `features` | 기능 플래그 (`markers`, `emDash`, `references`) |
|
|
68
|
+
| `markers` | 마커 종류·시점 라벨 |
|
|
69
|
+
| `docTypes` | 경로별 템플릿·프론트매터 스키마 |
|
|
70
|
+
| `skipCheck` | 검사 건너뛸 경로 |
|
|
71
|
+
| `skipRefs` | 참조 절 생성 건너뛸 경로 |
|
|
70
72
|
|
|
71
73
|
## SDD 작업 흐름
|
|
72
74
|
|
|
@@ -112,20 +114,20 @@ AI는 작업 중에 `check`와 `gen`을 자동으로 호출한다. `AGENTS.md`
|
|
|
112
114
|
|
|
113
115
|
`AGENTS.md`가 본체. 대부분의 AI 코딩 도구가 이 파일을 읽는다.
|
|
114
116
|
|
|
115
|
-
| 도구
|
|
116
|
-
|
|
117
|
-
| Claude Code
|
|
118
|
-
| Cursor / Copilot / Codex / Gemini | `AGENTS.md`를 네이티브로 읽음
|
|
117
|
+
| 도구 | 동작 |
|
|
118
|
+
| --------------------------------- | -------------------------------------- |
|
|
119
|
+
| Claude Code | `CLAUDE.md`의 `@AGENTS.md`가 자동 확장 |
|
|
120
|
+
| Cursor / Copilot / Codex / Gemini | `AGENTS.md`를 네이티브로 읽음 |
|
|
119
121
|
|
|
120
122
|
`--tools claude` (기본값)로 init하면 Claude Code 스킬이 함께 설치된다:
|
|
121
123
|
|
|
122
|
-
| 스킬
|
|
123
|
-
|
|
124
|
-
| `/check`
|
|
125
|
-
| `/gen`
|
|
126
|
-
| `/plan-open`
|
|
127
|
-
| `/plan-run`
|
|
128
|
-
| `/plan-close` | 완료된 작업을 spec에 흡수
|
|
124
|
+
| 스킬 | 역할 |
|
|
125
|
+
| ------------- | ----------------------------- |
|
|
126
|
+
| `/check` | 문서 검사 실행 + 결과 해석 |
|
|
127
|
+
| `/gen` | 참조 절·목차 생성 + 적용 안내 |
|
|
128
|
+
| `/plan-open` | 작업 계획 문서 작성·검수·확정 |
|
|
129
|
+
| `/plan-run` | 계획에 따라 실행·기록 |
|
|
130
|
+
| `/plan-close` | 완료된 작업을 spec에 흡수 |
|
|
129
131
|
|
|
130
132
|
스킬 없이 자연어로 같은 작업을 요청해도 된다. `AGENTS.md`가 AI에게 워크플로우를 알려주기 때문이다. 스킬은 자주 쓰는 흐름의 단축키다.
|
|
131
133
|
|
package/dist/bin/check.js
CHANGED
|
@@ -22,20 +22,18 @@ import { isWorkExempt } from '../utils/scope.js';
|
|
|
22
22
|
const config = loadConfig();
|
|
23
23
|
const index = buildIndex(config);
|
|
24
24
|
// 색인 규모를 먼저 찍는다. 지적 수만 보면 검사가 실제로 대상을 훑었는지 알 수 없다
|
|
25
|
-
const counts = {
|
|
25
|
+
const counts = { doc: 0, source: 0 };
|
|
26
26
|
let headings = 0;
|
|
27
27
|
let links = 0;
|
|
28
28
|
let sectionRefs = 0;
|
|
29
29
|
let markers = 0;
|
|
30
|
-
let legacyMarkers = 0;
|
|
31
30
|
let pendingItems = 0;
|
|
32
31
|
for (const f of index.files.values()) {
|
|
33
32
|
counts[f.kind]++;
|
|
34
33
|
headings += f.headings.length;
|
|
35
34
|
links += f.links.length;
|
|
36
35
|
sectionRefs += f.sectionRefs.length;
|
|
37
|
-
markers += f.markers.
|
|
38
|
-
legacyMarkers += f.markers.filter((m) => m.legacy).length;
|
|
36
|
+
markers += f.markers.length;
|
|
39
37
|
pendingItems += f.pendingItems.length;
|
|
40
38
|
}
|
|
41
39
|
let ignoredLines = 0;
|
|
@@ -44,9 +42,9 @@ for (const f of index.files.values())
|
|
|
44
42
|
const summary = {
|
|
45
43
|
title: '색인',
|
|
46
44
|
lines: [
|
|
47
|
-
`문서 ${counts.
|
|
45
|
+
`문서 ${counts.doc} / 소스 ${counts.source}`,
|
|
48
46
|
`헤딩 ${headings} / 링크 ${links} / 절 참조 ${sectionRefs}`,
|
|
49
|
-
`마커
|
|
47
|
+
`마커 ${markers} / 미확정 항목 ${pendingItems}`,
|
|
50
48
|
`인라인 억제 ${ignoredLines}`,
|
|
51
49
|
],
|
|
52
50
|
};
|
package/dist/checks/changelog.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RULE } from '../constants/rules.js';
|
|
2
2
|
/** 변경 이력 순서 - 오래된 순이어야 한다 (`docs/system/rules.md` §2-4). */
|
|
3
|
-
import {
|
|
3
|
+
import { isTargetDoc } from '../utils/scope.js';
|
|
4
4
|
/**
|
|
5
5
|
* 날짜가 거꾸로 놓인 첫 자리를 찾아 한 건만 지적한다.
|
|
6
6
|
*
|
|
@@ -10,7 +10,7 @@ import { isCheckTarget } from '../utils/scope.js';
|
|
|
10
10
|
export const checkChangeLog = (index) => {
|
|
11
11
|
const findings = [];
|
|
12
12
|
for (const file of index.files.values()) {
|
|
13
|
-
if (
|
|
13
|
+
if (!isTargetDoc(file, index.config))
|
|
14
14
|
continue;
|
|
15
15
|
if (file.changeLogDates.length < 2)
|
|
16
16
|
continue;
|
package/dist/checks/links.js
CHANGED
|
@@ -3,7 +3,7 @@ import { RULE } from '../constants/rules.js';
|
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import { join, dirname, normalize } from 'node:path';
|
|
5
5
|
import { REPO_ROOT } from '../utils/scan.js';
|
|
6
|
-
import { inChangeLog, inRefSection,
|
|
6
|
+
import { inChangeLog, inRefSection, isTargetDoc } from '../utils/scope.js';
|
|
7
7
|
/** 외부 링크는 파일 시스템에 없으니 확인하지 않는다 */
|
|
8
8
|
const isExternal = (target) => /^(https?:|mailto:)/.test(target);
|
|
9
9
|
/**
|
|
@@ -15,7 +15,7 @@ const isExternal = (target) => /^(https?:|mailto:)/.test(target);
|
|
|
15
15
|
export const checkLinks = (index) => {
|
|
16
16
|
const findings = [];
|
|
17
17
|
for (const file of index.files.values()) {
|
|
18
|
-
if (
|
|
18
|
+
if (!isTargetDoc(file, index.config))
|
|
19
19
|
continue;
|
|
20
20
|
const anchors = new Set(file.headings.map((h) => h.anchor));
|
|
21
21
|
for (const link of file.links) {
|
package/dist/checks/markers.js
CHANGED
|
@@ -32,7 +32,7 @@ export const checkMarkers = (index) => {
|
|
|
32
32
|
if (file.path === index.config.pending)
|
|
33
33
|
continue;
|
|
34
34
|
for (const marker of file.markers) {
|
|
35
|
-
if (marker.
|
|
35
|
+
if (marker.slug === "")
|
|
36
36
|
continue;
|
|
37
37
|
const id = `${marker.kind}::${marker.slug}`;
|
|
38
38
|
seen.add(id);
|
package/dist/checks/sections.js
CHANGED
|
@@ -38,7 +38,7 @@ const sectionNumbers = (index) => {
|
|
|
38
38
|
const byFile = new Map();
|
|
39
39
|
for (const file of index.files.values()) {
|
|
40
40
|
// 절 번호는 문서만 갖는다. 코드·데이터에는 헤딩이 없다
|
|
41
|
-
if (file.kind !== "
|
|
41
|
+
if (file.kind !== "doc")
|
|
42
42
|
continue;
|
|
43
43
|
const nums = new Set();
|
|
44
44
|
for (const heading of file.headings) {
|
|
@@ -102,7 +102,7 @@ const inspect = (index, numsByFile, file, ref) => {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
// 다른 문서의 절은 앵커 링크로 가리켜야 한다. 자기 절 참조와 코드 주석은 면제다
|
|
105
|
-
if (file.kind === "
|
|
105
|
+
if (file.kind === "doc" && !ref.linked && ref.targetFile !== file.path) {
|
|
106
106
|
return {
|
|
107
107
|
file: file.path,
|
|
108
108
|
line: ref.line,
|
package/dist/commands/init.js
CHANGED
|
@@ -88,13 +88,13 @@ export const init = (args) => {
|
|
|
88
88
|
console.log(` specthread/${file} 이미 존재 - 건너뜀`);
|
|
89
89
|
}
|
|
90
90
|
const templateFiles = ["spec.md", "plan.md"];
|
|
91
|
-
const templatesDir = join(
|
|
91
|
+
const templatesDir = join(stDir, "templates");
|
|
92
92
|
for (const file of templateFiles) {
|
|
93
93
|
const created = copyIfMissing(join(scaffold, "templates", file), join(templatesDir, file));
|
|
94
94
|
if (created)
|
|
95
|
-
console.log(`
|
|
95
|
+
console.log(` specthread/templates/${file} 생성`);
|
|
96
96
|
else
|
|
97
|
-
console.log(`
|
|
97
|
+
console.log(` specthread/templates/${file} 이미 존재 - 건너뜀`);
|
|
98
98
|
}
|
|
99
99
|
ensureAgentsMd(cwd, scaffold);
|
|
100
100
|
if (tools.has("claude")) {
|
package/dist/config.schema.d.ts
CHANGED
|
@@ -5,13 +5,25 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { RuleGroup } from "./constants/rules.ts";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* 파일 종류별 확장자 매핑.
|
|
9
|
+
*
|
|
10
|
+
* - `doc`: 기획 소스. 풀파싱 대상 (헤딩, 링크, 목차, 참조절, 변경이력, 마커).
|
|
11
|
+
* - `source`: 문서 외 참조 파일. 마커 + 절참조 스캔만.
|
|
12
|
+
*
|
|
13
|
+
* JSON 전용 `"_pending"` 키 패턴은 확장자로 내부 자동 분기.
|
|
14
|
+
*/
|
|
15
|
+
export interface FileKindsConfig {
|
|
16
|
+
doc: string[];
|
|
17
|
+
source: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 프로젝트 경로. 자유 KV - 키는 용도 라벨, 값은 경로 배열.
|
|
9
21
|
* 디렉터리면 재귀 스캔, 파일이면 직접 로드. 파싱 전략은 확장자로 결정.
|
|
10
22
|
*
|
|
11
23
|
* 예:
|
|
12
|
-
* "docs": ["docs/"]
|
|
13
|
-
* "source": ["client/src/"], "data": ["data/"]
|
|
14
|
-
* "meta": ["CLAUDE.md", "AGENTS.md"]
|
|
24
|
+
* "docs": ["docs/"] - docs-only 프로젝트
|
|
25
|
+
* "source": ["client/src/"], "data": ["data/"] - 소스+데이터
|
|
26
|
+
* "meta": ["CLAUDE.md", "AGENTS.md"] - 루트의 개별 파일
|
|
15
27
|
*/
|
|
16
28
|
export type PathConfig = Record<string, string[]>;
|
|
17
29
|
/**
|
|
@@ -67,12 +79,14 @@ export type Locale = "ko";
|
|
|
67
79
|
export interface SpecthreadConfig {
|
|
68
80
|
/** 스캔 대상 경로. 자유 KV */
|
|
69
81
|
path: PathConfig;
|
|
82
|
+
/** 파일 종류별 확장자 매핑 */
|
|
83
|
+
fileKinds: FileKindsConfig;
|
|
70
84
|
features: FeaturesConfig;
|
|
71
85
|
markers: MarkersConfig;
|
|
72
86
|
docTypes: Record<string, DocTypeConfig>;
|
|
73
87
|
/**
|
|
74
88
|
* 문서명 해소 시 무시할 단어.
|
|
75
|
-
* 예: ["spec"]
|
|
89
|
+
* 예: ["spec"] - "spec §4" 가 template/spec.md 로 잘못 매칭되는 것 방지.
|
|
76
90
|
*/
|
|
77
91
|
ignoreDocNames: string[];
|
|
78
92
|
/**
|
|
@@ -93,4 +107,5 @@ export interface SpecthreadConfig {
|
|
|
93
107
|
/** 초안 문서 폴더 */
|
|
94
108
|
work: string;
|
|
95
109
|
}
|
|
110
|
+
export declare const DEFAULT_FILE_KINDS: FileKindsConfig;
|
|
96
111
|
export declare const DEFAULT_CONFIG: SpecthreadConfig;
|
package/dist/config.schema.js
CHANGED
|
@@ -1,11 +1,49 @@
|
|
|
1
1
|
// ---------------------------------------------------------------------------
|
|
2
2
|
// 기본값
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
|
+
export const DEFAULT_FILE_KINDS = {
|
|
5
|
+
doc: [".md"],
|
|
6
|
+
source: [
|
|
7
|
+
".js",
|
|
8
|
+
".jsx",
|
|
9
|
+
".mjs",
|
|
10
|
+
".ts",
|
|
11
|
+
".tsx",
|
|
12
|
+
".mts",
|
|
13
|
+
".py",
|
|
14
|
+
".java",
|
|
15
|
+
".kt",
|
|
16
|
+
".c",
|
|
17
|
+
".h",
|
|
18
|
+
".cpp",
|
|
19
|
+
".cs",
|
|
20
|
+
".go",
|
|
21
|
+
".rs",
|
|
22
|
+
".swift",
|
|
23
|
+
".php",
|
|
24
|
+
".rb",
|
|
25
|
+
".dart",
|
|
26
|
+
".lua",
|
|
27
|
+
".sh",
|
|
28
|
+
".json",
|
|
29
|
+
".jsonc",
|
|
30
|
+
".yaml",
|
|
31
|
+
".yml",
|
|
32
|
+
".toml",
|
|
33
|
+
".xml",
|
|
34
|
+
".html",
|
|
35
|
+
".css",
|
|
36
|
+
".scss",
|
|
37
|
+
".sql",
|
|
38
|
+
".graphql",
|
|
39
|
+
],
|
|
40
|
+
};
|
|
4
41
|
export const DEFAULT_CONFIG = {
|
|
5
42
|
path: {
|
|
6
43
|
docs: ["docs/"],
|
|
7
44
|
specthread: ["specthread/"],
|
|
8
45
|
},
|
|
46
|
+
fileKinds: DEFAULT_FILE_KINDS,
|
|
9
47
|
features: {
|
|
10
48
|
markers: true,
|
|
11
49
|
emDash: true,
|
package/dist/gen/summary.js
CHANGED
|
@@ -52,7 +52,7 @@ const markerSites = (index) => {
|
|
|
52
52
|
if (file.path.startsWith(index.config.work))
|
|
53
53
|
continue;
|
|
54
54
|
for (const marker of file.markers) {
|
|
55
|
-
if (marker.
|
|
55
|
+
if (marker.slug === '')
|
|
56
56
|
continue;
|
|
57
57
|
const id = `${marker.kind}::${marker.slug}`;
|
|
58
58
|
out.set(id, (out.get(id) ?? 0) + 1);
|
package/dist/types.d.ts
CHANGED
|
@@ -63,13 +63,11 @@ export interface SectionRef {
|
|
|
63
63
|
linked: boolean;
|
|
64
64
|
line: number;
|
|
65
65
|
}
|
|
66
|
-
/** 미결 마커
|
|
66
|
+
/** 미결 마커 하나 */
|
|
67
67
|
export interface Marker {
|
|
68
68
|
kind: string;
|
|
69
69
|
slug: string;
|
|
70
70
|
line: number;
|
|
71
|
-
/** 구 `TEMP_*` 형식인지. 재편에서 치환 대상 */
|
|
72
|
-
legacy: boolean;
|
|
73
71
|
}
|
|
74
72
|
/** 큐 항목 또는 문서 미확정 사항 절 항목 */
|
|
75
73
|
export interface PendingItem {
|
|
@@ -78,7 +76,7 @@ export interface PendingItem {
|
|
|
78
76
|
line: number;
|
|
79
77
|
}
|
|
80
78
|
/** 파일 종류. 뽑을 재료와 참조 해소 규칙이 달라진다 */
|
|
81
|
-
export type FileKind = "
|
|
79
|
+
export type FileKind = "doc" | "source";
|
|
82
80
|
/** 색인된 파일 하나. 검사기와 생성기가 이 모양만 보고 일한다 */
|
|
83
81
|
export interface IndexedFile {
|
|
84
82
|
/** 리포 루트 기준 상대 경로 */
|
package/dist/utils/parse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnchorLabelSpan, FileKind, Heading, IndexedFile, Marker, Range } from
|
|
1
|
+
import type { AnchorLabelSpan, FileKind, Heading, IndexedFile, Marker, Range } from "../types.ts";
|
|
2
2
|
/**
|
|
3
3
|
* 펜스 코드블록 바깥의 줄만 넘겨준다.
|
|
4
4
|
*
|
|
@@ -25,12 +25,12 @@ export declare const anchorLinkLabelSpans: (line: string) => AnchorLabelSpan[];
|
|
|
25
25
|
/** 마크다운 링크의 대상 `(...)` 구간. URL 안 문자열을 본문과 가르는 데 쓴다 */
|
|
26
26
|
export declare const linkTargetSpans: (line: string) => Range[];
|
|
27
27
|
/**
|
|
28
|
-
* 마커를 모은다.
|
|
28
|
+
* 마커를 모은다.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* doc 은 펜스 안을 건너뛰고 (템플릿이 마커 예시를 코드블록에 담는다),
|
|
31
|
+
* source 는 전부 훑는다. JSON 계열 파일은 `"_pending"` 키 패턴을 추가로 잡는다.
|
|
32
32
|
*/
|
|
33
|
-
export declare const parseMarkers: (lines: string[], kind: FileKind) => Marker[];
|
|
33
|
+
export declare const parseMarkers: (lines: string[], kind: FileKind, path?: string) => Marker[];
|
|
34
34
|
/**
|
|
35
35
|
* 헤딩만 뽑는다.
|
|
36
36
|
*
|
|
@@ -47,4 +47,4 @@ export declare const parseHeadings: (lines: string[]) => Heading[];
|
|
|
47
47
|
* 훑으면서 들고 가는 상태는 두 개뿐이다 - 직전 헤딩 번호 (링크를 절에 귀속시킨다) 와
|
|
48
48
|
* 꼬리 절 진입 여부. 절 범위는 훑기가 끝난 뒤 헤딩 목록에서 뽑는다.
|
|
49
49
|
*/
|
|
50
|
-
export declare const parseMarkdown: (path: string, lines: string[]) => Omit<IndexedFile,
|
|
50
|
+
export declare const parseMarkdown: (path: string, lines: string[]) => Omit<IndexedFile, "sectionRefs" | "ignored">;
|
package/dist/utils/parse.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* 펜스 코드블록 안은 전부 무시한다. 템플릿이 골격을 코드블록으로 담고 있어서
|
|
6
6
|
* 추적하지 않으면 헤딩 88 개와 링크 90 개가 오탐으로 잡힌다.
|
|
7
7
|
*/
|
|
8
|
-
import { TAIL_NAMES } from
|
|
9
|
-
import { slugify, splitHeadingNum } from
|
|
8
|
+
import { TAIL_NAMES } from "../constants/docs.js";
|
|
9
|
+
import { slugify, splitHeadingNum } from "./anchor.js";
|
|
10
10
|
/**
|
|
11
11
|
* 꼬리 절 이름. 하나가 나오면 그 뒤는 전부 꼬리다.
|
|
12
12
|
*
|
|
@@ -42,7 +42,7 @@ export const codeSpanMask = (line) => {
|
|
|
42
42
|
const mask = new Array(line.length).fill(false);
|
|
43
43
|
let open = -1;
|
|
44
44
|
for (let i = 0; i < line.length; i++) {
|
|
45
|
-
if (line[i] !==
|
|
45
|
+
if (line[i] !== "`")
|
|
46
46
|
continue;
|
|
47
47
|
if (open < 0)
|
|
48
48
|
open = i;
|
|
@@ -64,13 +64,13 @@ export const codeSpanMask = (line) => {
|
|
|
64
64
|
export const anchorLinkLabelSpans = (line) => {
|
|
65
65
|
const spans = [];
|
|
66
66
|
for (const m of line.matchAll(/\[([^\]]*)\]\(([^)\s]+)\)/g)) {
|
|
67
|
-
if (!m[2].includes(
|
|
67
|
+
if (!m[2].includes("#"))
|
|
68
68
|
continue;
|
|
69
69
|
const labelStart = m.index + 1;
|
|
70
70
|
spans.push({
|
|
71
71
|
start: labelStart,
|
|
72
72
|
end: labelStart + m[1].length,
|
|
73
|
-
target: m[2].split(
|
|
73
|
+
target: m[2].split("#")[0],
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
return spans;
|
|
@@ -84,14 +84,10 @@ export const linkTargetSpans = (line) => {
|
|
|
84
84
|
}
|
|
85
85
|
return spans;
|
|
86
86
|
};
|
|
87
|
-
/**
|
|
88
|
-
const
|
|
89
|
-
/** 구 `TEMP_*` 형식. slug 가 없어 큐와 묶이지 않으므로 재편에서 치환한다 */
|
|
90
|
-
const MARKER_LEGACY = /TEMP_(DESIGN|BALANCE|DEPS|STYLE)\b/g;
|
|
87
|
+
/** 마커. 종류와 slug 를 함께 캡처한다 */
|
|
88
|
+
const MARKER = /PENDING::([a-z]+)::([a-z0-9][a-z0-9-]*)/g;
|
|
91
89
|
/** JSON 안 마커. 데이터에는 주석을 못 달아서 필드로 표기한다 */
|
|
92
90
|
const PENDING_JSON = /"_pending"\s*:\s*"([a-z]+)::([a-z0-9][a-z0-9-]*)"/g;
|
|
93
|
-
/** JSON 안 구 형식 마커 */
|
|
94
|
-
const TEMP_JSON = /"_temp"\s*:\s*"([a-z]+)"/g;
|
|
95
91
|
/**
|
|
96
92
|
* 미확정 항목. 마커와 달리 `PENDING` 접두가 없다.
|
|
97
93
|
*
|
|
@@ -104,27 +100,27 @@ const PENDING_ITEM = /^(?:\s*-|###)\s+[`\[]+([a-z]+)::([a-z0-9][a-z0-9-]*)[`\]]+
|
|
|
104
100
|
const LINK = /\[([^\]]*)\]\(([^)\s]+)\)/g;
|
|
105
101
|
/** 변경 이력 표의 첫 칸 날짜 */
|
|
106
102
|
const CHANGELOG_DATE = /^\|\s*(\d{4}-\d{2}-\d{2})/;
|
|
103
|
+
/** 주석 불가 확장자. `"_pending"` 키 패턴을 추가로 스캔한다 */
|
|
104
|
+
const UNCOMMENTABLE_EXTS = new Set([".json"]);
|
|
107
105
|
/**
|
|
108
|
-
* 마커를 모은다.
|
|
106
|
+
* 마커를 모은다.
|
|
109
107
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
108
|
+
* doc 은 펜스 안을 건너뛰고 (템플릿이 마커 예시를 코드블록에 담는다),
|
|
109
|
+
* source 는 전부 훑는다. JSON 계열 파일은 `"_pending"` 키 패턴을 추가로 잡는다.
|
|
112
110
|
*/
|
|
113
|
-
export const parseMarkers = (lines, kind) => {
|
|
111
|
+
export const parseMarkers = (lines, kind, path) => {
|
|
112
|
+
const ext = path ? path.slice(path.lastIndexOf(".")).toLowerCase() : "";
|
|
113
|
+
const isUncommentable = UNCOMMENTABLE_EXTS.has(ext);
|
|
114
114
|
const out = [];
|
|
115
115
|
const scan = (line, i) => {
|
|
116
|
-
for (const m of line.matchAll(
|
|
117
|
-
out.push({ kind: m[1], slug: m[2], line: i + 1
|
|
118
|
-
|
|
119
|
-
out.push({ kind: m[1].toLowerCase(), slug: '', line: i + 1, legacy: true });
|
|
120
|
-
if (kind === 'json') {
|
|
116
|
+
for (const m of line.matchAll(MARKER))
|
|
117
|
+
out.push({ kind: m[1], slug: m[2], line: i + 1 });
|
|
118
|
+
if (isUncommentable) {
|
|
121
119
|
for (const m of line.matchAll(PENDING_JSON))
|
|
122
|
-
out.push({ kind: m[1], slug: m[2], line: i + 1
|
|
123
|
-
for (const m of line.matchAll(TEMP_JSON))
|
|
124
|
-
out.push({ kind: m[1], slug: '', line: i + 1, legacy: true });
|
|
120
|
+
out.push({ kind: m[1], slug: m[2], line: i + 1 });
|
|
125
121
|
}
|
|
126
122
|
};
|
|
127
|
-
if (kind ===
|
|
123
|
+
if (kind === "doc")
|
|
128
124
|
eachContentLine(lines, scan);
|
|
129
125
|
else
|
|
130
126
|
lines.forEach((l, i) => scan(l, i));
|
|
@@ -147,13 +143,13 @@ const findTocBlock = (lines) => {
|
|
|
147
143
|
continue;
|
|
148
144
|
// 한 줄에 몰아 쓴 인라인 나열은 그 줄이 블록 전체다. 규칙 12 위반이라
|
|
149
145
|
// 생성기가 목록 형태로 갈아끼운다
|
|
150
|
-
if (lines[i].trim() !==
|
|
146
|
+
if (lines[i].trim() !== "**목차**")
|
|
151
147
|
return { start: i + 1, end: i + 1 };
|
|
152
148
|
let end = i;
|
|
153
149
|
for (let j = i + 1; j < lines.length; j++) {
|
|
154
150
|
if (/^\s*-\s+\[/.test(lines[j]))
|
|
155
151
|
end = j;
|
|
156
|
-
else if (lines[j].trim() ===
|
|
152
|
+
else if (lines[j].trim() === "")
|
|
157
153
|
continue;
|
|
158
154
|
else
|
|
159
155
|
break;
|
|
@@ -175,7 +171,10 @@ const tailRange = (headings, title, lineCount) => {
|
|
|
175
171
|
}
|
|
176
172
|
const heading = headings[at];
|
|
177
173
|
const next = headings.slice(at + 1).find((h) => h.level === 2);
|
|
178
|
-
return {
|
|
174
|
+
return {
|
|
175
|
+
start: heading.line + 1,
|
|
176
|
+
end: next === undefined ? lineCount : next.line - 1,
|
|
177
|
+
};
|
|
179
178
|
};
|
|
180
179
|
/**
|
|
181
180
|
* 헤딩만 뽑는다.
|
|
@@ -236,11 +235,11 @@ export const parseMarkdown = (path, lines) => {
|
|
|
236
235
|
return;
|
|
237
236
|
}
|
|
238
237
|
for (const m of line.matchAll(LINK)) {
|
|
239
|
-
const [rawTarget, anchor] = m[2].split(
|
|
238
|
+
const [rawTarget, anchor] = m[2].split("#");
|
|
240
239
|
links.push({
|
|
241
240
|
label: m[1],
|
|
242
241
|
// `(#앵커)` 처럼 대상이 비면 자기 문서 안 링크다
|
|
243
|
-
target: rawTarget ===
|
|
242
|
+
target: rawTarget === "" ? null : rawTarget,
|
|
244
243
|
anchor: anchor ?? null,
|
|
245
244
|
line: i + 1,
|
|
246
245
|
section: currentSection,
|
|
@@ -252,20 +251,22 @@ export const parseMarkdown = (path, lines) => {
|
|
|
252
251
|
dated.push({ line: i + 1, date: date[1] });
|
|
253
252
|
}
|
|
254
253
|
});
|
|
255
|
-
const changeLogRange = tailRange(headings,
|
|
254
|
+
const changeLogRange = tailRange(headings, "변경 이력", lines.length);
|
|
256
255
|
// 본문에도 날짜 표가 있을 수 있어서 변경 이력 절 안의 것만 센다
|
|
257
|
-
const inLog = (line) => changeLogRange !== null &&
|
|
256
|
+
const inLog = (line) => changeLogRange !== null &&
|
|
257
|
+
line >= changeLogRange.start &&
|
|
258
|
+
line <= changeLogRange.end;
|
|
258
259
|
return {
|
|
259
260
|
path,
|
|
260
|
-
kind:
|
|
261
|
+
kind: "doc",
|
|
261
262
|
lines,
|
|
262
263
|
headings,
|
|
263
264
|
links,
|
|
264
|
-
markers: parseMarkers(lines,
|
|
265
|
+
markers: parseMarkers(lines, "doc", path),
|
|
265
266
|
pendingItems,
|
|
266
267
|
tocBlock: findTocBlock(lines),
|
|
267
|
-
refSection: tailRange(headings,
|
|
268
|
-
pendingSection: tailRange(headings,
|
|
268
|
+
refSection: tailRange(headings, "참조", lines.length),
|
|
269
|
+
pendingSection: tailRange(headings, "미확정 사항", lines.length),
|
|
269
270
|
changeLogRange,
|
|
270
271
|
changeLogDates: dated.filter((d) => inLog(d.line)).map((d) => d.date),
|
|
271
272
|
};
|
package/dist/utils/resolve.js
CHANGED
|
@@ -113,8 +113,8 @@ export const makeRefContext = (mdPaths, ignoreDocNames = []) => {
|
|
|
113
113
|
export const parseSectionRefs = (path, kind, lines, { mdPaths, nameMap, knownStems }) => {
|
|
114
114
|
const out = [];
|
|
115
115
|
const scan = (line, i) => {
|
|
116
|
-
const mask = kind === "
|
|
117
|
-
const linkedSpans = kind === "
|
|
116
|
+
const mask = kind === "doc" ? codeSpanMask(line) : null;
|
|
117
|
+
const linkedSpans = kind === "doc" ? anchorLinkLabelSpans(line) : [];
|
|
118
118
|
for (const m of line.matchAll(SECTION_REF)) {
|
|
119
119
|
// 라벨 안에 있으면 그 링크의 대상이 정답이다. 라벨 글자로 풀면 경로를 잃는다
|
|
120
120
|
const span = linkedSpans.find((s) => m.index >= s.start && m.index < s.end);
|
|
@@ -130,9 +130,9 @@ export const parseSectionRefs = (path, kind, lines, { mdPaths, nameMap, knownSte
|
|
|
130
130
|
if (docName === null) {
|
|
131
131
|
out.push({
|
|
132
132
|
num: m[1],
|
|
133
|
-
targetFile: kind === "
|
|
133
|
+
targetFile: kind === "doc" ? path : null,
|
|
134
134
|
rawTarget: null,
|
|
135
|
-
reason: kind === "
|
|
135
|
+
reason: kind === "doc" ? "resolved" : "no-doc-name",
|
|
136
136
|
linked,
|
|
137
137
|
line: i + 1,
|
|
138
138
|
});
|
|
@@ -149,7 +149,7 @@ export const parseSectionRefs = (path, kind, lines, { mdPaths, nameMap, knownSte
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
|
-
if (kind === "
|
|
152
|
+
if (kind === "doc")
|
|
153
153
|
eachContentLine(lines, scan);
|
|
154
154
|
else
|
|
155
155
|
lines.forEach((l, i) => scan(l, i));
|
package/dist/utils/scan.js
CHANGED
|
@@ -10,15 +10,21 @@ import { parseMarkdown, parseMarkers } from "./parse.js";
|
|
|
10
10
|
import { makeRefContext, parseSectionRefs } from "./resolve.js";
|
|
11
11
|
/** 프로젝트 루트 절대 경로. 색인 경로를 여기 기준 상대 경로로 통일하는 데 쓴다 */
|
|
12
12
|
export const REPO_ROOT = normalize(process.cwd());
|
|
13
|
-
/**
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
/** config.fileKinds 에서 확장자 → kind 역매핑을 만든다 */
|
|
14
|
+
const buildExtMap = (kinds) => {
|
|
15
|
+
const map = new Map();
|
|
16
|
+
for (const ext of kinds.doc)
|
|
17
|
+
map.set(ext.toLowerCase(), "doc");
|
|
18
|
+
for (const ext of kinds.source)
|
|
19
|
+
map.set(ext.toLowerCase(), "source");
|
|
20
|
+
return map;
|
|
21
|
+
};
|
|
22
|
+
/** 확장자로 파일 종류를 결정한다. config.fileKinds 기반 */
|
|
23
|
+
const kindFromPath = (file, extMap) => {
|
|
24
|
+
const dot = file.lastIndexOf(".");
|
|
25
|
+
if (dot < 0)
|
|
26
|
+
return null;
|
|
27
|
+
return extMap.get(file.slice(dot).toLowerCase()) ?? null;
|
|
22
28
|
};
|
|
23
29
|
/** 디렉터리를 재귀로 훑어 파일 경로를 모은다. `node_modules` 와 숨김 디렉터리는 건너뛴다 */
|
|
24
30
|
const walk = (dir, out = []) => {
|
|
@@ -41,14 +47,14 @@ const walk = (dir, out = []) => {
|
|
|
41
47
|
* 값이 디렉터리면 재귀 스캔, 파일이면 직접 로드. 파싱 전략은 확장자로 결정한다.
|
|
42
48
|
* 인식하지 못하는 확장자는 건너뛴다.
|
|
43
49
|
*/
|
|
44
|
-
const collectTargets = (pathConfig) => {
|
|
50
|
+
const collectTargets = (pathConfig, extMap) => {
|
|
45
51
|
const out = [];
|
|
46
52
|
const seen = new Set();
|
|
47
53
|
const add = (abs) => {
|
|
48
54
|
const rel = relative(REPO_ROOT, abs);
|
|
49
55
|
if (seen.has(rel))
|
|
50
56
|
return;
|
|
51
|
-
const kind = kindFromPath(rel);
|
|
57
|
+
const kind = kindFromPath(rel, extMap);
|
|
52
58
|
if (kind === null)
|
|
53
59
|
return;
|
|
54
60
|
seen.add(rel);
|
|
@@ -77,15 +83,16 @@ const collectTargets = (pathConfig) => {
|
|
|
77
83
|
* 위해, 한 번은 실제 파싱을 위해. 코드와 JSON 은 헤딩이 없어서 빈 값으로 채운다.
|
|
78
84
|
*/
|
|
79
85
|
export const buildIndex = (config) => {
|
|
80
|
-
const
|
|
81
|
-
const
|
|
86
|
+
const extMap = buildExtMap(config.fileKinds);
|
|
87
|
+
const targets = collectTargets(config.path, extMap);
|
|
88
|
+
const mdPaths = targets.filter((t) => t.kind === "doc").map((t) => t.path);
|
|
82
89
|
const ctx = makeRefContext(mdPaths, config.ignoreDocNames);
|
|
83
90
|
const files = new Map();
|
|
84
91
|
for (const { path, kind } of targets) {
|
|
85
92
|
const lines = readFileSync(join(REPO_ROOT, path), "utf8").split("\n");
|
|
86
93
|
const sectionRefs = parseSectionRefs(path, kind, lines, ctx);
|
|
87
94
|
const ignored = parseIgnoredLines(lines);
|
|
88
|
-
if (kind === "
|
|
95
|
+
if (kind === "doc") {
|
|
89
96
|
files.set(path, { ...parseMarkdown(path, lines), sectionRefs, ignored });
|
|
90
97
|
}
|
|
91
98
|
else {
|
|
@@ -96,7 +103,7 @@ export const buildIndex = (config) => {
|
|
|
96
103
|
headings: [],
|
|
97
104
|
links: [],
|
|
98
105
|
sectionRefs,
|
|
99
|
-
markers: parseMarkers(lines, kind),
|
|
106
|
+
markers: parseMarkers(lines, kind, path),
|
|
100
107
|
pendingItems: [],
|
|
101
108
|
tocBlock: null,
|
|
102
109
|
refSection: null,
|
package/dist/utils/scope.js
CHANGED
|
@@ -29,7 +29,7 @@ export const inRefSection = (file, line) => file.refSection !== null &&
|
|
|
29
29
|
*/
|
|
30
30
|
export const isHeadingLine = (file, line) => file.headings.some((h) => h.line === line);
|
|
31
31
|
/** 규칙을 적용할 마크다운 문서인지. 검사기와 생성기가 같은 기준으로 걸러야 한다 */
|
|
32
|
-
export const isTargetDoc = (file, config) => file.kind === '
|
|
32
|
+
export const isTargetDoc = (file, config) => file.kind === 'doc' && isCheckTarget(file.path, config);
|
|
33
33
|
/** 참조 절을 생성·검사할 문서인지. skipRefs 에 등록된 경로는 제외한다 */
|
|
34
34
|
export const wantsRefSection = (file, config) => isTargetDoc(file, config) && !config.skipRefs.includes(file.path);
|
|
35
35
|
/** 문서 제목 헤딩 목록. 하나여야 정상이다 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specthread",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Spec-Driven Development (SDD) template. Docs are the single source of truth; code implements docs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc -p tsconfig.build.json",
|
|
23
23
|
"prepublishOnly": "npm run build",
|
|
24
|
+
"release:patch": "npm version patch && npm publish && git push --tags",
|
|
25
|
+
"release:minor": "npm version minor && npm publish && git push --tags",
|
|
26
|
+
"release:major": "npm version major && npm publish && git push --tags",
|
|
24
27
|
"docs:check": "node tools/docs/bin/check.ts",
|
|
25
28
|
"docs:generate": "node tools/docs/bin/generate.ts",
|
|
26
29
|
"docs:test": "node --test \"tools/docs/__tests__/*.test.ts\"",
|
package/scaffold/config.jsonc
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
// ── specthread 설정 ──────────────────────────────────────────────
|
|
3
3
|
// 생략한 키는 기본값이 적용된다. 개인 설정은 config.local.jsonc (gitignore 대상).
|
|
4
4
|
|
|
5
|
+
// ── 파일 종류 ────────────────────────────────────────────────────
|
|
6
|
+
// 확장자 → 종류 매핑. 생략하면 기본값(30개 확장자)이 적용된다.
|
|
7
|
+
// doc: 기획 소스. 풀파싱 대상 (헤딩, 링크, 목차, 참조절, 마커).
|
|
8
|
+
// source: 문서 외 참조 파일. 마커 + 절참조 스캔만.
|
|
9
|
+
// "fileKinds": {
|
|
10
|
+
// "doc": [".md"],
|
|
11
|
+
// "source": [".ts", ".tsx", ".js", ".py", ".go", ".json", ".yaml"]
|
|
12
|
+
// }
|
|
13
|
+
|
|
5
14
|
// ── 스캔 대상 경로 ───────────────────────────────────────────────
|
|
6
15
|
// 자유 KV. 키는 용도 라벨, 값은 경로 배열.
|
|
7
16
|
// 디렉터리면 재귀 스캔, 파일이면 직접 로드.
|
|
@@ -38,7 +47,7 @@
|
|
|
38
47
|
// "docTypes": {
|
|
39
48
|
// "spec": {
|
|
40
49
|
// "path": "docs/spec/",
|
|
41
|
-
// "template": "
|
|
50
|
+
// "template": "specthread/templates/spec.md",
|
|
42
51
|
// "frontmatter": { "required": ["title"], "optional": ["status"] }
|
|
43
52
|
// }
|
|
44
53
|
// }
|
|
@@ -56,7 +65,7 @@
|
|
|
56
65
|
|
|
57
66
|
// ── 참조 절 생성 제외 (기본값: []) ──────────────────────────────
|
|
58
67
|
// 이 경로 prefix 의 문서에는 참조 절을 생성하지 않는다.
|
|
59
|
-
// "skipRefs": ["
|
|
68
|
+
// "skipRefs": ["specthread/templates/"]
|
|
60
69
|
|
|
61
70
|
// ── 로케일 (기본값: "ko") ───────────────────────────────────────
|
|
62
71
|
// 현재 한국어 고정. 검사 메시지, 꼬리 절 이름, 시점 정규식 등에 영향.
|