farna-bootstrapper 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +30 -0
  3. package/NOTICE +42 -0
  4. package/README.md +1079 -2
  5. package/SECURITY.md +65 -0
  6. package/dist/cli/commands/check.d.ts +58 -0
  7. package/dist/cli/commands/check.js +198 -0
  8. package/dist/cli/commands/generate.d.ts +75 -0
  9. package/dist/cli/commands/generate.js +218 -0
  10. package/dist/cli/commands/init.d.ts +52 -0
  11. package/dist/cli/commands/init.js +271 -0
  12. package/dist/cli/main.d.ts +2 -0
  13. package/dist/cli/main.js +51 -0
  14. package/dist/cli/program.d.ts +23 -0
  15. package/dist/cli/program.js +183 -0
  16. package/dist/compose/resolve.d.ts +154 -0
  17. package/dist/compose/resolve.js +545 -0
  18. package/dist/config/load.d.ts +4 -0
  19. package/dist/config/load.js +45 -0
  20. package/dist/config/schema.d.ts +22 -0
  21. package/dist/config/schema.js +46 -0
  22. package/dist/core/constants.d.ts +268 -0
  23. package/dist/core/constants.js +336 -0
  24. package/dist/core/errors.d.ts +44 -0
  25. package/dist/core/errors.js +75 -0
  26. package/dist/core/fs.d.ts +31 -0
  27. package/dist/core/fs.js +169 -0
  28. package/dist/core/json.d.ts +22 -0
  29. package/dist/core/json.js +174 -0
  30. package/dist/core/paths.d.ts +45 -0
  31. package/dist/core/paths.js +110 -0
  32. package/dist/core/text.d.ts +10 -0
  33. package/dist/core/text.js +27 -0
  34. package/dist/index.d.ts +10 -0
  35. package/dist/index.js +1 -0
  36. package/dist/lock/lockfile.d.ts +229 -0
  37. package/dist/lock/lockfile.js +333 -0
  38. package/dist/materialise/source-tree.d.ts +77 -0
  39. package/dist/materialise/source-tree.js +264 -0
  40. package/dist/permissions/permissions.d.ts +128 -0
  41. package/dist/permissions/permissions.js +452 -0
  42. package/dist/render/commit.d.ts +59 -0
  43. package/dist/render/commit.js +279 -0
  44. package/dist/render/generate-lock.d.ts +9 -0
  45. package/dist/render/generate-lock.js +203 -0
  46. package/dist/render/identity.d.ts +23 -0
  47. package/dist/render/identity.js +396 -0
  48. package/dist/render/orphans.d.ts +59 -0
  49. package/dist/render/orphans.js +234 -0
  50. package/dist/render/port.d.ts +96 -0
  51. package/dist/render/port.js +1 -0
  52. package/dist/render/prepare.d.ts +33 -0
  53. package/dist/render/prepare.js +139 -0
  54. package/dist/render/root-cleanliness.d.ts +28 -0
  55. package/dist/render/root-cleanliness.js +76 -0
  56. package/dist/render/stage.d.ts +36 -0
  57. package/dist/render/stage.js +92 -0
  58. package/dist/render/staging.d.ts +16 -0
  59. package/dist/render/staging.js +94 -0
  60. package/dist/render/structured.d.ts +35 -0
  61. package/dist/render/structured.js +258 -0
  62. package/dist/render/upstream.d.ts +41 -0
  63. package/dist/render/upstream.js +179 -0
  64. package/dist/report/format.d.ts +7 -0
  65. package/dist/report/format.js +97 -0
  66. package/dist/report/warnings.d.ts +21 -0
  67. package/dist/report/warnings.js +24 -0
  68. package/dist/source/digest.d.ts +18 -0
  69. package/dist/source/digest.js +77 -0
  70. package/dist/source/frontmatter.d.ts +12 -0
  71. package/dist/source/frontmatter.js +29 -0
  72. package/dist/source/load.d.ts +103 -0
  73. package/dist/source/load.js +676 -0
  74. package/dist/source/schema.d.ts +149 -0
  75. package/dist/source/schema.js +283 -0
  76. package/dist/source/yaml.d.ts +10 -0
  77. package/dist/source/yaml.js +49 -0
  78. package/dist/verify/containment.d.ts +22 -0
  79. package/dist/verify/containment.js +753 -0
  80. package/package.json +79 -4
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Every on-disk name, exit code and fixed vocabulary the tool uses.
3
+ * A name appears here once; no other module restates one. The comment is a
4
+ * claim, so a duplicated literal is a defect: imports below are the only
5
+ * spelling of each name.
6
+ */
7
+ export declare const PRODUCT_NAME = "farna-bootstrapper";
8
+ export declare const PRODUCT_VERSION = "0.1.0";
9
+ /** The one source/schema version this build understands. */
10
+ export declare const SCHEMA_VERSION: 1;
11
+ /**
12
+ * The OpenCode major each OpenCode target is measured against. `opencode` is
13
+ * OpenCode 2.x (`@opencode/cli`): the V2 per-agent file (`description`, `mode`,
14
+ * `model`, ordered permission records, no `name`), the `mcp.servers` envelope
15
+ * and the `{ id, setup }` plugin. `opencodev1` is OpenCode 1.x (`opencode-ai`):
16
+ * V1 agent frontmatter with `name`, the per-tool `permission` map, the flat
17
+ * `mcp.<name>` map and the `RulesyncHooksPlugin` module. Both write the same
18
+ * paths. This is documentation for the user, not a runtime probe: the tool
19
+ * never shells out to OpenCode.
20
+ */
21
+ export declare const OPENCODE_SUPPORTED_MAJOR = "2";
22
+ export declare const OPENCODE_V1_SUPPORTED_MAJOR = "1";
23
+ /**
24
+ * The render modes this build can write. `agent` is the default: every persona
25
+ * is live and carried per agent. `profile` is selected by
26
+ * `targets.<target>.active` or the `--persona` override, makes exactly one
27
+ * persona live, and lets it own the workspace at the repository root.
28
+ */
29
+ export declare const RENDER_MODES: readonly ["agent", "profile"];
30
+ export type RenderMode = (typeof RENDER_MODES)[number];
31
+ export declare const MODE_AGENT: RenderMode;
32
+ export declare const MODE_PROFILE: RenderMode;
33
+ /** The source root, relative to the repository root. */
34
+ export declare const ROOT_DIR = ".farna";
35
+ export declare const CONFIG_FILE = "config.jsonc";
36
+ export declare const CONFIG_PATH = ".farna/config.jsonc";
37
+ export declare const LOCK_FILE = "lock.json";
38
+ export declare const LOCK_PATH = ".farna/lock.json";
39
+ /**
40
+ * The exclusive run lock: a **directory** created with `mkdir` (atomic on every
41
+ * supported filesystem), with the owner pid inside. Two `generate` runs in one
42
+ * repository would each plan from the same lockfile and each remove and rewrite
43
+ * the managed set, so the second could delete what the first just wrote (or
44
+ * commit a plan it computed before the first changed the tree). The lock is
45
+ * local-only state, never committed, and its presence is not a managed output.
46
+ */
47
+ export declare const GENERATE_LOCK_FILE = ".generate.lock";
48
+ export declare const GENERATE_LOCK_PATH = ".farna/.generate.lock";
49
+ /** How long a lockfile whose owner pid is still alive is honoured before it is treated as orphaned. */
50
+ export declare const GENERATE_LOCK_STALE_MS: number;
51
+ /** Generated files are `0644`, generated directories `0755`, whatever the umask. */
52
+ export declare const OUTPUT_FILE_MODE = 420;
53
+ export declare const OUTPUT_DIR_MODE = 493;
54
+ export declare const PERSONAS_DIR = "personas";
55
+ export declare const RESOURCES_DIR = "resources";
56
+ export declare const RULES_DIR = "rules";
57
+ export declare const PERMISSIONS_DIR = "permissions";
58
+ export declare const MCP_DIR = "mcp";
59
+ export declare const SKILLS_DIR = "skills";
60
+ export declare const COMMANDS_DIR = "commands";
61
+ export declare const HOOKS_DIR = "hooks";
62
+ /** The extensions each source kind uses, and the one emitted artefacts use. */
63
+ export declare const PERSONA_FILE_EXT = ".yaml";
64
+ export declare const RULE_FILE_EXT = ".md";
65
+ export declare const PERMISSION_FILE_EXT = ".jsonc";
66
+ export declare const COMMAND_FILE_EXT = ".md";
67
+ export declare const STRUCTURED_RESOURCE_FILE_EXT = ".jsonc";
68
+ export declare const SKILL_FILE_NAME = "SKILL.md";
69
+ export declare const AGENT_FILE_EXT = ".md";
70
+ /** The one base persona a composed persona may extend. */
71
+ export declare const MAX_EXTENDS_DEPTH = 32;
72
+ /**
73
+ * The targets this slice renders. Exactly one target is configured per run
74
+ * (`config.md`): rendering several configured targets in one run would need a
75
+ * per-target lockfile and mode plan, which is later work.
76
+ */
77
+ export declare const DEFAULT_TARGET: "claudecode";
78
+ export declare const OPENCODE_TARGET: "opencode";
79
+ export declare const OPENCODE_V1_TARGET: "opencodev1";
80
+ export type SupportedTarget = typeof DEFAULT_TARGET | typeof OPENCODE_TARGET | typeof OPENCODE_V1_TARGET;
81
+ /** The supported targets as a tuple, so a schema can validate against exactly them. */
82
+ export declare const TARGET_ENUM: readonly ["claudecode", "opencode", "opencodev1"];
83
+ export declare const SUPPORTED_TARGETS: readonly SupportedTarget[];
84
+ /**
85
+ * Both OpenCode targets write the same paths and the same workspace kinds; only
86
+ * the emitted shapes differ. Every branch that means "the OpenCode family"
87
+ * consults this list rather than repeating the two ids, so a third major is one
88
+ * edit.
89
+ */
90
+ export declare const OPENCODE_TARGETS: readonly SupportedTarget[];
91
+ /** A target in the OpenCode family, so a member type cannot drift from the list. */
92
+ export type OpencodeTarget = (typeof OPENCODE_TARGETS)[number];
93
+ export declare function isOpencodeTarget(target: SupportedTarget): target is OpencodeTarget;
94
+ /**
95
+ * The targets that support profile mode in this build. Profile mode needs a
96
+ * workspace a single persona can own end to end; the OpenCode targets'
97
+ * workspace resource kinds (`mcp`, `skill`, `command`, `hook`) make them the
98
+ * first targets. Claude Code's only workspace-only capability is `command`, a
99
+ * content capability that does not force a profile, so profile mode there is
100
+ * later work and `active` is refused rather than silently ignored.
101
+ */
102
+ export declare const PROFILE_TARGETS: readonly SupportedTarget[];
103
+ export declare function targetSupportsProfile(target: SupportedTarget): boolean;
104
+ /**
105
+ * The capabilities that *force* profile mode rather than merely being carried
106
+ * by it. Only a boundary capability the target can express at the workspace
107
+ * level and nowhere else forces the mode: on OpenCode that is `mcp` and `hook`.
108
+ * A `skill` or `command` is content the target could in principle drop with a
109
+ * loss, so selecting profile mode for it is a choice and is reported as W109.
110
+ */
111
+ export declare const PROFILE_FORCING_KINDS: readonly Capability[];
112
+ /** The Claude Code directories, relative to the repository root. */
113
+ export declare const CLAUDE_DIR = ".claude";
114
+ export declare const CLAUDE_AGENTS_DIR = ".claude/agents";
115
+ /**
116
+ * The OpenCode paths this slice writes, relative to the repository root.
117
+ * `commands` is plural and the workspace config is `opencode.jsonc`, both
118
+ * measured at rulesync 43.11.0.
119
+ */
120
+ export declare const OPENCODE_DIR = ".opencode";
121
+ export declare const OPENCODE_AGENTS_DIR = ".opencode/agents";
122
+ export declare const OPENCODE_COMMANDS_DIR = ".opencode/commands";
123
+ export declare const OPENCODE_SKILLS_DIR = ".opencode/skills";
124
+ export declare const OPENCODE_PLUGINS_DIR = ".opencode/plugins";
125
+ export declare const OPENCODE_CONFIG_FILE = "opencode.jsonc";
126
+ export declare const OPENCODE_HOOKS_PLUGIN = ".opencode/plugins/rulesync-hooks.js";
127
+ /** The rulesync source files a workspace resource kind needs. */
128
+ export declare const RULESYNC_MCP_FILE = "mcp.jsonc";
129
+ export declare const RULESYNC_HOOKS_FILE = "hooks.jsonc";
130
+ export declare const MANAGED_OUTPUT_DIRS: Readonly<Record<SupportedTarget, readonly string[]>>;
131
+ /** Whole files at the repository root that a target can own. */
132
+ export declare const MANAGED_OUTPUT_FILES: Readonly<Record<SupportedTarget, readonly string[]>>;
133
+ /**
134
+ * Operating-system metadata a checkout can create in a source directory. These
135
+ * are not source: a source tree that has been on macOS or Windows must not stop
136
+ * compiling because Finder wrote `.DS_Store`. Every other unexpected file stays a
137
+ * hard error.
138
+ */
139
+ export declare const OS_METADATA_NAMES: readonly string[];
140
+ export declare function isOsMetadataName(name: string): boolean;
141
+ /**
142
+ * Our own staging namespace. `commitFiles` writes hidden siblings named
143
+ * `.<target>.farna-tmp-<pid>-<uuid>` on the same filesystem and renames them
144
+ * into place; `check` ignores this namespace and `generate` sweeps it, so a
145
+ * killed run can never make the tree permanently red.
146
+ */
147
+ export declare const STAGING_INFIX = ".farna-tmp-";
148
+ /** The `.gitignore` pattern for the staging namespace, at any depth. */
149
+ export declare const STAGING_PATTERN = "**/.*.farna-tmp-*";
150
+ /**
151
+ * The local-only paths `init` adds to `.gitignore`, plus OS metadata. The
152
+ * staging pattern keeps a killed `generate`'s temporary sibling, which can
153
+ * appear in any managed directory, out of a commit.
154
+ */
155
+ export declare const GITIGNORE_LINES: readonly string[];
156
+ /**
157
+ * The managed paths whose line endings change their committed bytes. `check`
158
+ * compares bytes, so a checkout that rewrites them to CRLF would report drift
159
+ * the source never declared. `init` merges these into the consumer's
160
+ * `.gitattributes` for every supported target, so switching target in the
161
+ * config does not leave the new outputs unpinned.
162
+ */
163
+ export declare const GITATTRIBUTES_LINES: readonly string[];
164
+ /**
165
+ * This product's own lockfile (`.farna/lock.json`) is derived and small: it
166
+ * records the config hash, the file list and the renderer pin, so it is refused
167
+ * rather than read above this bound. It also bounds the small package manifests
168
+ * read to locate the installed renderer; npm's lock records use the separate
169
+ * `NPM_LOCKFILE_MAX_BYTES` below.
170
+ */
171
+ export declare const LOCKFILE_MAX_BYTES: number;
172
+ /**
173
+ * npm's lock records (`node_modules/.package-lock.json` and a project
174
+ * `package-lock.json`) scale with the dependency tree: a monorepo lockfile can
175
+ * legitimately be several megabytes, far above this product's own derived
176
+ * lockfile. The bound is generous so a real record is read, and still finite so
177
+ * a repository-controlled path can never allocate without limit.
178
+ *
179
+ * The renderer's entry is searched for under any `packages` key ending in
180
+ * `node_modules/<renderer-name>`, so a nested install
181
+ * (`node_modules/<product>/node_modules/<renderer>`) is read rather than
182
+ * mistaken for an absent record. The installed version is enforced regardless;
183
+ * a found entry's integrity is compared with the pin; a record with no renderer
184
+ * entry anywhere in it (a global install that wrote no npm lockfile) yields
185
+ * `W114_RENDERER_INTEGRITY_UNVERIFIED` and never substitutes the compile-time
186
+ * pin as a verified integrity. A present record that cannot be read, or is
187
+ * above this bound, is refused (F010) instead of warning.
188
+ */
189
+ export declare const NPM_LOCKFILE_MAX_BYTES: number;
190
+ /**
191
+ * A managed file and a source file are bounded for the same reason: a
192
+ * repository-controlled path must never make the process allocate until the JS
193
+ * string limit throws an untyped `Invalid string length`.
194
+ */
195
+ export declare const MANAGED_FILE_MAX_BYTES: number;
196
+ export declare const SOURCE_MAX_BYTES: number;
197
+ /** A staging sibling older than this is swept even when its pid was reused. */
198
+ export declare const STAGING_MAX_AGE_MS: number;
199
+ export declare const ID_RE: RegExp;
200
+ export declare const ID_MAX_LENGTH = 64;
201
+ export type Capability = 'rule' | 'mcp' | 'skill' | 'command' | 'permission' | 'hook' | 'model';
202
+ /**
203
+ * Capabilities a persona resource reference may name in this slice. `model` is
204
+ * absent: a model is expressed with the persona's `model` class, and a
205
+ * `model/<id>` reference is refused rather than accepted and ignored.
206
+ */
207
+ export declare const SUPPORTED_RESOURCE_KINDS: readonly Capability[];
208
+ /**
209
+ * The capability class of each resource kind. A dropped
210
+ * boundary capability is HIGH and can refuse; a dropped content capability is
211
+ * MEDIUM and can only produce a loss.
212
+ */
213
+ export declare const BOUNDARY_CAPABILITIES: readonly Capability[];
214
+ /** The resource kinds the OpenCode targets carry only at the workspace level. */
215
+ export declare const OPENCODE_WORKSPACE_KINDS: readonly Capability[];
216
+ export type ExitCode = 0 | 1 | 2 | 3 | 4 | 5;
217
+ export declare const EXIT: {
218
+ readonly ok: 0;
219
+ readonly invalidConfig: 1;
220
+ readonly conflict: 2;
221
+ readonly refused: 3;
222
+ /** `F008_DECLARED_NOT_EMITTED`: the renderer lost or invented declared content. */
223
+ readonly declaredNotEmitted: 4;
224
+ /** `check` reports drift as exit 1. Drift is not an exception, so it has no F-code. */
225
+ readonly drift: 1;
226
+ readonly renderFailed: 5;
227
+ };
228
+ /** The code a drift item carries in a `check` payload. Not an error code. */
229
+ export declare const DRIFT_CODE: "F007_DRIFT";
230
+ /**
231
+ * The code a drift item carries when the finding is not a changed byte of ours
232
+ * but content outside our ownership: an unrecorded file in a managed location,
233
+ * or an extra file in a skill tree. `check` fails on it because the path is
234
+ * live, but `generate` never deletes it.
235
+ */
236
+ export declare const OUTSIDE_OWNERSHIP_CODE: "W107_OUTSIDE_OWNERSHIP";
237
+ export type ErrorCode = 'F001_INVALID_CONFIG' | 'F002_SECRET_LITERAL' | 'F003_PATH_UNSAFE' | 'F005_CONFLICT' | 'F008_DECLARED_NOT_EMITTED' | 'F009_RENDER_FAILED' | 'F010_RENDERER_MISMATCH' | 'F011_PERMISSION_UNMAPPED' | 'F012_WRITE_FAILED';
238
+ /**
239
+ * A code the CLI can report. `ErrorCode` is the exception table; `DRIFT_CODE`
240
+ * is included because `generate` refuses to take over an unrecorded managed
241
+ * file with F007, the same code `check` reports as a drift result. `check`
242
+ * never throws it, so the exception table stays free of it.
243
+ */
244
+ export type DiagnosticCode = ErrorCode | typeof DRIFT_CODE;
245
+ /** Exit code per diagnostic code. The table lives here once. F007 is absent: drift is a result. */
246
+ export declare const EXIT_BY_CODE: Record<ErrorCode, ExitCode>;
247
+ 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"];
249
+ export type WarningCode = (typeof WARNING_CODES)[number];
250
+ /**
251
+ * A warning's default severity is a property of its code.
252
+ * W106 is the only code whose severity depends on what it removes: a deny that
253
+ * takes away an allow is medium, every other stricter-wins report is info.
254
+ *
255
+ * W114 is medium, not high: the renderer's version is still enforced, so a
256
+ * different renderer cannot pass. What is missing is the tarball digest that
257
+ * ties the installed bytes to the published package, which makes this a
258
+ * provenance caveat rather than a correctness failure. It is not info either:
259
+ * a run whose integrity could not be checked must never look like a clean
260
+ * integrity pass. High is reserved for a warning that records a real loss
261
+ * (W112), which this is not.
262
+ *
263
+ * W101's severity is dynamic: `high` for a boundary capability (`permission`,
264
+ * `hook`, `mcp`), `medium` for content (`rule`, `model`, `skill`, `command`).
265
+ * The table value is the content default; every boundary emission passes
266
+ * `high` explicitly so the classification is visible at the call site.
267
+ */
268
+ export declare const WARNING_SEVERITY: Record<WarningCode, Severity>;
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Every on-disk name, exit code and fixed vocabulary the tool uses.
3
+ * A name appears here once; no other module restates one. The comment is a
4
+ * claim, so a duplicated literal is a defect: imports below are the only
5
+ * spelling of each name.
6
+ */
7
+ export const PRODUCT_NAME = 'farna-bootstrapper';
8
+ export const PRODUCT_VERSION = '0.1.0';
9
+ /** The one source/schema version this build understands. */
10
+ export const SCHEMA_VERSION = 1;
11
+ /**
12
+ * The OpenCode major each OpenCode target is measured against. `opencode` is
13
+ * OpenCode 2.x (`@opencode/cli`): the V2 per-agent file (`description`, `mode`,
14
+ * `model`, ordered permission records, no `name`), the `mcp.servers` envelope
15
+ * and the `{ id, setup }` plugin. `opencodev1` is OpenCode 1.x (`opencode-ai`):
16
+ * V1 agent frontmatter with `name`, the per-tool `permission` map, the flat
17
+ * `mcp.<name>` map and the `RulesyncHooksPlugin` module. Both write the same
18
+ * paths. This is documentation for the user, not a runtime probe: the tool
19
+ * never shells out to OpenCode.
20
+ */
21
+ export const OPENCODE_SUPPORTED_MAJOR = '2';
22
+ export const OPENCODE_V1_SUPPORTED_MAJOR = '1';
23
+ /**
24
+ * The render modes this build can write. `agent` is the default: every persona
25
+ * is live and carried per agent. `profile` is selected by
26
+ * `targets.<target>.active` or the `--persona` override, makes exactly one
27
+ * persona live, and lets it own the workspace at the repository root.
28
+ */
29
+ export const RENDER_MODES = ['agent', 'profile'];
30
+ export const MODE_AGENT = 'agent';
31
+ export const MODE_PROFILE = 'profile';
32
+ /** The source root, relative to the repository root. */
33
+ export const ROOT_DIR = '.farna';
34
+ export const CONFIG_FILE = 'config.jsonc';
35
+ export const CONFIG_PATH = `${ROOT_DIR}/${CONFIG_FILE}`;
36
+ export const LOCK_FILE = 'lock.json';
37
+ export const LOCK_PATH = `${ROOT_DIR}/${LOCK_FILE}`;
38
+ /**
39
+ * The exclusive run lock: a **directory** created with `mkdir` (atomic on every
40
+ * supported filesystem), with the owner pid inside. Two `generate` runs in one
41
+ * repository would each plan from the same lockfile and each remove and rewrite
42
+ * the managed set, so the second could delete what the first just wrote (or
43
+ * commit a plan it computed before the first changed the tree). The lock is
44
+ * local-only state, never committed, and its presence is not a managed output.
45
+ */
46
+ export const GENERATE_LOCK_FILE = '.generate.lock';
47
+ export const GENERATE_LOCK_PATH = `${ROOT_DIR}/${GENERATE_LOCK_FILE}`;
48
+ /** How long a lockfile whose owner pid is still alive is honoured before it is treated as orphaned. */
49
+ export const GENERATE_LOCK_STALE_MS = 24 * 60 * 60 * 1000;
50
+ /** Generated files are `0644`, generated directories `0755`, whatever the umask. */
51
+ export const OUTPUT_FILE_MODE = 0o644;
52
+ export const OUTPUT_DIR_MODE = 0o755;
53
+ export const PERSONAS_DIR = 'personas';
54
+ export const RESOURCES_DIR = 'resources';
55
+ export const RULES_DIR = 'rules';
56
+ export const PERMISSIONS_DIR = 'permissions';
57
+ export const MCP_DIR = 'mcp';
58
+ export const SKILLS_DIR = 'skills';
59
+ export const COMMANDS_DIR = 'commands';
60
+ export const HOOKS_DIR = 'hooks';
61
+ /** The extensions each source kind uses, and the one emitted artefacts use. */
62
+ export const PERSONA_FILE_EXT = '.yaml';
63
+ export const RULE_FILE_EXT = '.md';
64
+ export const PERMISSION_FILE_EXT = '.jsonc';
65
+ export const COMMAND_FILE_EXT = '.md';
66
+ export const STRUCTURED_RESOURCE_FILE_EXT = '.jsonc';
67
+ export const SKILL_FILE_NAME = 'SKILL.md';
68
+ export const AGENT_FILE_EXT = '.md';
69
+ /** The one base persona a composed persona may extend. */
70
+ export const MAX_EXTENDS_DEPTH = 32;
71
+ /**
72
+ * The targets this slice renders. Exactly one target is configured per run
73
+ * (`config.md`): rendering several configured targets in one run would need a
74
+ * per-target lockfile and mode plan, which is later work.
75
+ */
76
+ export const DEFAULT_TARGET = 'claudecode';
77
+ export const OPENCODE_TARGET = 'opencode';
78
+ export const OPENCODE_V1_TARGET = 'opencodev1';
79
+ /** The supported targets as a tuple, so a schema can validate against exactly them. */
80
+ export const TARGET_ENUM = [DEFAULT_TARGET, OPENCODE_TARGET, OPENCODE_V1_TARGET];
81
+ export const SUPPORTED_TARGETS = TARGET_ENUM;
82
+ /**
83
+ * Both OpenCode targets write the same paths and the same workspace kinds; only
84
+ * the emitted shapes differ. Every branch that means "the OpenCode family"
85
+ * consults this list rather than repeating the two ids, so a third major is one
86
+ * edit.
87
+ */
88
+ export const OPENCODE_TARGETS = [OPENCODE_TARGET, OPENCODE_V1_TARGET];
89
+ export function isOpencodeTarget(target) {
90
+ return OPENCODE_TARGETS.includes(target);
91
+ }
92
+ /**
93
+ * The targets that support profile mode in this build. Profile mode needs a
94
+ * workspace a single persona can own end to end; the OpenCode targets'
95
+ * workspace resource kinds (`mcp`, `skill`, `command`, `hook`) make them the
96
+ * first targets. Claude Code's only workspace-only capability is `command`, a
97
+ * content capability that does not force a profile, so profile mode there is
98
+ * later work and `active` is refused rather than silently ignored.
99
+ */
100
+ export const PROFILE_TARGETS = [OPENCODE_TARGET, OPENCODE_V1_TARGET];
101
+ export function targetSupportsProfile(target) {
102
+ return PROFILE_TARGETS.includes(target);
103
+ }
104
+ /**
105
+ * The capabilities that *force* profile mode rather than merely being carried
106
+ * by it. Only a boundary capability the target can express at the workspace
107
+ * level and nowhere else forces the mode: on OpenCode that is `mcp` and `hook`.
108
+ * A `skill` or `command` is content the target could in principle drop with a
109
+ * loss, so selecting profile mode for it is a choice and is reported as W109.
110
+ */
111
+ export const PROFILE_FORCING_KINDS = ['mcp', 'hook'];
112
+ /** The Claude Code directories, relative to the repository root. */
113
+ export const CLAUDE_DIR = '.claude';
114
+ export const CLAUDE_AGENTS_DIR = `${CLAUDE_DIR}/agents`;
115
+ /**
116
+ * The OpenCode paths this slice writes, relative to the repository root.
117
+ * `commands` is plural and the workspace config is `opencode.jsonc`, both
118
+ * measured at rulesync 43.11.0.
119
+ */
120
+ export const OPENCODE_DIR = '.opencode';
121
+ export const OPENCODE_AGENTS_DIR = `${OPENCODE_DIR}/agents`;
122
+ export const OPENCODE_COMMANDS_DIR = `${OPENCODE_DIR}/commands`;
123
+ export const OPENCODE_SKILLS_DIR = `${OPENCODE_DIR}/skills`;
124
+ export const OPENCODE_PLUGINS_DIR = `${OPENCODE_DIR}/plugins`;
125
+ export const OPENCODE_CONFIG_FILE = 'opencode.jsonc';
126
+ export const OPENCODE_HOOKS_PLUGIN = `${OPENCODE_PLUGINS_DIR}/rulesync-hooks.js`;
127
+ /** The rulesync source files a workspace resource kind needs. */
128
+ export const RULESYNC_MCP_FILE = 'mcp.jsonc';
129
+ export const RULESYNC_HOOKS_FILE = 'hooks.jsonc';
130
+ /**
131
+ * The locations a target can own. `generate` may delete a lockfile-recorded
132
+ * file only when it lies in one of these locations, is still a regular file,
133
+ * and its bytes still equal the recorded digest. Everything outside them is
134
+ * user content, never swept.
135
+ */
136
+ const OPENCODE_OUTPUT_DIRS = [
137
+ OPENCODE_AGENTS_DIR,
138
+ OPENCODE_COMMANDS_DIR,
139
+ OPENCODE_SKILLS_DIR,
140
+ OPENCODE_PLUGINS_DIR,
141
+ ];
142
+ export const MANAGED_OUTPUT_DIRS = {
143
+ claudecode: [CLAUDE_AGENTS_DIR],
144
+ opencode: OPENCODE_OUTPUT_DIRS,
145
+ // Both OpenCode targets write the same locations, so a target switch rewrites
146
+ // the recorded paths in place rather than orphaning one target's output.
147
+ opencodev1: OPENCODE_OUTPUT_DIRS,
148
+ };
149
+ /** Whole files at the repository root that a target can own. */
150
+ export const MANAGED_OUTPUT_FILES = {
151
+ claudecode: [],
152
+ opencode: [OPENCODE_CONFIG_FILE],
153
+ opencodev1: [OPENCODE_CONFIG_FILE],
154
+ };
155
+ /**
156
+ * Operating-system metadata a checkout can create in a source directory. These
157
+ * are not source: a source tree that has been on macOS or Windows must not stop
158
+ * compiling because Finder wrote `.DS_Store`. Every other unexpected file stays a
159
+ * hard error.
160
+ */
161
+ export const OS_METADATA_NAMES = ['.DS_Store', 'Thumbs.db', 'desktop.ini'];
162
+ export function isOsMetadataName(name) {
163
+ return OS_METADATA_NAMES.includes(name);
164
+ }
165
+ /**
166
+ * Our own staging namespace. `commitFiles` writes hidden siblings named
167
+ * `.<target>.farna-tmp-<pid>-<uuid>` on the same filesystem and renames them
168
+ * into place; `check` ignores this namespace and `generate` sweeps it, so a
169
+ * killed run can never make the tree permanently red.
170
+ */
171
+ export const STAGING_INFIX = '.farna-tmp-';
172
+ /** The `.gitignore` pattern for the staging namespace, at any depth. */
173
+ export const STAGING_PATTERN = `**/.*${STAGING_INFIX}*`;
174
+ /**
175
+ * The local-only paths `init` adds to `.gitignore`, plus OS metadata. The
176
+ * staging pattern keeps a killed `generate`'s temporary sibling, which can
177
+ * appear in any managed directory, out of a commit.
178
+ */
179
+ export const GITIGNORE_LINES = [
180
+ `${ROOT_DIR}/local.jsonc`,
181
+ `${ROOT_DIR}/.journal.json`,
182
+ `/${GENERATE_LOCK_PATH}`,
183
+ `${STAGING_PATTERN}`,
184
+ ...OS_METADATA_NAMES,
185
+ ];
186
+ /**
187
+ * The managed paths whose line endings change their committed bytes. `check`
188
+ * compares bytes, so a checkout that rewrites them to CRLF would report drift
189
+ * the source never declared. `init` merges these into the consumer's
190
+ * `.gitattributes` for every supported target, so switching target in the
191
+ * config does not leave the new outputs unpinned.
192
+ */
193
+ export const GITATTRIBUTES_LINES = [
194
+ // The whole source root, so a CRLF checkout cannot change `configDigest` or
195
+ // any persona and resource byte between two machines.
196
+ `/${ROOT_DIR}/** text eol=lf`,
197
+ `/${CLAUDE_AGENTS_DIR}/** text eol=lf`,
198
+ `/${OPENCODE_AGENTS_DIR}/** text eol=lf`,
199
+ `/${OPENCODE_COMMANDS_DIR}/** text eol=lf`,
200
+ `/${OPENCODE_SKILLS_DIR}/** text eol=lf`,
201
+ `/${OPENCODE_PLUGINS_DIR}/** text eol=lf`,
202
+ `/${OPENCODE_CONFIG_FILE} text eol=lf`,
203
+ `/${LOCK_PATH} text eol=lf`,
204
+ ];
205
+ /**
206
+ * This product's own lockfile (`.farna/lock.json`) is derived and small: it
207
+ * records the config hash, the file list and the renderer pin, so it is refused
208
+ * rather than read above this bound. It also bounds the small package manifests
209
+ * read to locate the installed renderer; npm's lock records use the separate
210
+ * `NPM_LOCKFILE_MAX_BYTES` below.
211
+ */
212
+ export const LOCKFILE_MAX_BYTES = 4 * 1024 * 1024;
213
+ /**
214
+ * npm's lock records (`node_modules/.package-lock.json` and a project
215
+ * `package-lock.json`) scale with the dependency tree: a monorepo lockfile can
216
+ * legitimately be several megabytes, far above this product's own derived
217
+ * lockfile. The bound is generous so a real record is read, and still finite so
218
+ * a repository-controlled path can never allocate without limit.
219
+ *
220
+ * The renderer's entry is searched for under any `packages` key ending in
221
+ * `node_modules/<renderer-name>`, so a nested install
222
+ * (`node_modules/<product>/node_modules/<renderer>`) is read rather than
223
+ * mistaken for an absent record. The installed version is enforced regardless;
224
+ * a found entry's integrity is compared with the pin; a record with no renderer
225
+ * entry anywhere in it (a global install that wrote no npm lockfile) yields
226
+ * `W114_RENDERER_INTEGRITY_UNVERIFIED` and never substitutes the compile-time
227
+ * pin as a verified integrity. A present record that cannot be read, or is
228
+ * above this bound, is refused (F010) instead of warning.
229
+ */
230
+ export const NPM_LOCKFILE_MAX_BYTES = 64 * 1024 * 1024;
231
+ /**
232
+ * A managed file and a source file are bounded for the same reason: a
233
+ * repository-controlled path must never make the process allocate until the JS
234
+ * string limit throws an untyped `Invalid string length`.
235
+ */
236
+ export const MANAGED_FILE_MAX_BYTES = 4 * 1024 * 1024;
237
+ export const SOURCE_MAX_BYTES = 4 * 1024 * 1024;
238
+ /** A staging sibling older than this is swept even when its pid was reused. */
239
+ export const STAGING_MAX_AGE_MS = 60 * 60 * 1000;
240
+ export const ID_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
241
+ export const ID_MAX_LENGTH = 64;
242
+ /**
243
+ * Capabilities a persona resource reference may name in this slice. `model` is
244
+ * absent: a model is expressed with the persona's `model` class, and a
245
+ * `model/<id>` reference is refused rather than accepted and ignored.
246
+ */
247
+ export const SUPPORTED_RESOURCE_KINDS = [
248
+ 'rule',
249
+ 'permission',
250
+ 'mcp',
251
+ 'skill',
252
+ 'command',
253
+ 'hook',
254
+ ];
255
+ /**
256
+ * The capability class of each resource kind. A dropped
257
+ * boundary capability is HIGH and can refuse; a dropped content capability is
258
+ * MEDIUM and can only produce a loss.
259
+ */
260
+ export const BOUNDARY_CAPABILITIES = ['permission', 'hook', 'mcp'];
261
+ /** The resource kinds the OpenCode targets carry only at the workspace level. */
262
+ export const OPENCODE_WORKSPACE_KINDS = ['mcp', 'skill', 'command', 'hook'];
263
+ export const EXIT = {
264
+ ok: 0,
265
+ invalidConfig: 1,
266
+ conflict: 2,
267
+ refused: 3,
268
+ /** `F008_DECLARED_NOT_EMITTED`: the renderer lost or invented declared content. */
269
+ declaredNotEmitted: 4,
270
+ /** `check` reports drift as exit 1. Drift is not an exception, so it has no F-code. */
271
+ drift: 1,
272
+ renderFailed: 5,
273
+ };
274
+ /** The code a drift item carries in a `check` payload. Not an error code. */
275
+ export const DRIFT_CODE = 'F007_DRIFT';
276
+ /**
277
+ * The code a drift item carries when the finding is not a changed byte of ours
278
+ * but content outside our ownership: an unrecorded file in a managed location,
279
+ * or an extra file in a skill tree. `check` fails on it because the path is
280
+ * live, but `generate` never deletes it.
281
+ */
282
+ export const OUTSIDE_OWNERSHIP_CODE = 'W107_OUTSIDE_OWNERSHIP';
283
+ /** Exit code per diagnostic code. The table lives here once. F007 is absent: drift is a result. */
284
+ export const EXIT_BY_CODE = {
285
+ F001_INVALID_CONFIG: EXIT.invalidConfig,
286
+ F002_SECRET_LITERAL: EXIT.invalidConfig,
287
+ F003_PATH_UNSAFE: EXIT.invalidConfig,
288
+ F005_CONFLICT: EXIT.conflict,
289
+ F008_DECLARED_NOT_EMITTED: EXIT.declaredNotEmitted,
290
+ F009_RENDER_FAILED: EXIT.renderFailed,
291
+ F010_RENDERER_MISMATCH: EXIT.renderFailed,
292
+ F011_PERMISSION_UNMAPPED: EXIT.refused,
293
+ F012_WRITE_FAILED: EXIT.renderFailed,
294
+ };
295
+ export const WARNING_CODES = [
296
+ 'W101_CAPABILITY_DROPPED',
297
+ 'W106_DENY_WINS',
298
+ 'W107_OUTSIDE_OWNERSHIP',
299
+ 'W109_PROFILE_BY_CHOICE',
300
+ 'W111_ASK_DOWNGRADED',
301
+ 'W112_PERMISSION_LOSSY',
302
+ 'W113_ALLOW_LIST_NARROWS',
303
+ 'W114_RENDERER_INTEGRITY_UNVERIFIED',
304
+ 'W115_CREDENTIAL_IN_URL',
305
+ 'W116_SECRET_IN_ARGS',
306
+ ];
307
+ /**
308
+ * A warning's default severity is a property of its code.
309
+ * W106 is the only code whose severity depends on what it removes: a deny that
310
+ * takes away an allow is medium, every other stricter-wins report is info.
311
+ *
312
+ * W114 is medium, not high: the renderer's version is still enforced, so a
313
+ * different renderer cannot pass. What is missing is the tarball digest that
314
+ * ties the installed bytes to the published package, which makes this a
315
+ * provenance caveat rather than a correctness failure. It is not info either:
316
+ * a run whose integrity could not be checked must never look like a clean
317
+ * integrity pass. High is reserved for a warning that records a real loss
318
+ * (W112), which this is not.
319
+ *
320
+ * W101's severity is dynamic: `high` for a boundary capability (`permission`,
321
+ * `hook`, `mcp`), `medium` for content (`rule`, `model`, `skill`, `command`).
322
+ * The table value is the content default; every boundary emission passes
323
+ * `high` explicitly so the classification is visible at the call site.
324
+ */
325
+ export const WARNING_SEVERITY = {
326
+ W101_CAPABILITY_DROPPED: 'medium',
327
+ W106_DENY_WINS: 'info',
328
+ W107_OUTSIDE_OWNERSHIP: 'low',
329
+ W109_PROFILE_BY_CHOICE: 'info',
330
+ W111_ASK_DOWNGRADED: 'medium',
331
+ W112_PERMISSION_LOSSY: 'high',
332
+ W113_ALLOW_LIST_NARROWS: 'medium',
333
+ W114_RENDERER_INTEGRITY_UNVERIFIED: 'medium',
334
+ W115_CREDENTIAL_IN_URL: 'high',
335
+ W116_SECRET_IN_ARGS: 'high',
336
+ };
@@ -0,0 +1,44 @@
1
+ import { type DiagnosticCode } from './constants.js';
2
+ export type FarnaErrorOptions = {
3
+ subject?: string;
4
+ action?: string;
5
+ cause?: unknown;
6
+ };
7
+ /**
8
+ * A typed failure. The code selects the exit status; the message is assembled
9
+ * from the record, never by concatenation at a call site.
10
+ */
11
+ export declare class FarnaError extends Error {
12
+ readonly code: DiagnosticCode;
13
+ readonly exitCode: number;
14
+ readonly subject?: string;
15
+ readonly action?: string;
16
+ constructor(code: DiagnosticCode, message: string, options?: FarnaErrorOptions);
17
+ /**
18
+ * The one-line form the text reporter prints. The subject, the message and
19
+ * the action are all escaped: each can embed a source filename, a lockfile
20
+ * path or a foreign key from a hand-edited document, and a raw control
21
+ * character would rewrite the terminal lines the diagnostic appears on.
22
+ */
23
+ format(): string;
24
+ }
25
+ export declare function invalidConfig(message: string, options?: FarnaErrorOptions): FarnaError;
26
+ /**
27
+ * `generate` refuses to overwrite a managed path it cannot prove it owns. The
28
+ * code is F007 (drift, exit 1), never F008: the path is not a renderer loss, it
29
+ * is a file this tool did not write.
30
+ */
31
+ export declare function driftRefused(message: string, options?: FarnaErrorOptions): FarnaError;
32
+ /** A literal value in a credential position. The message never echoes it. */
33
+ export declare function secretLiteral(message: string, options?: FarnaErrorOptions): FarnaError;
34
+ export declare function pathUnsafe(message: string, options?: FarnaErrorOptions): FarnaError;
35
+ export declare function conflict(message: string, options?: FarnaErrorOptions): FarnaError;
36
+ export declare function declaredNotEmitted(message: string, options?: FarnaErrorOptions): FarnaError;
37
+ export declare function renderFailed(message: string, options?: FarnaErrorOptions): FarnaError;
38
+ export declare function rendererMismatch(message: string, options?: FarnaErrorOptions): FarnaError;
39
+ export declare function permissionUnmapped(message: string, options?: FarnaErrorOptions): FarnaError;
40
+ /**
41
+ * The verified managed set could not be written. The tree is left as it was;
42
+ * the subject names the path that could not be staged.
43
+ */
44
+ export declare function writeFailed(message: string, options?: FarnaErrorOptions): FarnaError;