@aspruyt/xfg 7.2.1 → 7.4.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.
Files changed (91) hide show
  1. package/PR.md +2 -0
  2. package/dist/ai/anthropic-client.d.ts +16 -0
  3. package/dist/ai/anthropic-client.js +35 -0
  4. package/dist/ai/change-describer.d.ts +16 -0
  5. package/dist/ai/change-describer.js +170 -0
  6. package/dist/ai/client-factory.d.ts +2 -0
  7. package/dist/ai/client-factory.js +33 -0
  8. package/dist/ai/http.d.ts +3 -0
  9. package/dist/ai/http.js +33 -0
  10. package/dist/ai/index.d.ts +5 -0
  11. package/dist/ai/index.js +4 -0
  12. package/dist/ai/openai-compatible-client.d.ts +16 -0
  13. package/dist/ai/openai-compatible-client.js +36 -0
  14. package/dist/ai/types.d.ts +22 -0
  15. package/dist/ai/types.js +1 -0
  16. package/dist/cli/program.d.ts +7 -0
  17. package/dist/cli/program.js +15 -11
  18. package/dist/cli/repo-sync-runner.js +1 -0
  19. package/dist/cli/secrets-command.js +1 -0
  20. package/dist/cli/settings-factories.d.ts +2 -1
  21. package/dist/cli/settings-factories.js +7 -1
  22. package/dist/cli/settings-report-builder.d.ts +6 -1
  23. package/dist/cli/settings-report-builder.js +15 -0
  24. package/dist/cli/settings-runner.js +12 -0
  25. package/dist/cli/sync-command.js +2 -0
  26. package/dist/cli/types.d.ts +5 -2
  27. package/dist/cli/unified-summary.d.ts +3 -1
  28. package/dist/cli/unified-summary.js +14 -26
  29. package/dist/config/index.d.ts +1 -1
  30. package/dist/config/index.js +0 -2
  31. package/dist/config/normalizer.js +49 -27
  32. package/dist/config/types.d.ts +30 -1
  33. package/dist/config/validator.js +11 -4
  34. package/dist/config/validators/ai-validator.d.ts +1 -0
  35. package/dist/config/validators/ai-validator.js +39 -0
  36. package/dist/config/validators/group-validator.js +3 -0
  37. package/dist/config/validators/repo-entry-validator.js +2 -0
  38. package/dist/config/validators/shared.js +33 -0
  39. package/dist/lifecycle/formatter.d.ts +0 -4
  40. package/dist/lifecycle/formatter.js +2 -6
  41. package/dist/lifecycle/github-lifecycle-provider.d.ts +1 -0
  42. package/dist/lifecycle/github-lifecycle-provider.js +30 -14
  43. package/dist/output/github-summary.d.ts +4 -3
  44. package/dist/output/github-summary.js +22 -5
  45. package/dist/output/lifecycle-report.d.ts +3 -2
  46. package/dist/output/lifecycle-report.js +20 -26
  47. package/dist/output/settings-report.d.ts +12 -2
  48. package/dist/output/settings-report.js +49 -47
  49. package/dist/output/summary-budget.d.ts +12 -0
  50. package/dist/output/summary-budget.js +125 -0
  51. package/dist/output/sync-report.d.ts +6 -3
  52. package/dist/output/sync-report.js +33 -34
  53. package/dist/settings/collaborators/diff.d.ts +17 -0
  54. package/dist/settings/collaborators/diff.js +64 -0
  55. package/dist/settings/collaborators/formatter.d.ts +14 -0
  56. package/dist/settings/collaborators/formatter.js +41 -0
  57. package/dist/settings/collaborators/github-collaborators-strategy.d.ts +18 -0
  58. package/dist/settings/collaborators/github-collaborators-strategy.js +43 -0
  59. package/dist/settings/collaborators/index.d.ts +4 -0
  60. package/dist/settings/collaborators/index.js +2 -0
  61. package/dist/settings/collaborators/processor.d.ts +21 -0
  62. package/dist/settings/collaborators/processor.js +77 -0
  63. package/dist/settings/collaborators/types.d.ts +19 -0
  64. package/dist/settings/collaborators/types.js +1 -0
  65. package/dist/settings/index.d.ts +1 -0
  66. package/dist/settings/index.js +1 -0
  67. package/dist/settings/labels/formatter.d.ts +0 -3
  68. package/dist/settings/labels/formatter.js +10 -17
  69. package/dist/settings/rulesets/formatter.d.ts +0 -6
  70. package/dist/settings/rulesets/formatter.js +4 -32
  71. package/dist/settings/secrets/formatter.js +4 -3
  72. package/dist/settings/variables/formatter.js +6 -5
  73. package/dist/shared/markdown-fence.d.ts +3 -0
  74. package/dist/shared/markdown-fence.js +32 -0
  75. package/dist/shared/string-utils.d.ts +1 -3
  76. package/dist/shared/string-utils.js +5 -4
  77. package/dist/sync/commit-push-manager.js +2 -2
  78. package/dist/sync/index.d.ts +1 -1
  79. package/dist/sync/pr-merge-handler.js +3 -1
  80. package/dist/sync/repository-processor.d.ts +5 -0
  81. package/dist/sync/repository-processor.js +4 -1
  82. package/dist/sync/sync-workflow.d.ts +4 -1
  83. package/dist/sync/sync-workflow.js +29 -2
  84. package/dist/sync/types.d.ts +14 -3
  85. package/dist/vcs/ado-pr-strategy.js +43 -1
  86. package/dist/vcs/git-commit-strategy.js +3 -5
  87. package/dist/vcs/graphql-commit-strategy.js +3 -6
  88. package/dist/vcs/pr-creator.d.ts +5 -10
  89. package/dist/vcs/pr-creator.js +34 -20
  90. package/dist/vcs/types.d.ts +1 -0
  91. package/package.json +4 -2
