@fro.bot/systematic 3.18.10 → 3.20.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-fpq5hwdt.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) {
@@ -8451,6 +8528,9 @@ var NO_PROFILE_SELECTION = {
8451
8528
  bundleSource: null
8452
8529
  };
8453
8530
  function resolveProfileSelector(input) {
8531
+ const envProfile = process.env.SYSTEMATIC_PROFILE?.trim();
8532
+ if (envProfile)
8533
+ return { value: envProfile, source: "environment" };
8454
8534
  const candidates = [
8455
8535
  ["custom", input.customConfig?.profile],
8456
8536
  ["project", input.projectConfig?.profile],
@@ -8475,12 +8555,21 @@ function lookupProfileBundle(input, name) {
8475
8555
  return { bundle, definingSource: input.userSource };
8476
8556
  }
8477
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
+ }
8478
8564
  return;
8479
8565
  }
8480
8566
  function trustedDefaultProfileName(input) {
8481
8567
  const userDefault = input.userConfig?.profile;
8482
8568
  return typeof userDefault === "string" ? userDefault : undefined;
8483
8569
  }
8570
+ function selectorSourceLabel(source) {
8571
+ return source === "environment" ? "SYSTEMATIC_PROFILE" : `${source} config`;
8572
+ }
8484
8573
  function resolveActiveProfile(input) {
8485
8574
  const selection = resolveProfileSelector(input);
8486
8575
  if (selection === null)
@@ -8508,7 +8597,7 @@ function resolveActiveProfile(input) {
8508
8597
  const trustedDefault = trustedDefaultProfileName(input);
8509
8598
  const fallbackLookup = trustedDefault !== undefined && trustedDefault !== requested ? lookupProfileBundle(input, trustedDefault) : undefined;
8510
8599
  if (fallbackLookup !== undefined && trustedDefault !== undefined) {
8511
- input.warningSink(`[systematic] profile "${sanitizeDiagnosticText(requested)}" (selected by ${selection.source} config) is not defined in \`profiles\`; falling back to your default profile "${sanitizeDiagnosticText(trustedDefault)}". See ${PROFILE_DOCS_URL} for how to define a profile.`);
8600
+ input.warningSink(`[systematic] profile "${sanitizeDiagnosticText(requested)}" (selected by ${selectorSourceLabel(selection.source)}) is not defined in \`profiles\`; falling back to your default profile "${sanitizeDiagnosticText(trustedDefault)}". See ${PROFILE_DOCS_URL} for how to define a profile.`);
8512
8601
  return {
8513
8602
  activeProfile: trustedDefault,
8514
8603
  profileSelectorSource: selection.source,
@@ -8517,7 +8606,7 @@ function resolveActiveProfile(input) {
8517
8606
  bundleSource: fallbackLookup.definingSource
8518
8607
  };
8519
8608
  }
8520
- const sourceNote = selection.source === "user" ? "" : ` (selected by ${selection.source} config)`;
8609
+ const sourceNote = selection.source === "user" ? "" : ` (selected by ${selectorSourceLabel(selection.source)})`;
8521
8610
  const alsoMissingNote = trustedDefault !== undefined && trustedDefault !== requested ? ` Your default profile "${sanitizeDiagnosticText(trustedDefault)}" is also not defined in \`profiles\`.` : trustedDefault === undefined ? " No default profile is configured (`profile` in your user config)." : "";
8522
8611
  input.warningSink(`[systematic] profile "${sanitizeDiagnosticText(requested)}"${sourceNote} is not defined in \`profiles\`; using base configuration (no profile).${alsoMissingNote} See ${PROFILE_DOCS_URL} for how to define a profile.`);
8523
8612
  return {
@@ -8580,6 +8669,19 @@ function buildAliasSuccessNotice(input) {
8580
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.`);
8581
8670
  };
8582
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
+ }
8583
8685
  function loadConfigWithSources(projectDir, options) {
8584
8686
  const includeProject = options?.includeProject ?? true;
8585
8687
  const invalidSource = options?.invalidSource ?? "throw";
@@ -8588,21 +8690,16 @@ function loadConfigWithSources(projectDir, options) {
8588
8690
  const aliasedCustomConfigPath = resolveAliasedCustomConfigPath(paths, includeProject);
8589
8691
  const projectStrip = createAliasStripTracker(warningSink, aliasedCustomConfigPath);
8590
8692
  const boundedProjectStrip = createBoundedStripWarningSink(projectStrip.sink);
8591
- const user = loadConfigSource(paths.userConfig, "user", invalidSource, warningSink);
8592
- 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) : {
8593
8697
  metadata: { kind: "project", presence: "absent" },
8594
8698
  source: null
8595
8699
  };
8596
- const custom = paths.customConfig ? loadConfigSource(paths.customConfig, "custom", invalidSource, warningSink) : {
8597
- metadata: { kind: "custom", presence: "absent" },
8598
- source: null
8599
- };
8600
- const userSource = user.source;
8601
8700
  const projectSource = project.source;
8602
- const customSource = custom.source;
8603
- if (projectSource?.protectedFields.some((field) => field.fieldPath === "profiles")) {
8604
- 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\`.`);
8605
- }
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);
8606
8703
  const suppressedStripCount = boundedProjectStrip.suppressedCount();
8607
8704
  if (suppressedStripCount > 0) {
8608
8705
  projectStrip.sink(`[systematic] ${suppressedStripCount} additional project-config protected-field warning(s) in (${sanitizeDiagnosticText(paths.projectConfig)}) were suppressed.`);
@@ -8629,13 +8726,15 @@ function loadConfigWithSources(projectDir, options) {
8629
8726
  const projectConfig = projectSource?.config;
8630
8727
  const customConfig = customSource?.config;
8631
8728
  const warned = new Set;
8632
- assertAllProfileBundlesAreValid(userConfig, customConfig);
8729
+ assertAllProfileBundlesAreValid(userConfig, customConfig, projectConfig);
8633
8730
  const profileSelection = resolveActiveProfile({
8634
8731
  userConfig,
8635
8732
  userSource,
8636
8733
  projectConfig,
8734
+ projectSource,
8637
8735
  customConfig,
8638
8736
  customSource,
8737
+ allowProjectProfiles,
8639
8738
  warningSink
8640
8739
  });
8641
8740
  const profileEntry = profileSelection.bundle && profileSelection.bundleSource && typeof profileSelection.activeProfile === "string" ? {
@@ -8647,14 +8746,10 @@ function loadConfigWithSources(projectDir, options) {
8647
8746
  categories: profileSelection.bundle.categories
8648
8747
  },
8649
8748
  protectedFields: [],
8650
- profileName: profileSelection.activeProfile
8749
+ profileName: profileSelection.activeProfile,
8750
+ bundleTrust: profileSelection.bundleSource.trust
8651
8751
  } : null;
8652
- const overlaySources = [
8653
- userSource,
8654
- profileEntry,
8655
- projectSource,
8656
- customSource
8657
- ].filter((source) => source !== null);
8752
+ const overlaySources = buildOverlaySources(profileEntry, profileSelection.bundleSource?.trust, userSource, projectSource, customSource);
8658
8753
  const mergedOverlays = mergeOverlaySources(overlaySources);
8659
8754
  const mergedPiSubagentsOverlays = mergePiSubagentsOverlaySources(sources);
8660
8755
  const droppedCategories = Object.keys(mergedOverlays.categories).filter((name) => REMOVED_AGENT_CATEGORIES_SET.has(name));
@@ -8687,7 +8782,8 @@ function loadConfigWithSources(projectDir, options) {
8687
8782
  categories: overlayValues(mergedPiSubagentsOverlays.categories),
8688
8783
  agents: overlayValues(mergedPiSubagentsOverlays.agents)
8689
8784
  },
8690
- 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
8691
8787
  };
8692
8788
  const droppedSkills = computeDroppedNames(result.disabled_skills, CURRENT_SKILL_NAMES_SET);
8693
8789
  warnDroppedNames(droppedSkills, "disabled_skills", warned, undefined, warningSink);
@@ -8711,7 +8807,8 @@ function loadConfigWithSources(projectDir, options) {
8711
8807
  user: user.metadata
8712
8808
  }),
8713
8809
  overlays,
8714
- piSubagentsOverlays: mergedPiSubagentsOverlays
8810
+ piSubagentsOverlays: mergedPiSubagentsOverlays,
8811
+ activeProfileSourcePath: profileSelection.bundleSource?.path ?? null
8715
8812
  };
8716
8813
  }
8717
8814
  function buildConfigObservationMetadata(summary) {
@@ -8828,8 +8925,8 @@ function assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle
8828
8925
  }
8829
8926
  }
