@agent-facets/adapter-claude-code 0.4.3 → 0.4.5

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 (2) hide show
  1. package/dist/index.mjs +82 -39
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -6,22 +6,6 @@ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
6
6
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
7
7
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
8
8
  //#endregion
9
- //#region ../../common/src/text.ts
10
- /**
11
- * Small text-normalization helpers used across packages that parse
12
- * user-authored files. Lives in `common` so core front-matter parsing and
13
- * the adapter SDK's asset-fs helpers can share one definition — Windows
14
- * line endings or a stray BOM shouldn't cause divergent behavior across
15
- * readers.
16
- */
17
- /**
18
- * Strip a leading UTF-8 BOM and convert any `\r\n` / `\r` line endings to
19
- * `\n`. Idempotent. Returns the string unchanged if already normalized.
20
- */
21
- function normalizeLineEndings(raw) {
22
- return raw.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
23
- }
24
- //#endregion
25
9
  //#region ../../../node_modules/.bun/yaml@2.8.3/node_modules/yaml/dist/nodes/identity.js
26
10
  var require_identity = /* @__PURE__ */ __commonJSMin(((exports) => {
27
11
  const ALIAS = Symbol.for("yaml.alias");
@@ -6570,7 +6554,7 @@ var require_public_api = /* @__PURE__ */ __commonJSMin(((exports) => {
6570
6554
  exports.stringify = stringify;
6571
6555
  }));
6572
6556
  //#endregion
6573
- //#region ../../adapter/src/asset-fs.ts
6557
+ //#region ../../common/src/text.ts
6574
6558
  var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
6575
6559
  var composer = require_composer();
6576
6560
  var Document = require_Document();
@@ -6618,6 +6602,69 @@ var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
6618
6602
  exports.visitAsync = visit.visitAsync;
6619
6603
  })))();
6620
6604
  /**
6605
+ * Small text-normalization helpers used across packages that parse
6606
+ * user-authored files. Lives in `common` so core front-matter parsing and
6607
+ * the adapter SDK's asset-fs helpers can share one definition — Windows
6608
+ * line endings or a stray BOM shouldn't cause divergent behavior across
6609
+ * readers.
6610
+ */
6611
+ /**
6612
+ * Strip a leading UTF-8 BOM and convert any `\r\n` / `\r` line endings to
6613
+ * `\n`. Idempotent. Returns the string unchanged if already normalized.
6614
+ */
6615
+ function normalizeLineEndings(raw) {
6616
+ return raw.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
6617
+ }
6618
+ //#endregion
6619
+ //#region ../../common/src/front-matter.ts
6620
+ /**
6621
+ * Split a string into a body without front matter and the parsed YAML
6622
+ * front-matter metadata, when present.
6623
+ *
6624
+ * Used by:
6625
+ * - the adapter SDK's `splitAssetContent` (and via it, every adapter's
6626
+ * read path) to recover the body + metadata from on-disk asset files.
6627
+ * - core's materialize skip-if-identical compare to normalize the
6628
+ * candidate write content the same way the read path would, so the
6629
+ * body comparison is symmetric.
6630
+ *
6631
+ * Lives in `common` because both the adapter SDK and `core` need
6632
+ * identical splitting semantics. A core-side implementation that
6633
+ * imported `splitAssetContent` from the adapter SDK directly would
6634
+ * pull `yaml` and friends into `core`'s runtime graph, which collides
6635
+ * with `Bun.build` when the CLI's adapter integration tests bundle the
6636
+ * same source files in the same process. Putting the primitive here
6637
+ * means both packages get the same code without a cross-package value
6638
+ * import.
6639
+ *
6640
+ * Returns `{ content: <normalized raw> }` when no front matter is
6641
+ * detected or the YAML is malformed.
6642
+ *
6643
+ * Known limitation: the regex below is non-greedy, so a body that
6644
+ * legitimately contains a literal `---` terminator line will be split
6645
+ * at the first match. Skills and commands rarely contain frontmatter-
6646
+ * shaped content inside their bodies, so in practice this is benign;
6647
+ * a parser swap (e.g., `gray-matter`) is the right fix when needed.
6648
+ */
6649
+ const FRONT_MATTER_RE = /^---\n([\s\S]*?)\n---\n?([\s\S]*)$/;
6650
+ function splitFrontMatter(raw) {
6651
+ const normalized = normalizeLineEndings(raw);
6652
+ const match = normalized.match(FRONT_MATTER_RE);
6653
+ if (!match) return { content: normalized };
6654
+ try {
6655
+ const parsed = (0, import_dist.parse)(match[1] ?? "");
6656
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return {
6657
+ content: match[2] ?? "",
6658
+ metadata: parsed
6659
+ };
6660
+ return { content: normalized };
6661
+ } catch {
6662
+ return { content: normalized };
6663
+ }
6664
+ }
6665
+ //#endregion
6666
+ //#region ../../adapter/src/asset-fs.ts
6667
+ /**
6621
6668
  * Write `body` to `path.file`, prepending YAML front-matter assembled from
6622
6669
  * `metadata` when non-empty. Creates parent directories. Overwrites
6623
6670
  * unconditionally (idempotent by contract — see Adjustment B).
@@ -6650,11 +6697,21 @@ async function deleteAssetFile(path) {
6650
6697
  await rm(path.file, { force: true });
6651
6698
  await rm(`${path.file}.meta.json`, { force: true });
6652
6699
  }
6653
- const FRONT_MATTER_RE = /^---\n([\s\S]*?)\n---\n?([\s\S]*)$/;
6654
6700
  /**
6655
6701
  * Assemble a full file string from optional front-matter metadata + body.
6656
6702
  * When `body` already contains a front-matter block, the two are merged
6657
6703
  * (`metadata` wins on key collision) so external keys on the body survive.
6704
+ *
6705
+ * The output is exactly `---\n<yaml>\n---\n<body>` — no separator newline
6706
+ * between the closing fence and the body. This is the inverse of
6707
+ * `splitAssetContent`'s regex (which consumes one `\n` after `---`), so
6708
+ * `assemble → write → read → split` is byte-stable.
6709
+ *
6710
+ * Earlier versions inserted a cosmetic blank line between the fence and
6711
+ * the body; that asymmetry caused materialize's skip-if-identical check
6712
+ * to see phantom drift on every re-install (`# body` going in, `\n# body`
6713
+ * coming out). Tests in this file's "round-trip" describe block enforce
6714
+ * the inverse contract explicitly.
6658
6715
  */
