agent-package-manager 0.4.5 → 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/dist/cli/index.js CHANGED
@@ -25,6 +25,9 @@ function createProgram(handlers2, version) {
25
25
  program2.command("diff").description("Show semantic diff between current and target package versions.").argument("<package>", "Package name, or name@version to compare against a specific version.").option("--format <format>", "Output format.", "text").action(async (packageArg, opts, cmd) => {
26
26
  await handlers2.diff(packageArg, opts, cmd.optsWithGlobals());
27
27
  });
28
+ program2.command("list").description("List installed packages and their status.").option("--json", "Output in machine-readable JSON format.", false).action(async (opts, cmd) => {
29
+ await handlers2.list(opts, cmd.optsWithGlobals());
30
+ });
28
31
  program2.command("check").description("Run full verification pipeline for CI.").action(async (opts, cmd) => {
29
32
  await handlers2.check({}, cmd.optsWithGlobals());
30
33
  });
@@ -4402,6 +4405,12 @@ async function commitAll(cwd2, message) {
4402
4405
  async function pushBranch(cwd2, remote = "origin", branch = "main") {
4403
4406
  await git(["push", remote, branch], cwd2);
4404
4407
  }
4408
+ async function createTag(cwd2, tagName, message) {
4409
+ await git(["tag", "-a", tagName, "-m", message], cwd2);
4410
+ }
4411
+ async function pushTag(cwd2, tagName, remote = "origin") {
4412
+ await git(["push", remote, tagName], cwd2);
4413
+ }
4405
4414
 
4406
4415
  // src/lib/registry.ts
4407
4416
  import { readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
@@ -4755,10 +4764,143 @@ async function runSync(input, projectDir) {
4755
4764
  }
4756
4765
 
4757
4766
  // src/lib/commands/update.ts
4767
+ import { existsSync as existsSync7 } from "fs";
4768
+ import { mkdir as mkdir5, rm as rm5, mkdtemp as mkdtemp2 } from "fs/promises";
4769
+ import { join as join9 } from "path";
4770
+ import { tmpdir as tmpdir2 } from "os";
4771
+ import { createInterface } from "readline";
4772
+ import semver3 from "semver";
4773
+
4774
+ // src/lib/commands/diff.ts
4758
4775
  import { existsSync as existsSync6 } from "fs";
4759
- import { mkdir as mkdir5, rm as rm4 } from "fs/promises";
4776
+ import { readFile as readFile5, mkdtemp, rm as rm4 } from "fs/promises";
4760
4777
  import { join as join8 } from "path";
4761
- import semver3 from "semver";
4778
+ import { tmpdir } from "os";
4779
+ async function runDiff(input, projectDir) {
4780
+ const config = await readProjectConfig(projectDir);
4781
+ const lock = await readLockFile(projectDir);
4782
+ const spec = parsePackageSpec(input.packageSpec);
4783
+ const name = spec.name;
4784
+ if (!config.packages[name]) {
4785
+ throw new Error(`Package "${name}" not found. Available: ${Object.keys(config.packages).join(", ")}`);
4786
+ }
4787
+ const pkg = config.packages[name];
4788
+ const registry = resolveRegistryForPackage(config, name);
4789
+ const repoDir = await ensureCloned(registry.owner, registry.repo);
4790
+ const manifest = await readManifestFromRepo(repoDir);
4791
+ let targetVersion;
4792
+ if (spec.version) {
4793
+ targetVersion = spec.version;
4794
+ } else {
4795
+ const versions = listVersionsFromManifest(manifest, name);
4796
+ if (versions.length === 0) {
4797
+ throw new Error(`No versions found for ${name} in registry manifest`);
4798
+ }
4799
+ const sorted = versions.map((v) => ({ raw: v, parts: parseSemverSimple(v) })).filter((v) => v.parts !== null).sort((a, b) => compareSemverSimple(a.parts, b.parts));
4800
+ targetVersion = sorted[sorted.length - 1].raw;
4801
+ }
4802
+ if (targetVersion === pkg.version) {
4803
+ log.info(`${name} is already at ${targetVersion}`);
4804
+ return;
4805
+ }
4806
+ log.step(`Comparing ${name} ${pkg.version} \u2192 ${targetVersion}`);
4807
+ const resolved = resolveVersionFromManifest(manifest, name, targetVersion);
4808
+ const tmpDir = await mkdtemp(join8(tmpdir(), "agent-pkg-diff-"));
4809
+ try {
4810
+ const targetDir = join8(tmpDir, "target");
4811
+ await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, targetDir);
4812
+ const currentDir = join8(projectDir, config.install.modulesDir, name);
4813
+ if (!existsSync6(currentDir)) {
4814
+ throw new Error(`Current package not installed at ${currentDir}. Run sync first.`);
4815
+ }
4816
+ const currentDsl = await loadYamlSafe(join8(currentDir, "agent-contracts.yaml"));
4817
+ const targetDsl = await loadYamlSafe(join8(targetDir, "agent-contracts.yaml"));
4818
+ const changes = computeDslDiff(currentDsl, targetDsl);
4819
+ if (input.format === "json") {
4820
+ console.log(JSON.stringify({
4821
+ package: name,
4822
+ fromVersion: pkg.version,
4823
+ toVersion: targetVersion,
4824
+ changes
4825
+ }, null, 2));
4826
+ } else {
4827
+ printTextDiff(name, pkg.version, targetVersion, changes);
4828
+ }
4829
+ const hasBreaking = changes.some((c) => c.breaking);
4830
+ if (hasBreaking) {
4831
+ process.exit(2);
4832
+ }
4833
+ } finally {
4834
+ await rm4(tmpDir, { recursive: true, force: true });
4835
+ }
4836
+ }
4837
+ function computeDslDiff(current, target) {
4838
+ const changes = [];
4839
+ if (!current || !target) return changes;
4840
+ const sections = ["agents", "tasks", "workflows", "guardrails", "handoff_types"];
4841
+ for (const section of sections) {
4842
+ const cur = current[section] || {};
4843
+ const tgt = target[section] || {};
4844
+ for (const key of Object.keys(tgt)) {
4845
+ if (!(key in cur)) {
4846
+ changes.push({ section, type: "added", key });
4847
+ } else if (JSON.stringify(cur[key]) !== JSON.stringify(tgt[key])) {
4848
+ changes.push({ section, type: "modified", key });
4849
+ }
4850
+ }
4851
+ for (const key of Object.keys(cur)) {
4852
+ if (!(key in tgt)) {
4853
+ changes.push({ section, type: "removed", key, breaking: true });
4854
+ }
4855
+ }
4856
+ }
4857
+ return changes;
4858
+ }
4859
+ function printTextDiff(name, fromVersion, toVersion, changes) {
4860
+ console.log(`${name} ${fromVersion} \u2192 ${toVersion}
4861
+ `);
4862
+ if (changes.length === 0) {
4863
+ console.log(" No semantic changes detected.");
4864
+ return;
4865
+ }
4866
+ const grouped = /* @__PURE__ */ new Map();
4867
+ for (const c of changes) {
4868
+ const list = grouped.get(c.section) || [];
4869
+ list.push(c);
4870
+ grouped.set(c.section, list);
4871
+ }
4872
+ for (const [section, items] of grouped) {
4873
+ const label = section.charAt(0).toUpperCase() + section.slice(1);
4874
+ console.log(`${label}:`);
4875
+ for (const item of items) {
4876
+ const breaking = item.breaking ? " BREAKING" : "";
4877
+ console.log(` ${item.type} ${item.key}${breaking}`);
4878
+ }
4879
+ console.log();
4880
+ }
4881
+ const hasBreaking = changes.some((c) => c.breaking);
4882
+ if (hasBreaking) {
4883
+ console.log("Risk:\n BREAKING CHANGE detected");
4884
+ }
4885
+ }
4886
+ async function loadYamlSafe(path) {
4887
+ if (!existsSync6(path)) return null;
4888
+ const { parse } = await import("yaml");
4889
+ const content = await readFile5(path, "utf8");
4890
+ return parse(content) || {};
4891
+ }
4892
+ function parseSemverSimple(v) {
4893
+ const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
4894
+ if (!m) return null;
4895
+ return [+m[1], +m[2], +m[3]];
4896
+ }
4897
+ function compareSemverSimple(a, b) {
4898
+ if (a[0] !== b[0]) return a[0] - b[0];
4899
+ if (a[1] !== b[1]) return a[1] - b[1];
4900
+ return a[2] - b[2];
4901
+ }
4902
+
4903
+ // src/lib/commands/update.ts
4762
4904
  async function runUpdate(input, projectDir) {
4763
4905
  const config = await readProjectConfig(projectDir);
4764
4906
  const lock = await readLockFile(projectDir);
@@ -4823,10 +4965,46 @@ async function runUpdate(input, projectDir) {
4823
4965
  const breaking = u.hasBreakingChanges ? " (BREAKING)" : "";
4824
4966
  log.info(`${u.package}: ${u.fromVersion} \u2192 ${u.toVersion}${breaking}`);
4825
4967
  }
4968
+ let hasAnyBreaking = false;
4969
+ for (const u of updates) {
4970
+ const pkg = config.packages[u.package];
4971
+ const registryName = pkg.registry || "default";
4972
+ const registry = config.registries[registryName];
4973
+ if (!registry) continue;
4974
+ const currentDir = join9(projectDir, config.install.modulesDir, u.package);
4975
+ if (!existsSync7(currentDir)) continue;
4976
+ const repoDir = await ensureCloned(registry.owner, registry.repo);
4977
+ const manifest = await readManifestFromRepo(repoDir);
4978
+ const resolved = resolveVersionFromManifest(manifest, u.package, u.toVersion);
4979
+ const tmpDir = await mkdtemp2(join9(tmpdir2(), "agent-pkg-update-diff-"));
4980
+ try {
4981
+ const targetDir = join9(tmpDir, "target");
4982
+ await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, targetDir);
4983
+ const currentDsl = await loadYamlSafe(join9(currentDir, "agent-contracts.yaml"));
4984
+ const targetDsl = await loadYamlSafe(join9(targetDir, "agent-contracts.yaml"));
4985
+ const changes = computeDslDiff(currentDsl, targetDsl);
4986
+ if (changes.length > 0) {
4987
+ console.log();
4988
+ printTextDiff(u.package, u.fromVersion, u.toVersion, changes);
4989
+ if (changes.some((c) => c.breaking)) {
4990
+ hasAnyBreaking = true;
4991
+ }
4992
+ }
4993
+ } finally {
4994
+ await rm5(tmpDir, { recursive: true, force: true });
4995
+ }
4996
+ }
4826
4997
  if (input.dryRun) {
4827
4998
  console.log(JSON.stringify({ updates, dryRun: true }, null, 2));
4828
4999
  return;
4829
5000
  }
5001
+ if (hasAnyBreaking && !input.yes) {
5002
+ const confirmed = await promptConfirm("BREAKING CHANGES detected. Continue with update?");
5003
+ if (!confirmed) {
5004
+ log.info("Update cancelled");
5005
+ return;
5006
+ }
5007
+ }
4830
5008
  const installedDeps = [];
4831
5009
  for (const u of updates) {
4832
5010
  const pkg = config.packages[u.package];
@@ -4835,9 +5013,9 @@ async function runUpdate(input, projectDir) {
4835
5013
  const repoDir = await ensureCloned(registry.owner, registry.repo);
4836
5014
  const manifest = await readManifestFromRepo(repoDir);
4837
5015
  const resolved = resolveVersionFromManifest(manifest, u.package, u.toVersion);
4838
- const installDir = join8(projectDir, config.install.modulesDir, u.package);
4839
- if (existsSync6(installDir)) {
4840
- await rm4(installDir, { recursive: true, force: true });
5016
+ const installDir = join9(projectDir, config.install.modulesDir, u.package);
5017
+ if (existsSync7(installDir)) {
5018
+ await rm5(installDir, { recursive: true, force: true });
4841
5019
  }
4842
5020
  await mkdir5(installDir, { recursive: true });
4843
5021
  await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
@@ -4877,16 +5055,16 @@ async function runUpdate(input, projectDir) {
4877
5055
  const registryName = pkg.registry || "default";
4878
5056
  const registry = config.registries[registryName];
4879
5057
  if (!registry) continue;
4880
- const installDir = join8(projectDir, config.install.modulesDir, name);
4881
- if (!existsSync6(installDir)) continue;
5058
+ const installDir = join9(projectDir, config.install.modulesDir, name);
5059
+ if (!existsSync7(installDir)) continue;
4882
5060
  const pkgManifest = await readPackageManifest(installDir);
4883
5061
  if (!pkgManifest?.dependencies) continue;
4884
5062
  const missingDeps = Object.entries(pkgManifest.dependencies).filter(
4885
5063
  ([depId, range]) => {
4886
5064
  const existing = config.packages[depId];
4887
5065
  if (!existing) return true;
4888
- const depDir = join8(projectDir, config.install.modulesDir, depId);
4889
- if (!existsSync6(depDir)) return true;
5066
+ const depDir = join9(projectDir, config.install.modulesDir, depId);
5067
+ if (!existsSync7(depDir)) return true;
4890
5068
  return !semver3.satisfies(existing.version, range);
4891
5069
  }
4892
5070
  );
@@ -4925,8 +5103,8 @@ async function installDependencies2(projectDir, config, lock, registry, registry
4925
5103
  throw new Error(`Circular dependency detected: ${chain}`);
4926
5104
  }
4927
5105
  const existing = config.packages[depId];
4928
- const depDir = join8(projectDir, config.install.modulesDir, depId);
4929
- if (existing && existsSync6(depDir) && semver3.satisfies(existing.version, range)) {
5106
+ const depDir = join9(projectDir, config.install.modulesDir, depId);
5107
+ if (existing && existsSync7(depDir) && semver3.satisfies(existing.version, range)) {
4930
5108
  log.debug(`Dependency ${depId}@${existing.version} already satisfies ${range}`);
4931
5109
  continue;
4932
5110
  }
@@ -4939,9 +5117,9 @@ async function installDependencies2(projectDir, config, lock, registry, registry
4939
5117
  log.step(`Dependency: ${depId}@${resolvedVersion} (required: ${range})`);
4940
5118
  resolving.add(depId);
4941
5119
  const resolved = resolveVersionFromManifest(manifest, depId, resolvedVersion);
4942
- const installDir = join8(projectDir, config.install.modulesDir, depId);
4943
- if (existsSync6(installDir)) {
4944
- await rm4(installDir, { recursive: true, force: true });
5120
+ const installDir = join9(projectDir, config.install.modulesDir, depId);
5121
+ if (existsSync7(installDir)) {
5122
+ await rm5(installDir, { recursive: true, force: true });
4945
5123
  }
4946
5124
  await mkdir5(installDir, { recursive: true });
4947
5125
  await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
@@ -4993,145 +5171,116 @@ function compareSemver(a, b) {
4993
5171
  if (a.minor !== b.minor) return a.minor - b.minor;
4994
5172
  return a.patch - b.patch;
4995
5173
  }
5174
+ function promptConfirm(message) {
5175
+ return new Promise((resolve2) => {
5176
+ if (!process.stdin.isTTY) {
5177
+ resolve2(true);
5178
+ return;
5179
+ }
5180
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
5181
+ rl.question(`${message} [y/N] `, (answer) => {
5182
+ rl.close();
5183
+ resolve2(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
5184
+ });
5185
+ });
5186
+ }
4996
5187
 
4997
- // src/lib/commands/diff.ts
4998
- import { existsSync as existsSync7 } from "fs";
4999
- import { readFile as readFile5, mkdtemp, rm as rm5 } from "fs/promises";
5000
- import { join as join9 } from "path";
5001
- import { tmpdir } from "os";
5002
- async function runDiff(input, projectDir) {
5188
+ // src/lib/commands/list.ts
5189
+ async function runList(input, projectDir) {
5003
5190
  const config = await readProjectConfig(projectDir);
5004
5191
  const lock = await readLockFile(projectDir);
5005
- const spec = parsePackageSpec(input.packageSpec);
5006
- const name = spec.name;
5007
- if (!config.packages[name]) {
5008
- throw new Error(`Package "${name}" not found. Available: ${Object.keys(config.packages).join(", ")}`);
5009
- }
5010
- const pkg = config.packages[name];
5011
- const registry = resolveRegistryForPackage(config, name);
5012
- const repoDir = await ensureCloned(registry.owner, registry.repo);
5013
- const manifest = await readManifestFromRepo(repoDir);
5014
- let targetVersion;
5015
- if (spec.version) {
5016
- targetVersion = spec.version;
5017
- } else {
5018
- const versions = listVersionsFromManifest(manifest, name);
5019
- if (versions.length === 0) {
5020
- throw new Error(`No versions found for ${name} in registry manifest`);
5021
- }
5022
- const sorted = versions.map((v) => ({ raw: v, parts: parseSemverSimple(v) })).filter((v) => v.parts !== null).sort((a, b) => compareSemverSimple(a.parts, b.parts));
5023
- targetVersion = sorted[sorted.length - 1].raw;
5024
- }
5025
- if (targetVersion === pkg.version) {
5026
- log.info(`${name} is already at ${targetVersion}`);
5027
- return;
5028
- }
5029
- log.step(`Comparing ${name} ${pkg.version} \u2192 ${targetVersion}`);
5030
- const resolved = resolveVersionFromManifest(manifest, name, targetVersion);
5031
- const tmpDir = await mkdtemp(join9(tmpdir(), "agent-pkg-diff-"));
5032
- try {
5033
- const targetDir = join9(tmpDir, "target");
5034
- await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, targetDir);
5035
- const currentDir = join9(projectDir, config.install.modulesDir, name);
5036
- if (!existsSync7(currentDir)) {
5037
- throw new Error(`Current package not installed at ${currentDir}. Run sync first.`);
5038
- }
5039
- const currentDsl = await loadYamlSafe(join9(currentDir, "agent-contracts.yaml"));
5040
- const targetDsl = await loadYamlSafe(join9(targetDir, "agent-contracts.yaml"));
5041
- const changes = computeDslDiff(currentDsl, targetDsl);
5042
- if (input.format === "json") {
5043
- console.log(JSON.stringify({
5044
- package: name,
5045
- fromVersion: pkg.version,
5046
- toVersion: targetVersion,
5047
- changes
5048
- }, null, 2));
5049
- } else {
5050
- printTextDiff(name, pkg.version, targetVersion, changes);
5051
- }
5052
- const hasBreaking = changes.some((c) => c.breaking);
5053
- if (hasBreaking) {
5054
- process.exit(2);
5055
- }
5056
- } finally {
5057
- await rm5(tmpDir, { recursive: true, force: true });
5058
- }
5059
- }
5060
- function computeDslDiff(current, target) {
5061
- const changes = [];
5062
- if (!current || !target) return changes;
5063
- const sections = ["agents", "tasks", "workflows", "guardrails", "handoff_types"];
5064
- for (const section of sections) {
5065
- const cur = current[section] || {};
5066
- const tgt = target[section] || {};
5067
- for (const key of Object.keys(tgt)) {
5068
- if (!(key in cur)) {
5069
- changes.push({ section, type: "added", key });
5070
- } else if (JSON.stringify(cur[key]) !== JSON.stringify(tgt[key])) {
5071
- changes.push({ section, type: "modified", key });
5072
- }
5073
- }
5074
- for (const key of Object.keys(cur)) {
5075
- if (!(key in tgt)) {
5076
- changes.push({ section, type: "removed", key, breaking: true });
5192
+ const packages = [];
5193
+ for (const [name, pkg] of Object.entries(config.packages)) {
5194
+ const lockEntry = lock.packages[name];
5195
+ const registryName = pkg.registry || "default";
5196
+ const registry = config.registries[registryName];
5197
+ const entry = {
5198
+ name,
5199
+ version: pkg.version,
5200
+ registry: registryName,
5201
+ installedTo: lockEntry?.installedTo
5202
+ };
5203
+ if (registry) {
5204
+ try {
5205
+ const repoDir = await ensureCloned(registry.owner, registry.repo);
5206
+ const manifest = await readManifestFromRepo(repoDir);
5207
+ const versions = listVersionsFromManifest(manifest, name);
5208
+ if (versions.length > 0) {
5209
+ const sorted = versions.map((v) => ({ raw: v, parts: parseSemver2(v) })).filter((v) => v.parts !== null).sort((a, b) => compareSemver2(a.parts, b.parts));
5210
+ const latest = sorted[sorted.length - 1].raw;
5211
+ entry.latestVersion = latest;
5212
+ entry.outdated = latest !== pkg.version;
5213
+ }
5214
+ } catch (e) {
5215
+ log.warn(`${name}: could not fetch registry (${e.message})`);
5077
5216
  }
5078
5217
  }
5218
+ packages.push(entry);
5079
5219
  }
5080
- return changes;
5081
- }
5082
- function printTextDiff(name, fromVersion, toVersion, changes) {
5083
- console.log(`${name} ${fromVersion} \u2192 ${toVersion}
5084
- `);
5085
- if (changes.length === 0) {
5086
- console.log(" No semantic changes detected.");
5220
+ if (input.json) {
5221
+ console.log(JSON.stringify({ packages }, null, 2));
5087
5222
  return;
5088
5223
  }
5089
- const grouped = /* @__PURE__ */ new Map();
5090
- for (const c of changes) {
5091
- const list = grouped.get(c.section) || [];
5092
- list.push(c);
5093
- grouped.set(c.section, list);
5094
- }
5095
- for (const [section, items] of grouped) {
5096
- const label = section.charAt(0).toUpperCase() + section.slice(1);
5097
- console.log(`${label}:`);
5098
- for (const item of items) {
5099
- const breaking = item.breaking ? " BREAKING" : "";
5100
- console.log(` ${item.type} ${item.key}${breaking}`);
5101
- }
5102
- console.log();
5224
+ if (packages.length === 0) {
5225
+ log.info("No packages installed.");
5226
+ return;
5103
5227
  }
5104
- const hasBreaking = changes.some((c) => c.breaking);
5105
- if (hasBreaking) {
5106
- console.log("Risk:\n BREAKING CHANGE detected");
5228
+ for (const pkg of packages) {
5229
+ const latest = pkg.latestVersion ? ` (latest: ${pkg.latestVersion})` : "";
5230
+ const badge = pkg.outdated ? " [outdated]" : "";
5231
+ console.log(`${pkg.name}@${pkg.version}${latest}${badge}`);
5107
5232
  }
5108
5233
  }
5109
- async function loadYamlSafe(path) {
5110
- if (!existsSync7(path)) return null;
5111
- const { parse } = await import("yaml");
5112
- const content = await readFile5(path, "utf8");
5113
- return parse(content) || {};
5114
- }
5115
- function parseSemverSimple(v) {
5234
+ function parseSemver2(v) {
5116
5235
  const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
5117
5236
  if (!m) return null;
5118
- return [+m[1], +m[2], +m[3]];
5237
+ return { major: +m[1], minor: +m[2], patch: +m[3] };
5119
5238
  }
5120
- function compareSemverSimple(a, b) {
5121
- if (a[0] !== b[0]) return a[0] - b[0];
5122
- if (a[1] !== b[1]) return a[1] - b[1];
5123
- return a[2] - b[2];
5239
+ function compareSemver2(a, b) {
5240
+ if (a.major !== b.major) return a.major - b.major;
5241
+ if (a.minor !== b.minor) return a.minor - b.minor;
5242
+ return a.patch - b.patch;
5124
5243
  }
5125
5244
 
5126
5245
  // src/lib/commands/check.ts
5127
5246
  import { existsSync as existsSync8 } from "fs";
5247
+ import { readFile as readFile6 } from "fs/promises";
5128
5248
  import { join as join10 } from "path";
5249
+
5250
+ // src/lib/external-tools.ts
5251
+ import { execFile as execFileCb2 } from "child_process";
5252
+ function exec(cmd, args, cwd2) {
5253
+ return new Promise((resolve2) => {
5254
+ execFileCb2(cmd, args, { cwd: cwd2, maxBuffer: 10 * 1024 * 1024 }, (err, stdout, stderr) => {
5255
+ const exitCode = err && "code" in err ? err.code : err ? 1 : 0;
5256
+ resolve2({ exitCode, stdout: stdout?.trim() ?? "", stderr: stderr?.trim() ?? "" });
5257
+ });
5258
+ });
5259
+ }
5260
+ async function isToolAvailable(cmd) {
5261
+ const { exitCode } = await exec("which", [cmd]);
5262
+ return exitCode === 0;
5263
+ }
5264
+ async function runExternalTool(cmd, args, cwd2) {
5265
+ const available = await isToolAvailable(cmd);
5266
+ if (!available) {
5267
+ log.debug(`${cmd} not found, skipping`);
5268
+ return { available: false, exitCode: -1, stdout: "", stderr: "" };
5269
+ }
5270
+ log.debug(`Running: ${cmd} ${args.join(" ")}`);
5271
+ const result = await exec(cmd, args, cwd2);
5272
+ return { available: true, ...result };
5273
+ }
5274
+
5275
+ // src/lib/commands/check.ts
5129
5276
  async function runCheck(projectDir) {
5130
5277
  const checks = [];
5131
5278
  checks.push(await checkConfigSchema(projectDir));
5132
5279
  checks.push(await checkLockSchema(projectDir));
5133
5280
  checks.push(await checkVersionConsistency(projectDir));
5134
5281
  checks.push(...await checkContentHashes(projectDir));
5282
+ checks.push(await checkResolvedDslHash(projectDir));
5283
+ checks.push(...await runExternalChecks(projectDir));
5135
5284
  const allPassed = checks.every((c) => c.status !== "fail");
5136
5285
  for (const check of checks) {
5137
5286
  const icon = check.status === "pass" ? "\u2713" : check.status === "warn" ? "\u26A0" : "\u2717";
@@ -5234,10 +5383,58 @@ async function checkContentHashes(projectDir) {
5234
5383
  }
5235
5384
  return items;
5236
5385
  }
5386
+ async function checkResolvedDslHash(projectDir) {
5387
+ const buildDir = join10(projectDir, ".agent-pkg", "build");
5388
+ const resolvedPath = join10(buildDir, "resolved.agent-contracts.yaml");
5389
+ if (!existsSync8(resolvedPath)) {
5390
+ return { name: "resolved_dsl_hash", status: "warn", message: "No build artifacts found (.agent-pkg/build/)" };
5391
+ }
5392
+ try {
5393
+ const actualHash = await hashDirectory(buildDir);
5394
+ const hashFilePath = join10(buildDir, ".content-hash");
5395
+ if (!existsSync8(hashFilePath)) {
5396
+ return { name: "resolved_dsl_hash", status: "warn", message: "No .content-hash file in build directory" };
5397
+ }
5398
+ const expectedHash = (await readFile6(hashFilePath, "utf8")).trim();
5399
+ if (actualHash !== expectedHash) {
5400
+ return {
5401
+ name: "resolved_dsl_hash",
5402
+ status: "fail",
5403
+ message: `Build artifacts may be stale. Expected ${expectedHash}, got ${actualHash}`
5404
+ };
5405
+ }
5406
+ return { name: "resolved_dsl_hash", status: "pass" };
5407
+ } catch (e) {
5408
+ return { name: "resolved_dsl_hash", status: "warn", message: e.message };
5409
+ }
5410
+ }
5411
+ async function runExternalChecks(projectDir) {
5412
+ const items = [];
5413
+ const toolChecks = [
5414
+ { name: "agent_contracts_validate", cmd: "agent-contracts", args: ["validate"] },
5415
+ { name: "agent_contracts_lint", cmd: "agent-contracts", args: ["lint", "--strict"] },
5416
+ { name: "agent_runtime_generate_check", cmd: "agent-runtime", args: ["generate", "--check"] },
5417
+ { name: "agent_runtime_doctor", cmd: "agent-runtime", args: ["doctor"] }
5418
+ ];
5419
+ for (const { name, cmd, args } of toolChecks) {
5420
+ const result = await runExternalTool(cmd, args, projectDir);
5421
+ if (!result.available) {
5422
+ items.push({ name, status: "warn", message: `${cmd} not found, skipped` });
5423
+ continue;
5424
+ }
5425
+ if (result.exitCode === 0) {
5426
+ items.push({ name, status: "pass" });
5427
+ } else {
5428
+ const detail = result.stderr || result.stdout;
5429
+ items.push({ name, status: "fail", message: detail.slice(0, 200) });
5430
+ }
5431
+ }
5432
+ return items;
5433
+ }
5237
5434
 
5238
5435
  // src/lib/commands/publish.ts
5239
5436
  import { existsSync as existsSync9 } from "fs";
5240
- import { cp } from "fs/promises";
5437
+ import { cp, readFile as readFile7 } from "fs/promises";
5241
5438
  import { join as join11, resolve, basename } from "path";
5242
5439
  async function runPublish(input, projectDir) {
5243
5440
  const sourceDir = resolve(projectDir, input.path);
@@ -5303,6 +5500,8 @@ async function runPublish(input, projectDir) {
5303
5500
  console.log(JSON.stringify(result2, null, 2));
5304
5501
  return;
5305
5502
  }
5503
+ await runPrePublishValidation(sourceDir);
5504
+ await checkChangelog(sourceDir, version);
5306
5505
  const workDir = await ensureWorkingCopy(owner, repo);
5307
5506
  let registryManifest;
5308
5507
  try {
@@ -5350,16 +5549,51 @@ async function runPublish(input, projectDir) {
5350
5549
  log.debug(`Manifest commit: ${manifestCommit.slice(0, 12)}`);
5351
5550
  await pushBranch(workDir);
5352
5551
  log.success("Pushed to remote");
5552
+ const tagName = `${packageName}/v${version}`;
5553
+ await createTag(workDir, tagName, `Release ${packageName}@${version}`);
5554
+ await pushTag(workDir, tagName);
5555
+ log.success(`Tagged ${tagName}`);
5353
5556
  const result = {
5354
5557
  package: packageName,
5355
5558
  version,
5356
5559
  registry: `github:${owner}/${repo}`,
5357
5560
  commit: packageCommit,
5358
- contentHash
5561
+ contentHash,
5562
+ tag: tagName
5359
5563
  };
5360
5564
  log.success(`Published ${packageName}@${version}`);
5361
5565
  console.log(JSON.stringify(result, null, 2));
5362
5566
  }
5567
+ async function runPrePublishValidation(sourceDir) {
5568
+ const validations = [
5569
+ { cmd: "agent-contracts", args: ["validate"], label: "agent-contracts validate" },
5570
+ { cmd: "agent-contracts", args: ["lint", "--strict"], label: "agent-contracts lint --strict" }
5571
+ ];
5572
+ for (const { cmd, args, label } of validations) {
5573
+ const result = await runExternalTool(cmd, args, sourceDir);
5574
+ if (!result.available) {
5575
+ log.warn(`${label}: skipped (${cmd} not found)`);
5576
+ continue;
5577
+ }
5578
+ if (result.exitCode !== 0) {
5579
+ const detail = result.stderr || result.stdout;
5580
+ throw new Error(`Pre-publish validation failed: ${label}
5581
+ ${detail}`);
5582
+ }
5583
+ log.success(`${label}: passed`);
5584
+ }
5585
+ }
5586
+ async function checkChangelog(sourceDir, version) {
5587
+ const changelogPath = join11(sourceDir, "CHANGELOG.md");
5588
+ if (!existsSync9(changelogPath)) {
5589
+ log.warn("CHANGELOG.md not found \u2014 consider adding one before publishing");
5590
+ return;
5591
+ }
5592
+ const content = await readFile7(changelogPath, "utf8");
5593
+ if (!content.includes(version)) {
5594
+ log.warn(`CHANGELOG.md does not mention version ${version}`);
5595
+ }
5596
+ }
5363
5597
 
5364
5598
  // src/cli/index.ts
5365
5599
  function setupGlobals(globals) {
@@ -5414,6 +5648,10 @@ var handlers = {
5414
5648
  format: opts.format
5415
5649
  }, cwd).catch(handleError);
5416
5650
  },
5651
+ list: async (opts, globals) => {
5652
+ setupGlobals(globals);
5653
+ await runList({ json: opts.json }, cwd).catch(handleError);
5654
+ },
5417
5655
  check: async (_opts, globals) => {
5418
5656
  setupGlobals(globals);
5419
5657
  await runCheck(cwd).catch(handleError);