specthread 0.1.5 → 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.
Files changed (69) hide show
  1. package/README.md +88 -13
  2. package/dist/bin/check.js +9 -34
  3. package/dist/bin/cli.js +4 -4
  4. package/dist/bin/generate.js +32 -19
  5. package/dist/bin/open-project.d.ts +5 -0
  6. package/dist/bin/open-project.js +26 -0
  7. package/dist/checks/changelog.js +5 -4
  8. package/dist/checks/headings.d.ts +0 -1
  9. package/dist/checks/headings.js +13 -4
  10. package/dist/checks/links.js +7 -4
  11. package/dist/checks/markers.d.ts +3 -1
  12. package/dist/checks/markers.js +33 -18
  13. package/dist/checks/pending.js +54 -22
  14. package/dist/checks/references.js +2 -2
  15. package/dist/checks/sections.js +3 -5
  16. package/dist/checks/style.d.ts +0 -8
  17. package/dist/checks/style.js +23 -43
  18. package/dist/checks/timestamps.js +5 -5
  19. package/dist/checks/toc.js +4 -6
  20. package/dist/commands/config-template.d.ts +8 -0
  21. package/{scaffold/config.jsonc → dist/commands/config-template.js} +48 -40
  22. package/dist/commands/init.js +92 -42
  23. package/dist/config-loader.d.ts +22 -1
  24. package/dist/config-loader.js +192 -25
  25. package/dist/config.schema.d.ts +16 -35
  26. package/dist/config.schema.js +1 -7
  27. package/dist/constants/docs.d.ts +7 -2
  28. package/dist/constants/docs.js +7 -3
  29. package/dist/constants/exit.d.ts +12 -0
  30. package/dist/constants/exit.js +12 -0
  31. package/dist/constants/paths.d.ts +25 -0
  32. package/dist/constants/paths.js +25 -0
  33. package/dist/constants/patterns.d.ts +12 -3
  34. package/dist/constants/patterns.js +15 -3
  35. package/dist/constants/rules.d.ts +7 -3
  36. package/dist/constants/rules.js +7 -3
  37. package/dist/gen/pending-section.js +18 -14
  38. package/dist/gen/references.js +9 -5
  39. package/dist/gen/summary.d.ts +1 -1
  40. package/dist/gen/summary.js +9 -6
  41. package/dist/gen/toc.js +4 -1
  42. package/dist/run-check.d.ts +5 -0
  43. package/dist/run-check.js +35 -0
  44. package/dist/types.d.ts +4 -2
  45. package/dist/utils/ignore.d.ts +2 -8
  46. package/dist/utils/ignore.js +23 -6
  47. package/dist/utils/parse.js +11 -19
  48. package/dist/utils/path-match.d.ts +19 -0
  49. package/dist/utils/path-match.js +27 -0
  50. package/dist/utils/report.d.ts +1 -7
  51. package/dist/utils/report.js +10 -3
  52. package/dist/utils/resolve.js +15 -1
  53. package/dist/utils/root.d.ts +2 -0
  54. package/dist/utils/root.js +19 -0
  55. package/dist/utils/scan.d.ts +1 -3
  56. package/dist/utils/scan.js +22 -24
  57. package/dist/utils/scope.d.ts +37 -11
  58. package/dist/utils/scope.js +60 -24
  59. package/package.json +2 -2
  60. package/scaffold/AGENTS.md +4 -6
  61. package/scaffold/claude/skills/{check.md → check/SKILL.md} +6 -3
  62. package/scaffold/claude/skills/{gen.md → gen/SKILL.md} +4 -2
  63. package/scaffold/claude/skills/{plan-close.md → plan-close/SKILL.md} +1 -0
  64. package/scaffold/claude/skills/{plan-open.md → plan-open/SKILL.md} +1 -0
  65. package/scaffold/claude/skills/{plan-run.md → plan-run/SKILL.md} +1 -0
  66. package/scaffold/pending.md +1 -1
  67. package/scaffold/project.md +1 -1
  68. package/scaffold/rules.md +28 -27
  69. package/scaffold/templates/plan.md +3 -7
