@skill-map/spec 0.17.0 → 0.19.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +672 -0
  2. package/README.md +1 -1
  3. package/architecture.md +281 -16
  4. package/cli-contract.md +122 -6
  5. package/conformance/cases/orphan-markdown-fallback.json +22 -0
  6. package/conformance/cases/plugin-missing-ui-rejected.json +4 -1
  7. package/conformance/cases/sidecar-end-to-end.json +25 -0
  8. package/conformance/coverage.md +9 -3
  9. package/conformance/fixtures/orphan-markdown/.claude/agents/reviewer.md +6 -0
  10. package/conformance/fixtures/orphan-markdown/ARCHITECTURE.md +10 -0
  11. package/conformance/fixtures/plugin-missing-ui/.skill-map/plugins/bad-provider/provider.js +6 -6
  12. package/conformance/fixtures/sidecar-end-to-end/.claude/agents/orphan.sm +12 -0
  13. package/conformance/fixtures/sidecar-end-to-end/.claude/agents/stale.md +8 -0
  14. package/conformance/fixtures/sidecar-end-to-end/.claude/agents/stale.sm +20 -0
  15. package/conformance/fixtures/sidecar-example/agent-example.md +17 -0
  16. package/conformance/fixtures/sidecar-example/agent-example.sm +53 -0
  17. package/db-schema.md +73 -15
  18. package/index.json +42 -19
  19. package/package.json +1 -1
  20. package/plugin-author-guide.md +426 -27
  21. package/schemas/annotations.schema.json +75 -0
  22. package/schemas/api/rest-envelope.schema.json +159 -46
  23. package/schemas/bump-report.schema.json +29 -0
  24. package/schemas/extensions/base.schema.json +36 -1
  25. package/schemas/extensions/extractor.schema.json +3 -10
  26. package/schemas/extensions/provider.schema.json +23 -1
  27. package/schemas/frontmatter/base.schema.json +6 -1
  28. package/schemas/input-types.schema.json +260 -0
  29. package/schemas/node.schema.json +36 -23
  30. package/schemas/plugins-registry.schema.json +14 -2
  31. package/schemas/project-config.schema.json +11 -0
  32. package/schemas/report-base-deterministic.schema.json +15 -0
  33. package/schemas/sidecar.schema.json +96 -0
  34. package/schemas/summaries/{note.schema.json → markdown.schema.json} +5 -5
  35. package/schemas/view-contracts.schema.json +298 -0
@@ -83,19 +83,20 @@ Concrete examples for the reference impl's bundled extensions:
83
83
  | Extension | Short id (in the file) | Qualified id (in the registry) |
84
84
  |---|---|---|
85
85
  | Claude Provider | `claude` | `claude/claude` |
86
- | Frontmatter extractor | `frontmatter` | `claude/frontmatter` |
87
- | Slash extractor | `slash` | `claude/slash` |
88
- | At-directive extractor | `at-directive` | `claude/at-directive` |
86
+ | Annotations extractor | `annotations` | `core/annotations` |
87
+ | Slash extractor | `slash` | `core/slash` |
88
+ | At-directive extractor | `at-directive` | `core/at-directive` |
89
+ | Markdown-link extractor | `markdown-link` | `core/markdown-link` |
89
90
  | External-URL counter | `external-url-counter` | `core/external-url-counter` |
90
91
  | Broken-ref rule | `broken-ref` | `core/broken-ref` |
91
92
  | Trigger-collision rule | `trigger-collision` | `core/trigger-collision` |
92
93
  | ASCII formatter | `ascii` | `core/ascii` |
93
94
  | Validate-all rule | `validate-all` | `core/validate-all` |
94
95
 
95
- Two namespaces are convention for built-ins:
96
+ Built-ins split between two namespaces:
96
97
 
97
- - **`core/`** — kernel-internal primitives (every built-in rule including `validate-all`, the ASCII formatter, the external-URL counter extractor). Platform-agnostic.
98
- - **`claude/`** — the Claude Code Provider bundle (the Provider plus the three extractors that decode Claude-specific syntax: frontmatter, slash, `@`-directive).
98
+ - **`core/`** — kernel-internal primitives, platform-agnostic. Owns every built-in rule (including `validate-all`), the ASCII formatter, and the cross-vendor extractors (`annotations`, `slash`, `at-directive`, `markdown-link`, `external-url-counter`) any Provider can rely on.
99
+ - **`claude/`** — the Claude Code Provider bundle: the Provider that classifies `.claude/{agents,commands,skills}` paths and parses their frontmatter. Vendor-specific bundles (`gemini`, `agent-skills`) follow the same shape — Provider only — since the syntax their nodes use is shared with Claude and lives in `core`.
99
100
 
100
101
  For your own plugin, the `id` you declare in `plugin.json` is the namespace for every extension the plugin contains. If your manifest declares `id: "my-plugin"` and your extension file declares `id: "foo-extractor"`, the kernel registers it as `my-plugin/foo-extractor`. You do **not** write the qualifier yourself — the loader injects it.
101
102
 
@@ -125,15 +126,15 @@ Every plugin and every built-in bundle declares a **granularity** that controls
125
126
 
126
127
  Built-in mapping:
127
128
 