6659
6716
  function assembleAssetContent(body, metadata) {
6660
6717
  const existing = splitAssetContent(body);
@@ -6664,35 +6721,21 @@ function assembleAssetContent(body, metadata) {
6664
6721
  };
6665
6722
  const bodyOnly = existing.content;
6666
6723
  if (Object.keys(merged).length === 0) return bodyOnly;
6667
- return `---\n${(0, import_dist.stringify)(merged).trimEnd()}\n---\n${bodyOnly.length === 0 || bodyOnly.startsWith("\n") ? "" : "\n"}${bodyOnly}`;
6724
+ return `---\n${(0, import_dist.stringify)(merged).trimEnd()}\n---\n${bodyOnly}`;
6668
6725
  }
6669
6726
  /**
6670
6727
  * Parse a file string into its body + parsed front-matter metadata. Returns
6671
6728
  * the raw string as `content` when no front-matter is detected. Malformed
6672
6729
  * YAML falls back to "no front-matter."
6673
6730
  *
6674
- * Known limitation (tracked as a post-alpha TODO see plan F10): the regex
6675
- * below is non-greedy, so if a body legitimately contains a literal line of
6676
- * exactly `---` followed by content and another `---` line, the first
6677
- * terminator wins and the body will be split in the wrong place. Skills and
6678
- * commands rarely include frontmatter-shaped content inside their bodies,
6679
- * so in practice this is benign — but replacing the regex with `gray-matter`
6680
- * or an equivalent well-tested parser is the right fix.
6731
+ * Thin re-export over `@agent-facets/common`'s `splitFrontMatter` so the
6732
+ * adapter SDK and `core` share one canonical implementation. Kept as a
6733
+ * named export here because adapter authors may import it directly when
6734
+ * they customize their read path; `common` is bundled into the published
6735
+ * adapter SDK so this stays a leaf import for consumers.
6681
6736
  */
6682
6737
  function splitAssetContent(raw) {
6683
- const normalized = normalizeLineEndings(raw);
6684
- const match = normalized.match(FRONT_MATTER_RE);
6685
- if (!match) return { content: normalized };
6686
- try {
6687
- const parsed = (0, import_dist.parse)(match[1] ?? "");
6688
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return {
6689
- content: match[2] ?? "",
6690
- metadata: parsed
6691
- };
6692
- return { content: normalized };
6693
- } catch {
6694
- return { content: normalized };
6695
- }
6738
+ return splitFrontMatter(raw);
6696
6739
  }
6697
6740
  //#endregion
6698
6741
  //#region ../../adapter/src/define-adapter.ts
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "https://github.com/agent-facets/facets",
6
6
  "directory": "packages/adapters/claude-code"
7
7
  },
8
- "version": "0.4.3",
8
+ "version": "0.4.5",
9
9
  "type": "module",
10
10
  "files": [
11
11
  "dist"