@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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +206 -2
  3. package/README.zh-CN.md +163 -0
  4. package/bin/featflow.mjs +113 -0
  5. package/package.json +62 -4
  6. package/skills/featflow/SKILL.md +127 -0
  7. package/skills/featflow-issues/SKILL.md +104 -0
  8. package/skills/featflow-regression/SKILL.md +63 -0
  9. package/src/agent-docs.mjs +143 -0
  10. package/src/changed-files.mjs +204 -0
  11. package/src/commands/cleanup.mjs +221 -0
  12. package/src/commands/codegraph.mjs +110 -0
  13. package/src/commands/doctor.mjs +265 -0
  14. package/src/commands/finish.mjs +249 -0
  15. package/src/commands/hook-cmd.mjs +78 -0
  16. package/src/commands/hooks-cmd.mjs +238 -0
  17. package/src/commands/init.mjs +382 -0
  18. package/src/commands/issue.mjs +434 -0
  19. package/src/commands/new.mjs +311 -0
  20. package/src/commands/plan-check.mjs +75 -0
  21. package/src/commands/policy-cmd.mjs +51 -0
  22. package/src/commands/pr-cleanup.mjs +194 -0
  23. package/src/commands/regression.mjs +206 -0
  24. package/src/commands/setup.mjs +343 -0
  25. package/src/commands/size-check.mjs +137 -0
  26. package/src/commands/status.mjs +100 -0
  27. package/src/commands/sync.mjs +407 -0
  28. package/src/commands/verify.mjs +206 -0
  29. package/src/commands/worktree.mjs +205 -0
  30. package/src/config.mjs +295 -0
  31. package/src/detect.mjs +314 -0
  32. package/src/git.mjs +331 -0
  33. package/src/hook-adapters.mjs +218 -0
  34. package/src/hooks-core.mjs +420 -0
  35. package/src/index.mjs +13 -0
  36. package/src/init-args.mjs +282 -0
  37. package/src/init-hooks.mjs +312 -0
  38. package/src/init-prompts.mjs +191 -0
  39. package/src/issues-helpers.mjs +463 -0
  40. package/src/issues.mjs +521 -0
  41. package/src/plan.mjs +202 -0
  42. package/src/policy.mjs +143 -0
  43. package/src/regression.mjs +338 -0
  44. package/src/size-check.mjs +203 -0
  45. package/src/tui-select.mjs +378 -0
  46. package/templates/adapters/antigravity/hooks.json +42 -0
  47. package/templates/adapters/claude-code/settings.json +46 -0
  48. package/templates/adapters/codex/config.toml +19 -0
  49. package/templates/adapters/cursor/hooks.json +27 -0
  50. package/templates/agents/codex/codebase-locator.toml +28 -0
  51. package/templates/agents/codex/implementation-scout.toml +28 -0
  52. package/templates/agents/codex/regression-guard-planner.toml +20 -0
  53. package/templates/features/README.md +56 -0
  54. package/templates/features/_program_template.md +79 -0
  55. package/templates/features/_template.md +120 -0
  56. package/templates/features/current-feature.md +18 -0
  57. package/templates/githooks/post-merge +7 -0
  58. package/templates/githooks/pre-commit +11 -0
  59. package/templates/githooks/pre-push +10 -0
  60. package/templates/regression/regression-ledger.yml +23 -0
  61. package/templates/snippets/AGENTS-workflow.md +21 -0