@@ -1,18 +1,18 @@
1
1
  /**
2
- * 관리 문서 항목 형식 (`docs/system/rules.md` §4-2).
2
+ * 관리 문서 항목 형식 (`specthread/rules.md` §4-2).
3
3
  *
4
4
  * 이 검사는 관리 문서 한 파일에만 걸린다. 항목이 한곳에 모이는 것이 그 문서의 존재
5
5
  * 이유라서, 다른 문서에 같은 모양이 나타나면 그건 미확정 사항 절 (생성 뷰) 이고
6
6
  * 형식이 다르다 - 뷰는 `li`, 정본은 `###` 헤딩이다.
7
7
  */
8
- import { timepointGlobal } from '../constants/patterns.js';
8
+ import { dirname, join, normalize } from 'node:path';
9
+ import { PENDING_PATH } from '../constants/paths.js';
10
+ import { ITEM_AS_LI, ITEM_HEADING, timepointGlobal } from '../constants/patterns.js';
9
11
  import { RULE } from '../constants/rules.js';
10
12
  import { summaryBlocks } from '../gen/summary.js';
11
13
  import { invertByTarget, pendingSectionBlock } from '../gen/pending-section.js';
12
- /** 항목 헤딩. id 뒤부터 줄 끝까지를 제목으로 본다 */
13
- const ITEM = /^###\s+`\[[a-z]+::[a-z0-9][a-z0-9-]*\]`(.*)$/;
14
- /** `li` 로 적힌 항목. 정본에서는 헤딩이어야 한다 */
15
- const ITEM_AS_LI = /^\s*-\s+`\[[a-z]+::[a-z0-9][a-z0-9-]*\]`/;
14
+ import { underPath } from '../utils/path-match.js';
15
+ import { inChangeLog, isWorkDoc } from '../utils/scope.js';
16
16
  /**
17
17
  * 문장이 끝난 흔적.
18
18
  *
@@ -49,7 +49,21 @@ const inspectHeading = (path, line, title) => {
49
49
  }
50
50
  return findings;
51
51
  };
52
- const inspectBody = (path, line, text) => {
52
+ /** 링크 대상과 코드 스팬. 둘 다 경로가 올 수 있다 */
53
+ const LINK_TARGET = /\]\(([^)]+)\)/g;
54
+ const CODE_SPAN = /`([^`]+)`/g;
55
+ /**
56
+ * 경로가 작업 폴더를 가리키는지.
57
+ *
58
+ * 링크는 문서 기준 상대 경로, 코드 스팬은 루트 기준 표기가 흔하다. 둘 다 본다.
59
+ */
60
+ const pointsToWork = (raw, dir, work) => {
61
+ const clean = raw.split('#')[0].trim();
62
+ if (clean === '')
63
+ return false;
64
+ return underPath(normalize(clean), work) || underPath(normalize(join(dir, clean)), work);
65
+ };
66
+ const inspectBody = (path, line, text, work) => {
53
67
  const findings = [];
54
68
  if (ITEM_AS_LI.test(text)) {
55
69
  findings.push({
@@ -67,7 +81,12 @@ const inspectBody = (path, line, text) => {
67
81
  message: '선택지는 `li` 로 낸다',
68
82
  });
69
83
  }
70
- if (/\]\(\.?\.?\/?work\//.test(text) || /`work\//.test(text)) {
84
+ const dir = dirname(path);
85
+ const refs = [
86
+ ...[...text.matchAll(LINK_TARGET)].map((m) => m[1]),
87
+ ...[...text.matchAll(CODE_SPAN)].map((m) => m[1]),
88
+ ];
89
+ if (refs.some((r) => pointsToWork(r, dir, work))) {
71
90
  findings.push({
72
91
  file: path,
73
92
  line,
@@ -77,8 +96,9 @@ const inspectBody = (path, line, text) => {
77
96
  }
78
97
  return findings;
79
98
  };
80
- /** 항목 헤딩 다음 첫 내용 줄이 시점인지 */
81
- const inspectTimepoint = (file, at) => {
99
+ /** 항목 헤딩 다음 첫 내용 줄이 시점인지, 해결 예정 라벨이 정의된 것인지 */
100
+ const inspectTimepoint = (file, at, config) => {
101
+ const { timepoints } = config.markers;
82
102
  for (let i = at; i < file.lines.length; i++) {
83
103
  const line = file.lines[i].trim();
84
104
  if (line === '')
@@ -104,6 +124,18 @@ const inspectTimepoint = (file, at) => {
104
124
  },
105
125
  ];
106
126
  }
127
+ // 목록이 비어 있으면 라벨을 자유롭게 쓰는 프로젝트다
128
+ const label = stamp[2]?.trim();
129
+ if (label !== undefined && timepoints.length > 0 && !timepoints.includes(label)) {
130
+ return [
131
+ {
132
+ file: file.path,
133
+ line: i + 1,
134
+ rule: RULE.PENDING.UNKNOWN_TIMEPOINT,
135
+ message: `해결 예정 ${label} 이 config.markers.timepoints 에 없다`,
136
+ },
137
+ ];
138
+ }
107
139
  return [];
108
140
  }
109
141
  // 헤딩 뒤에 아무 줄도 없으면 시점 줄이 빠진 것이다
@@ -150,17 +182,20 @@ const inspectSummary = (file, index) => {
150
182
  /**
151
183
  * 문서 미확정 사항 절 ↔ 관리 문서 백링크 일치.
152
184
  *
153
- * 목차·참조 절과 같은 구조다. `docs/pending.md` 를 제외한 모든 문서가 대상이다 -
185
+ * 목차·참조 절과 같은 구조다. 관리 문서를 제외한 모든 문서가 대상이다 -
154
186
  * 절 자체가 없는 문서는 `gen/pending-section.ts` 가 건드리지 않으므로 지적도 없다.
155
187
  */
156
188
  const inspectPendingSection = (index) => {
157
- const pending = index.files.get(index.config.pending);
189
+ const pending = index.files.get(PENDING_PATH);
158
190
  if (pending === undefined)
159
191
  return [];
160
192
  const byTarget = invertByTarget(pending);
161
193
  const findings = [];
162
194
  for (const file of index.files.values()) {
163
- if (file.path === index.config.pending || file.pendingSection === null)
195
+ if (file.path === PENDING_PATH || file.pendingSection === null)
196
+ continue;
197
+ // 작업 문서는 생성 대상이 아니다 (pendingSectionBlock 과 같은 조건).
198
+ if (isWorkDoc(file.path, index.config))
164
199
  continue;
165
200
  const expected = pendingSectionBlock(file, byTarget, index);
166
201
  const actual = file.lines.slice(file.pendingSection.start - 1, file.pendingSection.end);
@@ -177,24 +212,21 @@ const inspectPendingSection = (index) => {
177
212
  return findings;
178
213
  };
179
214
  export const checkPending = (index) => {
180
- const file = index.files.get(index.config.pending);
215
+ const file = index.files.get(PENDING_PATH);
181
216
  if (file === undefined)
182
217
  return [];
183
218
  const findings = [];
184
- let inChangeLog = false;
185
219
  file.lines.forEach((raw, i) => {
186
220
  const line = i + 1;
187
- if (raw.startsWith('## 변경 이력'))
188
- inChangeLog = true;
189
- if (inChangeLog)
221
+ if (inChangeLog(file, line))
190
222
  return;
191
- const item = ITEM.exec(raw);
223
+ const item = ITEM_HEADING.exec(raw);
192
224
  if (item) {
193
- findings.push(...inspectHeading(file.path, line, item[1]));
194
- findings.push(...inspectTimepoint(file, line));
225
+ findings.push(...inspectHeading(file.path, line, item[2]));
226
+ findings.push(...inspectTimepoint(file, line, index.config));
195
227
  return;
196
228
  }
197
- findings.push(...inspectBody(file.path, line, raw));
229
+ findings.push(...inspectBody(file.path, line, raw, index.config.work));
198
230
  });
199
231
  return [...findings, ...inspectSummary(file, index), ...inspectPendingSection(index)];
200
232
  };
@@ -5,14 +5,14 @@ import { RULE } from '../constants/rules.js';
5
5
  * 목차와 같은 구조다 - 본문에 이미 있는 정보를 문서 하단에 한 번 더 적는 자리라
6
6
  * 손으로 관리하면 반드시 어긋난다. 생성 결과와 다르면 지적한다.
7
7
  */
8
- import { isTargetDoc } from "../utils/scope.js";
8
+ import { isDoc } from "../utils/scope.js";
9
9
  import { referenceBlock } from "../gen/references.js";
10
10
  /** 블록 안 항목 줄 수. 지적 메시지에 규모를 실어준다 */
11
11
  const itemCount = (lines) => lines.filter((l) => l.startsWith("- [")).length;
12
12
  export const checkReferences = (index) => {
13
13
  const findings = [];
14
14
  for (const file of index.files.values()) {
15
- if (!isTargetDoc(file, index.config))
15
+ if (!isDoc(file))
16
16
  continue;
17
17
  // 본문 링크가 없으면 참조 절을 둘 이유가 없다
18
18
  const expected = referenceBlock(file, index.config);
@@ -6,7 +6,7 @@ import { RULE } from '../constants/rules.js';
6
6
  * 번호 없는 헤딩은 § 대상이 될 수 없으므로 대조 집합에 들어가지 않는다.
7
7
  */
8
8
  import { basename, dirname, relative } from "node:path";
9
- import { inChangeLog, inRefSection, inToc, isCheckTarget, isHeadingLine, } from "../utils/scope.js";
9
+ import { inChangeLog, inPendingSection, inRefSection, inToc, isHeadingLine, } from "../utils/scope.js";
10
10
  /** 미해소 사유별 메시지 */
11
11
  /**
12
12
  * 해소 실패 사유마다 규칙 id 와 메시지.
@@ -118,14 +118,12 @@ export const checkSectionRefs = (index) => {
118
118
  const numsByFile = sectionNumbers(index);
119
119
  for (const file of index.files.values()) {
120
120
  // 코드·데이터도 문서의 절을 가리키므로 `md` 로 좁히지 않는다
121
- if (!isCheckTarget(file.path, index.config))
122
- continue;
123
121
  for (const ref of file.sectionRefs) {
124
- if (file.ignored.has(ref.line) || inChangeLog(file, ref.line))
122
+ if (inChangeLog(file, ref.line))
125
123
  continue;
126
124
  if (isHeadingLine(file, ref.line) || inToc(file, ref.line))
127
125
  continue;
128
- if (inRefSection(file, ref.line))
126
+ if (inRefSection(file, ref.line) || inPendingSection(file, ref.line))
129
127
  continue;
130
128
  const finding = inspect(index, numsByFile, file, ref);
131
129
  if (finding !== null) {
@@ -1,10 +1,2 @@
1
1
  import type { DocIndex, Finding } from '../types.ts';
2
- export declare const checkStyle: (index: DocIndex) => Finding[];
3
- /**
4
- * 코드에 있는 검사 id 가 규칙 문서에 선언됐는지.
5
- *
6
- * 선언이 없으면 문서화되지 않은 규칙을 강제하는 것이다. 역방향 (문서에만 있고 코드에
7
- * 없는 것) 은 절 단위 판정이 애매해 검사하지 않는다 - 병기가 없는 절이 곧 사람만
8
- * 검사하는 규칙이다.
9
- */
10
2
  export declare const checkRuleDeclared: (index: DocIndex) => Finding[];
@@ -1,59 +1,39 @@
1
1
  /**
2
- * 문체 검사 (`docs/system/rules.md` §2-6).
2
+ * 규칙 선언 대조 (`specthread/rules.md` §5).
3
3
  *
4
- * 지금은 em dash 하나다. `Write` / `Edit` 뒤에 도는 훅이 예방하지만 스크립트나 외부
5
- * 유입은 훅을 거치지 않으므로 상태를 보는 검사가 따로 필요하다.
4
+ * 코드에 있는 검사 id 가 규칙 문서에 선언됐는지 본다. 선언이 없으면 문서화되지 않은
5
+ * 규칙을 강제하는 것이다. 역방향 (문서에만 있고 코드에 없는 것) 은 절 단위 판정이 애매해
6
+ * 검사하지 않는다 - 병기가 없는 절이 곧 사람만 검사하는 규칙이다.
6
7
  */
7
- import { EM_DASH } from '../constants/patterns.js';
8
+ import { RULES_PATH } from '../constants/paths.js';
8
9
  import { ALL_RULE_IDS, RULE } from '../constants/rules.js';
9
- import { codeSpanMask } from '../utils/parse.js';
10
- import { isCheckTarget } from '../utils/scope.js';
11
10
  /**
12
- * 대상 문자를 소스에 갖는 파일. 훅과 이 검사가 서로를 망가뜨리지 않게 뺀다.
11
+ * 지금 실제로 도는 검사 id 만.
13
12
  *
14
- * 이 파일 자신은 리터럴 대신 `\u2014` 로 적어 목록에 넣지 않는다 - 훅 설정에 기대지
15
- * 않고 손상을 막는다.
13
+ * 기능을 끄면 그 검사는 돌지 않으므로 규칙 문서에 선언을 요구할 이유도 없다.
14
+ * 끈 기능의 문서를 지웠다고 지적이 나오면 정리를 벌하는 셈이 된다.
16
15
  */
17
- const SELF = ['tools/hooks/no-em-dash.mjs'];
18
- export const checkStyle = (index) => {
19
- const findings = [];
20
- for (const file of index.files.values()) {
21
- if (!isCheckTarget(file.path, index.config) || SELF.includes(file.path))
22
- continue;
23
- file.lines.forEach((raw, i) => {
24
- if (!raw.includes(EM_DASH))
25
- return;
26
- // 백틱 안은 금지 문자를 인용한 것이다. 규칙 문서가 금지 예시를 그렇게 담는다
27
- const mask = codeSpanMask(raw);
28
- const at = [...raw].findIndex((c, k) => c === EM_DASH && !mask[k]);
29
- if (at < 0)
30
- return;
31
- findings.push({
32
- file: file.path,
33
- line: i + 1,
34
- rule: RULE.STYLE.EM_DASH,
35
- message: "em dash 를 쓰지 않는다. 하이픈 '-' 으로",
36
- });
37
- });
38
- }
39
- return findings;
16
+ const enabledRuleIds = (index) => {
17
+ const { features } = index.config;
18
+ return ALL_RULE_IDS.filter((id) => {
19
+ const group = id.split('/')[0];
20
+ if (group === 'reference')
21
+ return features.references;
22
+ if (group === 'marker' || group === 'pending')
23
+ return features.markers;
24
+ return true;
25
+ });
40
26
  };
41
- /**
42
- * 코드에 있는 검사 id 가 규칙 문서에 선언됐는지.
43
- *
44
- * 선언이 없으면 문서화되지 않은 규칙을 강제하는 것이다. 역방향 (문서에만 있고 코드에
45
- * 없는 것) 은 절 단위 판정이 애매해 검사하지 않는다 - 병기가 없는 절이 곧 사람만
46
- * 검사하는 규칙이다.
47
- */
48
27
  export const checkRuleDeclared = (index) => {
49
- const rulesPath = index.config.rules;
50
- const doc = index.files.get(rulesPath);
28
+ const doc = index.files.get(RULES_PATH);
51
29
  if (doc === undefined)
52
30
  return [];
53
31
  const text = doc.lines.join('\n');
54
32
  const heading = doc.headings.find((h) => h.title === '개요');
55
- return ALL_RULE_IDS.filter((id) => !text.includes(id)).map((id) => ({
56
- file: rulesPath,
33
+ return enabledRuleIds(index)
34
+ .filter((id) => !text.includes(id))
35
+ .map((id) => ({
36
+ file: RULES_PATH,
57
37
  line: heading?.line ?? 1,
58
38
  rule: RULE.STYLE.RULE_UNDECLARED,
59
39
  message: `검사 id 가 규칙 문서에 선언되지 않았다 - ${id}`,
@@ -1,7 +1,7 @@
1
1
  import { timepointGlobal } from '../constants/patterns.js';
2
2
  import { RULE } from '../constants/rules.js';
3
3
  /**
4
- * 본문 시점 표기 - 날짜를 본문에 남기지 않는가 (`docs/system/rules.md` §2-1).
4
+ * 본문 시점 표기 - 날짜를 본문에 남기지 않는가 (`specthread/rules.md` §2-1).
5
5
  *
6
6
  * 문서 본문은 현재 상태와 근거만 서술하고, _누가 언제 무엇을 뒤집었는가_ 는 변경 이력이
7
7
  * 갖는다. §2-1 이 금지하는 다섯 가지 중 **날짜만** 여기서 본다. 나머지 (시점을 함의하는
@@ -9,7 +9,7 @@ import { RULE } from '../constants/rules.js';
9
9
  * 검토에 맡긴다 - `신규 5 종` 같은 콘텐츠 서술까지 걸린다.
10
10
  */
11
11
  import { codeSpanMask, linkTargetSpans } from "../utils/parse.js";
12
- import { inChangeLog, inToc, isTargetDoc } from "../utils/scope.js";
12
+ import { inChangeLog, inPendingSection, inToc, isDoc } from "../utils/scope.js";
13
13
  const DATE = /20\d\d-\d\d-\d\d/g;
14
14
  /** 시점 표기가 차지한 자리 */
15
15
  const timepointSpans = (text) => [...text.matchAll(timepointGlobal())].map((m) => ({
@@ -19,7 +19,7 @@ const timepointSpans = (text) => [...text.matchAll(timepointGlobal())].map((m) =
19
19
  export const checkTimestamps = (index) => {
20
20
  const findings = [];
21
21
  for (const file of index.files.values()) {
22
- if (!isTargetDoc(file, index.config))
22
+ if (!isDoc(file))
23
23
  continue;
24
24
  let fence = false;
25
25
  file.lines.forEach((text, i) => {
@@ -28,8 +28,8 @@ export const checkTimestamps = (index) => {
28
28
  return;
29
29
  }
30
30
  const line = i + 1;
31
- // 펜스는 예시, 변경 이력은 날짜가 있어야 하는 자리, 목차는 헤딩을 복사한 생성물이다
32
- if (fence || inChangeLog(file, line) || inToc(file, line))
31
+ // 펜스는 예시, 변경 이력은 날짜가 있어야 하는 곳, 목차·미확정 사항 절은 생성물이다
32
+ if (fence || inChangeLog(file, line) || inToc(file, line) || inPendingSection(file, line))
33
33
  return;
34
34
  const mask = codeSpanMask(text);
35
35
  const urls = linkTargetSpans(text);
@@ -1,18 +1,16 @@
1
- import { RULE } from '../constants/rules.js';
1
+ import { RULE } from "../constants/rules.js";
2
2
  /**
3
3
  * 목차 ↔ `##` 헤딩 일치.
4
4
  *
5
5
  * 목차는 생성기가 채우지만 사람이 손으로 고칠 수 있고, 절을 하나 끼워 넣으면
6
- * 조용히 어긋난다. 생성 결과와 다르면 지적한다 - 고치는 방법은 `pnpm docs:generate --write` 다.
6
+ * 조용히 어긋난다. 생성 결과와 다르면 지적한다 - 고치는 방법은 `specthread gen --write` 다.
7
7
  */
8
- import { isTargetDoc, singleTitle } from "../utils/scope.js";
8
+ import { isDoc, singleTitle } from "../utils/scope.js";
9
9
  import { tocBlock } from "../gen/toc.js";
10
10
  export const checkToc = (index) => {
11
11
  const findings = [];
12
12
  for (const file of index.files.values()) {
13
- if (!isTargetDoc(file, index.config))
14
- continue;
15
- if (singleTitle(file) === null)
13
+ if (singleTitle(file) === null || !isDoc(file))
16
14
  continue;
17
15
  // `##` 절이 없으면 목차를 둘 이유가 없다
18
16
  const expected = tocBlock(file.headings);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * init 이 생성하는 config.jsonc 본문.
3
+ *
4
+ * 값은 DEFAULT_CONFIG 에서 보간한다. scaffold 에 사본을 두면 기본값이 두 곳이 되고,
5
+ * 한쪽만 고쳐도 아무 곳에서도 드러나지 않는다.
6
+ */
7
+ import type { SpecthreadConfig } from "../config.schema.ts";
8
+ export declare const renderConfig: (c: SpecthreadConfig) => string;
@@ -1,80 +1,88 @@
1
- {
1
+ /** 한 줄이 너무 길어지지 않게 확장자를 묶는다. 항목 추가 시 뒤쪽만 흐른다 */
2
+ const wrapList = (items, indent, width = 72) => {
3
+ const lines = [];
4
+ let line = "";
5
+ items.forEach((item, i) => {
6
+ const piece = `"${item}"${i < items.length - 1 ? "," : ""}`;
7
+ const next = line === "" ? piece : `${line} ${piece}`;
8
+ if (indent.length + next.length > width && line !== "") {
9
+ lines.push(indent + line);
10
+ line = piece;
11
+ return;
12
+ }
13
+ line = next;
14
+ });
15
+ if (line !== "")
16
+ lines.push(indent + line);
17
+ return lines.join("\n");
18
+ };
19
+ const inlineList = (items) => `[${items.map((i) => `"${i}"`).join(", ")}]`;
20
+ export const renderConfig = (c) => `{
2
21
  // ── specthread 설정 ──────────────────────────────────────────────
3
22
  // 생략한 키는 기본값이 적용된다. 개인 설정은 config.local.jsonc (gitignore 대상).
4
23
 
5
24
  // ── 파일 종류 ────────────────────────────────────────────────────
6
- // 확장자 → 종류 매핑. 생략하면 기본값(30개 확장자)이 적용된다.
25
+ // 확장자 → 종류 매핑. 아래는 기본값이고, 필요한 확장자를 더하거나 뺄 수 있다.
7
26
  // doc: 기획 소스. 풀파싱 대상 (헤딩, 링크, 목차, 참조절, 마커).
8
27
  // source: 문서 외 참조 파일. 마커 + 절참조 스캔만.
9
- // "fileKinds": {
10
- // "doc": [".md"],
11
- // "source": [".ts", ".tsx", ".js", ".py", ".go", ".json", ".yaml"]
12
- // }
28
+ "fileKinds": {
29
+ "doc": ${inlineList(c.fileKinds.doc)},
30
+ "source": [
31
+ ${wrapList(c.fileKinds.source, " ")}
32
+ ]
33
+ },
13
34
 
14
35
  // ── 스캔 대상 경로 ───────────────────────────────────────────────
15
36
  // 자유 KV. 키는 용도 라벨, 값은 경로 배열.
16
37
  // 디렉터리면 재귀 스캔, 파일이면 직접 로드.
38
+ // 적으면 기본값을 통째로 교체한다 (키 단위로 합치지 않는다).
39
+ // specthread/ 의 rules·pending·project 는 여기 없어도 항상 읽는다.
17
40
  // 예: "source": ["client/src/"], "data": ["data/"]
18
41
  // "meta": ["CLAUDE.md", "AGENTS.md"]
19
42
  "path": {
20
- "docs": ["docs/"],
21
- "specthread": ["specthread/"]
43
+ ${Object.entries(c.path)
44
+ .map(([k, v]) => ` "${k}": ${inlineList(v)}`)
45
+ .join(",\n")}
22
46
  },
23
47
 
24
48
  // ── 기능 플래그 ──────────────────────────────────────────────────
25
49
  // 기능 단위 on/off. 개별 규칙이 아닌 기능 묶음으로 제어한다.
26
50
  "features": {
27
51
  // 마커 체계 전체. false → marker/*, pending/* 검사 + pending 추적 비활성화
28
- "markers": true,
29
- // em dash 검사 + 치환 훅. false → style/em-dash 검사 + hook 비활성화
30
- "emDash": true,
52
+ "markers": ${c.features.markers},
31
53
  // 참조 절 자동 생성. false → reference/* 검사 + gen references 스킵
32
- "references": true
54
+ "references": ${c.features.references}
33
55
  },
34
56
 
35
57
  // ── 마커 체계 ────────────────────────────────────────────────────
36
58
  "markers": {
37
59
  // 마커 종류. "system" 은 코어 예약, 나머지는 프로젝트 정의.
60
+ // 여기 없는 종류의 마커·항목은 marker/unknown-type 으로 지적한다.
38
61
  // 예: ["system", "design", "balance", "deps"]
39
- "types": ["system"],
40
- // 처리 시점 라벨. 마일스톤 등.
41
- // 예: ["M1", "M2", "M3"]
42
- "timepoints": []
62
+ "types": ${inlineList(c.markers.types)},
63
+ // 처리 시점 라벨. 마일스톤 등. 비어 있으면 해결 예정 라벨을 검사하지 않는다.
64
+ // 예: ["M1", "M2", "P01-123"]
65
+ "timepoints": ${inlineList(c.markers.timepoints)}
43
66
  }
44
67
 
45
- // ── 문서 유형 (기본값: {}) ───────────────────────────────────────
46
- // 경로 패턴별 템플릿과 프론트매터 스키마를 지정한다.
47
- // "docTypes": {
48
- // "spec": {
49
- // "path": "docs/spec/",
50
- // "template": "specthread/templates/spec.md",
51
- // "frontmatter": { "required": ["title"], "optional": ["status"] }
52
- // }
53
- // }
54
-
55
68
  // ── 문서명 해소 무시 (기본값: []) ────────────────────────────────
56
- // 절 참조(예: "spec §4")가 파일명과 잘못 매칭되는 것을 방지한다.
69
+ // 절 참조가 파일명과 잘못 매칭되는 것을 방지한다.
57
70
  // "ignoreDocNames": ["spec"]
58
71
 
59
72
  // ── 검사 제외 (기본값: []) ───────────────────────────────────────
60
- // 경로 prefix 로 전체 검사를 건너뛰거나, 특정 군만 검사한다.
73
+ // 경로 아래의 검사·생성을 전부 건너뛰거나, 특정 군만 남긴다.
74
+ // specthread/templates/ 와 설정 파일은 적지 않아도 항상 제외한다.
61
75
  // "skipCheck": [
62
76
  // "docs/archive/",
63
77
  // { "path": "docs/drafts/", "only": ["heading", "link"] }
64
78
  // ]
65
79
 
66
80
  // ── 참조 절 생성 제외 (기본값: []) ──────────────────────────────
67
- // 이 경로 prefix 의 문서에는 참조 절을 생성하지 않는다.
68
- // "skipRefs": ["specthread/templates/"]
69
-
70
- // ── 로케일 (기본값: "ko") ───────────────────────────────────────
71
- // 현재 한국어 고정. 검사 메시지, 꼬리 절 이름, 시점 정규식 등에 영향.
72
- // "locale": "ko"
81
+ // 이 경로 아래의 문서에는 참조 절을 생성하지 않는다.
82
+ // "skipRefs": ["CLAUDE.md", "docs/drafts/"]
73
83
 
74
- // ── 규약 경로 ────────────────────────────────────────────────────
75
- // 도구가 직접 읽고 쓰는 파일. path 와 별개.
76
- // "rules": "specthread/rules.md",
77
- // "pending": "specthread/pending.md",
78
- // "project": "specthread/project.md",
79
- // "work": "docs/work/"
84
+ // ── 작업 문서 폴더 (기본값: "${c.work}/") ─────────────────────────
85
+ // 흡수 후 지우는 계획 문서. 미확정 사항 절을 만들지 않는다.
86
+ // "work": "${c.work}/"
80
87
  }
88
+ `;