@verentis/cli 1.0.5 → 1.0.6

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/index.js CHANGED
@@ -2453,9 +2453,34 @@ function validateAgentSpec(kind, spec) {
2453
2453
  ...fileAccessErrors(spec["file-access"]),
2454
2454
  ...uiErrors(spec.ui),
2455
2455
  ...modelErrors(spec.model),
2456
- ...capabilityErrors(spec.capabilities)
2456
+ ...capabilityErrors(spec.capabilities),
2457
+ ...chatErrors(spec.chat),
2458
+ ...subagentErrors(spec.subagents)
2457
2459
  ];
2458
2460
  }
2461
+ function chatErrors(value) {
2462
+ if (value === void 0) return [];
2463
+ if (!isRecord4(value)) return ["spec.chat must be a mapping (contact)."];
2464
+ const errors = Object.keys(value).filter((key) => key !== "contact").map((key) => `spec.chat.${key} is not supported.`);
2465
+ if (value.contact !== void 0 && typeof value.contact !== "boolean") errors.push("spec.chat.contact must be true or false.");
2466
+ return errors;
2467
+ }
2468
+ function subagentErrors(value) {
2469
+ if (value === void 0) return [];
2470
+ if (!isRecord4(value)) return ["spec.subagents must be a mapping (agents, max-children)."];
2471
+ const errors = Object.keys(value).filter((key) => key !== "agents" && key !== "max-children").map((key) => `spec.subagents.${key} is not supported.`);
2472
+ errors.push(...stringListErrors(
2473
+ value.agents,
2474
+ "spec.subagents.agents",
2475
+ "a list of agents: 'self', ./relative, @publisher/package[/path] or an absolute workspace path",
2476
+ true
2477
+ ));
2478
+ const max = value["max-children"];
2479
+ if (max !== void 0 && (!Number.isInteger(max) || max < 0 || max > 64)) {
2480
+ errors.push("spec.subagents.max-children must be a whole number from 0 to 64.");
2481
+ }
2482
+ return errors;
2483
+ }
2459
2484
  function stringListErrors(value, label, expected, unique = false) {
2460
2485
  if (value === void 0) return [];
2461
2486
  if (!Array.isArray(value)) return [`${label} must be ${expected}.`];
@@ -2630,9 +2655,9 @@ async function loadManifest(path) {
2630
2655
  if (messageErrors.length > 0) {
2631
2656
  throw new Error(`Invalid manifest at ${path}: ${messageErrors.join(" ")}`);
2632
2657
  }
2633
- const chatErrors = validateChatSection(kind, manifest.spec);
2634
- if (chatErrors.length > 0) {
2635
- throw new Error(`Invalid manifest at ${path}: ${chatErrors.join(" ")}`);
2658
+ const chatErrors2 = validateChatSection(kind, manifest.spec);
2659
+ if (chatErrors2.length > 0) {
2660
+ throw new Error(`Invalid manifest at ${path}: ${chatErrors2.join(" ")}`);
2636
2661
  }
2637
2662
  const actorErrors = validateActorSection(kind, manifest.spec);
2638
2663
  if (actorErrors.length > 0) {
@@ -5706,6 +5731,123 @@ function findPlaceholders(text) {
5706
5731
  }
5707
5732
  return placeholders;
5708
5733
  }
5734
+ var AGENT_FILE = /\.agent\.ya?ml$/i;
5735
+ var isRecord5 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
5736
+ async function validateAgentSuite(projectDir, manifestPath, manifest, payloadFiles) {
5737
+ const errors = [];
5738
+ const warnings = [];
5739
+ const agents = [];
5740
+ const spec = isRecord5(manifest.spec) ? manifest.spec : {};
5741
+ const recordFile = toPosix(relative(projectDir, manifestPath));
5742
+ if (manifest.kind === "Agent") agents.push(agentOf(recordFile, "the package agent", manifest.metadata?.id, spec));
5743
+ for (const file of payloadFiles.map(toPosix).filter((file2) => AGENT_FILE.test(file2)).sort()) {
5744
+ let document;
5745
+ try {
5746
+ document = parse(await readFile(join(projectDir, file), "utf8"));
5747
+ } catch (error) {
5748
+ errors.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
5749
+ continue;
5750
+ }
5751
+ if (!isRecord5(document) || document.kind !== "Agent") {
5752
+ errors.push(`${file}: an *.agent.yaml file must be an Agent manifest (kind: Agent).`);
5753
+ continue;
5754
+ }
5755
+ const metadata = isRecord5(document.metadata) ? document.metadata : {};
5756
+ const agentSpec = isRecord5(document.spec) ? document.spec : {};
5757
+ if (typeof metadata.id !== "string" || !metadata.id.trim()) errors.push(`${file}: metadata.id is required.`);
5758
+ errors.push(...validateAgentSpec("Agent", agentSpec).map((message) => `${file}: ${message}`));
5759
+ agents.push(agentOf(file, file, metadata.id, agentSpec));
5760
+ }
5761
+ if (agents.length === 0) return { errors, warnings };
5762
+ const ids = /* @__PURE__ */ new Map();
5763
+ for (const agent of agents) {
5764
+ if (!agent.id) continue;
5765
+ const other = ids.get(agent.id);
5766
+ if (other) errors.push(`${agent.label}: metadata.id '${agent.id}' is also used by ${other}; agents of one package need unique ids.`);
5767
+ else ids.set(agent.id, agent.label);
5768
+ }
5769
+ const files2 = new Set(agents.map((agent) => agent.file));
5770
+ const dependencies = dependencyPackages(spec);
5771
+ const own = typeof manifest.packaging?.publisher === "string" && typeof manifest.metadata?.id === "string" ? `${manifest.packaging.publisher}/${manifest.metadata.id}` : void 0;
5772
+ for (const agent of agents) {
5773
+ const subagents = isRecord5(agent.spec.subagents) ? agent.spec.subagents : void 0;
5774
+ const references = Array.isArray(subagents?.agents) ? subagents.agents.filter((r) => typeof r === "string") : [];
5775
+ for (const reference of references.map((r) => r.trim())) {
5776
+ const problem = referenceProblem(agent.file, reference, files2, dependencies, own);
5777
+ if (problem?.error) errors.push(`${agent.label}: spec.subagents.agents '${reference}' ${problem.error}`);
5778
+ else if (problem?.warning) warnings.push(`${agent.label}: spec.subagents.agents '${reference}' ${problem.warning}`);
5779
+ }
5780
+ }
5781
+ const contacts = agents.filter((agent) => agent.contact);
5782
+ if (agents.length > 1 && contacts.length > 1) {
5783
+ warnings.push(`${contacts.length} agents are Chat contacts (${contacts.map((a) => a.label).join(", ")}). Set spec.chat.contact: false on the sub-agents so Chat lists only the agent people talk to.`);
5784
+ }
5785
+ const orchestrators = agents.filter((agent) => isRecord5(agent.spec.subagents));
5786
+ if (agents.length > 1 && contacts.length === 0 && orchestrators.length > 0) {
5787
+ warnings.push(`No agent in this package is a Chat contact; ${orchestrators.map((a) => a.label).join(", ")} can only be started from a schedule, a trigger or the runs page.`);
5788
+ }
5789
+ if (manifest.kind !== "Agent") warnings.push(...bundledConsentWarnings(agents, spec));
5790
+ return { errors, warnings };
5791
+ }
5792
+ function agentOf(file, label, id, spec) {
5793
+ const chat = isRecord5(spec.chat) ? spec.chat : void 0;
5794
+ return { file, label, id: typeof id === "string" && id.trim() ? id : void 0, contact: chat?.contact !== false, spec };
5795
+ }
5796
+ function referenceProblem(from, reference, files2, dependencies, own) {
5797
+ if (reference === "self") return void 0;
5798
+ if (reference.startsWith("@")) {
5799
+ const body = reference.slice(1).split("@")[0];
5800
+ const parts = body.split("/").filter(Boolean);
5801
+ if (parts.length < 2 || parts.some((p) => p === "." || p === "..")) return { error: "is not a package reference (@publisher/package[/path])." };
5802
+ const pkg = `${parts[0]}/${parts[1]}`;
5803
+ if (pkg === own) {
5804
+ const item = parts.slice(2).join("/");
5805
+ return item && !files2.has(item) ? { error: `names ${item}, which is not an agent manifest in this package.` } : void 0;
5806
+ }
5807
+ return dependencies.has(pkg) ? void 0 : { warning: `names ${pkg}, which spec.dependencies doesn't declare; it resolves only where that package is already installed.` };
5808
+ }
5809
+ if (reference === "." || reference === ".." || reference.startsWith("./") || reference.startsWith("../")) {
5810
+ const target = posix.normalize(posix.join(posix.dirname(from || "."), reference));
5811
+ if (target.startsWith("../") || target === "..") return { error: "points outside the package." };
5812
+ return files2.has(target) ? void 0 : { error: `resolves to ${target}, which is not an agent manifest in this package.` };
5813
+ }
5814
+ return { warning: "is an absolute workspace path; use ./relative or @publisher/package so it moves with the package." };
5815
+ }
5816
+ function dependencyPackages(spec) {
5817
+ const packages = /* @__PURE__ */ new Set();
5818
+ for (const dependency of Array.isArray(spec.dependencies) ? spec.dependencies : []) {
5819
+ const value = typeof dependency === "string" ? dependency : isRecord5(dependency) ? dependency.package : void 0;
5820
+ if (typeof value === "string") packages.add(value.split("@")[0]);
5821
+ }
5822
+ return packages;
5823
+ }
5824
+ function bundledConsentWarnings(agents, spec) {
5825
+ const warnings = [];
5826
+ const scopes = new Set(Array.isArray(spec.permissions) ? spec.permissions.filter((p) => typeof p === "string") : []);
5827
+ const grants = (Array.isArray(spec["file-access"]) ? spec["file-access"] : []).filter(isRecord5).filter((g2) => typeof g2.path === "string" && g2.path.startsWith("/") && (g2.mode === "read" || g2.mode === "write")).map((g2) => ({ path: trimSlash(g2.path), mode: g2.mode }));
5828
+ for (const agent of agents) {
5829
+ const permissions = Array.isArray(agent.spec.permissions) ? agent.spec.permissions.filter((p) => typeof p === "string") : [];
5830
+ const missing = permissions.filter((p) => !scopes.has(p));
5831
+ if (missing.length > 0) {
5832
+ warnings.push(`${agent.label}: requests ${missing.join(", ")}, which the package's spec.permissions doesn't declare; a bundled agent only gets what the package is consented.`);
5833
+ }
5834
+ for (const entry of (Array.isArray(agent.spec["file-access"]) ? agent.spec["file-access"] : []).filter(isRecord5)) {
5835
+ if (typeof entry.path !== "string") continue;
5836
+ if (!entry.path.startsWith("/")) {
5837
+ warnings.push(`${agent.label}: spec.file-access '${entry.path}' is relative; a bundled agent's folder is covered only when an absolute package grant includes it. Request the absolute folder the package declares.`);
5838
+ continue;
5839
+ }
5840
+ const path = trimSlash(entry.path);
5841
+ const covered = grants.some((g2) => (path === g2.path || path.startsWith(`${g2.path}/`) || g2.path === "") && (g2.mode === "write" || entry.mode !== "write"));
5842
+ if (!covered) {
5843
+ warnings.push(`${agent.label}: spec.file-access '${entry.path}' (${String(entry.mode)}) isn't covered by the package's spec.file-access; a bundled agent only gets what the package is consented.`);
5844
+ }
5845
+ }
5846
+ }
5847
+ return warnings;
5848
+ }
5849
+ var trimSlash = (path) => path.replace(/\/+$/, "");
5850
+ var toPosix = (path) => path.split("\\").join("/");
5709
5851
  var ARGUMENTS_SCHEMA = "verentis.io/script-arguments/v1";
5710
5852
  var ARGUMENTS_SUFFIX = ".arguments.json";
5711
5853
  var KINDS = /* @__PURE__ */ new Set(["option", "positional"]);
@@ -6007,6 +6149,9 @@ async function pack(options) {
6007
6149
  const avatarInclusionErrors = validateAgentAvatarPayloadFiles(manifest, payloadFiles);
6008
6150
  if (avatarInclusionErrors.length > 0) throw new Error(`Invalid ${kind} payload:
6009
6151
  ${avatarInclusionErrors.join("\n ")}`);
6152
+ const suite = await validateAgentSuite(projectDir, manifestPath, manifest, payloadFiles);
6153
+ if (suite.errors.length > 0) throw new Error(`Invalid agents in ${kind} package:
6154
+ ${suite.errors.join("\n ")}`);
6010
6155
  const missingSources = expandedInstall.filter((from) => !payloadFiles.some((file) => toEntryPath2(file) === from));
6011
6156
  if (missingSources.length > 0) {
6012
6157
  throw new Error(`packaging.files does not include ${missingSources.join(", ")} declared by spec.assets.`);
@@ -6119,7 +6264,7 @@ async function pack(options) {
6119
6264
  treeDigest: sha256Hex(Buffer.from(digestsJson, "utf8")),
6120
6265
  signed,
6121
6266
  encrypted: encrypt,
6122
- warnings: icons.warnings
6267
+ warnings: [...icons.warnings, ...suite.warnings]
6123
6268
  };
6124
6269
  } finally {
6125
6270
  await rm(staging, { recursive: true, force: true });
@@ -6657,8 +6802,8 @@ function isNewerVersion(candidate, base) {
6657
6802
  return compareVersions(candidate, base) > 0;
6658
6803
  }
6659
6804
  function compareVersions(a, b2) {
6660
- const pa = parse8(a);
6661
- const pb = parse8(b2);
6805
+ const pa = parse9(a);
6806
+ const pb = parse9(b2);
6662
6807
  for (let i = 0; i < 3; i++) {
6663
6808
  if (pa.main[i] !== pb.main[i]) return pa.main[i] < pb.main[i] ? -1 : 1;
6664
6809
  }
@@ -6685,7 +6830,7 @@ function compareVersions(a, b2) {
6685
6830
  }
6686
6831
  return 0;
6687
6832
  }
6688
- function parse8(version) {
6833
+ function parse9(version) {
6689
6834
  const cleaned = version.trim().replace(/^v/i, "").split("+", 1)[0];
6690
6835
  const dash = cleaned.indexOf("-");
6691
6836
  const core = dash === -1 ? cleaned : cleaned.slice(0, dash);
@@ -7085,11 +7230,11 @@ function getCliVersion() {
7085
7230
  }
7086
7231
  function readVersion() {
7087
7232
  const candidates = ["../package.json", "../../package.json"];
7088
- for (const relative7 of candidates) {
7233
+ for (const relative8 of candidates) {
7089
7234
  try {
7090
- const raw = readFileSync(fileURLToPath(new URL(relative7, import.meta.url)), "utf8");
7235
+ const raw = readFileSync(fileURLToPath(new URL(relative8, import.meta.url)), "utf8");
7091
7236
  const pkg = JSON.parse(raw);
7092
- if (pkg.version && (relative7 === "../package.json" || pkg.name === PACKAGE_NAME)) return pkg.version;
7237
+ if (pkg.version && (relative8 === "../package.json" || pkg.name === PACKAGE_NAME)) return pkg.version;
7093
7238
  } catch {
7094
7239
  }
7095
7240
  }
@@ -7427,6 +7572,11 @@ function registerValidate(program2) {
7427
7572
  try {
7428
7573
  const payloadFiles = await resolvePayloadFiles(dirname(manifestPath), manifestPath, manifest);
7429
7574
  issues.push(...validateAgentAvatarPayloadFiles(manifest, payloadFiles).map((message) => ({ level: "error", message })));
7575
+ const suite = await validateAgentSuite(dirname(manifestPath), manifestPath, manifest, payloadFiles);
7576
+ issues.push(
7577
+ ...suite.errors.map((message) => ({ level: "error", message })),
7578
+ ...suite.warnings.map((message) => ({ level: "warning", message }))
7579
+ );
7430
7580
  if (avatarPayloadErrors.length === 0) {
7431
7581
  const templateInspection = await inspectPackagingTemplates(dirname(manifestPath), manifest, payloadFiles);
7432
7582
  issues.push(...templateInspection.issues);