farna-bootstrapper 0.1.2 → 0.1.3
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 +39 -0
- package/README.md +36 -13
- package/dist/compose/resolve.js +1 -1
- package/dist/core/constants.d.ts +2 -2
- package/dist/core/constants.js +2 -2
- package/dist/matrix/snapshot.js +1 -1
- package/dist/permissions/permissions.d.ts +1 -1
- package/dist/permissions/permissions.js +1 -1
- package/dist/render/upstream.js +2 -2
- package/dist/source/load.js +1 -1
- package/dist/verify/containment.js +64 -8
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,44 @@ 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.3] - 2026-11-24
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Self-dogfood.** This repository now generates its own configuration from `.farna/`:
|
|
14
|
+
`.claude/agents/maintainer.md` and `.farna/lock.json` are generated and committed, and CI runs
|
|
15
|
+
`check`, so a source change that was not regenerated, or a generated file edited by hand, fails
|
|
16
|
+
the build. The dogfood covers the `claudecode` target in agent mode only.
|
|
17
|
+
- **A macOS CI job.** CI runs a second job on macOS with every step identical to the Linux job, so
|
|
18
|
+
the same install, build, test, audit and `check` steps are proven on both platforms.
|
|
19
|
+
- **Weekly renderer-pin tracking.** `.github/workflows/renderer-pin.yml` compares the pinned
|
|
20
|
+
renderer with the published npm version once a week, opens one tracking issue when the pin is
|
|
21
|
+
behind, comments on that issue weekly while it stays behind, and closes it when the pin catches
|
|
22
|
+
up. It never bumps anything. A new `## Absorbing a renderer upgrade` runbook in
|
|
23
|
+
[CONTRIBUTING.md](CONTRIBUTING.md#absorbing-a-renderer-upgrade) documents the manual absorb
|
|
24
|
+
procedure.
|
|
25
|
+
- **A roadmap.** [ROADMAP.md](ROADMAP.md) records what is shipped, what is next and what is
|
|
26
|
+
deliberately out of scope, and the README status section links to it.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- **Renderer pin moved to `rulesync` 43.13.0** (from `43.11.0`), absorbed in two explained steps.
|
|
31
|
+
An OpenCode agent file whose description contains a comma now writes it as a plain YAML scalar
|
|
32
|
+
instead of a single-quoted one: the renderer replaced its frontmatter serialiser (`gray-matter`'s
|
|
33
|
+
YAML 1.1 writer) with YAML 1.2, where a comma is plain-safe. The pin also carried the 43.12.0
|
|
34
|
+
change: a `session-start` hook runs with `context: true`, so its stdout is captured as session
|
|
35
|
+
context while its stderr streams to the host, and the plugin's run helper returns its result on
|
|
36
|
+
success. The `claudecode` golden is byte-identical. Because the agent files and the plugin are
|
|
37
|
+
managed output, `check` reports drift on an existing project until the next `generate`.
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
|
|
41
|
+
- **An emitted OpenCode hook matcher now fires.** The generated hooks plugin writes the tool ids the
|
|
42
|
+
harness reports, lowercased and anchored, instead of the canonical names: `Edit|Write` is written
|
|
43
|
+
as `^(?:edit|write)$`, and `Bash` as `^(?:bash)$` on V1 and `^(?:shell)$` on V2. OpenCode reports
|
|
44
|
+
those lowercase ids, so a declared matcher matches a tool call instead of silently never
|
|
45
|
+
matching. The containment gate applies the same translation before comparing.
|
|
46
|
+
|
|
9
47
|
## [0.1.2] - 2026-11-23
|
|
10
48
|
|
|
11
49
|
### Added
|
|
@@ -132,6 +170,7 @@ output still matches the source.
|
|
|
132
170
|
runner does not grant), the POSIX mode assertions, the FIFO cases and the install-layout suite are
|
|
133
171
|
skipped on Windows; CI runs them on Linux.
|
|
134
172
|
|
|
173
|
+
[0.1.3]: https://github.com/farnalabs/farna-bootstrapper/compare/v0.1.2...v0.1.3
|
|
135
174
|
[0.1.2]: https://github.com/farnalabs/farna-bootstrapper/releases/tag/v0.1.2
|
|
136
175
|
[0.1.1]: https://github.com/farnalabs/farna-bootstrapper/releases/tag/v0.1.1
|
|
137
176
|
[0.1.0]: https://github.com/farnalabs/farna-bootstrapper/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -58,6 +58,7 @@ composed persona. Exactly one configured target is rendered per run. Everything
|
|
|
58
58
|
deliberately deferred; see
|
|
59
59
|
[What this slice does not do](#what-this-slice-does-not-do) and
|
|
60
60
|
[Residual risks and known gaps](#residual-risks-and-known-gaps).
|
|
61
|
+
See [ROADMAP.md](ROADMAP.md) for what is shipped, what is next and what is deliberately out of scope.
|
|
61
62
|
|
|
62
63
|
## Quickstart
|
|
63
64
|
|
|
@@ -441,7 +442,7 @@ severity names the widening, and a declaration is never silently weakened. A bar
|
|
|
441
442
|
inert rule; the bare `mcp` category on OpenCode is recorded as **not measured** and is never claimed
|
|
442
443
|
as carried.
|
|
443
444
|
|
|
444
|
-
The OpenCode V1 columns record these differences from V2, each verified against rulesync 43.
|
|
445
|
+
The OpenCode V1 columns record these differences from V2, each verified against rulesync 43.13.0
|
|
445
446
|
output in this repository's golden tests:
|
|
446
447
|
|
|
447
448
|
- **Agent frontmatter** — V1 keeps `name` and writes the per-tool `permission` map; V2 drops `name`
|
|
@@ -635,7 +636,7 @@ that *looks like a credential* (`sk-`, `ghp_`, `glpat-`, `npm_`, `AKIA`, a JWT,
|
|
|
635
636
|
string with letters and digits) is reported as `W116_SECRET_IN_ARGS` at high severity, naming the
|
|
636
637
|
argument's position and never echoing the value: it would otherwise be written verbatim into
|
|
637
638
|
`opencode.jsonc`. A `{ "fromEnv": "NAME" }` reference inside `args` cannot be expressed — rulesync
|
|
638
|
-
43.
|
|
639
|
+
43.13.0 accepts only string arguments and copies them into the emitted command verbatim, so the
|
|
639
640
|
reference would reach the server as the unexpanded text `${NAME}` — and is refused (F001) with the
|
|
640
641
|
supported alternative: put the credential in `env` or `headers`.
|
|
641
642
|
|
|
@@ -850,7 +851,7 @@ The generated bytes are the product, so they must not depend on where or when th
|
|
|
850
851
|
- **Ordering is canonical.** Personas and resources are sorted by kind and codepoint id before
|
|
851
852
|
hashing or writing. Permission records are the one deliberate exception: they keep source order
|
|
852
853
|
because OpenCode is last-match-wins, so the digest is order-sensitive there too.
|
|
853
|
-
- **The renderer is pinned.** `rulesync` is pinned to exactly `43.
|
|
854
|
+
- **The renderer is pinned.** `rulesync` is pinned to exactly `43.13.0` with a tarball integrity (see
|
|
854
855
|
[The renderer boundary](#the-renderer-boundary)). The lockfile records the pin, not the integrity
|
|
855
856
|
the local package manager happened to write, so two machines that both verified their install -
|
|
856
857
|
and one that could not verify its own - produce the same lockfile bytes for the same source.
|
|
@@ -864,7 +865,7 @@ The generated bytes are the product, so they must not depend on where or when th
|
|
|
864
865
|
|
|
865
866
|
The repository's own suites include golden byte comparisons and a two-root determinism test. Two
|
|
866
867
|
clean runs of the same source on one machine produce identical bytes and an identical lockfile;
|
|
867
|
-
cross-machine determinism follows from the same rules, and CI runs on Linux.
|
|
868
|
+
cross-machine determinism follows from the same rules, and CI runs on Linux and macOS.
|
|
868
869
|
|
|
869
870
|
## The renderer boundary
|
|
870
871
|
|
|
@@ -873,7 +874,7 @@ imports `rulesync`, and `src/cli/main.ts` is the only place that binds the real
|
|
|
873
874
|
Unit tests use an independent fake renderer, so the failure modes the port exists to catch can be
|
|
874
875
|
exercised without the network or the real renderer.
|
|
875
876
|
|
|
876
|
-
`rulesync` is pinned to exactly `43.
|
|
877
|
+
`rulesync` is pinned to exactly `43.13.0` with a tarball integrity. The lockfile records that pin,
|
|
877
878
|
and `check` compares it with the installed package before any byte comparison. The renderer
|
|
878
879
|
identity policy has three parts:
|
|
879
880
|
|
|
@@ -1051,8 +1052,8 @@ These are deliberate limits of the current controls, stated rather than implied
|
|
|
1051
1052
|
regression suites (creating a symbolic link needs a privilege the runner does not grant), the
|
|
1052
1053
|
POSIX file- and directory-mode assertions (mode bits are not meaningful on NTFS), the FIFO cases
|
|
1053
1054
|
(Windows has no `mkfifo`-equivalent endpoint to create one), and the install-layout suite (its
|
|
1054
|
-
fixtures model a hoisted or nested install with symlinks). CI runs all of them on Linux
|
|
1055
|
-
guard code itself is platform-independent.
|
|
1055
|
+
fixtures model a hoisted or nested install with symlinks). CI runs all of them on Linux and
|
|
1056
|
+
macOS; the guard code itself is platform-independent.
|
|
1056
1057
|
- **Unrecorded files are not drift.** With a lockfile present, `check` compares the paths in the
|
|
1057
1058
|
fresh plan (missing or changed) and the paths the committed lockfile records (an output the source
|
|
1058
1059
|
no longer produces). A file the user keeps in a managed directory is not this tool's output, so it
|
|
@@ -1066,12 +1067,14 @@ These are deliberate limits of the current controls, stated rather than implied
|
|
|
1066
1067
|
escaping in the inverse order before comparing, because it is the renderer's representation of the
|
|
1067
1068
|
same command. Each command's matcher is read from the slice between the previous command and this
|
|
1068
1069
|
one, so a matcher-less hook cannot inherit a neighbour's guard and a dropped matcher cannot be
|
|
1069
|
-
replaced by an earlier identical one.
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1070
|
+
replaced by an earlier identical one. rulesync translates a canonical tool name in a matcher to the
|
|
1071
|
+
target's lowercase id and anchors a pure name list (`Edit|Write` becomes `^(?:edit|write)$`), so the
|
|
1072
|
+
gate applies the same translation before comparing. The parser matches rulesync 43.13.0's two
|
|
1073
|
+
registration shapes and cannot recognise a registration emitted as a template literal under a
|
|
1074
|
+
future renderer, so a plugin that keeps the same commands but changes its registration shape is
|
|
1075
|
+
caught only by `check` against a fresh render of the pinned renderer. A change to rulesync's
|
|
1076
|
+
generated helper code that keeps the same registrations is likewise caught only by `check`, not by
|
|
1077
|
+
a committed plugin golden.
|
|
1075
1078
|
- **Skill extra files must be UTF-8.** The managed-output pipeline compares and writes text, so a
|
|
1076
1079
|
binary asset inside a skill directory is refused (F001) rather than carried; decoding and
|
|
1077
1080
|
re-encoding a valid UTF-8 file is byte-identical.
|
|
@@ -1116,6 +1119,7 @@ npm run lint
|
|
|
1116
1119
|
npm run typecheck
|
|
1117
1120
|
npm test
|
|
1118
1121
|
npm run build
|
|
1122
|
+
node dist/cli/main.js check # the committed agent config matches .farna/
|
|
1119
1123
|
npm audit --audit-level=moderate
|
|
1120
1124
|
node scripts/assert-pack.mjs # the tarball is dist/ plus the legal files, with no source map
|
|
1121
1125
|
npm pack --dry-run # the exact package npm would publish
|
|
@@ -1143,6 +1147,25 @@ tag is on `main`, runs the gates, publishes the packed tarball to npm with prove
|
|
|
1143
1147
|
the GitHub Release. The publish job waits for approval on the `release` environment, whose
|
|
1144
1148
|
`NPM_TOKEN` secret carries the npm token. See [Releasing](CONTRIBUTING.md#releasing).
|
|
1145
1149
|
|
|
1150
|
+
## This repository dogfoods itself
|
|
1151
|
+
|
|
1152
|
+
The source of this repository's own agent configuration is `.farna/`: one persona, `maintainer`,
|
|
1153
|
+
built from a rule distilled from [CONTRIBUTING.md](CONTRIBUTING.md) and a permission resource.
|
|
1154
|
+
`generate` renders it to a committed `.claude/agents/maintainer.md` and records the manifest in
|
|
1155
|
+
`.farna/lock.json`.
|
|
1156
|
+
|
|
1157
|
+
```sh
|
|
1158
|
+
node dist/cli/main.js generate # after any change under .farna/
|
|
1159
|
+
node dist/cli/main.js check # re-render and compare; drift exits 1
|
|
1160
|
+
```
|
|
1161
|
+
|
|
1162
|
+
`check` runs in CI, so a change to `.farna/` that was not regenerated, or a hand-edited generated
|
|
1163
|
+
file, fails the build rather than merging quietly.
|
|
1164
|
+
|
|
1165
|
+
This is the `claudecode` target in agent mode, and nothing else. This release renders exactly one
|
|
1166
|
+
configured target per run and Claude Code has no profile mode, so the OpenCode half of the dogfood
|
|
1167
|
+
waits on multi-target rendering; it is not represented here today.
|
|
1168
|
+
|
|
1146
1169
|
## Licence
|
|
1147
1170
|
|
|
1148
1171
|
MIT, Copyright (c) 2026 Farnalabs Ltd. See `LICENSE` and `NOTICE`. Security reports are handled
|
package/dist/compose/resolve.js
CHANGED
|
@@ -180,7 +180,7 @@ function sortResources(resources) {
|
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
182
182
|
* Why OpenCode cannot carry this hook, or `undefined` when it can. Measured at
|
|
183
|
-
* rulesync 43.
|
|
183
|
+
* rulesync 43.13.0: `session-end` has no OpenCode event, and a matcher is
|
|
184
184
|
* honoured only on the tool events (`preToolUse`/`postToolUse`).
|
|
185
185
|
*/
|
|
186
186
|
function hookProblem(hook) {
|
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.3";
|
|
9
9
|
/** The one source/schema version this build understands. */
|
|
10
10
|
export declare const SCHEMA_VERSION: 1;
|
|
11
11
|
/**
|
|
@@ -126,7 +126,7 @@ export declare const CLAUDE_AGENTS_DIR = ".claude/agents";
|
|
|
126
126
|
/**
|
|
127
127
|
* The OpenCode paths this slice writes, relative to the repository root.
|
|
128
128
|
* `commands` is plural and the workspace config is `opencode.jsonc`, both
|
|
129
|
-
* measured at rulesync 43.
|
|
129
|
+
* measured at rulesync 43.13.0.
|
|
130
130
|
*/
|
|
131
131
|
export declare const OPENCODE_DIR = ".opencode";
|
|
132
132
|
export declare const OPENCODE_AGENTS_DIR = ".opencode/agents";
|
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.3';
|
|
9
9
|
/** The one source/schema version this build understands. */
|
|
10
10
|
export const SCHEMA_VERSION = 1;
|
|
11
11
|
/**
|
|
@@ -125,7 +125,7 @@ export const CLAUDE_AGENTS_DIR = `${CLAUDE_DIR}/agents`;
|
|
|
125
125
|
/**
|
|
126
126
|
* The OpenCode paths this slice writes, relative to the repository root.
|
|
127
127
|
* `commands` is plural and the workspace config is `opencode.jsonc`, both
|
|
128
|
-
* measured at rulesync 43.
|
|
128
|
+
* measured at rulesync 43.13.0.
|
|
129
129
|
*/
|
|
130
130
|
export const OPENCODE_DIR = '.opencode';
|
|
131
131
|
export const OPENCODE_AGENTS_DIR = `${OPENCODE_DIR}/agents`;
|
package/dist/matrix/snapshot.js
CHANGED
|
@@ -139,7 +139,7 @@ function opencodeCells(target, testId, workspaceTestId) {
|
|
|
139
139
|
*/
|
|
140
140
|
export const SNAPSHOT = {
|
|
141
141
|
schemaVersion: 1,
|
|
142
|
-
renderer: { name: 'rulesync', version: '43.
|
|
142
|
+
renderer: { name: 'rulesync', version: '43.13.0' },
|
|
143
143
|
targets: [
|
|
144
144
|
{
|
|
145
145
|
id: DEFAULT_TARGET,
|
|
@@ -99,7 +99,7 @@ export type OpencodePermissionMapping = {
|
|
|
99
99
|
};
|
|
100
100
|
/**
|
|
101
101
|
* Map a persona's resolved permission map onto OpenCode's ordered permission
|
|
102
|
-
* records. Measured at rulesync 43.
|
|
102
|
+
* records. Measured at rulesync 43.13.0: `bash` becomes `shell`, `task` becomes
|
|
103
103
|
* `subagent`, and `write` folds into `edit` (there is no write category). The
|
|
104
104
|
* fold is reported as W112 when a write-derived allow is emitted without a
|
|
105
105
|
* matching edit declaration. `ask` becomes deny (W111).
|
|
@@ -277,7 +277,7 @@ function stricterWinner(a, b) {
|
|
|
277
277
|
}
|
|
278
278
|
/**
|
|
279
279
|
* Map a persona's resolved permission map onto OpenCode's ordered permission
|
|
280
|
-
* records. Measured at rulesync 43.
|
|
280
|
+
* records. Measured at rulesync 43.13.0: `bash` becomes `shell`, `task` becomes
|
|
281
281
|
* `subagent`, and `write` folds into `edit` (there is no write category). The
|
|
282
282
|
* fold is reported as W112 when a write-derived allow is emitted without a
|
|
283
283
|
* matching edit declaration. `ask` becomes deny (W111).
|
package/dist/render/upstream.js
CHANGED
|
@@ -26,8 +26,8 @@ import { installedRendererIdentity, integrityRecordOf } from './identity.js';
|
|
|
26
26
|
*/
|
|
27
27
|
export const RENDERER_PIN = {
|
|
28
28
|
name: 'rulesync',
|
|
29
|
-
version: '43.
|
|
30
|
-
integrity: 'sha512-
|
|
29
|
+
version: '43.13.0',
|
|
30
|
+
integrity: 'sha512-fGOfX/kbs089e2nPDNZtf/nY/eNKIgM8n5Mer6f+A2ZQlxjVTjBHS60O847aCV/kZIwHHUIXASgh6aRv3VlR9w==',
|
|
31
31
|
};
|
|
32
32
|
let loaded;
|
|
33
33
|
async function loadRenderer() {
|
package/dist/source/load.js
CHANGED
|
@@ -521,7 +521,7 @@ export function looksSecretShaped(value) {
|
|
|
521
521
|
/[A-Za-z]/.test(value));
|
|
522
522
|
}
|
|
523
523
|
/**
|
|
524
|
-
* A `{ fromEnv }` reference inside `args` cannot be expressed: rulesync 43.
|
|
524
|
+
* A `{ fromEnv }` reference inside `args` cannot be expressed: rulesync 43.13.0
|
|
525
525
|
* accepts only string arguments and copies them into the emitted command
|
|
526
526
|
* verbatim, so a reference would reach the server as the literal text `${NAME}`
|
|
527
527
|
* and silently not expand. Refusing is the honest outcome; `env` and `headers`
|
|
@@ -206,7 +206,7 @@ function permissionRecords(value) {
|
|
|
206
206
|
return records;
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
|
-
* The V2 (`opencode`) per-agent file. Measured at rulesync 43.
|
|
209
|
+
* The V2 (`opencode`) per-agent file. Measured at rulesync 43.13.0: the
|
|
210
210
|
* frontmatter is `description`, `mode`, `model` (when declared) and
|
|
211
211
|
* `permissions` (when the persona declares one), with no `name` key — OpenCode
|
|
212
212
|
* 2.x names the agent from the file, and a stray V1 field would make the file
|
|
@@ -240,7 +240,7 @@ function verifyOpencodeV2Agent(persona, source, parsed, managedPath) {
|
|
|
240
240
|
verifyBody(persona, source, parsed.body, managedPath);
|
|
241
241
|
}
|
|
242
242
|
/**
|
|
243
|
-
* The V1 (`opencodev1`) per-agent file. Measured at rulesync 43.
|
|
243
|
+
* The V1 (`opencodev1`) per-agent file. Measured at rulesync 43.13.0: the
|
|
244
244
|
* frontmatter is `name`, `description`, `mode`, `model` (when declared) and the
|
|
245
245
|
* per-tool `permission` map (when the persona declares one). `temperature` and
|
|
246
246
|
* `tools` are V1 keys this product does not author, so they must never appear;
|
|
@@ -428,7 +428,7 @@ const HOOK_EVENT_BY_PHASE = {
|
|
|
428
428
|
};
|
|
429
429
|
/**
|
|
430
430
|
* The V2 (`opencode`) plugin's registration anchors, measured at rulesync
|
|
431
|
-
* 43.
|
|
431
|
+
* 43.13.0: a tool hook (`ctx.tool.hook("execute.before"|"execute.after", ...)`)
|
|
432
432
|
* and an event hook whose `label: "<event>"` has no tool anchor.
|
|
433
433
|
*/
|
|
434
434
|
const OPENCODE_V2_HOOK_ANCHORS = [
|
|
@@ -442,7 +442,7 @@ const OPENCODE_V2_HOOK_ANCHORS = [
|
|
|
442
442
|
];
|
|
443
443
|
/**
|
|
444
444
|
* The V1 (`opencodev1`) `RulesyncHooksPlugin` registration anchors, measured at
|
|
445
|
-
* rulesync 43.
|
|
445
|
+
* rulesync 43.13.0: the returned object keys `"tool.execute.before"` and
|
|
446
446
|
* `"tool.execute.after"`, and the event-loop branches
|
|
447
447
|
* `event.type === "session.created"` / `event.type === "session.idle"`. The
|
|
448
448
|
* V1 plugin also carries `label: "sessionStart"|"stop"|"postToolUse"` inside
|
|
@@ -459,6 +459,60 @@ const OPENCODE_V1_HOOK_ANCHORS = [
|
|
|
459
459
|
},
|
|
460
460
|
{ pattern: /event\.type === "session\.idle"/g, event: () => 'stop', registration: true },
|
|
461
461
|
];
|
|
462
|
+
/**
|
|
463
|
+
* The canonical (Claude Code) tool names rulesync rewrites inside a hook
|
|
464
|
+
* matcher, and the id each OpenCode target reports at run time. Measured at
|
|
465
|
+
* rulesync 43.13.0: OpenCode 1.x reports `read`/`write`/`edit` and calls its
|
|
466
|
+
* shell tool `bash`, while OpenCode 2.x calls the same tool `shell`.
|
|
467
|
+
*/
|
|
468
|
+
const OPENCODE_V1_HOOK_TOOL_NAMES = {
|
|
469
|
+
Bash: 'bash',
|
|
470
|
+
Read: 'read',
|
|
471
|
+
Write: 'write',
|
|
472
|
+
Edit: 'edit',
|
|
473
|
+
};
|
|
474
|
+
const OPENCODE_V2_HOOK_TOOL_NAMES = {
|
|
475
|
+
Bash: 'shell',
|
|
476
|
+
Read: 'read',
|
|
477
|
+
Write: 'write',
|
|
478
|
+
Edit: 'edit',
|
|
479
|
+
};
|
|
480
|
+
/** The tool-name map for one OpenCode major (see the two tables above). */
|
|
481
|
+
function opencodeHookToolNames(target) {
|
|
482
|
+
return target === 'opencodev1' ? OPENCODE_V1_HOOK_TOOL_NAMES : OPENCODE_V2_HOOK_TOOL_NAMES;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* rulesync's whole-name tokenisation of a matcher, measured at 43.13.0: escapes
|
|
486
|
+
* and character classes are skipped, and a name is only a name at a word
|
|
487
|
+
* boundary (or after an escaped word character).
|
|
488
|
+
*/
|
|
489
|
+
const MATCHER_TOKEN_PATTERN = /\\.|\[(?:\\.|[^\]\\])*\]|(?<=^|[^\w\\]|\\\w)[A-Za-z_]\w*(?!\w)/gs;
|
|
490
|
+
/** A token that is a whole name, not an escape or a character class. */
|
|
491
|
+
function isMatcherName(token) {
|
|
492
|
+
return !token.startsWith('\\') && !token.startsWith('[');
|
|
493
|
+
}
|
|
494
|
+
/** Rewrite the whole tool names in a matcher, leaving escapes and classes as written. */
|
|
495
|
+
function replaceMatcherNames(matcher, names) {
|
|
496
|
+
return matcher.replace(MATCHER_TOKEN_PATTERN, (token) => isMatcherName(token) && Object.hasOwn(names, token) ? (names[token] ?? token) : token);
|
|
497
|
+
}
|
|
498
|
+
/** A matcher made only of plain names joined by `|`, which Claude Code matches as an exact list. */
|
|
499
|
+
const PLAIN_TOOL_NAME_MATCHER = /^[A-Za-z0-9_]+(?:\|[A-Za-z0-9_]+)*$/;
|
|
500
|
+
/**
|
|
501
|
+
* The matcher rulesync emits for a declared one, measured at 43.13.0. Canonical
|
|
502
|
+
* tool names are translated to the target's ids, and a pure name-list matcher
|
|
503
|
+
* is anchored as `^(?:...)$` so `write` does not also match `todowrite`; a
|
|
504
|
+
* regex-style matcher, or one with no translated name, is written as declared.
|
|
505
|
+
* The source schema refuses newline, carriage return and NUL in a matcher, so
|
|
506
|
+
* the control-character strip rulesync applies to the emitted literal is a
|
|
507
|
+
* no-op here.
|
|
508
|
+
*/
|
|
509
|
+
function emittedHookMatcher(matcher, target) {
|
|
510
|
+
const translated = replaceMatcherNames(matcher, opencodeHookToolNames(target));
|
|
511
|
+
if (translated !== matcher && PLAIN_TOOL_NAME_MATCHER.test(matcher)) {
|
|
512
|
+
return `^(?:${translated})$`;
|
|
513
|
+
}
|
|
514
|
+
return translated;
|
|
515
|
+
}
|
|
462
516
|
/**
|
|
463
517
|
* The hooks plugin is generated JavaScript, so it is verified at the level that
|
|
464
518
|
* matters: exactly the declared commands, each bound to its declared event and
|
|
@@ -471,7 +525,9 @@ const OPENCODE_V1_HOOK_ANCHORS = [
|
|
|
471
525
|
* registration. The anchor set is the only thing that differs between the two
|
|
472
526
|
* OpenCode majors: V2 registers through `ctx.tool.hook(...)` and a label-only
|
|
473
527
|
* event loop, V1 through the returned `"tool.execute.*"` keys and
|
|
474
|
-
* `event.type === ...` branches.
|
|
528
|
+
* `event.type === ...` branches. The declared matcher is translated the way the
|
|
529
|
+
* renderer translates it (`emittedHookMatcher`) before it is compared, so a
|
|
530
|
+
* target-name rewrite is not mistaken for a dropped or invented matcher.
|
|
475
531
|
*
|
|
476
532
|
* An `after-tool` command in V2 is emitted inside `ctx.tool.hook("execute.after",
|
|
477
533
|
* ...)` *and* carries `label: "postToolUse"` in the same `__rulesyncRunHook(...)`
|
|
@@ -480,7 +536,7 @@ const OPENCODE_V1_HOOK_ANCHORS = [
|
|
|
480
536
|
* previous command's end, so a matcher-less hook cannot inherit its neighbour's
|
|
481
537
|
* guard.
|
|
482
538
|
*/
|
|
483
|
-
function verifyHookPlugin(source, text, subject, anchorPatterns) {
|
|
539
|
+
function verifyHookPlugin(source, text, subject, target, anchorPatterns) {
|
|
484
540
|
const anchors = [];
|
|
485
541
|
for (const { pattern, event, registration } of anchorPatterns) {
|
|
486
542
|
for (const match of text.matchAll(pattern)) {
|
|
@@ -570,7 +626,7 @@ function verifyHookPlugin(source, text, subject, anchorPatterns) {
|
|
|
570
626
|
.map((hook) => ({
|
|
571
627
|
event: HOOK_EVENT_BY_PHASE[hook.phase] ?? '',
|
|
572
628
|
command: hook.command,
|
|
573
|
-
...(hook.matcher === undefined ? {} : { matcher: hook.matcher }),
|
|
629
|
+
...(hook.matcher === undefined ? {} : { matcher: emittedHookMatcher(hook.matcher, target) }),
|
|
574
630
|
}))
|
|
575
631
|
.sort((a, b) => compareCodepoints(`${a.event}\0${a.command}`, `${b.event}\0${b.command}`));
|
|
576
632
|
registrations.sort((a, b) => compareCodepoints(`${a.event}\0${a.command}`, `${b.event}\0${b.command}`));
|
|
@@ -647,7 +703,7 @@ async function verifyOpencodeWorkspace(source, outputRoot, target) {
|
|
|
647
703
|
if (text.length === 0) {
|
|
648
704
|
throw declaredNotEmitted('hooks plugin is empty', { subject: OPENCODE_HOOKS_PLUGIN });
|
|
649
705
|
}
|
|
650
|
-
verifyHookPlugin(source, text, OPENCODE_HOOKS_PLUGIN, target === 'opencodev1' ? OPENCODE_V1_HOOK_ANCHORS : OPENCODE_V2_HOOK_ANCHORS);
|
|
706
|
+
verifyHookPlugin(source, text, OPENCODE_HOOKS_PLUGIN, target, target === 'opencodev1' ? OPENCODE_V1_HOOK_ANCHORS : OPENCODE_V2_HOOK_ANCHORS);
|
|
651
707
|
verified.set(OPENCODE_HOOKS_PLUGIN, text);
|
|
652
708
|
}
|
|
653
709
|
return verified;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "farna-bootstrapper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Compile named agent personas and resources into the configuration each coding harness reads, and prove that the output still matches the source.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farnalabs Ltd",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"commander": "14.0.1",
|
|
70
70
|
"jsonc-parser": "3.3.1",
|
|
71
|
-
"rulesync": "43.
|
|
71
|
+
"rulesync": "43.13.0",
|
|
72
72
|
"yaml": "2.9.1",
|
|
73
73
|
"zod": "4.6.7"
|
|
74
74
|
},
|