agent-manifesto-kit 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +60 -1
  2. package/collection/bundles/blender-3d/README.md +41 -0
  3. package/collection/bundles/blender-3d/agents/visual-reviewer.md +51 -0
  4. package/collection/bundles/blender-3d/skills/blender-mocap-retarget/SKILL.md +96 -0
  5. package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/check_motion.py +162 -0
  6. package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/export_gltf_clip.py +71 -0
  7. package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/godot_verify.py +87 -0
  8. package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/inspect_motion_source.py +107 -0
  9. package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/render_frames.py +117 -0
  10. package/collection/bundles/blender-3d/skills/blender-mocap-retarget/scripts/verify_gltf.py +44 -0
  11. package/collection/bundles/blender-3d/skills/blender-reference-model/SKILL.md +83 -0
  12. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/colors.py +50 -0
  13. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/compare.py +77 -0
  14. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/contact_sheet.py +51 -0
  15. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/diff_renders.py +58 -0
  16. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/edges.py +54 -0
  17. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/measure_ref.py +137 -0
  18. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/mesh_report.py +67 -0
  19. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/refspec.py +91 -0
  20. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/render_views.py +99 -0
  21. package/collection/bundles/blender-3d/skills/blender-reference-model/scripts/zoom.py +47 -0
  22. package/collection/bundles/kit-adopt/README.md +1 -1
  23. package/collection/bundles/kit-adopt/skills/kit-adopt/SKILL.md +2 -2
  24. package/dist/agent-format.js +218 -0
  25. package/dist/catalog.js +13 -13
  26. package/dist/cli.js +57 -2
  27. package/dist/commands/adopt.js +13 -3
  28. package/dist/commands/ingest.js +120 -0
  29. package/dist/commands/sync.js +201 -0
  30. package/dist/portability.js +19 -2
  31. package/dist/providers.js +12 -2
  32. package/package.json +1 -1
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Canonical agents are Claude-style Markdown: YAML frontmatter (`name`, `description`, optional
3
+ * Claude keys such as `tools`, optional `codex:` block) followed by the instruction body.
4
+ * Codex reads custom agents as TOML with `name`, `description` and `developer_instructions`.
5
+ */
6
+ const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
7
+ function unquote(raw) {
8
+ const v = raw.trim();
9
+ if (v.length >= 2 && v.startsWith('"') && v.endsWith('"')) {
10
+ return v.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\");
11
+ }
12
+ if (v.length >= 2 && v.startsWith("'") && v.endsWith("'"))
13
+ return v.slice(1, -1).replace(/''/g, "'");
14
+ return v;
15
+ }
16
+ function indentOf(line) {
17
+ return line.length - line.trimStart().length;
18
+ }
19
+ /**
20
+ * Minimal frontmatter reader: scalar keys, quoted values, `>`/`|` block scalars, and one level of
21
+ * nested `key:` mappings. Enough for capability metadata; not a general YAML parser.
22
+ */
23
+ export function parseMarkdown(text) {
24
+ const m = FRONTMATTER.exec(text);
25
+ if (!m)
26
+ return { frontmatter: {}, body: text };
27
+ const lines = m[1].split(/\r?\n/);
28
+ const fm = {};
29
+ let i = 0;
30
+ while (i < lines.length) {
31
+ const line = lines[i];
32
+ const kv = /^([A-Za-z0-9_.-]+):\s*(.*)$/.exec(line);
33
+ if (!kv || indentOf(line) > 0) {
34
+ i++;
35
+ continue;
36
+ }
37
+ const [, key, rest] = kv;
38
+ i++;
39
+ if (/^[>|][+-]?$/.test(rest)) {
40
+ const folded = rest.startsWith(">");
41
+ const block = [];
42
+ while (i < lines.length && (lines[i].trim() === "" || indentOf(lines[i]) > 0)) {
43
+ block.push(lines[i].trim());
44
+ i++;
45
+ }
46
+ fm[key] = folded ? block.join(" ").replace(/\s+/g, " ").trim() : block.join("\n").trim();
47
+ }
48
+ else if (rest === "") {
49
+ const nested = {};
50
+ while (i < lines.length && (lines[i].trim() === "" || indentOf(lines[i]) > 0)) {
51
+ const sub = /^\s+([A-Za-z0-9_.-]+):\s*(.*)$/.exec(lines[i]);
52
+ if (sub)
53
+ nested[sub[1]] = unquote(sub[2]);
54
+ i++;
55
+ }
56
+ fm[key] = nested;
57
+ }
58
+ else {
59
+ fm[key] = unquote(rest);
60
+ }
61
+ }
62
+ return { frontmatter: fm, body: text.slice(m[0].length) };
63
+ }
64
+ function tomlString(value) {
65
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\r?\n/g, "\\n").replace(/\t/g, "\\t")}"`;
66
+ }
67
+ function tomlMultiline(value) {
68
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"""/g, '""\\"');
69
+ return `"""\n${escaped}${escaped.endsWith("\n") ? "" : "\n"}"""`;
70
+ }
71
+ function tomlValue(raw) {
72
+ if (/^(true|false)$/.test(raw) || /^-?\d+(\.\d+)?$/.test(raw))
73
+ return raw;
74
+ return tomlString(raw);
75
+ }
76
+ /** Claude tools that let an agent change files. Their absence means the agent is read-only. */
77
+ const WRITE_TOOLS = ["Edit", "Write", "MultiEdit", "NotebookEdit"];
78
+ /** Render a canonical Markdown agent as a Codex custom-agent TOML file. */
79
+ export function markdownAgentToCodexToml(markdown, fallbackName) {
80
+ const { frontmatter, body } = parseMarkdown(markdown);
81
+ const str = (k) => (typeof frontmatter[k] === "string" ? frontmatter[k] : "");
82
+ const name = str("name") || fallbackName;
83
+ const codex = typeof frontmatter.codex === "object" ? frontmatter.codex : {};
84
+ const extras = { ...codex };
85
+ const tools = str("tools");
86
+ if (tools && extras.sandbox_mode === undefined) {
87
+ const list = tools.split(",").map((t) => t.trim());
88
+ if (!list.some((t) => WRITE_TOOLS.includes(t)))
89
+ extras.sandbox_mode = "read-only";
90
+ }
91
+ // A read-only tool list survives as sandbox_mode, so it is translated rather than dropped.
92
+ const translated = extras.sandbox_mode === "read-only" && codex.sandbox_mode === undefined ? ["tools"] : [];
93
+ const dropped = Object.keys(frontmatter).filter((k) => !["name", "description", "codex", ...translated].includes(k));
94
+ const reserved = new Set(["name", "description", "developer_instructions"]);
95
+ const lines = [`name = ${tomlString(name)}`, `description = ${tomlString(str("description"))}`];
96
+ for (const [k, v] of Object.entries(extras)) {
97
+ if (!reserved.has(k))
98
+ lines.push(`${k} = ${tomlValue(v)}`);
99
+ }
100
+ lines.push(`developer_instructions = ${tomlMultiline(body.replace(/^\s*\n/, ""))}`);
101
+ return { toml: lines.join("\n") + "\n", dropped };
102
+ }
103
+ function unescapeBasic(raw) {
104
+ return raw.replace(/\\(u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|.)/g, (_, e) => {
105
+ if (e[0] === "u" || e[0] === "U")
106
+ return String.fromCodePoint(parseInt(e.slice(1), 16));
107
+ return { n: "\n", t: "\t", r: "\r", b: "\b", f: "\f", '"': '"', "\\": "\\" }[e] ?? e;
108
+ });
109
+ }
110
+ /**
111
+ * Read the top-level scalar keys of a Codex agent TOML file. Tables and arrays (for example
112
+ * `[mcp_servers]`) are reported as skipped; they are tool configuration, not agent intent.
113
+ */
114
+ export function parseAgentToml(text) {
115
+ const values = {};
116
+ const skipped = [];
117
+ let rest = text.replace(/\r\n/g, "\n");
118
+ let inTable = false;
119
+ while (rest.length > 0) {
120
+ const nl = rest.indexOf("\n");
121
+ const line = (nl === -1 ? rest : rest.slice(0, nl)).trim();
122
+ if (line === "" || line.startsWith("#")) {
123
+ rest = nl === -1 ? "" : rest.slice(nl + 1);
124
+ continue;
125
+ }
126
+ if (line.startsWith("[")) {
127
+ inTable = true;
128
+ skipped.push(line.replace(/^\[+|\]+$/g, ""));
129
+ rest = nl === -1 ? "" : rest.slice(nl + 1);
130
+ continue;
131
+ }
132
+ const kv = /^\s*([A-Za-z0-9_-]+|"[^"]+")\s*=\s*/.exec(rest);
133
+ if (!kv)
134
+ throw new Error(`cannot parse TOML line: ${line}`);
135
+ const key = kv[1].replace(/^"|"$/g, "");
136
+ rest = rest.slice(kv[0].length);
137
+ let value;
138
+ let consumed;
139
+ if (rest.startsWith('"""') || rest.startsWith("'''")) {
140
+ const q = rest.slice(0, 3);
141
+ let end = 3;
142
+ for (;;) {
143
+ end = rest.indexOf(q, end);
144
+ if (end === -1)
145
+ throw new Error(`unterminated multi-line string for "${key}"`);
146
+ if (q === '"""' && rest[end - 1] === "\\" && rest[end - 2] !== "\\") {
147
+ end += 1;
148
+ continue;
149
+ }
150
+ while (rest[end + 3] === q[0])
151
+ end++;
152
+ break;
153
+ }
154
+ const raw = rest.slice(3, end).replace(/^\n/, "");
155
+ value = q === '"""' ? unescapeBasic(raw.replace(/\\\n\s*/g, "")) : raw;
156
+ consumed = end + 3;
157
+ }
158
+ else if (rest.startsWith('"')) {
159
+ const m = /^"((?:[^"\\\n]|\\.)*)"/.exec(rest);
160
+ if (!m)
161
+ throw new Error(`unterminated string for "${key}"`);
162
+ value = unescapeBasic(m[1]);
163
+ consumed = m[0].length;
164
+ }
165
+ else if (rest.startsWith("'")) {
166
+ const m = /^'([^'\n]*)'/.exec(rest);
167
+ if (!m)
168
+ throw new Error(`unterminated string for "${key}"`);
169
+ value = m[1];
170
+ consumed = m[0].length;
171
+ }
172
+ else {
173
+ const m = /^([^\n#]*)/.exec(rest);
174
+ const token = m[1].trim();
175
+ if (token === "true" || token === "false")
176
+ value = token === "true";
177
+ else if (/^[+-]?\d+(\.\d+)?$/.test(token))
178
+ value = Number(token);
179
+ else
180
+ skipped.push(key);
181
+ consumed = m[0].length;
182
+ }
183
+ if (value !== undefined && !inTable)
184
+ values[key] = value;
185
+ rest = rest.slice(consumed);
186
+ const eol = rest.indexOf("\n");
187
+ rest = eol === -1 ? "" : rest.slice(eol + 1);
188
+ }
189
+ return { values, skipped };
190
+ }
191
+ function yamlScalar(value) {
192
+ return /^[\w .,/()'-]*$/.test(value) && !/^[\s'-]/.test(value) && !value.includes(": ")
193
+ ? value
194
+ : `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
195
+ }
196
+ /** Claude tools granted to an ingested Codex agent whose sandbox is read-only. */
197
+ const READ_ONLY_TOOLS = "Read, Grep, Glob, Bash";
198
+ /** Convert a Codex agent TOML file into a canonical Markdown agent. */
199
+ export function codexTomlAgentToMarkdown(text) {
200
+ const { values, skipped } = parseAgentToml(text);
201
+ for (const key of ["name", "description", "developer_instructions"]) {
202
+ if (typeof values[key] !== "string" || values[key].trim() === "") {
203
+ throw new Error(`Codex agent is missing required string "${key}"`);
204
+ }
205
+ }
206
+ const lines = ["---", `name: ${yamlScalar(values.name)}`, `description: ${yamlScalar(values.description)}`];
207
+ if (values.sandbox_mode === "read-only")
208
+ lines.push(`tools: ${READ_ONLY_TOOLS}`);
209
+ const extras = Object.entries(values).filter(([k]) => !["name", "description", "developer_instructions"].includes(k));
210
+ if (extras.length > 0) {
211
+ lines.push("codex:");
212
+ for (const [k, v] of extras)
213
+ lines.push(` ${k}: ${typeof v === "string" ? yamlScalar(v) : String(v)}`);
214
+ }
215
+ lines.push("---", "");
216
+ const body = values.developer_instructions.replace(/^\n+/, "");
217
+ return { markdown: lines.join("\n") + "\n" + body + (body.endsWith("\n") ? "" : "\n"), skipped };
218
+ }
package/dist/catalog.js CHANGED
@@ -6,11 +6,11 @@ export function packageRoot() {
6
6
  const here = dirname(fileURLToPath(import.meta.url));
7
7
  return dirname(here);
8
8
  }
9
- function collectionDir() {
10
- return join(packageRoot(), "collection");
9
+ function collectionDir(root = packageRoot()) {
10
+ return join(root, "collection");
11
11
  }
12
- function bundlesDir() {
13
- return join(collectionDir(), "bundles");
12
+ function bundlesDir(root) {
13
+ return join(collectionDir(root), "bundles");
14
14
  }
15
15
  function parseFrontmatter(text) {
16
16
  const out = {};
@@ -107,8 +107,8 @@ function scanTypeDir(base, type, bundle) {
107
107
  }
108
108
  const ALL_TYPES = ["skill", "agent", "pipeline", "convention"];
109
109
  /** Bundles found under collection/bundles/, each a cohesive, independently adoptable unit. */
110
- export function scanBundles() {
111
- const root = bundlesDir();
110
+ export function scanBundles(kitRoot) {
111
+ const root = bundlesDir(kitRoot);
112
112
  if (!existsSync(root))
113
113
  return [];
114
114
  const bundles = [];
@@ -129,18 +129,18 @@ export function scanBundles() {
129
129
  return bundles;
130
130
  }
131
131
  /** All individually addressable capabilities: flat collection items plus every bundle's items. */
132
- export function scanCatalog() {
133
- const root = collectionDir();
132
+ export function scanCatalog(kitRoot) {
133
+ const root = collectionDir(kitRoot);
134
134
  const flat = ALL_TYPES.flatMap((t) => scanTypeDir(root, t));
135
- const bundled = scanBundles().flatMap((b) => b.items);
135
+ const bundled = scanBundles(kitRoot).flatMap((b) => b.items);
136
136
  return [...flat, ...bundled];
137
137
  }
138
- export function findCapability(name) {
139
- const matches = scanCatalog().filter((c) => c.name === name);
138
+ export function findCapability(name, kitRoot) {
139
+ const matches = scanCatalog(kitRoot).filter((c) => c.name === name);
140
140
  if (matches.length === 1)
141
141
  return { match: matches[0], ambiguous: [] };
142
142
  return { ambiguous: matches.length > 1 ? matches : [] };
143
143
  }
144
- export function findBundle(name) {
145
- return scanBundles().find((b) => b.name === name);
144
+ export function findBundle(name, kitRoot) {
145
+ return scanBundles(kitRoot).find((b) => b.name === name);
146
146
  }
package/dist/cli.js CHANGED
@@ -4,6 +4,8 @@ import { join } from "node:path";
4
4
  import { list } from "./commands/list.js";
5
5
  import { adopt, isSupportedCli, SUPPORTED_CLIS } from "./commands/adopt.js";
6
6
  import { runLint } from "./commands/lint.js";
7
+ import { ingest } from "./commands/ingest.js";
8
+ import { sync, SYNC_PROVIDERS } from "./commands/sync.js";
7
9
  import { isProvider } from "./providers.js";
8
10
  import { packageRoot } from "./catalog.js";
9
11
  function version() {
@@ -15,6 +17,8 @@ function version() {
15
17
  return "unknown";
16
18
  }
17
19
  }
20
+ /** Flags that never take a value, so a following positional is not swallowed. */
21
+ const BOOLEAN_FLAGS = new Set(["force", "replace", "dry-run", "help", "version"]);
18
22
  function parseArgs(args) {
19
23
  const positionals = [];
20
24
  const flags = {};
@@ -23,7 +27,7 @@ function parseArgs(args) {
23
27
  if (arg.startsWith("--")) {
24
28
  const key = arg.slice(2);
25
29
  const next = args[i + 1];
26
- if (next !== undefined && !next.startsWith("-")) {
30
+ if (!BOOLEAN_FLAGS.has(key) && next !== undefined && !next.startsWith("-")) {
27
31
  flags[key] = next;
28
32
  i++;
29
33
  }
@@ -47,20 +51,34 @@ Usage:
47
51
  agentkit list [skills|agents|bundles]
48
52
  agentkit lint [name]
49
53
  agentkit adopt <name> [--provider claude|codex|agnostic] [--dest <dir>] [--force] [--cli <cli>]
54
+ agentkit ingest <path> [--bundle <name>] [--replace] [--kit <dir>]
55
+ agentkit sync [<name>...] [--provider claude,codex] [--remove <name,...>] [--dest <dir>] [--force] [--dry-run]
50
56
 
51
57
  <name> is a capability (skill/agent/pipeline/convention) or a bundle.
52
58
  Adopting a bundle explodes it into type-specific directories.
53
59
 
54
60
  list accepts one exact lowercase selector. Without a selector it shows the full catalog.
55
61
 
62
+ ingest imports a skill folder (SKILL.md), a Claude agent .md, or a Codex agent .toml
63
+ into the kit's collection/ as a canonical Claude-style capability.
64
+
65
+ sync keeps hard copies of skills and agents in the project's native Claude and Codex
66
+ locations. Names add to the sync set recorded in .agentkit-lock.json; without names it
67
+ refreshes that set. Locally edited files are kept and reported unless --force is given.
68
+
56
69
  Pass --cli to run an AI assistant after adoption to adapt the files to your project.
57
70
  Pass --force to overwrite existing targets without prompting.
58
71
 
59
72
  Options:
60
- --provider target AI provider (default: claude)
73
+ --provider target AI provider (default: claude; sync: claude,codex)
61
74
  --cli AI CLI to run after adoption for project-specific adaptation
62
75
  supported: ${SUPPORTED_CLIS.join("|")}
63
76
  --force overwrite existing targets without prompting
77
+ --bundle ingest into collection/bundles/<name>/ instead of the flat collection
78
+ --replace let ingest overwrite an existing item at the same location
79
+ --kit kit checkout whose collection/ ingest writes to (default: this package)
80
+ --remove comma-separated names to drop from the sync set
81
+ --dry-run show what sync would change without writing
64
82
  --dest target project root (default: current directory)
65
83
  --version,-v print the installed version
66
84
  --help,-h show this help`);