@@ -0,0 +1,434 @@
1
+ import { loadConfig, resolveIssuesConfig } from "../config.mjs";
2
+ import { fail, gitConfigGet } from "../git.mjs";
3
+ import {
4
+ claimIssue,
5
+ createIssue,
6
+ listIssues,
7
+ parseIssueRef,
8
+ releaseIssue,
9
+ resolveAssetsConfig,
10
+ resolveGitHubRepoSlug,
11
+ reviewIssue,
12
+ syncIssueLabels,
13
+ viewIssue,
14
+ } from "../issues.mjs";
15
+
16
+ const usage = `
17
+ Usage:
18
+ featflow issue <subcommand> [options]
19
+
20
+ Optional GitHub Issues closed-loop CLI (file -> list -> view -> claim + worktree -> review -> release).
21
+ Requires GitHub CLI ("gh") only when invoking this command.
22
+
23
+ Subcommands:
24
+ create Create a prefixed GitHub Issue (supports --attach when issues.assetsRepo is set)
25
+ list List GitHub Issues for the repository (sorted by priority, unclaimed first)
26
+ view <ref> Inspect Issue details/comments and optionally download attached images (--download-images)
27
+ claim <ref> Atomically preflight worktree, check collision lock, claim Issue, and create worktree
28
+ review <ref> Move a verified fix to status:in-review and post a structured verification comment
29
+ release <ref> Release a claimed Issue back to the pool (optionally add status:blocked)
30
+ labels:sync Idempotently create/update the 7 standard workflow labels on the repository
31
+
32
+ Common Options:
33
+ --repo <owner/repo> Override GitHub repository slug (defaults to issues.repo or git remote)
34
+ --dry-run Preview actions without mutating GitHub or creating worktrees
35
+ --json Output machine-readable JSON
36
+ -h, --help Show this help
37
+
38
+ Examples:
39
+ featflow issue create --type fix --scope auth --title "blank screen after callback" --body "..." --priority p1 --agent-ready
40
+ featflow issue list --unassigned --json
41
+ featflow issue view 12 --download-images --json
42
+ featflow issue claim 12 --json
43
+ featflow issue review 12 --commit a1b2c3d --summary "Fixed OAuth redirect state" --checks "npm test"
44
+ featflow issue release 12 --blocked --reason "Waiting on backend contract"
45
+ featflow issue labels:sync
46
+ `.trim();
47
+
48
+ function parseArgs(argv) {
49
+ const options = {
50
+ subcommand: "",
51
+ positionals: [],
52
+ repo: "",
53
+ type: "",
54
+ scope: "",
55
+ title: "",
56
+ body: "",
57
+ bodyFile: "",
58
+ priority: "",
59
+ labels: [],
60
+ attaches: [],
61
+ imageUrls: [],
62
+ assetsRepo: "",
63
+ assetsBranch: "",
64
+ assetsPrefix: "",
65
+ agentReady: false,
66
+ unassigned: false,
67
+ mine: false,
68
+ state: "open",
69
+ limit: 30,
70
+ downloadImages: false,
71
+ outDir: "",
72
+ branch: "",
73
+ worktreePath: "",
74
+ base: "",
75
+ noWorktree: false,
76
+ skipPostCreate: false,
77
+ force: false,
78
+ summary: "",
79
+ commit: "",
80
+ pr: "",
81
+ checks: "",
82
+ risks: "",
83
+ reason: "",
84
+ blocked: false,
85
+ dryRun: false,
86
+ json: false,
87
+ };
88
+
89
+ const boolFlags = {
90
+ "--agent-ready": "agentReady",
91
+ "--unassigned": "unassigned",
92
+ "--mine": "mine",
93
+ "--download-images": "downloadImages",
94
+ "--no-worktree": "noWorktree",
95
+ "--skip-post-create": "skipPostCreate",
96
+ "--force": "force",
97
+ "--blocked": "blocked",
98
+ "--dry-run": "dryRun",
99
+ "--json": "json",
100
+ };
101
+
102
+ const multiFlags = {
103
+ "--label": "labels",
104
+ "--attach": "attaches",
105
+ "--image-url": "imageUrls",
106
+ };
107
+
108
+ const singleFlags = {
109
+ "--repo": "repo",
110
+ "--type": "type",
111
+ "--scope": "scope",
112
+ "--title": "title",
113
+ "--body": "body",
114
+ "--body-file": "bodyFile",
115
+ "--priority": "priority",
116
+ "--assets-repo": "assetsRepo",
117
+ "--assets-branch": "assetsBranch",
118
+ "--assets-prefix": "assetsPrefix",
119
+ "--state": "state",
120
+ "--limit": "limit",
121
+ "--out-dir": "outDir",
122
+ "--branch": "branch",
123
+ "--path": "worktreePath",
124
+ "--base": "base",
125
+ "--summary": "summary",
126
+ "--commit": "commit",
127
+ "--pr": "pr",
128
+ "--checks": "checks",
129
+ "--risks": "risks",
130
+ "--reason": "reason",
131
+ };
132
+
133
+ for (let i = 0; i < argv.length; i += 1) {
134
+ const arg = argv[i];
135
+ if (arg === "-h" || arg === "--help") {
136
+ console.log(usage);
137
+ process.exit(0);
138
+ }
139
+ if (boolFlags[arg]) {
140
+ options[boolFlags[arg]] = true;
141
+ continue;
142
+ }
143
+
144
+ const eqIdx = arg.indexOf("=");
145
+ const flagName = eqIdx === -1 ? arg : arg.slice(0, eqIdx);
146
+ const hasInline = eqIdx !== -1;
147
+
148
+ if (multiFlags[flagName]) {
149
+ const value = hasInline ? arg.slice(eqIdx + 1) : (argv[++i] ?? "");
150
+ if (!value) {
151
+ fail(`Missing value for ${flagName}.`, usage);
152
+ }
153
+ options[multiFlags[flagName]].push(value);
154
+ continue;
155
+ }
156
+ if (singleFlags[flagName]) {
157
+ const value = hasInline ? arg.slice(eqIdx + 1) : (argv[++i] ?? "");
158
+ if (value === "" && flagName !== "--body") {
159
+ fail(`Missing value for ${flagName}.`, usage);
160
+ }
161
+ options[singleFlags[flagName]] = flagName === "--limit" ? Number(value) : value;
162
+ continue;
163
+ }
164
+ if (arg.startsWith("-")) {
165
+ fail(`Unknown option for issue: ${arg}`, usage);
166
+ }
167
+ if (!options.subcommand) {
168
+ options.subcommand = arg;
169
+ } else {
170
+ options.positionals.push(arg);
171
+ }
172
+ }
173
+
174
+ return options;
175
+ }
176
+
177
+ export async function runIssue(argv) {
178
+ const options = parseArgs(argv);
179
+ if (!options.subcommand) {
180
+ console.log(usage);
181
+ return;
182
+ }
183
+
184
+ const { config, repoRoot } = loadConfig(process.cwd());
185
+ const issuesConfig = resolveIssuesConfig(config);
186
+ const assetsConfig = resolveAssetsConfig(issuesConfig, {
187
+ assetsRepo: options.assetsRepo,
188
+ assetsBranch: options.assetsBranch,
189
+ assetsPrefix: options.assetsPrefix,
190
+ });
191
+
192
+ const sub = options.subcommand === "labels-sync" ? "labels:sync" : options.subcommand;
193
+
194
+ try {
195
+ if (sub === "create") {
196
+ const repoInfo = resolveGitHubRepoSlug(repoRoot, config, options.repo);
197
+ const result = createIssue({
198
+ repoSlug: repoInfo.slug,
199
+ repoName: repoInfo.name,
200
+ type: options.type,
201
+ scope: options.scope,
202
+ title: options.title,
203
+ body: options.body,
204
+ bodyFile: options.bodyFile,
205
+ priority: options.priority,
206
+ agentReady: options.agentReady,
207
+ labels: options.labels,
208
+ attaches: options.attaches,
209
+ imageUrls: options.imageUrls,
210
+ assetsConfig,
211
+ issuesConfig,
212
+ validTypes: config.prefixes,
213
+ dryRun: options.dryRun,
214
+ cwd: repoRoot,
215
+ });
216
+
217
+ if (options.json) {
218
+ console.log(JSON.stringify(result, null, 2));
219
+ return;
220
+ }
221
+ if (options.dryRun) {
222
+ console.log(`[dry-run] Would create issue in ${result.repoSlug}:`);
223
+ console.log(` Title: ${result.title}`);
224
+ console.log(` Labels: ${result.labels.join(", ") || "(none)"}`);
225
+ if (result.uploadedAttachments.length > 0) {
226
+ console.log(` Images: ${result.uploadedAttachments.map((u) => u.url).join(", ")}`);
227
+ }
228
+ return;
229
+ }
230
+ console.log(`Created ${result.ref ?? result.repoSlug}: ${result.url}`);
231
+ if (result.uploadedAttachments.length > 0 && assetsConfig.repo) {
232
+ console.log(`Uploaded ${result.uploadedAttachments.length} screenshot(s) to ${assetsConfig.repo}`);
233
+ }
234
+ return;
235
+ }
236
+
237
+ if (sub === "list") {
238
+ const repoInfo = resolveGitHubRepoSlug(repoRoot, config, options.repo);
239
+ const issues = listIssues({
240
+ repoSlug: repoInfo.slug,
241
+ repoName: repoInfo.name,
242
+ state: options.state,
243
+ limit: options.limit,
244
+ labels: options.labels,
245
+ mine: options.mine,
246
+ unassigned: options.unassigned,
247
+ issuesConfig,
248
+ cwd: repoRoot,
249
+ });
250
+
251
+ if (options.json) {
252
+ console.log(JSON.stringify({ count: issues.length, repo: repoInfo.name, repoSlug: repoInfo.slug, issues }, null, 2));
253
+ return;
254
+ }
255
+ if (issues.length === 0) {
256
+ console.log("No matching GitHub Issues found.");
257
+ return;
258
+ }
259
+ console.log(`GitHub Issues (${issues.length}):`);
260
+ for (const item of issues) {
261
+ const claimTag = item.claimed ? `[claimed:${item.assignees.join(",") || "in-progress"}]` : "[open]";
262
+ const labelsTag = item.labels.length > 0 ? ` (${item.labels.join(", ")})` : "";
263
+ console.log(` - ${item.ref.padEnd(22)} ${claimTag} ${item.title}${labelsTag}`);
264
+ }
265
+ return;
266
+ }
267
+
268
+ if (sub === "view") {
269
+ const rawRef = options.positionals[0];
270
+ const defaultSlug =
271
+ rawRef && (/^https?:\/\//i.test(rawRef) || rawRef.includes("/"))
272
+ ? ""
273
+ : resolveGitHubRepoSlug(repoRoot, config, options.repo).slug;
274
+ const target = parseIssueRef(rawRef, defaultSlug);
275
+ const developer =
276
+ config.mode === "developer-branch" ? gitConfigGet(config.developerBranchConfigKey, repoRoot) : "";
277
+
278
+ const payload = viewIssue({
279
+ repoSlug: target.repoSlug,
280
+ repoName: target.repoName,
281
+ number: target.number,
282
+ ref: target.ref,
283
+ assetsConfig,
284
+ downloadImages: options.downloadImages,
285
+ outDir: options.outDir,
286
+ issuesConfig,
287
+ branchMode: config.mode,
288
+ developer,
289
+ cwd: repoRoot,
290
+ });
291
+
292
+ if (options.json) {
293
+ console.log(JSON.stringify(payload, null, 2));
294
+ return;
295
+ }
296
+ console.log(`${payload.ref}: ${payload.title}`);
297
+ console.log(`URL: ${payload.url}`);
298
+ console.log(
299
+ `State: ${payload.state} | Labels: ${payload.labels.join(", ") || "(none)"} | Assignees: ${payload.assignees.join(", ") || "(unassigned)"}`,
300
+ );
301
+ console.log(`Suggested branch: ${payload.suggestedBranch}`);
302
+ console.log("");
303
+ console.log(payload.body);
304
+ if (payload.downloadedImages.length > 0) {
305
+ console.log("");
306
+ console.log("Downloaded original screenshots:");
307
+ for (const img of payload.downloadedImages) {
308
+ console.log(` - ${img.localPath}`);
309
+ }
310
+ }
311
+ return;
312
+ }
313
+
314
+ if (sub === "claim") {
315
+ const rawRef = options.positionals[0];
316
+ const defaultSlug =
317
+ rawRef && (/^https?:\/\//i.test(rawRef) || rawRef.includes("/"))
318
+ ? ""
319
+ : resolveGitHubRepoSlug(repoRoot, config, options.repo).slug;
320
+ const target = parseIssueRef(rawRef, defaultSlug);
321
+
322
+ const payload = claimIssue({
323
+ repoRoot,
324
+ config,
325
+ repoSlug: target.repoSlug,
326
+ repoName: target.repoName,
327
+ number: target.number,
328
+ ref: target.ref,
329
+ branch: options.branch,
330
+ worktreePath: options.worktreePath,
331
+ base: options.base,
332
+ noWorktree: options.noWorktree,
333
+ skipPostCreate: options.skipPostCreate,
334
+ force: options.force,
335
+ dryRun: options.dryRun,
336
+ captureOutput: options.json,
337
+ });
338
+
339
+ if (options.json) {
340
+ console.log(JSON.stringify(payload, null, 2));
341
+ return;
342
+ }
343
+ console.log(
344
+ `${options.dryRun ? "[dry-run] Would claim" : "Claimed"} ${payload.ref} as @${payload.claimedBy} (${issuesConfig.inProgressLabel}).`,
345
+ );
346
+ if (payload.worktree) {
347
+ console.log(` - [${payload.worktree.branch}] -> ${payload.worktree.worktreePath}`);
348
+ }
349
+ return;
350
+ }
351
+
352
+ if (sub === "review") {
353
+ const rawRef = options.positionals[0];
354
+ const defaultSlug =
355
+ rawRef && (/^https?:\/\//i.test(rawRef) || rawRef.includes("/"))
356
+ ? ""
357
+ : resolveGitHubRepoSlug(repoRoot, config, options.repo).slug;
358
+ const target = parseIssueRef(rawRef, defaultSlug);
359
+
360
+ const payload = reviewIssue({
361
+ repoSlug: target.repoSlug,
362
+ repoName: target.repoName,
363
+ number: target.number,
364
+ ref: target.ref,
365
+ summary: options.summary,
366
+ commit: options.commit,
367
+ pr: options.pr,
368
+ checks: options.checks,
369
+ risks: options.risks,
370
+ integrationBranch: config.integrationBranch || config.baseBranch || "main",
371
+ issuesConfig,
372
+ dryRun: options.dryRun,
373
+ cwd: repoRoot,
374
+ });
375
+
376
+ if (options.json) {
377
+ console.log(JSON.stringify(payload, null, 2));
378
+ return;
379
+ }
380
+ console.log(`Moved ${payload.ref} to ${payload.status} (issue left open for PR/manual acceptance).`);
381
+ return;
382
+ }
383
+
384
+ if (sub === "release") {
385
+ const rawRef = options.positionals[0];
386
+ const defaultSlug =
387
+ rawRef && (/^https?:\/\//i.test(rawRef) || rawRef.includes("/"))
388
+ ? ""
389
+ : resolveGitHubRepoSlug(repoRoot, config, options.repo).slug;
390
+ const target = parseIssueRef(rawRef, defaultSlug);
391
+
392
+ const payload = releaseIssue({
393
+ repoSlug: target.repoSlug,
394
+ repoName: target.repoName,
395
+ number: target.number,
396
+ ref: target.ref,
397
+ blocked: options.blocked,
398
+ reason: options.reason,
399
+ issuesConfig,
400
+ dryRun: options.dryRun,
401
+ cwd: repoRoot,
402
+ });
403
+
404
+ if (options.json) {
405
+ console.log(JSON.stringify(payload, null, 2));
406
+ return;
407
+ }
408
+ console.log(`Released ${payload.ref}${payload.blocked ? ` (marked ${issuesConfig.blockedLabel})` : ""}.`);
409
+ return;
410
+ }
411
+
412
+ if (sub === "labels:sync") {
413
+ const repoInfo = resolveGitHubRepoSlug(repoRoot, config, options.repo);
414
+ const entry = syncIssueLabels({
415
+ repoSlug: repoInfo.slug,
416
+ repoName: repoInfo.name,
417
+ issuesConfig,
418
+ dryRun: options.dryRun,
419
+ cwd: repoRoot,
420
+ });
421
+
422
+ if (options.json) {
423
+ console.log(JSON.stringify({ dryRun: options.dryRun, ...entry }, null, 2));
424
+ return;
425
+ }
426
+ console.log(`${options.dryRun ? "[dry-run] " : ""}Synced ${entry.labels.length} workflow labels on ${entry.repoSlug}`);
427
+ return;
428
+ }
429
+
430
+ fail(`Unknown issue subcommand "${options.subcommand}".`, usage);
431
+ } catch (error) {
432
+ fail(error instanceof Error ? error.message : String(error));
433
+ }
434
+ }