128
- - **`claude`** — `granularity: 'bundle'`. `sm plugins disable claude` flips the Provider and the three Claude-specific extractors at once.
129
- - **`core`** — `granularity: 'extension'`. `sm plugins disable core/superseded` flips just the supersession rule; the other six core extensions (the four other rules, the ASCII formatter, the external-URL counter extractor) stay live.
129
+ - **`claude`** / **`gemini`** / **`agent-skills`** — `granularity: 'bundle'`. Each vendor Provider bundle is enabled or disabled as a whole; today every such bundle ships only its Provider, so the toggle flips classification + frontmatter parsing for that platform.
130
+ - **`core`** — `granularity: 'extension'`. `sm plugins disable core/superseded` flips just the supersession rule; every other core extension (every other rule, the ASCII formatter, the cross-vendor extractors) stays live.
130
131
 
131
132
  Per-verb behaviour:
132
133
 
133
134
  | Command | Bundle granularity | Extension granularity |
134
135
  |---|---|---|
135
136
  | `sm plugins enable claude` | OK — flips the bundle. | Rejected: `'core' has granularity=extension; use sm plugins enable core/<ext-id>`. |
136
- | `sm plugins enable claude/slash` | Rejected: `'claude' has granularity=bundle; use sm plugins enable claude`. | n/a (no bundle of granularity=bundle accepts qualified ids) |
137
+ | `sm plugins enable claude/claude` | Rejected: `'claude' has granularity=bundle; use sm plugins enable claude`. | n/a (no bundle of granularity=bundle accepts qualified ids) |
137
138
  | `sm plugins disable core` | n/a | Rejected: same directed message as the bundle row above. |
138
139
  | `sm plugins disable core/superseded` | n/a | OK — persists `config_plugins['core/superseded'].enabled = 0`. |
139
140
 
@@ -160,7 +161,7 @@ The default (`'bundle'`) is the right answer for almost every plugin — keep th
160
161
 
161
162
  ### Extractor `applicableKinds` — narrow the pipeline
162
163
 
163
- An `Extractor` extension MAY declare an `applicableKinds` array on its manifest. When declared, the kernel runs the extractor **only** against nodes whose `kind` is in the list — the filter is fail-fast (no extractor context, no method call) so a probabilistic extractor wastes zero LLM cost (and a deterministic extractor zero CPU) on nodes it cannot meaningfully process.
164
+ An `Extractor` extension MAY declare an `applicableKinds` array on its manifest. When declared, the kernel runs the extractor **only** against nodes whose `kind` is in the list — the filter is fail-fast (no extractor context, no method call) so the extractor wastes zero CPU on nodes it cannot meaningfully process.
164
165
 
165
166
  | `applicableKinds` | Behaviour |
166
167
  |---|---|
@@ -171,36 +172,37 @@ An `Extractor` extension MAY declare an `applicableKinds` array on its manifest.
171
172
 
172
173
  There is no wildcard syntax (no `'*'`) — omitting the field IS the wildcard. The pattern is intentional: a literal absence is unambiguous, a string sentinel would invite typos that silently disable the extractor.
173
174
 
174
- Use case — a probabilistic tag-inferrer that only makes sense for skills:
175
+ Use case — a deterministic frontmatter-tag extractor that only makes sense for skills:
175
176
 
176
177
  ```javascript
177
178
  export default {
178
- id: 'tag-inferrer',
179
+ id: 'tag-extractor',
179
180
  kind: 'extractor',
180
- mode: 'probabilistic',
181
181
  version: '1.0.0',
182
- description: 'LLM-derived tag links for skill nodes.',
182
+ description: 'Lifts the `tags:` frontmatter array into `references` links for skill nodes.',
183
183
  emitsLinkKinds: ['references'],
184
- defaultConfidence: 'medium',
185
- scope: 'body',
184
+ defaultConfidence: 'high',
185
+ scope: 'frontmatter',
186
186
  applicableKinds: ['skill'],
187
187
  async extract(ctx) {
188
188
  // Never invoked for agents, commands, hooks, or notes — the kernel
189
189
  // skipped this node before reaching us.
190
- const tags = await ctx.runner.invoke({ /* prompt */ });
190
+ const tags = Array.isArray(ctx.frontmatter.tags) ? ctx.frontmatter.tags : [];
191
191
  for (const t of tags) {
192
192
  ctx.emitLink({
193
193
  source: ctx.node.path,
194
- target: t.path,
194
+ target: t,
195
195
  kind: 'references',
196
- confidence: 'medium',
197
- sources: ['tag-inferrer'],
196
+ confidence: 'high',
197
+ sources: ['tag-extractor'],
198
198
  });
199
199
  }
200
200
  },
201
201
  };
202
202
  ```
203
203
 
204
+ > **Why no `mode` field?** Extractors are deterministic-only — they sit on `sm scan`'s synchronous loop, and the loop must stay fast and reproducible. If you need an LLM to infer something about a node (tags, summaries, suspicious imports), write an `Action` instead and let the user dispatch it via `sm job submit action:<id>`. The Action's report flows back through the job lifecycle, not through the Extractor pipeline.
205
+
204
206
  **Unknown kinds are non-blocking.** An extractor that lists a kind no installed Provider declares (typo, missing Provider plugin) still loads with status `loaded`; `sm plugins doctor` surfaces an informational warning so the author sees the mismatch. The exit code of `doctor` is NOT promoted to 1 by this warning — the corresponding Provider may legitimately arrive later (e.g. when the user installs the matching plugin), and the load contract favours forward compatibility over rigid checks. The full set of "known kinds" is the union of every installed Provider's `defaultRefreshAction` keys.
205
207
 
206
208
  ---
@@ -244,12 +246,12 @@ Authors who explicitly review each minor's changelog **MAY** widen across the ne
244
246
 