@@ -1,7 +1,7 @@
1
1
  import type { MergeMode, MergeStrategy, RepoConfig } from "../config/index.js";
2
2
  import type { IRepoLifecycleManager } from "../lifecycle/index.js";
3
3
  import type { IRepositoryProcessor, FileChangeDetail } from "../sync/index.js";
4
- import type { ISettingsProcessor, IRulesetProcessor, IRepoSettingsProcessor, ILabelsProcessor, ICodeScanningProcessor, IVariablesProcessor, BaseProcessorResult } from "../settings/index.js";
4
+ import type { ISettingsProcessor, IRulesetProcessor, IRepoSettingsProcessor, ILabelsProcessor, ICodeScanningProcessor, IVariablesProcessor, ICollaboratorsProcessor, BaseProcessorResult } from "../settings/index.js";
5
5
  import type { RepoInfo } from "../repo/index.js";
6
6
  import type { ResultsCollector } from "./results-collector.js";
7
7
  import type { Logger } from "../shared/logger.js";
@@ -12,13 +12,15 @@ export type RepoSettingsProcessorFactory = SettingsProcessorFactory<IRepoSetting
12
12
  export type LabelsProcessorFactory = SettingsProcessorFactory<ILabelsProcessor>;
13
13
  export type CodeScanningProcessorFactory = SettingsProcessorFactory<ICodeScanningProcessor>;
14
14
  export type VariablesProcessorFactory = SettingsProcessorFactory<IVariablesProcessor>;
15
- export type SettingsKind = "rulesets" | "labels" | "repo" | "codeScanning" | "variables";
15
+ export type CollaboratorsProcessorFactory = SettingsProcessorFactory<ICollaboratorsProcessor>;
16
+ export type SettingsKind = "rulesets" | "labels" | "repo" | "codeScanning" | "variables" | "collaborators";
16
17
  export interface SettingsProcessorFactories {
17
18
  rulesets: RulesetProcessorFactory;
18
19
  labels: LabelsProcessorFactory;
19
20
  repo: RepoSettingsProcessorFactory;
20
21
  codeScanning: CodeScanningProcessorFactory;
21
22
  variables: VariablesProcessorFactory;
23
+ collaborators: CollaboratorsProcessorFactory;
22
24
  }