8830
8927
  }
8831
- function assertAllProfileBundlesAreValid(userConfig, customConfig) {
8832
- for (const config of [userConfig, customConfig]) {
8928
+ function assertAllProfileBundlesAreValid(userConfig, customConfig, projectConfig) {
8929
+ for (const config of [userConfig, customConfig, projectConfig]) {
8833
8930
  for (const [profileName, bundle] of Object.entries(config?.profiles ?? {})) {
8834
8931
  assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle);
8835
8932
  }
@@ -8877,13 +8974,50 @@ function mergeOverlayMap(target, source, mapKey) {
8877
8974
  }
8878
8975
  const previous = target[key];
8879
8976
  const nextValue = resolveOverlayEntryValue(previous?.value, value, source);
8977
+ const nextOrigins = resolveOverlayEntryOrigin(previous?.origins, value, source);
8880
8978
  target[key] = {
8881
8979
  value: nextValue,
8882
8980
  sourcePath: source.path,
8883
- keyPath
8981
+ keyPath,
8982
+ origins: nextOrigins
8884
8983
  };
8885
8984
  }
8886
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
+ }
8887
9021
  function resolveOverlayEntryValue(previous, next, source) {
8888
9022
  if (!previous)
8889
9023
  return next;
@@ -8892,6 +9026,8 @@ function resolveOverlayEntryValue(previous, next, source) {
8892
9026
  }
8893
9027
  if (source.trust === "project")
8894
9028
  return preserveSecurityFields(previous, next);
9029
+ if (source.trust === "user")
9030
+ return mergeProfileOverlayValue(previous, next);
8895
9031
  return next;
8896
9032
  }
8897
9033
  function stripProjectSecurityOverlay(sourcePath, keyPath, value, warningSink) {
@@ -9347,4 +9483,4 @@ function discoverSkills(options) {
9347
9483
  return Array.from(byName.values());
9348
9484
  }
9349
9485
 
9350
- 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 };
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  extractCommandFrontmatter,
20
20
  findSkillsInDir,
21
21
  discoverSkills
22
- } from "./index-fpq5hwdt.js";
22
+ } from "./index-c17zm38x.js";
23
23
 
