rulesync 43.12.0 → 43.13.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.
- package/dist/cli/index.cjs +3 -3
- package/dist/cli/index.js +3 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/{import-Ctgal4jT.js → import-9NB0tQm3.js} +343 -142
- package/dist/{import-Ctgal4jT.js.map → import-9NB0tQm3.js.map} +1 -1
- package/dist/{import-Bp-dK2hr.cjs → import-Djgg1Lrf.cjs} +341 -141
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +14 -14
|
@@ -9,8 +9,8 @@ import { intersection, kebabCase, uniq } from "es-toolkit";
|
|
|
9
9
|
import { globbySync, isGitIgnoredSync } from "globby";
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
import { format, isDeepStrictEqual } from "node:util";
|
|
12
|
-
import matter from "gray-matter";
|
|
13
12
|
import { CORE_SCHEMA, DUMP_SCHEMA, YAMLException, defineScalarTag, dump, load } from "js-yaml";
|
|
13
|
+
import { dump as dump$1, load as load$1 } from "js-yaml-v4";
|
|
14
14
|
import { omit } from "es-toolkit/object";
|
|
15
15
|
import { createHash } from "node:crypto";
|
|
16
16
|
import { encode } from "@toon-format/toon";
|
|
@@ -1807,6 +1807,32 @@ async function relativeWriteLanding({ rootPath, targetPath }) {
|
|
|
1807
1807
|
return relative(rootLanding, targetLanding);
|
|
1808
1808
|
}
|
|
1809
1809
|
/**
|
|
1810
|
+
* The first symbolic link on the way from `rootPath` down to `targetPath`, or
|
|
1811
|
+
* `null` when no existing entry below the root is a link. Only the segments
|
|
1812
|
+
* below the root are looked at, so a root that is itself a link (macOS
|
|
1813
|
+
* `/tmp -> /private/tmp`, a linked home directory) does not count; nor does a
|
|
1814
|
+
* target that is not spelled below the root. Once a segment is missing,
|
|
1815
|
+
* nothing below it exists, so the walk stops there.
|
|
1816
|
+
*/
|
|
1817
|
+
async function firstLinkBelowRoot({ rootPath, targetPath }) {
|
|
1818
|
+
const relativeTarget = relative(resolve(rootPath), resolve(targetPath));
|
|
1819
|
+
if (relativeTarget === "" || pathEscapesRoot(relativeTarget)) return null;
|
|
1820
|
+
let current = resolve(rootPath);
|
|
1821
|
+
for (const segment of splitPathSegments(relativeTarget)) {
|
|
1822
|
+
if (segment === "") continue;
|
|
1823
|
+
current = join(current, segment);
|
|
1824
|
+
let stats;
|
|
1825
|
+
try {
|
|
1826
|
+
stats = await lstat(current);
|
|
1827
|
+
} catch (error) {
|
|
1828
|
+
if (isFileNotFoundError(error) || isNotADirectoryError(error)) return null;
|
|
1829
|
+
throw error;
|
|
1830
|
+
}
|
|
1831
|
+
if (stats.isSymbolicLink()) return current;
|
|
1832
|
+
}
|
|
1833
|
+
return null;
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1810
1836
|
* Directory names that hold version-control metadata. Bytes landing in one of
|
|
1811
1837
|
* them change how the VCS behaves rather than what it tracks: `.git/config`
|
|
1812
1838
|
* can set `core.fsmonitor`, `.git/hooks/*` run on the next commit.
|
|
@@ -4463,37 +4489,6 @@ function toStringArray$1(value) {
|
|
|
4463
4489
|
function toRecord(value) {
|
|
4464
4490
|
return isRecord(value) ? value : {};
|
|
4465
4491
|
}
|
|
4466
|
-
// src/utils/yaml.ts
|
|
4467
|
-
/**
|
|
4468
|
-
* js-yaml v5's `reason` for an empty document. `load("")` — and any
|
|
4469
|
-
* whitespace/comment-only input — throws a `YAMLException` with this reason
|
|
4470
|
-
* instead of returning `undefined` the way v4 did.
|
|
4471
|
-
*/
|
|
4472
|
-
const EMPTY_INPUT_REASON = "expected a document, but the input is empty";
|
|
4473
|
-
/**
|
|
4474
|
-
* Load YAML content while preserving js-yaml v4's behavior of returning
|
|
4475
|
-
* `undefined` for empty documents (empty, whitespace-only, or comment-only
|
|
4476
|
-
* input).
|
|
4477
|
-
*
|
|
4478
|
-
* js-yaml v5 changed `load("")` to **throw** ("expected a document, but the
|
|
4479
|
-
* input is empty") instead of returning `undefined`. Many call sites here parse
|
|
4480
|
-
* config/lock/frontmatter files that can legitimately be empty and rely on the
|
|
4481
|
-
* old `undefined` sentinel (`load(input) ?? {}`, `if (loaded === undefined)`,
|
|
4482
|
-
* "an empty file parses to undefined/null"). Routing every load through this
|
|
4483
|
-
* wrapper keeps that contract in one place so a future js-yaml bump cannot
|
|
4484
|
-
* reintroduce the empty-input regression. Genuine parse errors still propagate.
|
|
4485
|
-
*
|
|
4486
|
-
* @see https://github.com/nodeca/js-yaml/blob/master/docs/migrate_v4_to_v5.md#empty-input-throws
|
|
4487
|
-
*/
|
|
4488
|
-
function loadYaml(content, options) {
|
|
4489
|
-
if (content.trim() === "") return;
|
|
4490
|
-
try {
|
|
4491
|
-
return load(content, options);
|
|
4492
|
-
} catch (error) {
|
|
4493
|
-
if (error instanceof YAMLException && error.reason === EMPTY_INPUT_REASON) return;
|
|
4494
|
-
throw error;
|
|
4495
|
-
}
|
|
4496
|
-
}
|
|
4497
4492
|
// src/utils/frontmatter.ts
|
|
4498
4493
|
/**
|
|
4499
4494
|
* Upper bound on the number of values a frontmatter document may expand to
|
|
@@ -4525,10 +4520,10 @@ const MAX_FRONTMATTER_STRING_CHARS = 4e6;
|
|
|
4525
4520
|
* block itself, checked before it is ever handed to the YAML parser.
|
|
4526
4521
|
*
|
|
4527
4522
|
* The budgets above only bound the *parsed* document — the walk over
|
|
4528
|
-
*
|
|
4523
|
+
* the parser's output — but a complex YAML key (an array or mapping used as a
|
|
4529
4524
|
* mapping key) is joined into a string by js-yaml while it parses, and a
|
|
4530
4525
|
* mapping with many such keys can cost real memory before that walk ever
|
|
4531
|
-
* starts, or even before
|
|
4526
|
+
* starts, or even before the parser returns. Capping the raw block size keeps
|
|
4532
4527
|
* that parse-time cost bounded regardless of what the block contains. Real
|
|
4533
4528
|
* frontmatter blocks are a few hundred bytes at most; even a large project
|
|
4534
4529
|
* manifest stays well under this.
|
|
@@ -4550,8 +4545,8 @@ function estimateLeafChars(value) {
|
|
|
4550
4545
|
/**
|
|
4551
4546
|
* Copy one parsed value, dropping nullish leaves and cyclic references.
|
|
4552
4547
|
*
|
|
4553
|
-
* Every alias is still written out as an independent copy, as
|
|
4554
|
-
*
|
|
4548
|
+
* Every alias is still written out as an independent copy, as js-yaml's
|
|
4549
|
+
* dumper would otherwise serialize shared references as `&ref_0`
|
|
4555
4550
|
* anchors that simplified frontmatter parsers cannot read; the expansion is
|
|
4556
4551
|
* bounded by {@link MAX_FRONTMATTER_VALUES} instead.
|
|
4557
4552
|
*/
|
|
@@ -4627,63 +4622,27 @@ function deepFlattenStringsObject(obj) {
|
|
|
4627
4622
|
function stringifyFrontmatter(body, frontmatter, options) {
|
|
4628
4623
|
const { avoidBlockScalars = false } = options ?? {};
|
|
4629
4624
|
const cleanFrontmatter = avoidBlockScalars ? deepFlattenStringsObject(frontmatter) : deepRemoveNullishObject(frontmatter);
|
|
4630
|
-
const
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
}
|
|
4637
|
-
/**
|
|
4638
|
-
* Thrown in place of gray-matter's built-in JavaScript engine.
|
|
4639
|
-
*
|
|
4640
|
-
* gray-matter picks the parser from the text after the opening fence, so a
|
|
4641
|
-
* file that opens with `---js` or `---javascript` has its frontmatter handed
|
|
4642
|
-
* to `eval()`. Frontmatter here comes from third-party skills, fetched sources
|
|
4643
|
-
* and untrusted repositories, so that would run arbitrary code on the machine
|
|
4644
|
-
* of whoever generates or imports it. Every engine name that resolves to code
|
|
4645
|
-
* execution is mapped to this refusal; {@link assertYamlFrontmatterLanguage}
|
|
4646
|
-
* refuses those fences earlier still, so this is the second line of defense.
|
|
4647
|
-
*/
|
|
4648
|
-
function refuseExecutableFrontmatter() {
|
|
4649
|
-
throw new Error("Frontmatter written in an executable language (JavaScript / CoffeeScript) is not supported; use YAML");
|
|
4650
|
-
}
|
|
4651
|
-
const REFUSED_FRONTMATTER_ENGINE = {
|
|
4652
|
-
parse: refuseExecutableFrontmatter,
|
|
4653
|
-
stringify: refuseExecutableFrontmatter
|
|
4654
|
-
};
|
|
4655
|
-
/**
|
|
4656
|
-
* Engines passed to every gray-matter parse. Supplying them merges over
|
|
4657
|
-
* gray-matter's defaults, so the JavaScript engine (and the CoffeeScript names
|
|
4658
|
-
* a plugin could register) can never be reached through an alias.
|
|
4659
|
-
*
|
|
4660
|
-
* `patches/gray-matter@4.0.3.patch` also deletes the JavaScript engine, but a
|
|
4661
|
-
* pnpm patch only applies inside this repository: gray-matter is an external
|
|
4662
|
-
* dependency of the published package, so an installed rulesync runs the
|
|
4663
|
-
* unpatched gray-matter, and this override plus the language check are what
|
|
4664
|
-
* protect it. Exported for the test that pins that.
|
|
4665
|
-
*/
|
|
4666
|
-
const FRONTMATTER_PARSE_OPTIONS = { engines: {
|
|
4667
|
-
javascript: REFUSED_FRONTMATTER_ENGINE,
|
|
4668
|
-
js: REFUSED_FRONTMATTER_ENGINE,
|
|
4669
|
-
coffee: REFUSED_FRONTMATTER_ENGINE,
|
|
4670
|
-
coffeescript: REFUSED_FRONTMATTER_ENGINE,
|
|
4671
|
-
cson: REFUSED_FRONTMATTER_ENGINE
|
|
4672
|
-
} };
|
|
4625
|
+
const yaml = (avoidBlockScalars ? dump(cleanFrontmatter, { lineWidth: -1 }) : dump$1(cleanFrontmatter)).trim();
|
|
4626
|
+
return (yaml === "{}" ? "" : `---\n${yaml}\n---\n`) + withTrailingNewline(body);
|
|
4627
|
+
}
|
|
4628
|
+
function withTrailingNewline(text) {
|
|
4629
|
+
return text.endsWith("\n") ? text : `${text}\n`;
|
|
4630
|
+
}
|
|
4673
4631
|
/** Frontmatter languages accepted after the opening `---` fence. */
|
|
4674
4632
|
const ALLOWED_FRONTMATTER_LANGUAGE_PATTERN = /^(?:ya?ml)?$/i;
|
|
4675
4633
|
/**
|
|
4676
|
-
* Read the opening frontmatter fence
|
|
4677
|
-
*
|
|
4634
|
+
* Read the opening frontmatter fence, or return `undefined` when the content
|
|
4635
|
+
* carries no frontmatter at all.
|
|
4678
4636
|
*
|
|
4679
|
-
* gray-matter
|
|
4680
|
-
*
|
|
4681
|
-
* fence
|
|
4682
|
-
*
|
|
4683
|
-
*
|
|
4684
|
-
*
|
|
4685
|
-
*
|
|
4686
|
-
*
|
|
4637
|
+
* The grammar is gray-matter's, which rulesync used to depend on, kept so that
|
|
4638
|
+
* every file reads the same as before: one byte order mark is skipped, `---`
|
|
4639
|
+
* is a fence only when a fourth `-` does not follow, and the language is the
|
|
4640
|
+
* text between the fence and the first `\r?\n`, trimmed — dropping the last
|
|
4641
|
+
* character when there is no line break at all. Every check that has to agree
|
|
4642
|
+
* with {@link splitFrontmatter} on where the block is (the language check and
|
|
4643
|
+
* the repair pass) goes through this one reading, so none of them
|
|
4644
|
+
* can be bypassed by a fence line the splitter accepts and a stricter pattern
|
|
4645
|
+
* would not (a stray `\r` before the line break, say).
|
|
4687
4646
|
*/
|
|
4688
4647
|
function readFrontmatterFence(content) {
|
|
4689
4648
|
const offset = content.startsWith("") ? 1 : 0;
|
|
@@ -4702,26 +4661,60 @@ function readFrontmatterFence(content) {
|
|
|
4702
4661
|
/**
|
|
4703
4662
|
* Refuse a frontmatter fence that names any language other than YAML.
|
|
4704
4663
|
*
|
|
4705
|
-
* Only YAML is ever written by rulesync or by the tools it targets
|
|
4706
|
-
*
|
|
4707
|
-
*
|
|
4664
|
+
* Only YAML is ever written by rulesync or by the tools it targets. Generic
|
|
4665
|
+
* frontmatter libraries pick a parser from the fence language, and some hand a
|
|
4666
|
+
* `---js` block to `eval()`; rulesync parses everything as YAML, and refusing
|
|
4667
|
+
* any other language keeps a file meant for such a parser from being read as
|
|
4668
|
+
* something it is not.
|
|
4708
4669
|
*/
|
|
4709
4670
|
function assertYamlFrontmatterLanguage(content) {
|
|
4710
4671
|
const fence = readFrontmatterFence(content);
|
|
4711
4672
|
if (fence && !ALLOWED_FRONTMATTER_LANGUAGE_PATTERN.test(fence.language)) throw new Error(`Unsupported frontmatter language ${JSON.stringify(fence.language.slice(0, 40))}; only YAML frontmatter is supported`);
|
|
4712
4673
|
}
|
|
4713
4674
|
/**
|
|
4714
|
-
*
|
|
4715
|
-
*
|
|
4716
|
-
*
|
|
4717
|
-
*
|
|
4675
|
+
* Split `content` into its raw frontmatter block and its body, the way
|
|
4676
|
+
* gray-matter 4 did (see {@link readFrontmatterFence}).
|
|
4677
|
+
*
|
|
4678
|
+
* The block ends at the first `\n---`, with no requirement that the delimiter
|
|
4679
|
+
* be alone on its line, and one line break after it is dropped from the body.
|
|
4680
|
+
* A fence nothing closes makes the rest of the file the block and leaves the
|
|
4681
|
+
* body empty. Without a fence, `block` is `""` and the body is the content
|
|
4682
|
+
* minus a leading byte order mark.
|
|
4718
4683
|
*/
|
|
4719
|
-
function
|
|
4720
|
-
const
|
|
4721
|
-
if (
|
|
4722
|
-
|
|
4684
|
+
function splitFrontmatter(content) {
|
|
4685
|
+
const text = content.startsWith("") ? content.slice(1) : content;
|
|
4686
|
+
if (!text.startsWith("---") || text.charAt(3) === "-") return {
|
|
4687
|
+
block: "",
|
|
4688
|
+
body: text
|
|
4689
|
+
};
|
|
4690
|
+
let rest = text.slice(3);
|
|
4691
|
+
const rawLanguage = rest.slice(0, rest.search(/\r?\n/));
|
|
4692
|
+
if (rawLanguage.trim() !== "") rest = rest.slice(rawLanguage.length);
|
|
4723
4693
|
const closeIndex = rest.indexOf("\n---");
|
|
4724
|
-
|
|
4694
|
+
if (closeIndex === -1) return {
|
|
4695
|
+
block: rest,
|
|
4696
|
+
body: ""
|
|
4697
|
+
};
|
|
4698
|
+
let body = rest.slice(closeIndex + 4);
|
|
4699
|
+
if (body.startsWith("\r")) body = body.slice(1);
|
|
4700
|
+
if (body.startsWith("\n")) body = body.slice(1);
|
|
4701
|
+
return {
|
|
4702
|
+
block: rest.slice(0, closeIndex),
|
|
4703
|
+
body
|
|
4704
|
+
};
|
|
4705
|
+
}
|
|
4706
|
+
/**
|
|
4707
|
+
* Whether a raw block holds nothing but blank and comment lines. Checked line
|
|
4708
|
+
* by line rather than with gray-matter's `/^\s*#[^\n]+/gm`, whose `\s*` also
|
|
4709
|
+
* spans line breaks and backtracks quadratically on a long run of blank lines.
|
|
4710
|
+
* The one known difference: a lone `\r` now ends a comment line, as it does
|
|
4711
|
+
* in YAML, where the old pattern let the comment run on past it.
|
|
4712
|
+
*/
|
|
4713
|
+
function isBlankFrontmatterBlock(block) {
|
|
4714
|
+
return block.split(/\r\n|\r|\n/).every((line) => {
|
|
4715
|
+
const trimmed = line.trim();
|
|
4716
|
+
return trimmed === "" || trimmed.startsWith("#");
|
|
4717
|
+
});
|
|
4725
4718
|
}
|
|
4726
4719
|
function parseFrontmatter(content, filePath) {
|
|
4727
4720
|
let frontmatter;
|
|
@@ -4729,11 +4722,11 @@ function parseFrontmatter(content, filePath) {
|
|
|
4729
4722
|
let hasFrontmatter;
|
|
4730
4723
|
try {
|
|
4731
4724
|
assertYamlFrontmatterLanguage(content);
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
frontmatter = deepRemoveNullishObject(
|
|
4735
|
-
body =
|
|
4736
|
-
hasFrontmatter =
|
|
4725
|
+
const split = splitFrontmatter(content);
|
|
4726
|
+
if (split.block.length > 65536) throw new Error(`Frontmatter block is larger than ${MAX_FRONTMATTER_RAW_CHARS} characters; refusing to parse it (a complex YAML key can cost memory while parsing, before any post-parse budget applies)`);
|
|
4727
|
+
frontmatter = deepRemoveNullishObject(isBlankFrontmatterBlock(split.block) ? {} : load$1(split.block));
|
|
4728
|
+
body = split.body;
|
|
4729
|
+
hasFrontmatter = content === "" || split.block !== "" || content.trimStart().startsWith("---");
|
|
4737
4730
|
} catch (error) {
|
|
4738
4731
|
if (filePath) throw new Error(`Failed to parse frontmatter in ${filePath}: ${formatError(error)}`, { cause: error });
|
|
4739
4732
|
throw error;
|
|
@@ -4790,11 +4783,11 @@ function repairFrontmatterLine(line) {
|
|
|
4790
4783
|
/**
|
|
4791
4784
|
* Locate a raw `---`-delimited frontmatter block's bounds within `content`,
|
|
4792
4785
|
* without parsing it, for the YAML repair pass below and the rule loaders that
|
|
4793
|
-
* pre-process `globs:`. The opening fence is read exactly as
|
|
4786
|
+
* pre-process `globs:`. The opening fence is read exactly as the splitter reads
|
|
4794
4787
|
* it ({@link readFrontmatterFence}); an explicit `yaml` / `yml` language is
|
|
4795
|
-
* still YAML, any other language yields no bounds.
|
|
4788
|
+
* still YAML, any other language yields no bounds. The splitter ends the block
|
|
4796
4789
|
* at the first `\n---`, with no requirement that the delimiter be alone on its
|
|
4797
|
-
* line, so a stricter pattern here would run past
|
|
4790
|
+
* line, so a stricter pattern here would run past the splitter's delimiter and
|
|
4798
4791
|
* act on text that is really the body. A block with no closing fence has no
|
|
4799
4792
|
* bounds; the size guard measures that case separately.
|
|
4800
4793
|
*/
|
|
@@ -12709,6 +12702,37 @@ function serialize(value) {
|
|
|
12709
12702
|
function stripStrings(_key, value) {
|
|
12710
12703
|
return typeof value === "string" ? stripControlCharacters(value) : value;
|
|
12711
12704
|
}
|
|
12705
|
+
// src/utils/yaml.ts
|
|
12706
|
+
/**
|
|
12707
|
+
* js-yaml v5's `reason` for an empty document. `load("")` — and any
|
|
12708
|
+
* whitespace/comment-only input — throws a `YAMLException` with this reason
|
|
12709
|
+
* instead of returning `undefined` the way v4 did.
|
|
12710
|
+
*/
|
|
12711
|
+
const EMPTY_INPUT_REASON = "expected a document, but the input is empty";
|
|
12712
|
+
/**
|
|
12713
|
+
* Load YAML content while preserving js-yaml v4's behavior of returning
|
|
12714
|
+
* `undefined` for empty documents (empty, whitespace-only, or comment-only
|
|
12715
|
+
* input).
|
|
12716
|
+
*
|
|
12717
|
+
* js-yaml v5 changed `load("")` to **throw** ("expected a document, but the
|
|
12718
|
+
* input is empty") instead of returning `undefined`. Many call sites here parse
|
|
12719
|
+
* config/lock/frontmatter files that can legitimately be empty and rely on the
|
|
12720
|
+
* old `undefined` sentinel (`load(input) ?? {}`, `if (loaded === undefined)`,
|
|
12721
|
+
* "an empty file parses to undefined/null"). Routing every load through this
|
|
12722
|
+
* wrapper keeps that contract in one place so a future js-yaml bump cannot
|
|
12723
|
+
* reintroduce the empty-input regression. Genuine parse errors still propagate.
|
|
12724
|
+
*
|
|
12725
|
+
* @see https://github.com/nodeca/js-yaml/blob/master/docs/migrate_v4_to_v5.md#empty-input-throws
|
|
12726
|
+
*/
|
|
12727
|
+
function loadYaml(content, options) {
|
|
12728
|
+
if (content.trim() === "") return;
|
|
12729
|
+
try {
|
|
12730
|
+
return load(content, options);
|
|
12731
|
+
} catch (error) {
|
|
12732
|
+
if (error instanceof YAMLException && error.reason === EMPTY_INPUT_REASON) return;
|
|
12733
|
+
throw error;
|
|
12734
|
+
}
|
|
12735
|
+
}
|
|
12712
12736
|
// src/features/shared/jsonc-object-edit.ts
|
|
12713
12737
|
/**
|
|
12714
12738
|
* In-place editing of a JSONC object's text: the engine behind the shared
|
|
@@ -14719,7 +14743,7 @@ function tryParseStructured({ filePath, content }) {
|
|
|
14719
14743
|
}
|
|
14720
14744
|
}
|
|
14721
14745
|
/**
|
|
14722
|
-
*
|
|
14746
|
+
* The parsed body often starts with extra newlines right after the closing ---; strip those so the
|
|
14723
14747
|
* body matches across generators vs on-disk formatters. Trailing whitespace is normalized via
|
|
14724
14748
|
* addTrailingNewline (trimEnd + single newline), same as writes.
|
|
14725
14749
|
*/
|
|
@@ -14810,7 +14834,7 @@ function fileContentIsEmptyPayload({ filePath, content }) {
|
|
|
14810
14834
|
* Whether on-disk content is equivalent to generated content for --check / dry-run.
|
|
14811
14835
|
*
|
|
14812
14836
|
* Uses structured comparison for JSON/JSONC (via jsonc-parser), YAML, TOML, and Markdown-like
|
|
14813
|
-
* frontmatter files (.md, .mdc — same
|
|
14837
|
+
* frontmatter files (.md, .mdc — same frontmatter parser as elsewhere).
|
|
14814
14838
|
*/
|
|
14815
14839
|
function fileContentsEquivalent({ filePath, expected, existing }) {
|
|
14816
14840
|
if (existing === null) return false;
|
|
@@ -14992,6 +15016,11 @@ var FeatureProcessor = class extends RulesyncSourceConsumer {
|
|
|
14992
15016
|
if (fileMode !== void 0 && !this.dryRun) await restoreMissingExecutableBit(filePath, fileMode);
|
|
14993
15017
|
continue;
|
|
14994
15018
|
}
|
|
15019
|
+
await warnIfWriteFollowsLink({
|
|
15020
|
+
logger: this.logger,
|
|
15021
|
+
rootPath: aiFile.getOutputRoot(),
|
|
15022
|
+
targetPath: filePath
|
|
15023
|
+
});
|
|
14995
15024
|
if (this.dryRun) this.logger.info(`[DRY RUN] Would write: ${stripControlCharacters(filePath)}`);
|
|
14996
15025
|
else {
|
|
14997
15026
|
await writeFileContent(filePath, contentWithNewline);
|
|
@@ -15176,6 +15205,37 @@ async function refusesWriteOutsideRoot({ logger, rootPath, targetPath }) {
|
|
|
15176
15205
|
return true;
|
|
15177
15206
|
}
|
|
15178
15207
|
/**
|
|
15208
|
+
* Warn, once per run and link, that a write to `targetPath` goes through a
|
|
15209
|
+
* symbolic link below `rootPath`: the warning names the link and the real path
|
|
15210
|
+
* it leads to, so the file the write really changes is visible.
|
|
15211
|
+
*
|
|
15212
|
+
* Links that lead out of the root (or into version-control metadata) are
|
|
15213
|
+
* refused by {@link refusesWriteOutsideRoot} before this is asked; an in-root
|
|
15214
|
+
* link is written through on purpose (dotfiles setups rely on it), but a
|
|
15215
|
+
* committed `AGENTS.md -> .claude/CLAUDE.md` would otherwise have one target
|
|
15216
|
+
* silently replace another target's file. Writers call this only for a file
|
|
15217
|
+
* they are about to change (or, in a dry run, would change), so an unchanged
|
|
15218
|
+
* file reached through a link stays quiet. The warning is keyed on the first
|
|
15219
|
+
* link on the path rather than on the file, so a linked directory such as
|
|
15220
|
+
* `~/.claude -> ~/dotfiles/.claude` is reported once however many files below
|
|
15221
|
+
* it a run writes.
|
|
15222
|
+
*/
|
|
15223
|
+
async function warnIfWriteFollowsLink({ logger, rootPath, targetPath }) {
|
|
15224
|
+
const linkPath = await firstLinkBelowRoot({
|
|
15225
|
+
rootPath,
|
|
15226
|
+
targetPath
|
|
15227
|
+
});
|
|
15228
|
+
if (linkPath === null) return;
|
|
15229
|
+
const linkLanding = await writeLandingPath(linkPath);
|
|
15230
|
+
if (linkLanding === null) return;
|
|
15231
|
+
warnOnceWithFallback(logger, `${quoteForLog(linkPath)} is a symbolic link to ${quoteForLog(linkLanding)}; files rulesync writes through it land there`);
|
|
15232
|
+
const restOfPath = relative(linkPath, resolve(targetPath));
|
|
15233
|
+
if (restOfPath === "") return;
|
|
15234
|
+
const targetLanding = await writeLandingPath(targetPath);
|
|
15235
|
+
if (targetLanding === null || targetLanding === join(linkLanding, restOfPath)) return;
|
|
15236
|
+
warnOnceWithFallback(logger, `${quoteForLog(targetPath)} is reached through further symbolic links; rulesync writes it to ${quoteForLog(targetLanding)}`);
|
|
15237
|
+
}
|
|
15238
|
+
/**
|
|
15179
15239
|
* Why the orphan sweep has to leave the files in `dirPath` alone, or `null`
|
|
15180
15240
|
* when it may delete them.
|
|
15181
15241
|
*
|
|
@@ -18510,6 +18570,11 @@ var GooseCommand = class GooseCommand extends ToolCommand {
|
|
|
18510
18570
|
entries: []
|
|
18511
18571
|
});
|
|
18512
18572
|
if (nextContent === currentContent) return 0;
|
|
18573
|
+
await warnIfWriteFollowsLink({
|
|
18574
|
+
logger,
|
|
18575
|
+
rootPath: outputRoot,
|
|
18576
|
+
targetPath: configPath
|
|
18577
|
+
});
|
|
18513
18578
|
if (dryRun) logger.info(`[DRY RUN] Would write: ${configPath}`);
|
|
18514
18579
|
else await writeFileContent(configPath, nextContent);
|
|
18515
18580
|
return 1;
|
|
@@ -19692,6 +19757,11 @@ var HermesagentCommand = class HermesagentCommand extends ToolCommand {
|
|
|
19692
19757
|
global
|
|
19693
19758
|
});
|
|
19694
19759
|
if (nextContent === currentContent) return 0;
|
|
19760
|
+
await warnIfWriteFollowsLink({
|
|
19761
|
+
logger,
|
|
19762
|
+
rootPath: outputRoot,
|
|
19763
|
+
targetPath: configPath
|
|
19764
|
+
});
|
|
19695
19765
|
if (dryRun) logger.info(`[DRY RUN] Would write: ${configPath}`);
|
|
19696
19766
|
else await writeFileContent(configPath, nextContent);
|
|
19697
19767
|
return 1;
|
|
@@ -23308,6 +23378,17 @@ var DirFeatureProcessor = class extends RulesyncSourceConsumer {
|
|
|
23308
23378
|
});
|
|
23309
23379
|
}
|
|
23310
23380
|
/**
|
|
23381
|
+
* Warn about each file of `aiDir` about to be written through a symbolic link
|
|
23382
|
+
* that stays inside the output root (see {@link warnIfWriteFollowsLink}).
|
|
23383
|
+
*/
|
|
23384
|
+
async warnIfFilesFollowLinks({ aiDir, filePaths }) {
|
|
23385
|
+
for (const targetPath of filePaths) await warnIfWriteFollowsLink({
|
|
23386
|
+
logger: this.logger,
|
|
23387
|
+
rootPath: aiDir.getOutputRoot(),
|
|
23388
|
+
targetPath
|
|
23389
|
+
});
|
|
23390
|
+
}
|
|
23391
|
+
/**
|
|
23311
23392
|
* Once converted to rulesync/tool dirs, write them to the filesystem.
|
|
23312
23393
|
* Returns the number of directories written.
|
|
23313
23394
|
*
|
|
@@ -23360,6 +23441,10 @@ var DirFeatureProcessor = class extends RulesyncSourceConsumer {
|
|
|
23360
23441
|
}
|
|
23361
23442
|
continue;
|
|
23362
23443
|
}
|
|
23444
|
+
await this.warnIfFilesFollowLinks({
|
|
23445
|
+
aiDir,
|
|
23446
|
+
filePaths: writtenPaths.slice(1)
|
|
23447
|
+
});
|
|
23363
23448
|
const relativeDir = aiDir.getRelativePathFromCwd();
|
|
23364
23449
|
if (this.dryRun) {
|
|
23365
23450
|
this.logger.info(`[DRY RUN] Would create directory: ${stripControlCharacters(dirPath)}`);
|
|
@@ -34547,6 +34632,24 @@ function isMissingDescription(value) {
|
|
|
34547
34632
|
function nameFromFileName(relativeFilePath) {
|
|
34548
34633
|
return relativeFilePath.replace(/(\.agent)?\.md$/, "");
|
|
34549
34634
|
}
|
|
34635
|
+
/**
|
|
34636
|
+
* Normalizes a subagent name the way Junie does: the result is what Junie
|
|
34637
|
+
* accepts for `--agent` and must match `[a-z0-9][a-z0-9_-]*`.
|
|
34638
|
+
*
|
|
34639
|
+
* - Surrounding whitespace is trimmed first, so a quoted `" Code Reviewer "`
|
|
34640
|
+
* (or a file named ` Reviewer.md`) does not start or end with a hyphen,
|
|
34641
|
+
* which the leading-character rule would reject.
|
|
34642
|
+
* - Uppercase letters are lowercased.
|
|
34643
|
+
* - Each run of whitespace (spaces, tabs, ...) becomes a single hyphen. The
|
|
34644
|
+
* upstream docs only say Junie "replaces spaces with hyphens"; collapsing
|
|
34645
|
+
* runs gives `code-reviewer` for `Code Reviewer`, which is the name a user
|
|
34646
|
+
* would expect and still matches the pattern, instead of `code--reviewer`.
|
|
34647
|
+
*
|
|
34648
|
+
* @see https://junie.jetbrains.com/docs/junie-cli-subagents.html
|
|
34649
|
+
*/
|
|
34650
|
+
function normalizeJunieName(name) {
|
|
34651
|
+
return name.trim().toLowerCase().replace(/\s+/g, "-");
|
|
34652
|
+
}
|
|
34550
34653
|
var JunieSubagent = class JunieSubagent extends ToolSubagent {
|
|
34551
34654
|
frontmatter;
|
|
34552
34655
|
body;
|
|
@@ -34571,14 +34674,30 @@ var JunieSubagent = class JunieSubagent extends ToolSubagent {
|
|
|
34571
34674
|
getBody() {
|
|
34572
34675
|
return this.body;
|
|
34573
34676
|
}
|
|
34677
|
+
/**
|
|
34678
|
+
* The name Junie resolves after normalization, so `Code Reviewer.md` and
|
|
34679
|
+
* `code-reviewer.md` (both `code-reviewer`) are reported as duplicates on
|
|
34680
|
+
* import instead of becoming two rulesync subagents with the same name.
|
|
34681
|
+
*/
|
|
34682
|
+
getImportIdentity() {
|
|
34683
|
+
return this.getNormalizedName();
|
|
34684
|
+
}
|
|
34685
|
+
/**
|
|
34686
|
+
* An empty or whitespace-only `name` would normalize to `""`, which is not a
|
|
34687
|
+
* valid Junie name and would make every such file share one import identity,
|
|
34688
|
+
* so it falls back to the file name just like a missing `name` does.
|
|
34689
|
+
*/
|
|
34690
|
+
getNormalizedName() {
|
|
34691
|
+
return (this.frontmatter.name === void 0 ? "" : normalizeJunieName(this.frontmatter.name)) || normalizeJunieName(nameFromFileName(this.getRelativeFilePath()));
|
|
34692
|
+
}
|
|
34574
34693
|
toRulesyncSubagent() {
|
|
34575
|
-
const { name, description, ...restFields } = this.frontmatter;
|
|
34694
|
+
const { name: _name, description, ...restFields } = this.frontmatter;
|
|
34576
34695
|
const junieSection = { ...restFields };
|
|
34577
34696
|
return new RulesyncSubagent({
|
|
34578
34697
|
outputRoot: ".",
|
|
34579
34698
|
frontmatter: {
|
|
34580
34699
|
targets: ["*"],
|
|
34581
|
-
name:
|
|
34700
|
+
name: this.getNormalizedName(),
|
|
34582
34701
|
...description !== void 0 && { description },
|
|
34583
34702
|
...Object.keys(junieSection).length > 0 && { junie: junieSection }
|
|
34584
34703
|
},
|
|
@@ -48358,8 +48477,8 @@ var TraeRule = class TraeRule extends ToolRule {
|
|
|
48358
48477
|
* before parsing, inside the frontmatter block only so the body is never
|
|
48359
48478
|
* rewritten. A quoted value, a YAML flow list, a null or boolean keyword and a
|
|
48360
48479
|
* block scalar indicator (`|`, `>`) are left alone. The block bounds are
|
|
48361
|
-
*
|
|
48362
|
-
* `----` line), so the quoting never reaches text
|
|
48480
|
+
* `parseFrontmatter`'s own (it closes the block at the first `\n---`, even
|
|
48481
|
+
* inside a `----` line), so the quoting never reaches text it reads as body.
|
|
48363
48482
|
*/
|
|
48364
48483
|
static parseTraeFrontmatter(fileContent, filePath) {
|
|
48365
48484
|
const bounds = findFrontmatterBlockBounds(fileContent);
|
|
@@ -51664,19 +51783,17 @@ var CursorCheck = class extends AggregatedToolCheck {
|
|
|
51664
51783
|
*
|
|
51665
51784
|
* rulesync never writes frontmatter here, but a user who authored this path as
|
|
51666
51785
|
* an ordinary skill did, and that block is the skill's metadata rather than
|
|
51667
|
-
* review instructions.
|
|
51668
|
-
*
|
|
51669
|
-
*
|
|
51670
|
-
*
|
|
51671
|
-
*
|
|
51672
|
-
*
|
|
51673
|
-
*
|
|
51674
|
-
*
|
|
51675
|
-
*
|
|
51676
|
-
*
|
|
51677
|
-
*
|
|
51678
|
-
* a fence nothing closes: gray-matter would swallow the rest of the file, so
|
|
51679
|
-
* only the rule line goes and the prose under it is kept.
|
|
51786
|
+
* review instructions. Left in place it would be carried into the body of
|
|
51787
|
+
* the check written to `.rulesync/checks/` as a block of YAML right behind
|
|
51788
|
+
* that file's own frontmatter, where a `severity: bogus` copied out of a skill
|
|
51789
|
+
* looks like the check's own setting to anyone reading or editing it.
|
|
51790
|
+
*
|
|
51791
|
+
* The block is therefore found the way `parseFrontmatter` finds it rather than
|
|
51792
|
+
* by parsing it, so that what the parser would have read as frontmatter is
|
|
51793
|
+
* what goes: the opening delimiter may carry a language name (`---yaml`), but
|
|
51794
|
+
* four dashes are a horizontal rule the parser itself skips. The one
|
|
51795
|
+
* deliberate difference is a fence nothing closes: the parser would take the
|
|
51796
|
+
* rest of the file, so only the rule line goes and the prose under it is kept.
|
|
51680
51797
|
*/
|
|
51681
51798
|
const FRONTMATTER_OPEN_PATTERN = /^\uFEFF?---(?!-)[^\r\n]*\r?\n/;
|
|
51682
51799
|
const FRONTMATTER_CLOSE_PATTERN = /^---|\r?\n---/;
|
|
@@ -60737,6 +60854,51 @@ function warnIgnoredFailClosed({ config, supportedEvents, toolConfigKey, logger
|
|
|
60737
60854
|
}
|
|
60738
60855
|
}
|
|
60739
60856
|
}
|
|
60857
|
+
/**
|
|
60858
|
+
* Canonical (Claude Code) tool names mapped to the lowercase tool ids OpenCode
|
|
60859
|
+
* 1.x and its forks (Kilo, MiMo Code) pass as `input.tool`, which a matcher is
|
|
60860
|
+
* tested against case-sensitively. The shell tool is `bash` here, the same id
|
|
60861
|
+
* the shell events gate on (see {@link SHELL_EVENT_TOOL_GATES}).
|
|
60862
|
+
* @see https://opencode.ai/docs/plugins/
|
|
60863
|
+
*/
|
|
60864
|
+
const CANONICAL_TO_OPENCODE_V1_TOOL_NAMES = {
|
|
60865
|
+
Bash: "bash",
|
|
60866
|
+
Read: "read",
|
|
60867
|
+
Write: "write",
|
|
60868
|
+
Edit: "edit"
|
|
60869
|
+
};
|
|
60870
|
+
/**
|
|
60871
|
+
* A matcher made only of plain names joined by `|`, which Claude Code matches
|
|
60872
|
+
* as an exact tool name list rather than as a regex.
|
|
60873
|
+
*/
|
|
60874
|
+
const PLAIN_NAME_MATCHER_PATTERN = /^[A-Za-z0-9_]+(?:\|[A-Za-z0-9_]+)*$/;
|
|
60875
|
+
/**
|
|
60876
|
+
* Build a translator that rewrites the canonical tool names in a matcher
|
|
60877
|
+
* through `toolNames` and warns about a capitalized name left over
|
|
60878
|
+
* (`MultiEdit`, `Glob`), which no lowercase tool id can match. Each distinct
|
|
60879
|
+
* matcher of an event is translated once, so hooks sharing one do not repeat
|
|
60880
|
+
* its warning.
|
|
60881
|
+
*
|
|
60882
|
+
* The plugins test the matcher unanchored, so a translated plain-name matcher
|
|
60883
|
+
* is anchored as `^(?:...)$` to keep Claude Code's exact-name semantics:
|
|
60884
|
+
* otherwise `write` would also match OpenCode's `todowrite`. Regex-style and
|
|
60885
|
+
* untranslated matchers are left as written.
|
|
60886
|
+
*/
|
|
60887
|
+
function createOpencodeMatcherTranslator({ toolNames, toolConfigKey, logger }) {
|
|
60888
|
+
const label = FAIL_CLOSED_TOOL_LABELS[toolConfigKey];
|
|
60889
|
+
const translated = /* @__PURE__ */ new Map();
|
|
60890
|
+
return (matcher, eventName) => {
|
|
60891
|
+
const key = `${eventName}\0${matcher}`;
|
|
60892
|
+
const cached = translated.get(key);
|
|
60893
|
+
if (cached !== void 0) return cached;
|
|
60894
|
+
const replaced = replaceMatcherNames(matcher, toolNames);
|
|
60895
|
+
const result = replaced !== matcher && PLAIN_NAME_MATCHER_PATTERN.test(stripControlChars(matcher)) ? `^(?:${replaced})$` : replaced;
|
|
60896
|
+
const unmatched = capitalizedMatcherNames(result);
|
|
60897
|
+
if (unmatched.length > 0) logger?.warn(`${label} matches hook matchers case-sensitively against lowercase tool names, and ${unmatched.map((name) => quoteValueForWarning(name)).join(", ")} in the ${quoteValueForWarning(eventName)} matcher ${quoteValueForWarning(matcher)} is not translated by rulesync, so it is written as-is and will likely never match. Use the tool name ${label} reports instead.`);
|
|
60898
|
+
translated.set(key, result);
|
|
60899
|
+
return result;
|
|
60900
|
+
};
|
|
60901
|
+
}
|
|
60740
60902
|
/** Whether any handler is a `sessionStart` one, whose stdout becomes session context. */
|
|
60741
60903
|
function usesSessionContext(handlers) {
|
|
60742
60904
|
return handlers.some((handler) => handler.context);
|
|
@@ -60762,7 +60924,7 @@ function handlerExtrasFor(canonicalEvent) {
|
|
|
60762
60924
|
* Group the effective hooks into named (tool.execute.*) and generic event
|
|
60763
60925
|
* handler groups, keyed by tool event name. Mutates the supplied groups.
|
|
60764
60926
|
*/
|
|
60765
|
-
function collectOpencodeStyleHandlers({ effectiveHooks, eventMap, namedEventHandlers, genericEventHandlers }) {
|
|
60927
|
+
function collectOpencodeStyleHandlers({ effectiveHooks, eventMap, namedEventHandlers, genericEventHandlers, translateMatcher }) {
|
|
60766
60928
|
for (const [canonicalEvent, definitions] of Object.entries(effectiveHooks)) {
|
|
60767
60929
|
const shellGate = SHELL_EVENT_TOOL_GATES[canonicalEvent];
|
|
60768
60930
|
const extras = handlerExtrasFor(canonicalEvent);
|
|
@@ -60770,6 +60932,7 @@ function collectOpencodeStyleHandlers({ effectiveHooks, eventMap, namedEventHand
|
|
|
60770
60932
|
if (!toolEvent) continue;
|
|
60771
60933
|
const isNamedHook = Object.hasOwn(NAMED_HOOK_MATCHER_SUBJECTS, toolEvent);
|
|
60772
60934
|
const matcherSupported = !shellGate && isNamedHook && NAMED_HOOK_MATCHER_SUBJECTS[toolEvent] !== null;
|
|
60935
|
+
const matchesToolName = NAMED_HOOK_MATCHER_SUBJECTS[toolEvent] === "input.tool";
|
|
60773
60936
|
const handlers = [];
|
|
60774
60937
|
for (const def of definitions) {
|
|
60775
60938
|
if ((def.type ?? "command") !== "command") continue;
|
|
@@ -60777,7 +60940,7 @@ function collectOpencodeStyleHandlers({ effectiveHooks, eventMap, namedEventHand
|
|
|
60777
60940
|
if (def.matcher && !matcherSupported) continue;
|
|
60778
60941
|
handlers.push({
|
|
60779
60942
|
command: def.command,
|
|
60780
|
-
matcher: def.matcher ? def.matcher : void 0,
|
|
60943
|
+
matcher: def.matcher ? matchesToolName ? translateMatcher(def.matcher, canonicalEvent) : def.matcher : void 0,
|
|
60781
60944
|
blocking: BLOCKING_HOOKS.has(toolEvent),
|
|
60782
60945
|
...hookTimingOf(def),
|
|
60783
60946
|
inProcess: !isNamedHook,
|
|
@@ -60941,7 +61104,7 @@ function wrapInExportShape({ preambleLines, bodyLines, exportStyle }) {
|
|
|
60941
61104
|
lines.push("");
|
|
60942
61105
|
return lines;
|
|
60943
61106
|
}
|
|
60944
|
-
function generateOpencodeStylePluginCode(config, supportedEvents, toolConfigKey, eventMap, exportStyle = "named") {
|
|
61107
|
+
function generateOpencodeStylePluginCode(config, supportedEvents, toolConfigKey, eventMap, exportStyle = "named", logger) {
|
|
60945
61108
|
const supported = new Set(supportedEvents);
|
|
60946
61109
|
const configHooks = {
|
|
60947
61110
|
...config.hooks,
|
|
@@ -60955,7 +61118,12 @@ function generateOpencodeStylePluginCode(config, supportedEvents, toolConfigKey,
|
|
|
60955
61118
|
effectiveHooks,
|
|
60956
61119
|
eventMap,
|
|
60957
61120
|
namedEventHandlers,
|
|
60958
|
-
genericEventHandlers
|
|
61121
|
+
genericEventHandlers,
|
|
61122
|
+
translateMatcher: createOpencodeMatcherTranslator({
|
|
61123
|
+
toolNames: CANONICAL_TO_OPENCODE_V1_TOOL_NAMES,
|
|
61124
|
+
toolConfigKey,
|
|
61125
|
+
logger
|
|
61126
|
+
})
|
|
60959
61127
|
});
|
|
60960
61128
|
const usesContext = Object.values(genericEventHandlers).some(usesSessionContext);
|
|
60961
61129
|
const bodyLines = [
|
|
@@ -61009,7 +61177,7 @@ var KiloHooks = class KiloHooks extends ToolHooks {
|
|
|
61009
61177
|
toolConfigKey: "kilo",
|
|
61010
61178
|
logger
|
|
61011
61179
|
});
|
|
61012
|
-
const fileContent = generateOpencodeStylePluginCode(config, KILO_HOOK_EVENTS, "kilo", CANONICAL_TO_KILO_EVENT_NAMES, "default");
|
|
61180
|
+
const fileContent = generateOpencodeStylePluginCode(config, KILO_HOOK_EVENTS, "kilo", CANONICAL_TO_KILO_EVENT_NAMES, "default", logger);
|
|
61013
61181
|
const paths = KiloHooks.getSettablePaths({ global });
|
|
61014
61182
|
return new KiloHooks({
|
|
61015
61183
|
outputRoot,
|
|
@@ -61873,6 +62041,21 @@ var LettacodeHooks = class LettacodeHooks extends ToolHooks {
|
|
|
61873
62041
|
/** Tool name OpenCode V2 gives its shell tool (V1 called it `bash`). */
|
|
61874
62042
|
const OPENCODE_V2_SHELL_TOOL = "shell";
|
|
61875
62043
|
/**
|
|
62044
|
+
* Canonical (Claude Code) tool names mapped to the lowercase names OpenCode 2.x
|
|
62045
|
+
* reports in `event.tool`, which a matcher is tested against case-sensitively.
|
|
62046
|
+
* Observed on OpenCode 2.3.2: a `preToolUse` hook fires with `read`, `write`,
|
|
62047
|
+
* `edit` and `shell`, so a canonical `Read|Edit|Write` or `Bash` never matched.
|
|
62048
|
+
* `Bash` becomes the V2 name `shell`; the generated helper still accepts the
|
|
62049
|
+
* V1 name `bash` for a matcher written that way.
|
|
62050
|
+
* https://opencode.ai/v2/docs/build/plugins/
|
|
62051
|
+
*/
|
|
62052
|
+
const CANONICAL_TO_OPENCODE_V2_TOOL_NAMES = {
|
|
62053
|
+
Bash: OPENCODE_V2_SHELL_TOOL,
|
|
62054
|
+
Read: "read",
|
|
62055
|
+
Write: "write",
|
|
62056
|
+
Edit: "edit"
|
|
62057
|
+
};
|
|
62058
|
+
/**
|
|
61876
62059
|
* Per-canonical-event conditions the generated handler gates on, because the
|
|
61877
62060
|
* hook point or event it shares fires more broadly than the canonical event:
|
|
61878
62061
|
* - the shell events run only for the `shell` tool's calls;
|
|
@@ -62049,7 +62232,7 @@ function isBlockingOpencodeV2Target(target) {
|
|
|
62049
62232
|
return !target.startsWith("event:") && target !== "tool:execute.after";
|
|
62050
62233
|
}
|
|
62051
62234
|
/** Build the handlers of one canonical event's command definitions. */
|
|
62052
|
-
function buildHandlersFor({ canonicalEvent, definitions, target }) {
|
|
62235
|
+
function buildHandlersFor({ canonicalEvent, definitions, target, translateMatcher }) {
|
|
62053
62236
|
const gate = OPENCODE_V2_HANDLER_GATES[canonicalEvent];
|
|
62054
62237
|
const payload = OPENCODE_V2_STDIN_PAYLOADS[canonicalEvent];
|
|
62055
62238
|
const matcherSupported = !(canonicalEvent === "beforeShellExecution" || canonicalEvent === "afterShellExecution") && OPENCODE_V2_MATCHABLE_HOOKS.has(target);
|
|
@@ -62063,7 +62246,7 @@ function buildHandlersFor({ canonicalEvent, definitions, target }) {
|
|
|
62063
62246
|
event: canonicalEvent,
|
|
62064
62247
|
blocking: isBlockingOpencodeV2Target(target),
|
|
62065
62248
|
...hookTimingOf(def),
|
|
62066
|
-
...def.matcher ? { matcher: def.matcher } : {},
|
|
62249
|
+
...def.matcher ? { matcher: translateMatcher(def.matcher, canonicalEvent) } : {},
|
|
62067
62250
|
...gate ? { gate } : {},
|
|
62068
62251
|
...payload ? { payload } : {},
|
|
62069
62252
|
...sessionContextExtrasFor(canonicalEvent)
|
|
@@ -62099,12 +62282,17 @@ function buildSetupBodyLines({ hookHandlers, eventHandlers }) {
|
|
|
62099
62282
|
body.push("", "return async () => {", ...cleanup, "};");
|
|
62100
62283
|
return body;
|
|
62101
62284
|
}
|
|
62102
|
-
function generateOpencodeV2PluginCode({ config, supportedEvents, toolConfigKey, eventMap }) {
|
|
62285
|
+
function generateOpencodeV2PluginCode({ config, supportedEvents, toolConfigKey, eventMap, logger }) {
|
|
62103
62286
|
const supported = new Set(supportedEvents);
|
|
62104
62287
|
const configHooks = {
|
|
62105
62288
|
...config.hooks,
|
|
62106
62289
|
...config[toolConfigKey]?.hooks
|
|
62107
62290
|
};
|
|
62291
|
+
const translateMatcher = createOpencodeMatcherTranslator({
|
|
62292
|
+
toolNames: CANONICAL_TO_OPENCODE_V2_TOOL_NAMES,
|
|
62293
|
+
toolConfigKey,
|
|
62294
|
+
logger
|
|
62295
|
+
});
|
|
62108
62296
|
const hookHandlers = /* @__PURE__ */ new Map();
|
|
62109
62297
|
const eventHandlers = /* @__PURE__ */ new Map();
|
|
62110
62298
|
for (const [canonicalEvent, definitions] of Object.entries(configHooks)) {
|
|
@@ -62114,7 +62302,8 @@ function generateOpencodeV2PluginCode({ config, supportedEvents, toolConfigKey,
|
|
|
62114
62302
|
const handlers = buildHandlersFor({
|
|
62115
62303
|
canonicalEvent,
|
|
62116
62304
|
definitions,
|
|
62117
|
-
target
|
|
62305
|
+
target,
|
|
62306
|
+
translateMatcher
|
|
62118
62307
|
});
|
|
62119
62308
|
if (handlers.length === 0) continue;
|
|
62120
62309
|
const isEvent = target.startsWith("event:");
|
|
@@ -62169,8 +62358,9 @@ var OpencodeHooks = class extends ToolHooks {
|
|
|
62169
62358
|
config,
|
|
62170
62359
|
supportedEvents: OPENCODE_V2_HOOK_EVENTS,
|
|
62171
62360
|
toolConfigKey: this.layout.toolTarget,
|
|
62172
|
-
eventMap: CANONICAL_TO_OPENCODE_V2_EVENT_NAMES
|
|
62173
|
-
|
|
62361
|
+
eventMap: CANONICAL_TO_OPENCODE_V2_EVENT_NAMES,
|
|
62362
|
+
logger
|
|
62363
|
+
}) : generateOpencodeStylePluginCode(config, OPENCODE_HOOK_EVENTS, this.layout.toolTarget, CANONICAL_TO_OPENCODE_EVENT_NAMES, "named", logger);
|
|
62174
62364
|
const paths = this.getSettablePaths({ global });
|
|
62175
62365
|
return new this({
|
|
62176
62366
|
outputRoot,
|
|
@@ -105880,6 +106070,11 @@ async function ensureAntigravityPluginManifests({ outputRoots, dryRun, logger })
|
|
|
105880
106070
|
if (name !== dirName) warnOnceWithFallback(logger, `The Antigravity plugin directory ${quoteForLog(dirName)} is not lowercase kebab-case, which \`agy plugin validate --strict\` and the Marketplace reject, so ${quoteForLog(filePath)} names the plugin ${quoteForLog(name)}.`);
|
|
105881
106071
|
noteName(name, filePath);
|
|
105882
106072
|
const content = addTrailingNewline(JSON.stringify({ name }, null, 2));
|
|
106073
|
+
await warnIfWriteFollowsLink({
|
|
106074
|
+
logger,
|
|
106075
|
+
rootPath: outputRoot,
|
|
106076
|
+
targetPath: filePath
|
|
106077
|
+
});
|
|
105883
106078
|
if (dryRun) logger.info(`[DRY RUN] Would write: ${stripControlCharacters(filePath)}`);
|
|
105884
106079
|
else await writeFileContent(filePath, content);
|
|
105885
106080
|
paths.push(ANTIGRAVITY_PLUGIN_MANIFEST_FILE_NAME);
|
|
@@ -105928,7 +106123,7 @@ function mergeEnabledPlugins({ existingContent, filePath, pluginNames }) {
|
|
|
105928
106123
|
}
|
|
105929
106124
|
});
|
|
105930
106125
|
}
|
|
105931
|
-
async function writeActivationFile({ filePath, relativePath, expectedContent, dryRun, logger }) {
|
|
106126
|
+
async function writeActivationFile({ rootPath, filePath, relativePath, expectedContent, dryRun, logger }) {
|
|
105932
106127
|
const existingContent = await readFileContentOrNull(filePath);
|
|
105933
106128
|
const normalizedExpected = addTrailingNewline(expectedContent);
|
|
105934
106129
|
if (fileContentsEquivalent({
|
|
@@ -105936,6 +106131,11 @@ async function writeActivationFile({ filePath, relativePath, expectedContent, dr
|
|
|
105936
106131
|
expected: normalizedExpected,
|
|
105937
106132
|
existing: existingContent
|
|
105938
106133
|
})) return false;
|
|
106134
|
+
await warnIfWriteFollowsLink({
|
|
106135
|
+
logger,
|
|
106136
|
+
rootPath,
|
|
106137
|
+
targetPath: filePath
|
|
106138
|
+
});
|
|
105939
106139
|
if (dryRun) logger.info(`[DRY RUN] Would write: ${filePath}`);
|
|
105940
106140
|
else await writeFileContent(filePath, normalizedExpected);
|
|
105941
106141
|
logger.debug(`Hermes project-plugin activation requires ${relativePath}`);
|
|
@@ -105972,6 +106172,7 @@ async function activateHermesProjectPlugins({ pluginNames, dryRun, logger }) {
|
|
|
105972
106172
|
const paths = [];
|
|
105973
106173
|
logger.warn(`Hermes project plugins require explicit trust. Run Hermes from this trusted repository with ${HERMESAGENT_PROJECT_PLUGINS_ENV_VAR}=true. RuleSync does not persist this global setting.`);
|
|
105974
106174
|
if (await writeActivationFile({
|
|
106175
|
+
rootPath: configRoot,
|
|
105975
106176
|
filePath: configPath,
|
|
105976
106177
|
relativePath: relativeConfigPath,
|
|
105977
106178
|
expectedContent: expectedConfig,
|
|
@@ -107992,6 +108193,6 @@ const CHECKS_IMPORT_STRATEGY = {
|
|
|
107992
108193
|
missingLabel: "check files",
|
|
107993
108194
|
createdLabel: "check files"
|
|
107994
108195
|
};
|
|
107995
|
-
export {
|
|
108196
|
+
export { RulesyncSkillFrontmatterSchema as $, RULESYNC_RULES_RELATIVE_DIR_PATH as $n, getFileSizeAndExecutableBit as $t, CODEBUDDY_LOCAL_RULE_FILE_NAME as A, ToolTargetSchema as An, fallbackLogger as At, CLAUDECODE_DIR as B, RULESYNC_CONFIG_RELATIVE_FILE_PATH as Bn, assertDirectoryIfExists as Bt, LETTACODE_DIR as C, toPosixPath as Cn, SourceEntrySchema as Ct, COMMANDCODE_DIR as D, ALL_TOOL_TARGETS as Dn, ConsoleLogger as Dt, FACTORYDROID_SETTINGS_LOCAL_FILE_NAME as E, mapWithConcurrency as En, findControlCharacter as Et, sweepRefusalReason as F, FEATURE_SOURCE_TREE_ENTRIES as Fn, CLIError as Ft, findProjectInstructionBudgetFindings as G, RULESYNC_IGNORE_RELATIVE_FILE_PATH as Gn, assertWritablePathInsideRoot as Gt, CLAUDECODE_MEMORIES_DIR_NAME as H, RULESYNC_CURATED_RULES_RELATIVE_DIR_PATH as Hn, assertNoSymlinkBelowRoot as Ht, loadYaml as I, MAX_FILE_SIZE as In, ErrorCodes as It, hasWindowsFoldableName as J, RULESYNC_MCP_SCHEMA_URL as Jn, directoryExists as Jt, toInstructionBudgetFile as K, RULESYNC_LOCAL_CONFIG_RELATIVE_FILE_PATH as Kn, checkPathTraversal as Kt, CODEXCLI_BASH_RULES_FILE_NAME as L, RULESYNC_AIIGNORE_RELATIVE_FILE_PATH as Ln, parseJsonc as Lt, AUGMENTCODE_SETTINGS_LOCAL_FILE_NAME as M, ALL_FEATURES_WITH_WILDCARD as Mn, withFallbackLoggerTarget as Mt, caseFoldIdentity as N, DEPRECATED_FEATURE_REPLACEMENTS as Nn, resetRunWarningState as Nt, COMMANDCODE_SETTINGS_LOCAL_FILE_NAME as O, ALL_TOOL_TARGETS_WITH_WILDCARD as On, JsonLogger as Ot, groupSpellingsByCaseFoldedIdentity as P, CURATED_RULES_FEATURE_SUBDIR as Pn, withWarnOnceScope as Pt, RulesyncSkill as Q, RULESYNC_RELATIVE_DIR_PATH as Qn, findFilesByGlobs as Qt, CODEXCLI_DIR as R, RULESYNC_CHECKS_RELATIVE_DIR_PATH as Rn, PathOutsideRootError as Rt, QWENCODE_LOCAL_RULE_FILE_NAME as S, splitPathSegments as Sn, GITIGNORE_DESTINATION_KEY as St, FACTORYDROID_DIR as T, writeFileContent as Tn, getSourceTransport as Tt, CLAUDECODE_SETTINGS_LOCAL_FILE_NAME as U, RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH as Un, assertPathResolvesInsideRoot as Ut, CLAUDECODE_LOCAL_RULE_FILE_NAME as V, RULESYNC_CONFIG_SCHEMA_URL as Vn, assertLandingOutsideVcsMetadata as Vt, CLAUDECODE_SKILLS_DIR_PATH as W, RULESYNC_HOOKS_RELATIVE_FILE_PATH as Wn, assertTreeContainsNoSymlinks as Wt, RulesyncSubagent as X, RULESYNC_PERMISSIONS_RELATIVE_FILE_PATH as Xn, fileExists as Xt, getLocalSkillDirNames as Y, RULESYNC_NPM_SOURCES_LOCK_RELATIVE_FILE_PATH as Yn, ensureDir as Yt, RulesyncSubagentFrontmatterSchema as Z, RULESYNC_PERMISSIONS_SCHEMA_URL as Zn, fileExistsStrict as Zt, SkillsProcessor as _, removeFileWithoutFollowingSymlinks as _n, mergeInputRootConfigs as _t, convertFromTool as a, listDirectoryEntryNames as an, formatMegabytes as ar, RulesyncHooks as at, REASONIX_LOCAL_RULE_FILE_NAME as b, resolvedRelativePath as bn, CONFLICTING_TARGET_PAIRS as bt, ELLIPSIS_WIDTH as c, normalizePosixDirPath as cn, hasEnclosingMarkOutsideKeycap as cr, RulesyncCommand as ct, McpProcessor as d, readFileContent as dn, stripControlCharactersKeepingLineFeeds as dr, RulesyncCheckFrontmatterSchema as dt, getHomeDirectory as en, RULESYNC_SKILLS_RELATIVE_DIR_PATH as er, RulesyncRule as et, IgnoreProcessor as f, readFileContentOrNull as fn, stripControlCharactersKeepingLineFeedsAndTabs as fr, stringifyFrontmatter as ft, SubagentsProcessor as g, removeFileStrict as gn, ConfigResolver as gt, RulesProcessor as h, removeFile as hn, SKILL_FILE_NAME as ht, inspectInputRoots as i, isSymlink as in, RULESYNC_XDG_CONFIG_HOME_DEFAULT_DIR_NAME as ir, RulesyncIgnore as it, AUGMENTCODE_DIR as j, ALL_FEATURES as jn, warnOnConflictingFlags as jt, CODEBUDDY_DIR as k, PACKAGING_TOOL_TARGETS as kn, WarningCollectingLogger as kt, displayWidthOf as l, pathEscapesRoot as ln, quoteForLog as lr, RulesyncCommandFrontmatterSchema as lt, ChecksProcessor as m, removeDirectoryStrict as mn, SHARED_USER_MANAGED_CONFIG_PATHS as mt, formatSourceLoadFailure as n, isFileSystemError as nn, RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH as nr, RulesyncPermissions as nt, getProcessorRegistryEntry as o, listFilePathsRecursively as on, formatError as or, getRulesyncSourceCandidates as ot, HooksProcessor as p, removeDirectory as pn, stripHiddenCharacters as pr, isRecord as pt, classifyRemoteName as q, RULESYNC_MCP_RELATIVE_FILE_PATH as qn, createTempDirectory as qt, generate as r, isRootDirPath as rn, RULESYNC_USER_CONFIG_DIR_NAME as rr, RulesyncMcp as rt, parseCommaSeparatedList as s, listSubdirectoryNames as sn, truncateText as sr, resolveRulesyncSourceWritePath as st, importFromTool as t, isFileNotFoundError as tn, RULESYNC_SOURCES_LOCK_RELATIVE_FILE_PATH as tr, RulesyncRuleFrontmatterSchema as tt, shortenToWidth as u, posixRelativePathEscapesRoot as un, stripControlCharacters as ur, RulesyncCheck as ut, CRUSH_LOCAL_RULE_FILE_NAME as v, removeTempDirectory as vn, parseConfigFileContent as vt, LETTACODE_SETTINGS_LOCAL_FILE_NAME as w, writeFileBuffer as wn, assertTargetsFeaturesExclusive as wt, QWENCODE_DIR as x, runWithDirectoryRollback as xn, ConfigFileSchema as xt, CommandsProcessor as y, resolvePath as yn, resolveEffectiveInputRoots as yt, CLAUDECODE_AGENT_MEMORY_LOCAL_DIR_NAME as z, RULESYNC_COMMANDS_RELATIVE_DIR_PATH as zn, applyFileMode as zt };
|
|
107996
108197
|
|
|
107997
|
-
//# sourceMappingURL=import-
|
|
108198
|
+
//# sourceMappingURL=import-9NB0tQm3.js.map
|