23
25
  /**
24
26
  * Dependencies for the sync command (dependency injection).
@@ -40,6 +42,7 @@ export interface SyncOptions extends SharedOptions {
40
42
  merge?: MergeMode;
41
43
  mergeStrategy?: MergeStrategy;
42
44
  deleteBranch?: boolean;
45
+ noAi?: boolean;
43
46
  }
44
47
  export interface SyncResultEntry {
45
48
  repoName: string;
@@ -1,11 +1,13 @@
1
1
  import { type LifecycleReport, type SyncReport, type SettingsReport } from "../output/index.js";
2
+ import type { DebugLog } from "../shared/logger.js";
2
3
  interface UnifiedSummaryInput {
3
4
  lifecycle?: LifecycleReport;
4
5
  sync?: SyncReport;
5
6
  settings?: SettingsReport;
6
7
  dryRun: boolean;
7
8
  summaryPath?: string | undefined;
9
+ log?: DebugLog;
8
10
  }
9
- export declare function formatUnifiedSummaryMarkdown(input: UnifiedSummaryInput): string;
11
+ export declare function formatUnifiedSummaryMarkdown(input: UnifiedSummaryInput, maxBytes?: number): string;
10
12
  export declare function writeUnifiedSummary(input: UnifiedSummaryInput): void;
11
13
  export {};
@@ -1,5 +1,8 @@
1
+ import { STEP_SUMMARY_MAX_BYTES } from "../output/github-summary.js";
2
+ import { fitSummary, summaryHeader, } from "../output/summary-budget.js";
1
3
  import { hasLifecycleChanges, writeGitHubStepSummary, renderSyncLines, renderRepoSettingsDiffLines, formatCountEntry, formatSettingsCountEntries, hasRepoSettingsChanges, } from "../output/index.js";
2
4
  import { formatActionCountEntry } from "../shared/count-format.js";
5
+ import { quoted } from "../shared/string-utils.js";
3
6
  function selectLabel(dry, pastLabel, futureLabel) {
4
7
  return dry ? futureLabel : pastLabel;
5
8
  }
@@ -61,23 +64,14 @@ function renderLifecycleLines(lcAction, diffLines) {
61
64
  diffLines.push(`+ visibility: ${lcAction.settings.visibility}`);
62
65
  }
63
66
  if (lcAction.settings.description) {
64
- diffLines.push(`+ description: "${lcAction.settings.description}"`);
67
+ diffLines.push(`+ description: ${quoted(lcAction.settings.description)}`);
65
68
  }
66
69
  }
67
70
  }
68
- export function formatUnifiedSummaryMarkdown(input) {
71
+ export function formatUnifiedSummaryMarkdown(input, maxBytes = STEP_SUMMARY_MAX_BYTES) {
69
72
  if (!hasAnyChanges(input)) {
70
73
  return "";
71
74
  }
72
- const lines = [];
73
- const title = input.dryRun ? "## xfg Plan" : "## xfg Apply";
74
- lines.push(title);
75
- lines.push("");
76
- if (input.dryRun) {
77
- lines.push("> [!WARNING]");
78
- lines.push("> This was a dry run — no changes were applied");
79
- lines.push("");
80
- }
81
75
  const lifecycleByRepo = new Map((input.lifecycle?.actions ?? []).map((a) => [a.repoName, a]));
82
76
  const syncByRepo = new Map((input.sync?.repos ?? []).map((r) => [r.repoName, r]));
83
77
  // The same repo can appear more than once (e.g. listed twice in config); keep every entry.
@@ -99,6 +93,7 @@ export function formatUnifiedSummaryMarkdown(input) {
99
93
  addRepo(r.repoName);
100
94
  for (const r of input.settings?.repos ?? [])
101
95
  addRepo(r.repoName);
96
+ const blocks = [];
102
97
  for (const repoName of allRepos) {
103
98
  const lcAction = lifecycleByRepo.get(repoName);
104
99
  const syncRepo = syncByRepo.get(repoName);
@@ -108,15 +103,13 @@ export function formatUnifiedSummaryMarkdown(input) {
108
103
  const repoHasSettingsChanges = settingsRepos.length > 0;
109
104
  if (!hasLcChange && !hasSyncChanges && !repoHasSettingsChanges)
110
105
  continue;
111
- lines.push(`### ${repoName}`);
112
- lines.push("");
113
106
  const diffLines = [];
114
107
  if (lcAction)
115
108
  renderLifecycleLines(lcAction, diffLines);
116
109
  if (hasLcChange && hasSyncChanges)
117
110
  diffLines.push("");
118
111
  if (syncRepo)
119
- diffLines.push(...renderSyncLines(syncRepo));
112
+ renderSyncLines(syncRepo, diffLines);
120
113
  if (hasSyncChanges && repoHasSettingsChanges)
121
114
  diffLines.push("");
122
115
  settingsRepos.forEach((settingsRepo, i) => {
@@ -124,19 +117,14 @@ export function formatUnifiedSummaryMarkdown(input) {
124
117
  diffLines.push("");
125
118
  renderRepoSettingsDiffLines(settingsRepo, diffLines);
126
119
  });
127
- if (diffLines.length > 0) {
128
- lines.push("```diff");
129
- lines.push(...diffLines);
130
- lines.push("```");
131
- lines.push("");
132
- }
120
+ blocks.push({ heading: `### ${repoName}`, diffLines, repos: [repoName] });
133
121
  }
134
- lines.push(`**${formatCombinedSummary(input)}**`);
135
- return lines.join("\n");
122
+ return fitSummary({
123
+ header: summaryHeader(input.dryRun),
124
+ blocks,
125
+ footer: `**${formatCombinedSummary(input)}**`,
126
+ }, maxBytes);
136
127
  }
137
128
  export function writeUnifiedSummary(input) {
138
- const markdown = formatUnifiedSummaryMarkdown(input);
139
- if (!markdown)
140
- return;
141
- writeGitHubStepSummary(markdown, input.summaryPath);
129
+ writeGitHubStepSummary((maxBytes) => formatUnifiedSummaryMarkdown(input, maxBytes), input.summaryPath, input.log);
142
130
  }
@@ -1,4 +1,4 @@
1
- export type { PRMergeOptions, MergeMode, MergeStrategy, BypassActor, BypassMode, StatusCheckConfig, CodeScanningTool, PullRequestRuleParameters, RulesetRule, Ruleset, GitHubRepoSettings, RepoVisibility, SquashMergeCommitTitle, SquashMergeCommitMessage, MergeCommitTitle, MergeCommitMessage, Label, CodeScanningSettings, CodeScanningState, CodeScanningQuerySuite, CodeScanningLanguage, RepoSettings, RawFileConfig, RawRepoFileOverride, RawGroupConfig, SecretConfig, SecretsConfig, RawRootSettings, RawRepoSettings, RawRepoConfig, RawConfig, RawConditionalGroupWhen, RawConditionalGroupConfig, RepoConfig, Config, FileContent, ContentValue, } from "./types.js";
1
+ export type { PRMergeOptions, RepoPROptions, AiConfig, AiProvider, ResolvedAiConfig, MergeMode, MergeStrategy, BypassActor, BypassMode, StatusCheckConfig, CodeScanningTool, PullRequestRuleParameters, RulesetRule, Ruleset, GitHubRepoSettings, RepoVisibility, SquashMergeCommitTitle, SquashMergeCommitMessage, MergeCommitTitle, MergeCommitMessage, Label, CodeScanningSettings, CodeScanningState, CodeScanningQuerySuite, CodeScanningLanguage, RepoSettings, RawFileConfig, RawRepoFileOverride, RawGroupConfig, SecretConfig, CollaboratorsConfig, RawCollaboratorsConfig, SecretsConfig, RawRootSettings, RawRepoSettings, RawRepoConfig, RawConfig, RawConditionalGroupWhen, RawConditionalGroupConfig, RepoConfig, Config, FileContent, ContentValue, } from "./types.js";
2
2
  export { RULESET_COMPARABLE_FIELDS } from "./types.js";
3
3
  export { loadRawConfig, loadConfig, normalizeConfig } from "./loader.js";
4
4
  export { convertContentToString } from "./formatter.js";
@@ -1,6 +1,4 @@
1
- // Re-export values (non-type exports)
2
1
  export { RULESET_COMPARABLE_FIELDS } from "./types.js";
3
- // Re-export loading functions
4
2
  export { loadRawConfig, loadConfig, normalizeConfig } from "./loader.js";
5
3
  // Config formatting
6
4
  export { convertContentToString } from "./formatter.js";
@@ -18,21 +18,17 @@ function cloneContent(content) {
18
18
  * or root file with no content and no repo override).
19
19
  */
