@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/README.md +69 -24
- package/README.zh-CN.md +112 -23
- package/bin/featflow.mjs +7 -0
- package/package.json +3 -2
- package/skills/featflow/SKILL.md +2 -1
- package/src/commands/codegraph.mjs +2 -4
- package/src/commands/doctor.mjs +77 -39
- package/src/commands/finish.mjs +35 -3
- package/src/commands/hooks-cmd.mjs +9 -0
- package/src/commands/init.mjs +113 -18
- package/src/commands/policy-cmd.mjs +6 -2
- package/src/commands/skills.mjs +181 -0
- package/src/commands/status.mjs +17 -0
- package/src/commands/sync-dev.mjs +400 -0
- package/src/commands/sync.mjs +19 -5
- package/src/commands/worktree.mjs +38 -2
- package/src/config.mjs +34 -0
- package/src/hooks-core.mjs +2 -2
- package/src/index.mjs +1 -0
- package/src/init-args.mjs +14 -2
- package/src/init-prompts.mjs +3 -3
- package/src/skills-manager.mjs +348 -0
- package/templates/githooks/post-merge +3 -0
- package/templates/githooks/pre-commit +4 -1
- package/templates/githooks/pre-push +3 -0
- package/templates/snippets/AGENTS-workflow.md +1 -1
package/src/commands/status.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "../git.mjs";
|
|
12
12
|
import { listFeatureFiles } from "../plan.mjs";
|
|
13
13
|
import { setupInstructions } from "../policy.mjs";
|
|
14
|
+
import { countCommitsBehind } from "./sync-dev.mjs";
|
|
14
15
|
|
|
15
16
|
const usage = `
|
|
16
17
|
Usage:
|
|
@@ -80,6 +81,22 @@ export async function runStatus(argv) {
|
|
|
80
81
|
}
|
|
81
82
|
const devWt = findWorktreeForBranch(worktrees, devBranch);
|
|
82
83
|
console.log(`Developer worktree: ${devWt?.path ?? "(not checked out)"}`);
|
|
84
|
+
const integrationRef =
|
|
85
|
+
hasRemote && remoteTrackingBranchExists(config.remote, config.integrationBranch, repoRoot)
|
|
86
|
+
? `${config.remote}/${config.integrationBranch}`
|
|
87
|
+
: localBranchExists(config.integrationBranch, repoRoot)
|
|
88
|
+
? config.integrationBranch
|
|
89
|
+
: "";
|
|
90
|
+
if (integrationRef && localBranchExists(devBranch, repoRoot)) {
|
|
91
|
+
const behind = countCommitsBehind(devBranch, integrationRef, repoRoot);
|
|
92
|
+
if (behind !== null) {
|
|
93
|
+
console.log(
|
|
94
|
+
behind > 0
|
|
95
|
+
? `Sync with ${integrationRef}: behind by ${String(behind)} commit(s) (run \`featflow sync-dev\`)`
|
|
96
|
+
: `Sync with ${integrationRef}: up to date`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
console.log(`Worktrees (${worktrees.length}):`);
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { loadConfig } from "../config.mjs";
|
|
7
|
+
import {
|
|
8
|
+
ensureCleanWorktree,
|
|
9
|
+
fail,
|
|
10
|
+
findWorktreeForBranch,
|
|
11
|
+
formatCommand,
|
|
12
|
+
gitConfigGet,
|
|
13
|
+
gitWorktrees,
|
|
14
|
+
isAncestor,
|
|
15
|
+
localBranchExists,
|
|
16
|
+
remoteExists,
|
|
17
|
+
remoteTrackingBranchExists,
|
|
18
|
+
runReadSoft,
|
|
19
|
+
runWrite,
|
|
20
|
+
statusShort,
|
|
21
|
+
} from "../git.mjs";
|
|
22
|
+
import { setupInstructions } from "../policy.mjs";
|
|
23
|
+
|
|
24
|
+
const usage = `
|
|
25
|
+
Usage:
|
|
26
|
+
featflow sync-dev [options]
|
|
27
|
+
|
|
28
|
+
Syncs the shared integration branch (for example origin/dev) back into your
|
|
29
|
+
personal developer branch in developer-branch mode.
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
--developer <branch> Override configured developer branch.
|
|
33
|
+
--remote <name> Remote to fetch/push. Defaults to config.remote.
|
|
34
|
+
--no-push Merge locally without pushing the developer branch.
|
|
35
|
+
--abort-on-conflict Automatically run "git merge --abort" if conflicts occur.
|
|
36
|
+
--dry-run Print mutating commands without executing them.
|
|
37
|
+
-h, --help Show this help.
|
|
38
|
+
`.trim();
|
|
39
|
+
|
|
40
|
+
function parseArgs(argv) {
|
|
41
|
+
const options = {
|
|
42
|
+
abortOnConflict: false,
|
|
43
|
+
developer: "",
|
|
44
|
+
dryRun: false,
|
|
45
|
+
noPush: false,
|
|
46
|
+
remote: "",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
50
|
+
const arg = argv[i];
|
|
51
|
+
if (arg === "-h" || arg === "--help") {
|
|
52
|
+
console.log(usage);
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
if (arg === "--dry-run") {
|
|
56
|
+
options.dryRun = true;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (arg === "--no-push") {
|
|
60
|
+
options.noPush = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (arg === "--abort-on-conflict") {
|
|
64
|
+
options.abortOnConflict = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (arg === "--developer" || arg === "--remote") {
|
|
68
|
+
const value = argv[++i] ?? "";
|
|
69
|
+
if (!value) {
|
|
70
|
+
fail(`Missing value for ${arg}.`, usage);
|
|
71
|
+
}
|
|
72
|
+
options[arg.slice(2)] = value;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (arg.startsWith("--developer=") || arg.startsWith("--remote=")) {
|
|
76
|
+
const idx = arg.indexOf("=");
|
|
77
|
+
const key = arg.slice(2, idx);
|
|
78
|
+
const value = arg.slice(idx + 1);
|
|
79
|
+
if (!value) {
|
|
80
|
+
fail(`Missing value for --${key}.`, usage);
|
|
81
|
+
}
|
|
82
|
+
options[key] = value;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
fail(`Unknown option: ${arg}`, usage);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return options;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function runGitAction(args, cwd, { dryRun = false, silent = false } = {}) {
|
|
92
|
+
if (dryRun) {
|
|
93
|
+
if (!silent) {
|
|
94
|
+
runWrite("git", args, cwd, { dryRun: true });
|
|
95
|
+
}
|
|
96
|
+
return { status: 0, stdout: "", stderr: "" };
|
|
97
|
+
}
|
|
98
|
+
const result = spawnSync("git", args, {
|
|
99
|
+
cwd,
|
|
100
|
+
encoding: "utf8",
|
|
101
|
+
stdio: silent ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
102
|
+
});
|
|
103
|
+
if (result.error) {
|
|
104
|
+
throw new Error(`${formatCommand("git", args)} failed: ${result.error.message}`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
status: result.status ?? 1,
|
|
108
|
+
stdout: (result.stdout ?? "").trim(),
|
|
109
|
+
stderr: (result.stderr ?? "").trim(),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function listConflictedFiles(cwd) {
|
|
114
|
+
const res = runReadSoft("git", ["diff", "--name-only", "--diff-filter=U"], cwd);
|
|
115
|
+
if (res.status !== 0 || !res.stdout) {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
return res.stdout
|
|
119
|
+
.split(/\r?\n/)
|
|
120
|
+
.map((line) => line.trim())
|
|
121
|
+
.filter(Boolean);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function countCommitsBehind(targetRef, baseRef, cwd) {
|
|
125
|
+
const res = runReadSoft("git", ["rev-list", "--count", `${targetRef}..${baseRef}`], cwd);
|
|
126
|
+
if (res.status !== 0 || !res.stdout) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const count = Number(res.stdout);
|
|
130
|
+
return Number.isFinite(count) ? count : null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createTempDeveloperWorktree(repoRoot, devBranch) {
|
|
134
|
+
const tempParent = mkdtempSync(path.join(tmpdir(), "featflow-sync-dev-"));
|
|
135
|
+
const tempWorktree = path.join(tempParent, "wt");
|
|
136
|
+
const addRes = runGitAction(["worktree", "add", tempWorktree, devBranch], repoRoot, { silent: true });
|
|
137
|
+
if (addRes.status !== 0) {
|
|
138
|
+
rmSync(tempParent, { force: true, recursive: true });
|
|
139
|
+
throw new Error(
|
|
140
|
+
`Failed to prepare temporary worktree for "${devBranch}"${addRes.stderr ? `:\n${addRes.stderr}` : "."}`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
path: tempWorktree,
|
|
145
|
+
cleanup() {
|
|
146
|
+
runGitAction(["worktree", "remove", "--force", tempWorktree], repoRoot, { silent: true });
|
|
147
|
+
rmSync(tempParent, { force: true, recursive: true });
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Safely syncs `integrationBranch` (e.g. `origin/dev`) into the configured
|
|
154
|
+
* personal developer branch (e.g. `daniel`).
|
|
155
|
+
*/
|
|
156
|
+
export function syncDeveloperBranchWithIntegration(repoRoot, config, options = {}) {
|
|
157
|
+
const silent = Boolean(options.silent);
|
|
158
|
+
const dryRun = Boolean(options.dryRun);
|
|
159
|
+
const log = (msg) => {
|
|
160
|
+
if (!silent) {
|
|
161
|
+
console.log(msg);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const warn = (msg) => {
|
|
165
|
+
if (!silent) {
|
|
166
|
+
console.warn(msg);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (config.mode !== "developer-branch") {
|
|
171
|
+
if (options.strictMode) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`featflow sync-dev is only available in developer-branch mode (current mode: "${config.mode}").`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return { status: "skipped", reason: "not-developer-branch-mode" };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const integrationBranch = config.integrationBranch || config.baseBranch || "dev";
|
|
180
|
+
const remote = options.remote || config.remote || "origin";
|
|
181
|
+
const devBranch = options.developer || gitConfigGet(config.developerBranchConfigKey, repoRoot);
|
|
182
|
+
|
|
183
|
+
if (!devBranch) {
|
|
184
|
+
throw new Error(setupInstructions(config));
|
|
185
|
+
}
|
|
186
|
+
if (devBranch === integrationBranch) {
|
|
187
|
+
return { status: "skipped", reason: "same-branch", devBranch, integrationRef: integrationBranch };
|
|
188
|
+
}
|
|
189
|
+
if (!localBranchExists(devBranch, repoRoot)) {
|
|
190
|
+
throw new Error(`Local developer branch "${devBranch}" does not exist.`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const existingDevWorktree =
|
|
194
|
+
options.targetWorktreePath || findWorktreeForBranch(gitWorktrees(repoRoot), devBranch)?.path || "";
|
|
195
|
+
const gitCwd = existingDevWorktree || repoRoot;
|
|
196
|
+
|
|
197
|
+
if (existingDevWorktree && !options.dryRunMissing) {
|
|
198
|
+
const dirty = statusShort(existingDevWorktree);
|
|
199
|
+
if (dirty) {
|
|
200
|
+
if (options.skipIfDirty) {
|
|
201
|
+
warn(
|
|
202
|
+
`Note: developer worktree ${existingDevWorktree} has uncommitted changes; skipping auto-sync with ${remote}/${integrationBranch}.`,
|
|
203
|
+
);
|
|
204
|
+
return { status: "skipped", reason: "dirty-worktree", devBranch };
|
|
205
|
+
}
|
|
206
|
+
ensureCleanWorktree(existingDevWorktree, "developer");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const hasRemote = remoteExists(remote, gitCwd);
|
|
211
|
+
const shouldFetch = hasRemote && options.fetch !== false;
|
|
212
|
+
|
|
213
|
+
if (shouldFetch) {
|
|
214
|
+
const fetchInt = runGitAction(["fetch", remote, integrationBranch], gitCwd, {
|
|
215
|
+
dryRun,
|
|
216
|
+
silent: dryRun ? silent : true,
|
|
217
|
+
});
|
|
218
|
+
if (fetchInt.status !== 0) {
|
|
219
|
+
if (options.bestEffortFetch) {
|
|
220
|
+
warn(`Warning: could not fetch ${remote}/${integrationBranch}; continuing with local refs.`);
|
|
221
|
+
} else {
|
|
222
|
+
throw new Error(
|
|
223
|
+
`Failed to fetch ${remote}/${integrationBranch}${fetchInt.stderr ? `:\n${fetchInt.stderr}` : "."}`,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const fetchDev = runGitAction(["fetch", remote, devBranch], gitCwd, {
|
|
229
|
+
dryRun,
|
|
230
|
+
silent: dryRun ? silent : true,
|
|
231
|
+
});
|
|
232
|
+
if (
|
|
233
|
+
!dryRun &&
|
|
234
|
+
fetchDev.status === 0 &&
|
|
235
|
+
remoteTrackingBranchExists(remote, devBranch, gitCwd) &&
|
|
236
|
+
!isAncestor(`${remote}/${devBranch}`, devBranch, gitCwd)
|
|
237
|
+
) {
|
|
238
|
+
if (existingDevWorktree) {
|
|
239
|
+
const ffRes = runGitAction(["merge", "--ff-only", `${remote}/${devBranch}`], existingDevWorktree, {
|
|
240
|
+
dryRun,
|
|
241
|
+
silent,
|
|
242
|
+
});
|
|
243
|
+
if (ffRes.status !== 0) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`Local "${devBranch}" has diverged from "${remote}/${devBranch}". Reconcile "${devBranch}" with "${remote}/${devBranch}" before syncing ${integrationBranch}.`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
} else if (isAncestor(devBranch, `${remote}/${devBranch}`, gitCwd)) {
|
|
249
|
+
runGitAction(["branch", "-f", devBranch, `${remote}/${devBranch}`], gitCwd, { dryRun, silent });
|
|
250
|
+
} else {
|
|
251
|
+
throw new Error(
|
|
252
|
+
`Local "${devBranch}" has diverged from "${remote}/${devBranch}". Switch to "${devBranch}" and reconcile before syncing ${integrationBranch}.`,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
let integrationRef = "";
|
|
259
|
+
if (hasRemote && remoteTrackingBranchExists(remote, integrationBranch, gitCwd)) {
|
|
260
|
+
integrationRef = `${remote}/${integrationBranch}`;
|
|
261
|
+
} else if (!hasRemote && localBranchExists(integrationBranch, gitCwd)) {
|
|
262
|
+
integrationRef = integrationBranch;
|
|
263
|
+
} else if (dryRun && hasRemote) {
|
|
264
|
+
integrationRef = `${remote}/${integrationBranch}`;
|
|
265
|
+
} else {
|
|
266
|
+
if (options.skipIfMissingIntegration) {
|
|
267
|
+
return {
|
|
268
|
+
status: "skipped",
|
|
269
|
+
reason: "missing-integration-ref",
|
|
270
|
+
devBranch,
|
|
271
|
+
integrationRef: hasRemote ? `${remote}/${integrationBranch}` : integrationBranch,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Integration branch ref "${hasRemote ? `${remote}/${integrationBranch}` : integrationBranch}" was not found.`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!dryRun && isAncestor(integrationRef, devBranch, gitCwd)) {
|
|
280
|
+
return {
|
|
281
|
+
status: "up-to-date",
|
|
282
|
+
devBranch,
|
|
283
|
+
integrationRef,
|
|
284
|
+
commitsMerged: 0,
|
|
285
|
+
pushed: false,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const behindCount = dryRun ? null : countCommitsBehind(devBranch, integrationRef, gitCwd);
|
|
290
|
+
const countLabel = behindCount && behindCount > 0 ? ` (${String(behindCount)} new commit(s))` : "";
|
|
291
|
+
log(`Syncing developer branch "${devBranch}" with ${integrationRef}${countLabel}...`);
|
|
292
|
+
|
|
293
|
+
let tempWorktree = null;
|
|
294
|
+
try {
|
|
295
|
+
if (!existingDevWorktree && !dryRun && isAncestor(devBranch, integrationRef, gitCwd)) {
|
|
296
|
+
// Fast-forward directly without requiring a checked-out worktree on devBranch.
|
|
297
|
+
const ffBranchRes = runGitAction(["branch", "-f", devBranch, integrationRef], gitCwd, { silent });
|
|
298
|
+
if (ffBranchRes.status !== 0) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`Failed to fast-forward "${devBranch}" to ${integrationRef}${ffBranchRes.stderr ? `:\n${ffBranchRes.stderr}` : "."}`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
let mergeCwd = existingDevWorktree;
|
|
305
|
+
if (!mergeCwd) {
|
|
306
|
+
if (dryRun) {
|
|
307
|
+
mergeCwd = repoRoot;
|
|
308
|
+
} else {
|
|
309
|
+
tempWorktree = createTempDeveloperWorktree(repoRoot, devBranch);
|
|
310
|
+
mergeCwd = tempWorktree.path;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const mergeRes = runGitAction(["merge", "--no-edit", integrationRef], mergeCwd, {
|
|
315
|
+
dryRun,
|
|
316
|
+
silent,
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
if (mergeRes.status !== 0) {
|
|
320
|
+
const conflicts = listConflictedFiles(mergeCwd);
|
|
321
|
+
const conflictSummary =
|
|
322
|
+
conflicts.length > 0 ? `\nConflicted files:\n${conflicts.map((file) => ` - ${file}`).join("\n")}` : "";
|
|
323
|
+
|
|
324
|
+
if (options.abortOnConflict || tempWorktree) {
|
|
325
|
+
runGitAction(["merge", "--abort"], mergeCwd, { silent: true });
|
|
326
|
+
const nextStep = tempWorktree
|
|
327
|
+
? `Switch to "${devBranch}" and resolve conflicts explicitly with: git switch ${devBranch} && featflow sync-dev`
|
|
328
|
+
: "Resolve conflicts explicitly with: featflow sync-dev\nOr skip auto-sync once with: --no-sync-dev";
|
|
329
|
+
throw new Error(
|
|
330
|
+
`Auto-sync of "${devBranch}" with ${integrationRef} hit merge conflicts and was cleanly aborted (git merge --abort).${conflictSummary}\n${nextStep}`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
throw new Error(
|
|
335
|
+
`Merge conflicts while syncing "${devBranch}" with ${integrationRef}.${conflictSummary}\nResolve conflicts in ${mergeCwd}, then run: git add <files> && git commit${hasRemote && options.push !== false ? ` && git push ${remote} ${devBranch}` : ""}\nOr abort with: git merge --abort`,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const shouldPush = hasRemote && options.push !== false;
|
|
341
|
+
if (shouldPush) {
|
|
342
|
+
const pushCwd = existingDevWorktree || tempWorktree?.path || repoRoot;
|
|
343
|
+
const pushRes = runGitAction(["push", remote, devBranch], pushCwd, {
|
|
344
|
+
dryRun,
|
|
345
|
+
silent,
|
|
346
|
+
});
|
|
347
|
+
if (pushRes.status !== 0) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
`Synced "${devBranch}" locally with ${integrationRef}, but failed to push to ${remote}/${devBranch}${pushRes.stderr ? `:\n${pushRes.stderr}` : "."}`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
status: "synced",
|
|
356
|
+
devBranch,
|
|
357
|
+
integrationRef,
|
|
358
|
+
commitsMerged: behindCount ?? 0,
|
|
359
|
+
pushed: shouldPush,
|
|
360
|
+
};
|
|
361
|
+
} finally {
|
|
362
|
+
if (tempWorktree) {
|
|
363
|
+
tempWorktree.cleanup();
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export async function runSyncDev(argv) {
|
|
369
|
+
const options = parseArgs(argv);
|
|
370
|
+
const { config, repoRoot } = loadConfig(process.cwd());
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
const result = syncDeveloperBranchWithIntegration(repoRoot, config, {
|
|
374
|
+
strictMode: true,
|
|
375
|
+
developer: options.developer,
|
|
376
|
+
remote: options.remote,
|
|
377
|
+
dryRun: options.dryRun,
|
|
378
|
+
push: !options.noPush,
|
|
379
|
+
abortOnConflict: options.abortOnConflict,
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
if (result.status === "up-to-date") {
|
|
383
|
+
console.log(`Developer branch "${result.devBranch}" is already up to date with ${result.integrationRef}.`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (result.status === "synced") {
|
|
388
|
+
const prefix = options.dryRun ? "Dry run complete" : "Synced";
|
|
389
|
+
const suffix = result.pushed
|
|
390
|
+
? ` and pushed to ${options.remote || config.remote}/${result.devBranch}`
|
|
391
|
+
: " (local only)";
|
|
392
|
+
console.log(`${prefix}: "${result.devBranch}" now includes ${result.integrationRef}${suffix}.`);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
console.log(`Skipped sync-dev (${result.reason ?? "no-op"}).`);
|
|
397
|
+
} catch (error) {
|
|
398
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
399
|
+
}
|
|
400
|
+
}
|
package/src/commands/sync.mjs
CHANGED
|
@@ -27,6 +27,7 @@ Options:
|
|
|
27
27
|
--check Verify managed files match the installed featflow version (exit 1 on drift).
|
|
28
28
|
--dry-run Print files that would be created or updated without writing.
|
|
29
29
|
--only <groups> Comma-separated subset: skill,issues-skill,regression-skill,templates,githooks,agent-docs.
|
|
30
|
+
--with-repo-skills Include repo-embedded .agents/skills/ files even if not present yet.
|
|
30
31
|
--with-issues-skill Include .agents/skills/featflow-issues/SKILL.md even if issues is not configured yet.
|
|
31
32
|
--skip-issues-skill Skip .agents/skills/featflow-issues/SKILL.md even if issues is configured.
|
|
32
33
|
--with-regression-skill Include .agents/skills/featflow-regression/SKILL.md.
|
|
@@ -44,6 +45,7 @@ function parseArgs(argv) {
|
|
|
44
45
|
check: false,
|
|
45
46
|
dryRun: false,
|
|
46
47
|
only: null,
|
|
48
|
+
withRepoSkills: false,
|
|
47
49
|
withIssuesSkill: false,
|
|
48
50
|
skipIssuesSkill: false,
|
|
49
51
|
withRegressionSkill: false,
|
|
@@ -69,6 +71,10 @@ function parseArgs(argv) {
|
|
|
69
71
|
options.dryRun = true;
|
|
70
72
|
continue;
|
|
71
73
|
}
|
|
74
|
+
if (arg === "--with-repo-skills") {
|
|
75
|
+
options.withRepoSkills = true;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
72
78
|
if (arg === "--with-issues-skill") {
|
|
73
79
|
options.withIssuesSkill = true;
|
|
74
80
|
continue;
|
|
@@ -143,23 +149,31 @@ function resolveGroups(options, repoRoot, config) {
|
|
|
143
149
|
const hasRepoSkill = existsSync(path.join(repoRoot, ".agents", "skills", "featflow", "SKILL.md"));
|
|
144
150
|
const hasIssuesSkill = existsSync(path.join(repoRoot, ".agents", "skills", "featflow-issues", "SKILL.md"));
|
|
145
151
|
const hasRegressionSkill = existsSync(path.join(repoRoot, ".agents", "skills", "featflow-regression", "SKILL.md"));
|
|
146
|
-
const hasRepoTemplates =
|
|
152
|
+
const hasRepoTemplates =
|
|
153
|
+
existsSync(path.join(repoRoot, config.featuresDir, "_template.md")) ||
|
|
154
|
+
existsSync(path.join(repoRoot, config.featuresDir, "README.md")) ||
|
|
155
|
+
existsSync(path.join(repoRoot, config.featuresDir, "_program_template.md"));
|
|
147
156
|
const hasGithooksDir = existsSync(path.join(repoRoot, ".githooks"));
|
|
148
157
|
const managedAgentDocs = findManagedAgentDocs(repoRoot);
|
|
149
|
-
const
|
|
158
|
+
const includeRepoSkills = options.withRepoSkills || hasRepoSkill;
|
|
150
159
|
|
|
151
160
|
const groups = new Set();
|
|
152
|
-
if (
|
|
161
|
+
if (includeRepoSkills) {
|
|
153
162
|
groups.add("skill");
|
|
163
|
+
}
|
|
164
|
+
if (hasRepoTemplates) {
|
|
154
165
|
groups.add("templates");
|
|
155
166
|
}
|
|
156
167
|
if (
|
|
157
168
|
!options.skipIssuesSkill &&
|
|
158
|
-
(options.withIssuesSkill || hasIssuesSkill || (
|
|
169
|
+
(options.withIssuesSkill || hasIssuesSkill || (includeRepoSkills && Boolean(config.issues)))
|
|
159
170
|
) {
|
|
160
171
|
groups.add("issues-skill");
|
|
161
172
|
}
|
|
162
|
-
if (
|
|
173
|
+
if (
|
|
174
|
+
!options.skipRegressionSkill &&
|
|
175
|
+
(options.withRegressionSkill || hasRegressionSkill || (includeRepoSkills && Boolean(config.regression)))
|
|
176
|
+
) {
|
|
163
177
|
groups.add("regression-skill");
|
|
164
178
|
}
|
|
165
179
|
if (!options.skipGithooks && (options.withGithooks || hasGithooksDir)) {
|
|
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync, mkdirSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
import { loadConfig, resolveWorktreeParent } from "../config.mjs";
|
|
5
|
+
import { loadConfig, resolveSyncIntegrationConfig, resolveWorktreeParent } from "../config.mjs";
|
|
6
6
|
import {
|
|
7
7
|
fail,
|
|
8
8
|
findWorktreeForBranch,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
validateTaskBranchName,
|
|
16
16
|
} from "../git.mjs";
|
|
17
17
|
import { setupInstructions } from "../policy.mjs";
|
|
18
|
+
import { syncDeveloperBranchWithIntegration } from "./sync-dev.mjs";
|
|
18
19
|
|
|
19
20
|
const usage = `
|
|
20
21
|
Usage:
|
|
@@ -22,11 +23,15 @@ Usage:
|
|
|
22
23
|
featflow worktree <branch> --path <worktree-path> --base <base>
|
|
23
24
|
|
|
24
25
|
Creates a dedicated Git worktree for a typed task branch and runs any
|
|
25
|
-
configured postWorktreeCreate commands.
|
|
26
|
+
configured postWorktreeCreate commands. In developer-branch mode, automatically
|
|
27
|
+
syncs the integration branch (e.g. origin/dev) into your developer branch first
|
|
28
|
+
when clean (disable via --no-sync-dev or syncIntegration.onWorktree=false).
|
|
26
29
|
|
|
27
30
|
Options:
|
|
28
31
|
--path <path> Worktree directory path. Defaults to <worktreeParent>/<sanitized-branch>.
|
|
29
32
|
--base <ref> Base ref for a new branch. Defaults to developer branch or baseBranch.
|
|
33
|
+
--no-sync-dev Skip syncing the integration branch into your developer branch before branching.
|
|
34
|
+
--no-push Do not push the developer branch after auto-syncing the integration branch.
|
|
30
35
|
--skip-post-create Skip running configured postWorktreeCreate commands.
|
|
31
36
|
--dry-run Print commands without executing them.
|
|
32
37
|
-h, --help Show this help.
|
|
@@ -38,6 +43,8 @@ function parseArgs(argv) {
|
|
|
38
43
|
path: "",
|
|
39
44
|
base: "",
|
|
40
45
|
baseProvided: false,
|
|
46
|
+
noPush: false,
|
|
47
|
+
noSyncDev: false,
|
|
41
48
|
skipPostCreate: false,
|
|
42
49
|
dryRun: false,
|
|
43
50
|
};
|
|
@@ -53,6 +60,14 @@ function parseArgs(argv) {
|
|
|
53
60
|
options.skipPostCreate = true;
|
|
54
61
|
continue;
|
|
55
62
|
}
|
|
63
|
+
if (arg === "--no-sync-dev") {
|
|
64
|
+
options.noSyncDev = true;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (arg === "--no-push") {
|
|
68
|
+
options.noPush = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
56
71
|
if (arg === "--dry-run") {
|
|
57
72
|
options.dryRun = true;
|
|
58
73
|
continue;
|
|
@@ -165,6 +180,27 @@ export function createTaskWorktree(repoRoot, config, options = {}, preflighted =
|
|
|
165
180
|
const plan = preflighted ?? preflightTaskWorktree(repoRoot, config, options);
|
|
166
181
|
const execWrite = options.captureOutput ? runCapturedWrite : runWrite;
|
|
167
182
|
|
|
183
|
+
const syncCfg = resolveSyncIntegrationConfig(config);
|
|
184
|
+
if (
|
|
185
|
+
config.mode === "developer-branch" &&
|
|
186
|
+
syncCfg.onWorktree &&
|
|
187
|
+
!options.baseProvided &&
|
|
188
|
+
!options.noSyncDev &&
|
|
189
|
+
!plan.branchExists
|
|
190
|
+
) {
|
|
191
|
+
syncDeveloperBranchWithIntegration(repoRoot, config, {
|
|
192
|
+
developer: plan.baseRef,
|
|
193
|
+
dryRun: Boolean(options.dryRun),
|
|
194
|
+
push: syncCfg.pushAfterSync && !options.noPush,
|
|
195
|
+
abortOnConflict: true,
|
|
196
|
+
skipIfDirty: true,
|
|
197
|
+
skipIfUncheckedOut: true,
|
|
198
|
+
skipIfMissingIntegration: true,
|
|
199
|
+
bestEffortFetch: true,
|
|
200
|
+
silent: Boolean(options.captureOutput),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
168
204
|
if (!options.dryRun) {
|
|
169
205
|
mkdirSync(path.dirname(plan.worktreePath), { recursive: true });
|
|
170
206
|
}
|
package/src/config.mjs
CHANGED
|
@@ -48,6 +48,12 @@ export const DEFAULT_REGRESSION_CONFIG = {
|
|
|
48
48
|
enforceInStopGate: false,
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
export const DEFAULT_SYNC_INTEGRATION_CONFIG = {
|
|
52
|
+
onWorktree: true,
|
|
53
|
+
onFinish: true,
|
|
54
|
+
pushAfterSync: true,
|
|
55
|
+
};
|
|
56
|
+
|
|
51
57
|
export const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
52
58
|
|
|
53
59
|
export function presetConfig(mode = "trunk") {
|
|
@@ -214,6 +220,33 @@ export function resolveRegressionConfig(config) {
|
|
|
214
220
|
return { ...DEFAULT_REGRESSION_CONFIG };
|
|
215
221
|
}
|
|
216
222
|
|
|
223
|
+
export function normalizeSyncIntegrationConfig(rawSync) {
|
|
224
|
+
if (rawSync === false) {
|
|
225
|
+
return { onWorktree: false, onFinish: false, pushAfterSync: false };
|
|
226
|
+
}
|
|
227
|
+
if (rawSync === true) {
|
|
228
|
+
return { ...DEFAULT_SYNC_INTEGRATION_CONFIG };
|
|
229
|
+
}
|
|
230
|
+
if (!isPlainObject(rawSync)) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
onWorktree: rawSync.onWorktree !== false,
|
|
235
|
+
onFinish: rawSync.onFinish !== false,
|
|
236
|
+
pushAfterSync: rawSync.pushAfterSync !== false,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function resolveSyncIntegrationConfig(config) {
|
|
241
|
+
if (config?.mode !== "developer-branch") {
|
|
242
|
+
return { onWorktree: false, onFinish: false, pushAfterSync: false };
|
|
243
|
+
}
|
|
244
|
+
if (config && isPlainObject(config.syncIntegration)) {
|
|
245
|
+
return normalizeSyncIntegrationConfig(config.syncIntegration);
|
|
246
|
+
}
|
|
247
|
+
return { ...DEFAULT_SYNC_INTEGRATION_CONFIG };
|
|
248
|
+
}
|
|
249
|
+
|
|
217
250
|
export function resolveWorktreeParent(repoRoot, config) {
|
|
218
251
|
const mainRoot = findMainRepoRoot(repoRoot) ?? repoRoot;
|
|
219
252
|
if (config.worktreeParent) {
|
|
@@ -263,6 +296,7 @@ export function loadConfig(startCwd = process.cwd()) {
|
|
|
263
296
|
issues: normalizeIssuesConfig(raw.issues),
|
|
264
297
|
fileSizeBudget: normalizeFileSizeBudget(raw.fileSizeBudget),
|
|
265
298
|
regression: normalizeRegressionConfig(raw.regression),
|
|
299
|
+
syncIntegration: normalizeSyncIntegrationConfig(raw.syncIntegration),
|
|
266
300
|
protectedBranches: Array.isArray(raw.protectedBranches)
|
|
267
301
|
? raw.protectedBranches.filter((item) => typeof item === "string" && item.trim().length > 0)
|
|
268
302
|
: base.protectedBranches,
|
package/src/hooks-core.mjs
CHANGED
|
@@ -278,7 +278,7 @@ export function evaluateUserPrompt(config, payload) {
|
|
|
278
278
|
|
|
279
279
|
if (/feature|plan|workflow|worktree|milestone|roadmap|refactor|implement|迁移|重构|计划|工作流|功能|实现/.test(lower)) {
|
|
280
280
|
reminders.push(
|
|
281
|
-
`For substantial or write-oriented work, follow the featflow skill
|
|
281
|
+
`For substantial or write-oriented work, follow the \`featflow\` skill: complete read-only discovery, present a concrete plan, wait for approval, and work in a dedicated worktree (\`featflow worktree\`).`,
|
|
282
282
|
);
|
|
283
283
|
}
|
|
284
284
|
|
|
@@ -300,7 +300,7 @@ export function evaluateUserPrompt(config, payload) {
|
|
|
300
300
|
)
|
|
301
301
|
) {
|
|
302
302
|
reminders.push(
|
|
303
|
-
"For GitHub Issues (filing with prefixes/screenshots or claiming & reviewing), follow
|
|
303
|
+
"For GitHub Issues (filing with prefixes/screenshots or claiming & reviewing), follow the `featflow-issues` skill and use `featflow issue create|list|view|claim|review|release` (do not create an Issue for plain direct fix requests).",
|
|
304
304
|
);
|
|
305
305
|
}
|
|
306
306
|
|
package/src/index.mjs
CHANGED