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 +46 -0
- package/README.md +107 -36
- package/dist/cli/commands/doctor.d.ts +64 -0
- package/dist/cli/commands/doctor.js +101 -0
- package/dist/cli/commands/report.d.ts +11 -0
- package/dist/cli/commands/report.js +16 -0
- package/dist/cli/program.d.ts +1 -1
- package/dist/cli/program.js +45 -4
- package/dist/compose/resolve.d.ts +8 -1
- package/dist/compose/resolve.js +31 -0
- package/dist/core/constants.d.ts +13 -2
- package/dist/core/constants.js +16 -1
- package/dist/lock/lockfile.d.ts +1 -0
- package/dist/materialise/source-tree.d.ts +2 -2
- package/dist/materialise/source-tree.js +5 -2
- package/dist/matrix/snapshot.d.ts +87 -0
- package/dist/matrix/snapshot.js +232 -0
- package/dist/report/capability.d.ts +32 -0
- package/dist/report/capability.js +136 -0
- package/dist/report/format.d.ts +7 -0
- package/dist/report/format.js +42 -0
- package/dist/source/schema.d.ts +5 -0
- package/dist/source/schema.js +10 -1
- package/dist/verify/containment.js +3 -3
- package/package.json +1 -1
package/dist/compose/resolve.js
CHANGED
|
@@ -106,6 +106,22 @@ function resolveModel(chain, config, target) {
|
|
|
106
106
|
}
|
|
107
107
|
return distinct[0];
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The mode a composed persona declares. A mode is inherited from the base and
|
|
111
|
+
* overridden by the most derived persona that declares one; a chain with no
|
|
112
|
+
* declaration returns `undefined`, which is the target's default. Unlike the
|
|
113
|
+
* model there is no conflict: the child is the more specific declaration, so
|
|
114
|
+
* overriding is the intended composition.
|
|
115
|
+
*/
|
|
116
|
+
function resolveMode(chain) {
|
|
117
|
+
for (let index = chain.length - 1; index >= 0; index -= 1) {
|
|
118
|
+
const declared = chain[index]?.mode;
|
|
119
|
+
if (declared !== undefined) {
|
|
120
|
+
return declared;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
109
125
|
function assertSupportedRef(persona, ref, target, mode) {
|
|
110
126
|
const { kind } = splitRef(ref);
|
|
111
127
|
if (kind === 'model') {
|
|
@@ -178,10 +194,24 @@ function hookProblem(hook) {
|
|
|
178
194
|
}
|
|
179
195
|
function resolveOne(persona, chain, byKind, config, target, mode) {
|
|
180
196
|
const model = resolveModel(chain, config, target);
|
|
197
|
+
const personaMode = resolveMode(chain);
|
|
181
198
|
const resources = new Map();
|
|
182
199
|
const permissions = emptyResolvedPermissions();
|
|
183
200
|
const warnings = [];
|
|
184
201
|
const seenRefs = new Set();
|
|
202
|
+
// Claude Code models one agent per file and has no primary/subagent axis, so
|
|
203
|
+
// a declared mode has no representation there. The declaration is still
|
|
204
|
+
// valid; dropping it silently would hide that the source asked for something
|
|
205
|
+
// the target cannot do. The warning names both the persona and the target,
|
|
206
|
+
// and the emitted file carries no `mode` key at all.
|
|
207
|
+
if (target === 'claudecode' && personaMode !== undefined) {
|
|
208
|
+
warnings.push(warning({
|
|
209
|
+
code: 'W117_PERSONA_MODE_IGNORED',
|
|
210
|
+
persona: persona.id,
|
|
211
|
+
target,
|
|
212
|
+
message: `persona "${persona.id}" declares mode "${personaMode}", which claudecode cannot carry: Claude Code has no primary/subagent mode, so no mode key is written`,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
185
215
|
const missing = (kind, id, contributor) => {
|
|
186
216
|
const dirs = {
|
|
187
217
|
rule: 'rules',
|
|
@@ -351,6 +381,7 @@ function resolveOne(persona, chain, byKind, config, target, mode) {
|
|
|
351
381
|
purpose: persona.purpose,
|
|
352
382
|
...(persona.extends === undefined ? {} : { extends: persona.extends }),
|
|
353
383
|
chain: chain.map((entry) => entry.id),
|
|
384
|
+
...(personaMode === undefined ? {} : { mode: personaMode }),
|
|
354
385
|
rules: resolvedRules,
|
|
355
386
|
mcp: resolvedMcp,
|
|
356
387
|
skills: resolvedSkills,
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* spelling of each name.
|
|
6
6
|
*/
|
|
7
7
|
export declare const PRODUCT_NAME = "farna-bootstrapper";
|
|
8
|
-
export declare const PRODUCT_VERSION = "0.1.
|
|
8
|
+
export declare const PRODUCT_VERSION = "0.1.2";
|
|
9
9
|
/** The one source/schema version this build understands. */
|
|
10
10
|
export declare const SCHEMA_VERSION: 1;
|
|
11
11
|
/**
|
|
@@ -30,6 +30,17 @@ export declare const RENDER_MODES: readonly ["agent", "profile"];
|
|
|
30
30
|
export type RenderMode = (typeof RENDER_MODES)[number];
|
|
31
31
|
export declare const MODE_AGENT: RenderMode;
|
|
32
32
|
export declare const MODE_PROFILE: RenderMode;
|
|
33
|
+
/**
|
|
34
|
+
* The OpenCode per-agent `mode` values a persona may declare. `primary` makes
|
|
35
|
+
* the agent selectable as the main agent, `subagent` makes it callable only by
|
|
36
|
+
* another agent, and `all` makes it both. The value is OpenCode-facing: Claude
|
|
37
|
+
* Code has no such concept, so a declared mode there is reported (W117) and not
|
|
38
|
+
* emitted. `subagent` is the default when a persona declares no mode, which is
|
|
39
|
+
* the same default this tool emitted before the field existed.
|
|
40
|
+
*/
|
|
41
|
+
export declare const PERSONA_MODES: readonly ["primary", "subagent", "all"];
|
|
42
|
+
export type PersonaMode = (typeof PERSONA_MODES)[number];
|
|
43
|
+
export declare const DEFAULT_PERSONA_MODE: PersonaMode;
|
|
33
44
|
/** The source root, relative to the repository root. */
|
|
34
45
|
export declare const ROOT_DIR = ".farna";
|
|
35
46
|
export declare const CONFIG_FILE = "config.jsonc";
|
|
@@ -245,7 +256,7 @@ export type DiagnosticCode = ErrorCode | typeof DRIFT_CODE;
|
|
|
245
256
|
/** Exit code per diagnostic code. The table lives here once. F007 is absent: drift is a result. */
|
|
246
257
|
export declare const EXIT_BY_CODE: Record<ErrorCode, ExitCode>;
|
|
247
258
|
export type Severity = 'error' | 'high' | 'medium' | 'low' | 'info';
|
|
248
|
-
export declare const WARNING_CODES: readonly ["W101_CAPABILITY_DROPPED", "W106_DENY_WINS", "W107_OUTSIDE_OWNERSHIP", "W109_PROFILE_BY_CHOICE", "W111_ASK_DOWNGRADED", "W112_PERMISSION_LOSSY", "W113_ALLOW_LIST_NARROWS", "W114_RENDERER_INTEGRITY_UNVERIFIED", "W115_CREDENTIAL_IN_URL", "W116_SECRET_IN_ARGS"];
|
|
259
|
+
export declare const WARNING_CODES: readonly ["W101_CAPABILITY_DROPPED", "W106_DENY_WINS", "W107_OUTSIDE_OWNERSHIP", "W109_PROFILE_BY_CHOICE", "W111_ASK_DOWNGRADED", "W112_PERMISSION_LOSSY", "W113_ALLOW_LIST_NARROWS", "W114_RENDERER_INTEGRITY_UNVERIFIED", "W115_CREDENTIAL_IN_URL", "W116_SECRET_IN_ARGS", "W117_PERSONA_MODE_IGNORED"];
|
|
249
260
|
export type WarningCode = (typeof WARNING_CODES)[number];
|
|
250
261
|
/**
|
|
251
262
|
* A warning's default severity is a property of its code.
|
package/dist/core/constants.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* spelling of each name.
|
|
6
6
|
*/
|
|
7
7
|
export const PRODUCT_NAME = 'farna-bootstrapper';
|
|
8
|
-
export const PRODUCT_VERSION = '0.1.
|
|
8
|
+
export const PRODUCT_VERSION = '0.1.2';
|
|
9
9
|
/** The one source/schema version this build understands. */
|
|
10
10
|
export const SCHEMA_VERSION = 1;
|
|
11
11
|
/**
|
|
@@ -29,6 +29,16 @@ export const OPENCODE_V1_SUPPORTED_MAJOR = '1';
|
|
|
29
29
|
export const RENDER_MODES = ['agent', 'profile'];
|
|
30
30
|
export const MODE_AGENT = 'agent';
|
|
31
31
|
export const MODE_PROFILE = 'profile';
|
|
32
|
+
/**
|
|
33
|
+
* The OpenCode per-agent `mode` values a persona may declare. `primary` makes
|
|
34
|
+
* the agent selectable as the main agent, `subagent` makes it callable only by
|
|
35
|
+
* another agent, and `all` makes it both. The value is OpenCode-facing: Claude
|
|
36
|
+
* Code has no such concept, so a declared mode there is reported (W117) and not
|
|
37
|
+
* emitted. `subagent` is the default when a persona declares no mode, which is
|
|
38
|
+
* the same default this tool emitted before the field existed.
|
|
39
|
+
*/
|
|
40
|
+
export const PERSONA_MODES = ['primary', 'subagent', 'all'];
|
|
41
|
+
export const DEFAULT_PERSONA_MODE = 'subagent';
|
|
32
42
|
/** The source root, relative to the repository root. */
|
|
33
43
|
export const ROOT_DIR = '.farna';
|
|
34
44
|
export const CONFIG_FILE = 'config.jsonc';
|
|
@@ -303,6 +313,7 @@ export const WARNING_CODES = [
|
|
|
303
313
|
'W114_RENDERER_INTEGRITY_UNVERIFIED',
|
|
304
314
|
'W115_CREDENTIAL_IN_URL',
|
|
305
315
|
'W116_SECRET_IN_ARGS',
|
|
316
|
+
'W117_PERSONA_MODE_IGNORED',
|
|
306
317
|
];
|
|
307
318
|
/**
|
|
308
319
|
* A warning's default severity is a property of its code.
|
|
@@ -333,4 +344,8 @@ export const WARNING_SEVERITY = {
|
|
|
333
344
|
W114_RENDERER_INTEGRITY_UNVERIFIED: 'medium',
|
|
334
345
|
W115_CREDENTIAL_IN_URL: 'high',
|
|
335
346
|
W116_SECRET_IN_ARGS: 'high',
|
|
347
|
+
// W117 is info: the declaration is not carried, but nothing the target
|
|
348
|
+
// supports is lost. Claude Code has no primary/subagent mode, and the agent
|
|
349
|
+
// file is still emitted with every capability it can carry.
|
|
350
|
+
W117_PERSONA_MODE_IGNORED: 'info',
|
|
336
351
|
};
|
package/dist/lock/lockfile.d.ts
CHANGED
|
@@ -163,6 +163,7 @@ export declare const lockfileDocumentSchema: z.ZodObject<{
|
|
|
163
163
|
W114_RENDERER_INTEGRITY_UNVERIFIED: "W114_RENDERER_INTEGRITY_UNVERIFIED";
|
|
164
164
|
W115_CREDENTIAL_IN_URL: "W115_CREDENTIAL_IN_URL";
|
|
165
165
|
W116_SECRET_IN_ARGS: "W116_SECRET_IN_ARGS";
|
|
166
|
+
W117_PERSONA_MODE_IGNORED: "W117_PERSONA_MODE_IGNORED";
|
|
166
167
|
}>;
|
|
167
168
|
severity: z.ZodEnum<{
|
|
168
169
|
error: "error";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ResolvedPersona, ResolvedSource } from '../compose/resolve.js';
|
|
2
|
-
import { type OpencodeTarget, type SupportedTarget } from '../core/constants.js';
|
|
2
|
+
import { type OpencodeTarget, type PersonaMode, type SupportedTarget } from '../core/constants.js';
|
|
3
3
|
import type { RenderFeature } from '../render/port.js';
|
|
4
4
|
/**
|
|
5
5
|
* Join rule bodies into the persona body, in canonical order. The rule body
|
|
@@ -28,7 +28,7 @@ export type ClaudeBlock = {
|
|
|
28
28
|
disallowedTools?: string[];
|
|
29
29
|
};
|
|
30
30
|
export type OpencodePersonaSection = {
|
|
31
|
-
mode:
|
|
31
|
+
mode: PersonaMode;
|
|
32
32
|
model?: string;
|
|
33
33
|
permission?: Record<string, Record<string, 'allow' | 'deny'>>;
|
|
34
34
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { stringify } from 'yaml';
|
|
4
|
-
import { COMMANDS_DIR, isOpencodeTarget, OPENCODE_V1_TARGET, RULESYNC_HOOKS_FILE, RULESYNC_MCP_FILE, SKILL_FILE_NAME, SKILLS_DIR, } from '../core/constants.js';
|
|
4
|
+
import { COMMANDS_DIR, DEFAULT_PERSONA_MODE, isOpencodeTarget, OPENCODE_V1_TARGET, RULESYNC_HOOKS_FILE, RULESYNC_MCP_FILE, SKILL_FILE_NAME, SKILLS_DIR, } from '../core/constants.js';
|
|
5
5
|
/**
|
|
6
6
|
* Join rule bodies into the persona body, in canonical order. The rule body
|
|
7
7
|
* itself is never re-wrapped or re-indented. This is the only place a persona's
|
|
@@ -85,7 +85,10 @@ export function personaSourceFile(persona) {
|
|
|
85
85
|
* other.
|
|
86
86
|
*/
|
|
87
87
|
export function opencodePersonaFrontmatter(persona, target) {
|
|
88
|
-
|
|
88
|
+
// The persona's own OpenCode mode, or the measured default. This is the one
|
|
89
|
+
// place the value is chosen, so the emitted file and the containment gate
|
|
90
|
+
// cannot drift.
|
|
91
|
+
const section = { mode: persona.mode ?? DEFAULT_PERSONA_MODE };
|
|
89
92
|
if (persona.model !== undefined) {
|
|
90
93
|
section.model = persona.model;
|
|
91
94
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type Capability, type SupportedTarget } from '../core/constants.js';
|
|
2
|
+
import { type PermissionCategory } from '../permissions/permissions.js';
|
|
3
|
+
/**
|
|
4
|
+
* The measured capability matrix.
|
|
5
|
+
*
|
|
6
|
+
* A cell answers two questions with one value, so it carries two emissions:
|
|
7
|
+
*
|
|
8
|
+
* - `agent`: can the capability land in the artefact for one persona, visible
|
|
9
|
+
* only to that persona?
|
|
10
|
+
* - `workspace`: can it land at the workspace level, visible to every persona?
|
|
11
|
+
*
|
|
12
|
+
* The value vocabulary is closed. `unknown` is not a soft `native`: it means
|
|
13
|
+
* the behaviour was never measured, so it is never presented as a tick.
|
|
14
|
+
*
|
|
15
|
+
* The data here is the committed measured record for this release. It is not
|
|
16
|
+
* generated by a probe in this slice, so every measured cell is backed by a
|
|
17
|
+
* golden test that pins the emitted bytes; `basis` says which kind of evidence
|
|
18
|
+
* it is. A cell is edited only in the same change that moves the test observing
|
|
19
|
+
* it.
|
|
20
|
+
*/
|
|
21
|
+
export type Emission = 'native' | 'emulated' | 'dropped' | 'unknown';
|
|
22
|
+
export type TargetStatus = 'promised' | 'unverified';
|
|
23
|
+
export type CellBasis = 'probe' | 'emitted' | 'upstream-doc' | 'none';
|
|
24
|
+
export type CapabilityCell = {
|
|
25
|
+
agent: Emission;
|
|
26
|
+
workspace: Emission;
|
|
27
|
+
basis: CellBasis;
|
|
28
|
+
/**
|
|
29
|
+
* The test that observes the cell's claim, repository-relative: the golden
|
|
30
|
+
* test that pins the emitted bytes, or the planner test that proves a
|
|
31
|
+
* refusal. `null` when no single test observes the claim.
|
|
32
|
+
*/
|
|
33
|
+
testId: string | null;
|
|
34
|
+
/** What the emission means for the author; required for a non-native value. */
|
|
35
|
+
consequence: string | null;
|
|
36
|
+
};
|
|
37
|
+
/** One product permission key as the target carries it, per persona. */
|
|
38
|
+
export type PermissionKeyCell = {
|
|
39
|
+
emission: Emission;
|
|
40
|
+
/** The diagnostic a declaration raises, or `null` when it is carried plainly. */
|
|
41
|
+
code: string | null;
|
|
42
|
+
consequence: string | null;
|
|
43
|
+
};
|
|
44
|
+
export type TargetMatrix = {
|
|
45
|
+
id: SupportedTarget;
|
|
46
|
+
status: TargetStatus;
|
|
47
|
+
/** Whether a persona is the primary session or a callable subagent. */
|
|
48
|
+
agentReach: 'primary' | 'subagent';
|
|
49
|
+
cells: Record<Capability, CapabilityCell>;
|
|
50
|
+
permissionKeys: Record<PermissionCategory, PermissionKeyCell>;
|
|
51
|
+
};
|
|
52
|
+
export type CapabilitySnapshot = {
|
|
53
|
+
schemaVersion: 1;
|
|
54
|
+
renderer: {
|
|
55
|
+
name: string;
|
|
56
|
+
version: string;
|
|
57
|
+
};
|
|
58
|
+
targets: TargetMatrix[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The reported order. It follows the source model: what a persona reads
|
|
62
|
+
* (rule), what it runs as (model), what it may do (permission), then the
|
|
63
|
+
* workspace-level kinds that are carried only by profile mode.
|
|
64
|
+
*/
|
|
65
|
+
export declare const MATRIX_CAPABILITIES: readonly Capability[];
|
|
66
|
+
/**
|
|
67
|
+
* The measured record. `renderer.version` must equal the pinned renderer; a
|
|
68
|
+
* test asserts it, so a renderer bump cannot leave a stale matrix silently
|
|
69
|
+
* published.
|
|
70
|
+
*/
|
|
71
|
+
export declare const SNAPSHOT: CapabilitySnapshot;
|
|
72
|
+
/**
|
|
73
|
+
* Refuse a snapshot that cannot be published. This is the structural guard
|
|
74
|
+
* behind "an unknown cell is never a tick": a promised target must have a
|
|
75
|
+
* measured emission on both axes for every capability. `unknown` remains valid
|
|
76
|
+
* on an unverified target, where the whole row is labelled unverified.
|
|
77
|
+
*
|
|
78
|
+
* F010 is the design's code for a matrix that does not match the build: it
|
|
79
|
+
* fails the report rather than rendering a claim nobody measured.
|
|
80
|
+
*/
|
|
81
|
+
export declare function verifySnapshot(snapshot: CapabilitySnapshot, rendererVersion?: string): void;
|
|
82
|
+
/** The one glyph each emission renders as. No value renders blank. */
|
|
83
|
+
export declare function emissionGlyph(emission: Emission): string;
|
|
84
|
+
/** The word each emission renders as. `unknown` is always "not measured". */
|
|
85
|
+
export declare function emissionWord(emission: Emission): string;
|
|
86
|
+
/** Every permission category, in the product's declared order. */
|
|
87
|
+
export declare function permissionCategories(): readonly PermissionCategory[];
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { DEFAULT_TARGET, OPENCODE_TARGET, OPENCODE_V1_TARGET, SUPPORTED_TARGETS, } from '../core/constants.js';
|
|
2
|
+
import { FarnaError } from '../core/errors.js';
|
|
3
|
+
import { PERMISSION_CATEGORIES } from '../permissions/permissions.js';
|
|
4
|
+
/**
|
|
5
|
+
* The reported order. It follows the source model: what a persona reads
|
|
6
|
+
* (rule), what it runs as (model), what it may do (permission), then the
|
|
7
|
+
* workspace-level kinds that are carried only by profile mode.
|
|
8
|
+
*/
|
|
9
|
+
export const MATRIX_CAPABILITIES = [
|
|
10
|
+
'rule',
|
|
11
|
+
'model',
|
|
12
|
+
'permission',
|
|
13
|
+
'skill',
|
|
14
|
+
'command',
|
|
15
|
+
'mcp',
|
|
16
|
+
'hook',
|
|
17
|
+
];
|
|
18
|
+
const CLAUDE_TEST = 'tests/golden/builder-python.test.ts';
|
|
19
|
+
const OPENCODE_TEST = 'tests/golden/opencode.test.ts';
|
|
20
|
+
const OPENCODE_V1_TEST = 'tests/golden/opencode-v1.test.ts';
|
|
21
|
+
function cell(agent, workspace, options = {}) {
|
|
22
|
+
return {
|
|
23
|
+
agent,
|
|
24
|
+
workspace,
|
|
25
|
+
basis: options.basis ?? 'emitted',
|
|
26
|
+
testId: options.testId ?? null,
|
|
27
|
+
consequence: options.consequence ?? null,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** A cell that is refused in every mode: the evidence is a planner test. */
|
|
31
|
+
function refused(consequence, testId) {
|
|
32
|
+
return cell('dropped', 'dropped', { basis: 'probe', testId, consequence });
|
|
33
|
+
}
|
|
34
|
+
function claudeWorkspaceDropped(capability) {
|
|
35
|
+
return `profile mode is not supported on claudecode in this release, so no workspace-level ${capability} is written`;
|
|
36
|
+
}
|
|
37
|
+
function claudeNotCarried(kind) {
|
|
38
|
+
return `claudecode does not carry ${kind} in this release; a persona that references one is refused with F001`;
|
|
39
|
+
}
|
|
40
|
+
function opencodeWorkspaceOnly(kind, target) {
|
|
41
|
+
switch (kind) {
|
|
42
|
+
case 'skill':
|
|
43
|
+
return `skills are workspace level only on ${target}, so an agent mode persona loses this skill; profile mode carries it`;
|
|
44
|
+
case 'command':
|
|
45
|
+
return `commands are workspace level only on ${target}, so an agent mode persona loses its command set; profile mode carries it`;
|
|
46
|
+
case 'mcp':
|
|
47
|
+
return `${target} configures MCP servers at the workspace level, not per agent, so an agent mode persona loses its server; profile mode carries it`;
|
|
48
|
+
default:
|
|
49
|
+
return `${target} carries hooks at the workspace level only, as a generated plugin, so an agent mode persona loses its hook (W101, high); profile mode carries representable events only`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const CLAUDE_PERMISSION_KEYS = {
|
|
53
|
+
read: { emission: 'native', code: null, consequence: null },
|
|
54
|
+
write: { emission: 'native', code: null, consequence: null },
|
|
55
|
+
edit: { emission: 'native', code: null, consequence: null },
|
|
56
|
+
shell: { emission: 'native', code: null, consequence: null },
|
|
57
|
+
task: { emission: 'native', code: null, consequence: null },
|
|
58
|
+
network: {
|
|
59
|
+
emission: 'dropped',
|
|
60
|
+
code: 'F011_PERMISSION_UNMAPPED',
|
|
61
|
+
consequence: 'Claude Code has no tool for a bare network category; a declaration is refused with F011',
|
|
62
|
+
},
|
|
63
|
+
mcp: {
|
|
64
|
+
emission: 'dropped',
|
|
65
|
+
code: 'F011_PERMISSION_UNMAPPED',
|
|
66
|
+
consequence: 'a bare mcp category names no tool; a declaration is refused with F011',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
function opencodePermissionKeys(target) {
|
|
70
|
+
return {
|
|
71
|
+
read: { emission: 'native', code: null, consequence: null },
|
|
72
|
+
write: {
|
|
73
|
+
emission: 'emulated',
|
|
74
|
+
code: 'W112_PERMISSION_LOSSY',
|
|
75
|
+
consequence: `${target} has no write category, so write is emitted as edit; an allow also permits modifying existing files`,
|
|
76
|
+
},
|
|
77
|
+
edit: { emission: 'native', code: null, consequence: null },
|
|
78
|
+
shell: { emission: 'native', code: null, consequence: null },
|
|
79
|
+
task: { emission: 'native', code: null, consequence: null },
|
|
80
|
+
network: {
|
|
81
|
+
emission: 'dropped',
|
|
82
|
+
code: 'F011_PERMISSION_UNMAPPED',
|
|
83
|
+
consequence: `${target} has no mapping for a bare network category; a declaration is refused with F011`,
|
|
84
|
+
},
|
|
85
|
+
mcp: {
|
|
86
|
+
emission: 'unknown',
|
|
87
|
+
code: 'F011_PERMISSION_UNMAPPED',
|
|
88
|
+
consequence: `${target}'s bare mcp permission category is not measured in this release; a declaration is refused with F011`,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function claudeCells() {
|
|
93
|
+
return {
|
|
94
|
+
rule: cell('native', 'dropped', {
|
|
95
|
+
testId: CLAUDE_TEST,
|
|
96
|
+
consequence: claudeWorkspaceDropped('rule'),
|
|
97
|
+
}),
|
|
98
|
+
model: cell('native', 'dropped', {
|
|
99
|
+
testId: CLAUDE_TEST,
|
|
100
|
+
consequence: claudeWorkspaceDropped('model'),
|
|
101
|
+
}),
|
|
102
|
+
permission: cell('native', 'dropped', {
|
|
103
|
+
testId: CLAUDE_TEST,
|
|
104
|
+
consequence: claudeWorkspaceDropped('permission'),
|
|
105
|
+
}),
|
|
106
|
+
skill: refused(claudeNotCarried('skills'), 'tests/unit/loader.test.ts'),
|
|
107
|
+
command: refused(claudeNotCarried('commands'), 'tests/unit/loader.test.ts'),
|
|
108
|
+
mcp: refused(claudeNotCarried('MCP servers'), 'tests/unit/loader.test.ts'),
|
|
109
|
+
hook: refused(claudeNotCarried('hooks'), 'tests/unit/loader.test.ts'),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function opencodeCells(target, testId, workspaceTestId) {
|
|
113
|
+
return {
|
|
114
|
+
rule: cell('native', 'native', { testId }),
|
|
115
|
+
model: cell('native', 'native', { testId }),
|
|
116
|
+
permission: cell('native', 'native', { testId }),
|
|
117
|
+
skill: cell('dropped', 'native', {
|
|
118
|
+
testId: workspaceTestId,
|
|
119
|
+
consequence: opencodeWorkspaceOnly('skill', target),
|
|
120
|
+
}),
|
|
121
|
+
command: cell('dropped', 'native', {
|
|
122
|
+
testId: workspaceTestId,
|
|
123
|
+
consequence: opencodeWorkspaceOnly('command', target),
|
|
124
|
+
}),
|
|
125
|
+
mcp: cell('dropped', 'native', {
|
|
126
|
+
testId: workspaceTestId,
|
|
127
|
+
consequence: opencodeWorkspaceOnly('mcp', target),
|
|
128
|
+
}),
|
|
129
|
+
hook: cell('dropped', 'native', {
|
|
130
|
+
testId: workspaceTestId,
|
|
131
|
+
consequence: opencodeWorkspaceOnly('hook', target),
|
|
132
|
+
}),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The measured record. `renderer.version` must equal the pinned renderer; a
|
|
137
|
+
* test asserts it, so a renderer bump cannot leave a stale matrix silently
|
|
138
|
+
* published.
|
|
139
|
+
*/
|
|
140
|
+
export const SNAPSHOT = {
|
|
141
|
+
schemaVersion: 1,
|
|
142
|
+
renderer: { name: 'rulesync', version: '43.11.0' },
|
|
143
|
+
targets: [
|
|
144
|
+
{
|
|
145
|
+
id: DEFAULT_TARGET,
|
|
146
|
+
status: 'promised',
|
|
147
|
+
agentReach: 'subagent',
|
|
148
|
+
cells: claudeCells(),
|
|
149
|
+
permissionKeys: CLAUDE_PERMISSION_KEYS,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
id: OPENCODE_TARGET,
|
|
153
|
+
status: 'promised',
|
|
154
|
+
agentReach: 'primary',
|
|
155
|
+
cells: opencodeCells(OPENCODE_TARGET, OPENCODE_TEST, 'tests/unit/profile-mode.test.ts'),
|
|
156
|
+
permissionKeys: opencodePermissionKeys(OPENCODE_TARGET),
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: OPENCODE_V1_TARGET,
|
|
160
|
+
status: 'promised',
|
|
161
|
+
agentReach: 'primary',
|
|
162
|
+
cells: opencodeCells(OPENCODE_V1_TARGET, OPENCODE_V1_TEST, 'tests/unit/opencode-v1-target.test.ts'),
|
|
163
|
+
permissionKeys: opencodePermissionKeys(OPENCODE_V1_TARGET),
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Refuse a snapshot that cannot be published. This is the structural guard
|
|
169
|
+
* behind "an unknown cell is never a tick": a promised target must have a
|
|
170
|
+
* measured emission on both axes for every capability. `unknown` remains valid
|
|
171
|
+
* on an unverified target, where the whole row is labelled unverified.
|
|
172
|
+
*
|
|
173
|
+
* F010 is the design's code for a matrix that does not match the build: it
|
|
174
|
+
* fails the report rather than rendering a claim nobody measured.
|
|
175
|
+
*/
|
|
176
|
+
export function verifySnapshot(snapshot, rendererVersion) {
|
|
177
|
+
if (rendererVersion !== undefined && snapshot.renderer.version !== rendererVersion) {
|
|
178
|
+
throw new FarnaError('F010_RENDERER_MISMATCH', `the capability snapshot records ${snapshot.renderer.name} ${snapshot.renderer.version} but this build pins ${rendererVersion}`, {
|
|
179
|
+
subject: snapshot.renderer.name,
|
|
180
|
+
action: 'measure the matrix against the pinned renderer and update the snapshot in the same change',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const ids = snapshot.targets.map((target) => target.id);
|
|
184
|
+
for (const supported of SUPPORTED_TARGETS) {
|
|
185
|
+
const matches = ids.filter((id) => id === supported).length;
|
|
186
|
+
if (matches !== 1) {
|
|
187
|
+
throw new FarnaError('F010_RENDERER_MISMATCH', `the capability snapshot has ${matches} row(s) for the supported target "${supported}"`, {
|
|
188
|
+
subject: supported,
|
|
189
|
+
action: 'give every supported target exactly one measured row',
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
for (const target of snapshot.targets) {
|
|
194
|
+
if (target.status !== 'promised') {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
for (const capability of MATRIX_CAPABILITIES) {
|
|
198
|
+
const measured = target.cells[capability];
|
|
199
|
+
if (measured.agent === 'unknown' || measured.workspace === 'unknown') {
|
|
200
|
+
throw new FarnaError('F010_RENDERER_MISMATCH', `the promised target "${target.id}" has an unmeasured "${capability}" cell`, {
|
|
201
|
+
subject: `${target.id}/${capability}`,
|
|
202
|
+
action: 'measure the cell, or mark the target unverified',
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** The one glyph each emission renders as. No value renders blank. */
|
|
209
|
+
export function emissionGlyph(emission) {
|
|
210
|
+
switch (emission) {
|
|
211
|
+
case 'native':
|
|
212
|
+
return '[x]';
|
|
213
|
+
case 'emulated':
|
|
214
|
+
return '[~]';
|
|
215
|
+
case 'dropped':
|
|
216
|
+
return '[ ]';
|
|
217
|
+
case 'unknown':
|
|
218
|
+
return '[?]';
|
|
219
|
+
default: {
|
|
220
|
+
const exhaustive = emission;
|
|
221
|
+
return exhaustive;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** The word each emission renders as. `unknown` is always "not measured". */
|
|
226
|
+
export function emissionWord(emission) {
|
|
227
|
+
return emission === 'unknown' ? 'not measured' : emission;
|
|
228
|
+
}
|
|
229
|
+
/** Every permission category, in the product's declared order. */
|
|
230
|
+
export function permissionCategories() {
|
|
231
|
+
return PERMISSION_CATEGORIES;
|
|
232
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Capability } from '../core/constants.js';
|
|
2
|
+
import { type CapabilityCell, type CapabilitySnapshot, type PermissionKeyCell, type TargetStatus } from '../matrix/snapshot.js';
|
|
3
|
+
import type { PermissionCategory } from '../permissions/permissions.js';
|
|
4
|
+
/**
|
|
5
|
+
* The machine-readable capability report. It is built from the committed
|
|
6
|
+
* snapshot and carries every value the human table prints, so `--json` is the
|
|
7
|
+
* same claim in a shape a pipeline can consume.
|
|
8
|
+
*/
|
|
9
|
+
export type CapabilityReport = {
|
|
10
|
+
schemaVersion: 1;
|
|
11
|
+
command: 'report';
|
|
12
|
+
ok: true;
|
|
13
|
+
exitCode: 0;
|
|
14
|
+
renderer: {
|
|
15
|
+
name: string;
|
|
16
|
+
version: string;
|
|
17
|
+
};
|
|
18
|
+
targets: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
status: TargetStatus;
|
|
21
|
+
agentReach: 'primary' | 'subagent';
|
|
22
|
+
capabilities: Record<Capability, CapabilityCell>;
|
|
23
|
+
permissionKeys: Record<PermissionCategory, PermissionKeyCell>;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
export declare function buildCapabilityReport(snapshot?: CapabilitySnapshot): CapabilityReport;
|
|
27
|
+
/**
|
|
28
|
+
* The human table. `unknown` renders as `[?] not measured` and is never
|
|
29
|
+
* printed as `[x]`; every dropped, emulated and unknown cell prints its
|
|
30
|
+
* consequence, so the table never becomes a bare tick a reader can misread.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatCapabilityReport(report: CapabilityReport): string;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { PRODUCT_VERSION } from '../core/constants.js';
|
|
2
|
+
import { escapeControlCharacters } from '../core/text.js';
|
|
3
|
+
import { emissionGlyph, emissionWord, MATRIX_CAPABILITIES, permissionCategories, SNAPSHOT, } from '../matrix/snapshot.js';
|
|
4
|
+
export function buildCapabilityReport(snapshot = SNAPSHOT) {
|
|
5
|
+
return {
|
|
6
|
+
schemaVersion: 1,
|
|
7
|
+
command: 'report',
|
|
8
|
+
ok: true,
|
|
9
|
+
exitCode: 0,
|
|
10
|
+
renderer: { ...snapshot.renderer },
|
|
11
|
+
targets: snapshot.targets.map((target) => ({
|
|
12
|
+
id: target.id,
|
|
13
|
+
status: target.status,
|
|
14
|
+
agentReach: target.agentReach,
|
|
15
|
+
// A copy, never the snapshot object: a caller must not be able to mutate
|
|
16
|
+
// the measured record through a report it was handed.
|
|
17
|
+
capabilities: Object.fromEntries(MATRIX_CAPABILITIES.map((capability) => [capability, { ...target.cells[capability] }])),
|
|
18
|
+
permissionKeys: Object.fromEntries(permissionCategories().map((key) => [key, { ...target.permissionKeys[key] }])),
|
|
19
|
+
})),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function pad(value, width) {
|
|
23
|
+
return value.length >= width ? `${value} ` : value.padEnd(width);
|
|
24
|
+
}
|
|
25
|
+
const CAPABILITY_WIDTH = 14;
|
|
26
|
+
const TARGET_WIDTH = 17;
|
|
27
|
+
const AXIS_AGENT_WIDTH = 6;
|
|
28
|
+
const AXIS_WORKSPACE_WIDTH = 11;
|
|
29
|
+
/** The non-native axes of a cell, each with its glyph and word. */
|
|
30
|
+
function nonNativeAxes(cell) {
|
|
31
|
+
const axes = [];
|
|
32
|
+
if (cell.agent !== 'native') {
|
|
33
|
+
axes.push(`agent ${emissionGlyph(cell.agent)} ${emissionWord(cell.agent)}`);
|
|
34
|
+
}
|
|
35
|
+
if (cell.workspace !== 'native') {
|
|
36
|
+
axes.push(`workspace ${emissionGlyph(cell.workspace)} ${emissionWord(cell.workspace)}`);
|
|
37
|
+
}
|
|
38
|
+
return axes.join(', ');
|
|
39
|
+
}
|
|
40
|
+
function capabilityTable(report) {
|
|
41
|
+
const lines = ['capability matrix'];
|
|
42
|
+
const header = report.targets.map((target) => pad(target.id, TARGET_WIDTH)).join('');
|
|
43
|
+
lines.push(` ${pad('capability', CAPABILITY_WIDTH)}${header}`.trimEnd());
|
|
44
|
+
const axisHeader = report.targets
|
|
45
|
+
.map(() => `${pad('agent', AXIS_AGENT_WIDTH)}${pad('workspace', AXIS_WORKSPACE_WIDTH)}`)
|
|
46
|
+
.join('');
|
|
47
|
+
lines.push(` ${pad('', CAPABILITY_WIDTH)}${axisHeader}`.trimEnd());
|
|
48
|
+
for (const capability of MATRIX_CAPABILITIES) {
|
|
49
|
+
const cells = report.targets
|
|
50
|
+
.map((target) => {
|
|
51
|
+
const cell = target.capabilities[capability];
|
|
52
|
+
return `${pad(emissionGlyph(cell.agent), AXIS_AGENT_WIDTH)}${pad(emissionGlyph(cell.workspace), AXIS_WORKSPACE_WIDTH)}`;
|
|
53
|
+
})
|
|
54
|
+
.join('');
|
|
55
|
+
lines.push(` ${pad(capability, CAPABILITY_WIDTH)}${cells}`.trimEnd());
|
|
56
|
+
}
|
|
57
|
+
lines.push('', 'consequences');
|
|
58
|
+
let anyConsequence = false;
|
|
59
|
+
for (const target of report.targets) {
|
|
60
|
+
lines.push(` ${escapeControlCharacters(target.id)}`);
|
|
61
|
+
for (const capability of MATRIX_CAPABILITIES) {
|
|
62
|
+
const cell = target.capabilities[capability];
|
|
63
|
+
const axes = nonNativeAxes(cell);
|
|
64
|
+
if (axes === '') {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
anyConsequence = true;
|
|
68
|
+
lines.push(` ${pad(capability, 12)}${axes}`);
|
|
69
|
+
if (cell.consequence !== null) {
|
|
70
|
+
lines.push(` ${escapeControlCharacters(cell.consequence)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!anyConsequence) {
|
|
75
|
+
lines.push(' none: every cell is native');
|
|
76
|
+
}
|
|
77
|
+
return lines;
|
|
78
|
+
}
|
|
79
|
+
function permissionTable(report) {
|
|
80
|
+
const keys = permissionCategories();
|
|
81
|
+
const lines = ['', 'permission keys (per persona, agent mode)'];
|
|
82
|
+
const header = report.targets.map((target) => pad(target.id, 13)).join('');
|
|
83
|
+
lines.push(` ${pad('key', 12)}${header}`.trimEnd());
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
const cells = report.targets
|
|
86
|
+
.map((target) => pad(emissionGlyph(target.permissionKeys[key].emission), 13))
|
|
87
|
+
.join('');
|
|
88
|
+
lines.push(` ${pad(key, 12)}${cells}`.trimEnd());
|
|
89
|
+
}
|
|
90
|
+
lines.push('', 'permission consequences');
|
|
91
|
+
let anyConsequence = false;
|
|
92
|
+
for (const target of report.targets) {
|
|
93
|
+
const entries = [];
|
|
94
|
+
for (const key of keys) {
|
|
95
|
+
const cell = target.permissionKeys[key];
|
|
96
|
+
if (cell.emission === 'native') {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
anyConsequence = true;
|
|
100
|
+
const code = cell.code === null ? '' : ` (${cell.code})`;
|
|
101
|
+
entries.push(` ${pad(key, 10)}${emissionGlyph(cell.emission)} ${emissionWord(cell.emission)}${code}`);
|
|
102
|
+
if (cell.consequence !== null) {
|
|
103
|
+
entries.push(` ${escapeControlCharacters(cell.consequence)}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (entries.length > 0) {
|
|
107
|
+
lines.push(` ${escapeControlCharacters(target.id)}`, ...entries);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!anyConsequence) {
|
|
111
|
+
lines.push(' none: every permission key is native');
|
|
112
|
+
}
|
|
113
|
+
return lines;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The human table. `unknown` renders as `[?] not measured` and is never
|
|
117
|
+
* printed as `[x]`; every dropped, emulated and unknown cell prints its
|
|
118
|
+
* consequence, so the table never becomes a bare tick a reader can misread.
|
|
119
|
+
*/
|
|
120
|
+
export function formatCapabilityReport(report) {
|
|
121
|
+
const lines = [
|
|
122
|
+
`farna-bootstrapper report ${PRODUCT_VERSION}`,
|
|
123
|
+
` renderer ${report.renderer.name} ${report.renderer.version}`,
|
|
124
|
+
' cells native [x] emulated [~] dropped [ ] not measured [?]',
|
|
125
|
+
' note the committed measured matrix; the harness remains the authority on runtime behaviour',
|
|
126
|
+
'',
|
|
127
|
+
...capabilityTable(report),
|
|
128
|
+
...permissionTable(report),
|
|
129
|
+
'',
|
|
130
|
+
'labels',
|
|
131
|
+
...report.targets.map((target) => ` ${pad(target.id, 12)}${pad(escapeControlCharacters(target.status), 12)}reach ${target.agentReach}`),
|
|
132
|
+
'',
|
|
133
|
+
'report: ok',
|
|
134
|
+
];
|
|
135
|
+
return `${lines.join('\n')}\n`;
|
|
136
|
+
}
|