farna-bootstrapper 0.1.0 → 0.1.2

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/CHANGELOG.md CHANGED
@@ -6,6 +6,50 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Before 1.0.0, a minor
7
7
  release may contain a breaking change; every change of that kind is listed under **Changed**.
8
8
 
9
+ ## [0.1.2] - 2026-11-23
10
+
11
+ ### Added
12
+
13
+ - **`doctor`.** Validates a `.farna` source without rendering or writing: the config schema, persona
14
+ and resource references, `extends` cycles, the model map, target support, permission categories
15
+ and patterns, secret references, path and symlink safety, and the profile-mode invariants. It
16
+ reuses the same config loader, source loader and resolver as `generate` and `check`, so it cannot
17
+ accept a source they refuse. A failure carries the same typed code and exit status; `--json`
18
+ emits one object, and the human report lists every check that ran, every resolved persona and
19
+ resource with its source path, and every warning.
20
+ - **`report`.** Prints the measured capability matrix for all three supported targets, with two
21
+ emissions per capability (per persona and workspace level) and a per-key permission table. The
22
+ vocabulary is `native`, `emulated`, `dropped` and `unknown`; `unknown` renders as `[?] not
23
+ measured` and is never a tick. `--json` emits the same claim as data. The command reads no source
24
+ tree and writes nothing.
25
+ - **A structural matrix guard.** `verifySnapshot` refuses (F010) a snapshot measured against a
26
+ different renderer, a missing supported-target row, or an `unknown` cell on a promised target.
27
+
28
+ ### Changed
29
+
30
+ - The README, `CONTRIBUTING.md` and `--help` describe the five-command surface and the capability
31
+ report.
32
+
33
+ ### Fixed
34
+
35
+ - The `CONTRIBUTING.md` release example used `v0.1.0` as its tag; it now uses the current release
36
+ version.
37
+
38
+ ## [0.1.1] - 2026-11-22
39
+
40
+ ### Added
41
+
42
+ - **Persona `mode`.** A persona may declare `mode: primary`, `subagent` or `all`, which both
43
+ OpenCode targets emit as the per-agent `mode`. The default when the key is absent is `subagent`,
44
+ so an existing source renders byte for byte as before. The value composes with `extends`: a
45
+ derived persona inherits its base's mode and may override it.
46
+ - **`W117_PERSONA_MODE_IGNORED`.** Claude Code has no primary/subagent mode, so a persona that
47
+ declares `mode` on the `claudecode` target is reported at info severity, naming the persona and
48
+ the target, and the emitted Claude Code file carries no `mode` key.
49
+
50
+ Both OpenCode examples now declare `mode: primary` on their live persona, and the README documents
51
+ the field, its composition and the Claude Code warning.
52
+
9
53
  ## [0.1.0] - 2026-11-22
10
54
 
11
55
  The first public release. `farna-bootstrapper` compiles named agent personas and their resources
@@ -88,4 +132,6 @@ output still matches the source.
88
132
  runner does not grant), the POSIX mode assertions, the FIFO cases and the install-layout suite are
89
133
  skipped on Windows; CI runs them on Linux.
90
134
 
135
+ [0.1.2]: https://github.com/farnalabs/farna-bootstrapper/releases/tag/v0.1.2
136
+ [0.1.1]: https://github.com/farnalabs/farna-bootstrapper/releases/tag/v0.1.1
91
137
  [0.1.0]: https://github.com/farnalabs/farna-bootstrapper/releases/tag/v0.1.0
package/README.md CHANGED
@@ -16,6 +16,12 @@ and their resources once, under `.farna/`, and it renders the files a harness re
16
16
  - **`check`** renders the same source into a temporary directory and compares it with the
17
17
  repository. Exit `0` when identical, `1` when anything drifted. It never writes.
18
18
  - **`init`** creates the source root and the ignore/attribute lines generated output needs.
19
+ - **`doctor`** validates the source without rendering or writing: schema, references, `extends`
20
+ cycles, the model map, target support, permissions, secret references, paths and profile-mode
21
+ invariants. It exits `0` when the source is valid; when it is not, it reports the loader's own
22
+ typed code and exits non-zero.
23
+ - **`report`** prints the measured capability matrix for every supported target, in a human table
24
+ or as one JSON object. It reads no source and writes nothing.
19
25
 
20
26
  It is a compiler in the useful sense, not a loader:
21
27
 
@@ -44,10 +50,10 @@ It is a compiler in the useful sense, not a loader:
44
50
 
45
51
  ## Status
46
52
 