@@ -108,6 +126,43 @@ async function main() {
108
126
  const force = flags.force === true;
109
127
  return adopt({ name, provider, projectRoot, force, cli });
110
128
  }
129
+ case "ingest": {
130
+ const source = positionals[1];
131
+ if (!source || positionals.length > 2) {
132
+ console.error("ingest requires exactly one <path>: a skill folder, an agent .md, or a Codex agent .toml.");
133
+ return 1;
134
+ }
135
+ return ingest({
136
+ source,
137
+ bundle: typeof flags.bundle === "string" ? flags.bundle : undefined,
138
+ kitRoot: typeof flags.kit === "string" ? flags.kit : undefined,
139
+ replace: flags.replace === true,
140
+ });
141
+ }
142
+ case "sync": {
143
+ let providers;
144
+ if (flags.provider !== undefined) {
145
+ const list = typeof flags.provider === "string" ? flags.provider.split(",").map((p) => p.trim()) : [];
146
+ const bad = list.filter((p) => !SYNC_PROVIDERS.includes(p));
147
+ if (list.length === 0 || bad.length > 0) {
148
+ console.error(`Invalid --provider "${String(flags.provider)}". sync supports: ${SYNC_PROVIDERS.join(",")}.`);
149
+ return 1;
150
+ }
151
+ providers = [...new Set(list)];
152
+ }
153
+ if (flags.remove === true) {
154
+ console.error("--remove needs a comma-separated list of names.");
155
+ return 1;
156
+ }
157
+ return sync({
158
+ names: positionals.slice(1),
159
+ remove: typeof flags.remove === "string" ? flags.remove.split(",").map((n) => n.trim()).filter(Boolean) : [],
160
+ providers,
161
+ projectRoot: typeof flags.dest === "string" ? flags.dest : process.cwd(),
162
+ force: flags.force === true,
163
+ dryRun: flags["dry-run"] === true,
164
+ });
165
+ }
111
166
  default:
