@fro.bot/systematic 3.19.0 → 3.21.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.
package/dist/cli.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  parseTree,
7
7
  modify,
8
8
  applyEdits,
9
+ CONFIG_PROTECTED_FIELD_PATHS,
9
10
  _isoDateTime,
10
11
  _isoDate,
11
12
  _isoTime,
@@ -33,7 +34,7 @@ import {
33
34
  findCommandsInDir,
34
35
  findSkillsInDir,
35
36
  discoverSkills
36
- } from "./index-mf76ybyr.js";
37
+ } from "./index-c17zm38x.js";
37
38
  var __defProp = Object.defineProperty;
38
39
  var __returnValue = (v) => v;
39
40
  function __exportSetter(name, newValue) {
@@ -183,22 +184,6 @@ var CONFIG_AUTHORITY_FIELD_PATHS = [
183
184
  "workflow_guard.debug",
184
185
  "workflow_guard.mode"
185
186
  ];
186
- var CONFIG_PROTECTED_FIELD_PATHS = [
187
- "workflow_guard",
188
- "profiles",
189
- "agents.*.model",
190
- "agents.*.permission",
191
- "agents.*.skills",
192
- "agents.*.variant",
193
- "agents.*.opencode",
194
- "agents.*.pi",
195
- "categories.*.model",
196
- "categories.*.permission",
197
- "categories.*.skills",
198
- "categories.*.variant",
199
- "categories.*.opencode",
200
- "categories.*.pi"
201
- ];
202
187
  var CONFIG_SOURCE_ERROR_CODES = [
203
188
  "parse-failed",
204
189
  "read-failed",
@@ -3460,13 +3445,19 @@ function formatRoutingQualifier(qualifier) {
3460
3445
  return qualifier === undefined ? "(none)" : qualifier;
3461
3446
  }
3462
3447
  function formatRoutingSource(source) {
3463
- return source === undefined ? "(n/a)" : `${source.level}/${source.form}`;
3448
+ if (source === undefined)
3449
+ return "(n/a)";
3450
+ return source.origin === undefined ? `${source.level}/${source.form}` : `${source.level}/${source.form}, ${source.origin}`;
3464
3451
  }
3465
- function printProfileSummary(metadata) {
3452
+ function printProfileSummary(loaded) {
3453
+ const metadata = loaded.metadata;
3466
3454
  const activeLabel = metadata.activeProfile ?? "none";
3467
3455
  const selectedByLabel = metadata.profileSelectorSource ?? "(none)";
3468
3456
  console.log(` Active profile: ${activeLabel}`);
3469
3457
  console.log(` Selected by: ${selectedByLabel}`);
3458
+ if (loaded.activeProfileSourcePath !== null) {
3459
+ console.log(` Defined in: ${loaded.activeProfileSourcePath}`);
3460
+ }
3470
3461
  if (metadata.profileFallback) {
3471
3462
  const usedLabel = metadata.profileFallback.usedDefault ? `your default profile "${metadata.profileFallback.usedDefault}"` : "base configuration (no default profile is set)";
3472
3463
  console.log(` Fallback: requested "${metadata.profileFallback.requested}" is not defined; used ${usedLabel}`);
@@ -3513,7 +3504,7 @@ Resolved configuration:`);
3513
3504
  console.log(" No profiles are selected and no per-agent/category overlays are defined.");
3514
3505
  return true;
3515
3506
  }
3516
- printProfileSummary(metadata);
3507
+ printProfileSummary(loaded);
3517
3508
  console.log("");
3518
3509
  console.log(" Routing:");
3519
3510
  printRoutingTable(loaded);
@@ -3562,6 +3553,7 @@ function buildConfigShowJson() {
3562
3553
  locations,
3563
3554
  activeProfile: loaded.metadata.activeProfile,
3564
3555
  profileSelectorSource: loaded.metadata.profileSelectorSource,
3556
+ activeProfileSourcePath: loaded.activeProfileSourcePath,
3565
3557
  profileFallback: loaded.metadata.profileFallback,
3566
3558
  routing
3567
3559
  };
@@ -126,8 +126,8 @@ function toSourcedPiSubagentsOverlays(map) {
126
126
  categories: toSourcedOverlayMap(map?.categories)
127
127
  };
128
128
  }
129
- function lookupAgentOverlay(overlays, target) {
130
- return getOverlayValue(overlays.agents, target.agentKey) ?? getOverlayValue(overlays.agents, `${target.category}/${target.agentKey}`);
129
+ function lookupAgentOverlayEntry(overlays, target) {
130
+ return overlays.agents[target.agentKey] ?? overlays.agents[`${target.category}/${target.agentKey}`];
131
131
  }
132
132
  function readBlockField(overlay, blockKey, field) {
133
133
  if (overlay === undefined)
@@ -160,23 +160,31 @@ function resolveField(candidates) {
160
160
  }
161
161
  return { value: undefined, source: undefined };
162
162
  }
163
- function resolveModel(agentOverlay, categoryOverlay, harness) {
163
+ function resolveModel(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, harness) {
164
164
  const { value, source } = resolveField([
165
165
  {
166
166
  value: readBlockField(agentOverlay, harness, "model"),
167
- source: { level: "agent", form: "block" }
167
+ source: { level: "agent", form: "block", origin: agentOrigins?.piModel }
168
168
  },
169
169
  {
170
170
  value: readFlatField(agentOverlay, "model"),
171
- source: { level: "agent", form: "flat" }
171
+ source: { level: "agent", form: "flat", origin: agentOrigins?.model }
172
172
  },
173
173
  {
174
174
  value: readBlockField(categoryOverlay, harness, "model"),
175
- source: { level: "category", form: "block" }
175
+ source: {
176
+ level: "category",
177
+ form: "block",
178
+ origin: categoryOrigins?.piModel
179
+ }
176
180
  },
177
181
  {
178
182
  value: readFlatField(categoryOverlay, "model"),
179
- source: { level: "category", form: "flat" }
183
+ source: {
184
+ level: "category",
185
+ form: "flat",
186
+ origin: categoryOrigins?.model
187
+ }
180
188
  }
181
189
  ]);
182
190
  const narrowedValue = narrowModelValue(value);
@@ -195,13 +203,23 @@ function readOpencodeLayerField(agentOverlay, categoryOverlay, layer, field) {
195
203
  const overlay = layer.level === "agent" ? agentOverlay : categoryOverlay;
196
204
  return layer.form === "block" ? readBlockField(overlay, "opencode", field) : readFlatField(overlay, field);
197
205
  }
198
- function resolveOpencodeModelAndVariant(agentOverlay, categoryOverlay) {
206
+ function readOpencodeLayerOrigin(agentOrigins, categoryOrigins, layer, field) {
207
+ const origins = layer.level === "agent" ? agentOrigins : categoryOrigins;
208
+ if (field === "model") {
209
+ return layer.form === "block" ? origins?.opencodeModel : origins?.model;
210
+ }
211
+ return layer.form === "block" ? origins?.opencodeVariant : origins?.variant;
212
+ }
213
+ function resolveOpencodeModelAndVariant(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins) {
199
214
  const modelLayerIndex = OPENCODE_MODEL_VARIANT_LAYERS.findIndex((layer) => readOpencodeLayerField(agentOverlay, categoryOverlay, layer, "model") !== undefined);
200
215
  const modelLayer = modelLayerIndex === -1 ? undefined : OPENCODE_MODEL_VARIANT_LAYERS[modelLayerIndex];
201
216
  const rawModel = modelLayer === undefined ? undefined : readOpencodeLayerField(agentOverlay, categoryOverlay, modelLayer, "model");
202
217
  const model = narrowModelValue(rawModel);
203
218
  const hasModel = model !== undefined;
204
- const modelSource = hasModel ? OPENCODE_MODEL_VARIANT_LAYERS[modelLayerIndex] : undefined;
219
+ const modelSource = hasModel && modelLayer !== undefined ? {
220
+ ...modelLayer,
221
+ origin: readOpencodeLayerOrigin(agentOrigins, categoryOrigins, modelLayer, "model")
222
+ } : undefined;
205
223
  let qualifier;
206
224
  let qualifierSource;
207
225
  if (model !== null) {
@@ -210,22 +228,33 @@ function resolveOpencodeModelAndVariant(agentOverlay, categoryOverlay) {
210
228
  const narrowed = narrowQualifierValue(readOpencodeLayerField(agentOverlay, categoryOverlay, layer, "variant"));
211
229
  if (narrowed !== undefined) {
212
230
  qualifier = narrowed;
213
- qualifierSource = layer;
231
+ qualifierSource = {
232
+ ...layer,
233
+ origin: readOpencodeLayerOrigin(agentOrigins, categoryOrigins, layer, "variant")
234
+ };
214
235
  break;
215
236
  }
216
237
  }
217
238
  }
218
239
  return { model, modelSource, qualifier, qualifierSource };
219
240
  }
220
- function resolvePiThinking(agentOverlay, categoryOverlay, piSubagentsOverlays, target) {
241
+ function resolvePiThinking(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, piSubagentsOverlays, target) {
221
242
  const blockResolution = resolveField([
222
243
  {
223
244
  value: readBlockField(agentOverlay, "pi", "thinking"),
224
- source: { level: "agent", form: "block" }
245
+ source: {
246
+ level: "agent",
247
+ form: "block",
248
+ origin: agentOrigins?.piThinking
249
+ }
225
250
  },
226
251
  {
227
252
  value: readBlockField(categoryOverlay, "pi", "thinking"),
228
- source: { level: "category", form: "block" }
253
+ source: {
254
+ level: "category",
255
+ form: "block",
256
+ origin: categoryOrigins?.piThinking
257
+ }
229
258
  }
230
259
  ]);
231
260
  const legacyAgentThinking = getOverlayValue(piSubagentsOverlays.agents, target.agentKey)?.thinking;
@@ -255,10 +284,14 @@ function resolvePiThinking(agentOverlay, categoryOverlay, piSubagentsOverlays, t
255
284
  }
256
285
  function resolveRouting(input) {
257
286
  const { overlays, piSubagentsOverlays, target, harness } = input;
258
- const agentOverlay = lookupAgentOverlay(overlays, target);
259
- const categoryOverlay = getOverlayValue(overlays.categories, target.category);
287
+ const agentEntry = lookupAgentOverlayEntry(overlays, target);
288
+ const categoryEntry = overlays.categories[target.category];
289
+ const agentOverlay = agentEntry?.value;
290
+ const categoryOverlay = categoryEntry?.value;
291
+ const agentOrigins = agentEntry?.origins;
292
+ const categoryOrigins = categoryEntry?.origins;
260
293
  if (harness === "opencode") {
261
- const resolution = resolveOpencodeModelAndVariant(agentOverlay, categoryOverlay);
294
+ const resolution = resolveOpencodeModelAndVariant(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins);
262
295
  return {
263
296
  model: resolution.model,
264
297
  qualifier: resolution.qualifier,
@@ -270,8 +303,8 @@ function resolveRouting(input) {
270
303
  harness
271
304
  };
272
305
  }
273
- const modelResolution = resolveModel(agentOverlay, categoryOverlay, harness);
274
- const qualifierResolution = resolvePiThinking(agentOverlay, categoryOverlay, piSubagentsOverlays, target);
306
+ const modelResolution = resolveModel(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, harness);
307
+ const qualifierResolution = resolvePiThinking(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, piSubagentsOverlays, target);
275
308
  return {
276
309
  model: modelResolution.value,
277
310
  qualifier: qualifierResolution.value,
@@ -1786,6 +1819,25 @@ var BUNDLED_SKILL_NAMES = [
1786
1819
  "writing-skills"
1787
1820
  ];
1788
1821
 
1822
+ // src/lib/config-protected-fields.ts
1823
+ var CONFIG_PROTECTED_FIELD_PATHS = [
1824
+ "workflow_guard",
1825
+ "profiles",
1826
+ "allow_project_profiles",
1827
+ "agents.*.model",
1828
+ "agents.*.permission",
1829
+ "agents.*.skills",
1830
+ "agents.*.variant",
1831
+ "agents.*.opencode",
1832
+ "agents.*.pi",
1833
+ "categories.*.model",
1834
+ "categories.*.permission",
1835
+ "categories.*.skills",
1836
+ "categories.*.variant",
1837
+ "categories.*.opencode",
1838
+ "categories.*.pi"
1839
+ ];
1840
+
1789
1841
  // node_modules/.bun/zod@4.6.5/node_modules/zod/v4/core/util.js
1790
1842
  function getEnumValues(entries) {
1791
1843
  const numericValues = Object.values(entries).filter((v) => typeof v === "number");
@@ -7989,7 +8041,7 @@ function createSystematicConfigSchema(opts) {
7989
8041
  examples: [{ review: { model: "anthropic/claude-opus-5" } }, {}]
7990
8042
  }),
7991
8043
  profiles: record(string(), createProfileBundleSchema(agentNames, qualifiedAgentIds)).default({}).meta({
7992
- description: "Named routing-only overlay bundles, selectable by name via the profile field. Only valid in user config or OPENCODE_CONFIG_DIR config \u2014 a project config may select a profile but may not define this field.",
8044
+ description: "Named routing-only overlay bundles, selectable by name via the profile field. Valid in user config and OPENCODE_CONFIG_DIR config. A project config may always select a profile, but may only define this field when the user sets allow_project_profiles; a project-defined bundle is advisory and fills only routing the user has not set.",
7993
8045
  examples: [
7994
8046
  {
7995
8047
  personal: {
@@ -8002,6 +8054,10 @@ function createSystematicConfigSchema(opts) {
8002
8054
  ]
8003
8055
  }),
8004
8056
  profile: profileSchema,
8057
+ allow_project_profiles: trustProtected(boolean().meta({
8058
+ description: "Allow a repository's project config to define its own `profiles` map. User-owned only \u2014 only valid in user config or OPENCODE_CONFIG_DIR config; a project config setting this field has it ignored (a project cannot grant itself a permission it does not already have). Defaults to false.",
8059
+ examples: [true, false]
8060
+ })).default(false),
8005
8061
  disabled_skills: array(_enum([...skillNames, ...removedSkillNames])).default([]).meta({
8006
8062
  description: "Array of bundled skill names to disable globally. Unknown skill names are rejected at parse time.",
8007
8063
  examples: [["ce:plan", "ce:review"]]
@@ -8079,7 +8135,8 @@ var DEFAULT_CONFIG = {
8079
8135
  agents: {},
8080
8136
  categories: {},
8081
8137
  pi_subagents: { categories: {}, agents: {} },
8082
- skills_as_commands: true
8138
+ skills_as_commands: true,
8139
+ allow_project_profiles: false
8083
8140
  };
8084
8141
  var PROTECTED_OVERLAY_FIELD_PATHS = {
8085
8142
  agents: {
@@ -8099,7 +8156,10 @@ var PROTECTED_OVERLAY_FIELD_PATHS = {
8099
8156
  pi: "categories.*.pi"
8100
8157
  }
8101
8158
  };
8102
- var PROJECT_PROTECTED_FIELDS = new Set(["workflow_guard", "profiles"]);
8159
+ var PROJECT_ALWAYS_PROTECTED_FIELDS = new Set([
8160
+ "workflow_guard",
8161
+ "allow_project_profiles"
8162
+ ]);
8103
8163
  var MAX_DIAGNOSTIC_TEXT = 200;
8104
8164
  var MAX_STRIP_WARNINGS = 20;
8105
8165
  var DIAGNOSTIC_ELLIPSIS = "\u2026";
@@ -8292,7 +8352,7 @@ ${formatted.map((entry) => ` - ${entry}`).join(`
8292
8352
  issues
8293
8353
  });
8294
8354
  }
8295
- function loadConfigSource(filePath, trust, invalidSource, warningSink) {
8355
+ function loadConfigSource(filePath, trust, invalidSource, warningSink, allowProjectProfiles) {
8296
8356
  try {
8297
8357
  const rawConfig = loadJsoncFile(filePath);
8298
8358
  if (!rawConfig) {
@@ -8301,8 +8361,8 @@ function loadConfigSource(filePath, trust, invalidSource, warningSink) {
8301
8361
  source: null
8302
8362
  };
8303
8363
  }
8304
- const protectedFields = collectProjectProtectedFields(rawConfig, trust);
8305
- const topLevelStripped = trust === "project" ? stripProjectProtectedFields(rawConfig) : rawConfig;
8364
+ const protectedFields = collectProjectProtectedFields(rawConfig, trust, allowProjectProfiles);
8365
+ const topLevelStripped = trust === "project" ? stripProjectProtectedFields(rawConfig, allowProjectProfiles) : rawConfig;
8306
8366
  const config = trust === "project" ? stripProjectSecurityOverlayFields(topLevelStripped, filePath, warningSink) : topLevelStripped;
8307
8367
  const result = SystematicConfigSchema.safeParse(config);
8308
8368
  if (!result.success) {
@@ -8353,7 +8413,14 @@ function resolveConfigSourcePath(filePath) {
8353
8413
  return path.resolve(filePath);
8354
8414
  }
8355
8415
  }
8356
- function collectProjectProtectedFields(rawConfig, trust) {
8416
+ function emitTopLevelProtectedFieldWarning(projectSource, fieldPath, messageTemplate, sink) {
8417
+ if (!projectSource?.protectedFields.some((field) => field.fieldPath === fieldPath)) {
8418
+ return;
8419
+ }
8420
+ const safePath = sanitizeDiagnosticText(projectSource.path);
8421
+ sink(`[systematic] ${messageTemplate.replace("%PATH%", safePath)}`);
8422
+ }
8423
+ function collectProjectProtectedFields(rawConfig, trust, allowProjectProfiles) {
8357
8424
  if (trust !== "project")
8358
8425
  return [];
8359
8426
  return [
@@ -8364,13 +8431,20 @@ function collectProjectProtectedFields(rawConfig, trust) {
8364
8431
  sourceKind: "project"
8365
8432
  }
8366
8433
  ] : [],
8367
- ...Object.hasOwn(rawConfig, "profiles") ? [
8434
+ ...!allowProjectProfiles && Object.hasOwn(rawConfig, "profiles") ? [
8368
8435
  {
8369
8436
  fieldPath: "profiles",
8370
8437
  outcome: "blocked",
8371
8438
  sourceKind: "project"
8372
8439
  }
8373
8440
  ] : [],
8441
+ ...Object.hasOwn(rawConfig, "allow_project_profiles") ? [
8442
+ {
8443
+ fieldPath: "allow_project_profiles",
8444
+ outcome: "blocked",
8445
+ sourceKind: "project"
8446
+ }
8447
+ ] : [],
8374
8448
  ...collectOverlayProtectedFields(rawConfig.agents, "agents"),
8375
8449
  ...collectOverlayProtectedFields(rawConfig.categories, "categories")
8376
8450
  ];
@@ -8387,11 +8461,14 @@ function collectProtectedOverlayValue(value, mapKey) {
8387
8461
  sourceKind: "project"
8388
8462
  }));
8389
8463
  }
8390
- function stripProjectProtectedFields(rawConfig) {
8464
+ function stripProjectProtectedFields(rawConfig, allowProjectProfiles) {
8391
8465
  const config = { ...rawConfig };
8392
- for (const field of PROJECT_PROTECTED_FIELDS) {
8466
+ for (const field of PROJECT_ALWAYS_PROTECTED_FIELDS) {
8393
8467
  delete config[field];
8394
8468
  }
8469
+ if (!allowProjectProfiles) {
8470
+ delete config.profiles;
8471
+ }
8395
8472
  return config;
8396
8473
  }
8397
8474
  function stripProjectSecurityOverlayFields(rawConfig, filePath, warningSink) {
@@ -8478,6 +8555,12 @@ function lookupProfileBundle(input, name) {
8478
8555
  return { bundle, definingSource: input.userSource };
8479
8556
  }
8480
8557
  }
8558
+ if (input.allowProjectProfiles && input.projectSource) {
8559
+ const bundle = input.projectSource.config.profiles?.[name];
8560
+ if (bundle !== undefined) {
8561
+ return { bundle, definingSource: input.projectSource };
8562
+ }
8563
+ }
8481
8564
  return;
8482
8565
  }
8483
8566
  function trustedDefaultProfileName(input) {
@@ -8586,6 +8669,19 @@ function buildAliasSuccessNotice(input) {
8586
8669
  warningSink(`[systematic] project config (${sanitizeDiagnosticText(projectConfigPath)}) and custom config (${sanitizeDiagnosticText(aliasedCustomConfigPath)}) resolve to the same file; protected fields stripped from the project pass (security-overlay fields, \`profiles\`, \`workflow_guard\`) apply through the custom-trust pass instead.`);
8587
8670
  };
8588
8671
  }
8672
+ function loadUserAndCustomSources(paths, invalidSource, warningSink) {
8673
+ const user = loadConfigSource(paths.userConfig, "user", invalidSource, warningSink, false);
8674
+ const custom = paths.customConfig ? loadConfigSource(paths.customConfig, "custom", invalidSource, warningSink, false) : {
8675
+ metadata: { kind: "custom", presence: "absent" },
8676
+ source: null
8677
+ };
8678
+ const allowProjectProfiles = custom.source?.config.allow_project_profiles ?? user.source?.config.allow_project_profiles ?? DEFAULT_CONFIG.allow_project_profiles;
8679
+ return { user, custom, allowProjectProfiles };
8680
+ }
8681
+ function buildOverlaySources(profileEntry, bundleSourceTrust, userSource, projectSource, customSource) {
8682
+ const ordered = profileEntry !== null && bundleSourceTrust === "project" ? [profileEntry, userSource, projectSource, customSource] : [userSource, profileEntry, projectSource, customSource];
8683
+ return ordered.filter((source) => source !== null);
8684
+ }
8589
8685
  function loadConfigWithSources(projectDir, options) {
8590
8686
  const includeProject = options?.includeProject ?? true;
8591
8687
  const invalidSource = options?.invalidSource ?? "throw";
@@ -8594,21 +8690,16 @@ function loadConfigWithSources(projectDir, options) {
8594
8690
  const aliasedCustomConfigPath = resolveAliasedCustomConfigPath(paths, includeProject);
8595
8691
  const projectStrip = createAliasStripTracker(warningSink, aliasedCustomConfigPath);
8596
8692
  const boundedProjectStrip = createBoundedStripWarningSink(projectStrip.sink);
8597
- const user = loadConfigSource(paths.userConfig, "user", invalidSource, warningSink);
8598
- const project = includeProject ? loadConfigSource(paths.projectConfig, "project", invalidSource, boundedProjectStrip.sink) : {
8693
+ const { user, custom, allowProjectProfiles } = loadUserAndCustomSources(paths, invalidSource, warningSink);
8694
+ const userSource = user.source;
8695
+ const customSource = custom.source;
8696
+ const project = includeProject ? loadConfigSource(paths.projectConfig, "project", invalidSource, boundedProjectStrip.sink, allowProjectProfiles) : {
8599
8697
  metadata: { kind: "project", presence: "absent" },
8600
8698
  source: null
8601
8699
  };
8602
- const custom = paths.customConfig ? loadConfigSource(paths.customConfig, "custom", invalidSource, warningSink) : {
8603
- metadata: { kind: "custom", presence: "absent" },
8604
- source: null
8605
- };
8606
- const userSource = user.source;
8607
8700
  const projectSource = project.source;
8608
- const customSource = custom.source;
8609
- if (projectSource?.protectedFields.some((field) => field.fieldPath === "profiles")) {
8610
- boundedProjectStrip.sink(`[systematic] \`profiles\` in project config (${sanitizeDiagnosticText(projectSource.path)}) is only valid in user config or OPENCODE_CONFIG_DIR config and has been ignored. Its bundles are not selectable even if this project also sets \`profile\`.`);
8611
- }
8701
+ emitTopLevelProtectedFieldWarning(projectSource, "profiles", `\`profiles\` in project config (%PATH%) is only valid in user config or OPENCODE_CONFIG_DIR config and has been ignored. Its bundles are not selectable even if this project also sets \`profile\`.`, boundedProjectStrip.sink);
8702
+ emitTopLevelProtectedFieldWarning(projectSource, "allow_project_profiles", `\`allow_project_profiles\` in project config (%PATH%) is only valid in user config or OPENCODE_CONFIG_DIR config and has been ignored.`, boundedProjectStrip.sink);
8612
8703
  const suppressedStripCount = boundedProjectStrip.suppressedCount();
8613
8704
  if (suppressedStripCount > 0) {
8614
8705
  projectStrip.sink(`[systematic] ${suppressedStripCount} additional project-config protected-field warning(s) in (${sanitizeDiagnosticText(paths.projectConfig)}) were suppressed.`);
@@ -8635,13 +8726,15 @@ function loadConfigWithSources(projectDir, options) {
8635
8726
  const projectConfig = projectSource?.config;
8636
8727
  const customConfig = customSource?.config;
8637
8728
  const warned = new Set;
8638
- assertAllProfileBundlesAreValid(userConfig, customConfig);
8729
+ assertAllProfileBundlesAreValid(userConfig, customConfig, projectConfig);
8639
8730
  const profileSelection = resolveActiveProfile({
8640
8731
  userConfig,
8641
8732
  userSource,
8642
8733
  projectConfig,
8734
+ projectSource,
8643
8735
  customConfig,
8644
8736
  customSource,
8737
+ allowProjectProfiles,
8645
8738
  warningSink
8646
8739
  });
8647
8740
  const profileEntry = profileSelection.bundle && profileSelection.bundleSource && typeof profileSelection.activeProfile === "string" ? {
@@ -8653,14 +8746,10 @@ function loadConfigWithSources(projectDir, options) {
8653
8746
  categories: profileSelection.bundle.categories
8654
8747
  },
8655
8748
  protectedFields: [],
8656
- profileName: profileSelection.activeProfile
8749
+ profileName: profileSelection.activeProfile,
8750
+ bundleTrust: profileSelection.bundleSource.trust
8657
8751
  } : null;
8658
- const overlaySources = [
8659
- userSource,
8660
- profileEntry,
8661
- projectSource,
8662
- customSource
8663
- ].filter((source) => source !== null);
8752
+ const overlaySources = buildOverlaySources(profileEntry, profileSelection.bundleSource?.trust, userSource, projectSource, customSource);
8664
8753
  const mergedOverlays = mergeOverlaySources(overlaySources);
8665
8754
  const mergedPiSubagentsOverlays = mergePiSubagentsOverlaySources(sources);
8666
8755
  const droppedCategories = Object.keys(mergedOverlays.categories).filter((name) => REMOVED_AGENT_CATEGORIES_SET.has(name));
@@ -8693,7 +8782,8 @@ function loadConfigWithSources(projectDir, options) {
8693
8782
  categories: overlayValues(mergedPiSubagentsOverlays.categories),
8694
8783
  agents: overlayValues(mergedPiSubagentsOverlays.agents)
8695
8784
  },
8696
- skills_as_commands: customConfig?.skills_as_commands ?? projectConfig?.skills_as_commands ?? userConfig?.skills_as_commands ?? DEFAULT_CONFIG.skills_as_commands
8785
+ skills_as_commands: customConfig?.skills_as_commands ?? projectConfig?.skills_as_commands ?? userConfig?.skills_as_commands ?? DEFAULT_CONFIG.skills_as_commands,
8786
+ allow_project_profiles: customConfig?.allow_project_profiles ?? userConfig?.allow_project_profiles ?? DEFAULT_CONFIG.allow_project_profiles
8697
8787
  };
8698
8788
  const droppedSkills = computeDroppedNames(result.disabled_skills, CURRENT_SKILL_NAMES_SET);
8699
8789
  warnDroppedNames(droppedSkills, "disabled_skills", warned, undefined, warningSink);
@@ -8717,7 +8807,8 @@ function loadConfigWithSources(projectDir, options) {
8717
8807
  user: user.metadata
8718
8808
  }),
8719
8809
  overlays,
8720
- piSubagentsOverlays: mergedPiSubagentsOverlays
8810
+ piSubagentsOverlays: mergedPiSubagentsOverlays,
8811
+ activeProfileSourcePath: profileSelection.bundleSource?.path ?? null
8721
8812
  };
8722
8813
  }
8723
8814
  function buildConfigObservationMetadata(summary) {
@@ -8834,8 +8925,8 @@ function assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle
8834
8925
  }
8835
8926
  }
8836
8927
  }
8837
- function assertAllProfileBundlesAreValid(userConfig, customConfig) {
8838
- for (const config of [userConfig, customConfig]) {
8928
+ function assertAllProfileBundlesAreValid(userConfig, customConfig, projectConfig) {
8929
+ for (const config of [userConfig, customConfig, projectConfig]) {
8839
8930
  for (const [profileName, bundle] of Object.entries(config?.profiles ?? {})) {
8840
8931
  assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle);
8841
8932
  }
@@ -8883,13 +8974,50 @@ function mergeOverlayMap(target, source, mapKey) {
8883
8974
  }
8884
8975
  const previous = target[key];
8885
8976
  const nextValue = resolveOverlayEntryValue(previous?.value, value, source);
8977
+ const nextOrigins = resolveOverlayEntryOrigin(previous?.origins, value, source);
8886
8978
  target[key] = {
8887
8979
  value: nextValue,
8888
8980
  sourcePath: source.path,
8889
- keyPath
8981
+ keyPath,
8982
+ origins: nextOrigins
8890
8983
  };
8891
8984
  }
8892
8985
  }
8986
+ function originForSource(source) {
8987
+ if (source.kind === "profile-bundle") {
8988
+ return `${source.bundleTrust}-profile`;
8989
+ }
8990
+ return source.trust;
8991
+ }
8992
+ function routingOriginsFromOwnFields(fragment, tag) {
8993
+ const origins = {};
8994
+ if (Object.hasOwn(fragment, "model"))
8995
+ origins.model = tag;
8996
+ if (Object.hasOwn(fragment, "variant"))
8997
+ origins.variant = tag;
8998
+ const opencodeBlock = fragment.opencode;
8999
+ if (isRecord2(opencodeBlock)) {
9000
+ if (Object.hasOwn(opencodeBlock, "model"))
9001
+ origins.opencodeModel = tag;
9002
+ if (Object.hasOwn(opencodeBlock, "variant"))
9003
+ origins.opencodeVariant = tag;
9004
+ }
9005
+ const piBlock = fragment.pi;
9006
+ if (isRecord2(piBlock)) {
9007
+ if (Object.hasOwn(piBlock, "model"))
9008
+ origins.piModel = tag;
9009
+ if (Object.hasOwn(piBlock, "thinking"))
9010
+ origins.piThinking = tag;
9011
+ }
9012
+ return origins;
9013
+ }
9014
+ function resolveOverlayEntryOrigin(previous, fragment, source) {
9015
+ const own = routingOriginsFromOwnFields(fragment, originForSource(source));
9016
+ if (!previous)
9017
+ return own;
9018
+ const preserves = source.kind === "profile-bundle" || source.trust === "project" || source.trust === "user";
9019
+ return preserves ? { ...previous, ...own } : own;
9020
+ }
8893
9021
  function resolveOverlayEntryValue(previous, next, source) {
8894
9022
  if (!previous)
8895
9023
  return next;
@@ -8898,6 +9026,8 @@ function resolveOverlayEntryValue(previous, next, source) {
8898
9026
  }
8899
9027
  if (source.trust === "project")
8900
9028
  return preserveSecurityFields(previous, next);
9029
+ if (source.trust === "user")
9030
+ return mergeProfileOverlayValue(previous, next);
8901
9031
  return next;
8902
9032
  }
8903
9033
  function stripProjectSecurityOverlay(sourcePath, keyPath, value, warningSink) {
@@ -9353,4 +9483,4 @@ function discoverSkills(options) {
9353
9483
  return Array.from(byName.values());
9354
9484
  }
9355
9485
 
9356
- export { parseFrontmatter, parse, parseTree, modify, applyEdits, _isoDateTime, _isoDate, _isoTime, _isoDuration, string, ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration, number, boolean, array, object, union, discriminatedUnion, record, _enum, literal, AgentOverlaySchema, CategoryOverlaySchema, isRecord, extractString, toSourcedPiSubagentsOverlays, resolveRouting, loadConfig, loadConfigWithSources, collectRoutingTargets, getConfigPaths, isDiscoverableMarkdown, findAgentsInDir, extractAgentFrontmatter, findCommandsInDir, extractCommandFrontmatter, findSkillsInDir, discoverSkills };
9486
+ export { parseFrontmatter, parse, parseTree, modify, applyEdits, CONFIG_PROTECTED_FIELD_PATHS, _isoDateTime, _isoDate, _isoTime, _isoDuration, string, ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration, number, boolean, array, object, union, discriminatedUnion, record, _enum, literal, AgentOverlaySchema, CategoryOverlaySchema, isRecord, extractString, toSourcedPiSubagentsOverlays, resolveRouting, loadConfig, loadConfigWithSources, collectRoutingTargets, getConfigPaths, isDiscoverableMarkdown, findAgentsInDir, extractAgentFrontmatter, findCommandsInDir, extractCommandFrontmatter, findSkillsInDir, discoverSkills };