@danielstyle/featflow 0.6.4 → 0.7.0

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