@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/pi.js CHANGED
@@ -9657,7 +9657,7 @@ function createSystematicConfigSchema(opts) {
9657
9657
  examples: [{ review: { model: "anthropic/claude-opus-5" } }, {}]
9658
9658
  }),
9659
9659
  profiles: record(string2(), createProfileBundleSchema(agentNames, qualifiedAgentIds)).default({}).meta({
9660
- description: "Named routing-only overlay bundles, selectable by name via the profile field. Only valid in user config or OPENCODE_CONFIG_DIR config — a project config may select a profile but may not define this field.",
9660
+ 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.",
9661
9661
  examples: [
9662
9662
  {
9663
9663
  personal: {
@@ -9670,6 +9670,10 @@ function createSystematicConfigSchema(opts) {
9670
9670
  ]
9671
9671
  }),
9672
9672
  profile: profileSchema,
9673
+ allow_project_profiles: trustProtected(boolean2().meta({
9674
+ description: "Allow a repository's project config to define its own `profiles` map. User-owned only — 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.",
9675
+ examples: [true, false]
9676
+ })).default(false),
9673
9677
  disabled_skills: array(_enum([...skillNames, ...removedSkillNames])).default([]).meta({
9674
9678
  description: "Array of bundled skill names to disable globally. Unknown skill names are rejected at parse time.",
9675
9679
  examples: [["ce:plan", "ce:review"]]
@@ -9744,8 +9748,8 @@ function toSourcedPiSubagentsOverlays(map) {
9744
9748
  categories: toSourcedOverlayMap(map?.categories)
9745
9749
  };
9746
9750
  }
9747
- function lookupAgentOverlay(overlays, target) {
9748
- return getOverlayValue(overlays.agents, target.agentKey) ?? getOverlayValue(overlays.agents, `${target.category}/${target.agentKey}`);
9751
+ function lookupAgentOverlayEntry(overlays, target) {
9752
+ return overlays.agents[target.agentKey] ?? overlays.agents[`${target.category}/${target.agentKey}`];
9749
9753
  }
9750
9754
  function readBlockField(overlay, blockKey, field) {
9751
9755
  if (overlay === undefined)
@@ -9778,23 +9782,31 @@ function resolveField(candidates) {
9778
9782
  }
9779
9783
  return { value: undefined, source: undefined };
9780
9784
  }
9781
- function resolveModel(agentOverlay, categoryOverlay, harness) {
9785
+ function resolveModel(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, harness) {
9782
9786
  const { value, source } = resolveField([
9783
9787
  {
9784
9788
  value: readBlockField(agentOverlay, harness, "model"),
9785
- source: { level: "agent", form: "block" }
9789
+ source: { level: "agent", form: "block", origin: agentOrigins?.piModel }
9786
9790
  },
9787
9791
  {
9788
9792
  value: readFlatField(agentOverlay, "model"),
9789
- source: { level: "agent", form: "flat" }
9793
+ source: { level: "agent", form: "flat", origin: agentOrigins?.model }
9790
9794
  },
9791
9795
  {
9792
9796
  value: readBlockField(categoryOverlay, harness, "model"),
9793
- source: { level: "category", form: "block" }
9797
+ source: {
9798
+ level: "category",
9799
+ form: "block",
9800
+ origin: categoryOrigins?.piModel
9801
+ }
9794
9802
  },
9795
9803
  {
9796
9804
  value: readFlatField(categoryOverlay, "model"),
9797
- source: { level: "category", form: "flat" }
9805
+ source: {
9806
+ level: "category",
9807
+ form: "flat",
9808
+ origin: categoryOrigins?.model
9809
+ }
9798
9810
  }
9799
9811
  ]);
9800
9812
  const narrowedValue = narrowModelValue(value);
@@ -9813,13 +9825,23 @@ function readOpencodeLayerField(agentOverlay, categoryOverlay, layer, field) {
9813
9825
  const overlay = layer.level === "agent" ? agentOverlay : categoryOverlay;
9814
9826
  return layer.form === "block" ? readBlockField(overlay, "opencode", field) : readFlatField(overlay, field);
9815
9827
  }
9816
- function resolveOpencodeModelAndVariant(agentOverlay, categoryOverlay) {
9828
+ function readOpencodeLayerOrigin(agentOrigins, categoryOrigins, layer, field) {
9829
+ const origins = layer.level === "agent" ? agentOrigins : categoryOrigins;
9830
+ if (field === "model") {
9831
+ return layer.form === "block" ? origins?.opencodeModel : origins?.model;
9832
+ }
9833
+ return layer.form === "block" ? origins?.opencodeVariant : origins?.variant;
9834
+ }
9835
+ function resolveOpencodeModelAndVariant(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins) {
9817
9836
  const modelLayerIndex = OPENCODE_MODEL_VARIANT_LAYERS.findIndex((layer) => readOpencodeLayerField(agentOverlay, categoryOverlay, layer, "model") !== undefined);
9818
9837
  const modelLayer = modelLayerIndex === -1 ? undefined : OPENCODE_MODEL_VARIANT_LAYERS[modelLayerIndex];
9819
9838
  const rawModel = modelLayer === undefined ? undefined : readOpencodeLayerField(agentOverlay, categoryOverlay, modelLayer, "model");
9820
9839
  const model = narrowModelValue(rawModel);
9821
9840
  const hasModel = model !== undefined;
9822
- const modelSource = hasModel ? OPENCODE_MODEL_VARIANT_LAYERS[modelLayerIndex] : undefined;
9841
+ const modelSource = hasModel && modelLayer !== undefined ? {
9842
+ ...modelLayer,
9843
+ origin: readOpencodeLayerOrigin(agentOrigins, categoryOrigins, modelLayer, "model")
9844
+ } : undefined;
9823
9845
  let qualifier;
9824
9846
  let qualifierSource;
9825
9847
  if (model !== null) {
@@ -9828,22 +9850,33 @@ function resolveOpencodeModelAndVariant(agentOverlay, categoryOverlay) {
9828
9850
  const narrowed = narrowQualifierValue(readOpencodeLayerField(agentOverlay, categoryOverlay, layer, "variant"));
9829
9851
  if (narrowed !== undefined) {
9830
9852
  qualifier = narrowed;
9831
- qualifierSource = layer;
9853
+ qualifierSource = {
9854
+ ...layer,
9855
+ origin: readOpencodeLayerOrigin(agentOrigins, categoryOrigins, layer, "variant")
9856
+ };
9832
9857
  break;
9833
9858
  }
9834
9859
  }
9835
9860
  }
9836
9861
  return { model, modelSource, qualifier, qualifierSource };
9837
9862
  }
9838
- function resolvePiThinking(agentOverlay, categoryOverlay, piSubagentsOverlays, target) {
9863
+ function resolvePiThinking(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, piSubagentsOverlays, target) {
9839
9864
  const blockResolution = resolveField([
9840
9865
  {
9841
9866
  value: readBlockField(agentOverlay, "pi", "thinking"),
9842
- source: { level: "agent", form: "block" }
9867
+ source: {
9868
+ level: "agent",
9869
+ form: "block",
9870
+ origin: agentOrigins?.piThinking
9871
+ }
9843
9872
  },
9844
9873
  {
9845
9874
  value: readBlockField(categoryOverlay, "pi", "thinking"),
9846
- source: { level: "category", form: "block" }
9875
+ source: {
9876
+ level: "category",
9877
+ form: "block",
9878
+ origin: categoryOrigins?.piThinking
9879
+ }
9847
9880
  }
9848
9881
  ]);
9849
9882
  const legacyAgentThinking = getOverlayValue(piSubagentsOverlays.agents, target.agentKey)?.thinking;
@@ -9873,10 +9906,14 @@ function resolvePiThinking(agentOverlay, categoryOverlay, piSubagentsOverlays, t
9873
9906
  }
9874
9907
  function resolveRouting(input) {
9875
9908
  const { overlays, piSubagentsOverlays, target, harness } = input;
9876
- const agentOverlay = lookupAgentOverlay(overlays, target);
9877
- const categoryOverlay = getOverlayValue(overlays.categories, target.category);
9909
+ const agentEntry = lookupAgentOverlayEntry(overlays, target);
9910
+ const categoryEntry = overlays.categories[target.category];
9911
+ const agentOverlay = agentEntry?.value;
9912
+ const categoryOverlay = categoryEntry?.value;
9913
+ const agentOrigins = agentEntry?.origins;
9914
+ const categoryOrigins = categoryEntry?.origins;
9878
9915
  if (harness === "opencode") {
9879
- const resolution = resolveOpencodeModelAndVariant(agentOverlay, categoryOverlay);
9916
+ const resolution = resolveOpencodeModelAndVariant(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins);
9880
9917
  return {
9881
9918
  model: resolution.model,
9882
9919
  qualifier: resolution.qualifier,
@@ -9888,8 +9925,8 @@ function resolveRouting(input) {
9888
9925
  harness
9889
9926
  };
9890
9927
  }
9891
- const modelResolution = resolveModel(agentOverlay, categoryOverlay, harness);
9892
- const qualifierResolution = resolvePiThinking(agentOverlay, categoryOverlay, piSubagentsOverlays, target);
9928
+ const modelResolution = resolveModel(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, harness);
9929
+ const qualifierResolution = resolvePiThinking(agentOverlay, agentOrigins, categoryOverlay, categoryOrigins, piSubagentsOverlays, target);
9893
9930
  return {
9894
9931
  model: modelResolution.value,
9895
9932
  qualifier: qualifierResolution.value,
@@ -9946,7 +9983,8 @@ var DEFAULT_CONFIG = {
9946
9983
  agents: {},
9947
9984
  categories: {},
9948
9985
  pi_subagents: { categories: {}, agents: {} },
9949
- skills_as_commands: true
9986
+ skills_as_commands: true,
9987
+ allow_project_profiles: false
9950
9988
  };
9951
9989
  var PROTECTED_OVERLAY_FIELD_PATHS = {
9952
9990
  agents: {
@@ -9966,7 +10004,10 @@ var PROTECTED_OVERLAY_FIELD_PATHS = {
9966
10004
  pi: "categories.*.pi"
9967
10005
  }
9968
10006
  };
9969
- var PROJECT_PROTECTED_FIELDS = new Set(["workflow_guard", "profiles"]);
10007
+ var PROJECT_ALWAYS_PROTECTED_FIELDS = new Set([
10008
+ "workflow_guard",
10009
+ "allow_project_profiles"
10010
+ ]);
9970
10011
  var MAX_DIAGNOSTIC_TEXT = 200;
9971
10012
  var MAX_STRIP_WARNINGS = 20;
9972
10013
  var DIAGNOSTIC_ELLIPSIS = "…";
@@ -10159,7 +10200,7 @@ ${formatted.map((entry) => ` - ${entry}`).join(`
10159
10200
  issues
10160
10201
  });
10161
10202
  }
10162
- function loadConfigSource(filePath, trust, invalidSource, warningSink) {
10203
+ function loadConfigSource(filePath, trust, invalidSource, warningSink, allowProjectProfiles) {
10163
10204
  try {
10164
10205
  const rawConfig = loadJsoncFile(filePath);
10165
10206
  if (!rawConfig) {
@@ -10168,8 +10209,8 @@ function loadConfigSource(filePath, trust, invalidSource, warningSink) {
10168
10209
  source: null
10169
10210
  };
10170
10211
  }
10171
- const protectedFields = collectProjectProtectedFields(rawConfig, trust);
10172
- const topLevelStripped = trust === "project" ? stripProjectProtectedFields(rawConfig) : rawConfig;
10212
+ const protectedFields = collectProjectProtectedFields(rawConfig, trust, allowProjectProfiles);
10213
+ const topLevelStripped = trust === "project" ? stripProjectProtectedFields(rawConfig, allowProjectProfiles) : rawConfig;
10173
10214
  const config = trust === "project" ? stripProjectSecurityOverlayFields(topLevelStripped, filePath, warningSink) : topLevelStripped;
10174
10215
  const result = SystematicConfigSchema.safeParse(config);
10175
10216
  if (!result.success) {
@@ -10220,7 +10261,14 @@ function resolveConfigSourcePath(filePath) {
10220
10261
  return path3.resolve(filePath);
10221
10262
  }
10222
10263
  }
10223
- function collectProjectProtectedFields(rawConfig, trust) {
10264
+ function emitTopLevelProtectedFieldWarning(projectSource, fieldPath, messageTemplate, sink) {
10265
+ if (!projectSource?.protectedFields.some((field) => field.fieldPath === fieldPath)) {
10266
+ return;
10267
+ }
10268
+ const safePath = sanitizeDiagnosticText(projectSource.path);
10269
+ sink(`[systematic] ${messageTemplate.replace("%PATH%", safePath)}`);
10270
+ }
10271
+ function collectProjectProtectedFields(rawConfig, trust, allowProjectProfiles) {
10224
10272
  if (trust !== "project")
10225
10273
  return [];
10226
10274
  return [
@@ -10231,13 +10279,20 @@ function collectProjectProtectedFields(rawConfig, trust) {
10231
10279
  sourceKind: "project"
10232
10280
  }
10233
10281
  ] : [],
10234
- ...Object.hasOwn(rawConfig, "profiles") ? [
10282
+ ...!allowProjectProfiles && Object.hasOwn(rawConfig, "profiles") ? [
10235
10283
  {
10236
10284
  fieldPath: "profiles",
10237
10285
  outcome: "blocked",
10238
10286
  sourceKind: "project"
10239
10287
  }
10240
10288
  ] : [],
10289
+ ...Object.hasOwn(rawConfig, "allow_project_profiles") ? [
10290
+ {
10291
+ fieldPath: "allow_project_profiles",
10292
+ outcome: "blocked",
10293
+ sourceKind: "project"
10294
+ }
10295
+ ] : [],
10241
10296
  ...collectOverlayProtectedFields(rawConfig.agents, "agents"),
10242
10297
  ...collectOverlayProtectedFields(rawConfig.categories, "categories")
10243
10298
  ];
@@ -10254,11 +10309,14 @@ function collectProtectedOverlayValue(value, mapKey) {
10254
10309
  sourceKind: "project"
10255
10310
  }));
10256
10311
  }
10257
- function stripProjectProtectedFields(rawConfig) {
10312
+ function stripProjectProtectedFields(rawConfig, allowProjectProfiles) {
10258
10313
  const config = { ...rawConfig };
10259
- for (const field of PROJECT_PROTECTED_FIELDS) {
10314
+ for (const field of PROJECT_ALWAYS_PROTECTED_FIELDS) {
10260
10315
  delete config[field];
10261
10316
  }
10317
+ if (!allowProjectProfiles) {
10318
+ delete config.profiles;
10319
+ }
10262
10320
  return config;
10263
10321
  }
10264
10322
  function stripProjectSecurityOverlayFields(rawConfig, filePath, warningSink) {
@@ -10345,6 +10403,12 @@ function lookupProfileBundle(input, name) {
10345
10403
  return { bundle, definingSource: input.userSource };
10346
10404
  }
10347
10405
  }
10406
+ if (input.allowProjectProfiles && input.projectSource) {
10407
+ const bundle = input.projectSource.config.profiles?.[name];
10408
+ if (bundle !== undefined) {
10409
+ return { bundle, definingSource: input.projectSource };
10410
+ }
10411
+ }
10348
10412
  return;
10349
10413
  }
10350
10414
  function trustedDefaultProfileName(input) {
@@ -10450,6 +10514,19 @@ function buildAliasSuccessNotice(input) {
10450
10514
  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.`);
10451
10515
  };
10452
10516
  }
10517
+ function loadUserAndCustomSources(paths, invalidSource, warningSink) {
10518
+ const user = loadConfigSource(paths.userConfig, "user", invalidSource, warningSink, false);
10519
+ const custom = paths.customConfig ? loadConfigSource(paths.customConfig, "custom", invalidSource, warningSink, false) : {
10520
+ metadata: { kind: "custom", presence: "absent" },
10521
+ source: null
10522
+ };
10523
+ const allowProjectProfiles = custom.source?.config.allow_project_profiles ?? user.source?.config.allow_project_profiles ?? DEFAULT_CONFIG.allow_project_profiles;
10524
+ return { user, custom, allowProjectProfiles };
10525
+ }
10526
+ function buildOverlaySources(profileEntry, bundleSourceTrust, userSource, projectSource, customSource) {
10527
+ const ordered = profileEntry !== null && bundleSourceTrust === "project" ? [profileEntry, userSource, projectSource, customSource] : [userSource, profileEntry, projectSource, customSource];
10528
+ return ordered.filter((source) => source !== null);
10529
+ }
10453
10530
  function loadConfigWithSources(projectDir, options) {
10454
10531
  const includeProject = options?.includeProject ?? true;
10455
10532
  const invalidSource = options?.invalidSource ?? "throw";
@@ -10458,21 +10535,16 @@ function loadConfigWithSources(projectDir, options) {
10458
10535
  const aliasedCustomConfigPath = resolveAliasedCustomConfigPath(paths, includeProject);
10459
10536
  const projectStrip = createAliasStripTracker(warningSink, aliasedCustomConfigPath);
10460
10537
  const boundedProjectStrip = createBoundedStripWarningSink(projectStrip.sink);
10461
- const user = loadConfigSource(paths.userConfig, "user", invalidSource, warningSink);
10462
- const project = includeProject ? loadConfigSource(paths.projectConfig, "project", invalidSource, boundedProjectStrip.sink) : {
10538
+ const { user, custom, allowProjectProfiles } = loadUserAndCustomSources(paths, invalidSource, warningSink);
10539
+ const userSource = user.source;
10540
+ const customSource = custom.source;
10541
+ const project = includeProject ? loadConfigSource(paths.projectConfig, "project", invalidSource, boundedProjectStrip.sink, allowProjectProfiles) : {
10463
10542
  metadata: { kind: "project", presence: "absent" },
10464
10543
  source: null
10465
10544
  };
10466
- const custom = paths.customConfig ? loadConfigSource(paths.customConfig, "custom", invalidSource, warningSink) : {
10467
- metadata: { kind: "custom", presence: "absent" },
10468
- source: null
10469
- };
10470
- const userSource = user.source;
10471
10545
  const projectSource = project.source;
10472
- const customSource = custom.source;
10473
- if (projectSource?.protectedFields.some((field) => field.fieldPath === "profiles")) {
10474
- 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\`.`);
10475
- }
10546
+ 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);
10547
+ 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);
10476
10548
  const suppressedStripCount = boundedProjectStrip.suppressedCount();
10477
10549
  if (suppressedStripCount > 0) {
10478
10550
  projectStrip.sink(`[systematic] ${suppressedStripCount} additional project-config protected-field warning(s) in (${sanitizeDiagnosticText(paths.projectConfig)}) were suppressed.`);
@@ -10499,13 +10571,15 @@ function loadConfigWithSources(projectDir, options) {
10499
10571
  const projectConfig = projectSource?.config;
10500
10572
  const customConfig = customSource?.config;
10501
10573
  const warned = new Set;
10502
- assertAllProfileBundlesAreValid(userConfig, customConfig);
10574
+ assertAllProfileBundlesAreValid(userConfig, customConfig, projectConfig);
10503
10575
  const profileSelection = resolveActiveProfile({
10504
10576
  userConfig,
10505
10577
  userSource,
10506
10578
  projectConfig,
10579
+ projectSource,
10507
10580
  customConfig,
10508
10581
  customSource,
10582
+ allowProjectProfiles,
10509
10583
  warningSink
10510
10584
  });
10511
10585
  const profileEntry = profileSelection.bundle && profileSelection.bundleSource && typeof profileSelection.activeProfile === "string" ? {
@@ -10517,14 +10591,10 @@ function loadConfigWithSources(projectDir, options) {
10517
10591
  categories: profileSelection.bundle.categories
10518
10592
  },
10519
10593
  protectedFields: [],
10520
- profileName: profileSelection.activeProfile
10594
+ profileName: profileSelection.activeProfile,
10595
+ bundleTrust: profileSelection.bundleSource.trust
10521
10596
  } : null;
10522
- const overlaySources = [
10523
- userSource,
10524
- profileEntry,
10525
- projectSource,
10526
- customSource
10527
- ].filter((source) => source !== null);
10597
+ const overlaySources = buildOverlaySources(profileEntry, profileSelection.bundleSource?.trust, userSource, projectSource, customSource);
10528
10598
  const mergedOverlays = mergeOverlaySources(overlaySources);
10529
10599
  const mergedPiSubagentsOverlays = mergePiSubagentsOverlaySources(sources);
10530
10600
  const droppedCategories = Object.keys(mergedOverlays.categories).filter((name) => REMOVED_AGENT_CATEGORIES_SET.has(name));
@@ -10557,7 +10627,8 @@ function loadConfigWithSources(projectDir, options) {
10557
10627
  categories: overlayValues(mergedPiSubagentsOverlays.categories),
10558
10628
  agents: overlayValues(mergedPiSubagentsOverlays.agents)
10559
10629
  },
10560
- skills_as_commands: customConfig?.skills_as_commands ?? projectConfig?.skills_as_commands ?? userConfig?.skills_as_commands ?? DEFAULT_CONFIG.skills_as_commands
10630
+ skills_as_commands: customConfig?.skills_as_commands ?? projectConfig?.skills_as_commands ?? userConfig?.skills_as_commands ?? DEFAULT_CONFIG.skills_as_commands,
10631
+ allow_project_profiles: customConfig?.allow_project_profiles ?? userConfig?.allow_project_profiles ?? DEFAULT_CONFIG.allow_project_profiles
10561
10632
  };
10562
10633
  const droppedSkills = computeDroppedNames(result.disabled_skills, CURRENT_SKILL_NAMES_SET);
10563
10634
  warnDroppedNames(droppedSkills, "disabled_skills", warned, undefined, warningSink);
@@ -10581,7 +10652,8 @@ function loadConfigWithSources(projectDir, options) {
10581
10652
  user: user.metadata
10582
10653
  }),
10583
10654
  overlays,
10584
- piSubagentsOverlays: mergedPiSubagentsOverlays
10655
+ piSubagentsOverlays: mergedPiSubagentsOverlays,
10656
+ activeProfileSourcePath: profileSelection.bundleSource?.path ?? null
10585
10657
  };
10586
10658
  }
10587
10659
  function buildConfigObservationMetadata(summary) {
@@ -10698,8 +10770,8 @@ function assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle
10698
10770
  }
10699
10771
  }
10700
10772
  }
10701
- function assertAllProfileBundlesAreValid(userConfig, customConfig) {
10702
- for (const config of [userConfig, customConfig]) {
10773
+ function assertAllProfileBundlesAreValid(userConfig, customConfig, projectConfig) {
10774
+ for (const config of [userConfig, customConfig, projectConfig]) {
10703
10775
  for (const [profileName, bundle] of Object.entries(config?.profiles ?? {})) {
10704
10776
  assertProfileBundleCategoryKeysAreBundledCategories(profileName, bundle);
10705
10777
  }
@@ -10747,13 +10819,50 @@ function mergeOverlayMap(target, source, mapKey) {
10747
10819
  }
10748
10820
  const previous = target[key];
10749
10821
  const nextValue = resolveOverlayEntryValue(previous?.value, value, source);
10822
+ const nextOrigins = resolveOverlayEntryOrigin(previous?.origins, value, source);
10750
10823
  target[key] = {
10751
10824
  value: nextValue,
10752
10825
  sourcePath: source.path,
10753
- keyPath
10826
+ keyPath,
10827
+ origins: nextOrigins
10754
10828
  };
10755
10829
  }
10756
10830
  }
10831
+ function originForSource(source) {
10832
+ if (source.kind === "profile-bundle") {
10833
+ return `${source.bundleTrust}-profile`;
10834
+ }
10835
+ return source.trust;
10836
+ }
10837
+ function routingOriginsFromOwnFields(fragment, tag) {
10838
+ const origins = {};
10839
+ if (Object.hasOwn(fragment, "model"))
10840
+ origins.model = tag;
10841
+ if (Object.hasOwn(fragment, "variant"))
10842
+ origins.variant = tag;
10843
+ const opencodeBlock = fragment.opencode;
10844
+ if (isRecord2(opencodeBlock)) {
10845
+ if (Object.hasOwn(opencodeBlock, "model"))
10846
+ origins.opencodeModel = tag;
10847
+ if (Object.hasOwn(opencodeBlock, "variant"))
10848
+ origins.opencodeVariant = tag;
10849
+ }
10850
+ const piBlock = fragment.pi;
10851
+ if (isRecord2(piBlock)) {
10852
+ if (Object.hasOwn(piBlock, "model"))
10853
+ origins.piModel = tag;
10854
+ if (Object.hasOwn(piBlock, "thinking"))
10855
+ origins.piThinking = tag;
10856
+ }
10857
+ return origins;
10858
+ }
10859
+ function resolveOverlayEntryOrigin(previous, fragment, source) {
10860
+ const own = routingOriginsFromOwnFields(fragment, originForSource(source));
10861
+ if (!previous)
10862
+ return own;
10863
+ const preserves = source.kind === "profile-bundle" || source.trust === "project" || source.trust === "user";
10864
+ return preserves ? { ...previous, ...own } : own;
10865
+ }
10757
10866
  function resolveOverlayEntryValue(previous, next, source) {
10758
10867
  if (!previous)
10759
10868
  return next;
@@ -10762,6 +10871,8 @@ function resolveOverlayEntryValue(previous, next, source) {
10762
10871
  }
10763
10872
  if (source.trust === "project")
10764
10873
  return preserveSecurityFields(previous, next);
10874
+ if (source.trust === "user")
10875
+ return mergeProfileOverlayValue(previous, next);
10765
10876
  return next;
10766
10877
  }
10767
10878
  function stripProjectSecurityOverlay(sourcePath, keyPath, value, warningSink) {
@@ -11513,8 +11624,40 @@ function buildSkillToolParameterHint(options) {
11513
11624
  const hint = examples.length > 0 ? ` (e.g., ${examples}, ...)` : "";
11514
11625
  return `The name of the skill from available_skills${hint}`;
11515
11626
  }
11516
- function buildSkillContentOutput(matchedSkill) {
11517
- const body = extractSkillBody(matchedSkill.wrappedTemplate);
11627
+ function parsePositionalArgs(raw) {
11628
+ const matches = raw.match(/(?:\[Image\s+\d+\]|"[^"]*"|'[^']*'|[^\s"']+)/gi);
11629
+ if (!matches)
11630
+ return [];
11631
+ return matches.map((token) => token.replace(/^["']|["']$/g, ""));
11632
+ }
11633
+ function substituteSkillArguments(body, raw) {
11634
+ const placeholderNumbers = [...body.matchAll(/\$(\d+)/g)].map((m) => Number(m[1]));
11635
+ const hasPositional = placeholderNumbers.length > 0;
11636
+ const hasArguments = body.includes("$ARGUMENTS");
11637
+ let result = body;
11638
+ if (hasPositional) {
11639
+ const last = Math.max(...placeholderNumbers);
11640
+ const args = parsePositionalArgs(raw);
11641
+ result = result.replace(/\$(\d+)/g, (_match, numStr) => {
11642
+ const n = Number(numStr);
11643
+ if (n - 1 >= args.length)
11644
+ return "";
11645
+ if (n === last)
11646
+ return args.slice(n - 1).join(" ");
11647
+ return args[n - 1] ?? "";
11648
+ });
11649
+ }
11650
+ result = result.replaceAll("$ARGUMENTS", raw);
11651
+ if (!hasPositional && !hasArguments && raw.trim().length > 0) {
11652
+ result = `${result}
11653
+
11654
+ ${raw}`;
11655
+ }
11656
+ return result;
11657
+ }
11658
+ function buildSkillContentOutput(matchedSkill, argument) {
11659
+ const trimmedBody = extractSkillBody(matchedSkill.wrappedTemplate).trim();
11660
+ const body = argument === undefined ? trimmedBody : substituteSkillArguments(trimmedBody, argument);
11518
11661
  const dir = path6.dirname(matchedSkill.skillFile);
11519
11662
  const base = pathToFileURL(dir).href;
11520
11663
  const files = discoverSkillFiles(dir);
@@ -11522,7 +11665,7 @@ function buildSkillContentOutput(matchedSkill) {
11522
11665
  `<skill_content name="${matchedSkill.prefixedName}">`,
11523
11666
  `# Skill: ${matchedSkill.prefixedName}`,
11524
11667
  "",
11525
- body.trim(),
11668
+ body,
11526
11669
  "",
11527
11670
  `Base directory for this skill: ${base}`,
11528
11671
  "Relative paths in this skill (e.g., scripts/, reference/) are relative to this base directory.",