@izkac/forgekit 0.3.12 → 0.3.14

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 (120) hide show
  1. package/bin/forge.mjs +119 -107
  2. package/bin/forgekit.mjs +83 -83
  3. package/bin/review.mjs +81 -81
  4. package/package.json +2 -1
  5. package/scripts/prepack.mjs +78 -78
  6. package/scripts/run-tests.mjs +50 -50
  7. package/src/adr.mjs +236 -236
  8. package/src/adr.test.mjs +170 -170
  9. package/src/change.mjs +327 -234
  10. package/src/change.test.mjs +145 -83
  11. package/src/cleanup-sessions.mjs +84 -84
  12. package/src/config.mjs +103 -103
  13. package/src/defer.mjs +75 -75
  14. package/src/doctor.mjs +350 -341
  15. package/src/doctor.test.mjs +114 -114
  16. package/src/fleet.test.mjs +50 -0
  17. package/src/init.mjs +680 -621
  18. package/src/install.mjs +815 -815
  19. package/src/install.test.mjs +180 -180
  20. package/src/integrity-check.mjs +60 -60
  21. package/src/integrity.mjs +688 -682
  22. package/src/integrity.test.mjs +612 -566
  23. package/src/lib/fleet.mjs +61 -4
  24. package/src/lib.mjs +160 -143
  25. package/src/lib.test.mjs +128 -0
  26. package/src/models.defaults.json +41 -41
  27. package/src/new-session.mjs +99 -99
  28. package/src/openspec-overlays/README.md +19 -19
  29. package/src/openspec-overlays/openspec-apply-change-footer.md +14 -14
  30. package/src/openspec-overlays/opsx-apply-completion-step.md +1 -1
  31. package/src/openspec-overlays/opsx-apply-implement-step.md +11 -11
  32. package/src/paths.mjs +92 -92
  33. package/src/plan-engine.mjs +321 -278
  34. package/src/plan-engine.test.mjs +447 -283
  35. package/src/preferences.defaults.json +78 -78
  36. package/src/preferences.mjs +438 -438
  37. package/src/preferences.test.mjs +174 -174
  38. package/src/record-evidence.mjs +204 -204
  39. package/src/repo-root.mjs +33 -0
  40. package/src/resolve-model.mjs +312 -312
  41. package/src/resolve-model.test.mjs +194 -194
  42. package/src/review/cli.test.mjs +117 -117
  43. package/src/review/export.mjs +172 -172
  44. package/src/review/export.test.mjs +197 -197
  45. package/src/review/fixtures/valid-review.json +42 -42
  46. package/src/review/lib.mjs +894 -894
  47. package/src/review/lib.test.mjs +266 -266
  48. package/src/review/schema.json +196 -196
  49. package/src/review/signals.test.mjs +62 -62
  50. package/src/score-cli.mjs +68 -68
  51. package/src/score.mjs +568 -568
  52. package/src/score.test.mjs +366 -366
  53. package/src/session-reminder.mjs +207 -207
  54. package/src/session-status.mjs +70 -70
  55. package/src/set-models.mjs +186 -186
  56. package/src/set-phase.mjs +205 -205
  57. package/src/set-prefs.mjs +294 -294
  58. package/src/specs-sync.mjs +232 -0
  59. package/src/specs-sync.test.mjs +114 -0
  60. package/src/spine.mjs +93 -93
  61. package/src/triage-prompt.mjs +175 -175
  62. package/src/triage-prompt.test.mjs +50 -50
  63. package/src/vendor-openspec-overlays.mjs +176 -176
  64. package/src/vendor-openspec-overlays.test.mjs +62 -62
  65. package/vendor/skills/archive-to-adr/SKILL.md +149 -149
  66. package/vendor/skills/forge/SKILL.md +136 -136
  67. package/vendor/skills/forge/docs/forge.md +650 -647
  68. package/vendor/skills/forge/phases/brainstorm.md +23 -23
  69. package/vendor/skills/forge/phases/finish.md +90 -87
  70. package/vendor/skills/forge/phases/implement.md +77 -77
  71. package/vendor/skills/forge/phases/plan-openspec.md +60 -60
  72. package/vendor/skills/forge/phases/plan-specs.md +163 -117
  73. package/vendor/skills/forge/phases/review.md +25 -25
  74. package/vendor/skills/forge/phases/verify.md +124 -124
  75. package/vendor/skills/forge/references/forge-layout.md +85 -85
  76. package/vendor/skills/forge/references/pace.md +115 -115
  77. package/vendor/skills/forge/references/plan-routing.md +52 -51
  78. package/vendor/skills/forge/references/runtime-integrity.md +232 -232
  79. package/vendor/skills/forge/references/substantial-work.md +37 -37
  80. package/vendor/skills/forge/references/test-evidence.md +30 -30
  81. package/vendor/skills/forge/references/test-strategy.md +68 -68
  82. package/vendor/skills/forge/skills/subagent-driven-development/SKILL.md +87 -87
  83. package/vendor/skills/forge/subagents/final-reviewer-prompt.md +56 -56
  84. package/vendor/skills/forge/subagents/implementer-prompt.md +38 -38
  85. package/vendor/skills/git-resolve-adr-conflict/SKILL.md +132 -132
  86. package/vendor/skills/thorough-code-review/SKILL.md +290 -290
  87. package/vendor/skills/thorough-code-review/examples.md +133 -133
  88. package/vendor/skills/thorough-code-review/reference/accepted-risks.md +26 -26
  89. package/vendor/skills/thorough-code-review/reference/lenses.md +96 -96
  90. package/vendor/skills/thorough-code-review/reference/phase1-scout.md +62 -62
  91. package/vendor/skills/thorough-code-review/reference/phase2-skeptic.md +105 -105
  92. package/vendor/skills/thorough-code-review/reference/report-schema.json +222 -222
  93. package/vendor/skills/thorough-code-review/reference/report-template.md +115 -115
  94. package/vendor/skills/thorough-code-review/reference/severity-rubric.md +49 -49
  95. package/vendor/skills/thorough-code-review/reference/signals-preflight.md +55 -55
  96. package/vendor/templates/adr/README.md +7 -7
  97. package/vendor/templates/adr/decisions.md +141 -141
  98. package/vendor/templates/adr/hooks/check-pending-adrs.mjs +74 -74
  99. package/vendor/templates/adr/hooks/check-pending-adrs.sh +3 -3
  100. package/vendor/templates/adr/hooks/openspec-archive-agent-message.mjs +52 -52
  101. package/vendor/templates/adr/hooks/openspec-archive-agent-message.sh +3 -3
  102. package/vendor/templates/project/claude/commands/forge-apply.md +75 -75
  103. package/vendor/templates/project/claude/commands/forge-brainstorm.md +7 -7
  104. package/vendor/templates/project/claude/commands/forge-build.md +17 -17
  105. package/vendor/templates/project/claude/commands/forge-plan.md +12 -12
  106. package/vendor/templates/project/claude/commands/forge-skip.md +14 -14
  107. package/vendor/templates/project/claude/commands/forge-status.md +16 -16
  108. package/vendor/templates/project/claude/commands/forge.md +16 -16
  109. package/vendor/templates/project/claude/hooks/forge-prompt-hook.mjs +73 -73
  110. package/vendor/templates/project/claude/hooks/forge-session-start.mjs +19 -19
  111. package/vendor/templates/project/claude/hooks/forge-triage-hook.mjs +77 -77
  112. package/vendor/templates/project/cursor/commands/forge-apply.md +75 -75
  113. package/vendor/templates/project/cursor/commands/forge-brainstorm.md +10 -10
  114. package/vendor/templates/project/cursor/commands/forge-build.md +17 -17
  115. package/vendor/templates/project/cursor/commands/forge-plan.md +15 -15
  116. package/vendor/templates/project/cursor/commands/forge-skip.md +14 -14
  117. package/vendor/templates/project/cursor/commands/forge-status.md +16 -16
  118. package/vendor/templates/project/cursor/commands/forge.md +16 -16
  119. package/vendor/templates/project/cursor/hooks/forge-session-start.mjs +30 -30
  120. package/vendor/templates/project/cursor/hooks/forge-session-start.sh +3 -3