245
247
  ## The six extension kinds
246
248
 
247
- The kernel knows six categories. Four are dual-mode (deterministic or probabilistic per [`architecture.md` §Execution modes](./architecture.md)); two are deterministic-only because they sit at the system boundaries.
249
+ The kernel knows six categories. Three are dual-mode (deterministic or probabilistic per [`architecture.md` §Execution modes](./architecture.md)); three are deterministic-only because they sit on the deterministic scan path.
248
250
 
249
251
  | Kind | Method | Receives | Returns | Mode |
250
252
  |---|---|---|---|---|
251
253
  | `provider` | `walk(roots, opts)` | filesystem roots | `IRawNode[]` | deterministic only |
252
- | `extractor` | `extract(ctx)` | one node + body + frontmatter + callbacks | `void` (output via `ctx.emitLink` / `ctx.enrichNode` / `ctx.store`) | dual-mode |
254
+ | `extractor` | `extract(ctx)` | one node + body + frontmatter + callbacks | `void` (output via `ctx.emitLink` / `ctx.enrichNode` / `ctx.store`) | deterministic only |
253
255
  | `rule` | `evaluate(ctx)` | full graph | `Issue[]` | dual-mode |
254
256
  | `action` | `run(ctx)` | one or more nodes | execution record | dual-mode |
255
257
  | `formatter` | `format(ctx)` | full graph | `string` | deterministic only |
@@ -264,10 +266,10 @@ Pure single-node analysis. **Never** read another node, the graph, or the databa
264
266
  The runtime method is `extract(ctx) → void`. Output flows through three callbacks the kernel binds onto the context:
265
267
 
266
268
  - **`ctx.emitLink(link)`** — append a `Link` to the kernel's `links` table. The kernel validates against the extractor's declared `emitsLinkKinds` before persistence; off-contract kinds are dropped and surface as `extension.error` events. URL-shaped targets are partitioned into `node.externalRefsCount` and never persisted.
267
- - **`ctx.enrichNode(partial)`** — merge canonical, kernel-curated properties onto the node's enrichment layer (persisted into `node_enrichments` per `db-schema.md`). **Strictly separate from the author-supplied frontmatter** — the latter is IMMUTABLE from any Extractor. Use the enrichment layer for facts the author did not write but the Extractor inferred (computed titles, summaries, signals from probabilistic Extractors). Probabilistic enrichments track `body_hash_at_enrichment`; when the scan loop sees a body change, those rows are flagged `stale = 1` (NOT deleted, preserving the LLM cost paid to produce them) and surface for refresh via `sm refresh <node>` or `sm refresh --stale`. Deterministic enrichments are simply overwritten via PRIMARY KEY conflict on the next re-extract through the A.9 cache and are never stale-flagged.
269
+ - **`ctx.enrichNode(partial)`** — merge canonical, kernel-curated properties onto the node's enrichment layer (persisted into `node_enrichments` per `db-schema.md`). **Strictly separate from the author-supplied frontmatter** — the latter is IMMUTABLE from any Extractor. Use the enrichment layer for facts the author did not write but the Extractor inferred (computed titles, summaries, signals derived from the body). Enrichment rows are overwritten via PRIMARY KEY conflict on the next re-extract through the A.9 cache and are never stale-flagged (Extractors are deterministic; re-running is free).
268
270
  - **`ctx.store`** — plugin-scoped persistence. Optional, only present when your `plugin.json` declares `storage.mode`. Shape depends on the mode (`KvStore` for mode A, scoped `Database` for mode B). See [`plugin-kv-api.md`](./plugin-kv-api.md).
269
271
 
