@zenrick/zenkit 0.5.0 → 0.5.1
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/package.json +1 -1
- package/scripts/archive-codex-rollouts.ps1 +35 -0
- package/scripts/bundle.mjs +15 -3
- package/scripts/cli.mjs +23 -5
- package/scripts/content-checks.mjs +18 -0
- package/scripts/doctor.mjs +5 -9
- package/scripts/generate.mjs +19 -7
- package/scripts/layer-remote.mjs +71 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenrick/zenkit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Agentes, skills e regras para assistentes de IA (Cursor, Claude Code, Codex, Gemini CLI), com camadas privadas por pessoa. npx @zenrick/zenkit init",
|
|
6
6
|
"author": "Zenrick",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Archive (not delete) Codex rollout JSONL older than 30 days.
|
|
2
|
+
# Usage: .\scripts\archive-codex-rollouts.ps1 [-CodexHome $env:USERPROFILE\.codex]
|
|
3
|
+
param(
|
|
4
|
+
[string]$CodexHome = $(Join-Path $env:USERPROFILE ".codex"),
|
|
5
|
+
[int]$KeepDays = 30
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
$ErrorActionPreference = "Stop"
|
|
9
|
+
$sessions = Join-Path $CodexHome "sessions"
|
|
10
|
+
$archiveRoot = Join-Path $CodexHome ("archive-rollouts-" + (Get-Date -Format "yyyyMM"))
|
|
11
|
+
|
|
12
|
+
if (-not (Test-Path $sessions)) {
|
|
13
|
+
Write-Host "No sessions dir at $sessions"
|
|
14
|
+
exit 0
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$cutoff = (Get-Date).AddDays(-$KeepDays)
|
|
18
|
+
$targets = Get-ChildItem -Path $sessions -Recurse -Filter "rollout-*.jsonl" -File -ErrorAction SilentlyContinue |
|
|
19
|
+
Where-Object { $_.LastWriteTime -lt $cutoff }
|
|
20
|
+
|
|
21
|
+
if (-not $targets) {
|
|
22
|
+
Write-Host "Nothing to archive (cutoff $cutoff)."
|
|
23
|
+
exit 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
foreach ($file in $targets) {
|
|
27
|
+
$rel = $file.FullName.Substring($sessions.Length).TrimStart('\\', '/')
|
|
28
|
+
$dest = Join-Path $archiveRoot $rel
|
|
29
|
+
$destDir = Split-Path $dest -Parent
|
|
30
|
+
New-Item -ItemType Directory -Force -Path $destDir | Out-Null
|
|
31
|
+
Move-Item -LiteralPath $file.FullName -Destination $dest -Force
|
|
32
|
+
Write-Host "Archived $rel"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Write-Host "Archived $($targets.Count) rollout file(s) under $archiveRoot"
|
package/scripts/bundle.mjs
CHANGED
|
@@ -70,14 +70,26 @@ export async function loadBundleFiles() {
|
|
|
70
70
|
} catch {
|
|
71
71
|
throw new Error(`⛔ ${BUNDLES_DIR} não existe — fail-closed.`);
|
|
72
72
|
}
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
73
|
+
const byName = await readBundleDir(BUNDLES_DIR, entries);
|
|
74
|
+
if (byName.size === 0) {
|
|
75
75
|
throw new Error("⛔ nenhum bundle em kit/bundles — fail-closed.");
|
|
76
76
|
}
|
|
77
|
+
return byName;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Recipes kept in a layer's bundles/ (a paid pack's storefronts); empty when there are none. */
|
|
81
|
+
export async function loadLayerBundles(layerDir) {
|
|
82
|
+
const dir = path.join(layerDir, "bundles");
|
|
83
|
+
const entries = await fs.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
84
|
+
return readBundleDir(dir, entries);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function readBundleDir(dir, entries) {
|
|
88
|
+
const files = entries.filter((e) => e.isFile() && e.name.endsWith(".yaml"));
|
|
77
89
|
const byName = new Map();
|
|
78
90
|
for (const f of files) {
|
|
79
91
|
const stem = f.name.replace(/\.yaml$/, "");
|
|
80
|
-
const raw = await fs.readFile(path.join(
|
|
92
|
+
const raw = await fs.readFile(path.join(dir, f.name), "utf8");
|
|
81
93
|
const data = parseSimpleYaml(raw, f.name);
|
|
82
94
|
const name = (data.name || "").trim();
|
|
83
95
|
if (!name) throw new Error(`${f.name}: sem 'name'`);
|
package/scripts/cli.mjs
CHANGED
|
@@ -38,7 +38,7 @@ Uso:
|
|
|
38
38
|
zenkit layer push DIR
|
|
39
39
|
zenkit layer pull NOME [--version N] [--into DIR]
|
|
40
40
|
zenkit layer list
|
|
41
|
-
zenkit layer pack DIR --out ARQUIVO
|
|
41
|
+
zenkit layer pack DIR --out ARQUIVO [--bundle RECEITA]
|
|
42
42
|
|
|
43
43
|
--layer soma uma camada (diretório com zenkit-layer.yaml) por cima do núcleo;
|
|
44
44
|
repita para empilhar, da mais geral para a mais específica. Sem --layer, vale
|
|
@@ -52,6 +52,8 @@ ZENKIT_ARCHIVE_TOKEN_FILE).
|
|
|
52
52
|
layer push publica uma nova versão da camada no NexusCore (recusa segredo).
|
|
53
53
|
NexusCore: ZENKIT_NEXUS_URL e ZENKIT_NEXUS_KEY (ou ZENKIT_NEXUS_KEY_FILE).
|
|
54
54
|
layer pack gera o arquivo de uma camada (recusa segredo) e mostra o sha256.
|
|
55
|
+
Com --bundle, só o que a receita usa da camada (uma vitrine de um pacote pago),
|
|
56
|
+
conferindo o carimbo de validade das skills fiscal e de privacidade.
|
|
55
57
|
|
|
56
58
|
Sem comando: init no diretório atual (Kit Lite).
|
|
57
59
|
O default copia o recorte para .cursor, .claude e .agents (Codex/Gemini).
|
|
@@ -62,6 +64,18 @@ a skill duas vezes.
|
|
|
62
64
|
|
|
63
65
|
const layerArg = (value) => (isRemoteSpec(value) ? value : path.resolve(value));
|
|
64
66
|
|
|
67
|
+
/** `pack DIR --out FILE [--bundle NAME]`; null when the arguments do not fit. */
|
|
68
|
+
function parsePackFlags(args) {
|
|
69
|
+
const [dir, ...flags] = args;
|
|
70
|
+
const parsed = { dir, out: null, bundle: undefined };
|
|
71
|
+
for (let i = 0; i < flags.length; i += 2) {
|
|
72
|
+
if (flags[i] === "--out" && flags[i + 1]) parsed.out = flags[i + 1];
|
|
73
|
+
else if (flags[i] === "--bundle" && flags[i + 1]) parsed.bundle = flags[i + 1];
|
|
74
|
+
else return null;
|
|
75
|
+
}
|
|
76
|
+
return dir && parsed.out ? parsed : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
65
79
|
export async function runLayer(argv, { env = process.env, fetch, out = process.stdout } = {}) {
|
|
66
80
|
const [sub, ...rest] = argv;
|
|
67
81
|
if (sub === "push" && rest.length === 1) {
|
|
@@ -86,9 +100,13 @@ export async function runLayer(argv, { env = process.env, fetch, out = process.s
|
|
|
86
100
|
out.write(`camada '${name}' v${res.version} em ${res.dir}\n`);
|
|
87
101
|
return res;
|
|
88
102
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
103
|
+
const packFlags = sub === "pack" ? parsePackFlags(rest) : null;
|
|
104
|
+
if (packFlags) {
|
|
105
|
+
const out_ = path.resolve(packFlags.out);
|
|
106
|
+
const packed = await packLayer(path.resolve(packFlags.dir), {
|
|
107
|
+
maxBytes: MAX_ARCHIVE_BYTES,
|
|
108
|
+
bundle: packFlags.bundle,
|
|
109
|
+
});
|
|
92
110
|
await fs.mkdir(path.dirname(out_), { recursive: true });
|
|
93
111
|
await fs.writeFile(out_, packed.bytes);
|
|
94
112
|
out.write(
|
|
@@ -105,7 +123,7 @@ export async function runLayer(argv, { env = process.env, fetch, out = process.s
|
|
|
105
123
|
return layers;
|
|
106
124
|
}
|
|
107
125
|
throw new Error(
|
|
108
|
-
`uso: zenkit layer push DIR | pull NOME [--version N] [--into DIR] | list | pack DIR --out ARQUIVO\n${USAGE}`,
|
|
126
|
+
`uso: zenkit layer push DIR | pull NOME [--version N] [--into DIR] | list | pack DIR --out ARQUIVO [--bundle RECEITA]\n${USAGE}`,
|
|
109
127
|
);
|
|
110
128
|
}
|
|
111
129
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content rules that travel with a skill wherever it ships: the public core
|
|
3
|
+
* (checked by doctor) or a paid pack (checked by `zenkit layer pack --bundle`).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Skills whose output is legal or tax material: they must carry a validity stamp. */
|
|
7
|
+
export const STAMPED = ["negocio-fiscal", "negocio-privacidade"];
|
|
8
|
+
export const STAMP_RE = /legisla[cç][aã]o[^.]{0,80}agosto de 2026/i;
|
|
9
|
+
|
|
10
|
+
/** Problems in a stamped skill's SKILL.md; empty when it is fine. */
|
|
11
|
+
export function stampProblems(name, body) {
|
|
12
|
+
const problems = [];
|
|
13
|
+
if (!STAMP_RE.test(body)) problems.push(`${name} sem carimbo "agosto de 2026"`);
|
|
14
|
+
if (!(/rascunho/i.test(body) && /(contador|advogado)/i.test(body))) {
|
|
15
|
+
problems.push(`${name} não manda validar rascunho com contador/advogado`);
|
|
16
|
+
}
|
|
17
|
+
return problems;
|
|
18
|
+
}
|
package/scripts/doctor.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { fileURLToPath } from "node:url";
|
|
|
13
13
|
import { generateKit, emitPluginPackage } from "./generate.mjs";
|
|
14
14
|
import { loadBundleFiles, resolveBundle } from "./bundle.mjs";
|
|
15
15
|
import { applySlots } from "./layers.mjs";
|
|
16
|
+
import { STAMPED, stampProblems } from "./content-checks.mjs";
|
|
16
17
|
import { expectedMarketplaces, marketplacePaths } from "./marketplace.mjs";
|
|
17
18
|
import { pluginId } from "./product.mjs";
|
|
18
19
|
import { spawnSync } from "node:child_process";
|
|
@@ -27,8 +28,6 @@ const LITE_FORBIDDEN = [
|
|
|
27
28
|
"negocio-agenda",
|
|
28
29
|
"rust-pro",
|
|
29
30
|
];
|
|
30
|
-
const STAMPED = ["negocio-fiscal", "negocio-privacidade"];
|
|
31
|
-
const STAMP_RE = /legisla[cç][aã]o[^.]{0,80}agosto de 2026/i;
|
|
32
31
|
|
|
33
32
|
let failed = 0;
|
|
34
33
|
|
|
@@ -525,15 +524,12 @@ async function main() {
|
|
|
525
524
|
for (const name of STAMPED) {
|
|
526
525
|
const file = path.join(ROOT, "kit", "skills", name, "SKILL.md");
|
|
527
526
|
if (!(await exists(file))) {
|
|
528
|
-
warn(`${name} não está no núcleo (camada paga); o carimbo
|
|
527
|
+
warn(`${name} não está no núcleo (camada paga); o carimbo é conferido no zenkit layer pack --bundle`);
|
|
529
528
|
continue;
|
|
530
529
|
}
|
|
531
|
-
const
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
if (/rascunho/i.test(body) && /(contador|advogado)/i.test(body)) {
|
|
535
|
-
ok(`${name} manda validar rascunho`);
|
|
536
|
-
} else fail(`${name} não manda validar rascunho com contador/advogado`);
|
|
530
|
+
const problems = stampProblems(name, await fs.readFile(file, "utf8"));
|
|
531
|
+
if (problems.length === 0) ok(`carimbo de validade em ${name} e rascunho a validar`);
|
|
532
|
+
for (const p of problems) fail(p);
|
|
537
533
|
}
|
|
538
534
|
|
|
539
535
|
// §2c (P0): o encerramento tem de entregar as opções pelo MENU do runtime, não em
|
package/scripts/generate.mjs
CHANGED
|
@@ -397,21 +397,32 @@ async function dropHomeRootAgents(target) {
|
|
|
397
397
|
if (content.includes(GENERATED_MARK)) await fs.rm(rootAgents, { force: true });
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
/**
|
|
401
|
+
* A skill reference the install cannot resolve becomes the plain name: a recipe
|
|
402
|
+
* (kit-lite, kit-engenharia) does not carry every skill the master rule cites,
|
|
403
|
+
* and an agent should not go looking for a skill that is not there. `installed`
|
|
404
|
+
* null means "no filter" (the full kit resolves every reference).
|
|
405
|
+
*/
|
|
406
|
+
export function unlinkAbsentSkills(text, installed) {
|
|
407
|
+
if (!installed) return text;
|
|
408
|
+
return text.replace(/@\[skills\/([a-z0-9-]+)\]/g, (ref, name) => (installed.has(name) ? ref : name));
|
|
409
|
+
}
|
|
410
|
+
|
|
400
411
|
/** Cursor reads ZENKIT.mdc itself: write it with the slots filled, never with the markers. */
|
|
401
|
-
async function writeCursorMasterRule(rulesDir, layers = []) {
|
|
412
|
+
async function writeCursorMasterRule(rulesDir, layers = [], installed = null) {
|
|
402
413
|
const master = await fs.readFile(path.join(KIT, "rules", "ZENKIT.mdc"), "utf8");
|
|
403
414
|
// Layer sections arrive with their own line endings; keep the file in the kit's one.
|
|
404
|
-
const rendered = applySlots(master.replace(/\r\n/g, "\n"), layers);
|
|
415
|
+
const rendered = unlinkAbsentSkills(applySlots(master.replace(/\r\n/g, "\n"), layers), installed);
|
|
405
416
|
const eol = master.includes("\r\n") ? "\r\n" : "\n";
|
|
406
417
|
await fs.writeFile(path.join(rulesDir, "ZENKIT.mdc"), rendered.replace(/\n/g, eol));
|
|
407
418
|
}
|
|
408
419
|
|
|
409
|
-
async function writeClaudeMd(target, homeDir = os.homedir(), layers = []) {
|
|
420
|
+
async function writeClaudeMd(target, homeDir = os.homedir(), layers = [], installed = null) {
|
|
410
421
|
const atHome = samePath(target, homeDir);
|
|
411
422
|
if (atHome) await dropHomeRootAgents(target);
|
|
412
423
|
const masterPath = path.join(KIT, "rules", "ZENKIT.mdc");
|
|
413
424
|
const master = await fs.readFile(masterPath, "utf8");
|
|
414
|
-
const body = applySlots(splitFrontmatter(master).body, layers);
|
|
425
|
+
const body = unlinkAbsentSkills(applySlots(splitFrontmatter(master).body, layers), installed);
|
|
415
426
|
await fs.mkdir(path.join(target, ".claude"), { recursive: true });
|
|
416
427
|
await fs.mkdir(path.join(target, ".codex"), { recursive: true });
|
|
417
428
|
const rulesetAppend = await readRulesetAppend();
|
|
@@ -481,7 +492,7 @@ export async function emitPluginPackage({ dest, bundle }) {
|
|
|
481
492
|
for (const layer of ["rules", "workflows", "commands"]) {
|
|
482
493
|
await copyTree(path.join(KIT, layer), path.join(cursorDest, layer));
|
|
483
494
|
}
|
|
484
|
-
await writeCursorMasterRule(path.join(cursorDest, "rules"));
|
|
495
|
+
await writeCursorMasterRule(path.join(cursorDest, "rules"), [], new Set(meta.skills));
|
|
485
496
|
// Plugin packages ship the public core only: user layers stay private.
|
|
486
497
|
const skillSources = await coreSkillSources(meta.skills);
|
|
487
498
|
const agentSources = await coreAgentSources(meta.agents);
|
|
@@ -609,7 +620,8 @@ export async function generateKit({ target, bundle, homeDir, layers }) {
|
|
|
609
620
|
await fs.copyFile(src, path.join(target, ".cursor", "rules", `${name}.mdc`));
|
|
610
621
|
}
|
|
611
622
|
}
|
|
612
|
-
|
|
623
|
+
const installed = new Set(skillSources.keys());
|
|
624
|
+
await writeCursorMasterRule(path.join(target, ".cursor", "rules"), loadedLayers, installed);
|
|
613
625
|
await copySelectedSkillDirs(path.join(target, ".cursor", "skills"), skillSources);
|
|
614
626
|
await emitCursorAgents(target, agentSources);
|
|
615
627
|
|
|
@@ -617,7 +629,7 @@ export async function generateKit({ target, bundle, homeDir, layers }) {
|
|
|
617
629
|
await emitAgentsSkills(target, skillSources);
|
|
618
630
|
await copySelectedAgents(path.join(target, ".claude", "agents"), agentSources);
|
|
619
631
|
await copyTree(path.join(KIT, "commands"), path.join(target, ".claude", "commands"));
|
|
620
|
-
await writeClaudeMd(target, homeDir, loadedLayers);
|
|
632
|
+
await writeClaudeMd(target, homeDir, loadedLayers, installed);
|
|
621
633
|
|
|
622
634
|
const count = async (p) =>
|
|
623
635
|
(await fs.readdir(p).catch(() => [])).filter((n) => n !== OWNED_MANIFEST).length;
|
package/scripts/layer-remote.mjs
CHANGED
|
@@ -16,6 +16,8 @@ import os from "node:os";
|
|
|
16
16
|
import path from "node:path";
|
|
17
17
|
import { gunzipSync, gzipSync } from "node:zlib";
|
|
18
18
|
import { LAYER_MANIFEST, loadLayer } from "./layers.mjs";
|
|
19
|
+
import { listSkillNames, loadBundleFiles, loadLayerBundles, resolveBundle } from "./bundle.mjs";
|
|
20
|
+
import { STAMPED, stampProblems } from "./content-checks.mjs";
|
|
19
21
|
|
|
20
22
|
export const BUNDLE_FORMAT = "zenkit-layer/1";
|
|
21
23
|
/** Same cap the NexusCore route enforces (720 KB of bundle bytes). */
|
|
@@ -118,29 +120,90 @@ async function walk(root, rel, out) {
|
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Pack a layer directory into the bundle bytes. Refuses secrets and oversize.
|
|
125
|
+
* With `bundle`, packs only what that recipe needs from the layer (a storefront
|
|
126
|
+
* cut out of a paid pack): see sliceForBundle.
|
|
127
|
+
*/
|
|
128
|
+
export async function packLayer(dir, { maxBytes = MAX_BUNDLE_BYTES, bundle } = {}) {
|
|
123
129
|
const layer = await loadLayer(dir);
|
|
124
|
-
const files =
|
|
125
|
-
for (const sub of SUBTREES) await walk(layer.dir, sub, files);
|
|
130
|
+
const { name, files } = bundle ? await sliceForBundle(layer, bundle) : await wholeLayer(layer);
|
|
126
131
|
|
|
127
132
|
const secrets = findSecrets(files);
|
|
128
133
|
if (secrets.length) {
|
|
129
134
|
throw new Error(
|
|
130
|
-
`camada '${
|
|
135
|
+
`camada '${name}' parece conter segredo; nada foi enviado:\n ${secrets.join("\n ")}\n` +
|
|
131
136
|
"Segredo fica no ambiente (liste o nome em 'secrets:' no manifesto), nunca na camada.",
|
|
132
137
|
);
|
|
133
138
|
}
|
|
134
139
|
const json = JSON.stringify({
|
|
135
140
|
format: BUNDLE_FORMAT,
|
|
136
|
-
name
|
|
141
|
+
name,
|
|
137
142
|
files: files.map((f) => ({ path: f.path, data: f.data.toString("base64") })),
|
|
138
143
|
});
|
|
139
144
|
const bytes = gzipSync(Buffer.from(json, "utf8"), { level: 9 });
|
|
140
145
|
if (bytes.length > maxBytes) {
|
|
141
|
-
throw new Error(`camada '${
|
|
146
|
+
throw new Error(`camada '${name}' tem ${bytes.length} bytes compactada; o máximo é ${maxBytes}`);
|
|
147
|
+
}
|
|
148
|
+
return { name, bytes, sha256: sha256(bytes), files: files.length };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function wholeLayer(layer) {
|
|
152
|
+
const files = [{ path: LAYER_MANIFEST, data: await fs.readFile(path.join(layer.dir, LAYER_MANIFEST)) }];
|
|
153
|
+
for (const sub of SUBTREES) await walk(layer.dir, sub, files);
|
|
154
|
+
return { name: layer.name, files };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const SKILL_REF = /@\[skills\/([a-z0-9-]+)\]/g;
|
|
158
|
+
|
|
159
|
+
/** Drop the lines of a section that point at a skill the buyer will not have. */
|
|
160
|
+
export function dropLinesCitingAbsent(text, available) {
|
|
161
|
+
return text
|
|
162
|
+
.split("\n")
|
|
163
|
+
.filter((line) => [...line.matchAll(SKILL_REF)].every((m) => available.has(m[1])))
|
|
164
|
+
.join("\n");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A storefront cut out of a layer. The recipe resolves against the core's and
|
|
169
|
+
* the layer's bundles; the pack carries only the layer skills (and agents) the
|
|
170
|
+
* recipe uses, since the core ones the buyer already has. Sections keep only
|
|
171
|
+
* lines whose skill references the buyer will have. Stamped skills must pass
|
|
172
|
+
* their content check, or nothing is packed.
|
|
173
|
+
*/
|
|
174
|
+
async function sliceForBundle(layer, bundleName) {
|
|
175
|
+
const core = await loadBundleFiles();
|
|
176
|
+
const own = await loadLayerBundles(layer.dir);
|
|
177
|
+
const clash = [...own.keys()].filter((n) => core.has(n));
|
|
178
|
+
if (clash.length) throw new Error(`receita na camada com o nome de uma do núcleo: ${clash.join(", ")}`);
|
|
179
|
+
const recipe = resolveBundle(bundleName, new Map([...core, ...own]));
|
|
180
|
+
|
|
181
|
+
const coreSkills = new Set(await listSkillNames());
|
|
182
|
+
const keep = [...recipe.skills].filter((s) => layer.skills.has(s)).sort();
|
|
183
|
+
const absent = [...recipe.skills].filter((s) => !layer.skills.has(s) && !coreSkills.has(s));
|
|
184
|
+
if (absent.length) throw new Error(`receita '${bundleName}' cita skill que não existe no núcleo nem na camada: ${absent.join(", ")}`);
|
|
185
|
+
if (keep.length === 0) throw new Error(`receita '${bundleName}' não usa nenhuma skill da camada '${layer.name}'`);
|
|
186
|
+
|
|
187
|
+
const problems = [];
|
|
188
|
+
for (const s of keep.filter((s) => STAMPED.includes(s))) {
|
|
189
|
+
problems.push(...stampProblems(s, await fs.readFile(path.join(layer.skills.get(s), "SKILL.md"), "utf8")));
|
|
190
|
+
}
|
|
191
|
+
if (problems.length) throw new Error(`receita '${bundleName}' não empacotada:\n ${problems.join("\n ")}`);
|
|
192
|
+
|
|
193
|
+
const overrides = keep.filter((s) => coreSkills.has(s));
|
|
194
|
+
const manifest =
|
|
195
|
+
`name: ${bundleName}\n` + (overrides.length ? `override:\n${overrides.map((s) => ` - ${s}\n`).join("")}` : "");
|
|
196
|
+
const files = [{ path: LAYER_MANIFEST, data: Buffer.from(manifest, "utf8") }];
|
|
197
|
+
for (const s of keep) await walk(layer.dir, `skills/${s}`, files);
|
|
198
|
+
for (const a of [...recipe.agents].filter((a) => layer.agents.has(a)).sort()) {
|
|
199
|
+
files.push({ path: `agents/${a}.md`, data: await fs.readFile(layer.agents.get(a)) });
|
|
200
|
+
}
|
|
201
|
+
const available = new Set([...keep, ...coreSkills]);
|
|
202
|
+
for (const [id, text] of layer.sections) {
|
|
203
|
+
const kept = dropLinesCitingAbsent(text, available);
|
|
204
|
+
if (kept.trim()) files.push({ path: `sections/${id}.md`, data: Buffer.from(kept, "utf8") });
|
|
142
205
|
}
|
|
143
|
-
return { name:
|
|
206
|
+
return { name: bundleName, files };
|
|
144
207
|
}
|
|
145
208
|
|
|
146
209
|
function safeRel(rel) {
|