package/src/adr.mjs CHANGED
@@ -1,236 +1,236 @@
1
- #!/usr/bin/env node
2
- /**
3
- * ADR project/user config + scaffolding for forgekit.
4
- *
5
- * User defaults: ~/.forgekit/config.json → { adr: { enabled, dir } }
6
- * Project: <repo>/.forge/config.json → { adr: { enabled, dir, decisionsDoc } }
7
- */
8
-
9
- import fs from 'node:fs';
10
- import path from 'node:path';
11
- import {
12
- loadProjectConfig,
13
- loadUserConfig,
14
- saveProjectConfig,
15
- saveUserConfig as saveUserConfigBase,
16
- userConfigPath,
17
- projectConfigPath,
18
- } from './config.mjs';
19
- import { resolveAsset } from './paths.mjs';
20
-
21
- export {
22
- loadProjectConfig,
23
- loadUserConfig,
24
- userConfigPath,
25
- projectConfigPath,
26
- };
27
-
28
- export const DEFAULT_ADR_DIR = 'docs/adr';
29
- export const ADR_SKILLS = Object.freeze(['archive-to-adr', 'git-resolve-adr-conflict']);
30
-
31
- /**
32
- * @param {string} adrDir posix-ish relative path
33
- * @returns {string}
34
- */
35
- export function decisionsDocFor(adrDir) {
36
- const normalized = normalizeAdrDir(adrDir);
37
- const parent = path.posix.dirname(normalized);
38
- if (!parent || parent === '.') return 'decisions.md';
39
- return path.posix.join(parent, 'decisions.md');
40
- }
41
-
42
- /**
43
- * @param {string} raw
44
- * @returns {string}
45
- */
46
- export function normalizeAdrDir(raw) {
47
- let s = String(raw ?? '')
48
- .trim()
49
- .replace(/\\/g, '/');
50
- if (!s) s = DEFAULT_ADR_DIR;
51
- s = s.replace(/^\.\/+/, '').replace(/\/+$/, '');
52
- if (!s) s = DEFAULT_ADR_DIR;
53
- if (path.isAbsolute(s) || s.startsWith('..') || s.split('/').includes('..')) {
54
- throw new Error(
55
- `ADR directory must be a relative path inside the repo (got: ${raw})`,
56
- );
57
- }
58
- return s;
59
- }
60
-
61
- /**
62
- * @param {{ adr?: { enabled?: boolean, dir?: string } }} patch
63
- * @param {string} [home]
64
- */
65
- export function saveUserConfig(patch, home) {
66
- return saveUserConfigBase(patch, home);
67
- }
68
-
69
- /**
70
- * @param {string} cwd
71
- * @param {{ adr: { enabled: boolean, dir?: string, decisionsDoc?: string } }} patch
72
- */
73
- export function writeProjectAdrConfig(cwd, patch) {
74
- const current = loadProjectConfig(cwd);
75
- const enabled = Boolean(patch.adr.enabled);
76
- /** @type {{ enabled: boolean, dir?: string, decisionsDoc?: string }} */
77
- const adr = { enabled };
78
- if (enabled) {
79
- const curAdr =
80
- current.adr && typeof current.adr === 'object'
81
- ? /** @type {{ dir?: string, decisionsDoc?: string }} */ (current.adr)
82
- : {};
83
- const dir = normalizeAdrDir(patch.adr.dir ?? curAdr.dir ?? DEFAULT_ADR_DIR);
84
- adr.dir = dir;
85
- adr.decisionsDoc =
86
- patch.adr.decisionsDoc ?? curAdr.decisionsDoc ?? decisionsDocFor(dir);
87
- }
88
- return saveProjectConfig(cwd, { adr });
89
- }
90
-
91
- /**
92
- * @returns {string}
93
- */
94
- export function resolveAdrTemplatesRoot() {
95
- return resolveAsset('templates/adr');
96
- }
97
-
98
- /**
99
- * @param {string} template
100
- * @param {Record<string, string>} vars
101
- */
102
- function renderTemplate(template, vars) {
103
- return template.replace(/\{\{(\w+)\}\}/g, (_, key) => vars[key] ?? '');
104
- }
105
-
106
- /**
107
- * Relative link from adr README to decisions doc.
108
- * @param {string} adrDir
109
- * @param {string} decisionsDoc
110
- */
111
- export function decisionsRelFromAdrReadme(adrDir, decisionsDoc) {
112
- const fromDir = adrDir.replace(/\/+$/, '');
113
- const target = decisionsDoc.replace(/\\/g, '/');
114
- const rel = path.posix.relative(fromDir, target);
115
- return rel.startsWith('.') ? rel : `./${rel}`;
116
- }
117
-
118
- /**
119
- * Scaffold decisions.md, adr README, optional hooks.
120
- * @param {string} cwd
121
- * @param {{ dir?: string, decisionsDoc?: string, force?: boolean, hooks?: boolean }} opts
122
- */
123
- export function scaffoldAdr(cwd, opts = {}) {
124
- const dir = normalizeAdrDir(opts.dir ?? DEFAULT_ADR_DIR);
125
- const decisionsDoc = opts.decisionsDoc ?? decisionsDocFor(dir);
126
- const templates = resolveAdrTemplatesRoot();
127
- const force = Boolean(opts.force);
128
- /** @type {{ file: string, status: string }[]} */
129
- const files = [];
130
-
131
- const write = (relPath, body) => {
132
- const dest = path.join(cwd, ...relPath.split('/'));
133
- fs.mkdirSync(path.dirname(dest), { recursive: true });
134
- if (fs.existsSync(dest) && !force) {
135
- files.push({ file: relPath, status: 'skipped' });
136
- return;
137
- }
138
- fs.writeFileSync(dest, body, 'utf8');
139
- files.push({ file: relPath, status: 'written' });
140
- };
141
-
142
- const decisionsTpl = fs.readFileSync(path.join(templates, 'decisions.md'), 'utf8');
143
- write(decisionsDoc, renderTemplate(decisionsTpl, { ADR_DIR: dir }));
144
-
145
- const readmeTpl = fs.readFileSync(path.join(templates, 'README.md'), 'utf8');
146
- write(
147
- path.posix.join(dir, 'README.md'),
148
- renderTemplate(readmeTpl, {
149
- ADR_DIR: dir,
150
- DECISIONS_REL: decisionsRelFromAdrReadme(dir, decisionsDoc),
151
- }),
152
- );
153
-
154
- if (opts.hooks !== false) {
155
- const hooksSrc = path.join(templates, 'hooks');
156
- if (fs.existsSync(hooksSrc)) {
157
- const hooksDestRel = 'scripts/hooks';
158
- for (const name of fs.readdirSync(hooksSrc)) {
159
- const from = path.join(hooksSrc, name);
160
- if (!fs.statSync(from).isFile()) continue;
161
- write(path.posix.join(hooksDestRel, name), fs.readFileSync(from, 'utf8'));
162
- }
163
- }
164
- }
165
-
166
- const config = writeProjectAdrConfig(cwd, {
167
- adr: { enabled: true, dir, decisionsDoc },
168
- });
169
-
170
- return { dir, decisionsDoc, files, config };
171
- }
172
-
173
- /**
174
- * @param {string} cwd
175
- */
176
- export function disableProjectAdr(cwd) {
177
- return writeProjectAdrConfig(cwd, { adr: { enabled: false } });
178
- }
179
-
180
- /**
181
- * @param {string} cwd
182
- * @returns {boolean}
183
- */
184
- export function isGitRepo(cwd) {
185
- return fs.existsSync(path.join(cwd, '.git'));
186
- }
187
-
188
- /**
189
- * @param {string} cwd
190
- * @param {{ home?: string }} [opts]
191
- * @returns {{ enabled: boolean, dir: string, decisionsDoc: string, source: string }}
192
- */
193
- export function resolveProjectAdr(cwd, opts = {}) {
194
- const project = loadProjectConfig(cwd);
195
- const projectAdr =
196
- project.adr && typeof project.adr === 'object'
197
- ? /** @type {{ enabled?: boolean, dir?: string, decisionsDoc?: string }} */ (project.adr)
198
- : null;
199
- if (projectAdr && typeof projectAdr.enabled === 'boolean') {
200
- const dir = normalizeAdrDir(projectAdr.dir ?? DEFAULT_ADR_DIR);
201
- return {
202
- enabled: projectAdr.enabled,
203
- dir,
204
- decisionsDoc: projectAdr.decisionsDoc ?? decisionsDocFor(dir),
205
- source: 'project',
206
- };
207
- }
208
- const user = loadUserConfig(opts.home);
209
- const userAdr =
210
- user.adr && typeof user.adr === 'object'
211
- ? /** @type {{ enabled?: boolean, dir?: string }} */ (user.adr)
212
- : null;
213
- if (userAdr && typeof userAdr.enabled === 'boolean') {
214
- const dir = normalizeAdrDir(userAdr.dir ?? DEFAULT_ADR_DIR);
215
- return {
216
- enabled: userAdr.enabled,
217
- dir,
218
- decisionsDoc: decisionsDocFor(dir),
219
- source: 'user',
220
- };
221
- }
222
- if (fs.existsSync(path.join(cwd, DEFAULT_ADR_DIR))) {
223
- return {
224
- enabled: true,
225
- dir: DEFAULT_ADR_DIR,
226
- decisionsDoc: decisionsDocFor(DEFAULT_ADR_DIR),
227
- source: 'heuristic',
228
- };
229
- }
230
- return {
231
- enabled: false,
232
- dir: DEFAULT_ADR_DIR,
233
- decisionsDoc: decisionsDocFor(DEFAULT_ADR_DIR),
234
- source: 'default',
235
- };
236
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * ADR project/user config + scaffolding for forgekit.
4
+ *
5
+ * User defaults: ~/.forgekit/config.json → { adr: { enabled, dir } }
6
+ * Project: <repo>/.forge/config.json → { adr: { enabled, dir, decisionsDoc } }
7
+ */
8
+
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import {
12
+ loadProjectConfig,
13
+ loadUserConfig,
14
+ saveProjectConfig,
15
+ saveUserConfig as saveUserConfigBase,
16
+ userConfigPath,
17
+ projectConfigPath,
18
+ } from './config.mjs';
19
+ import { resolveAsset } from './paths.mjs';
20
+
21
+ export {
22
+ loadProjectConfig,
23
+ loadUserConfig,
24
+ userConfigPath,
25
+ projectConfigPath,
26
+ };
27
+
28
+ export const DEFAULT_ADR_DIR = 'docs/adr';
29
+ export const ADR_SKILLS = Object.freeze(['archive-to-adr', 'git-resolve-adr-conflict']);
30
+
31
+ /**
32
+ * @param {string} adrDir posix-ish relative path
33
+ * @returns {string}
34
+ */
35
+ export function decisionsDocFor(adrDir) {
36
+ const normalized = normalizeAdrDir(adrDir);
37
+ const parent = path.posix.dirname(normalized);
38
+ if (!parent || parent === '.') return 'decisions.md';
39
+ return path.posix.join(parent, 'decisions.md');
40
+ }
41
+
42
+ /**
43
+ * @param {string} raw
44
+ * @returns {string}
45
+ */
46
+ export function normalizeAdrDir(raw) {
47
+ let s = String(raw ?? '')
48
+ .trim()
49
+ .replace(/\\/g, '/');
50
+ if (!s) s = DEFAULT_ADR_DIR;
51
+ s = s.replace(/^\.\/+/, '').replace(/\/+$/, '');
52
+ if (!s) s = DEFAULT_ADR_DIR;
53
+ if (path.isAbsolute(s) || s.startsWith('..') || s.split('/').includes('..')) {
54
+ throw new Error(
55
+ `ADR directory must be a relative path inside the repo (got: ${raw})`,
56
+ );
57
+ }
58
+ return s;
59
+ }
60
+
61
+ /**
62
+ * @param {{ adr?: { enabled?: boolean, dir?: string } }} patch
63
+ * @param {string} [home]
64
+ */
65
+ export function saveUserConfig(patch, home) {
66
+ return saveUserConfigBase(patch, home);
67
+ }
68
+
69
+ /**
70
+ * @param {string} cwd
71
+ * @param {{ adr: { enabled: boolean, dir?: string, decisionsDoc?: string } }} patch
72
+ */
73
+ export function writeProjectAdrConfig(cwd, patch) {
74
+ const current = loadProjectConfig(cwd);
75
+ const enabled = Boolean(patch.adr.enabled);
76
+ /** @type {{ enabled: boolean, dir?: string, decisionsDoc?: string }} */
77
+ const adr = { enabled };
78
+ if (enabled) {
79
+ const curAdr =
80
+ current.adr && typeof current.adr === 'object'
81
+ ? /** @type {{ dir?: string, decisionsDoc?: string }} */ (current.adr)
82
+ : {};
83
+ const dir = normalizeAdrDir(patch.adr.dir ?? curAdr.dir ?? DEFAULT_ADR_DIR);
84
+ adr.dir = dir;
85
+ adr.decisionsDoc =
86
+ patch.adr.decisionsDoc ?? curAdr.decisionsDoc ?? decisionsDocFor(dir);
87
+ }
88
+ return saveProjectConfig(cwd, { adr });
89
+ }
90
+
91
+ /**
92
+ * @returns {string}
93
+ */
94
+ export function resolveAdrTemplatesRoot() {
95
+ return resolveAsset('templates/adr');
96
+ }
97
+
98
+ /**
99
+ * @param {string} template
100
+ * @param {Record<string, string>} vars
101
+ */
102
+ function renderTemplate(template, vars) {
103
+ return template.replace(/\{\{(\w+)\}\}/g, (_, key) => vars[key] ?? '');
104
+ }
105
+
106
+ /**
107
+ * Relative link from adr README to decisions doc.
108
+ * @param {string} adrDir
109
+ * @param {string} decisionsDoc
110
+ */
111
+ export function decisionsRelFromAdrReadme(adrDir, decisionsDoc) {
112
+ const fromDir = adrDir.replace(/\/+$/, '');
113
+ const target = decisionsDoc.replace(/\\/g, '/');
114
+ const rel = path.posix.relative(fromDir, target);
115
+ return rel.startsWith('.') ? rel : `./${rel}`;
116
+ }
117
+
118
+ /**
119
+ * Scaffold decisions.md, adr README, optional hooks.
120
+ * @param {string} cwd
121
+ * @param {{ dir?: string, decisionsDoc?: string, force?: boolean, hooks?: boolean }} opts
122
+ */
123
+ export function scaffoldAdr(cwd, opts = {}) {
124
+ const dir = normalizeAdrDir(opts.dir ?? DEFAULT_ADR_DIR);
125
+ const decisionsDoc = opts.decisionsDoc ?? decisionsDocFor(dir);
126
+ const templates = resolveAdrTemplatesRoot();
127
+ const force = Boolean(opts.force);
128
+ /** @type {{ file: string, status: string }[]} */
129
+ const files = [];
130
+
131
+ const write = (relPath, body) => {
132
+ const dest = path.join(cwd, ...relPath.split('/'));
133
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
134
+ if (fs.existsSync(dest) && !force) {
135
+ files.push({ file: relPath, status: 'skipped' });
136
+ return;
137
+ }
138
+ fs.writeFileSync(dest, body, 'utf8');
139
+ files.push({ file: relPath, status: 'written' });
140
+ };
141
+
142
+ const decisionsTpl = fs.readFileSync(path.join(templates, 'decisions.md'), 'utf8');
143
+ write(decisionsDoc, renderTemplate(decisionsTpl, { ADR_DIR: dir }));
144
+
145
+ const readmeTpl = fs.readFileSync(path.join(templates, 'README.md'), 'utf8');
146
+ write(
147
+ path.posix.join(dir, 'README.md'),
148
+ renderTemplate(readmeTpl, {
149
+ ADR_DIR: dir,
150
+ DECISIONS_REL: decisionsRelFromAdrReadme(dir, decisionsDoc),
151
+ }),
152
+ );
153
+
154
+ if (opts.hooks !== false) {
155
+ const hooksSrc = path.join(templates, 'hooks');
156
+ if (fs.existsSync(hooksSrc)) {
157
+ const hooksDestRel = 'scripts/hooks';
158
+ for (const name of fs.readdirSync(hooksSrc)) {
159
+ const from = path.join(hooksSrc, name);
160
+ if (!fs.statSync(from).isFile()) continue;
161
+ write(path.posix.join(hooksDestRel, name), fs.readFileSync(from, 'utf8'));
162
+ }
163
+ }
164
+ }
165
+
166
+ const config = writeProjectAdrConfig(cwd, {
167
+ adr: { enabled: true, dir, decisionsDoc },
168
+ });
169
+
170
+ return { dir, decisionsDoc, files, config };
171
+ }
172
+
173
+ /**
174
+ * @param {string} cwd
175
+ */
176
+ export function disableProjectAdr(cwd) {
177
+ return writeProjectAdrConfig(cwd, { adr: { enabled: false } });
178
+ }
179
+
180
+ /**
181
+ * @param {string} cwd
182
+ * @returns {boolean}
183
+ */
184
+ export function isGitRepo(cwd) {
185
+ return fs.existsSync(path.join(cwd, '.git'));
186
+ }
187
+
188
+ /**
189
+ * @param {string} cwd
190
+ * @param {{ home?: string }} [opts]
191
+ * @returns {{ enabled: boolean, dir: string, decisionsDoc: string, source: string }}
192
+ */
193
+ export function resolveProjectAdr(cwd, opts = {}) {
194
+ const project = loadProjectConfig(cwd);
195
+ const projectAdr =
196
+ project.adr && typeof project.adr === 'object'
197
+ ? /** @type {{ enabled?: boolean, dir?: string, decisionsDoc?: string }} */ (project.adr)
198
+ : null;
199
+ if (projectAdr && typeof projectAdr.enabled === 'boolean') {
200
+ const dir = normalizeAdrDir(projectAdr.dir ?? DEFAULT_ADR_DIR);
201
+ return {
202
+ enabled: projectAdr.enabled,
203
+ dir,
204
+ decisionsDoc: projectAdr.decisionsDoc ?? decisionsDocFor(dir),
205
+ source: 'project',
206
+ };
207
+ }
208
+ const user = loadUserConfig(opts.home);
209
+ const userAdr =
210
+ user.adr && typeof user.adr === 'object'
211
+ ? /** @type {{ enabled?: boolean, dir?: string }} */ (user.adr)
212
+ : null;
213
+ if (userAdr && typeof userAdr.enabled === 'boolean') {
214
+ const dir = normalizeAdrDir(userAdr.dir ?? DEFAULT_ADR_DIR);
215
+ return {
216
+ enabled: userAdr.enabled,
217
+ dir,
218
+ decisionsDoc: decisionsDocFor(dir),
219
+ source: 'user',
220
+ };
221
+ }
222
+ if (fs.existsSync(path.join(cwd, DEFAULT_ADR_DIR))) {
223
+ return {
224
+ enabled: true,
225
+ dir: DEFAULT_ADR_DIR,
226
+ decisionsDoc: decisionsDocFor(DEFAULT_ADR_DIR),
227
+ source: 'heuristic',
228
+ };
229
+ }
230
+ return {
231
+ enabled: false,
232
+ dir: DEFAULT_ADR_DIR,
233
+ decisionsDoc: decisionsDocFor(DEFAULT_ADR_DIR),
234
+ source: 'default',
235
+ };
236
+ }