@danielstyle/featflow 0.0.0-stage → 0.6.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/LICENSE +21 -0
- package/README.md +206 -2
- package/README.zh-CN.md +163 -0
- package/bin/featflow.mjs +113 -0
- package/package.json +62 -4
- package/skills/featflow/SKILL.md +127 -0
- package/skills/featflow-issues/SKILL.md +104 -0
- package/skills/featflow-regression/SKILL.md +63 -0
- package/src/agent-docs.mjs +143 -0
- package/src/changed-files.mjs +204 -0
- package/src/commands/cleanup.mjs +221 -0
- package/src/commands/codegraph.mjs +110 -0
- package/src/commands/doctor.mjs +265 -0
- package/src/commands/finish.mjs +249 -0
- package/src/commands/hook-cmd.mjs +78 -0
- package/src/commands/hooks-cmd.mjs +238 -0
- package/src/commands/init.mjs +382 -0
- package/src/commands/issue.mjs +434 -0
- package/src/commands/new.mjs +311 -0
- package/src/commands/plan-check.mjs +75 -0
- package/src/commands/policy-cmd.mjs +51 -0
- package/src/commands/pr-cleanup.mjs +194 -0
- package/src/commands/regression.mjs +206 -0
- package/src/commands/setup.mjs +343 -0
- package/src/commands/size-check.mjs +137 -0
- package/src/commands/status.mjs +100 -0
- package/src/commands/sync.mjs +407 -0
- package/src/commands/verify.mjs +206 -0
- package/src/commands/worktree.mjs +205 -0
- package/src/config.mjs +295 -0
- package/src/detect.mjs +314 -0
- package/src/git.mjs +331 -0
- package/src/hook-adapters.mjs +218 -0
- package/src/hooks-core.mjs +420 -0
- package/src/index.mjs +13 -0
- package/src/init-args.mjs +282 -0
- package/src/init-hooks.mjs +312 -0
- package/src/init-prompts.mjs +191 -0
- package/src/issues-helpers.mjs +463 -0
- package/src/issues.mjs +521 -0
- package/src/plan.mjs +202 -0
- package/src/policy.mjs +143 -0
- package/src/regression.mjs +338 -0
- package/src/size-check.mjs +203 -0
- package/src/tui-select.mjs +378 -0
- package/templates/adapters/antigravity/hooks.json +42 -0
- package/templates/adapters/claude-code/settings.json +46 -0
- package/templates/adapters/codex/config.toml +19 -0
- package/templates/adapters/cursor/hooks.json +27 -0
- package/templates/agents/codex/codebase-locator.toml +28 -0
- package/templates/agents/codex/implementation-scout.toml +28 -0
- package/templates/agents/codex/regression-guard-planner.toml +20 -0
- package/templates/features/README.md +56 -0
- package/templates/features/_program_template.md +79 -0
- package/templates/features/_template.md +120 -0
- package/templates/features/current-feature.md +18 -0
- package/templates/githooks/post-merge +7 -0
- package/templates/githooks/pre-commit +11 -0
- package/templates/githooks/pre-push +10 -0
- package/templates/regression/regression-ledger.yml +23 -0
- package/templates/snippets/AGENTS-workflow.md +21 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { fail } from "./git.mjs";
|
|
2
|
+
import { parseAgentHooksList } from "./init-hooks.mjs";
|
|
3
|
+
|
|
4
|
+
export const INIT_USAGE = `
|
|
5
|
+
Usage:
|
|
6
|
+
featflow init [options]
|
|
7
|
+
|
|
8
|
+
Scaffolds or upgrades featflow in the current Git repository with automatic
|
|
9
|
+
environment detection, interactive multi-select checkboxes on TTY, universal
|
|
10
|
+
AI agent hooks, and non-destructive AGENTS.md / CLAUDE.md workflow injection.
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
--preset <minimal|standard|full> Preset bundle ("full" enables size-budget, regression, issues, codex-agents, repo Git hooks & all 4 agent hooks).
|
|
14
|
+
--minimal Shortcut for --preset minimal (lightweight .featflow.json + AGENTS.md + local hooks).
|
|
15
|
+
--merge Non-destructively upgrade an existing .featflow.json repo (preserves existing keys & unmanaged AGENTS.md).
|
|
16
|
+
--mode <trunk|developer-branch> Branch topology preset (default: trunk, or prompted on TTY).
|
|
17
|
+
--finish-target <merge|pr> In trunk mode, whether "finish" merges into base or pushes for PR (default: merge).
|
|
18
|
+
--features-dir <dir> Custom directory for feature records (default: features).
|
|
19
|
+
--local-features Store feature records locally (.gitignore features/) instead of tracking in Git.
|
|
20
|
+
--track-pointer Track features/current-feature.md in Git instead of ignoring it locally.
|
|
21
|
+
--with-githooks Copy tracked .githooks/ and enable core.hooksPath when not claimed by Husky/Lefthook.
|
|
22
|
+
--local-hooks Install managed Git hook blocks in .git/hooks/ (default in --minimal).
|
|
23
|
+
--no-hooks Skip Git hook installation.
|
|
24
|
+
--agent-hooks <list|all|none> Comma-separated agent hooks: antigravity,claude-code,codex,cursor (or "all" / "none").
|
|
25
|
+
--with-all-hooks Install/merge hooks for all 4 supported agents (antigravity, claude-code, codex, cursor).
|
|
26
|
+
--with-antigravity-hooks Install or merge Antigravity hook configuration (.agents/hooks.json).
|
|
27
|
+
--with-codex-hooks Install or merge Codex hook configuration (.codex/config.toml).
|
|
28
|
+
--with-claude-hooks Install or merge Claude Code hook configuration (.claude/settings.json).
|
|
29
|
+
--with-cursor-hooks Install or merge Cursor hook configuration (.cursor/hooks.json).
|
|
30
|
+
--with-codex-agents Install generic read-only Codex subagent templates (.codex/agents/*.toml).
|
|
31
|
+
--with-issues Enable optional GitHub Issues closed-loop config & featflow-issues Skill.
|
|
32
|
+
--issue-assets-repo <o/r> Configure issues.assetsRepo for screenshot uploads (implies --with-issues).
|
|
33
|
+
--with-size-budget Enable optional fileSizeBudget (600 prod / 700 style / 900 test + pre-commit guard).
|
|
34
|
+
--with-regression Enable optional regression ledger config, starter ledger & featflow-regression Skill.
|
|
35
|
+
--agent-docs <files> Comma-separated agent doc files to update (e.g. AGENTS.md,CLAUDE.md).
|
|
36
|
+
--no-agent-docs Skip injecting the managed workflow block into AGENTS.md / CLAUDE.md.
|
|
37
|
+
--no-detect Skip automatic branch, productPaths, and verifyCommands detection.
|
|
38
|
+
--developer-branch <name> In developer-branch mode, also run personal branch setup immediately.
|
|
39
|
+
--local-only When setting up a developer branch during init, do not touch the remote.
|
|
40
|
+
--no-gitignore Do not update .gitignore automatically.
|
|
41
|
+
-y, --yes Accept detected defaults without interactive prompts.
|
|
42
|
+
--force Overwrite existing featflow templates and config.
|
|
43
|
+
-h, --help Show this help.
|
|
44
|
+
`.trim();
|
|
45
|
+
|
|
46
|
+
function applyAgentHookSet(options, hookSet) {
|
|
47
|
+
options.withAntigravityHooks = hookSet.has("antigravity");
|
|
48
|
+
options.withClaudeHooks = hookSet.has("claude-code");
|
|
49
|
+
options.withCodexHooks = hookSet.has("codex");
|
|
50
|
+
options.withCursorHooks = hookSet.has("cursor");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function parseInitArgs(argv) {
|
|
54
|
+
const options = {
|
|
55
|
+
preset: "",
|
|
56
|
+
minimal: false,
|
|
57
|
+
minimalExplicit: false,
|
|
58
|
+
merge: false,
|
|
59
|
+
mode: "trunk",
|
|
60
|
+
modeExplicit: false,
|
|
61
|
+
finishTarget: "",
|
|
62
|
+
finishTargetExplicit: false,
|
|
63
|
+
featuresDir: "",
|
|
64
|
+
localFeatures: false,
|
|
65
|
+
trackPointer: false,
|
|
66
|
+
withGithooks: false,
|
|
67
|
+
localHooks: false,
|
|
68
|
+
noHooks: false,
|
|
69
|
+
hooksExplicit: false,
|
|
70
|
+
withAntigravityHooks: false,
|
|
71
|
+
withCodexHooks: false,
|
|
72
|
+
withClaudeHooks: false,
|
|
73
|
+
withCursorHooks: false,
|
|
74
|
+
agentHooksExplicit: false,
|
|
75
|
+
withCodexAgents: false,
|
|
76
|
+
withIssues: false,
|
|
77
|
+
issueAssetsRepo: "",
|
|
78
|
+
withSizeBudget: false,
|
|
79
|
+
withRegression: false,
|
|
80
|
+
capabilitiesExplicit: false,
|
|
81
|
+
agentDocs: null,
|
|
82
|
+
updateAgentDocs: true,
|
|
83
|
+
detect: true,
|
|
84
|
+
developerBranch: "",
|
|
85
|
+
localOnly: false,
|
|
86
|
+
updateGitignore: true,
|
|
87
|
+
yes: false,
|
|
88
|
+
force: false,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
92
|
+
const arg = argv[i];
|
|
93
|
+
if (arg === "-h" || arg === "--help") {
|
|
94
|
+
console.log(INIT_USAGE);
|
|
95
|
+
process.exit(0);
|
|
96
|
+
}
|
|
97
|
+
if (arg === "--preset" || arg.startsWith("--preset=")) {
|
|
98
|
+
const value = arg.startsWith("--preset=") ? arg.slice("--preset=".length) : (argv[++i] ?? "");
|
|
99
|
+
if (!["minimal", "standard", "full"].includes(value)) {
|
|
100
|
+
fail(`Invalid value for --preset "${value}". Expected minimal, standard, or full.`, INIT_USAGE);
|
|
101
|
+
}
|
|
102
|
+
options.preset = value;
|
|
103
|
+
options.minimal = value === "minimal";
|
|
104
|
+
options.minimalExplicit = true;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (arg === "--minimal") {
|
|
108
|
+
options.preset = "minimal";
|
|
109
|
+
options.minimal = true;
|
|
110
|
+
options.minimalExplicit = true;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (arg === "--merge") {
|
|
114
|
+
options.merge = true;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (arg === "--mode" || arg.startsWith("--mode=")) {
|
|
118
|
+
options.mode = arg.startsWith("--mode=") ? arg.slice("--mode=".length) : (argv[++i] ?? "");
|
|
119
|
+
options.modeExplicit = true;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (arg === "--finish-target" || arg.startsWith("--finish-target=")) {
|
|
123
|
+
options.finishTarget = arg.startsWith("--finish-target=")
|
|
124
|
+
? arg.slice("--finish-target=".length)
|
|
125
|
+
: (argv[++i] ?? "");
|
|
126
|
+
options.finishTargetExplicit = true;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (arg === "--features-dir" || arg.startsWith("--features-dir=")) {
|
|
130
|
+
options.featuresDir = arg.startsWith("--features-dir=")
|
|
131
|
+
? arg.slice("--features-dir=".length)
|
|
132
|
+
: (argv[++i] ?? "");
|
|
133
|
+
if (!options.featuresDir) fail("Missing value for --features-dir.", INIT_USAGE);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (arg === "--local-features") {
|
|
137
|
+
options.localFeatures = true;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (arg === "--track-pointer") {
|
|
141
|
+
options.trackPointer = true;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (arg === "--with-githooks") {
|
|
145
|
+
options.withGithooks = true;
|
|
146
|
+
options.hooksExplicit = true;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (arg === "--local-hooks") {
|
|
150
|
+
options.localHooks = true;
|
|
151
|
+
options.hooksExplicit = true;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (arg === "--no-hooks") {
|
|
155
|
+
options.noHooks = true;
|
|
156
|
+
options.hooksExplicit = true;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (arg === "--agent-hooks" || arg.startsWith("--agent-hooks=")) {
|
|
160
|
+
const value = arg.startsWith("--agent-hooks=") ? arg.slice("--agent-hooks=".length) : (argv[++i] ?? "");
|
|
161
|
+
try {
|
|
162
|
+
applyAgentHookSet(options, parseAgentHooksList(value));
|
|
163
|
+
} catch (error) {
|
|
164
|
+
fail(error instanceof Error ? error.message : String(error), INIT_USAGE);
|
|
165
|
+
}
|
|
166
|
+
options.agentHooksExplicit = true;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (arg === "--with-all-hooks") {
|
|
170
|
+
applyAgentHookSet(options, parseAgentHooksList("all"));
|
|
171
|
+
options.agentHooksExplicit = true;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (arg === "--with-antigravity-hooks") {
|
|
175
|
+
options.withAntigravityHooks = true;
|
|
176
|
+
options.agentHooksExplicit = true;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (arg === "--with-codex-hooks") {
|
|
180
|
+
options.withCodexHooks = true;
|
|
181
|
+
options.agentHooksExplicit = true;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (arg === "--with-claude-hooks") {
|
|
185
|
+
options.withClaudeHooks = true;
|
|
186
|
+
options.agentHooksExplicit = true;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (arg === "--with-cursor-hooks") {
|
|
190
|
+
options.withCursorHooks = true;
|
|
191
|
+
options.agentHooksExplicit = true;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (arg === "--with-codex-agents") {
|
|
195
|
+
options.withCodexAgents = true;
|
|
196
|
+
options.capabilitiesExplicit = true;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (arg === "--with-size-budget") {
|
|
200
|
+
options.withSizeBudget = true;
|
|
201
|
+
options.capabilitiesExplicit = true;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (arg === "--with-regression") {
|
|
205
|
+
options.withRegression = true;
|
|
206
|
+
options.capabilitiesExplicit = true;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (arg === "--with-issues") {
|
|
210
|
+
options.withIssues = true;
|
|
211
|
+
options.capabilitiesExplicit = true;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (arg === "--issue-assets-repo" || arg.startsWith("--issue-assets-repo=")) {
|
|
215
|
+
options.issueAssetsRepo = arg.startsWith("--issue-assets-repo=")
|
|
216
|
+
? arg.slice("--issue-assets-repo=".length)
|
|
217
|
+
: (argv[++i] ?? "");
|
|
218
|
+
if (!options.issueAssetsRepo || !options.issueAssetsRepo.includes("/")) {
|
|
219
|
+
fail('Invalid value for --issue-assets-repo. Expected "<owner>/<repo>".', INIT_USAGE);
|
|
220
|
+
}
|
|
221
|
+
options.withIssues = true;
|
|
222
|
+
options.capabilitiesExplicit = true;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (arg === "--agent-docs" || arg.startsWith("--agent-docs=")) {
|
|
226
|
+
const value = arg.startsWith("--agent-docs=") ? arg.slice("--agent-docs=".length) : (argv[++i] ?? "");
|
|
227
|
+
if (!value) fail("Missing value for --agent-docs.", INIT_USAGE);
|
|
228
|
+
options.agentDocs = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (arg === "--no-agent-docs") {
|
|
232
|
+
options.updateAgentDocs = false;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (arg === "--no-detect") {
|
|
236
|
+
options.detect = false;
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (arg === "--developer-branch" || arg.startsWith("--developer-branch=")) {
|
|
240
|
+
options.developerBranch = arg.startsWith("--developer-branch=")
|
|
241
|
+
? arg.slice("--developer-branch=".length)
|
|
242
|
+
: (argv[++i] ?? "");
|
|
243
|
+
if (!options.developerBranch) fail("Missing value for --developer-branch.", INIT_USAGE);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (arg === "--local-only") {
|
|
247
|
+
options.localOnly = true;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (arg === "--no-gitignore") {
|
|
251
|
+
options.updateGitignore = false;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (arg === "-y" || arg === "--yes") {
|
|
255
|
+
options.yes = true;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (arg === "--force") {
|
|
259
|
+
options.force = true;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
fail(`Unknown option: ${arg}`, INIT_USAGE);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (options.preset === "full") {
|
|
266
|
+
options.withSizeBudget = true;
|
|
267
|
+
options.withRegression = true;
|
|
268
|
+
options.withIssues = true;
|
|
269
|
+
options.withCodexAgents = true;
|
|
270
|
+
options.capabilitiesExplicit = true;
|
|
271
|
+
if (!options.hooksExplicit) {
|
|
272
|
+
options.withGithooks = true;
|
|
273
|
+
options.hooksExplicit = true;
|
|
274
|
+
}
|
|
275
|
+
if (!options.agentHooksExplicit) {
|
|
276
|
+
applyAgentHookSet(options, parseAgentHooksList("all"));
|
|
277
|
+
options.agentHooksExplicit = true;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return options;
|
|
282
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { packageRoot } from "./config.mjs";
|
|
5
|
+
|
|
6
|
+
const CODEX_BLOCK_START = "# >>> featflow managed hooks >>>";
|
|
7
|
+
const CODEX_BLOCK_END = "# <<< featflow managed hooks <<<";
|
|
8
|
+
|
|
9
|
+
export const AGENT_HOOK_IDS = ["antigravity", "claude-code", "codex", "cursor"];
|
|
10
|
+
|
|
11
|
+
export function parseAgentHooksList(rawValue) {
|
|
12
|
+
const normalized = String(rawValue ?? "").trim().toLowerCase();
|
|
13
|
+
if (!normalized || normalized === "none") {
|
|
14
|
+
return new Set();
|
|
15
|
+
}
|
|
16
|
+
if (normalized === "all") {
|
|
17
|
+
return new Set(AGENT_HOOK_IDS);
|
|
18
|
+
}
|
|
19
|
+
const aliases = {
|
|
20
|
+
antigravity: "antigravity",
|
|
21
|
+
agy: "antigravity",
|
|
22
|
+
claude: "claude-code",
|
|
23
|
+
"claude-code": "claude-code",
|
|
24
|
+
codex: "codex",
|
|
25
|
+
cursor: "cursor",
|
|
26
|
+
};
|
|
27
|
+
const selected = new Set();
|
|
28
|
+
for (const part of normalized.split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
29
|
+
const mapped = aliases[part];
|
|
30
|
+
if (!mapped) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Unknown agent hook target "${part}". Expected comma-separated values from: ${AGENT_HOOK_IDS.join(", ")}, "all", or "none".`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
selected.add(mapped);
|
|
36
|
+
}
|
|
37
|
+
return selected;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function copyTemplateFile(src, dest, force, created, skipped) {
|
|
41
|
+
if (existsSync(dest) && !force) {
|
|
42
|
+
skipped.push(dest);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
mkdirSync(path.dirname(dest), { recursive: true });
|
|
46
|
+
copyFileSync(src, dest);
|
|
47
|
+
created.push(dest);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function writeTextFile(dest, content, force, created, skipped) {
|
|
52
|
+
if (existsSync(dest) && !force) {
|
|
53
|
+
skipped.push(dest);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
mkdirSync(path.dirname(dest), { recursive: true });
|
|
57
|
+
writeFileSync(dest, content, "utf8");
|
|
58
|
+
created.push(dest);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function ensureGitignoreEntries(repoRoot, entries) {
|
|
63
|
+
const gitignorePath = path.join(repoRoot, ".gitignore");
|
|
64
|
+
const existing = existsSync(gitignorePath) ? readFileSync(gitignorePath, "utf8") : "";
|
|
65
|
+
const lines = existing.split(/\r?\n/);
|
|
66
|
+
const toAdd = entries.filter((entry) => !lines.includes(entry));
|
|
67
|
+
if (toAdd.length === 0) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const block = [
|
|
72
|
+
existing && !existing.endsWith("\n") ? "\n" : "",
|
|
73
|
+
existing ? "\n" : "",
|
|
74
|
+
"# featflow local state\n",
|
|
75
|
+
...toAdd.map((entry) => `${entry}\n`),
|
|
76
|
+
].join("");
|
|
77
|
+
writeFileSync(gitignorePath, `${existing}${block}`, "utf8");
|
|
78
|
+
return toAdd;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function hasHookCommand(entries, command) {
|
|
82
|
+
if (!Array.isArray(entries)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
if (!entry || typeof entry !== "object") {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (entry.command === command) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(entry.hooks) && entry.hooks.some((item) => item && item.command === command)) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function installClaudeHooks(repoRoot, force, created, updated, skipped, notices) {
|
|
100
|
+
const src = path.join(packageRoot, "templates", "adapters", "claude-code", "settings.json");
|
|
101
|
+
const dest = path.join(repoRoot, ".claude", "settings.json");
|
|
102
|
+
|
|
103
|
+
if (!existsSync(dest) || force) {
|
|
104
|
+
copyTemplateFile(src, dest, force, created, skipped);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let existing;
|
|
109
|
+
try {
|
|
110
|
+
existing = JSON.parse(readFileSync(dest, "utf8"));
|
|
111
|
+
} catch (error) {
|
|
112
|
+
skipped.push(dest);
|
|
113
|
+
notices.push(
|
|
114
|
+
`Skipped merging .claude/settings.json (invalid JSON: ${error instanceof Error ? error.message : String(error)}).`,
|
|
115
|
+
);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!existing || typeof existing !== "object" || Array.isArray(existing)) {
|
|
120
|
+
skipped.push(dest);
|
|
121
|
+
notices.push("Skipped merging .claude/settings.json (expected a top-level JSON object).");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const template = JSON.parse(readFileSync(src, "utf8"));
|
|
126
|
+
if (!existing.hooks || typeof existing.hooks !== "object" || Array.isArray(existing.hooks)) {
|
|
127
|
+
existing.hooks = {};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let changed = false;
|
|
131
|
+
for (const [eventName, templateEntries] of Object.entries(template.hooks ?? {})) {
|
|
132
|
+
if (!Array.isArray(existing.hooks[eventName])) {
|
|
133
|
+
existing.hooks[eventName] = [];
|
|
134
|
+
}
|
|
135
|
+
for (const templateEntry of templateEntries) {
|
|
136
|
+
const targetCmd = templateEntry.hooks?.[0]?.command ?? templateEntry.command ?? "";
|
|
137
|
+
if (targetCmd && !hasHookCommand(existing.hooks[eventName], targetCmd)) {
|
|
138
|
+
existing.hooks[eventName].push(templateEntry);
|
|
139
|
+
changed = true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (changed) {
|
|
145
|
+
writeFileSync(dest, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
|
|
146
|
+
updated.push(dest);
|
|
147
|
+
} else {
|
|
148
|
+
skipped.push(dest);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function installAntigravityHooks(repoRoot, force, created, updated, skipped, notices) {
|
|
153
|
+
const src = path.join(packageRoot, "templates", "adapters", "antigravity", "hooks.json");
|
|
154
|
+
const dest = path.join(repoRoot, ".agents", "hooks.json");
|
|
155
|
+
|
|
156
|
+
if (!existsSync(dest) || force) {
|
|
157
|
+
copyTemplateFile(src, dest, force, created, skipped);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let existing;
|
|
162
|
+
try {
|
|
163
|
+
existing = JSON.parse(readFileSync(dest, "utf8"));
|
|
164
|
+
} catch (error) {
|
|
165
|
+
skipped.push(dest);
|
|
166
|
+
notices.push(
|
|
167
|
+
`Skipped merging .agents/hooks.json (invalid JSON: ${error instanceof Error ? error.message : String(error)}).`,
|
|
168
|
+
);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!existing || typeof existing !== "object" || Array.isArray(existing)) {
|
|
173
|
+
skipped.push(dest);
|
|
174
|
+
notices.push("Skipped merging .agents/hooks.json (expected a top-level JSON object).");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const template = JSON.parse(readFileSync(src, "utf8"));
|
|
179
|
+
const before = JSON.stringify(existing.featflow ?? null);
|
|
180
|
+
const after = JSON.stringify(template.featflow);
|
|
181
|
+
if (before === after) {
|
|
182
|
+
skipped.push(dest);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
existing.featflow = template.featflow;
|
|
187
|
+
writeFileSync(dest, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
|
|
188
|
+
updated.push(dest);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function installCursorHooks(repoRoot, force, created, updated, skipped, notices) {
|
|
192
|
+
const src = path.join(packageRoot, "templates", "adapters", "cursor", "hooks.json");
|
|
193
|
+
const dest = path.join(repoRoot, ".cursor", "hooks.json");
|
|
194
|
+
|
|
195
|
+
if (!existsSync(dest) || force) {
|
|
196
|
+
copyTemplateFile(src, dest, force, created, skipped);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
let existing;
|
|
201
|
+
try {
|
|
202
|
+
existing = JSON.parse(readFileSync(dest, "utf8"));
|
|
203
|
+
} catch (error) {
|
|
204
|
+
skipped.push(dest);
|
|
205
|
+
notices.push(
|
|
206
|
+
`Skipped merging .cursor/hooks.json (invalid JSON: ${error instanceof Error ? error.message : String(error)}).`,
|
|
207
|
+
);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!existing || typeof existing !== "object" || Array.isArray(existing)) {
|
|
212
|
+
skipped.push(dest);
|
|
213
|
+
notices.push("Skipped merging .cursor/hooks.json (expected a top-level JSON object).");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const template = JSON.parse(readFileSync(src, "utf8"));
|
|
218
|
+
if (existing.version === undefined) {
|
|
219
|
+
existing.version = template.version ?? 1;
|
|
220
|
+
}
|
|
221
|
+
if (!existing.hooks || typeof existing.hooks !== "object" || Array.isArray(existing.hooks)) {
|
|
222
|
+
existing.hooks = {};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let changed = false;
|
|
226
|
+
for (const [eventName, templateEntries] of Object.entries(template.hooks ?? {})) {
|
|
227
|
+
if (!Array.isArray(existing.hooks[eventName])) {
|
|
228
|
+
existing.hooks[eventName] = [];
|
|
229
|
+
}
|
|
230
|
+
for (const templateEntry of templateEntries) {
|
|
231
|
+
const targetCmd = templateEntry.command ?? "";
|
|
232
|
+
if (targetCmd && !hasHookCommand(existing.hooks[eventName], targetCmd)) {
|
|
233
|
+
existing.hooks[eventName].push(templateEntry);
|
|
234
|
+
changed = true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (changed) {
|
|
240
|
+
writeFileSync(dest, `${JSON.stringify(existing, null, 2)}\n`, "utf8");
|
|
241
|
+
updated.push(dest);
|
|
242
|
+
} else {
|
|
243
|
+
skipped.push(dest);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function installCodexHooks(repoRoot, force, created, updated, skipped, notices) {
|
|
248
|
+
const src = path.join(packageRoot, "templates", "adapters", "codex", "config.toml");
|
|
249
|
+
const dest = path.join(repoRoot, ".codex", "config.toml");
|
|
250
|
+
|
|
251
|
+
if (!existsSync(dest) || force) {
|
|
252
|
+
copyTemplateFile(src, dest, force, created, skipped);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const existing = readFileSync(dest, "utf8");
|
|
257
|
+
if (existing.includes("featflow hook codex")) {
|
|
258
|
+
skipped.push(dest);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (/^\s*\[hooks\]\s*$/m.test(existing)) {
|
|
263
|
+
skipped.push(dest);
|
|
264
|
+
notices.push(
|
|
265
|
+
[
|
|
266
|
+
"Kept existing .codex/config.toml (custom [hooks] section already exists).",
|
|
267
|
+
"Merge these featflow entries under [hooks]:",
|
|
268
|
+
' userPromptSubmit: { command = "featflow hook codex user-prompt", timeoutSec = 5 }',
|
|
269
|
+
' preToolUse: { command = "featflow hook codex pre-tool-use", timeoutSec = 5 }',
|
|
270
|
+
' postToolUse: { command = "featflow hook codex post-tool-use", timeoutSec = 30 }',
|
|
271
|
+
' stop: { command = "featflow hook codex stop", timeoutSec = 8 }',
|
|
272
|
+
].join("\n"),
|
|
273
|
+
);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const templateBody = readFileSync(src, "utf8").trim();
|
|
278
|
+
const trimmed = existing.replace(/\s+$/, "");
|
|
279
|
+
const appended = [trimmed, trimmed ? "" : null, CODEX_BLOCK_START, templateBody, CODEX_BLOCK_END, ""]
|
|
280
|
+
.filter((line) => line !== null)
|
|
281
|
+
.join("\n");
|
|
282
|
+
writeFileSync(dest, appended, "utf8");
|
|
283
|
+
updated.push(dest);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function installCodexAgents(repoRoot, force, created, skipped) {
|
|
287
|
+
const srcDir = path.join(packageRoot, "templates", "agents", "codex");
|
|
288
|
+
const destDir = path.join(repoRoot, ".codex", "agents");
|
|
289
|
+
for (const name of ["codebase-locator.toml", "implementation-scout.toml", "regression-guard-planner.toml"]) {
|
|
290
|
+
copyTemplateFile(path.join(srcDir, name), path.join(destDir, name), force, created, skipped);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function installInitialRegressionLedger(repoRoot, ledgerRelPath, force, created, skipped) {
|
|
295
|
+
const src = path.join(packageRoot, "templates", "regression", "regression-ledger.yml");
|
|
296
|
+
const dest = path.resolve(repoRoot, ledgerRelPath || "context/regression-ledger.yml");
|
|
297
|
+
return copyTemplateFile(src, dest, force, created, skipped);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function parseYesNo(answer, defaultYes = true) {
|
|
301
|
+
const normalized = String(answer ?? "").trim().toLowerCase();
|
|
302
|
+
if (!normalized) {
|
|
303
|
+
return defaultYes;
|
|
304
|
+
}
|
|
305
|
+
if (["y", "yes", "true", "1"].includes(normalized)) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
if (["n", "no", "false", "0"].includes(normalized)) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
return defaultYes;
|
|
312
|
+
}
|