@danielstyle/featflow 0.0.0-stage → 0.6.4
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 +249 -2
- package/README.zh-CN.md +250 -0
- package/bin/featflow.mjs +116 -0
- package/package.json +63 -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 +108 -0
- package/src/commands/doctor.mjs +303 -0
- package/src/commands/finish.mjs +249 -0
- package/src/commands/hook-cmd.mjs +78 -0
- package/src/commands/hooks-cmd.mjs +247 -0
- package/src/commands/init.mjs +477 -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 +55 -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/skills.mjs +181 -0
- package/src/commands/status.mjs +100 -0
- package/src/commands/sync.mjs +421 -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 +14 -0
- package/src/init-args.mjs +294 -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/skills-manager.mjs +348 -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 +10 -0
- package/templates/githooks/pre-commit +14 -0
- package/templates/githooks/pre-push +13 -0
- package/templates/regression/regression-ledger.yml +23 -0
- package/templates/snippets/AGENTS-workflow.md +21 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { findManagedAgentDocs, renderAgentWorkflowBlock, resolveAgentDocTargets, upsertAgentDocBlock } from "../agent-docs.mjs";
|
|
5
|
+
import {
|
|
6
|
+
CONFIG_FILENAME,
|
|
7
|
+
DEFAULT_FILE_SIZE_BUDGET,
|
|
8
|
+
DEFAULT_ISSUES_CONFIG,
|
|
9
|
+
DEFAULT_REGRESSION_CONFIG,
|
|
10
|
+
packageRoot,
|
|
11
|
+
presetConfig,
|
|
12
|
+
} from "../config.mjs";
|
|
13
|
+
import { applyDetectedConfig, detectRepoEnvironment } from "../detect.mjs";
|
|
14
|
+
import { fail, findRepoRoot, gitConfigGet } from "../git.mjs";
|
|
15
|
+
import { INIT_USAGE, parseInitArgs } from "../init-args.mjs";
|
|
16
|
+
import {
|
|
17
|
+
copyTemplateFile,
|
|
18
|
+
ensureGitignoreEntries,
|
|
19
|
+
installAntigravityHooks,
|
|
20
|
+
installClaudeHooks,
|
|
21
|
+
installCodexAgents,
|
|
22
|
+
installCodexHooks,
|
|
23
|
+
installCursorHooks,
|
|
24
|
+
installInitialRegressionLedger,
|
|
25
|
+
writeTextFile,
|
|
26
|
+
} from "../init-hooks.mjs";
|
|
27
|
+
import { promptInteractiveOptions } from "../init-prompts.mjs";
|
|
28
|
+
import { evaluateFileSizeBudget, updateFileSizeBaseline } from "../size-check.mjs";
|
|
29
|
+
import {
|
|
30
|
+
inspectCliAvailability,
|
|
31
|
+
inspectSkillsStatus,
|
|
32
|
+
installGlobalSkills,
|
|
33
|
+
mapHookAgentsToSkillTargets,
|
|
34
|
+
requiredSkillsForConfig,
|
|
35
|
+
} from "../skills-manager.mjs";
|
|
36
|
+
import { createSmartPrompter, promptSingleSelect } from "../tui-select.mjs";
|
|
37
|
+
import { configureGitHooksSafely, installLocalHooks } from "./hooks-cmd.mjs";
|
|
38
|
+
import { setupDeveloperBranchWorkflow } from "./setup.mjs";
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
configureGitHooksSafely,
|
|
42
|
+
installAntigravityHooks,
|
|
43
|
+
installClaudeHooks,
|
|
44
|
+
installCodexAgents,
|
|
45
|
+
installCodexHooks,
|
|
46
|
+
installCursorHooks,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function readExistingRawConfig(configPath) {
|
|
50
|
+
if (!existsSync(configPath)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
55
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
fail(`Existing ${CONFIG_FILENAME} is invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function runInit(argv) {
|
|
62
|
+
const options = parseInitArgs(argv);
|
|
63
|
+
const repoRoot = findRepoRoot(process.cwd());
|
|
64
|
+
if (!repoRoot) {
|
|
65
|
+
fail("Not inside a Git repository. Run `git init` first.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const configPath = path.join(repoRoot, CONFIG_FILENAME);
|
|
69
|
+
const existingConfig = options.merge ? readExistingRawConfig(configPath) : null;
|
|
70
|
+
|
|
71
|
+
const detected = options.detect
|
|
72
|
+
? detectRepoEnvironment(repoRoot, { featuresDir: options.featuresDir || existingConfig?.featuresDir || "features" })
|
|
73
|
+
: null;
|
|
74
|
+
|
|
75
|
+
const isInteractive =
|
|
76
|
+
!options.yes &&
|
|
77
|
+
(Boolean(process.stdin.isTTY && process.stdout.isTTY) || process.env.FEATFLOW_FORCE_TTY === "1");
|
|
78
|
+
|
|
79
|
+
const prompter = isInteractive ? createSmartPrompter() : null;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
if (prompter && detected) {
|
|
83
|
+
await promptInteractiveOptions(prompter, options, detected, repoRoot, existingConfig);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let config;
|
|
87
|
+
let configChangedInMerge = false;
|
|
88
|
+
if (options.merge && existingConfig) {
|
|
89
|
+
config = structuredClone(existingConfig);
|
|
90
|
+
if (options.withIssues && !config.issues) {
|
|
91
|
+
config.issues = { ...DEFAULT_ISSUES_CONFIG, assetsRepo: options.issueAssetsRepo || null };
|
|
92
|
+
configChangedInMerge = true;
|
|
93
|
+
} else if (options.issueAssetsRepo && config.issues && !config.issues.assetsRepo) {
|
|
94
|
+
config.issues.assetsRepo = options.issueAssetsRepo;
|
|
95
|
+
configChangedInMerge = true;
|
|
96
|
+
}
|
|
97
|
+
if (options.withSizeBudget && !config.fileSizeBudget) {
|
|
98
|
+
config.fileSizeBudget = { ...DEFAULT_FILE_SIZE_BUDGET };
|
|
99
|
+
configChangedInMerge = true;
|
|
100
|
+
}
|
|
101
|
+
if (options.withRegression && !config.regression) {
|
|
102
|
+
config.regression = { ...DEFAULT_REGRESSION_CONFIG };
|
|
103
|
+
configChangedInMerge = true;
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
try {
|
|
107
|
+
config = presetConfig(options.mode);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
fail(error instanceof Error ? error.message : String(error), INIT_USAGE);
|
|
110
|
+
}
|
|
111
|
+
if (detected) {
|
|
112
|
+
config = applyDetectedConfig(config, detected, {
|
|
113
|
+
explicitFeaturesDir: Boolean(options.featuresDir),
|
|
114
|
+
minimal: options.minimal,
|
|
115
|
+
localFeatures: options.localFeatures,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (options.featuresDir) config.featuresDir = options.featuresDir;
|
|
119
|
+
if (options.finishTarget) {
|
|
120
|
+
if (config.mode !== "trunk" || !["merge", "pr"].includes(options.finishTarget)) {
|
|
121
|
+
fail(`--finish-target "${options.finishTarget}" is only valid in trunk mode ("merge" or "pr").`, INIT_USAGE);
|
|
122
|
+
}
|
|
123
|
+
config.finishTarget = options.finishTarget;
|
|
124
|
+
}
|
|
125
|
+
if (options.localFeatures) config.trackFeaturesInGit = false;
|
|
126
|
+
if (options.trackPointer) config.trackCurrentFeaturePointer = true;
|
|
127
|
+
if (options.withIssues) {
|
|
128
|
+
config.issues = { ...DEFAULT_ISSUES_CONFIG, assetsRepo: options.issueAssetsRepo || null };
|
|
129
|
+
}
|
|
130
|
+
if (options.withSizeBudget) config.fileSizeBudget = { ...DEFAULT_FILE_SIZE_BUDGET };
|
|
131
|
+
if (options.withRegression) config.regression = { ...DEFAULT_REGRESSION_CONFIG };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const shouldInstallLocalHooks =
|
|
135
|
+
!options.noHooks && !options.withGithooks && (options.localHooks || (options.minimal && !options.merge));
|
|
136
|
+
const shouldInstallRepoHooks = !options.noHooks && options.withGithooks;
|
|
137
|
+
|
|
138
|
+
const created = [];
|
|
139
|
+
const updated = [];
|
|
140
|
+
const skipped = [];
|
|
141
|
+
const notices = [];
|
|
142
|
+
|
|
143
|
+
if (!options.merge && detected?.featuresDirConflict && !options.featuresDir) {
|
|
144
|
+
notices.push(
|
|
145
|
+
`Detected existing non-featflow "features/" directory; set featuresDir="${config.featuresDir}" to avoid collision (override with --features-dir).`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (options.merge && existingConfig) {
|
|
150
|
+
if (configChangedInMerge) {
|
|
151
|
+
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
152
|
+
updated.push(configPath);
|
|
153
|
+
} else {
|
|
154
|
+
skipped.push(configPath);
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
writeTextFile(configPath, `${JSON.stringify(config, null, 2)}\n`, options.force, created, skipped);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const featuresDir = config.featuresDir || "features";
|
|
161
|
+
if (!options.minimal && !(options.merge && existingConfig)) {
|
|
162
|
+
const featuresRoot = path.join(repoRoot, featuresDir);
|
|
163
|
+
for (const subdir of ["active", "done", "paused", "programs"]) {
|
|
164
|
+
mkdirSync(path.join(featuresRoot, subdir), { recursive: true });
|
|
165
|
+
const gitkeep = path.join(featuresRoot, subdir, ".gitkeep");
|
|
166
|
+
if (config.trackFeaturesInGit !== false && !existsSync(gitkeep)) {
|
|
167
|
+
writeFileSync(gitkeep, "", "utf8");
|
|
168
|
+
created.push(gitkeep);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const templateFeaturesDir = path.join(packageRoot, "templates", "features");
|
|
173
|
+
for (const file of ["README.md", "_template.md", "_program_template.md"]) {
|
|
174
|
+
copyTemplateFile(path.join(templateFeaturesDir, file), path.join(featuresRoot, file), options.force, created, skipped);
|
|
175
|
+
}
|
|
176
|
+
if (config.trackCurrentFeaturePointer) {
|
|
177
|
+
copyTemplateFile(
|
|
178
|
+
path.join(templateFeaturesDir, "current-feature.md"),
|
|
179
|
+
path.join(featuresRoot, "current-feature.md"),
|
|
180
|
+
options.force,
|
|
181
|
+
created,
|
|
182
|
+
skipped,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!options.minimal) {
|
|
188
|
+
if (options.withRepoSkills) {
|
|
189
|
+
copyTemplateFile(
|
|
190
|
+
path.join(packageRoot, "skills", "featflow", "SKILL.md"),
|
|
191
|
+
path.join(repoRoot, ".agents", "skills", "featflow", "SKILL.md"),
|
|
192
|
+
options.force,
|
|
193
|
+
created,
|
|
194
|
+
skipped,
|
|
195
|
+
);
|
|
196
|
+
if (options.withIssues || config.issues) {
|
|
197
|
+
copyTemplateFile(
|
|
198
|
+
path.join(packageRoot, "skills", "featflow-issues", "SKILL.md"),
|
|
199
|
+
path.join(repoRoot, ".agents", "skills", "featflow-issues", "SKILL.md"),
|
|
200
|
+
options.force,
|
|
201
|
+
created,
|
|
202
|
+
skipped,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
if (options.withRegression || config.regression) {
|
|
206
|
+
copyTemplateFile(
|
|
207
|
+
path.join(packageRoot, "skills", "featflow-regression", "SKILL.md"),
|
|
208
|
+
path.join(repoRoot, ".agents", "skills", "featflow-regression", "SKILL.md"),
|
|
209
|
+
options.force,
|
|
210
|
+
created,
|
|
211
|
+
skipped,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (options.withRegression) {
|
|
216
|
+
installInitialRegressionLedger(
|
|
217
|
+
repoRoot,
|
|
218
|
+
config.regression?.ledgerFile || DEFAULT_REGRESSION_CONFIG.ledgerFile,
|
|
219
|
+
options.force,
|
|
220
|
+
created,
|
|
221
|
+
skipped,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (options.updateAgentDocs) {
|
|
227
|
+
const targets =
|
|
228
|
+
options.merge && existingConfig && !options.agentDocs
|
|
229
|
+
? findManagedAgentDocs(repoRoot)
|
|
230
|
+
: resolveAgentDocTargets(repoRoot, options.agentDocs);
|
|
231
|
+
const renderedBlock = renderAgentWorkflowBlock();
|
|
232
|
+
for (const relTarget of targets) {
|
|
233
|
+
const absTarget = path.resolve(repoRoot, relTarget);
|
|
234
|
+
const result = upsertAgentDocBlock(absTarget, renderedBlock);
|
|
235
|
+
if (result.action === "created") created.push(absTarget);
|
|
236
|
+
else if (result.action === "updated") updated.push(absTarget);
|
|
237
|
+
else skipped.push(absTarget);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
let hookNotice = "";
|
|
242
|
+
if (shouldInstallRepoHooks) {
|
|
243
|
+
const srcHooks = path.join(packageRoot, "templates", "githooks");
|
|
244
|
+
const destHooks = path.join(repoRoot, ".githooks");
|
|
245
|
+
for (const hook of ["pre-commit", "pre-push", "post-merge"]) {
|
|
246
|
+
const dest = path.join(destHooks, hook);
|
|
247
|
+
const copied = copyTemplateFile(path.join(srcHooks, hook), dest, options.force, created, skipped);
|
|
248
|
+
if (copied || existsSync(dest)) chmodSync(dest, 0o755);
|
|
249
|
+
}
|
|
250
|
+
const hookResult = configureGitHooksSafely(repoRoot);
|
|
251
|
+
hookNotice = hookResult.configured
|
|
252
|
+
? "Git hooks enabled: core.hooksPath=.githooks"
|
|
253
|
+
: [
|
|
254
|
+
`Kept existing core.hooksPath=${hookResult.existingHooksPath} (did not overwrite).`,
|
|
255
|
+
"Add these lines to your existing hook manager instead:",
|
|
256
|
+
" pre-commit: featflow policy pre-commit",
|
|
257
|
+
" pre-push: featflow policy pre-push",
|
|
258
|
+
" post-merge: featflow cleanup --post-merge || true",
|
|
259
|
+
].join("\n");
|
|
260
|
+
} else if (shouldInstallLocalHooks) {
|
|
261
|
+
const localResult = installLocalHooks(repoRoot, { quiet: true });
|
|
262
|
+
hookNotice = localResult.installed
|
|
263
|
+
? `Local Git hooks enabled in ${localResult.hooksDir}: ${localResult.hooks.join(", ")}`
|
|
264
|
+
: [
|
|
265
|
+
`Kept existing core.hooksPath=${localResult.existingHooksPath} (did not overwrite).`,
|
|
266
|
+
"Add these lines to your existing hook manager instead:",
|
|
267
|
+
" pre-commit: featflow policy pre-commit",
|
|
268
|
+
" pre-push: featflow policy pre-push",
|
|
269
|
+
" post-merge: featflow cleanup --post-merge || true",
|
|
270
|
+
].join("\n");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (options.withAntigravityHooks) {
|
|
274
|
+
installAntigravityHooks(repoRoot, options.force, created, updated, skipped, notices);
|
|
275
|
+
}
|
|
276
|
+
if (options.withCodexHooks) {
|
|
277
|
+
installCodexHooks(repoRoot, options.force, created, updated, skipped, notices);
|
|
278
|
+
}
|
|
279
|
+
if (options.withClaudeHooks) {
|
|
280
|
+
installClaudeHooks(repoRoot, options.force, created, updated, skipped, notices);
|
|
281
|
+
}
|
|
282
|
+
if (options.withCursorHooks) {
|
|
283
|
+
installCursorHooks(repoRoot, options.force, created, updated, skipped, notices);
|
|
284
|
+
}
|
|
285
|
+
if (options.withCodexAgents) {
|
|
286
|
+
installCodexAgents(repoRoot, options.force, created, skipped);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (options.withSizeBudget && config.fileSizeBudget?.baselineFile) {
|
|
290
|
+
const baselineAbs = path.resolve(repoRoot, config.fileSizeBudget.baselineFile);
|
|
291
|
+
if (!existsSync(baselineAbs)) {
|
|
292
|
+
const evalRes = evaluateFileSizeBudget(repoRoot, config);
|
|
293
|
+
if (!evalRes.ok) {
|
|
294
|
+
const baseRes = updateFileSizeBaseline(repoRoot, config);
|
|
295
|
+
created.push(baseRes.absPath);
|
|
296
|
+
notices.push(
|
|
297
|
+
`Generated legacy size baseline ${baseRes.baselineFile} (${baseRes.entryCount} oversized file(s) ratcheted so existing code passes immediately).`,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let ignoredAdded = [];
|
|
304
|
+
if (options.updateGitignore) {
|
|
305
|
+
const entries = [".featflow/"];
|
|
306
|
+
if (!options.minimal && !(options.merge && existingConfig)) {
|
|
307
|
+
if (config.trackFeaturesInGit === false) entries.push(`${featuresDir}/`);
|
|
308
|
+
else if (!config.trackCurrentFeaturePointer) entries.push(`${featuresDir}/current-feature.md`);
|
|
309
|
+
}
|
|
310
|
+
ignoredAdded = ensureGitignoreEntries(repoRoot, entries);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
let devSetupSummary = "";
|
|
314
|
+
const devBranchConfigKey = config.developerBranchConfigKey || "featflow.developerBranch";
|
|
315
|
+
const hasConfiguredDevBranch = Boolean(gitConfigGet(devBranchConfigKey, repoRoot));
|
|
316
|
+
if (config.mode === "developer-branch" && (!options.merge || !hasConfiguredDevBranch)) {
|
|
317
|
+
let shouldRunSetup = Boolean(options.developerBranch);
|
|
318
|
+
if (!shouldRunSetup && prompter) {
|
|
319
|
+
const answer = await promptSingleSelect(prompter, {
|
|
320
|
+
title: "Set up your personal developer branch now?",
|
|
321
|
+
defaultId: "yes",
|
|
322
|
+
choices: [
|
|
323
|
+
{ id: "yes", label: "Yes", detail: "create/track your personal developer branch now", aliases: ["y", "true"] },
|
|
324
|
+
{ id: "no", label: "No", detail: "skip for now (run `featflow setup <name>` later)", aliases: ["n", "false"] },
|
|
325
|
+
],
|
|
326
|
+
});
|
|
327
|
+
shouldRunSetup = answer === "yes";
|
|
328
|
+
}
|
|
329
|
+
if (shouldRunSetup) {
|
|
330
|
+
try {
|
|
331
|
+
const setupRes = await setupDeveloperBranchWorkflow(repoRoot, config, {
|
|
332
|
+
branch: options.developerBranch,
|
|
333
|
+
localOnly: options.localOnly,
|
|
334
|
+
rl: prompter,
|
|
335
|
+
});
|
|
336
|
+
devSetupSummary = `Developer branch configured: ${setupRes.branch} (${setupRes.result})`;
|
|
337
|
+
} catch (error) {
|
|
338
|
+
notices.push(
|
|
339
|
+
`[WARN] Developer branch setup was NOT completed:\n${error instanceof Error ? error.message : String(error)}`,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
let skillSummary = "";
|
|
346
|
+
let needsGlobalSkillInstall = false;
|
|
347
|
+
const requiredSkills = requiredSkillsForConfig(config);
|
|
348
|
+
const ensureSkillAgents = mapHookAgentsToSkillTargets(options);
|
|
349
|
+
if (!options.withRepoSkills) {
|
|
350
|
+
const skillReport = inspectSkillsStatus({
|
|
351
|
+
repoRoot,
|
|
352
|
+
skillNames: requiredSkills,
|
|
353
|
+
ensureAgents: ensureSkillAgents,
|
|
354
|
+
});
|
|
355
|
+
if (skillReport.allGlobalReady) {
|
|
356
|
+
skillSummary = `Global skills ready: ${requiredSkills.join(", ")} (${skillReport.targets.map((t) => t.displayDir).join(", ")})`;
|
|
357
|
+
} else {
|
|
358
|
+
const pendingNames = [...new Set([...skillReport.missingSkills, ...skillReport.driftedSkills])];
|
|
359
|
+
let shouldSyncGlobal = options.installGlobalSkills;
|
|
360
|
+
if (!shouldSyncGlobal && prompter) {
|
|
361
|
+
const answer = await promptSingleSelect(prompter, {
|
|
362
|
+
title: `Global skills need install/update (${pendingNames.join(", ")}). Sync now?`,
|
|
363
|
+
defaultId: "yes",
|
|
364
|
+
choices: [
|
|
365
|
+
{
|
|
366
|
+
id: "yes",
|
|
367
|
+
label: "Yes",
|
|
368
|
+
detail: `sync to ${skillReport.targets.map((t) => t.displayDir).join(", ")} (offline, matches CLI)`,
|
|
369
|
+
aliases: ["y", "true"],
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
id: "no",
|
|
373
|
+
label: "No",
|
|
374
|
+
detail: "skip for now (run `featflow skills install` later)",
|
|
375
|
+
aliases: ["n", "false"],
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
});
|
|
379
|
+
shouldSyncGlobal = answer === "yes";
|
|
380
|
+
}
|
|
381
|
+
if (shouldSyncGlobal) {
|
|
382
|
+
const syncRes = installGlobalSkills({
|
|
383
|
+
skillNames: requiredSkills,
|
|
384
|
+
ensureAgents: ensureSkillAgents,
|
|
385
|
+
});
|
|
386
|
+
const touched = syncRes.installed.length + syncRes.updated.length;
|
|
387
|
+
skillSummary = `Synced global skills (${touched} file(s) across ${syncRes.targets.map((t) => t.displayDir).join(", ")})`;
|
|
388
|
+
} else {
|
|
389
|
+
needsGlobalSkillInstall = true;
|
|
390
|
+
notices.push(
|
|
391
|
+
[
|
|
392
|
+
`Global skills missing or outdated for this repo: ${pendingNames.join(", ")}.`,
|
|
393
|
+
"Run `featflow skills install` (offline, syncs all detected agents) or `npx skills add https://github.com/daniel-style/featflow --skill " +
|
|
394
|
+
requiredSkills.join(" ") +
|
|
395
|
+
" -g`.",
|
|
396
|
+
].join("\n"),
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (skillReport.shadowedSkills.length > 0) {
|
|
401
|
+
notices.push(
|
|
402
|
+
`Existing repo-level .agents/skills/ copies detected (${skillReport.shadowedSkills.join(", ")}); they take precedence over global skills until removed or updated via \`featflow sync\`.`,
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const cliState = inspectCliAvailability(repoRoot);
|
|
408
|
+
const hasAgentHooks =
|
|
409
|
+
options.withAntigravityHooks ||
|
|
410
|
+
options.withClaudeHooks ||
|
|
411
|
+
options.withCodexHooks ||
|
|
412
|
+
options.withCursorHooks;
|
|
413
|
+
const needsGlobalCli = !cliState.onPath && (hasAgentHooks || (!cliState.localBin && !cliState.mainLocalBin));
|
|
414
|
+
if (!cliState.onPath && hasAgentHooks) {
|
|
415
|
+
notices.push(
|
|
416
|
+
[
|
|
417
|
+
"[WARN] `featflow` CLI is not on your global PATH, while AI coding-agent hooks invoke `featflow hook ...` directly.",
|
|
418
|
+
"Install globally so hooks and agents work across all worktrees: npm install -g @danielstyle/featflow",
|
|
419
|
+
].join("\n"),
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const actionVerb = options.merge && existingConfig ? "Upgraded" : "Initialized";
|
|
424
|
+
const profileLabel = options.minimal ? "minimal" : options.preset || "full";
|
|
425
|
+
console.log(`${actionVerb} featflow in ${repoRoot} (mode: ${config.mode}, profile: ${profileLabel})`);
|
|
426
|
+
if (detected && !(options.merge && existingConfig)) {
|
|
427
|
+
const verifySummary =
|
|
428
|
+
Object.keys(config.verifyCommands ?? {}).length > 0 ? Object.values(config.verifyCommands)[0] : "(none)";
|
|
429
|
+
console.log(
|
|
430
|
+
`Detected: baseBranch=${config.baseBranch}, protected=[${(config.protectedBranches ?? []).join(", ")}], productPaths=[${(config.productPaths ?? []).join(", ")}], verify=${verifySummary}`,
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
if (created.length > 0) {
|
|
434
|
+
console.log("Created:");
|
|
435
|
+
for (const file of created) console.log(` - ${path.relative(repoRoot, file)}`);
|
|
436
|
+
}
|
|
437
|
+
if (updated.length > 0) {
|
|
438
|
+
console.log("Updated (non-destructive):");
|
|
439
|
+
for (const file of updated) console.log(` - ${path.relative(repoRoot, file)}`);
|
|
440
|
+
}
|
|
441
|
+
if (skipped.length > 0) {
|
|
442
|
+
console.log("Kept existing (pass --force to overwrite):");
|
|
443
|
+
for (const file of skipped) console.log(` - ${path.relative(repoRoot, file)}`);
|
|
444
|
+
}
|
|
445
|
+
if (ignoredAdded.length > 0) console.log(`Updated .gitignore with: ${ignoredAdded.join(", ")}`);
|
|
446
|
+
if (hookNotice) console.log(`\n${hookNotice}`);
|
|
447
|
+
if (skillSummary) console.log(`\n${skillSummary}`);
|
|
448
|
+
if (devSetupSummary) console.log(`\n${devSetupSummary}`);
|
|
449
|
+
for (const notice of notices) console.log(`\n${notice}`);
|
|
450
|
+
|
|
451
|
+
if (!options.merge && detected?.suggestions?.length > 0) {
|
|
452
|
+
console.log("\nOptional .featflow.json suggestions:");
|
|
453
|
+
for (const suggestion of detected.suggestions) console.log(` - ${suggestion}`);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
console.log("\nNext steps:");
|
|
457
|
+
const steps = [];
|
|
458
|
+
if (needsGlobalCli) {
|
|
459
|
+
steps.push("Ensure featflow CLI is on PATH: npm install -g @danielstyle/featflow");
|
|
460
|
+
}
|
|
461
|
+
if (needsGlobalSkillInstall) {
|
|
462
|
+
steps.push("Sync global Agent Skills: featflow skills install");
|
|
463
|
+
}
|
|
464
|
+
if (!options.merge && config.mode === "developer-branch" && !devSetupSummary) {
|
|
465
|
+
steps.push("Run: featflow setup <your-branch-name>");
|
|
466
|
+
}
|
|
467
|
+
steps.push("Start a task worktree: featflow worktree feat/my-first-task");
|
|
468
|
+
steps.push(
|
|
469
|
+
options.minimal
|
|
470
|
+
? "Draft a feature record inside the worktree: featflow new my-first-task --local"
|
|
471
|
+
: "Check workflow health anytime with: featflow doctor",
|
|
472
|
+
);
|
|
473
|
+
steps.forEach((step, idx) => console.log(` ${idx + 1}. ${step}`));
|
|
474
|
+
} finally {
|
|
475
|
+
if (prompter) prompter.close();
|
|
476
|
+
}
|
|
477
|
+
}
|