@danielstyle/featflow 0.6.3 → 0.6.5

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/src/init-args.mjs CHANGED
@@ -28,10 +28,12 @@ Options:
28
28
  --with-claude-hooks Install or merge Claude Code hook configuration (.claude/settings.json).
29
29
  --with-cursor-hooks Install or merge Cursor hook configuration (.cursor/hooks.json).
30
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.
31
+ --with-issues Enable optional GitHub Issues closed-loop config (uses global featflow-issues Skill).
32
32
  --issue-assets-repo <o/r> Configure issues.assetsRepo for screenshot uploads (implies --with-issues).
33
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.
34
+ --with-regression Enable optional regression ledger config & starter ledger (uses global featflow-regression Skill).
35
+ --with-repo-skills Embed featflow SKILL.md files in .agents/skills/ inside this repo (default: use global skills).
36
+ --install-global-skills Install or refresh required global skills automatically without prompting.
35
37
  --agent-docs <files> Comma-separated agent doc files to update (e.g. AGENTS.md,CLAUDE.md).
36
38
  --no-agent-docs Skip injecting the managed workflow block into AGENTS.md / CLAUDE.md.
37
39
  --no-detect Skip automatic branch, productPaths, and verifyCommands detection.
@@ -77,6 +79,8 @@ export function parseInitArgs(argv) {
77
79
  issueAssetsRepo: "",
78
80
  withSizeBudget: false,
79
81
  withRegression: false,
82
+ withRepoSkills: false,
83
+ installGlobalSkills: false,
80
84
  capabilitiesExplicit: false,
81
85
  agentDocs: null,
82
86
  updateAgentDocs: true,
@@ -206,6 +210,14 @@ export function parseInitArgs(argv) {
206
210
  options.capabilitiesExplicit = true;
207
211
  continue;
208
212
  }
213
+ if (arg === "--with-repo-skills") {
214
+ options.withRepoSkills = true;
215
+ continue;
216
+ }
217
+ if (arg === "--install-global-skills") {
218
+ options.installGlobalSkills = true;
219
+ continue;
220
+ }
209
221
  if (arg === "--with-issues") {
210
222
  options.withIssues = true;
211
223
  options.capabilitiesExplicit = true;
@@ -30,7 +30,7 @@ export async function promptInteractiveOptions(prompter, options, detected, repo
30
30
  title: "Setup profile",
31
31
  defaultId: "full",
32
32
  choices: [
33
- { id: "full", label: "full", detail: "features/ templates, skills, guardrails & hooks", aliases: ["f"] },
33
+ { id: "full", label: "full", detail: "features/ templates, guardrails & hooks (uses global skills)", aliases: ["f"] },
34
34
  { id: "minimal", label: "minimal", detail: "lightweight (.featflow.json + AGENTS.md + local hooks)", aliases: ["m"] },
35
35
  ],
36
36
  });
@@ -118,13 +118,13 @@ export async function promptInteractiveOptions(prompter, options, detected, repo
118
118
  {
119
119
  id: "regression",
120
120
  label: "Regression Guardian",
121
- detail: "regression-ledger.yml + impact check + Skill",
121
+ detail: "regression-ledger.yml + impact check",
122
122
  checked: Boolean(defaultCheckAll || options.withRegression || existingConfig?.regression),
123
123
  },
124
124
  {
125
125
  id: "issues",
126
126
  label: "GitHub Issues loop",
127
- detail: "featflow issue CLI + featflow-issues Skill",
127
+ detail: "featflow issue CLI & GitHub workflow",
128
128
  checked: Boolean(defaultCheckAll || options.withIssues || existingConfig?.issues),
129
129
  },
130
130
  {
@@ -0,0 +1,348 @@
1
+ import { copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, rmSync } from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ import { packageRoot } from "./config.mjs";
6
+ import { commandExists, findMainRepoRoot } from "./git.mjs";
7
+
8
+ export const BUNDLED_SKILLS = ["featflow", "featflow-issues", "featflow-regression"];
9
+
10
+ export const GLOBAL_SKILL_AGENTS = [
11
+ {
12
+ id: "agents",
13
+ label: "Standard (.agents / Antigravity / Codex / Cursor)",
14
+ parentDir: ".agents",
15
+ skillsRel: path.join(".agents", "skills"),
16
+ alwaysDefault: true,
17
+ },
18
+ {
19
+ id: "claude-code",
20
+ label: "Claude Code (.claude)",
21
+ parentDir: ".claude",
22
+ skillsRel: path.join(".claude", "skills"),
23
+ alwaysDefault: false,
24
+ },
25
+ {
26
+ id: "codex",
27
+ label: "OpenAI Codex (.codex)",
28
+ parentDir: ".codex",
29
+ skillsRel: path.join(".codex", "skills"),
30
+ alwaysDefault: false,
31
+ },
32
+ {
33
+ id: "cursor",
34
+ label: "Cursor (.cursor)",
35
+ parentDir: ".cursor",
36
+ skillsRel: path.join(".cursor", "skills"),
37
+ alwaysDefault: false,
38
+ },
39
+ ];
40
+
41
+ const AGENT_ALIASES = {
42
+ agents: "agents",
43
+ standard: "agents",
44
+ antigravity: "agents",
45
+ agy: "agents",
46
+ claude: "claude-code",
47
+ "claude-code": "claude-code",
48
+ codex: "codex",
49
+ cursor: "cursor",
50
+ };
51
+
52
+ function normalizeLineEndings(content) {
53
+ return content.replace(/\r\n/g, "\n");
54
+ }
55
+
56
+ export function resolveFeatflowHome(env = process.env) {
57
+ return env.FEATFLOW_HOME || os.homedir() || "";
58
+ }
59
+
60
+ export function formatHomePath(absPath, home) {
61
+ if (home && absPath.startsWith(home)) {
62
+ return `~${absPath.slice(home.length).replaceAll("\\", "/")}`;
63
+ }
64
+ return absPath.replaceAll("\\", "/");
65
+ }
66
+
67
+ export function bundledSkillSourcePath(skillName) {
68
+ return path.join(packageRoot, "skills", skillName, "SKILL.md");
69
+ }
70
+
71
+ export function parseSkillNamesList(rawValue) {
72
+ const normalized = String(rawValue ?? "").trim().toLowerCase();
73
+ if (!normalized || normalized === "all") {
74
+ return [...BUNDLED_SKILLS];
75
+ }
76
+ const result = [];
77
+ for (const item of normalized.split(",").map((s) => s.trim()).filter(Boolean)) {
78
+ if (!BUNDLED_SKILLS.includes(item)) {
79
+ throw new Error(`Unknown skill "${item}". Expected comma-separated values from: ${BUNDLED_SKILLS.join(", ")}, or "all".`);
80
+ }
81
+ if (!result.includes(item)) {
82
+ result.push(item);
83
+ }
84
+ }
85
+ if (result.length === 0) {
86
+ throw new Error(`--only requires at least one skill (${BUNDLED_SKILLS.join(", ")}).`);
87
+ }
88
+ return result;
89
+ }
90
+
91
+ export function parseGlobalSkillAgents(rawValue) {
92
+ const normalized = String(rawValue ?? "").trim().toLowerCase();
93
+ if (!normalized || normalized === "auto") {
94
+ return null;
95
+ }
96
+ if (normalized === "all") {
97
+ return GLOBAL_SKILL_AGENTS.map((entry) => entry.id);
98
+ }
99
+ const result = [];
100
+ for (const item of normalized.split(",").map((s) => s.trim()).filter(Boolean)) {
101
+ const mapped = AGENT_ALIASES[item];
102
+ if (!mapped) {
103
+ throw new Error(
104
+ `Unknown agent target "${item}". Expected comma-separated values from: agents, antigravity, claude-code, codex, cursor, "all", or "auto".`,
105
+ );
106
+ }
107
+ if (!result.includes(mapped)) {
108
+ result.push(mapped);
109
+ }
110
+ }
111
+ return result;
112
+ }
113
+
114
+ export function requiredSkillsForConfig(config) {
115
+ const names = ["featflow"];
116
+ if (config?.issues) {
117
+ names.push("featflow-issues");
118
+ }
119
+ if (config?.regression) {
120
+ names.push("featflow-regression");
121
+ }
122
+ return names;
123
+ }
124
+
125
+ export function mapHookAgentsToSkillTargets(hookFlags = {}) {
126
+ const targets = ["agents"];
127
+ if (hookFlags.withClaudeHooks) targets.push("claude-code");
128
+ if (hookFlags.withCodexHooks) targets.push("codex");
129
+ if (hookFlags.withCursorHooks) targets.push("cursor");
130
+ return targets;
131
+ }
132
+
133
+ export function resolveGlobalSkillTargets({ home, agents = null, ensureAgents = [] }) {
134
+ if (!home) {
135
+ return [];
136
+ }
137
+ const explicitSet = Array.isArray(agents) ? new Set(agents) : null;
138
+ const ensureSet = new Set(ensureAgents);
139
+
140
+ const selected = [];
141
+ for (const entry of GLOBAL_SKILL_AGENTS) {
142
+ const parentAbs = path.join(home, entry.parentDir);
143
+ const shouldInclude = explicitSet
144
+ ? explicitSet.has(entry.id)
145
+ : entry.alwaysDefault || ensureSet.has(entry.id) || existsSync(parentAbs);
146
+ if (!shouldInclude) {
147
+ continue;
148
+ }
149
+ const skillsDir = path.join(home, entry.skillsRel);
150
+ selected.push({
151
+ ...entry,
152
+ skillsDir,
153
+ displayDir: formatHomePath(skillsDir, home),
154
+ });
155
+ }
156
+ return selected;
157
+ }
158
+
159
+ function inspectSkillFile(srcPath, destPath) {
160
+ if (!existsSync(destPath)) {
161
+ return "missing";
162
+ }
163
+ const expected = normalizeLineEndings(readFileSync(srcPath, "utf8"));
164
+ const actual = normalizeLineEndings(readFileSync(destPath, "utf8"));
165
+ return expected === actual ? "up-to-date" : "drifted";
166
+ }
167
+
168
+ function isSymlink(targetPath) {
169
+ try {
170
+ return lstatSync(targetPath).isSymbolicLink();
171
+ } catch {
172
+ return false;
173
+ }
174
+ }
175
+
176
+ export function inspectSkillsStatus({
177
+ repoRoot = null,
178
+ skillNames = BUNDLED_SKILLS,
179
+ agents = null,
180
+ ensureAgents = [],
181
+ env = process.env,
182
+ } = {}) {
183
+ const home = resolveFeatflowHome(env);
184
+ const targets = resolveGlobalSkillTargets({ home, agents, ensureAgents });
185
+ const skills = [];
186
+
187
+ for (const name of skillNames) {
188
+ const srcPath = bundledSkillSourcePath(name);
189
+ const globalTargets = targets.map((target) => {
190
+ const destPath = path.join(target.skillsDir, name, "SKILL.md");
191
+ const status = inspectSkillFile(srcPath, destPath);
192
+ return {
193
+ agentId: target.id,
194
+ label: target.label,
195
+ path: destPath,
196
+ display: formatHomePath(destPath, home),
197
+ status,
198
+ };
199
+ });
200
+
201
+ const repoPath = repoRoot ? path.join(repoRoot, ".agents", "skills", name, "SKILL.md") : null;
202
+ const repoStatus = repoPath ? inspectSkillFile(srcPath, repoPath) : "missing";
203
+
204
+ const upToDateCount = globalTargets.filter((t) => t.status === "up-to-date").length;
205
+ const driftedCount = globalTargets.filter((t) => t.status === "drifted").length;
206
+ const missingCount = globalTargets.filter((t) => t.status === "missing").length;
207
+ const hasAnyGlobal = upToDateCount > 0 || driftedCount > 0;
208
+ const allTargetsUpToDate = globalTargets.length > 0 && driftedCount === 0 && missingCount === 0;
209
+ const hasRepoCopy = repoStatus !== "missing";
210
+
211
+ skills.push({
212
+ name,
213
+ globalTargets,
214
+ hasAnyGlobal,
215
+ allTargetsUpToDate,
216
+ upToDateCount,
217
+ driftedCount,
218
+ missingCount,
219
+ repoPath,
220
+ repoStatus,
221
+ hasRepoCopy,
222
+ repoShadowsGlobal: hasRepoCopy && hasAnyGlobal,
223
+ repoStaleShadow: repoStatus === "drifted" && hasAnyGlobal,
224
+ });
225
+ }
226
+
227
+ return {
228
+ home,
229
+ targets,
230
+ skills,
231
+ allGlobalReady: skills.length > 0 && skills.every((s) => s.allTargetsUpToDate),
232
+ missingSkills: skills.filter((s) => s.missingCount > 0).map((s) => s.name),
233
+ driftedSkills: skills.filter((s) => s.driftedCount > 0).map((s) => s.name),
234
+ shadowedSkills: skills.filter((s) => s.repoShadowsGlobal).map((s) => s.name),
235
+ };
236
+ }
237
+
238
+ export function installGlobalSkills({
239
+ skillNames = BUNDLED_SKILLS,
240
+ agents = null,
241
+ ensureAgents = [],
242
+ dryRun = false,
243
+ env = process.env,
244
+ } = {}) {
245
+ const home = resolveFeatflowHome(env);
246
+ if (!home) {
247
+ throw new Error("Could not resolve home directory for global skill installation.");
248
+ }
249
+ const targets = resolveGlobalSkillTargets({ home, agents, ensureAgents });
250
+ const installed = [];
251
+ const updated = [];
252
+ const upToDate = [];
253
+
254
+ for (const target of targets) {
255
+ for (const name of skillNames) {
256
+ const srcPath = bundledSkillSourcePath(name);
257
+ const skillDir = path.join(target.skillsDir, name);
258
+ const destPath = path.join(skillDir, "SKILL.md");
259
+ const display = formatHomePath(destPath, home);
260
+
261
+ const status = inspectSkillFile(srcPath, destPath);
262
+ if (status === "up-to-date") {
263
+ upToDate.push({ name, agentId: target.id, path: destPath, display });
264
+ continue;
265
+ }
266
+
267
+ if (!dryRun) {
268
+ if (isSymlink(skillDir) && !existsSync(skillDir)) {
269
+ rmSync(skillDir, { force: true });
270
+ }
271
+ mkdirSync(skillDir, { recursive: true });
272
+ if (isSymlink(destPath) && !existsSync(destPath)) {
273
+ rmSync(destPath, { force: true });
274
+ }
275
+ copyFileSync(srcPath, destPath);
276
+ }
277
+
278
+ if (status === "missing") {
279
+ installed.push({ name, agentId: target.id, path: destPath, display });
280
+ } else {
281
+ updated.push({ name, agentId: target.id, path: destPath, display });
282
+ }
283
+ }
284
+ }
285
+
286
+ return {
287
+ home,
288
+ dryRun,
289
+ targets: targets.map((t) => ({ id: t.id, displayDir: t.displayDir })),
290
+ installed,
291
+ updated,
292
+ upToDate,
293
+ };
294
+ }
295
+
296
+ export function uninstallGlobalSkills({
297
+ skillNames = BUNDLED_SKILLS,
298
+ agents = null,
299
+ dryRun = false,
300
+ env = process.env,
301
+ } = {}) {
302
+ const home = resolveFeatflowHome(env);
303
+ if (!home) {
304
+ throw new Error("Could not resolve home directory.");
305
+ }
306
+ const agentList = agents ?? GLOBAL_SKILL_AGENTS.map((entry) => entry.id);
307
+ const targets = resolveGlobalSkillTargets({ home, agents: agentList });
308
+ const removed = [];
309
+
310
+ for (const target of targets) {
311
+ for (const name of skillNames) {
312
+ const skillDir = path.join(target.skillsDir, name);
313
+ const skillFile = path.join(skillDir, "SKILL.md");
314
+ if (!existsSync(skillFile) && !isSymlink(skillDir)) {
315
+ continue;
316
+ }
317
+ if (!dryRun) {
318
+ rmSync(skillDir, { recursive: true, force: true });
319
+ }
320
+ removed.push({
321
+ name,
322
+ agentId: target.id,
323
+ path: skillDir,
324
+ display: formatHomePath(skillDir, home),
325
+ });
326
+ }
327
+ }
328
+
329
+ return { home, dryRun, removed };
330
+ }
331
+
332
+ export function inspectCliAvailability(repoRoot = null) {
333
+ const binName = process.platform === "win32" ? "featflow.cmd" : "featflow";
334
+ const onPath = commandExists("featflow");
335
+ const localBinPath = repoRoot ? path.join(repoRoot, "node_modules", ".bin", binName) : "";
336
+ const localBin = Boolean(localBinPath && existsSync(localBinPath));
337
+
338
+ const mainRoot = repoRoot ? (findMainRepoRoot(repoRoot) ?? repoRoot) : null;
339
+ const mainBinPath = mainRoot ? path.join(mainRoot, "node_modules", ".bin", binName) : "";
340
+ const mainLocalBin = Boolean(mainBinPath && existsSync(mainBinPath));
341
+
342
+ return {
343
+ onPath,
344
+ localBin,
345
+ mainLocalBin,
346
+ anyAvailable: onPath || localBin || mainLocalBin,
347
+ };
348
+ }
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env sh
2
2
 
3
+ _ff_common_dir="$(git rev-parse --git-common-dir 2>/dev/null || true)"
3
4
  if [ -x "./node_modules/.bin/featflow" ]; then
4
5
  ./node_modules/.bin/featflow cleanup --post-merge || true
6
+ elif [ -n "$_ff_common_dir" ] && [ -x "$_ff_common_dir/../node_modules/.bin/featflow" ]; then
7
+ "$_ff_common_dir/../node_modules/.bin/featflow" cleanup --post-merge || true
5
8
  elif command -v featflow >/dev/null 2>&1; then
6
9
  featflow cleanup --post-merge || true
7
10
  fi
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env sh
2
2
  set -e
3
3
 
4
+ _ff_common_dir="$(git rev-parse --git-common-dir 2>/dev/null || true)"
4
5
  if [ -x "./node_modules/.bin/featflow" ]; then
5
6
  exec ./node_modules/.bin/featflow policy pre-commit
7
+ elif [ -n "$_ff_common_dir" ] && [ -x "$_ff_common_dir/../node_modules/.bin/featflow" ]; then
8
+ exec "$_ff_common_dir/../node_modules/.bin/featflow" policy pre-commit
6
9
  elif command -v featflow >/dev/null 2>&1; then
7
10
  exec featflow policy pre-commit
8
11
  else
9
12
  echo "featflow: CLI not found in ./node_modules/.bin or PATH; skipping pre-commit check." >&2
10
- echo "Install featflow or set FEATFLOW_BOOTSTRAP=1 to silence this notice." >&2
13
+ echo "Install with \`npm install -g @danielstyle/featflow\` or set FEATFLOW_BOOTSTRAP=1 to silence this notice." >&2
11
14
  fi
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env sh
2
2
  set -e
3
3
 
4
+ _ff_common_dir="$(git rev-parse --git-common-dir 2>/dev/null || true)"
4
5
  if [ -x "./node_modules/.bin/featflow" ]; then
5
6
  exec ./node_modules/.bin/featflow policy pre-push
7
+ elif [ -n "$_ff_common_dir" ] && [ -x "$_ff_common_dir/../node_modules/.bin/featflow" ]; then
8
+ exec "$_ff_common_dir/../node_modules/.bin/featflow" policy pre-push
6
9
  elif command -v featflow >/dev/null 2>&1; then
7
10
  exec featflow policy pre-push
8
11
  else
@@ -15,7 +15,7 @@
15
15
 
16
16
  ### Feature Planning Workflow
17
17
 
18
- - For substantial features, cross-module changes, long-running tasks, or multi-phase initiatives, read and follow the `featflow` skill (`.agents/skills/featflow/SKILL.md` or your globally installed skill).
18
+ - For substantial features, cross-module changes, long-running tasks, or multi-phase initiatives, read and follow the `featflow` skill (installed globally via `featflow skills install` or in `.agents/skills/featflow/SKILL.md`).
19
19
  - Draft complete `Feature Brief` and `Plan Details` (including `Pre-Implementation Approval`) via `featflow new <short-kebab-title>` (or `featflow new <short-kebab-title> --local` when feature records are not tracked in Git) before editing product code, and verify with `featflow plan-check`.
20
20
  - Move completed records to `done/` before committing and running `featflow finish <branch>`.
21
21
  - Tiny one-off edits do not require a feature record, but still follow the Universal Pre-Implementation Gate and dedicated task worktree flow.