agent-package-manager 0.4.5 → 0.5.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.
package/dist/cli/index.js CHANGED
@@ -4402,6 +4402,12 @@ async function commitAll(cwd2, message) {
4402
4402
  async function pushBranch(cwd2, remote = "origin", branch = "main") {
4403
4403
  await git(["push", remote, branch], cwd2);
4404
4404
  }
4405
+ async function createTag(cwd2, tagName, message) {
4406
+ await git(["tag", "-a", tagName, "-m", message], cwd2);
4407
+ }
4408
+ async function pushTag(cwd2, tagName, remote = "origin") {
4409
+ await git(["push", remote, tagName], cwd2);
4410
+ }
4405
4411
 
4406
4412
  // src/lib/registry.ts
4407
4413
  import { readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
@@ -4755,10 +4761,143 @@ async function runSync(input, projectDir) {
4755
4761
  }
4756
4762
 
4757
4763
  // src/lib/commands/update.ts
4764
+ import { existsSync as existsSync7 } from "fs";
4765
+ import { mkdir as mkdir5, rm as rm5, mkdtemp as mkdtemp2 } from "fs/promises";
4766
+ import { join as join9 } from "path";
4767
+ import { tmpdir as tmpdir2 } from "os";
4768
+ import { createInterface } from "readline";
4769
+ import semver3 from "semver";
4770
+
4771
+ // src/lib/commands/diff.ts
4758
4772
  import { existsSync as existsSync6 } from "fs";
4759
- import { mkdir as mkdir5, rm as rm4 } from "fs/promises";
4773
+ import { readFile as readFile5, mkdtemp, rm as rm4 } from "fs/promises";
4760
4774
  import { join as join8 } from "path";
4761
- import semver3 from "semver";
4775
+ import { tmpdir } from "os";
4776
+ async function runDiff(input, projectDir) {
4777
+ const config = await readProjectConfig(projectDir);
4778
+ const lock = await readLockFile(projectDir);
4779
+ const spec = parsePackageSpec(input.packageSpec);
4780
+ const name = spec.name;
4781
+ if (!config.packages[name]) {
4782
+ throw new Error(`Package "${name}" not found. Available: ${Object.keys(config.packages).join(", ")}`);
4783
+ }
4784
+ const pkg = config.packages[name];
4785
+ const registry = resolveRegistryForPackage(config, name);
4786
+ const repoDir = await ensureCloned(registry.owner, registry.repo);
4787
+ const manifest = await readManifestFromRepo(repoDir);
4788
+ let targetVersion;
4789
+ if (spec.version) {
4790
+ targetVersion = spec.version;
4791
+ } else {
4792
+ const versions = listVersionsFromManifest(manifest, name);
4793
+ if (versions.length === 0) {
4794
+ throw new Error(`No versions found for ${name} in registry manifest`);
4795
+ }
4796
+ const sorted = versions.map((v) => ({ raw: v, parts: parseSemverSimple(v) })).filter((v) => v.parts !== null).sort((a, b) => compareSemverSimple(a.parts, b.parts));
4797
+ targetVersion = sorted[sorted.length - 1].raw;
4798
+ }
4799
+ if (targetVersion === pkg.version) {
4800
+ log.info(`${name} is already at ${targetVersion}`);
4801
+ return;
4802
+ }
4803
+ log.step(`Comparing ${name} ${pkg.version} \u2192 ${targetVersion}`);
4804
+ const resolved = resolveVersionFromManifest(manifest, name, targetVersion);
4805
+ const tmpDir = await mkdtemp(join8(tmpdir(), "agent-pkg-diff-"));
4806
+ try {
4807
+ const targetDir = join8(tmpDir, "target");
4808
+ await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, targetDir);
4809
+ const currentDir = join8(projectDir, config.install.modulesDir, name);
4810
+ if (!existsSync6(currentDir)) {
4811
+ throw new Error(`Current package not installed at ${currentDir}. Run sync first.`);
4812
+ }
4813
+ const currentDsl = await loadYamlSafe(join8(currentDir, "agent-contracts.yaml"));
4814
+ const targetDsl = await loadYamlSafe(join8(targetDir, "agent-contracts.yaml"));
4815
+ const changes = computeDslDiff(currentDsl, targetDsl);
4816
+ if (input.format === "json") {
4817
+ console.log(JSON.stringify({
4818
+ package: name,
4819
+ fromVersion: pkg.version,
4820
+ toVersion: targetVersion,
4821
+ changes
4822
+ }, null, 2));
4823
+ } else {
4824
+ printTextDiff(name, pkg.version, targetVersion, changes);
4825
+ }
4826
+ const hasBreaking = changes.some((c) => c.breaking);
4827
+ if (hasBreaking) {
4828
+ process.exit(2);
4829
+ }
4830
+ } finally {
4831
+ await rm4(tmpDir, { recursive: true, force: true });
4832
+ }
4833
+ }
4834
+ function computeDslDiff(current, target) {
4835
+ const changes = [];
4836
+ if (!current || !target) return changes;
4837
+ const sections = ["agents", "tasks", "workflows", "guardrails", "handoff_types"];
4838
+ for (const section of sections) {
4839
+ const cur = current[section] || {};
4840
+ const tgt = target[section] || {};
4841
+ for (const key of Object.keys(tgt)) {
4842
+ if (!(key in cur)) {
4843
+ changes.push({ section, type: "added", key });
4844
+ } else if (JSON.stringify(cur[key]) !== JSON.stringify(tgt[key])) {
4845
+ changes.push({ section, type: "modified", key });
4846
+ }
4847
+ }
4848
+ for (const key of Object.keys(cur)) {
4849
+ if (!(key in tgt)) {
4850
+ changes.push({ section, type: "removed", key, breaking: true });
4851
+ }
4852
+ }
4853
+ }
4854
+ return changes;
4855
+ }
4856
+ function printTextDiff(name, fromVersion, toVersion, changes) {
4857
+ console.log(`${name} ${fromVersion} \u2192 ${toVersion}
4858
+ `);
4859
+ if (changes.length === 0) {
4860
+ console.log(" No semantic changes detected.");
4861
+ return;
4862
+ }
4863
+ const grouped = /* @__PURE__ */ new Map();
4864
+ for (const c of changes) {
4865
+ const list = grouped.get(c.section) || [];
4866
+ list.push(c);
4867
+ grouped.set(c.section, list);
4868
+ }
4869
+ for (const [section, items] of grouped) {
4870
+ const label = section.charAt(0).toUpperCase() + section.slice(1);
4871
+ console.log(`${label}:`);
4872
+ for (const item of items) {
4873
+ const breaking = item.breaking ? " BREAKING" : "";
4874
+ console.log(` ${item.type} ${item.key}${breaking}`);
4875
+ }
4876
+ console.log();
4877
+ }
4878
+ const hasBreaking = changes.some((c) => c.breaking);
4879
+ if (hasBreaking) {
4880
+ console.log("Risk:\n BREAKING CHANGE detected");
4881
+ }
4882
+ }
4883
+ async function loadYamlSafe(path) {
4884
+ if (!existsSync6(path)) return null;
4885
+ const { parse } = await import("yaml");
4886
+ const content = await readFile5(path, "utf8");
4887
+ return parse(content) || {};
4888
+ }
4889
+ function parseSemverSimple(v) {
4890
+ const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
4891
+ if (!m) return null;
4892
+ return [+m[1], +m[2], +m[3]];
4893
+ }
4894
+ function compareSemverSimple(a, b) {
4895
+ if (a[0] !== b[0]) return a[0] - b[0];
4896
+ if (a[1] !== b[1]) return a[1] - b[1];
4897
+ return a[2] - b[2];
4898
+ }
4899
+
4900
+ // src/lib/commands/update.ts
4762
4901
  async function runUpdate(input, projectDir) {
4763
4902
  const config = await readProjectConfig(projectDir);
4764
4903
  const lock = await readLockFile(projectDir);
@@ -4823,10 +4962,46 @@ async function runUpdate(input, projectDir) {
4823
4962
  const breaking = u.hasBreakingChanges ? " (BREAKING)" : "";
4824
4963
  log.info(`${u.package}: ${u.fromVersion} \u2192 ${u.toVersion}${breaking}`);
4825
4964
  }
4965
+ let hasAnyBreaking = false;
4966
+ for (const u of updates) {
4967
+ const pkg = config.packages[u.package];
4968
+ const registryName = pkg.registry || "default";
4969
+ const registry = config.registries[registryName];
4970
+ if (!registry) continue;
4971
+ const currentDir = join9(projectDir, config.install.modulesDir, u.package);
4972
+ if (!existsSync7(currentDir)) continue;
4973
+ const repoDir = await ensureCloned(registry.owner, registry.repo);
4974
+ const manifest = await readManifestFromRepo(repoDir);
4975
+ const resolved = resolveVersionFromManifest(manifest, u.package, u.toVersion);
4976
+ const tmpDir = await mkdtemp2(join9(tmpdir2(), "agent-pkg-update-diff-"));
4977
+ try {
4978
+ const targetDir = join9(tmpDir, "target");
4979
+ await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, targetDir);
4980
+ const currentDsl = await loadYamlSafe(join9(currentDir, "agent-contracts.yaml"));
4981
+ const targetDsl = await loadYamlSafe(join9(targetDir, "agent-contracts.yaml"));
4982
+ const changes = computeDslDiff(currentDsl, targetDsl);
4983
+ if (changes.length > 0) {
4984
+ console.log();
4985
+ printTextDiff(u.package, u.fromVersion, u.toVersion, changes);
4986
+ if (changes.some((c) => c.breaking)) {
4987
+ hasAnyBreaking = true;
4988
+ }
4989
+ }
4990
+ } finally {
4991
+ await rm5(tmpDir, { recursive: true, force: true });
4992
+ }
4993
+ }
4826
4994
  if (input.dryRun) {
4827
4995
  console.log(JSON.stringify({ updates, dryRun: true }, null, 2));
4828
4996
  return;
4829
4997
  }
4998
+ if (hasAnyBreaking && !input.yes) {
4999
+ const confirmed = await promptConfirm("BREAKING CHANGES detected. Continue with update?");
5000
+ if (!confirmed) {
5001
+ log.info("Update cancelled");
5002
+ return;
5003
+ }
5004
+ }
4830
5005
  const installedDeps = [];
4831
5006
  for (const u of updates) {
4832
5007
  const pkg = config.packages[u.package];
@@ -4835,9 +5010,9 @@ async function runUpdate(input, projectDir) {
4835
5010
  const repoDir = await ensureCloned(registry.owner, registry.repo);
4836
5011
  const manifest = await readManifestFromRepo(repoDir);
4837
5012
  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 });
5013
+ const installDir = join9(projectDir, config.install.modulesDir, u.package);
5014
+ if (existsSync7(installDir)) {
5015
+ await rm5(installDir, { recursive: true, force: true });
4841
5016
  }
4842
5017
  await mkdir5(installDir, { recursive: true });
4843
5018
  await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
@@ -4877,16 +5052,16 @@ async function runUpdate(input, projectDir) {
4877
5052
  const registryName = pkg.registry || "default";
4878
5053
  const registry = config.registries[registryName];
4879
5054
  if (!registry) continue;
4880
- const installDir = join8(projectDir, config.install.modulesDir, name);
4881
- if (!existsSync6(installDir)) continue;
5055
+ const installDir = join9(projectDir, config.install.modulesDir, name);
5056
+ if (!existsSync7(installDir)) continue;
4882
5057
  const pkgManifest = await readPackageManifest(installDir);
4883
5058
  if (!pkgManifest?.dependencies) continue;
4884
5059
  const missingDeps = Object.entries(pkgManifest.dependencies).filter(
4885
5060
  ([depId, range]) => {
4886
5061
  const existing = config.packages[depId];
4887
5062
  if (!existing) return true;
4888
- const depDir = join8(projectDir, config.install.modulesDir, depId);
4889
- if (!existsSync6(depDir)) return true;
5063
+ const depDir = join9(projectDir, config.install.modulesDir, depId);
5064
+ if (!existsSync7(depDir)) return true;
4890
5065
  return !semver3.satisfies(existing.version, range);
4891
5066
  }
4892
5067
  );
@@ -4925,8 +5100,8 @@ async function installDependencies2(projectDir, config, lock, registry, registry
4925
5100
  throw new Error(`Circular dependency detected: ${chain}`);
4926
5101
  }
4927
5102
  const existing = config.packages[depId];
4928
- const depDir = join8(projectDir, config.install.modulesDir, depId);
4929
- if (existing && existsSync6(depDir) && semver3.satisfies(existing.version, range)) {
5103
+ const depDir = join9(projectDir, config.install.modulesDir, depId);
5104
+ if (existing && existsSync7(depDir) && semver3.satisfies(existing.version, range)) {
4930
5105
  log.debug(`Dependency ${depId}@${existing.version} already satisfies ${range}`);
4931
5106
  continue;
4932
5107
  }
@@ -4939,9 +5114,9 @@ async function installDependencies2(projectDir, config, lock, registry, registry
4939
5114
  log.step(`Dependency: ${depId}@${resolvedVersion} (required: ${range})`);
4940
5115
  resolving.add(depId);
4941
5116
  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 });
5117
+ const installDir = join9(projectDir, config.install.modulesDir, depId);
5118
+ if (existsSync7(installDir)) {
5119
+ await rm5(installDir, { recursive: true, force: true });
4945
5120
  }
4946
5121
  await mkdir5(installDir, { recursive: true });
4947
5122
  await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
@@ -4993,145 +5168,59 @@ function compareSemver(a, b) {
4993
5168
  if (a.minor !== b.minor) return a.minor - b.minor;
4994
5169
  return a.patch - b.patch;
4995
5170
  }
4996
-
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) {
5003
- const config = await readProjectConfig(projectDir);
5004
- 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 });
5077
- }
5078
- }
5079
- }
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.");
5087
- return;
5088
- }
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}`);
5171
+ function promptConfirm(message) {
5172
+ return new Promise((resolve2) => {
5173
+ if (!process.stdin.isTTY) {
5174
+ resolve2(true);
5175
+ return;
5101
5176
  }
5102
- console.log();
5103
- }
5104
- const hasBreaking = changes.some((c) => c.breaking);
5105
- if (hasBreaking) {
5106
- console.log("Risk:\n BREAKING CHANGE detected");
5107
- }
5177
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
5178
+ rl.question(`${message} [y/N] `, (answer) => {
5179
+ rl.close();
5180
+ resolve2(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
5181
+ });
5182
+ });
5108
5183
  }
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) || {};
5184
+
5185
+ // src/lib/commands/check.ts
5186
+ import { existsSync as existsSync8 } from "fs";
5187
+ import { readFile as readFile6 } from "fs/promises";
5188
+ import { join as join10 } from "path";
5189
+
5190
+ // src/lib/external-tools.ts
5191
+ import { execFile as execFileCb2 } from "child_process";
5192
+ function exec(cmd, args, cwd2) {
5193
+ return new Promise((resolve2) => {
5194
+ execFileCb2(cmd, args, { cwd: cwd2, maxBuffer: 10 * 1024 * 1024 }, (err, stdout, stderr) => {
5195
+ const exitCode = err && "code" in err ? err.code : err ? 1 : 0;
5196
+ resolve2({ exitCode, stdout: stdout?.trim() ?? "", stderr: stderr?.trim() ?? "" });
5197
+ });
5198
+ });
5114
5199
  }
5115
- function parseSemverSimple(v) {
5116
- const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
5117
- if (!m) return null;
5118
- return [+m[1], +m[2], +m[3]];
5200
+ async function isToolAvailable(cmd) {
5201
+ const { exitCode } = await exec("which", [cmd]);
5202
+ return exitCode === 0;
5119
5203
  }
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];
5204
+ async function runExternalTool(cmd, args, cwd2) {
5205
+ const available = await isToolAvailable(cmd);
5206
+ if (!available) {
5207
+ log.debug(`${cmd} not found, skipping`);
5208
+ return { available: false, exitCode: -1, stdout: "", stderr: "" };
5209
+ }
5210
+ log.debug(`Running: ${cmd} ${args.join(" ")}`);
5211
+ const result = await exec(cmd, args, cwd2);
5212
+ return { available: true, ...result };
5124
5213
  }
5125
5214
 
5126
5215
  // src/lib/commands/check.ts
5127
- import { existsSync as existsSync8 } from "fs";
5128
- import { join as join10 } from "path";
5129
5216
  async function runCheck(projectDir) {
5130
5217
  const checks = [];
5131
5218
  checks.push(await checkConfigSchema(projectDir));
5132
5219
  checks.push(await checkLockSchema(projectDir));
5133
5220
  checks.push(await checkVersionConsistency(projectDir));
5134
5221
  checks.push(...await checkContentHashes(projectDir));
5222
+ checks.push(await checkResolvedDslHash(projectDir));
5223
+ checks.push(...await runExternalChecks(projectDir));
5135
5224
  const allPassed = checks.every((c) => c.status !== "fail");
5136
5225
  for (const check of checks) {
5137
5226
  const icon = check.status === "pass" ? "\u2713" : check.status === "warn" ? "\u26A0" : "\u2717";
@@ -5234,10 +5323,58 @@ async function checkContentHashes(projectDir) {
5234
5323
  }
5235
5324
  return items;
5236
5325
  }
5326
+ async function checkResolvedDslHash(projectDir) {
5327
+ const buildDir = join10(projectDir, ".agent-pkg", "build");
5328
+ const resolvedPath = join10(buildDir, "resolved.agent-contracts.yaml");
5329
+ if (!existsSync8(resolvedPath)) {
5330
+ return { name: "resolved_dsl_hash", status: "warn", message: "No build artifacts found (.agent-pkg/build/)" };
5331
+ }
5332
+ try {
5333
+ const actualHash = await hashDirectory(buildDir);
5334
+ const hashFilePath = join10(buildDir, ".content-hash");
5335
+ if (!existsSync8(hashFilePath)) {
5336
+ return { name: "resolved_dsl_hash", status: "warn", message: "No .content-hash file in build directory" };
5337
+ }
5338
+ const expectedHash = (await readFile6(hashFilePath, "utf8")).trim();
5339
+ if (actualHash !== expectedHash) {
5340
+ return {
5341
+ name: "resolved_dsl_hash",
5342
+ status: "fail",
5343
+ message: `Build artifacts may be stale. Expected ${expectedHash}, got ${actualHash}`
5344
+ };
5345
+ }
5346
+ return { name: "resolved_dsl_hash", status: "pass" };
5347
+ } catch (e) {
5348
+ return { name: "resolved_dsl_hash", status: "warn", message: e.message };
5349
+ }
5350
+ }
5351
+ async function runExternalChecks(projectDir) {
5352
+ const items = [];
5353
+ const toolChecks = [
5354
+ { name: "agent_contracts_validate", cmd: "agent-contracts", args: ["validate"] },
5355
+ { name: "agent_contracts_lint", cmd: "agent-contracts", args: ["lint", "--strict"] },
5356
+ { name: "agent_runtime_generate_check", cmd: "agent-runtime", args: ["generate", "--check"] },
5357
+ { name: "agent_runtime_doctor", cmd: "agent-runtime", args: ["doctor"] }
5358
+ ];
5359
+ for (const { name, cmd, args } of toolChecks) {
5360
+ const result = await runExternalTool(cmd, args, projectDir);
5361
+ if (!result.available) {
5362
+ items.push({ name, status: "warn", message: `${cmd} not found, skipped` });
5363
+ continue;
5364
+ }
5365
+ if (result.exitCode === 0) {
5366
+ items.push({ name, status: "pass" });
5367
+ } else {
5368
+ const detail = result.stderr || result.stdout;
5369
+ items.push({ name, status: "fail", message: detail.slice(0, 200) });
5370
+ }
5371
+ }
5372
+ return items;
5373
+ }
5237
5374
 
5238
5375
  // src/lib/commands/publish.ts
5239
5376
  import { existsSync as existsSync9 } from "fs";
5240
- import { cp } from "fs/promises";
5377
+ import { cp, readFile as readFile7 } from "fs/promises";
5241
5378
  import { join as join11, resolve, basename } from "path";
5242
5379
  async function runPublish(input, projectDir) {
5243
5380
  const sourceDir = resolve(projectDir, input.path);
@@ -5303,6 +5440,8 @@ async function runPublish(input, projectDir) {
5303
5440
  console.log(JSON.stringify(result2, null, 2));
5304
5441
  return;
5305
5442
  }
5443
+ await runPrePublishValidation(sourceDir);
5444
+ await checkChangelog(sourceDir, version);
5306
5445
  const workDir = await ensureWorkingCopy(owner, repo);
5307
5446
  let registryManifest;
5308
5447
  try {
@@ -5350,16 +5489,51 @@ async function runPublish(input, projectDir) {
5350
5489
  log.debug(`Manifest commit: ${manifestCommit.slice(0, 12)}`);
5351
5490
  await pushBranch(workDir);
5352
5491
  log.success("Pushed to remote");
5492
+ const tagName = `${packageName}/v${version}`;
5493
+ await createTag(workDir, tagName, `Release ${packageName}@${version}`);
5494
+ await pushTag(workDir, tagName);
5495
+ log.success(`Tagged ${tagName}`);
5353
5496
  const result = {
5354
5497
  package: packageName,
5355
5498
  version,
5356
5499
  registry: `github:${owner}/${repo}`,
5357
5500
  commit: packageCommit,
5358
- contentHash
5501
+ contentHash,
5502
+ tag: tagName
5359
5503
  };
5360
5504
  log.success(`Published ${packageName}@${version}`);
5361
5505
  console.log(JSON.stringify(result, null, 2));
5362
5506
  }
5507
+ async function runPrePublishValidation(sourceDir) {
5508
+ const validations = [
5509
+ { cmd: "agent-contracts", args: ["validate"], label: "agent-contracts validate" },
5510
+ { cmd: "agent-contracts", args: ["lint", "--strict"], label: "agent-contracts lint --strict" }
5511
+ ];
5512
+ for (const { cmd, args, label } of validations) {
5513
+ const result = await runExternalTool(cmd, args, sourceDir);
5514
+ if (!result.available) {
5515
+ log.warn(`${label}: skipped (${cmd} not found)`);
5516
+ continue;
5517
+ }
5518
+ if (result.exitCode !== 0) {
5519
+ const detail = result.stderr || result.stdout;
5520
+ throw new Error(`Pre-publish validation failed: ${label}
5521
+ ${detail}`);
5522
+ }
5523
+ log.success(`${label}: passed`);
5524
+ }
5525
+ }
5526
+ async function checkChangelog(sourceDir, version) {
5527
+ const changelogPath = join11(sourceDir, "CHANGELOG.md");
5528
+ if (!existsSync9(changelogPath)) {
5529
+ log.warn("CHANGELOG.md not found \u2014 consider adding one before publishing");
5530
+ return;
5531
+ }
5532
+ const content = await readFile7(changelogPath, "utf8");
5533
+ if (!content.includes(version)) {
5534
+ log.warn(`CHANGELOG.md does not mention version ${version}`);
5535
+ }
5536
+ }
5363
5537
 
5364
5538
  // src/cli/index.ts
5365
5539
  function setupGlobals(globals) {