@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,247 @@
|
|
|
1
|
+
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { packageRoot } from "../config.mjs";
|
|
5
|
+
import { fail, findGitCommonDir, findRepoRoot, gitConfigGet, gitConfigSet } from "../git.mjs";
|
|
6
|
+
|
|
7
|
+
const BLOCK_START = "# >>> featflow managed hook >>>";
|
|
8
|
+
const BLOCK_END = "# <<< featflow managed hook <<<";
|
|
9
|
+
|
|
10
|
+
const HOOK_SNIPPETS = {
|
|
11
|
+
"pre-commit": [
|
|
12
|
+
BLOCK_START,
|
|
13
|
+
'_ff_common_dir="$(git rev-parse --git-common-dir 2>/dev/null || true)"',
|
|
14
|
+
'if [ -x "./node_modules/.bin/featflow" ]; then',
|
|
15
|
+
" ./node_modules/.bin/featflow policy pre-commit || exit $?",
|
|
16
|
+
'elif [ -n "$_ff_common_dir" ] && [ -x "$_ff_common_dir/../node_modules/.bin/featflow" ]; then',
|
|
17
|
+
' "$_ff_common_dir/../node_modules/.bin/featflow" policy pre-commit || exit $?',
|
|
18
|
+
"elif command -v featflow >/dev/null 2>&1; then",
|
|
19
|
+
" featflow policy pre-commit || exit $?",
|
|
20
|
+
"fi",
|
|
21
|
+
BLOCK_END,
|
|
22
|
+
].join("\n"),
|
|
23
|
+
"pre-push": [
|
|
24
|
+
BLOCK_START,
|
|
25
|
+
'_ff_common_dir="$(git rev-parse --git-common-dir 2>/dev/null || true)"',
|
|
26
|
+
'if [ -x "./node_modules/.bin/featflow" ]; then',
|
|
27
|
+
" ./node_modules/.bin/featflow policy pre-push || exit $?",
|
|
28
|
+
'elif [ -n "$_ff_common_dir" ] && [ -x "$_ff_common_dir/../node_modules/.bin/featflow" ]; then',
|
|
29
|
+
' "$_ff_common_dir/../node_modules/.bin/featflow" policy pre-push || exit $?',
|
|
30
|
+
"elif command -v featflow >/dev/null 2>&1; then",
|
|
31
|
+
" featflow policy pre-push || exit $?",
|
|
32
|
+
"fi",
|
|
33
|
+
BLOCK_END,
|
|
34
|
+
].join("\n"),
|
|
35
|
+
"post-merge": [
|
|
36
|
+
BLOCK_START,
|
|
37
|
+
'_ff_common_dir="$(git rev-parse --git-common-dir 2>/dev/null || true)"',
|
|
38
|
+
'if [ -x "./node_modules/.bin/featflow" ]; then',
|
|
39
|
+
" ./node_modules/.bin/featflow cleanup --post-merge || true",
|
|
40
|
+
'elif [ -n "$_ff_common_dir" ] && [ -x "$_ff_common_dir/../node_modules/.bin/featflow" ]; then',
|
|
41
|
+
' "$_ff_common_dir/../node_modules/.bin/featflow" cleanup --post-merge || true',
|
|
42
|
+
"elif command -v featflow >/dev/null 2>&1; then",
|
|
43
|
+
" featflow cleanup --post-merge || true",
|
|
44
|
+
"fi",
|
|
45
|
+
BLOCK_END,
|
|
46
|
+
].join("\n"),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const usage = `
|
|
50
|
+
Usage:
|
|
51
|
+
featflow hooks install [--local|--repo]
|
|
52
|
+
featflow hooks uninstall [--local]
|
|
53
|
+
featflow hooks status
|
|
54
|
+
|
|
55
|
+
Manages Git hooks for featflow without polluting the target repository.
|
|
56
|
+
|
|
57
|
+
Modes:
|
|
58
|
+
--local (default) Install/remove managed blocks inside .git/hooks/ (zero tracked
|
|
59
|
+
files, preserves existing local hooks, works across worktrees).
|
|
60
|
+
--repo Copy tracked hooks to .githooks/ and safely configure core.hooksPath.
|
|
61
|
+
`.trim();
|
|
62
|
+
|
|
63
|
+
export function configureGitHooksSafely(repoRoot) {
|
|
64
|
+
const existingHooksPath = gitConfigGet("core.hooksPath", repoRoot);
|
|
65
|
+
if (!existingHooksPath || existingHooksPath === ".githooks") {
|
|
66
|
+
gitConfigSet("core.hooksPath", ".githooks", repoRoot);
|
|
67
|
+
return { configured: true, existingHooksPath: ".githooks" };
|
|
68
|
+
}
|
|
69
|
+
return { configured: false, existingHooksPath };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function escapeRegex(value) {
|
|
73
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function stripManagedBlock(content) {
|
|
77
|
+
const regex = new RegExp(`(?:\\r?\\n)*${escapeRegex(BLOCK_START)}[\\s\\S]*?${escapeRegex(BLOCK_END)}(?:\\r?\\n)?`, "g");
|
|
78
|
+
return content.replace(regex, "\n").replace(/\n{3,}/g, "\n\n").trimEnd();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function hasManagedBlock(filePath) {
|
|
82
|
+
if (!existsSync(filePath)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return readFileSync(filePath, "utf8").includes(BLOCK_START);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function installLocalHooks(repoRoot, options = {}) {
|
|
89
|
+
const quiet = Boolean(options.quiet);
|
|
90
|
+
const commonDir = findGitCommonDir(repoRoot);
|
|
91
|
+
if (!commonDir) {
|
|
92
|
+
fail("Could not resolve .git directory.");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const hooksPath = gitConfigGet("core.hooksPath", repoRoot);
|
|
96
|
+
if (hooksPath) {
|
|
97
|
+
if (!quiet) {
|
|
98
|
+
console.warn(`Warning: core.hooksPath is set to "${hooksPath}", so Git ignores .git/hooks/.`);
|
|
99
|
+
console.warn("Add these calls to your existing hook manager instead:");
|
|
100
|
+
console.warn(" pre-commit: featflow policy pre-commit");
|
|
101
|
+
console.warn(" pre-push: featflow policy pre-push");
|
|
102
|
+
console.warn(" post-merge: featflow cleanup --post-merge || true");
|
|
103
|
+
}
|
|
104
|
+
return { installed: false, existingHooksPath: hooksPath, hooks: [], hooksDir: "" };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const hooksDir = path.join(commonDir, "hooks");
|
|
108
|
+
mkdirSync(hooksDir, { recursive: true });
|
|
109
|
+
|
|
110
|
+
const installed = [];
|
|
111
|
+
for (const [hookName, snippet] of Object.entries(HOOK_SNIPPETS)) {
|
|
112
|
+
const hookFile = path.join(hooksDir, hookName);
|
|
113
|
+
let nextContent;
|
|
114
|
+
if (existsSync(hookFile)) {
|
|
115
|
+
const existing = readFileSync(hookFile, "utf8");
|
|
116
|
+
const cleaned = stripManagedBlock(existing);
|
|
117
|
+
const base = cleaned.length > 0 ? cleaned : "#!/usr/bin/env sh";
|
|
118
|
+
nextContent = `${base}\n\n${snippet}\n`;
|
|
119
|
+
} else {
|
|
120
|
+
nextContent = `#!/usr/bin/env sh\n\n${snippet}\n`;
|
|
121
|
+
}
|
|
122
|
+
writeFileSync(hookFile, nextContent, "utf8");
|
|
123
|
+
chmodSync(hookFile, 0o755);
|
|
124
|
+
installed.push(hookName);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!quiet) {
|
|
128
|
+
console.log(`Installed local featflow Git hooks in ${hooksDir}: ${installed.join(", ")}`);
|
|
129
|
+
console.log("Zero repository files were modified (existing custom hooks were preserved).");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return { installed: true, existingHooksPath: "", hooks: installed, hooksDir };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function uninstallLocalHooks(repoRoot) {
|
|
136
|
+
const commonDir = findGitCommonDir(repoRoot);
|
|
137
|
+
if (!commonDir) {
|
|
138
|
+
fail("Could not resolve .git directory.");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const hooksDir = path.join(commonDir, "hooks");
|
|
142
|
+
const removed = [];
|
|
143
|
+
const preserved = [];
|
|
144
|
+
|
|
145
|
+
for (const hookName of Object.keys(HOOK_SNIPPETS)) {
|
|
146
|
+
const hookFile = path.join(hooksDir, hookName);
|
|
147
|
+
if (!hasManagedBlock(hookFile)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const existing = readFileSync(hookFile, "utf8");
|
|
151
|
+
const cleaned = stripManagedBlock(existing).trim();
|
|
152
|
+
const isOnlyShebang = !cleaned || /^#!\/[^\r\n]+$/.test(cleaned);
|
|
153
|
+
if (isOnlyShebang) {
|
|
154
|
+
unlinkSync(hookFile);
|
|
155
|
+
removed.push(hookName);
|
|
156
|
+
} else {
|
|
157
|
+
writeFileSync(hookFile, `${cleaned}\n`, "utf8");
|
|
158
|
+
preserved.push(hookName);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (removed.length === 0 && preserved.length === 0) {
|
|
163
|
+
console.log("No local featflow Git hooks found in .git/hooks/.");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (removed.length > 0) {
|
|
167
|
+
console.log(`Removed featflow-only local hooks: ${removed.join(", ")}`);
|
|
168
|
+
}
|
|
169
|
+
if (preserved.length > 0) {
|
|
170
|
+
console.log(`Removed featflow block while preserving custom hooks: ${preserved.join(", ")}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function installRepoHooks(repoRoot) {
|
|
175
|
+
const srcDir = path.join(packageRoot, "templates", "githooks");
|
|
176
|
+
const destDir = path.join(repoRoot, ".githooks");
|
|
177
|
+
mkdirSync(destDir, { recursive: true });
|
|
178
|
+
for (const hookName of Object.keys(HOOK_SNIPPETS)) {
|
|
179
|
+
const dest = path.join(destDir, hookName);
|
|
180
|
+
copyFileSync(path.join(srcDir, hookName), dest);
|
|
181
|
+
chmodSync(dest, 0o755);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const result = configureGitHooksSafely(repoRoot);
|
|
185
|
+
if (result.configured) {
|
|
186
|
+
console.log("Installed tracked hooks in .githooks/ and set core.hooksPath=.githooks.");
|
|
187
|
+
} else {
|
|
188
|
+
console.log(`Copied hooks to .githooks/, but kept existing core.hooksPath=${result.existingHooksPath}.`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function showHookStatus(repoRoot) {
|
|
193
|
+
const commonDir = findGitCommonDir(repoRoot);
|
|
194
|
+
const hooksPath = gitConfigGet("core.hooksPath", repoRoot);
|
|
195
|
+
const localHooksDir = commonDir ? path.join(commonDir, "hooks") : "";
|
|
196
|
+
const localActive = localHooksDir
|
|
197
|
+
? Object.keys(HOOK_SNIPPETS).filter((name) => hasManagedBlock(path.join(localHooksDir, name)))
|
|
198
|
+
: [];
|
|
199
|
+
const repoHooksExist = existsSync(path.join(repoRoot, ".githooks", "pre-commit"));
|
|
200
|
+
|
|
201
|
+
console.log("featflow hooks status");
|
|
202
|
+
console.log(`core.hooksPath: ${hooksPath || "(default .git/hooks)"}`);
|
|
203
|
+
console.log(`Local .git/hooks managed blocks: ${localActive.length > 0 ? localActive.join(", ") : "(none)"}`);
|
|
204
|
+
console.log(`Tracked .githooks/ present: ${repoHooksExist ? "yes" : "no"}`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function runHooks(argv) {
|
|
208
|
+
const action = argv[0] ?? "";
|
|
209
|
+
if (!action || action === "-h" || action === "--help") {
|
|
210
|
+
console.log(usage);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const rest = argv.slice(1);
|
|
215
|
+
if (rest.includes("-h") || rest.includes("--help")) {
|
|
216
|
+
console.log(usage);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const repoRoot = findRepoRoot(process.cwd());
|
|
221
|
+
if (!repoRoot) {
|
|
222
|
+
fail("Not inside a Git repository.");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const useRepo = rest.includes("--repo");
|
|
226
|
+
|
|
227
|
+
if (action === "install") {
|
|
228
|
+
if (useRepo) {
|
|
229
|
+
installRepoHooks(repoRoot);
|
|
230
|
+
} else {
|
|
231
|
+
installLocalHooks(repoRoot);
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (action === "uninstall") {
|
|
237
|
+
uninstallLocalHooks(repoRoot);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (action === "status") {
|
|
242
|
+
showHookStatus(repoRoot);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
fail(`Unknown hooks subcommand "${action}". Expected "install", "uninstall", or "status".`, usage);
|
|
247
|
+
}
|