270
- A probabilistic extractor additionally receives `ctx.runner` (the `RunnerPort`) for LLM dispatch.
272
+ Extractors are deterministic-only and never see `ctx.runner`. If an Extractor needs LLM-derived data on a node, that workload belongs in an Action — see [`architecture.md` §Execution modes](./architecture.md#execution-modes).
271
273
 
272
274
  > **Pick a syntax that doesn't collide with built-ins.** The built-in `at-directive` extractor fires on any `@token`; the built-in `slash` extractor fires on any `/token`. A new extractor that also matches one of those prefixes will likely fire on the same input, and if the two emit different `target` shapes the kernel raises a `trigger-collision` error. The example below uses a wikilink-style `[[ref:<name>]]` pattern to side-step this; reserve `@` and `/` for the built-ins.
273
275
 
@@ -604,11 +606,11 @@ The kernel validates the row passed to `ctx.store.write(table, row)` against the
604
606
 
605
607
  ## Execution modes
606
608
 
607
- Extractor / Rule / Action declare `mode` in the manifest with default `deterministic`. Provider / Formatter must NOT declare `mode`.
609
+ Rule / Action / Hook declare `mode` in the manifest. Action's `mode` is required; Rule and Hook default to `deterministic`. Provider / Extractor / Formatter must NOT declare `mode` — they are deterministic-only by spec.
608
610
 
609
611
  ```jsonc
610
- // deterministic extractor — default, runs in sm scan
611
- { "kind": "extractor", "id": "my-extractor", "mode": "deterministic", ... }
612
+ // extractor — deterministic by spec, no mode field
613
+ { "kind": "extractor", "id": "my-extractor", ... }
612
614
  ```
613
615
 
614
616
  ```jsonc
@@ -681,6 +683,403 @@ Full surface in `@skill-map/testkit/index.ts`.
681
683
 
682
684
  ---
683
685
 
686
+ ## Annotation contributions
687
+
688
+ > **Status.** Ships with spec v0.18.0 (Step 9.6.6). Plugins that want to write first-class fields into a node's co-located `.sm` sidecar declare them in their extension manifest under `annotationContributions`. The kernel validates the contributions at load time, surfaces the runtime catalog via `kernel.getRegisteredAnnotationKeys()` (consumed by the BFF / UI for autocomplete), and treats two plugins claiming the same root-exclusive key as a fatal startup error.
689
+
690
+ ### Manifest shape
691
+
692
+ `annotationContributions` is an object map keyed by the annotation key the extension wants to own. Each entry declares an inline JSON Schema for the value plus two policy fields:
693
+
694
+ ```js
695
+ // my-plugin/extensions/extractor.js
696
+ export default {
697
+ id: 'my-extractor',
698
+ kind: 'extractor',
699
+ version: '1.0.0',
700
+ // ...rest of the extractor manifest...
701
+ annotationContributions: {
702
+ lastReviewedAt: {
703
+ schema: { type: 'string', format: 'date-time' },
704
+ // location and ownership default to 'namespaced' / 'shared'
705
+ },
706
+ },
707
+ };
708
+ ```
709
+
710
+ Field-by-field:
711
+
712
+ | Field | Type | Default | Meaning |
713
+ |--------------|-----------------------------------|----------------|------------------------------------------------------------------------------------------------------|
714
+ | `schema` | inline JSON Schema (object) | required | Validates the value the extension writes under this key. Compiled with AJV at load time. |
715
+ | `location` | `'namespaced'` \| `'root'` | `'namespaced'` | Where the key lands inside the sidecar (see below). |
716
+ | `ownership` | `'shared'` \| `'exclusive'` | `'shared'` | Conflict policy. REQUIRED to be `'exclusive'` when `location: 'root'`. |
717
+
718
+ The `schema` field is **inline** — an object literal in the manifest, not a `$ref` to a file. Aligns with how the extractor / rule / action schemas already declare other inline shapes; avoids an extra path-resolution step at load time.
719
+
720
+ ### Namespacing default vs root opt-in
721
+
722
+ By default a contribution lands inside the plugin's `<plugin-id>:` block at the sidecar root. Two plugins can ship a contribution with the same key and never collide because the runtime path keeps them under separate namespaces:
723
+
724
+ ```yaml
725
+ # .claude/agents/architect.sm
726
+ identity:
727
+ path: .claude/agents/architect.md
728
+ bodyHash: ...
729
+ frontmatterHash: ...
730
+ annotations:
731
+ version: 3
732
+
733
+ # Plugin 'reviewer' contributes 'lastReviewedAt'
734
+ reviewer:
735
+ lastReviewedAt: 2026-05-06T10:00:00Z
736
+
737
+ # Plugin 'auditor' also contributes 'lastReviewedAt' — different namespace, no conflict
738
+ auditor:
739
+ lastReviewedAt: 2026-05-05T18:30:00Z
740
+ ```
741
+
742
+ Opting into a top-level (root) key requires `location: 'root'` AND `ownership: 'exclusive'`. The pair travels together — a top-level reserved key cannot be silently shared between plugins, because `.sm` writes deep-merge per the `SidecarStore` contract and a shared root key would route non-deterministically. Use root sparingly: for every plugin that contributes a root key, the kernel reserves that name across the whole installed-plugin surface.
743
+
744
+ ```js
745
+ // compliance-plugin/extensions/rule.js
746
+ export default {
747
+ id: 'compliance-checker',
748
+ kind: 'rule',
749
+ // ...
750
+ annotationContributions: {
751
+ compliance: {
752
+ schema: {
753
+ type: 'object',
754
+ required: ['audit'],
755
+ properties: {
756
+ audit: { type: 'string' },
757
+ dueAt: { type: 'string', format: 'date-time' },
758
+ },
759
+ },
760
+ location: 'root',
761
+ ownership: 'exclusive',
762
+ },
763
+ },
764
+ };
765
+ ```
766
+
767
+ The resulting sidecar block:
768
+
769
+ ```yaml
770
+ # .claude/agents/architect.sm
771
+ identity: { path: ..., bodyHash: ..., frontmatterHash: ... }
772
+ compliance:
773
+ audit: sox-2026
774
+ dueAt: 2026-12-31T23:59:59Z
775
+ ```
776
+
777
+ ### Ownership rules
778
+
779
+ - `shared` (default) — multiple plugins MAY write the same key. Every plugin gets its own namespaced block; `last-write-wins` is per-`(plugin, key)` tuple inside `FilesystemSidecarStore.applyPatch`. Two plugins on the SAME namespaced key from the same plugin id is structurally impossible (one extension per kind per plugin id by spec), so the only collision surface is intra-extension.
780
+ - `exclusive` — only this plugin may write the key. The kernel rejects any other plugin that tries to claim the same `(key, location: 'root')` tuple as `exclusive`. `exclusive` + `namespaced` is permitted but redundant in practice (the namespace already isolates by plugin id); use it as documentation when you want the manifest to scream "no other plugin should ever write this".
781
+
782
+ ### Collision behaviour — hard fail, no boot
783
+
784
+ Two plugins claiming the same `(key, location: 'root', ownership: 'exclusive')` tuple is a **fatal startup error**. The kernel does NOT boot in this state — `loadPluginRuntime` throws `AnnotationContributionConflictError` and the host (CLI verb, BFF, watch mode) propagates the error and exits non-zero with a clear stderr message naming both offenders. Stricter than the default per-plugin `invalid-manifest` "disable just that plugin" path: annotation-namespace conflicts are non-recoverable because annotated `.sm` files would otherwise become non-deterministically routed.
785
+
786
+ This is the only fatal path on the plugin-load surface. Every other failure mode (manifest invalid, schema invalid, dynamic-import failure, id collision) is per-plugin and the kernel keeps booting on the survivors.
787
+
788
+ ### Tier-1 typo guard (`core/unknown-field`)
789
+
790
+ The built-in `core/unknown-field` Rule walks every parsed `.sm` and emits a `warn` issue per truly-unknown key. Three surfaces are checked:
791
+
792
+ 1. Inside `annotations:` — keys not in `annotations.schema.json`'s curated catalog (the ~25 conventional fields). Plugins do NOT contribute to `annotations:`; that block is skill-map-curated.
793
+ 2. At the sidecar root — keys outside the four reserved blocks (`for`, `annotations`, `settings`, `audit`) that are also NOT a registered plugin namespace `<plugin-id>:` AND NOT a registered `location: 'root'` contribution.
794
+ 3. Inside a registered `<plugin-id>:` namespace — values that fail the schema declared by the owning plugin's `annotationContributions[<key>].schema`.
795
+
796
+ The rule never blocks a scan; advisories surface through the standard issue channel (CLI, UI, REST). When you ship a contribution, the loader compiles your inline schema, the runtime catalog publishes it, and `core/unknown-field` automatically validates user writes against your declaration.
797
+
798
+ ### Runtime catalog accessor
799
+
800
+ Once every plugin has loaded, the runtime catalog is reachable via `kernel.getRegisteredAnnotationKeys()`:
801
+
802
+ ```ts
803
+ // Each entry: { pluginId, key, location, ownership, schema }
804
+ const keys = kernel.getRegisteredAnnotationKeys();
805
+ ```
806
+
807
+ Pure read; no side effects. Built-in catalog fields from `annotations.schema.json` are NOT included — this catalog is plugin-only. The UI knows the built-in catalog separately via the schema bundle. The (future) BFF endpoint surfaces this through `GET /api/annotations/catalog` for autocomplete.
808
+
809
+ ---
810
+
811
+ ## View contributions
812
+
813
+ > **Status.** Sibling system to annotation contributions, designed to let plugins surface per-node data in the UI without shipping any UI code. Plugin authors pick a **contract** by name from a closed kernel catalog, declare per-node emissions in their extension manifest, and emit payloads at scan time via `ctx.emitContribution(id, payload)`. The UI maps contracts to slots and renders. See [`architecture.md`](./architecture.md) §View contribution system for the normative contract.
814
+
815
+ ### What it solves
816
+
817
+ Today, the only way a plugin can surface UI is implicit: extractors emit `Link` (rendered by the kernel-built `linked-nodes-panel`), rules emit `Issue` (rendered by the kernel-built issues panel), providers ship `kinds[*].ui` styling, and one-off plugins write into the sidecar via `annotationContributions`. The moment your extractor wants to surface anything else — a counter on each card, a stat breakdown panel in the inspector, a tree showing parsed structure, a per-node tag — there is no path. View contributions fill that gap. You declare what to surface; the UI decides where and how.
818
+
819
+ ### What you NEVER write
820
+
821
+ - HTML, CSS, JavaScript, or Angular components.
822
+ - JSON Schema for your contributions or your settings.
823
+ - The slot id where your contribution appears (slots are UI-only).
824
+ - The renderer component that draws your contribution.
825
+
826
+ You DO write:
827
+
828
+ - The `contract` name (one of 10 closed-catalog values).
829
+ - Optional `label`, `tooltip`, `icon`, `emptyText`, `emitWhenEmpty` per contribution.
830
+ - The per-node payload your `extract(ctx)` emits via `ctx.emitContribution(...)`.
831
+
832
+ ### Manifest shape
833
+
834
+ Inside any extension manifest (`IExtractor`, `IRule`, ...), declare a `viewContributions` map next to `annotationContributions`. Each key is your local contribution id; the value picks a contract.
835
+
836
+ ```jsonc
837
+ {
838
+ "id": "keyword-finder",
839
+ "kind": "extractor",
840
+ "viewContributions": {
841
+ "breakdown": {
842
+ "contract": "node-breakdown",
843
+ "label": "Keyword hits",
844
+ "emptyText": "No matches."
845
+ },
846
+ "total": {
847
+ "contract": "node-counter",
848
+ "icon": "🔍",
849
+ "label": "kw",
850
+ "emitWhenEmpty": false
851
+ }
852
+ }
853
+ }
854
+ ```
855
+
856
+ Field reference (full schema in [`schemas/view-contracts.schema.json`](./schemas/view-contracts.schema.json) at `$defs/IViewContribution`):
857
+
858
+ | Field | Required | Notes |
859
+ |---|---|---|
860
+ | `contract` | yes | One of the 10 catalog names (see below). Unknown name → `invalid-manifest` at load. |
861
+ | `label` | no | Short human-readable label. English-only per [`AGENTS.md`](../AGENTS.md) (`Externalized texts, not internationalized`). |
862
+ | `tooltip` | no | Hover tooltip on the chip / panel header. |
863
+ | `icon` | no | Single string. If matches Unicode `\p{Extended_Pictographic}` → emoji. Otherwise → PrimeIcons name (no `pi-` prefix). |
864
+ | `emptyText` | no | Text shown when payload is empty AND `emitWhenEmpty: true`. |
865
+ | `emitWhenEmpty` | no, default `false` | When `false`, kernel drops empty payloads silently so the slot stays clean. |
866
+
867
+ ### Contract catalog (closed)
868
+
869
+ The kernel ships exactly these 10 contracts. Each has a fixed payload shape and a fixed set of UI slots it surfaces in. Adding a contract requires a spec / UI / scaffolder round-trip — discuss in [`ROADMAP.md`](../ROADMAP.md) before opening a PR.
870
+
871
+ | Contract | Payload shape | Surfaces in |
872
+ |---|---|---|
873
+ | `node-counter` | `{ value: integer ≥ 0, severity?, label?, tooltip? }` | card chip + inspector header badge |
874
+ | `node-tag` | `{ label, severity?, tooltip? }` | card chip + inspector header badge |
875
+ | `node-breakdown` | `{ entries: Array<{ label, value, tooltip? }> }` (≤ 20) | inspector body (chart-bar) |
876
+ | `node-records` | `{ columns: ≤6, rows: ≤50 }` | inspector body (table) |
877
+ | `node-tree` | recursive `{ label, marker?, children? }` (depth ≤ 6, total ≤ 200) | inspector body (tree) |
878
+ | `node-key-values` | `{ entries: Array<{ key, value, tooltip? }> }` (≤ 50) | inspector body (key-value list) |
879
+ | `node-link-list` | `{ entries: Array<{ path, label?, kind? }> }` (≤ 100) | inspector body (link list) |
880
+ | `node-markdown` | `{ markdown }` (≤ 4096 chars, sanitized) | inspector body (markdown text) |
881
+ | `node-alert` | `{ icon?, severity?, count?, tooltip? }` | graph node corner badge |
882
+ | `scope-stat` | `{ value, label?, severity?, tooltip? }` | topbar indicator |
883
+
884
+ Per-contract semantics, edge cases, and exact payload schemas live in [`schemas/view-contracts.schema.json`](./schemas/view-contracts.schema.json) at `$defs/payloads/<contract>`. Read that schema before emitting.
885
+
886
+ ### Emit path
887
+
888
+ Inside `extract(ctx)`, call:
889
+
890
+ ```ts
891
+ ctx.emitContribution('breakdown', {
892
+ entries: Object.entries(perKeyword).map(([label, value]) => ({ label, value })),
893
+ });
894
+
895
+ ctx.emitContribution('total', { value: total });
896
+ ```
897
+
898
+ The first argument is the manifest Record key (`'breakdown'` or `'total'` above), NOT the contract name. The kernel composes the qualified id from your plugin id, extension id, and this Record key.
899
+
900
+ The kernel validates the payload against the contract's payload schema in `view-contracts.schema.json#/$defs/payloads/<contract>`. Off-contract payloads emit an `extension.error` event and drop silently — same posture as `emitLink` rejecting links not in your `emitsLinkKinds`.
901
+
902
+ For `scope-stat`, rules use `ctx.emitScopeContribution(id, payload)` (extractors do not see this method — scope-level emission lives in rule context).
903
+
904
+ ### Settings
905
+
906
+ User-configurable settings live at the manifest root in `settings: Record<string, ISettingDeclaration>`. Each entry picks an `input-type` from a closed catalog. You NEVER write JSON Schema for settings.
907
+
908
+ ```jsonc
909
+ {
910
+ "id": "keyword-finder",
911
+ "version": "1.0.0",
912
+ "specCompat": "^0.20.0",
913
+ "catalogCompat": "^1.0.0",
914
+ "extensions": ["./extension.js"],
915
+ "settings": {
916
+ "keywords": {
917
+ "type": "string-list",
918
+ "label": "Keywords to track",
919
+ "description": "Words counted across each node's body.",
920
+ "default": ["TODO", "FIXME"],
921
+ "min": 1
922
+ },
923
+ "caseSensitive": {
924
+ "type": "boolean-flag",
925
+ "label": "Case-sensitive matching",
926
+ "default": false
927
+ }
928
+ }
929
+ }
930
+ ```
931
+
932
+ The 10 input-types:
933
+
934
+ | Type | Value at runtime | Use for |
935
+ |---|---|---|
936
+ | `string-list` | `string[]` | keyword lists, ignore patterns |
937
+ | `single-string` | `string` | URLs, names, identifiers |
938
+ | `boolean-flag` | `boolean` | toggles |
939
+ | `integer` | `number` (always integer) | counts, thresholds |
940
+ | `enum-pick` | `string` | pick one from a closed set |
941
+ | `enum-multipick` | `string[]` | pick zero or more |
942
+ | `path-glob` | `string` or `string[]` | glob patterns |
943
+ | `regex` | `string` | ECMAScript regex (body, no `/` delimiters) |
944
+ | `secret` | `string` | tokens, passwords (encrypted at rest) |
945
+ | `key-value-list` | `Array<{ key, value }>` | custom maps, alias dictionaries |
946
+
947
+ Per-type parameter schema lives in [`schemas/input-types.schema.json`](./schemas/input-types.schema.json) at `$defs/Setting_<TypeName>`.
948
+
949
+ The kernel exposes resolved settings to extractors via `ctx.settings.<settingId>`. Settings are read once at extractor invocation; **changing a setting requires `sm scan` to re-emit** affected contributions. The UI surfaces a "settings changed, rescan needed" indicator.
950
+
951
+ ### Catalog version
952
+
953
+ The catalog of contracts and input-types evolves on its own cadence. Declare a semver range in your manifest:
954
+
955
+ ```jsonc
956
+ { "catalogCompat": "^1.0.0" }
957
+ ```
958
+
959
+ Independent of `specCompat` (the spec version range). Mismatch surfaces as `incompatible-catalog` plugin status; resolution is `sm plugins upgrade <id>`, which runs registered migrations from the kernel's closed migration registry. When auto-migration is impossible (a contract you used was removed entirely), the upgrade verb fails loud (CLI exit ≠ 0 + console message) and your manifest needs a manual edit.
960
+
961
+ `catalogCompat` is **optional**: omit it if your plugin declares no `viewContributions` and no `settings`. The doctor verb (`sm plugins doctor`) warns if such a plugin actually emits via `viewContributions` or declares `settings`.
962
+
963
+ ### Worked example — `acme/keyword-finder`
964
+
965
+ Full plugin walkthrough:
966
+
967
+ ```
968
+ plugins/acme-keyword-finder/
969
+ ├── plugin.json ← manifest with settings + catalogCompat
970
+ └── extensions/
971
+ └── extractor.js ← extract() with ctx.emitContribution
972
+ ```
973
+
974
+ `plugin.json`:
975
+
976
+ ```jsonc
977
+ {
978
+ "id": "acme-keyword-finder",
979
+ "version": "1.0.0",
980
+ "specCompat": "^0.20.0",
981
+ "catalogCompat": "^1.0.0",
982
+ "extensions": ["./extensions/extractor.js"],
983
+ "settings": {
984
+ "keywords": {
985
+ "type": "string-list",
986
+ "label": "Keywords to track",
987
+ "default": ["TODO", "FIXME"],
988
+ "min": 1
989
+ }
990
+ }
991
+ }
992
+ ```
993
+
994
+ `extensions/extractor.js`:
995
+
996
+ ```js
997
+ export const extractor = {
998
+ id: 'keyword-finder',
999
+ pluginId: 'acme-keyword-finder',
1000
+ kind: 'extractor',
1001
+ version: '1.0.0',
1002
+ description: 'Counts configured keywords per node.',
1003
+ stability: 'stable',
1004
+ mode: 'deterministic',
1005
+ emitsLinkKinds: [],
1006
+ defaultConfidence: 'high',
1007
+ scope: 'body',
1008
+
1009
+ viewContributions: {
1010
+ breakdown: {
1011
+ contract: 'node-breakdown',
1012
+ label: 'Keyword hits',
1013
+ emptyText: 'No matches.',
1014
+ },
1015
+ total: {
1016
+ contract: 'node-counter',
1017
+ icon: '🔍',
1018
+ label: 'kw',
1019
+ emitWhenEmpty: false,
1020
+ },
1021
+ },
1022
+
1023
+ extract(ctx) {
1024
+ const keywords = ctx.settings.keywords;
1025
+ const perKeyword = Object.create(null);
1026
+ let total = 0;
1027
+
1028
+ for (const kw of keywords) {
1029
+ const re = new RegExp(`\\b${escapeRegex(kw)}\\b`, 'gi');
1030
+ const n = (ctx.body.match(re) ?? []).length;
1031
+ perKeyword[kw] = n;
1032
+ total += n;
1033
+ }
1034
+
1035
+ ctx.emitContribution('breakdown', {
1036
+ entries: Object.entries(perKeyword).map(([label, value]) => ({ label, value })),
1037
+ });
1038
+
1039
+ if (total > 0) {
1040
+ ctx.emitContribution('total', { value: total });
1041
+ }
1042
+ },
1043
+ };
1044
+
1045
+ function escapeRegex(s) {
1046
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
1047
+ }
1048
+ ```
1049
+
1050
+ After `sm scan`, the UI surfaces:
1051
+
1052
+ - A `🔍 N` chip on every node's card (when `total > 0`).
1053
+ - A "Keyword hits" panel in the inspector body for every node, with a horizontal bar chart per keyword.
1054
+
1055
+ The plugin author wrote zero UI code, zero CSS, zero HTML, zero JSON Schema, and never typed the words "panel", "chip", "renderer", or "slot".
1056
+
1057
+ ### Scaffolder
1058
+
1059
+ Hand-writing the manifest is supported but discouraged. Run:
1060
+
1061
+ ```sh
1062
+ sm plugins create
1063
+ ```
1064
+
1065
+ The scaffolder walks you through the closed catalogs (settings + view contributions) and emits a complete plugin directory with manifest, extension stub, test scaffold, and README. Hand-writing remains valid because the spec is the source of truth, but the scaffolder catches invalid contract picks at author time, while a hand-written manifest only fails at load time.
1066
+
1067
+ Companion verbs:
1068
+
1069
+ - `sm plugins doctor` — surfaces `incompatible-catalog`, `invalid-manifest`, deprecated-contract usage.
1070
+ - `sm plugins upgrade <id>` — applies catalog migrations registered in the kernel.
1071
+ - `sm plugins contracts list` — prints the catalog (contracts + input-types), flags deprecated entries.
1072
+
1073
+ ### Watch out for
1074
+
1075
+ - **Don't pick a slot.** The plugin author never types `inspector.body.panel`, `card.footer.left`, etc. Slot mapping is a UI decision; if you find yourself wanting to "place" a contribution, you're working against the model.
1076
+ - **Don't write JSON Schema.** Settings use `type` from the input-type catalog; view contributions use `contract` from the contract catalog.
1077
+ - **Don't mutate payloads after emission.** The kernel validates and serializes at emit time; a plugin holding a reference to the emitted payload and mutating it later has undefined behavior.
1078
+ - **Don't emit HTML.** `node-markdown` accepts markdown with a sanitized allow-list; `[innerHTML]` bindings in the renderer are lint-banned (see [`context/view-contributions.md`](../context/view-contributions.md)).
1079
+ - **Don't try to read another plugin's contributions.** The BFF rejects cross-plugin reads at the route level.
1080
+
1081
+ ---
1082
+
684
1083
  ## See also
685
1084
 
686
1085
  - [`architecture.md`](./architecture.md) — extension contract, ports, execution modes.
@@ -0,0 +1,75 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://skill-map.dev/spec/v0/annotations.schema.json",
4
+ "title": "Annotations",
5
+ "description": "Catalog of conventional annotation fields skill-map ships out of the box, written into the `annotations:` block of a sidecar (`<basename>.sm`). Every field is OPTIONAL — a sidecar with an empty `annotations: {}` is valid. Schema is `additionalProperties: true` so users / plugins can add custom keys without coordination; the built-in `unknown-field` rule emits a warning on unrecognized keys (typo guard). The curated catalog is the load-bearing 13 fields below — versioning + supersession (`version`, `stability`, `supersedes`, `supersededBy`, `requires`, `conflictsWith`, `related`), provenance (`authors`, `license`, `source`, `sourceVersion`), taxonomy (`tags`), docs (`docsUrl`). The activity timestamp lives in the reserved `audit:` block (`audit.lastBumpedAt`), not in `annotations:`. Plugins that want first-class custom keys with their own validation declare `annotationContributions` in their manifest (see Step 9.6.6).",
6
+ "type": "object",
7
+ "additionalProperties": true,
8
+ "properties": {
9
+ "version": {
10
+ "type": "integer",
11
+ "minimum": 1,
12
+ "description": "Monotonic counter. Bumped via the built-in `bump` Action when the underlying node changes meaningfully. Orthogonal to `stability` — `stability` carries the lifecycle stage; `version` is just a counter. There is no major: a change so big it would justify a major bump uses the convention `create a new node, supersede the old one` instead. Default: missing == unversioned."
13
+ },
14
+ "stability": {
15
+ "type": "string",
16
+ "enum": ["experimental", "stable", "deprecated"],
17
+ "description": "Lifecycle stage. Denormalized into `scan_nodes.stability` for fast queries (see `node.schema.json` #/properties/stability). Default: missing == unspecified."
18
+ },
19
+ "supersedes": {
20
+ "type": "array",
21
+ "items": { "type": "string", "minLength": 1 },
22
+ "description": "Paths (relative to scope root) of nodes this node replaces. Consumed by the built-in `superseded` rule and surfaces in `sm list --superseded`."
23
+ },
24
+ "supersededBy": {
25
+ "type": "string",
26
+ "minLength": 1,
27
+ "description": "Path (relative to scope root) of the node that replaces this one. When set, the current node is end-of-life and consumers should migrate."
28
+ },
29
+ "requires": {
30
+ "type": "array",
31
+ "items": { "type": "string", "minLength": 1 },
32
+ "description": "Paths (relative to scope root) of nodes this node depends on. Surfaces in the dependency graph; the `broken-ref` rule flags missing targets."
33
+ },
34
+ "conflictsWith": {
35
+ "type": "array",
36
+ "items": { "type": "string", "minLength": 1 },
37
+ "description": "Paths (relative to scope root) of nodes that cannot be active alongside this one. Surfaces in conflict detection (post-v0.5.0)."
38
+ },
39
+ "related": {
40
+ "type": "array",
41
+ "items": { "type": "string", "minLength": 1 },
42
+ "description": "Paths (relative to scope root) of conceptually related nodes. Soft link for navigation; no strong semantics, no rule enforcement."
43
+ },
44
+ "authors": {
45
+ "type": "array",
46
+ "items": { "type": "string", "minLength": 1 },
47
+ "description": "Multi-author list. Single-author files use a one-element array."
48
+ },
49
+ "license": {
50
+ "type": "string",
51
+ "minLength": 1,
52
+ "description": "SPDX identifier preferred (e.g. `MIT`, `Apache-2.0`); free-form accepted."
53
+ },
54
+ "source": {
55
+ "type": "string",
56
+ "format": "uri",
57
+ "description": "URL of the canonical upstream (e.g. GitHub raw URL). Consumed by the `github-enrichment` Action for hash verification."
58
+ },
59
+ "sourceVersion": {
60
+ "type": "string",
61
+ "minLength": 1,
62
+ "description": "Tag, branch, or full commit SHA at the upstream. Drives `github-enrichment` SHA pin / tag resolution."
63
+ },
64
+ "tags": {
65
+ "type": "array",
66
+ "items": { "type": "string", "minLength": 1 },
67
+ "description": "**User-supplied** taxonomy tags. Skill-map's tag system is dual-source: this field carries the user's post-hoc tags (curator's view of the node from the `.sm` sidecar); `frontmatter.tags` carries the author's tags (intrinsic categories written in the `.md`). Both surfaces are first-class — `sm list --tag <name>` and UI faceted search match the union and the UI distinguishes them visually (`sm list --tag-source author|user` filters one source). Empty array and missing field are equivalent."
68
+ },
69
+ "docsUrl": {
70
+ "type": "string",
71
+ "format": "uri",
72
+ "description": "Canonical docs URL for this node (separate from `source`, which points at the file's upstream)."
73
+ }
74
+ }
75
+ }