@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/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  extractCommandFrontmatter,
20
20
  findSkillsInDir,
21
21
  discoverSkills
22
- } from "./index-mf76ybyr.js";
22
+ } from "./index-c17zm38x.js";
23
23
 
24
24
  // src/index.ts
25
25
  import { createHash as createHash4 } from "crypto";
@@ -659,24 +659,11 @@ function collectSkillsAsCommands(dir, disabledSkills) {
659
659
  }
660
660
  function loadDiscoveredSkillAsCommand(skill) {
661
661
  const description = skill.description || `${skill.name} skill`;
662
- if (skill.frontmatter.disableModelInvocation === true) {
663
- return {
664
- template: wrapSkillTemplate(skill.skillPath, skill.body),
665
- description
666
- };
667
- }
668
662
  return {
669
- template: buildDiscoveredSkillShimTemplate(skill.name),
663
+ template: wrapSkillTemplate(skill.skillPath, skill.body),
670
664
  description
671
665
  };
672
666
  }
673
- function buildDiscoveredSkillShimTemplate(skillName) {
674
- return `Load the "${skillName}" skill using the skill tool, then follow its instructions to address this request:
675
-
676
- <user-request>
677
- $ARGUMENTS
678
- </user-request>`;
679
- }
680
667
  function collectDiscoveredSkillsAsCommands(startDir, homeDir, configDir, opencodeConfigDirOverride, disabledCommands) {
681
668
  const commands = {};
682
669
  let discovered;
@@ -10409,12 +10396,13 @@ function parseHostAfter(input) {
10409
10396
  return;
10410
10397
  return { ...before, args: input.args };
10411
10398
  }
10412
- function parseHostOutput(output) {
10399
+ function parseHostOutput(output, options) {
10413
10400
  if (!isRecord7(output))
10414
10401
  return;
10415
10402
  const title = output.title === undefined ? "" : output.title;
10416
10403
  const result = output.output === undefined ? "" : output.output;
10417
- if (typeof title !== "string" || title.length > MAX_STATUS_LENGTH || typeof result !== "string" || result.length > MAX_HOST_OUTPUT_LENGTH || !("metadata" in output)) {
10404
+ const maxOutputLength = options?.maxOutputLength ?? MAX_HOST_OUTPUT_LENGTH;
10405
+ if (typeof title !== "string" || title.length > MAX_STATUS_LENGTH || typeof result !== "string" || result.length > maxOutputLength || !("metadata" in output)) {
10418
10406
  return;
10419
10407
  }
10420
10408
  if (isRecord7(output.metadata)) {
@@ -10847,6 +10835,9 @@ function remoteReadbackInput(operation, local, workspaceIdentity, snapshot, incl
10847
10835
  function isSuccessfulAfter(output) {
10848
10836
  return parseHostOutput(output) !== undefined;
10849
10837
  }
10838
+ function isSuccessfulSkillAfter(output) {
10839
+ return parseHostOutput(output, { maxOutputLength: Number.POSITIVE_INFINITY }) !== undefined;
10840
+ }
10850
10841
  function statusForTool(status, unavailableCause) {
10851
10842
  return JSON.stringify({
10852
10843
  state: status.state,
@@ -12271,7 +12262,7 @@ function createSessionRuntime(options, operationObservers, recoveredOperationCon
12271
12262
  markUnavailable();
12272
12263
  return;
12273
12264
  }
12274
- if (!isSuccessfulAfter(output))
12265
+ if (!isSuccessfulSkillAfter(output))
12275
12266
  return;
12276
12267
  completedSkillCalls.set(callDigest, pending.skill);
12277
12268
  await activateCompletedSkill(pending.skill);
@@ -13218,8 +13209,40 @@ function buildSkillToolParameterHint(options) {
13218
13209
  const hint = examples.length > 0 ? ` (e.g., ${examples}, ...)` : "";
13219
13210
  return `The name of the skill from available_skills${hint}`;
13220
13211
  }
13221
- function buildSkillContentOutput(matchedSkill) {
13222
- const body2 = extractSkillBody(matchedSkill.wrappedTemplate);
13212
+ function parsePositionalArgs(raw) {
13213
+ const matches = raw.match(/(?:\[Image\s+\d+\]|"[^"]*"|'[^']*'|[^\s"']+)/gi);
13214
+ if (!matches)
13215
+ return [];
13216
+ return matches.map((token) => token.replace(/^["']|["']$/g, ""));
13217
+ }
13218
+ function substituteSkillArguments(body2, raw) {
13219
+ const placeholderNumbers = [...body2.matchAll(/\$(\d+)/g)].map((m) => Number(m[1]));
13220
+ const hasPositional = placeholderNumbers.length > 0;
13221
+ const hasArguments = body2.includes("$ARGUMENTS");
13222
+ let result = body2;
13223
+ if (hasPositional) {
13224
+ const last = Math.max(...placeholderNumbers);
13225
+ const args2 = parsePositionalArgs(raw);
13226
+ result = result.replace(/\$(\d+)/g, (_match, numStr) => {
13227
+ const n = Number(numStr);
13228
+ if (n - 1 >= args2.length)
13229
+ return "";
13230
+ if (n === last)
13231
+ return args2.slice(n - 1).join(" ");
13232
+ return args2[n - 1] ?? "";
13233
+ });
13234
+ }
13235
+ result = result.replaceAll("$ARGUMENTS", raw);
13236
+ if (!hasPositional && !hasArguments && raw.trim().length > 0) {
13237
+ result = `${result}
13238
+
13239
+ ${raw}`;
13240
+ }
13241
+ return result;
13242
+ }
13243
+ function buildSkillContentOutput(matchedSkill, argument) {
13244
+ const trimmedBody = extractSkillBody(matchedSkill.wrappedTemplate).trim();
13245
+ const body2 = argument === undefined ? trimmedBody : substituteSkillArguments(trimmedBody, argument);
13223
13246
  const dir = path7.dirname(matchedSkill.skillFile);
13224
13247
  const base = pathToFileURL(dir).href;
13225
13248
  const files = discoverSkillFiles(dir);
@@ -13227,7 +13250,7 @@ function buildSkillContentOutput(matchedSkill) {
13227
13250
  `<skill_content name="${matchedSkill.prefixedName}">`,
13228
13251
  `# Skill: ${matchedSkill.prefixedName}`,
13229
13252
  "",
13230
- body2.trim(),
13253
+ body2,
13231
13254
  "",
13232
13255
  `Base directory for this skill: ${base}`,
13233
13256
  "Relative paths in this skill (e.g., scripts/, reference/) are relative to this base directory.",
@@ -13275,8 +13298,72 @@ function discoverSkillFiles(dir, limit = 10) {
13275
13298
  }
13276
13299
 
13277
13300
  // src/lib/skill-tool.ts
13301
+ var DEFAULT_MAX_ENTRIES = 32;
13302
+ var DEFAULT_TTL_MS = 300000;
13303
+ var STORE_KEY_DELIMITER = "\x00";
13304
+ function createSkillOutputStore(options) {
13305
+ const maxEntries = options?.maxEntries ?? DEFAULT_MAX_ENTRIES;
13306
+ const ttlMs = options?.ttlMs ?? DEFAULT_TTL_MS;
13307
+ const now = options?.now ?? Date.now;
13308
+ const entries = new Map;
13309
+ const toKey = (sessionID, callID) => `${sessionID}${STORE_KEY_DELIMITER}${callID}`;
13310
+ return {
13311
+ put(sessionID, callID, output) {
13312
+ const key = toKey(sessionID, callID);
13313
+ entries.delete(key);
13314
+ entries.set(key, { output, expiresAt: now() + ttlMs });
13315
+ while (entries.size > maxEntries) {
13316
+ const oldestKey = entries.keys().next().value;
13317
+ if (oldestKey === undefined)
13318
+ break;
13319
+ entries.delete(oldestKey);
13320
+ }
13321
+ },
13322
+ take(sessionID, callID) {
13323
+ const key = toKey(sessionID, callID);
13324
+ const entry = entries.get(key);
13325
+ entries.delete(key);
13326
+ if (!entry)
13327
+ return;
13328
+ if (now() > entry.expiresAt)
13329
+ return;
13330
+ return entry.output;
13331
+ }
13332
+ };
13333
+ }
13334
+ var TRUNCATION_MARKER_RE = /\n\n\.\.\.\d+ (?:lines|bytes) truncated\.\.\.\n\n/g;
13335
+ function restoreSkillOutput(store, input, output, options) {
13336
+ if (!isRecord(input) || input.tool !== "systematic_skill")
13337
+ return;
13338
+ const { sessionID, callID } = input;
13339
+ if (typeof sessionID !== "string" || sessionID === "")
13340
+ return;
13341
+ if (typeof callID !== "string" || callID === "")
13342
+ return;
13343
+ const full = store.take(sessionID, callID);
13344
+ if (!full)
13345
+ return;
13346
+ if (options.userOutputLimitSet)
13347
+ return;
13348
+ if (!isRecord(output))
13349
+ return;
13350
+ if (!isRecord(output.metadata) || output.metadata.truncated !== true)
13351
+ return;
13352
+ if (typeof output.output !== "string")
13353
+ return;
13354
+ const matches = [...output.output.matchAll(TRUNCATION_MARKER_RE)];
13355
+ const lastMatch = matches.at(-1);
13356
+ if (!lastMatch || lastMatch.index === undefined)
13357
+ return;
13358
+ const preview = output.output.slice(0, lastMatch.index);
13359
+ if (!full.startsWith(preview))
13360
+ return;
13361
+ output.output = full;
13362
+ output.metadata.truncated = false;
13363
+ delete output.metadata.outputPath;
13364
+ }
13278
13365
  function createSkillTool(options) {
13279
- const { bundledSkillsDir, disabledSkills } = options;
13366
+ const { bundledSkillsDir, disabledSkills, outputStore } = options;
13280
13367
  const buildDescription = () => buildSkillToolDescription({ bundledSkillsDir, disabledSkills });
13281
13368
  const buildParameterHint = () => buildSkillToolParameterHint({ bundledSkillsDir, disabledSkills });
13282
13369
  let cachedDescription = null;
@@ -13294,12 +13381,13 @@ function createSkillTool(options) {
13294
13381
  cachedParameterHint = buildParameterHint();
13295
13382
  }
13296
13383
  return cachedParameterHint;
13297
- })())
13384
+ })()),
13385
+ arguments: string().optional().describe("Raw argument text the user explicitly supplied for this skill, substituted for $ARGUMENTS and $1..$N. Omit to leave those placeholders as written; an explicit empty string substitutes them with nothing. Only pass text the user explicitly supplied; never infer it.")
13298
13386
  },
13299
13387
  async execute(args2, context) {
13300
13388
  const requestedName = args2.name;
13301
13389
  const matchedSkill = resolveSkill({ bundledSkillsDir, disabledSkills }, requestedName);
13302
- const { output, dir } = buildSkillContentOutput(matchedSkill);
13390
+ const { output, dir } = buildSkillContentOutput(matchedSkill, args2.arguments);
13303
13391
  await context.ask({
13304
13392
  permission: "skill",
13305
13393
  patterns: [matchedSkill.prefixedName],
@@ -13313,6 +13401,12 @@ function createSkillTool(options) {
13313
13401
  dir
13314
13402
  }
13315
13403
  });
13404
+ if (outputStore) {
13405
+ const contextRecord = context;
13406
+ if (isRecord(contextRecord) && typeof contextRecord.sessionID === "string" && contextRecord.sessionID !== "" && typeof contextRecord.callID === "string" && contextRecord.callID !== "") {
13407
+ outputStore.put(contextRecord.sessionID, contextRecord.callID, output);
13408
+ }
13409
+ }
13316
13410
  return output;
13317
13411
  }
13318
13412
  };
@@ -13344,6 +13438,8 @@ var initializePlugin = async ({
13344
13438
  worktree
13345
13439
  }) => {
13346
13440
  let hasLoggedInit = false;
13441
+ let userOutputLimitSet = false;
13442
+ const skillOutputStore = createSkillOutputStore();
13347
13443
  const config = loadConfig(directory);
13348
13444
  const bootstrapContent = getBootstrapContent(config, {
13349
13445
  bundledSkillsDir,
@@ -13411,11 +13507,16 @@ var initializePlugin = async ({
13411
13507
  })()
13412
13508
  });
13413
13509
  const hooks = {
13414
- config: configHandler,
13510
+ config: async (incomingConfig) => {
13511
+ const configUnknown = incomingConfig;
13512
+ userOutputLimitSet = isRecord(configUnknown) && isRecord(configUnknown.tool_output) && (configUnknown.tool_output.max_lines !== undefined || configUnknown.tool_output.max_bytes !== undefined);
13513
+ return configHandler(incomingConfig);
13514
+ },
13415
13515
  tool: {
13416
13516
  systematic_skill: createSkillTool({
13417
13517
  bundledSkillsDir,
13418
- disabledSkills: config.disabled_skills
13518
+ disabledSkills: config.disabled_skills,
13519
+ outputStore: skillOutputStore
13419
13520
  }),
13420
13521
  ...workflowGuard.tools
13421
13522
  },
@@ -13431,6 +13532,11 @@ var initializePlugin = async ({
13431
13532
  try {
13432
13533
  await workflowGuard.hooks["tool.execute.after"](input, output);
13433
13534
  } catch {}
13535
+ try {
13536
+ restoreSkillOutput(skillOutputStore, input, output, {
13537
+ userOutputLimitSet
13538
+ });
13539
+ } catch {}
13434
13540
  },
13435
13541
  event: async (input) => {
13436
13542
  try {
@@ -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];
@@ -211,8 +211,8 @@ export declare const PiSubagentsSchema: z.ZodDefault<z.ZodObject<{
211
211
  * Fields in PiSubagentsAgentOverlaySchema/PiSubagentsCategoryOverlaySchema that
212
212
  * require a project-or-higher trust source. Project config cannot grant
213
213
  * `thinking`, `tools`, or `skills` to an exported persona; `max_turns` is
214
- * trust-any. Mirrors the hand-coded `PI_SUBAGENTS_PROTECTED_FIELDS` set in
215
- * `src/lib/config.ts`.
214
+ * trust-any. This is the single definition. `src/lib/config.ts` imports it
215
+ * rather than keeping a copy.
216
216
  */
217
217
  export declare const PI_SUBAGENTS_PROTECTED_FIELDS: readonly string[];
218
218
  export declare const BootstrapSchema: z.ZodObject<{
@@ -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
  }>>>;
@@ -684,6 +686,7 @@ export declare function validateConfig(input: unknown): ValidationResult;
684
686
  * assert that this list agrees with every field tagged `.meta({ trust:
685
687
  * 'project-or-higher' })` in AgentOverlaySchema — preventing silent drift.
686
688
  *
687
- * Matches the hand-coded `SECURITY_OVERLAY_FIELDS` set in `src/lib/config.ts`.
689
+ * This is the single definition. `src/lib/config.ts` imports it rather than
690
+ * keeping a copy.
688
691
  */
689
692
  export declare const SECURITY_OVERLAY_FIELDS: readonly ['model', 'variant', 'skills', 'permission', 'opencode', 'pi'];
@@ -1,3 +1,4 @@
1
+ import { CONFIG_PROTECTED_FIELD_PATHS, type ConfigProtectedFieldPath } from './config-protected-fields.js';
1
2
  import { type RoutingTarget } from './routing-resolver.js';
2
3
  export interface BootstrapConfig {
3
4
  enabled: boolean;
@@ -10,22 +11,75 @@ export interface WorkflowGuardConfig {
10
11
  }
11
12
  export type OverlayConfig = Record<string, unknown>;
12
13
  export type OverlayConfigMap = Record<string, OverlayConfig>;
14
+ /**
15
+ * Which FILE-level source contributed the winning value for one routing
16
+ * field -- distinct from `RoutingFieldSource.level`/`.form` in
17
+ * `routing-resolver.ts`, which describe SHAPE provenance (agent vs
18
+ * category, block vs flat), not file provenance. Reuses `ConfigSourceKind`
19
+ * for the non-profile cases (a plain agents/categories overlay entry from
20
+ * that trust level) and adds the three profile-bundle variants, since a
21
+ * bundle's own trust level (which file defined `profiles.<name>`) is a
22
+ * genuinely different fact from an ordinary same-trust overlay -- most
23
+ * importantly, `'project-profile'` is the only origin an advisory
24
+ * (project-sourced) bundle can ever produce, and is exactly the tag
25
+ * `config show` needs to make "the project bundle applied something"
26
+ * distinguishable from "the project bundle got fully absorbed by user
27
+ * config" (every field's origin reads `'user'`, never `'project-profile'`).
28
+ */
29
+ export type RoutingValueOrigin = ConfigSourceKind | 'user-profile' | 'custom-profile' | 'project-profile';
30
+ /**
31
+ * Per-leaf file-provenance for the exact set of fields
32
+ * `routing-resolver.ts` ever reads off a merged agent/category overlay
33
+ * value: the two flat fields (`model`, `variant`) and the four
34
+ * harness-block fields (`opencode.model`, `opencode.variant`, `pi.model`,
35
+ * `pi.thinking`). Deliberately NOT a generic recursive mirror of
36
+ * `OverlayConfig`'s shape -- routing is the only consumer, and a generic
37
+ * tree would have to track every overlay field (`mode`, `color`, `steps`,
38
+ * `hidden`, `disable`, `skills`, `permission`, ...) for no benefit, since
39
+ * none of those ever feed routing resolution.
40
+ *
41
+ * A leaf is `undefined` when no source in the merge chain has ever set
42
+ * that field as an OWN property for this key -- distinct from the field
43
+ * being unresolved at the routing layer (which can also happen when a
44
+ * lower-precedence layer, e.g. category, is shadowed by a higher one, e.g.
45
+ * agent, that DOES have an origin here).
46
+ */
47
+ export interface RoutingFieldOrigins {
48
+ readonly model?: RoutingValueOrigin;
49
+ readonly variant?: RoutingValueOrigin;
50
+ readonly opencodeModel?: RoutingValueOrigin;
51
+ readonly opencodeVariant?: RoutingValueOrigin;
52
+ readonly piModel?: RoutingValueOrigin;
53
+ readonly piThinking?: RoutingValueOrigin;
54
+ }
13
55
  export interface SourcedOverlayConfig {
14
56
  value: OverlayConfig;
15
57
  sourcePath: string;
16
58
  keyPath: string;
59
+ /**
60
+ * Per-routing-field file provenance for `value`, updated in lockstep
61
+ * with `value` at every merge step (see `resolveOverlayEntryOrigin`) --
62
+ * attached to the value that actually won, never derived after the fact
63
+ * from `sourcePath` (which is last-writer-wins across the WHOLE entry,
64
+ * not per field; see that field's doc comment for the trap this avoids).
65
+ * Optional and possibly `{}` for overlay maps this file's merge doesn't
66
+ * populate origins for (`pi_subagents`, and `routing-resolver.ts`'s
67
+ * `toSourcedOverlayMap` placeholder adapter for already-flattened
68
+ * inputs) -- routing resolution treats a missing leaf as "no known
69
+ * origin", never as an error.
70
+ */
71
+ origins?: RoutingFieldOrigins;
17
72
  }
18
73
  export interface SourcedOverlayConfigMap {
19
74
  agents: Record<string, SourcedOverlayConfig>;
20
75
  categories: Record<string, SourcedOverlayConfig>;
21
76
  }
22
77
  export declare const CONFIG_AUTHORITY_FIELD_PATHS: readonly ['bootstrap.enabled', 'bootstrap.file', 'skills_as_commands', 'workflow_guard.debug', 'workflow_guard.mode'];
23
- export 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'];
78
+ export { CONFIG_PROTECTED_FIELD_PATHS, type ConfigProtectedFieldPath };
24
79
  export type ConfigSourceKind = 'custom' | 'project' | 'user';
25
80
  export type ConfigSourcePresence = 'absent' | 'invalid' | 'present';
26
81
  export type ConfigSourceErrorCode = 'parse-failed' | 'read-failed' | 'schema-invalid' | 'source-invalid';
27
82
  export type ConfigAuthorityFieldPath = (typeof CONFIG_AUTHORITY_FIELD_PATHS)[number];
28
- export type ConfigProtectedFieldPath = (typeof CONFIG_PROTECTED_FIELD_PATHS)[number];
29
83
  export interface ConfigSourceMetadata {
30
84
  readonly errorCode?: ConfigSourceErrorCode;
31
85
  readonly kind: ConfigSourceKind;
@@ -84,6 +138,30 @@ export interface SourceAwareConfigResult {
84
138
  * the post-merge qualifier check, without recomputing it.
85
139
  */
86
140
  piSubagentsOverlays: SourcedOverlayConfigMap;
141
+ /**
142
+ * The (non-canonical) `path` of the file that defined the active
143
+ * profile's bundle content -- `profileSelection.bundleSource.path`,
144
+ * verbatim -- or `null` when no profile is active. Deliberately lives
145
+ * here and NOT on `ConfigObservationMetadata`: `capability-snapshot.ts`
146
+ * runs loader metadata through `assertAllowedKeys`, a hardcoded-allowlist
147
+ * gate that THROWS on any unknown key (see its doc comment), and only
148
+ * `.metadata` -- never the rest of `SourceAwareConfigResult` -- is an
149
+ * input to the capability snapshot. Adding a field to
150
+ * `ConfigObservationMetadata` would silently break `systematic
151
+ * capabilities` (`runCapabilities` catches the throw and prints
152
+ * "Capabilities diagnostic unavailable", naming no cause) exactly the way
153
+ * a hand-duplicated `CONFIG_PROTECTED_FIELD_PATHS` literal in
154
+ * `capability-snapshot.ts` once silently did, before that duplication was
155
+ * removed in favor of the shared `config-protected-fields.ts` module (see
156
+ * that module's doc comment for the incident record). Consumers
157
+ * (`systematic config show`) read `loaded.activeProfileSourcePath`
158
+ * directly, never `loaded.metadata.activeProfileSourcePath`. Uses `path`
159
+ * (matching `getConfigPaths`/`Configuration locations`'s non-canonical
160
+ * values), not `canonicalPath` -- printing the canonical path would
161
+ * disagree with the `Configuration locations` block a few lines above it
162
+ * for a symlinked config directory.
163
+ */
164
+ activeProfileSourcePath: string | null;
87
165
  }
88
166
  export interface PiSubagentsOverlayMap {
89
167
  categories?: OverlayConfigMap;
@@ -99,6 +177,7 @@ export interface SystematicConfig {
99
177
  categories?: OverlayConfigMap;
100
178
  pi_subagents?: PiSubagentsOverlayMap;
101
179
  skills_as_commands: boolean;
180
+ allow_project_profiles: boolean;
102
181
  }
103
182
  export declare const DEFAULT_CONFIG: SystematicConfig;
104
183
  /**
@@ -168,4 +247,3 @@ export declare function getConfigPaths(projectDir: string, options?: ConfigPathO
168
247
  customConfig?: string | undefined;
169
248
  customDir?: string | undefined;
170
249
  };
171
- export {};
@@ -13,7 +13,7 @@
13
13
  * (`src/lib/config.ts`), which has the `warningSink` this module deliberately
14
14
  * does not.
15
15
  */
16
- import type { OverlayConfigMap, PiSubagentsOverlayMap, SourcedOverlayConfig, SourcedOverlayConfigMap } from './config.js';
16
+ import type { OverlayConfigMap, PiSubagentsOverlayMap, RoutingValueOrigin, SourcedOverlayConfig, SourcedOverlayConfigMap } from './config.js';
17
17
  export type Harness = 'opencode' | 'pi';
18
18
  /**
19
19
  * One resolution target: a bundled agent's bare file-stem key plus its
@@ -32,10 +32,22 @@ export interface RoutingTarget {
32
32
  * `form` is `'legacy-pi-subagents'` only for a `pi` harness qualifier
33
33
  * resolved from the deprecated `pi_subagents.<agents|categories>.<key>.thinking`
34
34
  * location (R5) — `model` and `variant` never resolve from there.
35
+ *
36
+ * `level`/`form` are SHAPE provenance -- which key shape won (agent vs
37
+ * category, block vs flat) -- not FILE provenance. `origin` is the FILE
38
+ * provenance: which trust level/profile-bundle actually contributed the
39
+ * winning value, read from `SourcedOverlayConfig.origins` at the same leaf
40
+ * `level`/`form` identify (see `config.ts`'s `RoutingFieldOrigins` for how
41
+ * that's tracked through the merge). `undefined` for a legacy-pi-subagents
42
+ * source (that map isn't merge-tracked for origins -- profile bundles
43
+ * can't set `pi_subagents` fields at all) or when the caller supplied
44
+ * overlays via `toSourcedOverlayMap`'s placeholder adapter, which carries
45
+ * no real origins.
35
46
  */
36
47
  export interface RoutingFieldSource {
37
48
  readonly level: 'agent' | 'category';
38
49
  readonly form: 'block' | 'flat' | 'legacy-pi-subagents';
50
+ readonly origin?: RoutingValueOrigin;
39
51
  }
40
52
  export interface RoutingResolution {
41
53
  /**
@@ -20,10 +20,23 @@ export declare function buildSkillToolDescription(options: SkillResolverOptions)
20
20
  * Deterministic, catalog-derived parameter hint shared by every harness.
21
21
  */
22
22
  export declare function buildSkillToolParameterHint(options: SkillResolverOptions): string;
23
+ /**
24
+ * Text-only substitution matching OpenCode's `SessionPrompt.command`:
25
+ * positional `$N` first (the highest `$N` takes the remaining arguments,
26
+ * missing positions are empty), then `$ARGUMENTS` as the raw string. With no
27
+ * placeholders, non-blank arguments are appended after a blank line.
28
+ */
29
+ export declare function substituteSkillArguments(body: string, raw: string): string;
23
30
  /**
24
31
  * Builds the exact `<skill_content>`-wrapped output shared by every harness.
32
+ *
33
+ * When `argument` is `undefined`, the output is byte-identical to calling
34
+ * this without argument support at all (Pi's caller in src/pi.ts relies on
35
+ * this). When `argument` is a string (including an empty string), it is
36
+ * substituted into the trimmed body via {@link substituteSkillArguments}
37
+ * before wrapping — the wrapper lines themselves are never substituted.
25
38
  */
26
- export declare function buildSkillContentOutput(matchedSkill: LoadedSkill): {
39
+ export declare function buildSkillContentOutput(matchedSkill: LoadedSkill, argument?: string): {
27
40
  output: string;
28
41
  dir: string;
29
42
  };
@@ -1,7 +1,23 @@
1
1
  import type { ToolDefinition } from '@opencode-ai/plugin';
2
2
  export { discoverSkillFiles } from './skill-resolver.js';
3
+ export interface SkillOutputStore {
4
+ put(sessionID: string, callID: string, output: string): void;
5
+ take(sessionID: string, callID: string): string | undefined;
6
+ }
7
+ interface SkillOutputStoreOptions {
8
+ maxEntries?: number;
9
+ ttlMs?: number;
10
+ now?: () => number;
11
+ }
12
+ /** In-memory cache of full (pre-truncation) skill tool output, keyed by session+call, for `restoreSkillOutput`. */
13
+ export declare function createSkillOutputStore(options?: SkillOutputStoreOptions): SkillOutputStore;
14
+ /** Restores the full skill output into a truncated host `tool.execute.after` result, mutating `output` in place. */
15
+ export declare function restoreSkillOutput(store: SkillOutputStore, input: unknown, output: unknown, options: {
16
+ userOutputLimitSet: boolean;
17
+ }): void;
3
18
  export interface SkillToolOptions {
4
19
  bundledSkillsDir: string;
5
20
  disabledSkills: string[];
21
+ outputStore?: SkillOutputStore;
6
22
  }
7
23
  export declare function createSkillTool(options: SkillToolOptions): ToolDefinition;