112
167
  console.error(`Unknown command "${cmd}". Run "agentkit --help".`);
113
168
  return 1;
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
5
5
  import { dirname, join, relative } from "node:path";
6
6
  import { findBundle, findCapability } from "../catalog.js";
7
7
  import { bundleExtrasDestination, destinationFor, wiringHint } from "../providers.js";
8
- import { lint, transform } from "../portability.js";
8
+ import { lint, renderAgent, transform } from "../portability.js";
9
9
  export const SUPPORTED_CLIS = [
10
10
  "claude", "codex", "agy", "aider", "opencode", "grok", "kilo", "qwen",
11
11
  ];
@@ -185,6 +185,16 @@ function surfaceCompanions(recommendsPath) {
185
185
  console.log(r);
186
186
  console.log("Adopt any you want with: agentkit adopt <name>");
187
187
  }
188
+ /** Render a single-file capability in the provider's native format, reporting dropped metadata. */
189
+ export function renderFile(cap, content, provider) {
190
+ if (cap.type !== "agent")
191
+ return transform(content, provider);
192
+ const { content: rendered, dropped } = renderAgent(content, provider, cap.name);
193
+ if (dropped.length > 0) {
194
+ console.warn(`warning: ${cap.name}: frontmatter ${dropped.join(", ")} has no ${provider} equivalent and was not carried over.`);
195
+ }
196
+ return rendered;
197
+ }
188
198
  const CAPABILITY_DIRS = new Set(["skills", "agents", "pipelines", "conventions"]);