47
- This is the first public release. It implements three commands (`init`, `generate` and
48
- `check`), three targets (`claudecode`, `opencode` for OpenCode 2.x and `opencodev1` for OpenCode
49
- 1.x), agent mode plus OpenCode profile mode, six resource kinds (`rule`, `permission`, `mcp`,
50
- `skill`, `command` and `hook`) with a model class, and composition with one base persona per
53
+ This is the first public release. It implements five commands (`init`, `doctor`, `report`,
54
+ `generate` and `check`), three targets (`claudecode`, `opencode` for OpenCode 2.x and `opencodev1`
55
+ for OpenCode 1.x), agent mode plus OpenCode profile mode, six resource kinds (`rule`, `permission`,
56
+ `mcp`, `skill`, `command` and `hook`) with a model class, and composition with one base persona per
51
57
  composed persona. Exactly one configured target is rendered per run. Everything else is
52
58
  deliberately deferred; see
53
59
  [What this slice does not do](#what-this-slice-does-not-do) and
@@ -68,8 +74,10 @@ npx farna-bootstrapper init
68
74
  one file per resource; [Use](#use) has a complete pair. Then:
69
75
 
70
76
  ```sh
77
+ npx farna-bootstrapper doctor # validate the source; write nothing
71
78
  npx farna-bootstrapper generate # render the target and write .farna/lock.json
72
79
  npx farna-bootstrapper check # exit 0 when the tree matches a fresh render
80
+ npx farna-bootstrapper report # print the measured capability matrix
73
81
  ```
74
82
 
75
83
  Commit `.farna/` and the generated files. Running `check` in CI is the drift gate: a hand edit, a
@@ -78,6 +86,7 @@ stale render, or a source change that was never regenerated exits `1` and names
78
86
  ## The loop
79
87
 
80
88
  1. You declare personas and their resources under `.farna/`, and select one target in the config.
89
+ `farna-bootstrapper doctor` validates that declaration without rendering it.
81
90
  2. `farna-bootstrapper generate` renders that target's artefacts and records what it wrote in
82
91
  `.farna/lock.json`. Claude Code gets one whole file per persona under `.claude/agents/`; OpenCode
83
92
  in agent mode gets one whole file per persona under `.opencode/agents/` and no workspace file;
@@ -242,6 +251,26 @@ resources:
242
251
  - permission/python-tools
243
252
  ```
244
253
 
254
+ A persona may also declare **`mode`**, which selects its OpenCode agent mode: `primary` makes the
255
+ agent selectable as the main agent, `subagent` makes it callable only by another agent, and `all`
256
+ makes it both. `subagent` is the default when the key is absent. The value is source-derived and
257
+ composes with `extends`: a derived persona inherits its base's `mode`, and a child declaration
258
+ overrides it. Both OpenCode targets emit it; Claude Code has no primary/subagent distinction, so a
259
+ declared `mode` there is reported as `W117_PERSONA_MODE_IGNORED` (info) and no `mode` key is
260
+ written.
261
+
262
+ ```yaml
263
+ # .farna/personas/builder.yaml — a primary agent on an OpenCode target
264
+ kind: persona
265
+ id: builder
266
+ displayName: Builder
267
+ purpose: Writes code, runs the tests, and follows the house conventions.
268
+ mode: primary
269
+ resources:
270
+ - rule/house-style
271
+ - permission/builder-default
272
+ ```
273
+
245
274
  ```markdown
246
275
  ---
247
276
  kind: rule
@@ -281,6 +310,8 @@ Write the smallest change that satisfies the ticket.
281
310
  Then run:
282
311
 
283
312
  ```sh
313
+ farna-bootstrapper doctor # validate the source; render and write nothing
314
+ farna-bootstrapper report # print the measured capability matrix
284
315
  farna-bootstrapper generate # write the agent files and the lockfile
285
316
  farna-bootstrapper generate --dry-run # print the plan, write nothing
286
317
  farna-bootstrapper generate --adopt # take ownership of existing outputs (see below)
@@ -296,6 +327,8 @@ The complete flag surface:
296
327
  | all | `--json` | emit one JSON object on stdout and suppress the human report; a typed failure also writes its one human line to stderr |
297
328
  | all | `-v, --version`, `-h, --help` | print the compiled-in version or usage; neither needs the renderer |
298
329
  | `init` | `--json` | the created/updated paths and the next step |
330
+ | `doctor` | `--json` | every validation that ran, every resolved persona and resource, and the warnings |
331
+ | `report` | `--json` | the measured capability matrix for every supported target |
299
332
  | `generate` | `--dry-run` | print the plan and write nothing; `would-write` and `unchanged` are counted separately |
300
333
  | `generate` | `--adopt` | take ownership of every existing planned managed output; required when the lockfile is missing |
301
334
  | `generate` | `--persona <id>` | run profile mode as that persona; wins over `targets.<target>.active` and is not written back |
@@ -316,6 +349,13 @@ working tree, so `unchanged` and
316
349
  counts the `would-write` files, not the size of the plan: a tree that already matches reports
317
350
  `would write 0 file(s), N unchanged`.
318
351
 
352
+ `doctor` adds `target`, `mode`, `activePersona`, `notLive`, `configPath`, `counts`, `checks`,
353
+ `personas` and `warnings`; each persona carries its `chain`, `mode`, `model` and every resolved
354
+ resource with its `path`, `fromPersona` and `rank`. `report` adds `renderer` and `targets[]`, where
355
+ each target carries `id`, `status`, `agentReach`, `capabilities` (the seven cells, each with
356
+ `agent`, `workspace`, `basis`, `testId` and `consequence`) and `permissionKeys` (each with
357
+ `emission`, `code` and `consequence`).
358
+
319
359
  A persona's rule text is joined into the body of its subagent, in canonical rule-id order, under a
320
360
  `## displayName` heading. The rule body itself is never re-wrapped or re-indented. There is no
321
361
  shared root rules file: the per-agent body is the only rule surface, so one persona's rules never
@@ -357,23 +397,49 @@ writing any of them.
357
397
 
358
398
  ### Capability matrix
359
399
 
360
- What this release actually carries. A cell is either **native** (written into the emitted
361
- artefact), **profile only** (written at the workspace level, so it requires profile mode and exactly
362
- one live persona), **not carried** (refused with `F001`, naming the reference; nothing is written),
363
- or **unknown** (the harness behaviour is not verified by this release, so it is never claimed as a
364
- tick).
400
+ What this release actually carries, as measured by the tests that pin the emitted bytes and the
401
+ refusals. A cell has one of four values, and each has exactly one rendering in the `report` command:
402
+
403
+ | Value | Meaning | Glyph | Never |
404
+ |---|---|---|---|
405
+ | **native** | written into the emitted artefact | `[x]` | a claim that the harness obeys it at runtime |
406
+ | **emulated** | carried under a different category whose effect differs | `[~]` | counted as carried for a boundary capability |
407
+ | **dropped** | the target receives nothing; a declared reference is refused (`F001`) or reported (`W101`) | `[ ]` | silent |
408
+ | **unknown** | not measured in this release | `[?] not measured` | rendered as a tick |
365
409
 
366
- | Capability | Claude Code, per agent | Claude Code, workspace | OpenCode 2.x, per agent | OpenCode 2.x, workspace | OpenCode 1.x, per agent | OpenCode 1.x, workspace |
410
+ `farna-bootstrapper report` prints this matrix for all three supported targets, as a human table or
411
+ as one JSON object with `--json`. It reads no source and writes nothing; the same data is what this
412
+ section documents.
413
+
414
+ | Capability | claudecode, agent | claudecode, workspace | opencode, agent | opencode, workspace | opencodev1, agent | opencodev1, workspace |
367
415
  |---|---|---|---|---|---|---|
368
- | `rule` | native | — | native | — | native | — |
369
- | `model` | native | — | native | — | native | — |
370
- | `permission` | native (allow-list via opt-in) | — | native (deny-list; `write` folds into `edit`, W112) | — | native (per-tool map; `write` folds into `edit`, W112) | — |
371
- | `mcp` | not carried | — | not carried in agent mode | profile only (`mcp.servers`) | not carried in agent mode | profile only (flat `mcp.<name>`) |
372
- | `skill` | not carried | — | not carried in agent mode | profile only | not carried in agent mode | profile only |
373
- | `command` | not carried | — | not carried in agent mode | profile only | not carried in agent mode | profile only |
374
- | `hook` | not carried | — | not carried in agent mode | profile only; `{ id, setup }` plugin, representable events only (W101) | not carried in agent mode | profile only; `RulesyncHooksPlugin`, representable events only (W101) |
375
- | `temperature` | not carried (not authored) | — | not carried (not authored) | — | not carried (not authored) | — |
376
- | `tools` (per-agent) | native (allow-list via opt-in) | — | not carried (an OpenCode allow-list cannot be expressed) | — | not carried (an OpenCode allow-list cannot be expressed) | — |
416
+ | `rule` | native | dropped [^claude-workspace] | native | native | native | native |
417
+ | `model` | native | dropped [^claude-workspace] | native | native | native | native |
418
+ | `permission` | native | dropped [^claude-workspace] | native | native | native | native |
419
+ | `skill` | dropped | dropped [^claude-workspace] | dropped | native | dropped | native |
420
+ | `command` | dropped | dropped [^claude-workspace] | dropped | native | dropped | native |
421
+ | `mcp` | dropped | dropped [^claude-workspace] | dropped | native | dropped | native |
422
+ | `hook` | dropped | dropped [^claude-workspace] | dropped | native | dropped | native |
423
+
424
+ [^claude-workspace]: Profile mode is not supported on `claudecode` in this release, so no
425
+ workspace-level output is written for any capability.
426
+
427
+ The `permission` capability is one cell but a per-key measurement. `report` prints the key table
428
+ too, because the cell alone would hide where a key widens or refuses:
429
+
430
+ | Permission key | claudecode | opencode | opencodev1 |
431
+ |---|---|---|---|
432
+ | `read`, `edit`, `shell`, `task` | native | native | native |
433
+ | `write` | native | emulated (`W112`) | emulated (`W112`) |
434
+ | `network` | dropped (`F011`) | dropped (`F011`) | dropped (`F011`) |
435
+ | `mcp` (bare category) | dropped (`F011`) | not measured, refused (`F011`) | not measured, refused (`F011`) |
436
+
437
+ `write` on OpenCode is emulated, not native: OpenCode has no write category, so the rule lands as
438
+ `edit`, and an `allow` then also permits modifying existing files. `W112_PERMISSION_LOSSY` at high
439
+ severity names the widening, and a declaration is never silently weakened. A bare `network` or
440
+ `mcp` category has no mapping on any target, so it is refused (`F011`) rather than written as an
441
+ inert rule; the bare `mcp` category on OpenCode is recorded as **not measured** and is never claimed
442
+ as carried.
377
443
 
378
444
  The OpenCode V1 columns record these differences from V2, each verified against rulesync 43.11.0
379
445
  output in this repository's golden tests:
@@ -390,23 +456,24 @@ output in this repository's golden tests:
390
456
  - **Hooks plugin** — V1 writes the `RulesyncHooksPlugin` module, which OpenCode 2.x does not run;
391
457
  V2 writes the `{ id, setup }` plugin, which OpenCode 1.x does not run.
392
458
 
393
- Cells that are not verified by a test in this release are **unknown**, never a tick. In particular,
394
- this release verifies the emitted bytes and their containment; it does not verify that a particular
395
- OpenCode build honours `temperature` or per-agent `tools`, and it does not author either field, so
396
- they are not claimed.
397
-
398
459
  Two details matter more than the table:
399
460
 
400
461
  - **OpenCode's workspace kinds are not an agent-mode loss warning.** A workspace emission would give
401
462
  every persona the declaring persona's MCP server, skill, command or hook, with no per-recipient
402
463
  record and no opt-out. That is not a capability the author declared for those personas, so agent
403
- mode refuses the reference and points at profile mode instead of emitting it.
464
+ mode refuses the reference and points at profile mode instead of emitting it. Profile mode carries
465
+ the live persona's kinds; a hook OpenCode cannot represent (`session-end`, or a matcher on a
466
+ non-tool event) is reported as `W101_CAPABILITY_DROPPED` at high severity and is not emitted.
404
467
  - **Claude Code's workspace kinds are absent from this release.** `claudecode` does not carry
405
- `mcp`, `skill`, `command` or `hook` at all yet; a reference is refused rather than silently
468
+ `mcp`, `skill`, `command` or `hook` at any level yet; a reference is refused rather than silently
406
469
  losing it. Profile mode on `claudecode` is later work.
407
470
 
408
- A full 71-target capability matrix, the `agent with loss` and `refuse` plan outcomes, and a
409
- generated capability report page are not in this release. See
471
+ A persona `mode` is documented separately from these seven capabilities: it is native on both
472
+ OpenCode targets and has no Claude Code field (`W117_PERSONA_MODE_IGNORED`). The opt-in Claude Code
473
+ `tools` allow-list has no OpenCode equivalent and is refused there; see [Permissions](#permissions).
474
+
475
+ The full 71-target matrix and the generated `docs/capability-matrix.md` page are not in this
476
+ release. `report` prints the measured matrix for the three supported targets today. See
410
477
  [What this slice does not do](#what-this-slice-does-not-do).
411
478
 
412
479
  ### Output layout
@@ -696,6 +763,7 @@ is part of the code's definition, never set by a flag.
696
763
  | `W114_RENDERER_INTEGRITY_UNVERIFIED` | medium | No npm lock record at the install root supplied the renderer's tarball integrity. The pinned version is still enforced; this is a provenance gap, never a clean pass. |
697
764
  | `W115_CREDENTIAL_IN_URL` | high | An MCP `http` URL carries a credential-shaped query parameter (`token`, `api_key`, `apikey`, `access_token`, `secret`, `password`). The value is never echoed. |
698
765
  | `W116_SECRET_IN_ARGS` | high | An MCP `args` literal looks like a credential (`sk-`, `ghp_`, `glpat-`, `npm_`, `AKIA`, a JWT, or a long token-shaped string). The value is never echoed; put the credential in `env` or `headers` instead. |
766
+ | `W117_PERSONA_MODE_IGNORED` | info | A persona declares `mode`, which Claude Code cannot carry: it has no primary/subagent mode. The persona and target are named and no `mode` key is written; the agent file is otherwise emitted in full. |
699
767
 
700
768
  ### Exit codes
701
769
 
@@ -718,12 +786,13 @@ on stdout and its single human line on stderr.
718
786
 
719
787
  ```text
720
788
  src/
721
- cli/ Commander wiring, the three commands, and the error boundary
789
+ cli/ Commander wiring, the five commands, and the error boundary
722
790
  config/ strict JSONC config schema and loader
723
791
  source/ YAML personas; markdown rules, skills and commands; JSONC permissions,
724
792
  MCP servers and hooks; strict frontmatter and reference-only secrets
725
793
  compose/ mode resolution, extends resolution, resource union, deny-wins merge, digests
726
794
  permissions/ the canonical vocabulary and the Claude Code and OpenCode mappings
795
+ matrix/ the measured capability snapshot and its F010 integrity guard
727
796
  materialise/ persona and workspace resources -> rulesync source tree
728
797
  render/ port.ts (the seam), upstream.ts (the only rulesync import),
729
798
  identity.ts (installed vs pinned renderer), prepare.ts (the pipeline),
@@ -734,7 +803,7 @@ src/
734
803
  verify/ containment and cross-persona isolation gates
735
804
  lock/ lockfile construction and validated reading
736
805
  core/ constants, typed errors, paths, strict UTF-8 reads, canonical JSON
737
- report/ text and JSON output, warning records
806
+ report/ text and JSON output, warning records, the capability report
738
807
  tests/
739
808
  fixtures/demo/ the demo fixture: two personas, two rules, no permissions
740
809
  fixtures/composed/ builder, builder-python (extends builder) and reviewer, with permissions
@@ -901,9 +970,10 @@ where a change belongs and which gates it must pass.
901
970
 
902
971
  Deliberately out of scope:
903
972
 
904
- - `doctor`; `agent with loss` and `refuse` as plan outcomes; profile mode on `claudecode`;
905
- rendering more than one configured target per run; every target other than `claudecode`,
906
- `opencode` and `opencodev1`; the full 71-target capability matrix and the capability report page
973
+ - `agent with loss` and `refuse` as plan outcomes; profile mode on `claudecode`; rendering more
974
+ than one configured target per run; every target other than `claudecode`, `opencode` and
975
+ `opencodev1`; the full 71-target capability matrix and the generated `docs/capability-matrix.md`
976
+ page (the `report` command prints the measured matrix for the three supported targets today)
907
977
  - model resources (a model is the persona's `model` class in this slice)
908
978
  - carrying `mcp`, `skill`, `command` or `hook` on any target in **agent** mode; profile mode is
909
979
  where those workspace capabilities belong, and agent mode still refuses them
@@ -970,9 +1040,10 @@ These are deliberate limits of the current controls, stated rather than implied
970
1040
  - **An empty directory is left after a skill's last file is removed.** Only recorded regular files
971
1041
  are removed; the now-empty `<skill>/` (or `scripts/`) directory is harmless and carries no
972
1042
  declaration.
973
- - **The profile-mode per-agent frontmatter keeps `mode: subagent`.** The persona's own harness file
974
- is unchanged by profile mode; promoting the live persona to OpenCode's primary `mode` is a
975
- separate product decision, not a rendering detail, and is not claimed here.
1043
+ - **The per-agent `mode` is source-derived, not implied by the render mode.** A persona's declared
1044
+ `mode` (default `subagent`) is emitted on both OpenCode targets; profile mode does not promote the
1045
+ live persona implicitly. Claude Code has no primary/subagent mode, so a declaration there is
1046
+ reported (`W117`) and no `mode` key is written.
976
1047
  - **No coverage gate.** There is no coverage provider or threshold in this slice. CI runs lint,
977
1048
  type-check, tests (with a minimum count and real-renderer suite assertions), a dependency audit at
978
1049
  `moderate`, and a published-tarball check.
@@ -0,0 +1,64 @@
1
+ import { type Capability, type PersonaMode, type RenderMode, type SupportedTarget } from '../../core/constants.js';
2
+ import type { Warning } from '../../report/warnings.js';
3
+ /** One resolved resource with the attribution `doctor` prints. */
4
+ export type DoctorResource = {
5
+ kind: Capability;
6
+ id: string;
7
+ path: string;
8
+ fromPersona: string;
9
+ /** 0 for the persona itself, 1 for its immediate base, and so on. */
10
+ rank: number;
11
+ };
12
+ export type DoctorPersona = {
13
+ id: string;
14
+ displayName: string;
15
+ purpose: string;
16
+ /** The composition chain, base first. */
17
+ chain: string[];
18
+ mode: PersonaMode | null;
19
+ model: string | null;
20
+ resources: DoctorResource[];
21
+ };
22
+ /**
23
+ * One validation this run performed. `doctor` fails at the first error, so a
24
+ * check appears here only when it ran and did not fail; a report never claims
25
+ * a check it did not reach.
26
+ */
27
+ export type DoctorCheck = {
28
+ name: string;
29
+ detail: string;
30
+ };
31
+ export type DoctorResult = {
32
+ ok: true;
33
+ target: SupportedTarget;
34
+ mode: RenderMode;
35
+ activePersona: string | null;
36
+ notLive: string[];
37
+ configPath: string;
38
+ counts: {
39
+ /** Personas declared in the source, live or not. */
40
+ personas: number;
41
+ /** Personas this target emits in the selected mode. */
42
+ live: number;
43
+ resourceReferences: number;
44
+ modelClasses: number;
45
+ warnings: number;
46
+ };
47
+ checks: DoctorCheck[];
48
+ personas: DoctorPersona[];
49
+ warnings: Warning[];
50
+ };
51
+ /**
52
+ * Validate a `.farna` source without rendering or writing.
53
+ *
54
+ * The read → resolve half of `prepareRender` is reused wholesale: the config
55
+ * loader, the source loader and the resolver are the same ones `generate` and
56
+ * `check` run, so `doctor` cannot accept a source they refuse. Only the
57
+ * materialise → render → verify half is skipped, because a report that renders
58
+ * bytes would need the renderer and could mask a source error behind a render
59
+ * error.
60
+ *
61
+ * A failure throws the loader's or resolver's own `FarnaError`, so the exit
62
+ * code and the code are the ones `generate` would produce for the same source.
63
+ */
64
+ export declare function runDoctor(repoRoot: string): Promise<DoctorResult>;
@@ -0,0 +1,101 @@
1
+ import { resolveSource } from '../../compose/resolve.js';
2
+ import { loadConfig } from '../../config/load.js';
3
+ import { CONFIG_PATH, ROOT_DIR, } from '../../core/constants.js';
4
+ import { loadSource } from '../../source/load.js';
5
+ function doctorPersona(persona) {
6
+ return {
7
+ id: persona.id,
8
+ displayName: persona.displayName,
9
+ purpose: persona.purpose,
10
+ chain: persona.chain,
11
+ mode: persona.mode ?? null,
12
+ model: persona.model ?? null,
13
+ resources: persona.resources.map((resource) => ({
14
+ kind: resource.kind,
15
+ id: resource.id,
16
+ path: resource.path,
17
+ fromPersona: resource.fromPersona,
18
+ // Depth from the reported persona: its own resources are rank 0, an
19
+ // immediate base's are rank 1, and so on.
20
+ rank: persona.chain.length - 1 - persona.chain.indexOf(resource.fromPersona),
21
+ })),
22
+ };
23
+ }
24
+ /**
25
+ * Validate a `.farna` source without rendering or writing.
26
+ *
27
+ * The read → resolve half of `prepareRender` is reused wholesale: the config
28
+ * loader, the source loader and the resolver are the same ones `generate` and
29
+ * `check` run, so `doctor` cannot accept a source they refuse. Only the
30
+ * materialise → render → verify half is skipped, because a report that renders
31
+ * bytes would need the renderer and could mask a source error behind a render
32
+ * error.
33
+ *
34
+ * A failure throws the loader's or resolver's own `FarnaError`, so the exit
35
+ * code and the code are the ones `generate` would produce for the same source.
36
+ */
37
+ export async function runDoctor(repoRoot) {
38
+ const config = await loadConfig(repoRoot);
39
+ const tree = await loadSource(repoRoot);
40
+ const source = resolveSource(tree, config);
41
+ const modelClasses = Object.keys(config.models ?? {}).length;
42
+ const personas = source.personas.map(doctorPersona);
43
+ const resourceReferences = personas.reduce((total, persona) => total + persona.resources.length, 0);
44
+ const categories = new Set();
45
+ let patterns = 0;
46
+ for (const persona of source.personas) {
47
+ for (const key of Object.keys(persona.permissions.values)) {
48
+ categories.add(key);
49
+ }
50
+ for (const bucket of Object.values(persona.permissions.patterns)) {
51
+ patterns += Object.keys(bucket).length;
52
+ }
53
+ }
54
+ const modeDetail = source.mode === 'profile'
55
+ ? `${source.target}, profile mode, active ${source.active ?? '<none>'}`
56
+ : `${source.target}, agent mode, every persona live`;
57
+ return {
58
+ ok: true,
59
+ target: source.target,
60
+ mode: source.mode,
61
+ activePersona: source.active,
62
+ notLive: source.notLive,
63
+ configPath: CONFIG_PATH,
64
+ counts: {
65
+ personas: tree.personas.length,
66
+ live: source.personas.length,
67
+ resourceReferences,
68
+ modelClasses,
69
+ warnings: source.warnings.length,
70
+ },
71
+ checks: [
72
+ { name: 'config schema', detail: CONFIG_PATH },
73
+ { name: 'source tree and paths', detail: ROOT_DIR },
74
+ {
75
+ name: 'personas and extends chains',
76
+ detail: `${tree.personas.length} persona(s) resolved, no cycle`,
77
+ },
78
+ {
79
+ name: 'resource references',
80
+ detail: `${resourceReferences} reference(s) across ${source.personas.length} live persona(s)`,
81
+ },
82
+ {
83
+ name: 'model map',
84
+ detail: modelClasses === 0
85
+ ? 'no model class declared'
86
+ : `${modelClasses} model class(es) resolve for ${source.target}`,
87
+ },
88
+ { name: 'target and profile mode', detail: modeDetail },
89
+ {
90
+ name: 'permission categories and patterns',
91
+ detail: `${categories.size} categor(ies), ${patterns} pattern(s)`,
92
+ },
93
+ {
94
+ name: 'secret references',
95
+ detail: 'MCP credential fields are fromEnv or header references only',
96
+ },
97
+ ],
98
+ personas,
99
+ warnings: source.warnings,
100
+ };
101
+ }
@@ -0,0 +1,11 @@
1
+ import { type CapabilityReport } from '../../report/capability.js';
2
+ /**
3
+ * Print the measured capability matrix. This command reads no source tree and
4
+ * writes nothing: the matrix is a property of this build and its pinned
5
+ * renderer, so it is useful in an empty directory and in CI.
6
+ *
7
+ * The snapshot is verified against the pinned renderer before it is printed.
8
+ * A promised target with an unmeasured cell fails with F010 rather than
9
+ * rendering an `unknown` as a tick.
10
+ */
11
+ export declare function runReport(): CapabilityReport;
@@ -0,0 +1,16 @@
1
+ import { SNAPSHOT, verifySnapshot } from '../../matrix/snapshot.js';
2
+ import { RENDERER_PIN } from '../../render/upstream.js';
3
+ import { buildCapabilityReport } from '../../report/capability.js';
4
+ /**
5
+ * Print the measured capability matrix. This command reads no source tree and
6
+ * writes nothing: the matrix is a property of this build and its pinned
7
+ * renderer, so it is useful in an empty directory and in CI.
8
+ *
9
+ * The snapshot is verified against the pinned renderer before it is printed.
10
+ * A promised target with an unmeasured cell fails with F010 rather than
11
+ * rendering an `unknown` as a tick.
12
+ */
13
+ export function runReport() {
14
+ verifySnapshot(SNAPSHOT, RENDERER_PIN.version);
15
+ return buildCapabilityReport(SNAPSHOT);
16
+ }
@@ -19,5 +19,5 @@ export declare function unexpectedFailureObject(command: string | null, message:
19
19
  * the message may come from a platform library or from a tool.
20
20
  */
21
21
  export declare function redactRoot(message: string, root: string): string;
22
- /** Commander wiring for the three commands this slice implements. */
22
+ /** Commander wiring for the five commands this slice implements. */
23
23
  export declare function buildProgram(context: CliContext): Command;
@@ -2,10 +2,13 @@ import { Command } from 'commander';
2
2
  import { CONFIG_PATH, DRIFT_CODE, EXIT, OPENCODE_SUPPORTED_MAJOR, OPENCODE_V1_SUPPORTED_MAJOR, PRODUCT_NAME, PRODUCT_VERSION, SCHEMA_VERSION, } from '../core/constants.js';
3
3
  import { FarnaError } from '../core/errors.js';
4
4
  import { RENDERER_PIN } from '../render/upstream.js';
5
- import { formatCheck, formatGenerate, formatInit, formatJson } from '../report/format.js';
5
+ import { formatCapabilityReport } from '../report/capability.js';
6
+ import { formatCheck, formatDoctor, formatGenerate, formatInit, formatJson, } from '../report/format.js';
6
7
  import { runCheck } from './commands/check.js';
8
+ import { runDoctor } from './commands/doctor.js';
7
9
  import { runGenerate } from './commands/generate.js';
8
10
  import { runInit } from './commands/init.js';
11
+ import { runReport } from './commands/report.js';
9
12
  /** The one machine-readable failure object: the same keys for every command. */
10
13
  export function failureObject(command, error) {
11
14
  return {
@@ -67,13 +70,16 @@ async function emit(command, json, context, run) {
67
70
  process.exitCode = error.exitCode;
68
71
  }
69
72
  }
70
- /** Commander wiring for the three commands this slice implements. */
73
+ /** Commander wiring for the five commands this slice implements. */
71
74
  export function buildProgram(context) {
72
75
  const program = new Command();
73
76
  program
74
77
  .name(PRODUCT_NAME)
75
- .description('Compile named agent personas and resources into harness configuration, and prove the output still matches the source.')
76
- .addHelpText('after', `\nTwo OpenCode targets are supported, one per run: "opencode" for OpenCode ${OPENCODE_SUPPORTED_MAJOR}.x
78
+ .description('Compile named agent personas and resources into harness configuration, prove the output still matches the source, and report what each target carries.')
79
+ .addHelpText('after', `\nFive commands: init, doctor, report, generate and check. doctor validates a source without
80
+ rendering or writing; report prints the measured capability matrix for every supported target.
81
+
82
+ Two OpenCode targets are supported, one per run: "opencode" for OpenCode ${OPENCODE_SUPPORTED_MAJOR}.x
77
83
  (@opencode/cli) and "opencodev1" for OpenCode ${OPENCODE_V1_SUPPORTED_MAJOR}.x (opencode-ai). They write the same
78
84
  paths in each major's own shapes; configuring both at once is refused.
79
85
  \nProfile mode: pass --persona <id> to generate or check, or set "active" under a target
@@ -110,6 +116,41 @@ remains the default.`)
110
116
  };
111
117
  });