20
20
  function resolveFileContent(rootContent, repoOverride, mergeStrategy) {
21
- // Override mode: use only repo content
22
21
  if (repoOverride?.override) {
23
22
  return repoOverride.content !== undefined
24
23
  ? cloneContent(repoOverride.content)
25
24
  : null;
26
25
  }
27
- // Root has no content — use repo content if provided, otherwise empty
28
26
  if (rootContent === undefined) {
29
27
  return repoOverride?.content ? cloneContent(repoOverride.content) : null;
30
28
  }
31
- // No repo override — use root content as-is
32
29
  if (!repoOverride?.content) {
33
30
  return structuredClone(rootContent);
34
31
  }
35
- // Both exist — merge
36
32
  return mergeContentPair(rootContent, repoOverride.content, mergeStrategy);
37
33
  }
38
34
  /**
@@ -48,7 +44,6 @@ function mergeContentPair(base, overlay, strategy) {
48
44
  const merged = deepMerge(structuredClone(base), overlay, ctx);
49
45
  return stripMergeDirectives(merged);
50
46
  }
51
- // Type mismatch — overlay wins
52
47
  return overlay;
53
48
  }
54
49
  /**
@@ -79,10 +74,25 @@ function mergePROptions(global, perRepo) {
79
74
  return perRepo;
80
75
  if (!perRepo)
81
76
  return global;
82
- const merged = { ...global, ...perRepo };
77
+ const lastAi = typeof global.ai === "object" ? global.ai : global.lastAi;
78
+ const merged = { ...global, ...perRepo, lastAi: undefined };
79
+ if (merged.ai === true && lastAi)
80
+ merged.ai = lastAi;
81
+ if (merged.ai === false)
82
+ merged.lastAi = lastAi;
83
83
  const result = Object.fromEntries(Object.entries(merged).filter(([, v]) => v !== undefined));
84
84
  return Object.keys(result).length > 0 ? result : undefined;
85
85
  }
86
+ function normalizeAiOption(prOptions) {
87
+ if (prOptions === undefined)
88
+ return undefined;
89
+ const { ai, lastAi: _lastAi, ...rest } = prOptions;
90
+ if (ai === true)
91
+ return { ...rest, ai: { provider: "anthropic" } };
92
+ if (ai)
93
+ return { ...rest, ai: { ...ai, provider: ai.provider ?? "anthropic" } };
94
+ return Object.keys(rest).length > 0 ? rest : undefined;
95
+ }
86
96
  /**
87
97
  * Deep merges two rulesets: per-repo values override root values.
88
98
  */
@@ -185,6 +195,29 @@ function dropEntryMapIfEmpty(merged) {
185
195
  return undefined;
186
196
  return merged;
187
197
  }