24
24
  // src/index.ts
25
25
  import { createHash as createHash4 } from "crypto";
@@ -1,9 +1,9 @@
1
+ import { CONFIG_PROTECTED_FIELD_PATHS } from './config-protected-fields.js';
1
2
  declare const CAPABILITY_SNAPSHOT_SCHEMA_VERSION: 'cli-capabilities.v1';
2
3
  declare const CAPABILITY_SNAPSHOT_COMMAND: 'systematic capabilities';
3
4
  declare const CAPABILITY_SOURCE_IDS: readonly ['config:custom', 'config:global', 'config:project', 'config:user', 'discovery:agents', 'discovery:skills', 'host:runtime', 'package'];
4
5
  declare const CONFIG_SOURCE_KINDS: readonly ['custom', 'project', 'user'];
5
6
  declare const CONFIG_AUTHORITY_FIELD_PATHS: readonly ['bootstrap.enabled', 'bootstrap.file', 'skills_as_commands', 'workflow_guard.debug', 'workflow_guard.mode'];
6
- declare const CONFIG_PROTECTED_FIELD_PATHS: readonly ['workflow_guard', 'profiles', 'agents.*.model', 'agents.*.permission', 'agents.*.skills', 'agents.*.variant', 'agents.*.opencode', 'agents.*.pi', 'categories.*.model', 'categories.*.permission', 'categories.*.skills', 'categories.*.variant', 'categories.*.opencode', 'categories.*.pi'];
7
7
  declare const CONFIG_SOURCE_ERROR_CODES: readonly ['parse-failed', 'read-failed', 'schema-invalid', 'source-invalid'];