112
118
  });
119
+ program
120
+ .command('doctor')
121
+ .exitOverride()
122
+ .description('validate the source without rendering or writing anything')
123
+ .option('--json', 'print one JSON object')
124
+ .action(async (options) => {
125
+ await emit('doctor', options.json === true, context, async () => {
126
+ const result = await runDoctor(context.cwd);
127
+ return {
128
+ payload: {
129
+ schemaVersion: SCHEMA_VERSION,
130
+ command: 'doctor',
131
+ ...result,
132
+ exitCode: EXIT.ok,
133
+ },
134
+ text: formatDoctor(result),
135
+ exitCode: EXIT.ok,
136
+ };
137
+ });
138
+ });
139
+ program
140
+ .command('report')
141
+ .exitOverride()
142
+ .description('print the measured capability matrix for every supported target')
143
+ .option('--json', 'print one JSON object')
144
+ .action(async (options) => {
145
+ await emit('report', options.json === true, context, async () => {
146
+ const result = runReport();
147
+ return {
148
+ payload: result,
149
+ text: formatCapabilityReport(result),
150
+ exitCode: EXIT.ok,
151
+ };
152
+ });
153
+ });
113
154
  program
114
155
  .command('generate')
115
156
  .exitOverride()
@@ -1,5 +1,5 @@
1
1
  import type { Config } from '../config/schema.js';
2
- import { type RenderMode, type SupportedTarget } from '../core/constants.js';
2
+ import { type PersonaMode, type RenderMode, type SupportedTarget } from '../core/constants.js';
3
3
  import { type OpencodePermissionCategory, type OpencodePermissionRecord, type ResolvedPermissions } from '../permissions/permissions.js';
4
4
  import { type Warning } from '../report/warnings.js';
5
5
  import type { HookResource, McpResource, SkillFile, SourceTree } from '../source/load.js';
@@ -75,6 +75,13 @@ export type ResolvedPersona = {
75
75
  extends?: string;
76
76
  /** The full composition chain, base first, this persona last. */
77
77
  chain: string[];
78
+ /**
79
+ * The effective OpenCode agent mode this persona declares, with a composed
80
+ * base's value overridden by its children. Absent means no persona in the
81
+ * chain declared one, so the target emits its default (`subagent`). The
82
+ * field is not emitted on Claude Code, which has no such concept.
83
+ */
84
+ mode?: PersonaMode;
78
85
  rules: ResolvedRule[];
79
86
  mcp: ResolvedMcp[];
80
87
  skills: ResolvedSkill[];