198
+ /**
199
+ * Merges collaborator layers: users union (case-insensitive, first spelling wins),
200
+ * `inherit: false` drops base users but never clears an inherited deleteOrphaned.
201
+ */
202
+ function mergeCollaboratorsLayer(base, overlay) {
203
+ const inheritedUsers = overlay?.inherit === false ? [] : (base?.users ?? []);
204
+ const seen = new Set();
205
+ const users = [];
206
+ for (const user of [...inheritedUsers, ...(overlay?.users ?? [])]) {
207
+ const key = user.toLowerCase();
208
+ if (seen.has(key))
209
+ continue;
210
+ seen.add(key);
211
+ users.push(user);
212
+ }
213
+ const deleteOrphaned = overlay?.deleteOrphaned ?? base?.deleteOrphaned;
214
+ return deleteOrphaned === undefined ? { users } : { users, deleteOrphaned };
215
+ }
216
+ function dropCollaboratorsIfEmpty(merged) {
217
+ if ((merged.users ?? []).length === 0 && merged.deleteOrphaned === undefined)
218
+ return undefined;
219
+ return merged;
220
+ }
188
221
  /**
189
222
  * Merges settings: per-repo settings deep merge with root settings.
190
223
  * Returns undefined if no settings are defined.
@@ -193,7 +226,6 @@ export function mergeSettings(root, perRepo) {
193
226
  if (!root && !perRepo)
194
227
  return undefined;
195
228
  const result = {};
196
- // Merge rulesets by name - each ruleset is deep merged
197
229
  const rootRulesets = root?.rulesets ?? {};
198
230
  const repoRulesets = perRepo?.rulesets ?? {};
199
231
  const inheritRulesets = shouldInherit(repoRulesets);
@@ -206,31 +238,25 @@ export function mergeSettings(root, perRepo) {
206
238
  for (const name of allRulesetNames) {
207
239
  const rootRuleset = rootRulesets[name];
208
240
  const repoRuleset = repoRulesets[name];
209
- // Skip if repo explicitly opts out of this ruleset
210
241
  if (repoRuleset === false) {
211
242
  continue;
212
243
  }
213
- // Skip root rulesets if inherit: false (unless repo has override)
214
244
  if (!inheritRulesets && !repoRuleset && rootRuleset) {
215
245
  continue;
216
246
  }
217
247
  const merged = mergeRuleset(rootRuleset, repoRuleset);
218
248
  result.rulesets[name] = stripMergeDirectives(merged);
219
249
  }
220
- // Clean up empty rulesets object
221
250
  if (Object.keys(result.rulesets).length === 0) {
222
251
  delete result.rulesets;
223
252
  }
224
253
  }
225
- // deleteOrphaned: per-repo overrides root
226
254
  const deleteOrphaned = perRepo?.deleteOrphaned !== undefined
227
255
  ? perRepo.deleteOrphaned
228
256
  : root?.deleteOrphaned;
229
257
  if (deleteOrphaned !== undefined) {
230
258
  result.deleteOrphaned = deleteOrphaned;
231
259
  }
232
- // Merge repo settings: per-repo overrides root (shallow merge)
233
- // repo: false means opt out of all root repo settings
234
260
  if (perRepo?.repo === false) {
235
261
  // Opt-out: don't include any repo settings
236
262
  }
@@ -244,7 +270,6 @@ export function mergeSettings(root, perRepo) {
244
270
  };
245
271
  }
246
272
  }
247
- // Merge labels by name
248
273
  const mergedLabels = mergeLabels(root?.labels, perRepo?.labels);
249
274
  if (mergedLabels) {
250
275
  result.labels = mergedLabels;
@@ -281,6 +306,12 @@ export function mergeSettings(root, perRepo) {
281
306
  result.secrets = merged;
282
307
  }
283
308
  }
309
+ if (root?.collaborators || perRepo?.collaborators) {
310
+ const merged = dropCollaboratorsIfEmpty(mergeCollaboratorsLayer(root?.collaborators, perRepo?.collaborators));
311
+ if (merged) {
312
+ result.collaborators = merged;
313
+ }
314
+ }
284
315
  return Object.keys(result).length > 0 ? result : undefined;
285
316
  }
286
317
  /**
@@ -386,13 +417,11 @@ function mergeRawSettings(base, overlay) {
386
417
  if (!overlay)
387
418
  return structuredClone(base);
388
419
  const result = base ? structuredClone(base) : {};
389
- // Merge rulesets
390
420
  if (overlay.rulesets) {
391
421
  result.rulesets = mergeNamedEntries(result.rulesets, overlay.rulesets, (existing, entry) => existing && typeof existing === "object"
392
422
  ? mergeRuleset(existing, entry)
393
423
  : structuredClone(entry));
394
424
  }
395
- // Merge repo settings: overlay replaces base (shallow merge, same as mergeSettings)
396
425
  if (overlay.repo !== undefined) {
397
426
  if (overlay.repo === false) {
398
427
  result.repo = false;
@@ -404,14 +433,12 @@ function mergeRawSettings(base, overlay) {
404
433
  };
405
434
  }
406
435
  }
407
- // Merge labels
408
436
  if (overlay.labels) {
409
437
  result.labels = mergeNamedEntries(result.labels, overlay.labels, (existing, entry) => ({
410
438
  ...(existing && typeof existing === "object" ? existing : {}),
411
439
  ...entry,
412
440
  }));
413
441
  }
414
- // Merge code scanning: overlay fully replaces base (same semantics as mergeSettings)
415
442
  if (overlay.codeScanning !== undefined) {
416
443
  if (overlay.codeScanning === false) {
417
444
  result.codeScanning = false;
@@ -426,7 +453,9 @@ function mergeRawSettings(base, overlay) {
426
453
  if (overlay.secrets) {
427
454
  result.secrets = mergeEntryMapLayer(result.secrets, overlay.secrets);
428
455
  }
429
- // deleteOrphaned: overlay wins
456
+ if (overlay.collaborators) {
457
+ result.collaborators = mergeCollaboratorsLayer(result.collaborators, overlay.collaborators);
458
+ }
430
459
  if (overlay.deleteOrphaned !== undefined) {
431
460
  result.deleteOrphaned = overlay.deleteOrphaned;
432
461
  }
@@ -452,7 +481,6 @@ function mergeGroupSettings(rootSettings, groupNames, groupDefs) {
452
481
  * Absent conditions are treated as satisfied.
453
482
  */
