@agentproto/corpus-cli 0.1.0-alpha.2 → 0.1.0-alpha.3
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.mjs +17 -0
- package/dist/cli.mjs.map +1 -1
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -453,6 +453,10 @@ Run \`corpus init --list\` for available presets.`,
|
|
|
453
453
|
2
|
|
454
454
|
);
|
|
455
455
|
}
|
|
456
|
+
if (!presetSlug) {
|
|
457
|
+
const nameErr = invalidCorpusName(name);
|
|
458
|
+
if (nameErr) return fail(nameErr, 2);
|
|
459
|
+
}
|
|
456
460
|
const target = resolveWorkspacePath(pathArg);
|
|
457
461
|
const fs = new NodeFsAdapter({ root: target });
|
|
458
462
|
if (await fs.exists("KNOWLEDGE.md")) {
|
|
@@ -507,6 +511,19 @@ Try: corpus import-web ${pathArg ?? "."} --urls-file urls.txt
|
|
|
507
511
|
);
|
|
508
512
|
return 0;
|
|
509
513
|
}
|
|
514
|
+
var CORPUS_NAME_RE = /^[a-z][a-z0-9-]*[a-z0-9]$/;
|
|
515
|
+
function invalidCorpusName(name) {
|
|
516
|
+
if (name.length >= 2 && name.length <= 96 && CORPUS_NAME_RE.test(name)) {
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
const suggestion = slugifyName(name);
|
|
520
|
+
const hint = suggestion.length >= 2 && CORPUS_NAME_RE.test(suggestion) ? `
|
|
521
|
+
Did you mean: ${suggestion}` : "";
|
|
522
|
+
return `init: invalid corpus name "${name}". A corpus name is a kebab-case identifier \u2014 lowercase letters, digits and hyphens, 2\u201396 chars, starting with a letter and ending alphanumerically (^[a-z][a-z0-9-]*[a-z0-9]$).${hint}`;
|
|
523
|
+
}
|
|
524
|
+
function slugifyName(raw) {
|
|
525
|
+
return raw.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
526
|
+
}
|
|
510
527
|
function splitList(v) {
|
|
511
528
|
return (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
512
529
|
}
|