8
8
  declare const CAPABILITY_SOURCE_PRESENCE: readonly ['absent', 'invalid', 'present'];
9
9
  declare const CAPABILITY_STATUSES: readonly ['available', 'unknown', 'unavailable'];
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The list of top-level and per-overlay field paths a project-trust config
3
+ * source can never set, expressed as dotted paths with `*` standing in for
4
+ * any overlay key (e.g. `agents.*.model`).
5
+ *
6
+ * Extracted into its own dependency-free module so `src/lib/capability-snapshot.ts`
7
+ * -- which is deliberately import-free so it never pulls in `jsonc-parser`
8
+ * or the rest of `config.ts`'s transitive dependency graph -- can share the
9
+ * exact same list `src/lib/config.ts` enforces at load time, instead of
10
+ * maintaining a hand-duplicated copy that can silently drift out of sync.
11
+ * A stale duplicate here once made every `systematic capabilities`
12
+ * invocation fail with a cause-less "Capabilities diagnostic unavailable"
13
+ * (see `SourceAwareConfigResult.activeProfileSourcePath`'s doc comment in
14
+ * `config.ts` for the incident this module exists to prevent from
15
+ * recurring).
16
+ *
17
+ * This module must import nothing, ever -- that constraint is the entire
18
+ * reason it exists as a separate file rather than living directly in
19
+ * `config.ts`.
20
+ */
21
+ export declare const CONFIG_PROTECTED_FIELD_PATHS: readonly ['workflow_guard', 'profiles', 'allow_project_profiles', 'agents.*.model', 'agents.*.permission', 'agents.*.skills', 'agents.*.variant', 'agents.*.opencode', 'agents.*.pi', 'categories.*.model', 'categories.*.permission', 'categories.*.skills', 'categories.*.variant', 'categories.*.opencode', 'categories.*.pi'];
22
+ export type ConfigProtectedFieldPath = (typeof CONFIG_PROTECTED_FIELD_PATHS)[number];
@@ -392,6 +392,7 @@ export declare function createSystematicConfigSchema(opts: SystematicConfigSchem
392
392
  }, z.core.$strict>>>;
393
393
  }, z.core.$strict>>>;
394
394
  profile: z.ZodOptional<z.ZodNullable<z.ZodString>>;
395
+ allow_project_profiles: z.ZodDefault<z.ZodBoolean>;
395
396
  disabled_skills: z.ZodDefault<z.ZodArray<z.ZodEnum<{
396
397
  [x: string]: string;
397
398
  }>>>;
@@ -593,6 +594,7 @@ export declare const SystematicConfigSchema: z.ZodObject<{
593
594
  }, z.core.$strict>>>;
594
595
  }, z.core.$strict>>>;
595
596
  profile: z.ZodOptional<z.ZodNullable<z.ZodString>>;
597
+ allow_project_profiles: z.ZodDefault<z.ZodBoolean>;
596
598
  disabled_skills: z.ZodDefault<z.ZodArray<z.ZodEnum<{
597
599
  [x: string]: string;
598
600
  }>>>;