454
483
  function evaluateWhenClause(when, effectiveGroups) {
455
- // Defensive: if no condition is specified, don't match
456
484
  if (!when.allOf && !when.anyOf && !when.noneOf)
457
485
  return false;
458
486
  const allOfSatisfied = !when.allOf || when.allOf.every((g) => effectiveGroups.has(g));
@@ -477,11 +505,9 @@ function mergeConditionalGroups(accumulatedFiles, accumulatedPROptions, accumula
477
505
  if (cg.files) {
478
506
  files = applyFileLayer(files, cg.files);
479
507
  }
480
- // Merge prOptions
481
508
  if (cg.prOptions) {
482
509
  prOptions = mergePROptions(prOptions, cg.prOptions);
483
510
  }
484
- // Merge settings
485
511
  if (cg.settings) {
486
512
  settings = mergeRawSettings(settings, cg.settings);
487
513
  }
@@ -536,7 +562,7 @@ function normalizeRepoEntry(ctx) {
536
562
  if (entry)
537
563
  files.push(entry);
538
564
  }
539
- const prOptions = mergePROptions(ctx.effectivePROptions, ctx.rawRepo.prOptions);
565
+ const prOptions = normalizeAiOption(mergePROptions(ctx.effectivePROptions, ctx.rawRepo.prOptions));
540
566
  const settings = mergeSettings(ctx.effectiveSettings, ctx.rawRepo.settings);
541
567
  return {
542
568
  git: ctx.gitUrl,
@@ -555,11 +581,9 @@ export function normalizeConfig(raw, env) {
555
581
  const expandedRepos = [];
556
582
  for (const rawRepo of raw.repos) {
557
583
  const gitUrls = Array.isArray(rawRepo.git) ? rawRepo.git : [rawRepo.git];
558
- // Phase 0: Expand extends chains
559
584
  const expandedGroups = rawRepo.groups?.length
560
585
  ? expandRepoGroups(rawRepo.groups, raw.groups ?? {})
561
586
  : [];
562
- // Phase 1: Resolve groups - build effective root files/prOptions/settings by merging group layers
563
587
  let effectiveRootFiles = expandedGroups.length
564
588
  ? mergeGroupFiles(raw.files ?? {}, expandedGroups, raw.groups ?? {})
565
589
  : (raw.files ?? {});
@@ -569,7 +593,6 @@ export function normalizeConfig(raw, env) {
569
593
  let effectiveSettings = expandedGroups.length
570
594
  ? mergeGroupSettings(raw.settings, expandedGroups, raw.groups ?? {})
571
595
  : raw.settings;
572
- // Phase 2 + 3: Evaluate and merge conditional groups
573
596
  if (raw.conditionalGroups?.length) {
574
597
  const effectiveGroups = new Set(expandedGroups);
575
598
  const merged = mergeConditionalGroups(effectiveRootFiles, effectivePROptions, effectiveSettings, effectiveGroups, raw.conditionalGroups);
@@ -578,7 +601,6 @@ export function normalizeConfig(raw, env) {
578
601
  effectiveSettings = merged.settings;
579
602
  }
580
603
  const fileNames = Object.keys(effectiveRootFiles);
581
- // Collect repo-only file names (defined at repo level but not in root/groups)
582
604
  const repoOnlyFileNames = [];
583
605
  if (rawRepo.files) {
584
606
  for (const name of Object.keys(rawRepo.files)) {
@@ -1,6 +1,18 @@
1
1
  import type { ArrayMergeStrategy } from "./merge.js";
2
2
  export type MergeMode = "manual" | "auto" | "force" | "direct";
3
3
  export type MergeStrategy = "merge" | "squash" | "rebase";
4
+ export type AiProvider = "anthropic" | "openai";
5
+ export interface AiConfig {
6
+ provider?: AiProvider;
7
+ model?: string;
8
+ baseUrl?: string;
9
+ apiKeyEnv?: string;
10
+ prompt?: string;
11
+ maxDiffChars?: number;
12
+ }
13
+ export type ResolvedAiConfig = AiConfig & {
14
+ provider: AiProvider;
15
+ };
4
16
  export interface PRMergeOptions {
5
17
  merge?: MergeMode;
6
18
  mergeStrategy?: MergeStrategy;
@@ -8,7 +20,11 @@ export interface PRMergeOptions {
8
20
  bypassReason?: string;
9
21
  labels?: string[];
10
22
  branch?: string;
23
+ ai?: boolean | AiConfig;
11
24
  }
25
+ export type RepoPROptions = Omit<PRMergeOptions, "ai"> & {
26
+ ai?: ResolvedAiConfig;
27
+ };
12
28
  export type RulesetTarget = "branch" | "tag";
13
29
  export type RulesetEnforcement = "active" | "disabled" | "evaluate";
14
30
  export type BypassActorType = "Team" | "User" | "Integration";
@@ -275,6 +291,15 @@ export interface SecretConfig {
275
291
  export type SecretsConfig = Record<string, SecretConfig | boolean> & {
276
292
  deleteOrphaned?: boolean;
277
293
  };
294
+ export interface CollaboratorsConfig {
295
+ /** GitHub usernames granted write access (personal repos only) */
296
+ users?: string[];
297
+ /** Remove users xfg added (tracked in .xfg.json) once they leave the config */
298
+ deleteOrphaned?: boolean;
299
+ }
300
+ export interface RawCollaboratorsConfig extends CollaboratorsConfig {
301
+ inherit?: boolean;
302
+ }
278
303
  export interface RepoSettings {
279
304
  /** GitHub rulesets keyed by name */
280
305
  rulesets?: Record<string, Ruleset>;
@@ -292,6 +317,8 @@ export interface RepoSettings {
292
317
  secrets?: Record<string, SecretConfig> & {
293
318
  deleteOrphaned?: boolean;
294
319
  };
320
+ /** Direct collaborators on personal (user-owned) repos */
321
+ collaborators?: CollaboratorsConfig;
295
322
  deleteOrphaned?: boolean;
296
323
  }
297
324
  export type ContentValue = Record<string, unknown> | string | string[];
@@ -356,6 +383,7 @@ export interface RawRootSettings {
356
383
  deleteOrphaned?: boolean;
357
384
  };
358
385
  secrets?: SecretsConfig;
386
+ collaborators?: CollaboratorsConfig;
359
387
  deleteOrphaned?: boolean;
360
388
  }
361
389
  export interface RawRepoSettings {
@@ -374,6 +402,7 @@ export interface RawRepoSettings {
374
402
  secrets?: SecretsConfig & {
375
403
  inherit?: boolean;
376
404
  };
405
+ collaborators?: RawCollaboratorsConfig;
377
406
  deleteOrphaned?: boolean;
378
407
  }
379
408
  export interface RawRepoConfig {
@@ -415,7 +444,7 @@ export interface FileContent {
415
444
  export interface RepoConfig {
416
445
  git: string;
417
446
  files: FileContent[];
418
- prOptions?: PRMergeOptions;
447
+ prOptions?: RepoPROptions;
419
448
  settings?: RepoSettings;
420
449
  /** Fork upstream repo if target doesn't exist */
421
450
  upstream?: string;
@@ -2,6 +2,7 @@ import { validateFileName } from "./validators/file-validator.js";
2
2
  import { isPlainObject } from "../shared/type-guards.js";
3
3
  import { ValidationError } from "../shared/errors.js";
4
4
  import { validateBranchName } from "../shared/branch-validation.js";
5
+ import { validateAiOption } from "./validators/ai-validator.js";
5
6
  import { validateFileConfigFields, validateSettings, } from "./validators/shared.js";
6
7
  import { validateGroups, validateConditionalGroups, } from "./validators/group-validator.js";
7
8
  import { validateRepoEntry } from "./validators/repo-entry-validator.js";
@@ -68,6 +69,10 @@ function validateRootSettings(config) {
68
69
  if (config.settings.secrets && "inherit" in config.settings.secrets) {
69
70
  throw new ValidationError("'inherit' is not allowed in root-level secrets (nothing to inherit from)");
70
71
  }
72
+ if (config.settings.collaborators &&
73
+ "inherit" in config.settings.collaborators) {
74
+ throw new ValidationError("'inherit' is not allowed in root-level collaborators (nothing to inherit from)");
75
+ }
71
76
  }
72
77
  function validateGithubHosts(config) {
73
78
  if (config.githubHosts === undefined)
@@ -92,6 +97,7 @@ function validatePrOptions(config) {
92
97
  if (config.prOptions?.branch !== undefined) {
93
98
  validateBranchName(config.prOptions.branch);
94
99
  }
100
+ validateAiOption(config.prOptions?.ai);
95
101
  if (config.prOptions?.labels === undefined)
96
102
  return;
97
103
  if (!Array.isArray(config.prOptions.labels)) {
@@ -200,7 +206,6 @@ export function validateForSync(config) {
200
206
  "Use 'files' to sync configuration files, or 'settings' to manage repository settings. " +
201
207
  "For secrets, use 'xfg secrets sync'.");
202
208
  }
203
- // Validate variable names across all settings
204
209
  for (const settings of collectAllSettings(config)) {
205
210
  if (!settings?.variables)
206
211
  continue;
@@ -220,7 +225,6 @@ export function validateForSync(config) {
220
225
  throw new ValidationError(`Variable '${name}' must have a string value (got ${typeof value}). Quote numeric values in YAML: "${String(value)}".`);
221
226
  }
222
227
  }
223
- // Reject duplicate case-insensitive variable names
224
228
  const seenVarNames = new Map();
225
229
  for (const name of Object.keys(settings.variables)) {
226
230
  if (VARIABLE_RESERVED_KEYS.has(name))
@@ -233,7 +237,6 @@ export function validateForSync(config) {
233
237
  seenVarNames.set(upper, name);
234
238
  }
235
239
  }
236
- // Validate secret names and configs
237
240
  validateSecretsConfig(config);
238
241
  }
239
242
  const ENTRY_MAP_META_KEYS = new Set(["deleteOrphaned", "inherit"]);
@@ -287,6 +290,11 @@ export function hasActionableSettings(settings) {
287
290
  return true;
288
291
  }
289
292
  }
293
+ if (settings.collaborators &&
294
+ ((settings.collaborators.users ?? []).length > 0 ||
295
+ settings.collaborators.deleteOrphaned === true)) {
296
+ return true;
297
+ }
290
298
  // Secrets are deliberately absent: `xfg sync` must never process them.
291
299
  // A secrets-only config leaves `xfg sync` with nothing to do.
292
300
  return false;
@@ -321,7 +329,6 @@ function validateSecretsLayer(secrets) {
321
329
  if (inherit !== undefined && typeof inherit !== "boolean") {
322
330
  throw new ValidationError("'inherit' is a reserved key in secrets config and cannot be used as a secret name.");
323
331
  }
324
- // Reject duplicate case-insensitive secret names
325
332
  const seen = new Map();
326
333
  for (const name of Object.keys(secrets)) {
327
334
  if (SECRET_RESERVED_KEYS.has(name))
@@ -0,0 +1 @@
1
+ export declare function validateAiOption(ai: unknown): void;
@@ -0,0 +1,39 @@
1
+ import { isPlainObject } from "../../shared/type-guards.js";
2
+ import { ValidationError } from "../../shared/errors.js";
3
+ const VALID_PROVIDERS = ["anthropic", "openai"];
4
+ const STRING_FIELDS = ["model", "baseUrl", "apiKeyEnv", "prompt"];
5
+ const KNOWN_KEYS = new Set([
6
+ "provider",
7
+ "maxDiffChars",
8
+ ...STRING_FIELDS,
9
+ ]);
10
+ export function validateAiOption(ai) {
11
+ if (ai === undefined || typeof ai === "boolean")
12
+ return;
13
+ if (!isPlainObject(ai)) {
14
+ throw new ValidationError("prOptions.ai must be a boolean or an object");
15
+ }
16
+ const unknown = Object.keys(ai).find((key) => !KNOWN_KEYS.has(key));
17
+ if (unknown !== undefined) {
18
+ throw new ValidationError(`prOptions.ai has unknown key '${unknown}'`);
19
+ }
20
+ const provider = ai.provider;
21
+ if (provider !== undefined &&
22
+ !VALID_PROVIDERS.includes(provider)) {
23
+ throw new ValidationError(`prOptions.ai.provider must be one of: ${VALID_PROVIDERS.join(", ")}`);
24
+ }
25
+ for (const field of STRING_FIELDS) {
26
+ const value = ai[field];
27
+ if (value !== undefined && (typeof value !== "string" || value === "")) {
28
+ throw new ValidationError(`prOptions.ai.${field} must be a non-empty string`);
29
+ }
30
+ }
31
+ if (provider === "openai" && ai.model === undefined) {
32
+ throw new ValidationError("prOptions.ai.model is required when provider is 'openai'");
33
+ }
34
+ const max = ai.maxDiffChars;
35
+ if (max !== undefined &&
36
+ (typeof max !== "number" || !Number.isInteger(max) || max <= 0)) {
37
+ throw new ValidationError("prOptions.ai.maxDiffChars must be a positive integer");
38
+ }
39
+ }
@@ -2,6 +2,7 @@ import { resolveExtendsChain } from "../extends-resolver.js";
2
2
  import { isPlainObject } from "../../shared/type-guards.js";
3
3
  import { ValidationError } from "../../shared/errors.js";
4
4
  import { validateBranchName } from "../../shared/branch-validation.js";
5
+ import { validateAiOption } from "./ai-validator.js";
5
6
  import { validateFileConfigFields, validateSettings, buildRootSettingsContext, } from "./shared.js";
6
7
  function validateGroupExtends(groupName, extends_, groupNames) {
7
8
  if (typeof extends_ === "string") {
@@ -106,6 +107,7 @@ export function validateGroups(config) {
106
107
  if (group.prOptions?.branch !== undefined) {
107
108
  validateBranchName(group.prOptions.branch);
108
109
  }
110
+ validateAiOption(group.prOptions?.ai);
109
111
  }
110
112
  validateNoCircularExtends(config.groups);
111
113
  }
@@ -170,5 +172,6 @@ export function validateConditionalGroups(config) {
170
172
  if (entry.prOptions?.branch !== undefined) {
171
173
  validateBranchName(entry.prOptions.branch);
172
174
  }
175
+ validateAiOption(entry.prOptions?.ai);
173
176
  }
174
177
  }
@@ -4,6 +4,7 @@ import { isPlainObject } from "../../shared/type-guards.js";
4
4
  import { escapeRegExp } from "../../shared/regex-utils.js";
5
5
  import { ValidationError } from "../../shared/errors.js";
6
6
  import { validateBranchName } from "../../shared/branch-validation.js";
7
+ import { validateAiOption } from "./ai-validator.js";
7
8
  import { validateFileConfigFields, validateSettings, buildRootSettingsContext, enrichSettingsContext, } from "./shared.js";
8
9
  function isValidGitUrl(url) {
9
10
  return /^git@[^:]+:.+$/.test(url) || /^https?:\/\/[^/]+\/.+$/.test(url);
@@ -161,6 +162,7 @@ function validateRepoPrOptions(repo) {
161
162
  if (repo.prOptions?.branch !== undefined) {
162
163
  validateBranchName(repo.prOptions.branch);
163
164
  }
165
+ validateAiOption(repo.prOptions?.ai);
164
166
  }
165
167
  export function validateRepoEntry(config, repo, index) {
166
168
  const repoLabel = validateRepoGitField(repo, index);
@@ -228,6 +228,38 @@ function validateSettingsSecrets(settings, context) {
228
228
  }
229
229
  }
230
230
  }
231
+ const GITHUB_USERNAME_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;
232
+ const COLLABORATORS_KEYS = new Set(["users", "deleteOrphaned", "inherit"]);
233
+ function validateSettingsCollaborators(settings, context) {
234
+ if (settings.collaborators === undefined)
235
+ return;
236
+ if (!isPlainObject(settings.collaborators)) {
237
+ throw new ValidationError(`${context}: collaborators must be an object`);
238
+ }
239
+ const collaborators = settings.collaborators;
240
+ for (const key of Object.keys(collaborators)) {
241
+ if (!COLLABORATORS_KEYS.has(key)) {
242
+ throw new ValidationError(`${context}: collaborators: unknown key '${key}'`);
243
+ }
244
+ }
245
+ for (const key of ["deleteOrphaned", "inherit"]) {
246
+ const value = collaborators[key];
247
+ if (value !== undefined && typeof value !== "boolean") {
248
+ throw new ValidationError(`${context}: collaborators.${key} must be a boolean`);
249
+ }
250
+ }
251
+ const users = collaborators.users;
252
+ if (users === undefined)
253
+ return;
254
+ if (!Array.isArray(users)) {
255
+ throw new ValidationError(`${context}: collaborators.users must be an array of GitHub usernames`);
256
+ }
257
+ for (const user of users) {
258
+ if (typeof user !== "string" || !GITHUB_USERNAME_PATTERN.test(user)) {
259
+ throw new ValidationError(`${context}: collaborators.users entry '${String(user)}' is not a valid GitHub username`);
260
+ }
261
+ }
262
+ }
231
263
  export function validateSettings(settings, context, rootCtx) {
232
264
  if (!isPlainObject(settings)) {
233
265
  throw new ValidationError(`${context}: settings must be an object`);
@@ -238,6 +270,7 @@ export function validateSettings(settings, context, rootCtx) {
238
270
  validateSettingsRepo(settings, context, rootCtx);
239
271
  validateSettingsCodeScanning(settings, context, rootCtx);
240
272
  validateSettingsSecrets(settings, context);
273
+ validateSettingsCollaborators(settings, context);
241
274
  }
242
275
  export function enrichSettingsContext(rootCtx, settings) {
243
276
  if (!settings)