189
199
  async function adoptBundle(bundle, opts, onFile) {
190
200
  let bulkAction = null;
@@ -233,7 +243,7 @@ async function adoptBundle(bundle, opts, onFile) {
233
243
  for (const f of lint(content)) {
234
244
  console.warn(`warning: ${item.name}:${f.line} contains "${f.token}" — review for ${opts.provider}.`);
235
245
  }
236
- writeFileSync(target, transform(content, opts.provider));
246
+ writeFileSync(target, renderFile(item, content, opts.provider));
237
247
  onFile?.(target);
238
248
  }
239
249
  }
@@ -283,7 +293,7 @@ async function adoptSingle(match, opts, onFile) {
283
293
  }
284
294
  }
285
295
  else {
286
- writeFileSync(target, transform(readFileSync(match.sourceCopyPath, "utf8"), opts.provider));
296
+ writeFileSync(target, renderFile(match, readFileSync(match.sourceCopyPath, "utf8"), opts.provider));
287
297
  onFile?.(target);
288
298
  }
289
299
  console.log(`Adopted ${match.type} "${match.name}" (${opts.provider}) -> ${target}`);
@@ -0,0 +1,120 @@
1
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
2
+ import { basename, join, relative, resolve } from "node:path";
3
+ import { findCapability, packageRoot } from "../catalog.js";
4
+ import { codexTomlAgentToMarkdown, parseMarkdown } from "../agent-format.js";
5
+ import { lint } from "../portability.js";
6
+ const NAME = /^[a-z0-9][a-z0-9-]*$/;
7
+ /** Codex-native locations mapped back to the canonical `.claude/` tokens that adopt/sync rewrite. */
8
+ export function toCanonicalPaths(content) {
9
+ return content
10
+ .replace(/\.codex\/agents\/([A-Za-z0-9_.-]+)\.toml/g, ".claude/agents/$1.md")
11
+ .split(".agents/skills/")
12
+ .join(".claude/skills/");
13
+ }
14
+ function walkFiles(dir) {
15
+ const out = [];
16
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
17
+ if (entry.name.startsWith(".") || entry.name === "__pycache__")
18
+ continue;
19
+ const p = join(dir, entry.name);
20
+ if (entry.isDirectory())
21
+ out.push(...walkFiles(p));
22
+ else
23
+ out.push(p);
24
+ }
25
+ return out;
26
+ }
27
+ function fail(message) {
28
+ console.error(`ingest: ${message}`);
29
+ return 1;
30
+ }
31
+ export function ingest(opts) {
32
+ const source = resolve(opts.source);
33
+ if (!existsSync(source))
34
+ return fail(`source not found: ${opts.source}`);
35
+ const kitRoot = resolve(opts.kitRoot ?? packageRoot());
36
+ const collection = join(kitRoot, "collection");
37
+ if (!existsSync(collection))
38
+ return fail(`no collection/ directory in kit root ${kitRoot}`);
39
+ if (opts.bundle !== undefined && !NAME.test(opts.bundle))
40
+ return fail(`invalid bundle name "${opts.bundle}"`);
41
+ let kind;
42
+ let content;
43
+ let skillDir;
44
+ if (statSync(source).isDirectory()) {
45
+ const skillFile = join(source, "SKILL.md");
46
+ if (!existsSync(skillFile))
47
+ return fail(`${opts.source} is a directory without SKILL.md`);
48
+ kind = "skill";
49
+ skillDir = source;
50
+ content = readFileSync(skillFile, "utf8");
51
+ }
52
+ else if (source.endsWith(".toml")) {
53
+ kind = "agent";
54
+ try {
55
+ const converted = codexTomlAgentToMarkdown(readFileSync(source, "utf8"));
56
+ for (const key of converted.skipped)
57
+ console.warn(`warning: ${basename(source)}: "${key}" is not a scalar setting and was not ingested.`);
58
+ content = converted.markdown;
59
+ }
60
+ catch (err) {
61
+ return fail(`${opts.source}: ${err instanceof Error ? err.message : String(err)}`);
62
+ }
63
+ }
64
+ else if (source.endsWith(".md")) {
65
+ kind = "agent";
66
+ content = readFileSync(source, "utf8");
67
+ }
68
+ else {
69
+ return fail(`unsupported source ${opts.source}: expected a skill folder, an agent .md, or a Codex agent .toml`);
70
+ }
71
+ const { frontmatter } = parseMarkdown(content);
72
+ const fmName = typeof frontmatter.name === "string" ? frontmatter.name : "";
73
+ const fallback = kind === "skill" ? basename(source) : basename(source).replace(/\.(md|toml)$/, "");
74
+ const name = fmName || fallback;
75
+ if (!NAME.test(name))
76
+ return fail(`invalid capability name "${name}" (use lowercase letters, digits and hyphens)`);
77
+ if (typeof frontmatter.description !== "string" || frontmatter.description.trim() === "") {
78
+ return fail(`${name} has no frontmatter description; add one before ingesting`);
79
+ }
80
+ const base = opts.bundle ? join(collection, "bundles", opts.bundle) : collection;
81
+ const target = kind === "skill" ? join(base, "skills", name) : join(base, "agents", `${name}.md`);
82
+ const existing = findCapability(name, kitRoot);
83
+ const clash = [...(existing.match ? [existing.match] : []), ...existing.ambiguous];
84
+ const elsewhere = clash.filter((c) => resolve(c.sourceCopyPath) !== target);
85
+ if (elsewhere.length > 0) {
86
+ return fail(`"${name}" already exists at ${elsewhere.map((c) => relative(kitRoot, c.sourceCopyPath)).join(", ")}; capability names must be unique`);
87
+ }
88
+ if (existsSync(target)) {
89
+ if (!opts.replace)
90
+ return fail(`${relative(kitRoot, target)} already exists; pass --replace to overwrite it`);
91
+ rmSync(target, { recursive: true, force: true });
92
+ }
93
+ const written = [];
94
+ if (skillDir) {
95
+ for (const file of walkFiles(skillDir)) {
96
+ const dest = join(target, relative(skillDir, file));
97
+ mkdirSync(join(dest, ".."), { recursive: true });
98
+ if (file.endsWith(".md"))
99
+ writeFileSync(dest, toCanonicalPaths(readFileSync(file, "utf8")));
100
+ else
101
+ cpSync(file, dest);
102
+ written.push(dest);
103
+ }
104
+ }
105
+ else {
106
+ mkdirSync(join(target, ".."), { recursive: true });
107
+ writeFileSync(target, toCanonicalPaths(content));
108
+ written.push(target);
109
+ }
110
+ for (const file of written.filter((f) => f.endsWith(".md"))) {
111
+ for (const f of lint(readFileSync(file, "utf8"))) {
112
+ console.warn(`warning: ${relative(kitRoot, file)}:${f.line} contains "${f.token}" — make it provider-neutral.`);
113
+ }
114
+ }
115
+ console.log(`Ingested ${kind} "${name}" -> ${relative(kitRoot, target)} (${written.length} file(s))`);
116
+ if (opts.bundle && !existsSync(join(base, "README.md"))) {
117
+ console.log(`Note: bundle "${opts.bundle}" has no README.md yet; its first paragraph becomes the bundle description.`);
118
+ }
119
+ return 0;
120
+ }