@agent-facets/adapter-claude-code 0.4.4 → 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 +70 -38
  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,7 +6697,6 @@ 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
@@ -6682,28 +6728,14 @@ function assembleAssetContent(body, metadata) {
6682
6728
  * the raw string as `content` when no front-matter is detected. Malformed
6683
6729
  * YAML falls back to "no front-matter."
6684
6730
  *
6685
- * Known limitation (tracked as a post-alpha TODO see plan F10): the regex
6686
- * below is non-greedy, so if a body legitimately contains a literal line of
6687
- * exactly `---` followed by content and another `---` line, the first
6688
- * terminator wins and the body will be split in the wrong place. Skills and
6689
- * commands rarely include frontmatter-shaped content inside their bodies,
6690
- * so in practice this is benign — but replacing the regex with `gray-matter`
6691
- * 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.
6692
6736
  */
6693
6737
  function splitAssetContent(raw) {
6694
- const normalized = normalizeLineEndings(raw);
6695
- const match = normalized.match(FRONT_MATTER_RE);
6696
- if (!match) return { content: normalized };
6697
- try {
6698
- const parsed = (0, import_dist.parse)(match[1] ?? "");
6699
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return {
6700
- content: match[2] ?? "",
6701
- metadata: parsed
6702
- };
6703
- return { content: normalized };
6704
- } catch {
6705
- return { content: normalized };
6706
- }
6738
+ return splitFrontMatter(raw);
6707
6739
  }
6708
6740
  //#endregion
6709
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.4",
8
+ "version": "0.4.5",
9
9
  "type": "module",
10
10
  "files": [
11
11
  "dist"