/** * Reading one preset declaration's composition text, for display. * * The dialect is Harness's entry-list YAML: a top-level list of plugin rows * (`EntryOptions`, from `@deepseek-ai/cordis-plugin-loader`), where a * `group: true` row's `config` is itself a nested list of rows — * `delegation > tool-subagent-codex` is one row inside another row's * `config`, not a flat entry. The ONLY thing Harness's own discovery * validator (`entryListProblem` in `packages/preset/agent-preset-registry/src/ * definition.ts`) requires of a row is a non-empty `name`; `id` is not part of * the minimum-valid shape — the Loader assigns a random one at mount time * when a row omits it (`config/tree.ts`'s `Math.random().toString(16)...`). * This parser follows that same shallow acceptance rather than a stricter one * of its own: an id-less row is valid input here, exactly as it is to * Harness, and is displayed by its `name` and structural position instead. * * `disabled` is not only boolean: the same dialect tags a scalar * `!!js ` (`tag:yaml.org,2002:js` in `vendor/include`'s * `entryListSchema`), evaluated by the Loader against its own running * context at composition time. This module NEVER evaluates that expression — * doing so here would run untrusted host-specific logic * (`process.platform === 'win32'`, and worse is possible) inside a terminal * frontend that has no business deciding what it means. A row whose * `disabled` is a `!!js` node is modeled as `'conditional'` and its raw * expression text is carried through for display only. * * This module is now READ-ONLY, and that is a migration result rather than a * choice. The previous generation's roster was a live directory of * `agent.cordis.yml` files, so `/plugins` could address a row by a * {@link RowLocator} and splice exactly one `disabled` field in place, and * nothing about that survives: the adopted registry "accepts no preset paths", * returns no path to write, and its own preset tree overrides `write()` to a * no-op because "only the profile configuration editor persists definitions". * A composition now changes only through Harness's own profile-patch * reconciliation, and a second YAML-splicing path beside it would be a second * authority over the same file. So the locator, the re-parse-and-refuse * discipline, and the narrow edit are deleted, and what remains is the parse * the browser draws. * @module dshline/plugins/composition */ /** One row's own `disabled` field, modeled honestly instead of coerced to boolean. */ export type DisabledState = /** No `disabled` field, or an explicit falsy one. */ { readonly kind: 'enabled'; } /** `disabled: true` (or another truthy plain value). */ | { readonly kind: 'disabled'; } /** `disabled: !!js ` — the Loader decides this, not dshline. */ | { readonly kind: 'conditional'; readonly expression: string; }; /** Whether a row runs, once its own field and its ancestors' are combined. */ export type EffectiveState = 'enabled' | 'disabled' | 'conditional'; /** One row of a preset's composition, at whatever depth it was found. */ export interface CompositionRow { /** How to safely re-find this exact row in the declaration being edited. */ readonly locator: RowLocator; /** * Display breadcrumb from the root row down to and including this one — * each ancestor's `id`, falling back to its `name` when it has none. */ readonly path: readonly string[]; /** This row's own id, when the declaration gives it one. */ readonly id: string | undefined; /** Module specifier the row loads. */ readonly name: string; /** Nesting depth; `0` for a top-level row. */ readonly depth: number; /** Whether this row is a nested group (its `config` holds child rows). */ readonly group: boolean; /** This row's own `disabled` field, before any ancestor is considered. */ readonly disabled: DisabledState; /** * Whether the row actually runs, per the Loader's own inheritance rule: a * group's OWN row is always `'enabled'` here (a group container always * runs so its children can be evaluated — the Loader's `Entry._disabled` * returns `false` unconditionally for a group), but a group's `disabled` * field still governs every row nested under it, which is what makes a * leaf's `effective` here possibly `'disabled'` or `'conditional'` even * when its own {@link disabled} is `'enabled'`. */ readonly effective: EffectiveState; /** * A short, obvious summary of `config`, when it is worth showing: a plain * scalar, or a small object of plain scalars, whitespace-normalized and * capped to {@link MAX_SUMMARY_LENGTH} characters. Never computed for a * group row (its `config` is the child list) and omitted rather than * guessed whenever a value is not plainly summarizable — this keeps a * multi-kilobyte persona or system-prompt `config` from ever landing in a * row's detail line. */ readonly configSummary?: string; /** * This row's `config.provider`, when it declares one as a plain string. * * Read structurally and named after the FIELD, not after any meaning: this * module is a parser and does not know which registry a given row resolves a * provider from, or whether it resolves one at all. `health.ts` owns that * judgement, and only for module names it can prove the link for. Kept * separate from {@link configSummary}, which is display text and may be * absent (a large config is deliberately not summarized) while this is * present. */ readonly configProvider?: string; } /** What one parse of a composition file produced. */ export type CompositionTree = /** Parsed and structurally valid: a top-level list of entry rows. */ { readonly kind: 'parsed'; readonly rows: readonly CompositionRow[]; } /** The text could not be read as an entry list; the reason is Harness's own. */ | { readonly kind: 'broken'; readonly reason: string; }; /** * Parse one preset's composition text into a flat, pre-order row list. * * Never throws: text this dialect cannot make sense of is reported as * {@link CompositionTree} `'broken'`, the same posture Harness's own * registration takes toward a malformed `plugins` list — and, by design, no * MORE strict than that posture: a row this parser cannot make complete sense * of but Harness's own validator accepts (an id-less row, chiefly) is parsed, * not rejected. This function is presentation for declarations Harness already * considers valid; it does not independently decide a preset's health — see * `catalog.ts`, which treats the roster's own `AgentPresetRow.broken` as * authoritative over whatever this parser thinks. * @param text - the declaration's rendered child list, as `readDocument()` returns it. * @returns the flattened rows, or why none could be read. */ export declare function parseComposition(text: string): CompositionTree; /** * One step of a {@link RowLocator}: a row's position within its containing * entry list, and the fingerprint expected there. * * `name` is always checked because it is the one field Harness itself requires * of a row. `id` is checked only when the row had one, since its absence here * does not mean a re-read may not since have grown one — only that this locator * does not know to expect it. */ export interface RowLocatorStep { /** Index within the immediately containing entry list. */ readonly index: number; /** The name expected at that position. */ readonly name: string; /** The id expected at that position, when this row had one. */ readonly id: string | undefined; } /** * How to safely re-find one row after re-reading the declaration. * * A declaration is a list of rows where a `group: true` row's own children live * in its `config`, so a locator is a path of (index, name, id) steps from the * top-level list down to one row. `id` is optional to Harness and is not * guaranteed unique where present, so it is a corroborating check and never the * only one — the alternative, addressing a row by name alone, would silently * edit the first match in a list a person may have made ambiguous on purpose. */ export interface RowLocator { /** Steps from the top-level list down to and including the target row. */ readonly steps: readonly RowLocatorStep[]; } /** Why {@link togglePresetRow} could not apply the requested change. */ export type ToggleFailureReason = /** The declaration's child list is not the array of rows it should be. */ 'broken' /** The locator's structure (an index, or a group where one is expected) no longer exists. */ | 'not-found' /** * A row exists at the located position, but its name — or its id, when the * locator recorded one — no longer matches: the declaration changed * incompatibly since this locator was built, and mutating that position * anyway would edit a different row than the one shown. */ | 'changed' /** * The row's current `disabled` is a `!!js` expression: toggling here would * silently discard host-specific behavior an operator wrote on purpose. */ | 'conditional'; /** The result of attempting one narrow `disabled` edit. */ export type ToggleResult = /** The edit applied, or nothing needed to change. */ { readonly ok: true; readonly changed: boolean; readonly plugins: readonly unknown[]; } /** The edit was refused, or the row could not be safely re-found. */ | { readonly ok: false; readonly reason: ToggleFailureReason; readonly message: string; }; /** * Enable or disable exactly one row of a preset declaration. * * This operates on the STRUCTURED child list the Loader resolved, not on * rendered YAML text, and it copies every row it does not touch. That is the * point of the migration: a preset is a `@deepseek-ai/dsh-agent-preset` row in * a composition, the composition is persisted by `ctx.configEditor` through a * profile patch, and that path re-serializes the whole `config` through the * owning plugin's own `Config`. A second YAML writer producing a second * rendering of the same declaration would be a second authority over one file. * * Every step of the locator is re-verified against the list being edited, so a * declaration changed since the browser read it is refused rather than * mutating whatever now sits at that position. A request that changes nothing * returns the input list unchanged, so a redundant write never lands a * profile patch. * * A `!!js` `disabled` is refused outright. Overwriting one would discard * host-specific behavior an operator wrote on purpose, and the adopted Loader * still evaluates it, so there is no representation here that is both a toggle * and an honest edit. * @param plugins - the declaration's resolved child list. * @param locator - the row's locator, as {@link CompositionRow.locator} reports it. * @param enable - `true` to enable the row, `false` to disable it. * @returns the new list, or why the edit was refused. */ export declare function togglePresetRow(plugins: readonly unknown[], locator: RowLocator, enable: boolean): ToggleResult; //# sourceMappingURL=composition.d.ts.map