@inventarch/workspace-runtime 3.0.0 → 3.1.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/README.md +1 -1
- package/SPEC.md +6 -2
- package/dist/generate/index.d.ts +1 -0
- package/dist/generate/index.d.ts.map +1 -1
- package/dist/generate/index.js +1 -0
- package/dist/generate/index.js.map +1 -1
- package/dist/generate/plugin.d.ts +20 -0
- package/dist/generate/plugin.d.ts.map +1 -0
- package/dist/generate/plugin.js +116 -0
- package/dist/generate/plugin.js.map +1 -0
- package/dist/host-plugin/compare.d.ts +15 -0
- package/dist/host-plugin/compare.d.ts.map +1 -0
- package/dist/host-plugin/compare.js +117 -0
- package/dist/host-plugin/compare.js.map +1 -0
- package/dist/host-plugin/errors.d.ts +8 -0
- package/dist/host-plugin/errors.d.ts.map +1 -0
- package/dist/host-plugin/errors.js +11 -0
- package/dist/host-plugin/errors.js.map +1 -0
- package/dist/host-plugin/frontmatter.d.ts +29 -0
- package/dist/host-plugin/frontmatter.d.ts.map +1 -0
- package/dist/host-plugin/frontmatter.js +114 -0
- package/dist/host-plugin/frontmatter.js.map +1 -0
- package/dist/host-plugin/index.d.ts +7 -0
- package/dist/host-plugin/index.d.ts.map +1 -0
- package/dist/host-plugin/index.js +7 -0
- package/dist/host-plugin/index.js.map +1 -0
- package/dist/host-plugin/inventory.d.ts +31 -0
- package/dist/host-plugin/inventory.d.ts.map +1 -0
- package/dist/host-plugin/inventory.js +120 -0
- package/dist/host-plugin/inventory.js.map +1 -0
- package/dist/host-plugin/json.d.ts +8 -0
- package/dist/host-plugin/json.d.ts.map +1 -0
- package/dist/host-plugin/json.js +18 -0
- package/dist/host-plugin/json.js.map +1 -0
- package/dist/host-plugin/lower.d.ts +47 -0
- package/dist/host-plugin/lower.d.ts.map +1 -0
- package/dist/host-plugin/lower.js +484 -0
- package/dist/host-plugin/lower.js.map +1 -0
- package/dist/host-plugin/manifest.d.ts +21 -0
- package/dist/host-plugin/manifest.d.ts.map +1 -0
- package/dist/host-plugin/manifest.js +40 -0
- package/dist/host-plugin/manifest.js.map +1 -0
- package/dist/projection-host.js +1 -1
- package/package.json +13 -9
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The generic workspace runtime: workspace capture and adoption (`captureWorkspace`, `adoptWorkspace`, `verifyCapture`, `Corpus`), captured resources and native resource context, projections and prose catalogs, managed publication and candidate validation, captured template rendering, lifecycle rows, profiles and transport, the authoring index and manifest, the installed catalog digest and installed source policy, source policies, the local store adapter and installed adapter verification. [SPEC.md](SPEC.md) owns the boundary.
|
|
4
4
|
|
|
5
|
-
Consumers import the package root for capture, publication, candidate validation and the installed implementation digest, and the public subpaths (`/resources`, `/projections`, `/templates`, `/lifecycle`, `/lifecycle-profile`, `/authoring`, `/authoring-manifest`, `/sources`, `/local-store`, `/adapters`, `/corpus`, `/installed-catalog`, `/authoring-types`, `/authoring-format`, `/resource-format`, `/resource-sources`, `/task-capture-format`, `/candidate`, `/publication`) for the rest. `./internal/*` entries exist for every emitted top-level module and are not a stable contract. `./internal/generate` serves the host generators, which render host files and definitions from a workspace's authored records and report each authored record they do not render with the reason: `generateAgentProfiles` one claude agent file per authored `@agent-profile` (SPEC W01), `generatePlaybookSkills` one skill per authored `@playbook` for claude or codex (W02), `generateHookSet` the authored `@hook` declarations the `@mandate` edit guard can decide (W03), and `generateDefinitions` the authored `@operation` and `@harness` definitions (W04).
|
|
5
|
+
Consumers import the package root for capture, publication, candidate validation and the installed implementation digest, and the public subpaths (`/resources`, `/projections`, `/templates`, `/lifecycle`, `/lifecycle-profile`, `/authoring`, `/authoring-manifest`, `/sources`, `/local-store`, `/adapters`, `/corpus`, `/installed-catalog`, `/authoring-types`, `/authoring-format`, `/resource-format`, `/resource-sources`, `/task-capture-format`, `/candidate`, `/publication`) for the rest. `./internal/*` entries exist for every emitted top-level module and are not a stable contract. `./internal/generate` serves the host generators, which render host files and definitions from a workspace's authored records and report each authored record they do not render with the reason: `generateAgentProfiles` one claude agent file per authored `@agent-profile` (SPEC W01), `generatePlaybookSkills` one skill per authored `@playbook` for claude or codex (W02), `generateHookSet` the authored `@hook` declarations the `@mandate` edit guard can decide (W03), and `generateDefinitions` the authored `@operation` and `@harness` definitions (W04), and `renderPlugin` the host plugin a product `@distribution` describes (W05). `./internal/host-plugin` serves `ia init --from` and `ia project --product plugin`: it reads a host plugin, lowers it into records and compares a rendered plugin with the original (W06), and like every `./internal/*` entry it is not a stable contract.
|
|
6
6
|
|
|
7
7
|
This package never imports `@inventarch/agent-composition-system`. The composition compiler lives there and depends on this package.
|
|
8
8
|
|
package/SPEC.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Boundary
|
|
4
4
|
|
|
5
|
-
`@inventarch/workspace-runtime` is the generic workspace runtime. It owns workspace capture and adoption, captured resources, projections, publication and candidates, templates, lifecycle, authoring index and manifest, installed catalog and source policy, sources, the local store and adapters, and the host files and definitions generated from authored records (W01 to W04). The composition compiler (catalog, compile, compiled, execution, fields, inputs, installed read, task capture, task context declaration, task teaching closure, draft tools) stays in `@inventarch/agent-composition-system`, which depends on this package. There is no reverse edge: no module here imports `@inventarch/agent-composition-system`, and `tests/boundary.test.ts` fails if one appears.
|
|
5
|
+
`@inventarch/workspace-runtime` is the generic workspace runtime. It owns workspace capture and adoption, captured resources, projections, publication and candidates, templates, lifecycle, authoring index and manifest, installed catalog and source policy, sources, the local store and adapters, and the host files and definitions generated from authored records (W01 to W04), the host plugin rendered from a product `@distribution` (W05) and the lowering of a host plugin into records (W06). The composition compiler (catalog, compile, compiled, execution, fields, inputs, installed read, task capture, task context declaration, task teaching closure, draft tools) stays in `@inventarch/agent-composition-system`, which depends on this package. There is no reverse edge: no module here imports `@inventarch/agent-composition-system`, and `tests/boundary.test.ts` fails if one appears.
|
|
6
6
|
|
|
7
7
|
`installedImplementationDigest` pins the installed bytes of this package and its fixed first-party dependencies. An upper package pins its own installed entrypoint by passing it as an additional entry; the entries are never record- or model-supplied paths. Each pinned package directory is walked within the steward hook implementation bounds (depth 16, 2,000 entries, 8 MiB per code file and 32 MiB per package); a larger tree or a nonregular code file is refused with `IA-CORPUS-DENIED`, never truncated, and `tests/installed-catalog.test.ts` exercises each bound. Each code file is opened once and read through the descriptor whose size was bounded; a file that grows while it is read, or an entry swapped for a link, socket or device after its directory was read, is refused with the same code.
|
|
8
8
|
|
|
9
9
|
## Host generation
|
|
10
10
|
|
|
11
|
-
W01. Agent files from authored agent profiles (2026-10-09, revised 2026-10-11; position-and-projection §4; milestone generation-binding task generation-agent-profile, plan amendments C1, C5, C6, C7 and C12, operator decision OD4, review findings A-R3, A-R6 to A-R9, A-RC2 to A-RC5 and N1 to N5): `src/generate/agent-profile.ts`, exported through `src/generate/index.ts` on the `./internal/generate` subpath only, publishes `generateAgentProfiles(reader, within, host)`, which returns a frozen `GeneratedSet`, `{files, unsupported}`: `files` the `GeneratedFile` rows `{path, text, identity, word: 'agent-profile'}`, `unsupported` the `UnsupportedRecord` rows `{identity, word, reason}` the projection receipt's `unsupported` section holds. Only `@agent-profile` records at band 100 that the scope token `within` admits are read, by identity; a profile below band 100, where an installed or adopted base places its records, renders nothing and is not reported, and no system steward renders, a steward being an `@agent` (design §4). For `codex` every authored profile is an unsupported row: a codex agent needs an entry in `.codex/config.toml`, which holds the owned MCP block (C12). For `claude` each profile renders `.claude/agents/<profile name>.md`, unless it is reported instead: its name is no portable host name (`safeName`: lower-case letters, digits and single hyphens, a letter first and no hyphen last, at most 64 characters, no Windows device name, `com0` and `lpt0` included); its capabilities allow no host tool (claude gives an agent with no tool list every tool, so only an unwritten file grants nothing); the composition compiler would refuse its capability closure (`closureRefusal`: an inclusion cycle, or an included capability with an effect its includer does not declare, the compiler holding each capability's own `execution.effects` as the ceiling of what it includes); or its text is not inert prose (projection-host's `inert`: no executable dynamic context, no active HTML, no unbalanced code span or fence), judged on each authored value before rendering, so the reason names what the record itself holds, and on the rendered file. One record's refusal never fails the others. Any other host is IA-PROJECTION-INPUT-INVALID, and for either host an unknown or stale token keeps its database code. A profile's capability closure is its `composition.capabilities` and every capability they include through `composition.includes`, each once (`capabilityClosure`). The file is YAML frontmatter: `name` the JSON-quoted profile name; `description` the JSON-quoted `meaning.says` of its `composition.agent` when the workspace authors that `@agent`, else the profile's own, so an installed or adopted base's text never decides when claude delegates; and `tools`, the claude names of the host tools the `execution.effects` of the profile's own `composition.capabilities` cover (each bounds what it includes, so the closure adds none) through `PROSE_EFFECT_TOOLS` (`read` covers Read,
|
|
11
|
+
W01. Agent files from authored agent profiles (2026-10-09, revised 2026-10-11; position-and-projection §4; milestone generation-binding task generation-agent-profile, plan amendments C1, C5, C6, C7 and C12, operator decision OD4, review findings A-R3, A-R6 to A-R9, A-RC2 to A-RC5 and N1 to N5): `src/generate/agent-profile.ts`, exported through `src/generate/index.ts` on the `./internal/generate` subpath only, publishes `generateAgentProfiles(reader, within, host)`, which returns a frozen `GeneratedSet`, `{files, unsupported}`: `files` the `GeneratedFile` rows `{path, text, identity, word: 'agent-profile'}`, `unsupported` the `UnsupportedRecord` rows `{identity, word, reason}` the projection receipt's `unsupported` section holds. Only `@agent-profile` records at band 100 that the scope token `within` admits are read, by identity; a profile below band 100, where an installed or adopted base places its records, renders nothing and is not reported, and no system steward renders, a steward being an `@agent` (design §4). For `codex` every authored profile is an unsupported row: a codex agent needs an entry in `.codex/config.toml`, which holds the owned MCP block (C12). For `claude` each profile renders `.claude/agents/<profile name>.md`, unless it is reported instead: its name is no portable host name (`safeName`: lower-case letters, digits and single hyphens, a letter first and no hyphen last, at most 64 characters, no Windows device name, `com0` and `lpt0` included); its capabilities allow no host tool (claude gives an agent with no tool list every tool, so only an unwritten file grants nothing); the composition compiler would refuse its capability closure (`closureRefusal`: an inclusion cycle, or an included capability with an effect its includer does not declare, the compiler holding each capability's own `execution.effects` as the ceiling of what it includes); or its text is not inert prose (projection-host's `inert`: no executable dynamic context, no active HTML, no unbalanced code span or fence), judged on each authored value before rendering, so the reason names what the record itself holds, and on the rendered file. One record's refusal never fails the others. Any other host is IA-PROJECTION-INPUT-INVALID, and for either host an unknown or stale token keeps its database code. A profile's capability closure is its `composition.capabilities` and every capability they include through `composition.includes`, each once (`capabilityClosure`). The file is YAML frontmatter: `name` the JSON-quoted profile name; `description` the JSON-quoted `meaning.says` of its `composition.agent` when the workspace authors that `@agent`, else the profile's own, so an installed or adopted base's text never decides when claude delegates; and `tools`, the claude names of the host tools the `execution.effects` of the profile's own `composition.capabilities` cover (each bounds what it includes, so the closure adds none) through `PROSE_EFFECT_TOOLS` (`read` covers Read, Grep and Glob; no other effect maps a tool), first-stated and each once, as one JSON-quoted comma-separated string. Then a blank line and runtime's `PACKET_MARKER` on its own line (C5), and a body read only from the records the profile's own fields reference, each resolved through the same token: the title, the profile's `meaning.says`, its identity and its agent's; `## Mandate`; `## Voice`, when `composition.voice` is set, its identity and each `communication.*` field; `## Tools`, one line per capability of the closure naming its operations, effects and host tools, after a line for each `composition.capabilities` reference no admitted capability answers; and `## Delegates`, one line per `composition.delegates` reference, never refused. `## Mandate` holds the profile's own `composition.mandate` as one list item, its identity, with `authority.participant`, `moves`, `scope`, `excluded-words`, `covers` and each `execution.limit-*` it states nested beneath it, as authored and never judged. A profile that names none falls back to C1: the authored mandates `governingMandates(reader, within, {actor})` returns for its `composition.agent` that bind it (`binds !== false`, so a mandate naming no participant is included, unless it states neither scope nor covers and so governs no path), each as such a group, after a line labelling them as the fallback and saying the guard refuses the agent where a mandate that binds another participant governs and none of these grants the move; the agent is the one a subagent acts as for the edit guard (OD4), so the file states what that guard enforces. Every rendered profile separately explains that CLI commands choose an authored workspace participant or steward and that omitting `--actor` uses the workspace's default actor, rather than selecting the profile's agent. When none binds the line says so; when C1 cannot read a mandate (IA-RUNTIME-REQUEST-INVALID) or the agent is not an admitted `@agent`, the line says the fallback is unavailable and why. The fallback is resolved only for a rendered profile that needs it. When the profile's own mandate names a participant other than its agent, a nested line says so: the edit guard judges the agent by the mandates that bind it. Free text is written with runtime's packet helpers (`inline`, `code` and `prose` on `./internal/packet-host`): on one line, each bare IA word token a code span in the body; every C0 or C1 control but tab and the folded line breaks, the Unicode line and paragraph separators and the bidirectional controls become spaces; `<!--` is written `<!--`, a `!` that a rendered code span would follow `!`, and a leading `<` `<`, so no authored value starts a YAML or Markdown line, equals a marker line, opens a comment that hides what follows, reads as dynamic context or opens an HTML block. A reference is printed as the identity it resolves to, or as authored with `not admitted in this scope` where its fields would be read; a field contributes only its unconditional values. The text is a function of the scope's records alone: no absolute path, time, scope token, revision or package version. Generation reuses the prose catalog, the effect table, `inert` and `nativeValue`, not `compileProjection`'s descriptor and publication machinery (C6). Nothing applies the files yet: task host-consumes-generated-set hands them to `applyHostProjection` and lists them in the receipt (C4). `tests/generate-agent-profile.test.ts` lays apps/cli's composition fixture (`tests/fixtures/composition-workspace`, C7) over the conformance corpus adopted at band 90 and pins: the fixture profile's exact file, its own mandate's other-participant line included, and an empty unsupported list, frozen; the fallback naming the mandates that bind the reviewer agent and not the demo participant's, a participant-less mandate included and one that locates nowhere left out, the line for none binding, and an unavailable fallback for an admitted empty move list and for an unadmitted agent, while a profile that names its mandate and a workspace with no profile never resolve it; a named mandate's nested bounds; delegates; unsupported rows for profiles allowed no host tool, for unportable names and for text that runs a command or holds active HTML, the others still rendered; IA words, controls, separators and comment openers in free text, and an adopted agent's text kept out of the description; one tools line per capability, the tools of a profile whose capability includes another, and a closure the compiler refuses (a cycle, an undeclared included effect) reported; a `!` before a rendered span and a leading `<?` escaped, and a lone backtick reported by the value's own reason; narrowed scopes; an adopted profile rendering and reporting nothing for either host; this repository's own `example-profile`; codex reporting every profile, an unknown host refused, a forged or stale token refused; and equal bytes at two roots and under a second token.
|
|
12
12
|
|
|
13
13
|
W02. Skills from authored playbooks (2026-10-09, revised 2026-10-11; position-and-projection §4; milestone generation-binding task generation-playbook-skill, plan amendments C6, C7, C8 and C12, review findings A-R3, A-R6, N1 and N5): `src/generate/playbook.ts`, on the same subpath, publishes `generatePlaybookSkills(reader, within, host)`, which returns a frozen `GeneratedSet` with `word: 'playbook'`. Only `@playbook` records at band 100 that the token admits are read, by identity (C8, operator decision OD3): a playbook below band 100 renders nothing and stays the cells `ia position` delivers. For either host each renders one skill, `.claude/skills/<playbook name>/SKILL.md` for `claude` and `.agents/skills/<playbook name>/SKILL.md` for `codex`, with the same text, unless it is an unsupported row instead: its name is no portable host name (`safeName`), it is named `ia-authoring`, the one skill the packet renders for each host and the projection writer owns (a record's name is lowercase, so no spelling escapes this), or its text is not inert prose. The file is YAML frontmatter (`name` and `description`, the JSON-quoted name and `meaning.says`), a blank line and `PACKET_MARKER` on its own line, the title and identity, then one `## <phase>` section per phase in the cycle order orient, plan, act, learn (the language's `PHASES`), a phase with no cell left out: the primary primitive's cell first and marked `(primary)`, then the others in authored order, each with its condition's terms when it has one and its text written as W01 writes free text. The text is a function of the playbook's record alone. Nothing applies the files yet (C4). `tests/generate-playbook.test.ts` pins the fixture playbook's exact skill for both hosts, conditions and phase order, adopted playbooks rendering and reporting nothing, the reserved name reported for either host, unportable names and non-inert cells reported with the fixture's own skill still rendered, IA words and comment openers in cells, this repository's own `example-method`, refused hosts and tokens, and equal bytes at two roots.
|
|
14
14
|
|
|
@@ -16,6 +16,10 @@ W03. Hook declarations from authored hooks (2026-10-11; milestone generation-bin
|
|
|
16
16
|
|
|
17
17
|
W04. Operation and harness definitions (2026-10-11; milestone generation-binding plan amendment C11, review findings A-R5, A-R9, A-R10, A-RC5 and N7): `src/generate/definitions.ts`, on the same subpath, publishes `generateDefinitions(reader, within, host)`, which returns frozen `PacketDefinition` rows (runtime's union of `{word: 'operation', definition: OperationDefinition}` and `{word: 'harness', definition: HarnessDefinition}`), the authored (band 100) `@operation` records first, then the `@harness` records, each by identity. An operation's definition is its name, `meaning.says`, `execution.handler`, `execution.input`, `execution.output` and `execution.effects`, a field it does not state absent; the handler and the two validator ids are catalog keys an installed implementation answers, copied as authored and never imported, resolved, served or executed here (milestone 7 owns execution; the MCP door serves no new tool). A harness's definition is its name, `meaning.says`, `composition.workspace`, `execution.host-profile`, `composition.profiles`, `composition.bindings` and its registration set: the agent files rendered for its profiles, the skills rendered for the playbooks of their capability closure (W01; a closure the compiler refuses selects none), and the registered hooks its bindings' `binding.target` names, as identities and paths. A record the host does not render or register selects nothing, so hook or agent support never fails the definitions. `tests/generate-playbook.test.ts` pins both fixture rows exactly, the codex registration set, a harness whose profile reaches a playbook only through an include selecting exactly that skill and nothing of the fixture's, and nothing once the include closes a cycle, and this repository's `read-captured-source` row with handler `captured-source-read-v1` and its input and output validator ids.
|
|
18
18
|
|
|
19
|
+
W05. Host plugin from a product distribution (2026-10-14; plan host-authoring-kit-s1 task A8, spec host-authoring-kit §5): `src/generate/plugin.ts`, on the `./internal/generate` subpath, publishes `renderPlugin(reader, within, resources, assets)`, which returns the frozen `PluginFile` rows `{path, bytes}` of one plugin directory, sorted by path, with no marker line. It reads the one authored (band 100) `@distribution` that states `product.name`; none or several is IA-PLUGIN-PRODUCT. One plugin carries every host the product's `product.hosts` lists: for each, the manifest `pluginManifest(product, host)` builds (`.claude-plugin/plugin.json`, `.codex-plugin/plugin.json`, `.grok-plugin/plugin.json`, two-space JSON with a final newline). A product that lists no host is IA-PLUGIN-PRODUCT, so no plugin is rendered without a manifest. Each authored `@capability` with an invocation mode `model` or `user` renders `skills/<name>/SKILL.md`: frontmatter (`name`, `description` from `meaning.says`, `disable-model-invocation: true` for `user`, `argument-hint`) through `emitFrontmatter`, then its one inline body resource byte for byte, then its installed references at their output paths. Each authored `@agent-profile` with an invocation mode renders `agents/<name>.md`: `name`, `description`, `tools` (the claude names of the effects of its capabilities, `Read, Grep, Glob` for `read`, through `toolsOf`), `model` from `execution.model-profile`, `color` from `presentation.color` and `effort` from `execution.effort`, then its inline body. A mode `none` renders nothing; `delegated` is IA-PROJECT-FEATURE ("not rendered by this version of ia"), as is a profile whose capabilities allow no host tool. Assets are copied at their output paths. An output path that is not relative, POSIX and free of empty, `.` and `..` segments, two sources for one path, a skill or profile without exactly one inline body, or a capability reference no admitted record answers is IA-PLUGIN-PRODUCT. `tests/generate-plugin.test.ts` pins the manifests and a user-invoked skill, a profile without an invocation rendering nothing, an agent file with its tools, references and assets, the duplicate and unportable paths, the Claude manifest's fields, a delegated capability, and a product with an empty or absent host list refused.
|
|
20
|
+
|
|
21
|
+
W06. Host plugin lowering and comparison (2026-10-14; plan host-authoring-kit-s1 tasks A4 to A6 and A10, spec host-authoring-kit §5.2): `src/host-plugin/*`, on the `./internal/host-plugin` subpath only, which is not a stable contract. `errors.ts` holds `HostPluginError` and its codes. `frontmatter.ts` reads and writes the strict frontmatter subset (plain, double- and single-quoted strings, booleans and one-line lists of plain items; anything else, CRLF, a byte-order mark or non-UTF-8 bytes is unresolved, never normalized). `inventory.ts` reads a plugin directory (`readEntries`, `inventoryOf`, `readPlugin`): every regular file by sorted POSIX path, refusing a link, a `.git` or `node_modules` entry in any letter case, a non-regular file and more than 1,000 files or 16 MiB with IA-PLUGIN-INPUT, and classifying manifests, skills with their owned files, agents and other files; hooks, MCP and LSP configuration and `commands/` are unresolved. `manifest.ts` publishes `pluginManifest(product, host)`, the pure builder of the manifest object each host's `plugin.json` holds, which W05 writes and lowering compares against. `lower.ts` publishes `lowerPlugin(inventory, system)`, a frozen `LoweringPlan` of files, records, assets, the `ia.lowering-map.v1` map (every file and every accepted frontmatter key one disposition: field, resource, asset or derived; an agent's `name` derived as `@agent-profile <name>`, `model` to `execution.model-profile`, `effort` to `execution.effort`, `color` to `presentation.color`), `MIGRATION.md` generated from it, and the unresolved entries. Lowering admits only what W05 writes back: an agent's `tools` only as one string whose `split(', ')` rejoins to exactly the original; each manifest only when it equals, by `isDeepStrictEqual`, what `pluginManifest` builds for the lowered product, a Codex manifest's absent hook map excepted (each difference an unresolved entry naming the manifest and the key path); no explicit `disable-model-invocation: false`, which W05 omits (the reason says to remove the key). Its lowered system requires `agent-composition-system`, `agent-system`, `compliance-system`, `learning-system` and `workspace-system`, sorted, so trigger `@contract`, `@case` and `@observation` records can be authored in it. Every unresolved message says what "is not lowered by this version of ia", never a plan slice. `compare.ts` publishes `comparePlugin(original, rendered)` and `DIFF_RULES`: each file identical, ruled by named rules (`frontmatter-scalar-style`, `frontmatter-field-order`, `frontmatter-default-omitted`, `tool-order`, `manifest-format`, `codex-hooks-suppressed`), drift, missing or extra. `tests/host-plugin.test.ts` pins the frontmatter subset, the inventory and its refusals, lowering the sample byte for byte, each unresolved construct, the manifest builder against the sample, the tools forms and manifest variants lowering refuses or accepts, the agent dispositions, the wording and the comparison rules.
|
|
22
|
+
|
|
19
23
|
W02. Execution binding (milestone generation-binding task execution-binding-host-entry, plan amendments C16 and C24): `src/bind.ts` (`./bind`) joins each `@execution-binding` with the installed-implementation catalog's operation rows, typed by `@inventarch/db/distribution`'s `InstalledOperation`. `executionBindings(reader)` reads every admitted binding with its unconditional `binding.kind`, `binding.implementation` and `binding.target`, a stated target kept as the reference written and the identity it resolves to, null when no admitted record answers it (`BindingTarget`; review finding B2-R1: a stated target is never read as no target); `bindExecution(binding, catalog)` returns `bound` only when the catalog is present, lists the implementation as available, the binding is an operation binding and its target, when it states one, resolves to the operation the implementation serves; `unavailable` when there is no catalog, it does not list the implementation, lists it unavailable, the kind has no catalog section, the stated target resolves to no admitted record (so the canonical `read-captured-source-binding`, copied into an `ia init` consumer that admits no `@operation read-captured-source`, is unavailable there) or the implementation serves another operation; `revoked`, an error, when the catalog revokes it or failed verification. The catalog is the one `@inventarch/distribution` read from the verified host payload; this package never imports the composition system, and nothing is loaded or executed.
|
|
20
24
|
|
|
21
25
|
## Dependency policy
|
package/dist/generate/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export type { HostSet } from './definitions.js';
|
|
|
5
5
|
export { generateHooks, generateHookSet, HOOK_IDENTITY, HOOK_IDENTITY_LIMIT, HOOK_LIMIT, HOOK_SELECTION_LENGTH, HOOK_SELECTION_LIMIT, hookDeclaration, registrableHook, registrableSelection, } from './hook.js';
|
|
6
6
|
export type { HookSet } from './hook.js';
|
|
7
7
|
export type { GeneratedFile, GeneratedSet, GeneratedWord, UnsupportedRecord } from './format.js';
|
|
8
|
+
export { renderPlugin, type PluginAsset, type PluginFile, type PluginResource } from './plugin.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generate/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,oBAAoB,GACrB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generate/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,oBAAoB,GACrB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/generate/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { generateAgentProfiles } from './agent-profile.js';
|
|
|
4
4
|
export { generatePlaybookSkills } from './playbook.js';
|
|
5
5
|
export { generateDefinitions, generateHostSet } from './definitions.js';
|
|
6
6
|
export { generateHooks, generateHookSet, HOOK_IDENTITY, HOOK_IDENTITY_LIMIT, HOOK_LIMIT, HOOK_SELECTION_LENGTH, HOOK_SELECTION_LIMIT, hookDeclaration, registrableHook, registrableSelection, } from './hook.js';
|
|
7
|
+
export { renderPlugin } from './plugin.js';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generate/index.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,4DAA4D;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,oBAAoB,GACrB,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generate/index.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,4DAA4D;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,YAAY,EAA0D,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ReadHandle } from '@inventarch/db';
|
|
2
|
+
export interface PluginResource {
|
|
3
|
+
readonly owner: string;
|
|
4
|
+
readonly role: string;
|
|
5
|
+
readonly delivery: 'inline' | 'installed-reference';
|
|
6
|
+
/** Plugin-relative output path for an installed reference; unused for an inline body. */
|
|
7
|
+
readonly output: string;
|
|
8
|
+
readonly bytes: Buffer;
|
|
9
|
+
}
|
|
10
|
+
export interface PluginAsset {
|
|
11
|
+
readonly output: string;
|
|
12
|
+
readonly bytes: Buffer;
|
|
13
|
+
}
|
|
14
|
+
export interface PluginFile {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly bytes: Buffer;
|
|
17
|
+
}
|
|
18
|
+
/** The plugin a workspace's one product `@distribution` describes: manifests, skills, agents, references and assets. */
|
|
19
|
+
export declare function renderPlugin(reader: ReadHandle, within: string, resources: readonly PluginResource[], assets: readonly PluginAsset[]): readonly PluginFile[];
|
|
20
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/generate/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AASjD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,qBAAqB,CAAC;IACpD,yFAAyF;IACzF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAMD,wHAAwH;AACxH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,cAAc,EAAE,EACpC,MAAM,EAAE,SAAS,WAAW,EAAE,GAC7B,SAAS,UAAU,EAAE,CA0HvB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { emitFrontmatter } from '../host-plugin/frontmatter.js';
|
|
2
|
+
import { HostPluginError } from '../host-plugin/errors.js';
|
|
3
|
+
import { MANIFESTS } from '../host-plugin/inventory.js';
|
|
4
|
+
import { toolsOf } from '../host-plugin/lower.js';
|
|
5
|
+
import { pluginManifest } from '../host-plugin/manifest.js';
|
|
6
|
+
import { stated, textsAt, valuesAt } from './format.js';
|
|
7
|
+
const AUTHORED = 100;
|
|
8
|
+
const json = (value) => Buffer.from(`${JSON.stringify(value, null, 2)}\n`);
|
|
9
|
+
const plain = (text) => ({ kind: 'string', text, style: 'plain' });
|
|
10
|
+
/** The plugin a workspace's one product `@distribution` describes: manifests, skills, agents, references and assets. */
|
|
11
|
+
export function renderPlugin(reader, within, resources, assets) {
|
|
12
|
+
const records = reader.records({ within });
|
|
13
|
+
const authored = (word) => records
|
|
14
|
+
.filter((node) => node.discriminator === word && node.band === AUTHORED)
|
|
15
|
+
.sort((a, b) => (a.identity < b.identity ? -1 : 1));
|
|
16
|
+
const one = (node, field) => textsAt(node, field)[0];
|
|
17
|
+
const products = authored('distribution').filter((node) => stated(node, 'product.name'));
|
|
18
|
+
if (products.length !== 1)
|
|
19
|
+
throw new HostPluginError('IA-PLUGIN-PRODUCT', `A plugin product needs exactly one @distribution with a product section; found ${products.length}`);
|
|
20
|
+
const d = products[0];
|
|
21
|
+
const out = [];
|
|
22
|
+
/** A plugin-relative output path that is the same on every host: relative, POSIX, with no dot segment. */
|
|
23
|
+
const portable = (output) => {
|
|
24
|
+
if (output === '' ||
|
|
25
|
+
output.startsWith('/') ||
|
|
26
|
+
output.includes('\\') ||
|
|
27
|
+
/^[A-Za-z]:/.test(output) ||
|
|
28
|
+
output.split('/').some((segment) => segment === '' || segment === '.' || segment === '..'))
|
|
29
|
+
throw new HostPluginError('IA-PLUGIN-PRODUCT', `${output} is not a portable plugin path`);
|
|
30
|
+
return output;
|
|
31
|
+
};
|
|
32
|
+
const add = (path, bytes) => {
|
|
33
|
+
if (out.some((file) => file.path === path))
|
|
34
|
+
throw new HostPluginError('IA-PLUGIN-PRODUCT', `Two sources render ${path}`);
|
|
35
|
+
out.push(Object.freeze({ path, bytes }));
|
|
36
|
+
};
|
|
37
|
+
const name = one(d, 'product.name');
|
|
38
|
+
if (name === undefined)
|
|
39
|
+
throw new HostPluginError('IA-PLUGIN-PRODUCT', `${d.identity}: product.name is not a name`);
|
|
40
|
+
const product = {
|
|
41
|
+
name,
|
|
42
|
+
displayName: one(d, 'product.display-name'),
|
|
43
|
+
version: one(d, 'product.version'),
|
|
44
|
+
description: one(d, 'product.description'),
|
|
45
|
+
author: one(d, 'product.author'),
|
|
46
|
+
license: one(d, 'product.license'),
|
|
47
|
+
keywords: stated(d, 'product.keywords') ? textsAt(d, 'product.keywords') : undefined,
|
|
48
|
+
shortDescription: one(d, 'product.short-description'),
|
|
49
|
+
category: one(d, 'product.category'),
|
|
50
|
+
};
|
|
51
|
+
// One plugin carries every host its product lists; a product that lists none would render a plugin with no manifest.
|
|
52
|
+
const hosts = textsAt(d, 'product.hosts').filter((host) => Object.hasOwn(MANIFESTS, host));
|
|
53
|
+
if (hosts.length === 0)
|
|
54
|
+
throw new HostPluginError('IA-PLUGIN-PRODUCT', `${d.identity}: product.hosts names no host; a plugin needs at least one manifest`);
|
|
55
|
+
for (const host of hosts)
|
|
56
|
+
add(MANIFESTS[host], json(pluginManifest(product, host)));
|
|
57
|
+
const bodyOf = (owner) => {
|
|
58
|
+
const bodies = resources.filter((r) => r.owner === owner && r.role === 'body' && r.delivery === 'inline');
|
|
59
|
+
if (bodies.length !== 1)
|
|
60
|
+
throw new HostPluginError('IA-PLUGIN-PRODUCT', `${owner} needs exactly one inline body resource; found ${bodies.length}`);
|
|
61
|
+
return bodies[0].bytes;
|
|
62
|
+
};
|
|
63
|
+
for (const capability of authored('capability').filter((node) => stated(node, 'invocation.mode'))) {
|
|
64
|
+
const mode = one(capability, 'invocation.mode');
|
|
65
|
+
if (mode === 'none')
|
|
66
|
+
continue;
|
|
67
|
+
if (mode === 'delegated')
|
|
68
|
+
throw new HostPluginError('IA-PROJECT-FEATURE', `${capability.identity}: delegated skills are not rendered by this version of ia`);
|
|
69
|
+
const fields = [
|
|
70
|
+
{ key: 'name', value: plain(capability.name) },
|
|
71
|
+
{ key: 'description', value: plain(one(capability, 'meaning.says') ?? '') },
|
|
72
|
+
...(mode === 'user'
|
|
73
|
+
? [{ key: 'disable-model-invocation', value: { kind: 'boolean', value: true } }]
|
|
74
|
+
: []),
|
|
75
|
+
...(one(capability, 'invocation.argument-hint') === undefined
|
|
76
|
+
? []
|
|
77
|
+
: [{ key: 'argument-hint', value: plain(one(capability, 'invocation.argument-hint')) }]),
|
|
78
|
+
];
|
|
79
|
+
add(`skills/${capability.name}/SKILL.md`, Buffer.concat([Buffer.from(emitFrontmatter(fields)), bodyOf(capability.identity)]));
|
|
80
|
+
for (const reference of resources.filter((r) => r.owner === capability.identity && r.delivery === 'installed-reference'))
|
|
81
|
+
add(portable(reference.output), reference.bytes);
|
|
82
|
+
}
|
|
83
|
+
const nodes = new Map(records.map((node) => [node.identity, node]));
|
|
84
|
+
// An agent-profile without an invocation mode is not a plugin entry point (ruling R3).
|
|
85
|
+
for (const profile of authored('agent-profile').filter((node) => stated(node, 'invocation.mode'))) {
|
|
86
|
+
const mode = one(profile, 'invocation.mode');
|
|
87
|
+
if (mode === 'none')
|
|
88
|
+
continue;
|
|
89
|
+
if (mode === 'delegated')
|
|
90
|
+
throw new HostPluginError('IA-PROJECT-FEATURE', `${profile.identity}: delegated agents are not rendered by this version of ia`);
|
|
91
|
+
const effects = valuesAt(profile, 'composition.capabilities').flatMap((value) => {
|
|
92
|
+
const resolved = value.kind === 'ref' ? reader.resolve(value, { within }) : undefined;
|
|
93
|
+
const target = resolved?.ok ? nodes.get(resolved.identity) : undefined;
|
|
94
|
+
if (!target)
|
|
95
|
+
throw new HostPluginError('IA-PLUGIN-PRODUCT', `${profile.identity}: an unresolved capability`);
|
|
96
|
+
return textsAt(target, 'execution.effects');
|
|
97
|
+
});
|
|
98
|
+
const tools = toolsOf(effects);
|
|
99
|
+
if (tools.length === 0)
|
|
100
|
+
throw new HostPluginError('IA-PROJECT-FEATURE', `${profile.identity}: its capabilities allow no host tool`);
|
|
101
|
+
const optional = (key, field) => one(profile, field) === undefined ? [] : [{ key, value: plain(one(profile, field)) }];
|
|
102
|
+
const fields = [
|
|
103
|
+
{ key: 'name', value: plain(profile.name) },
|
|
104
|
+
{ key: 'description', value: plain(one(profile, 'meaning.says') ?? '') },
|
|
105
|
+
{ key: 'tools', value: plain(tools.join(', ')) },
|
|
106
|
+
...optional('model', 'execution.model-profile'),
|
|
107
|
+
...optional('color', 'presentation.color'),
|
|
108
|
+
...optional('effort', 'execution.effort'),
|
|
109
|
+
];
|
|
110
|
+
add(`agents/${profile.name}.md`, Buffer.concat([Buffer.from(emitFrontmatter(fields)), bodyOf(profile.identity)]));
|
|
111
|
+
}
|
|
112
|
+
for (const asset of assets)
|
|
113
|
+
add(portable(asset.output), asset.bytes);
|
|
114
|
+
return Object.freeze(out.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0)));
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/generate/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAmB,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAsB,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAmBxD,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,IAAI,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AAC5F,MAAM,KAAK,GAAG,CAAC,IAAY,EAAuB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAEhG,wHAAwH;AACxH,MAAM,UAAU,YAAY,CAC1B,MAAkB,EAClB,MAAc,EACd,SAAoC,EACpC,MAA8B;IAE9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAU,EAAE,CACxC,OAAO;SACJ,MAAM,CAAC,CAAC,IAA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AK,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7F,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type PluginEntry } from './inventory.js';
|
|
2
|
+
export declare const DIFF_RULES: readonly ["frontmatter-scalar-style", "frontmatter-field-order", "frontmatter-default-omitted", "tool-order", "manifest-format", "codex-hooks-suppressed"];
|
|
3
|
+
export type DiffRule = (typeof DIFF_RULES)[number];
|
|
4
|
+
export interface FileDiff {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly status: 'identical' | 'ruled' | 'drift' | 'missing' | 'extra';
|
|
7
|
+
readonly rules: readonly DiffRule[];
|
|
8
|
+
readonly reason: string | null;
|
|
9
|
+
}
|
|
10
|
+
/** Original files against rendered ones: identical, explained by named rules, or drift. */
|
|
11
|
+
export declare function comparePlugin(original: readonly PluginEntry[], rendered: readonly {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly bytes: Buffer;
|
|
14
|
+
}[]): FileDiff[];
|
|
15
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../src/host-plugin/compare.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7D,eAAO,MAAM,UAAU,4JAOb,CAAC;AACX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC;IACvE,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAkFD,2FAA2F;AAC3F,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,QAAQ,EAAE,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,GACrE,QAAQ,EAAE,CAmBZ"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { emitFrontmatter, parseFrontmatter, sameValue } from './frontmatter.js';
|
|
2
|
+
import { MANIFESTS } from './inventory.js';
|
|
3
|
+
import { sameJson } from './json.js';
|
|
4
|
+
export const DIFF_RULES = [
|
|
5
|
+
'frontmatter-scalar-style',
|
|
6
|
+
'frontmatter-field-order',
|
|
7
|
+
'frontmatter-default-omitted',
|
|
8
|
+
'tool-order',
|
|
9
|
+
'manifest-format',
|
|
10
|
+
'codex-hooks-suppressed',
|
|
11
|
+
];
|
|
12
|
+
const DEFAULTS = {
|
|
13
|
+
'disable-model-invocation': 'false',
|
|
14
|
+
'user-invocable': 'true',
|
|
15
|
+
};
|
|
16
|
+
const isFrontmatterFile = (path) => /^skills\/[^/]+\/SKILL\.md$/.test(path) || /^agents\/[^/]+\.md$/.test(path);
|
|
17
|
+
const drift = (path, reason) => ({ path, status: 'drift', rules: [], reason });
|
|
18
|
+
function manifestDiff(path, a, b) {
|
|
19
|
+
let before;
|
|
20
|
+
let after;
|
|
21
|
+
try {
|
|
22
|
+
before = JSON.parse(a.toString('utf8'));
|
|
23
|
+
after = JSON.parse(b.toString('utf8'));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return drift(path, 'manifest is not JSON');
|
|
27
|
+
}
|
|
28
|
+
if (sameJson(before, after))
|
|
29
|
+
return { path, status: 'ruled', rules: ['manifest-format'], reason: null };
|
|
30
|
+
if (path === MANIFESTS.codex && before['hooks'] === undefined) {
|
|
31
|
+
const { hooks, ...rest } = after;
|
|
32
|
+
if (sameJson(hooks, { hooks: {} }) && sameJson(before, rest))
|
|
33
|
+
return { path, status: 'ruled', rules: ['codex-hooks-suppressed', 'manifest-format'], reason: null };
|
|
34
|
+
}
|
|
35
|
+
return drift(path, 'manifest content differs');
|
|
36
|
+
}
|
|
37
|
+
/** The members of a tools value when it is a plain list or a comma-and-space string, else null. */
|
|
38
|
+
function members(value) {
|
|
39
|
+
if (value.kind === 'list')
|
|
40
|
+
return [...value.items];
|
|
41
|
+
if (value.kind === 'string')
|
|
42
|
+
return value.text.split(', ');
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
function frontmatterDiff(path, a, b) {
|
|
46
|
+
const before = parseFrontmatter(a, path), after = parseFrontmatter(b, path);
|
|
47
|
+
const unparsed = [...before.unresolved, ...after.unresolved];
|
|
48
|
+
if (unparsed.length > 0)
|
|
49
|
+
return drift(path, `frontmatter not compared: ${unparsed[0]}`);
|
|
50
|
+
if (!before.body.equals(after.body))
|
|
51
|
+
return drift(path, 'body bytes differ');
|
|
52
|
+
if (b.toString('utf8').startsWith('---\n')) {
|
|
53
|
+
const canonical = Buffer.concat([Buffer.from(emitFrontmatter(after.fields), 'utf8'), after.body]);
|
|
54
|
+
if (!canonical.equals(b))
|
|
55
|
+
return drift(path, 'rendered frontmatter is not in the emitted form');
|
|
56
|
+
}
|
|
57
|
+
const rules = new Set();
|
|
58
|
+
const kept = before.fields.filter((field) => {
|
|
59
|
+
const omitted = DEFAULTS[field.key] !== undefined &&
|
|
60
|
+
field.value.kind === 'boolean' &&
|
|
61
|
+
String(field.value.value) === DEFAULTS[field.key] &&
|
|
62
|
+
!after.fields.some((f) => f.key === field.key);
|
|
63
|
+
if (omitted)
|
|
64
|
+
rules.add('frontmatter-default-omitted');
|
|
65
|
+
return !omitted;
|
|
66
|
+
});
|
|
67
|
+
const keysBefore = kept.map((f) => f.key), keysAfter = after.fields.map((f) => f.key);
|
|
68
|
+
if (keysBefore.join() !== keysAfter.join()) {
|
|
69
|
+
if ([...keysBefore].sort().join() !== [...keysAfter].sort().join())
|
|
70
|
+
return drift(path, 'frontmatter keys differ');
|
|
71
|
+
rules.add('frontmatter-field-order');
|
|
72
|
+
}
|
|
73
|
+
for (const field of kept) {
|
|
74
|
+
const other = after.fields.find((f) => f.key === field.key);
|
|
75
|
+
if (sameValue(field.value, other.value)) {
|
|
76
|
+
if (field.value.kind === 'string' && other.value.kind === 'string' && field.value.style !== other.value.style)
|
|
77
|
+
rules.add('frontmatter-scalar-style');
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const left = field.key === 'tools' && field.value.kind === other.value.kind ? members(field.value) : null;
|
|
81
|
+
const right = left === null ? null : members(other.value);
|
|
82
|
+
if (left !== null && right !== null && [...left].sort().join() === [...right].sort().join()) {
|
|
83
|
+
rules.add('tool-order');
|
|
84
|
+
if (field.value.kind === 'string' && other.value.kind === 'string' && field.value.style !== other.value.style)
|
|
85
|
+
rules.add('frontmatter-scalar-style');
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
return drift(path, `frontmatter ${field.key} differs`);
|
|
89
|
+
}
|
|
90
|
+
if (rules.size === 0)
|
|
91
|
+
return drift(path, 'bytes differ and no rule explains them');
|
|
92
|
+
return { path, status: 'ruled', rules: DIFF_RULES.filter((rule) => rules.has(rule)), reason: null };
|
|
93
|
+
}
|
|
94
|
+
/** Original files against rendered ones: identical, explained by named rules, or drift. */
|
|
95
|
+
export function comparePlugin(original, rendered) {
|
|
96
|
+
const before = new Map(original.map((e) => [e.path, e.bytes])), after = new Map(rendered.map((e) => [e.path, e.bytes]));
|
|
97
|
+
return [...new Set([...before.keys(), ...after.keys()])].sort().map((path) => {
|
|
98
|
+
const a = before.get(path), b = after.get(path);
|
|
99
|
+
if (b === undefined)
|
|
100
|
+
return { path, status: 'missing', rules: [], reason: 'not rendered' };
|
|
101
|
+
if (a === undefined)
|
|
102
|
+
return {
|
|
103
|
+
path,
|
|
104
|
+
status: 'extra',
|
|
105
|
+
rules: [],
|
|
106
|
+
reason: 'not in the original',
|
|
107
|
+
};
|
|
108
|
+
if (a.equals(b))
|
|
109
|
+
return { path, status: 'identical', rules: [], reason: null };
|
|
110
|
+
if (Object.values(MANIFESTS).includes(path))
|
|
111
|
+
return manifestDiff(path, a, b);
|
|
112
|
+
if (isFrontmatterFile(path))
|
|
113
|
+
return frontmatterDiff(path, a, b);
|
|
114
|
+
return { path, status: 'drift', rules: [], reason: 'bytes differ' };
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/host-plugin/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAmB,gBAAgB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,SAAS,EAAoB,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,0BAA0B;IAC1B,yBAAyB;IACzB,6BAA6B;IAC7B,YAAY;IACZ,iBAAiB;IACjB,wBAAwB;CAChB,CAAC;AAQX,MAAM,QAAQ,GAAqC;IACjD,0BAA0B,EAAE,OAAO;IACnC,gBAAgB,EAAE,MAAM;CACzB,CAAC;AACF,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAW,EAAE,CAClD,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,C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AAM,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QAC3F,IAAI,CAAC,KAAK,SAAS;YACjB,OAAO;gBACL,IAAI;gBACJ,MAAM,EAAE,OAAO;gBACf,KAAK,EAAE,EAAE;gBACT,MAAM,EAAE,qBAAqB;aAC9B,CAAC;QACJ,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC/E,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7E,IAAI,iBAAiB,CAAC,IAAI,CAAC;YAAE,OAAO,eAAe,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Refusals of the host-plugin lowering and the plugin product; the CLI maps each to a Refusal with its next step. */
|
|
2
|
+
export type HostPluginCode = 'IA-LOWER-UNRESOLVED' | 'IA-PLUGIN-INPUT' | 'IA-PLUGIN-PRODUCT' | 'IA-PROJECT-FEATURE' | 'IA-RESOURCE-DIGEST' | 'IA-ROUNDTRIP-DRIFT' | 'IA-PLUGIN-OUT';
|
|
3
|
+
export declare class HostPluginError extends Error {
|
|
4
|
+
readonly code: HostPluginCode;
|
|
5
|
+
readonly details: readonly string[];
|
|
6
|
+
constructor(code: HostPluginCode, message: string, details?: readonly string[]);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/host-plugin/errors.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,MAAM,MAAM,cAAc,GACtB,qBAAqB,GACrB,iBAAiB,GACjB,mBAAmB,GACnB,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,eAAe,CAAC;AAEpB,qBAAa,eAAgB,SAAQ,KAAK;IAEtC,QAAQ,CAAC,IAAI,EAAE,cAAc;IAE7B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE;gBAF1B,IAAI,EAAE,cAAc,EAC7B,OAAO,EAAE,MAAM,EACN,OAAO,GAAE,SAAS,MAAM,EAAO;CAK3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/host-plugin/errors.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAE7B;IAEA;IAHX,YACW,IAAoB,EAC7B,OAAe,EACN,UAA6B,EAAE;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAgB;QAEpB,YAAO,GAAP,OAAO,CAAwB;QAGxC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** One frontmatter value in the strict subset lowering admits; anything else is unresolved, never guessed. */
|
|
2
|
+
export type FrontValue = {
|
|
3
|
+
readonly kind: 'string';
|
|
4
|
+
readonly text: string;
|
|
5
|
+
readonly style: 'plain' | 'double' | 'single';
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: 'boolean';
|
|
8
|
+
readonly value: boolean;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'list';
|
|
11
|
+
readonly items: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
export interface FrontField {
|
|
14
|
+
readonly key: string;
|
|
15
|
+
readonly value: FrontValue;
|
|
16
|
+
}
|
|
17
|
+
export interface Frontmatter {
|
|
18
|
+
readonly fields: readonly FrontField[];
|
|
19
|
+
/** Every byte after the closing `---` line, unchanged. */
|
|
20
|
+
readonly body: Buffer;
|
|
21
|
+
readonly unresolved: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
/** A string YAML reads back unchanged as a one-line plain scalar. */
|
|
24
|
+
export declare function isPlain(text: string): boolean;
|
|
25
|
+
export declare function parseFrontmatter(bytes: Buffer, path: string): Frontmatter;
|
|
26
|
+
export declare function sameValue(a: FrontValue, b: FrontValue): boolean;
|
|
27
|
+
/** `---`, one `key: value` line per field in the order given, `---`; the caller appends the body bytes. */
|
|
28
|
+
export declare function emitFrontmatter(fields: readonly FrontField[]): string;
|
|
29
|
+
//# sourceMappingURL=frontmatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/host-plugin/frontmatter.ts"],"names":[],"mappings":"AAEA,8GAA8G;AAC9G,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAA;CAAE,GACjG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AACjE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AACD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAQD,qEAAqE;AACrE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAY7C;AAgCD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CA+BzE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAK/D;AAYD,2GAA2G;AAC3G,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,CAErE"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { HostPluginError } from './errors.js';
|
|
2
|
+
const KEY = /^[a-z][a-z0-9-]*$/;
|
|
3
|
+
const RESERVED = /^(?:true|false|yes|no|on|off|null|~)$/i;
|
|
4
|
+
const NUMERIC = /^[-+.]?\d/;
|
|
5
|
+
const INDICATOR = /^[-?:,[\]{}#&*!|>'"%@`]/;
|
|
6
|
+
const control = (text) => [...text].some((c) => c.charCodeAt(0) < 0x20 || c.charCodeAt(0) === 0x7f);
|
|
7
|
+
/** A string YAML reads back unchanged as a one-line plain scalar. */
|
|
8
|
+
export function isPlain(text) {
|
|
9
|
+
return (text.length > 0 &&
|
|
10
|
+
text === text.trim() &&
|
|
11
|
+
!control(text) &&
|
|
12
|
+
!INDICATOR.test(text) &&
|
|
13
|
+
!text.includes(': ') &&
|
|
14
|
+
!text.includes(' #') &&
|
|
15
|
+
!text.endsWith(':') &&
|
|
16
|
+
!RESERVED.test(text) &&
|
|
17
|
+
!NUMERIC.test(text));
|
|
18
|
+
}
|
|
19
|
+
function parseValue(raw) {
|
|
20
|
+
if (raw === 'true' || raw === 'false')
|
|
21
|
+
return { kind: 'boolean', value: raw === 'true' };
|
|
22
|
+
if (raw.startsWith('"')) {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(raw);
|
|
25
|
+
// Only the canonical spelling is admitted: trailing text or non-canonical escapes would not regenerate byte-exact.
|
|
26
|
+
return typeof parsed === 'string' && JSON.stringify(parsed) === raw
|
|
27
|
+
? { kind: 'string', text: parsed, style: 'double' }
|
|
28
|
+
: null;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (raw.startsWith("'")) {
|
|
35
|
+
if (raw.length < 2 || !raw.endsWith("'"))
|
|
36
|
+
return null;
|
|
37
|
+
const inner = raw.slice(1, -1);
|
|
38
|
+
if (inner.replaceAll("''", '').includes("'"))
|
|
39
|
+
return null;
|
|
40
|
+
return { kind: 'string', text: inner.replaceAll("''", "'"), style: 'single' };
|
|
41
|
+
}
|
|
42
|
+
if (raw.startsWith('[')) {
|
|
43
|
+
if (!raw.endsWith(']'))
|
|
44
|
+
return null;
|
|
45
|
+
const inner = raw.slice(1, -1).trim();
|
|
46
|
+
const items = inner === '' ? [] : inner.split(',').map((item) => item.trim());
|
|
47
|
+
return items.every(isPlain) ? { kind: 'list', items } : null;
|
|
48
|
+
}
|
|
49
|
+
return isPlain(raw) ? { kind: 'string', text: raw, style: 'plain' } : null;
|
|
50
|
+
}
|
|
51
|
+
const only = (bytes, reason) => ({ fields: [], body: bytes, unresolved: [reason] });
|
|
52
|
+
export function parseFrontmatter(bytes, path) {
|
|
53
|
+
const text = bytes.toString('utf8');
|
|
54
|
+
if (!Buffer.from(text, 'utf8').equals(bytes))
|
|
55
|
+
return only(bytes, `${path}: not UTF-8`);
|
|
56
|
+
if (text.charCodeAt(0) === 0xfeff)
|
|
57
|
+
return only(bytes, `${path}: a byte-order mark precedes the frontmatter`);
|
|
58
|
+
if (text.includes('\r'))
|
|
59
|
+
return only(bytes, `${path}: CRLF line endings; lowering keeps bytes exact and needs LF`);
|
|
60
|
+
if (!text.startsWith('---\n'))
|
|
61
|
+
return { fields: [], body: bytes, unresolved: [] };
|
|
62
|
+
const end = text.indexOf('\n---\n', 3);
|
|
63
|
+
if (end < 0)
|
|
64
|
+
return only(bytes, `${path}: the frontmatter has no closing --- line`);
|
|
65
|
+
const fields = [];
|
|
66
|
+
const unresolved = [];
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
// An empty block (`---\n---\n`) has no lines; `''.split('\n')` would otherwise yield one bogus empty line.
|
|
69
|
+
const lines = end === 3 ? [] : text.slice(4, end).split('\n');
|
|
70
|
+
for (const line of lines) {
|
|
71
|
+
const colon = line.indexOf(':');
|
|
72
|
+
const key = colon < 0 ? '' : line.slice(0, colon);
|
|
73
|
+
if (!KEY.test(key) || line[colon + 1] !== ' ') {
|
|
74
|
+
unresolved.push(`${path}: unsupported frontmatter line ${JSON.stringify(line)}`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (seen.has(key)) {
|
|
78
|
+
unresolved.push(`${path}: duplicate frontmatter key ${key}`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
seen.add(key);
|
|
82
|
+
const value = parseValue(line.slice(colon + 2));
|
|
83
|
+
if (value === null)
|
|
84
|
+
unresolved.push(`${path}: unsupported value for ${key}`);
|
|
85
|
+
else
|
|
86
|
+
fields.push(Object.freeze({ key, value: Object.freeze(value) }));
|
|
87
|
+
}
|
|
88
|
+
const body = bytes.subarray(Buffer.byteLength(text.slice(0, end + 5), 'utf8'));
|
|
89
|
+
return Object.freeze({ fields: Object.freeze(fields), body, unresolved: Object.freeze(unresolved) });
|
|
90
|
+
}
|
|
91
|
+
export function sameValue(a, b) {
|
|
92
|
+
if (a.kind === 'boolean' && b.kind === 'boolean')
|
|
93
|
+
return a.value === b.value;
|
|
94
|
+
if (a.kind === 'list' && b.kind === 'list')
|
|
95
|
+
return JSON.stringify(a.items) === JSON.stringify(b.items);
|
|
96
|
+
if (a.kind === 'string' && b.kind === 'string')
|
|
97
|
+
return a.text === b.text;
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function emitValue(value) {
|
|
101
|
+
if (value.kind === 'boolean')
|
|
102
|
+
return String(value.value);
|
|
103
|
+
if (value.kind === 'list') {
|
|
104
|
+
if (!value.items.every(isPlain))
|
|
105
|
+
throw new HostPluginError('IA-PROJECT-FEATURE', 'A list item is not a plain scalar');
|
|
106
|
+
return `[${value.items.join(', ')}]`;
|
|
107
|
+
}
|
|
108
|
+
return isPlain(value.text) ? value.text : JSON.stringify(value.text);
|
|
109
|
+
}
|
|
110
|
+
/** `---`, one `key: value` line per field in the order given, `---`; the caller appends the body bytes. */
|
|
111
|
+
export function emitFrontmatter(fields) {
|
|
112
|
+
return ['---', ...fields.map(({ key, value }) => `${key}: ${emitValue(value)}`), '---', ''].join('\n');
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=frontmatter.js.map
|