agent-package-manager 0.4.4 → 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/README.md +0 -4
- package/cli-contract.yaml +12 -112
- package/dist/cli/index.js +326 -322
- package/dist/cli/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -10,10 +10,10 @@ function createProgram(handlers2, version) {
|
|
|
10
10
|
const program2 = new Command();
|
|
11
11
|
program2.name("agent-pkg").version(version, "-V, --version").description("Manage agent-contracts DSL packages from GitHub registries.");
|
|
12
12
|
program2.option("-v, --verbose", "Enable verbose output.", false);
|
|
13
|
-
program2.command("init").description("Initialize a project for agent-pkg package management.").option("-r, --registry <url>", "Default registry in the format github:<owner>/<repo>.").option("--modules-dir <path>", "Directory to store fetched packages.", "agent_modules").
|
|
13
|
+
program2.command("init").description("Initialize a project for agent-pkg package management.").option("-r, --registry <url>", "Default registry in the format github:<owner>/<repo>.").option("--modules-dir <path>", "Directory to store fetched packages.", "agent_modules").action(async (opts, cmd) => {
|
|
14
14
|
await handlers2.init(opts, cmd.optsWithGlobals());
|
|
15
15
|
});
|
|
16
|
-
program2.command("add").description("Add a package from a registry.").argument("<package>", "Package specifier in the format <name>@<version> or github:<owner>/<repo>//<path>@<version>.").option("-r, --registry <name>", "Registry name to use (from agent-pkg.json registries).", "default").option("--alias <name>", "Install under an alternative directory name.").
|
|
16
|
+
program2.command("add").description("Add a package from a registry.").argument("<package>", "Package specifier in the format <name>@<version> or github:<owner>/<repo>//<path>@<version>.").option("-r, --registry <name>", "Registry name to use (from agent-pkg.json registries).", "default").option("--alias <name>", "Install under an alternative directory name.").action(async (packageArg, opts, cmd) => {
|
|
17
17
|
await handlers2.add(packageArg, opts, cmd.optsWithGlobals());
|
|
18
18
|
});
|
|
19
19
|
program2.command("sync").description("Restore agent_modules from lock file.").option("--check", "Dry-run mode for CI. Exits with code 1 if agent_modules would change (drift detected).", false).action(async (opts, cmd) => {
|
|
@@ -25,9 +25,6 @@ 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("materialize").description("Build resolved DSL and generate runtime artifacts.").option("--no-generate", "Skip agent-runtime generate step.", false).option("--no-lint", "Skip agent-contracts lint step.", false).option("--clean", "Clean build directory before materializing.", false).action(async (opts, cmd) => {
|
|
29
|
-
await handlers2.materialize(opts, cmd.optsWithGlobals());
|
|
30
|
-
});
|
|
31
28
|
program2.command("check").description("Run full verification pipeline for CI.").action(async (opts, cmd) => {
|
|
32
29
|
await handlers2.check({}, cmd.optsWithGlobals());
|
|
33
30
|
});
|
|
@@ -4180,8 +4177,6 @@ var PackageManifestSchema = external_exports.strictObject({
|
|
|
4180
4177
|
var CONFIG_FILE = "agent-pkg.json";
|
|
4181
4178
|
var LOCK_FILE = "agent-pkg.lock.json";
|
|
4182
4179
|
var DEFAULT_MODULES_DIR = "agent_modules";
|
|
4183
|
-
var DEFAULT_BUILD_DIR = ".agent-pkg/build";
|
|
4184
|
-
var DEFAULT_CACHE_DIR = ".agent-pkg/cache";
|
|
4185
4180
|
var PACKAGE_MANIFEST_FILE = "agent-pkg.package.json";
|
|
4186
4181
|
var REGISTRY_MANIFEST_FILE = "agent-pkg.registry.json";
|
|
4187
4182
|
var DEFAULT_ENTRYPOINT = "agent-contracts.yaml";
|
|
@@ -4193,8 +4188,6 @@ async function runInit(opts, projectDir) {
|
|
|
4193
4188
|
throw new Error(`${CONFIG_FILE} already exists. Aborting init.`);
|
|
4194
4189
|
}
|
|
4195
4190
|
const modulesDir = opts.modulesDir || DEFAULT_MODULES_DIR;
|
|
4196
|
-
const buildDir = opts.buildDir || DEFAULT_BUILD_DIR;
|
|
4197
|
-
const cacheDir = DEFAULT_CACHE_DIR;
|
|
4198
4191
|
const filesCreated = [];
|
|
4199
4192
|
const dirsCreated = [];
|
|
4200
4193
|
const registries = {};
|
|
@@ -4211,15 +4204,9 @@ async function runInit(opts, projectDir) {
|
|
|
4211
4204
|
const config = {
|
|
4212
4205
|
schemaVersion: 1,
|
|
4213
4206
|
registries,
|
|
4214
|
-
install: { modulesDir
|
|
4207
|
+
install: { modulesDir },
|
|
4215
4208
|
packages: {},
|
|
4216
|
-
vars: {}
|
|
4217
|
-
materialize: {
|
|
4218
|
-
writeResolvedDsl: true,
|
|
4219
|
-
runValidate: true,
|
|
4220
|
-
runLint: true,
|
|
4221
|
-
runRuntimeGenerate: true
|
|
4222
|
-
}
|
|
4209
|
+
vars: {}
|
|
4223
4210
|
};
|
|
4224
4211
|
await writeFile(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
4225
4212
|
filesCreated.push(CONFIG_FILE);
|
|
@@ -4243,22 +4230,7 @@ async function runInit(opts, projectDir) {
|
|
|
4243
4230
|
filesCreated.push("agent-contracts.yaml");
|
|
4244
4231
|
log.success("Created agent-contracts.yaml");
|
|
4245
4232
|
}
|
|
4246
|
-
|
|
4247
|
-
await writeFile(
|
|
4248
|
-
join(projectDir, "agent-runtime.config.yaml"),
|
|
4249
|
-
`dsl: ./${buildDir}/resolved.agent-contracts.yaml
|
|
4250
|
-
generated_dir: ./agent/generated
|
|
4251
|
-
|
|
4252
|
-
bindings: []
|
|
4253
|
-
|
|
4254
|
-
active_guardrail_policy: default
|
|
4255
|
-
`,
|
|
4256
|
-
"utf8"
|
|
4257
|
-
);
|
|
4258
|
-
filesCreated.push("agent-runtime.config.yaml");
|
|
4259
|
-
log.success("Created agent-runtime.config.yaml");
|
|
4260
|
-
}
|
|
4261
|
-
for (const dir of [modulesDir, "agent_overrides", buildDir, cacheDir]) {
|
|
4233
|
+
for (const dir of [modulesDir, "agent_overrides"]) {
|
|
4262
4234
|
const full = join(projectDir, dir);
|
|
4263
4235
|
if (!existsSync(full)) {
|
|
4264
4236
|
await mkdir(full, { recursive: true });
|
|
@@ -4430,6 +4402,12 @@ async function commitAll(cwd2, message) {
|
|
|
4430
4402
|
async function pushBranch(cwd2, remote = "origin", branch = "main") {
|
|
4431
4403
|
await git(["push", remote, branch], cwd2);
|
|
4432
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
|
+
}
|
|
4433
4411
|
|
|
4434
4412
|
// src/lib/registry.ts
|
|
4435
4413
|
import { readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
|
|
@@ -4539,9 +4517,6 @@ async function collectFiles(dir) {
|
|
|
4539
4517
|
}
|
|
4540
4518
|
return results;
|
|
4541
4519
|
}
|
|
4542
|
-
function hashString(content) {
|
|
4543
|
-
return `sha256:${createHash("sha256").update(content, "utf8").digest("hex")}`;
|
|
4544
|
-
}
|
|
4545
4520
|
|
|
4546
4521
|
// src/lib/commands/add.ts
|
|
4547
4522
|
async function runAdd(input, projectDir) {
|
|
@@ -4613,8 +4588,7 @@ async function runAdd(input, projectDir) {
|
|
|
4613
4588
|
version: spec.version,
|
|
4614
4589
|
commit: lock.packages[packageName]?.commit,
|
|
4615
4590
|
installedTo: `${config.install.modulesDir}/${packageName}`,
|
|
4616
|
-
dependencies: ctx.installOrder.filter((p) => p !== packageName)
|
|
4617
|
-
materialized: false
|
|
4591
|
+
dependencies: ctx.installOrder.filter((p) => p !== packageName)
|
|
4618
4592
|
};
|
|
4619
4593
|
log.success(`Added ${packageName}@${spec.version}`);
|
|
4620
4594
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -4787,10 +4761,143 @@ async function runSync(input, projectDir) {
|
|
|
4787
4761
|
}
|
|
4788
4762
|
|
|
4789
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
|
|
4790
4772
|
import { existsSync as existsSync6 } from "fs";
|
|
4791
|
-
import {
|
|
4773
|
+
import { readFile as readFile5, mkdtemp, rm as rm4 } from "fs/promises";
|
|
4792
4774
|
import { join as join8 } from "path";
|
|
4793
|
-
import
|
|
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
|
|
4794
4901
|
async function runUpdate(input, projectDir) {
|
|
4795
4902
|
const config = await readProjectConfig(projectDir);
|
|
4796
4903
|
const lock = await readLockFile(projectDir);
|
|
@@ -4855,10 +4962,46 @@ async function runUpdate(input, projectDir) {
|
|
|
4855
4962
|
const breaking = u.hasBreakingChanges ? " (BREAKING)" : "";
|
|
4856
4963
|
log.info(`${u.package}: ${u.fromVersion} \u2192 ${u.toVersion}${breaking}`);
|
|
4857
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
|
+
}
|
|
4858
4994
|
if (input.dryRun) {
|
|
4859
4995
|
console.log(JSON.stringify({ updates, dryRun: true }, null, 2));
|
|
4860
4996
|
return;
|
|
4861
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
|
+
}
|
|
4862
5005
|
const installedDeps = [];
|
|
4863
5006
|
for (const u of updates) {
|
|
4864
5007
|
const pkg = config.packages[u.package];
|
|
@@ -4867,9 +5010,9 @@ async function runUpdate(input, projectDir) {
|
|
|
4867
5010
|
const repoDir = await ensureCloned(registry.owner, registry.repo);
|
|
4868
5011
|
const manifest = await readManifestFromRepo(repoDir);
|
|
4869
5012
|
const resolved = resolveVersionFromManifest(manifest, u.package, u.toVersion);
|
|
4870
|
-
const installDir =
|
|
4871
|
-
if (
|
|
4872
|
-
await
|
|
5013
|
+
const installDir = join9(projectDir, config.install.modulesDir, u.package);
|
|
5014
|
+
if (existsSync7(installDir)) {
|
|
5015
|
+
await rm5(installDir, { recursive: true, force: true });
|
|
4873
5016
|
}
|
|
4874
5017
|
await mkdir5(installDir, { recursive: true });
|
|
4875
5018
|
await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
|
|
@@ -4909,16 +5052,16 @@ async function runUpdate(input, projectDir) {
|
|
|
4909
5052
|
const registryName = pkg.registry || "default";
|
|
4910
5053
|
const registry = config.registries[registryName];
|
|
4911
5054
|
if (!registry) continue;
|
|
4912
|
-
const installDir =
|
|
4913
|
-
if (!
|
|
5055
|
+
const installDir = join9(projectDir, config.install.modulesDir, name);
|
|
5056
|
+
if (!existsSync7(installDir)) continue;
|
|
4914
5057
|
const pkgManifest = await readPackageManifest(installDir);
|
|
4915
5058
|
if (!pkgManifest?.dependencies) continue;
|
|
4916
5059
|
const missingDeps = Object.entries(pkgManifest.dependencies).filter(
|
|
4917
5060
|
([depId, range]) => {
|
|
4918
5061
|
const existing = config.packages[depId];
|
|
4919
5062
|
if (!existing) return true;
|
|
4920
|
-
const depDir =
|
|
4921
|
-
if (!
|
|
5063
|
+
const depDir = join9(projectDir, config.install.modulesDir, depId);
|
|
5064
|
+
if (!existsSync7(depDir)) return true;
|
|
4922
5065
|
return !semver3.satisfies(existing.version, range);
|
|
4923
5066
|
}
|
|
4924
5067
|
);
|
|
@@ -4957,8 +5100,8 @@ async function installDependencies2(projectDir, config, lock, registry, registry
|
|
|
4957
5100
|
throw new Error(`Circular dependency detected: ${chain}`);
|
|
4958
5101
|
}
|
|
4959
5102
|
const existing = config.packages[depId];
|
|
4960
|
-
const depDir =
|
|
4961
|
-
if (existing &&
|
|
5103
|
+
const depDir = join9(projectDir, config.install.modulesDir, depId);
|
|
5104
|
+
if (existing && existsSync7(depDir) && semver3.satisfies(existing.version, range)) {
|
|
4962
5105
|
log.debug(`Dependency ${depId}@${existing.version} already satisfies ${range}`);
|
|
4963
5106
|
continue;
|
|
4964
5107
|
}
|
|
@@ -4971,9 +5114,9 @@ async function installDependencies2(projectDir, config, lock, registry, registry
|
|
|
4971
5114
|
log.step(`Dependency: ${depId}@${resolvedVersion} (required: ${range})`);
|
|
4972
5115
|
resolving.add(depId);
|
|
4973
5116
|
const resolved = resolveVersionFromManifest(manifest, depId, resolvedVersion);
|
|
4974
|
-
const installDir =
|
|
4975
|
-
if (
|
|
4976
|
-
await
|
|
5117
|
+
const installDir = join9(projectDir, config.install.modulesDir, depId);
|
|
5118
|
+
if (existsSync7(installDir)) {
|
|
5119
|
+
await rm5(installDir, { recursive: true, force: true });
|
|
4977
5120
|
}
|
|
4978
5121
|
await mkdir5(installDir, { recursive: true });
|
|
4979
5122
|
await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
|
|
@@ -5025,272 +5168,59 @@ function compareSemver(a, b) {
|
|
|
5025
5168
|
if (a.minor !== b.minor) return a.minor - b.minor;
|
|
5026
5169
|
return a.patch - b.patch;
|
|
5027
5170
|
}
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
import { tmpdir } from "os";
|
|
5034
|
-
async function runDiff(input, projectDir) {
|
|
5035
|
-
const config = await readProjectConfig(projectDir);
|
|
5036
|
-
const lock = await readLockFile(projectDir);
|
|
5037
|
-
const spec = parsePackageSpec(input.packageSpec);
|
|
5038
|
-
const name = spec.name;
|
|
5039
|
-
if (!config.packages[name]) {
|
|
5040
|
-
throw new Error(`Package "${name}" not found. Available: ${Object.keys(config.packages).join(", ")}`);
|
|
5041
|
-
}
|
|
5042
|
-
const pkg = config.packages[name];
|
|
5043
|
-
const registry = resolveRegistryForPackage(config, name);
|
|
5044
|
-
const repoDir = await ensureCloned(registry.owner, registry.repo);
|
|
5045
|
-
const manifest = await readManifestFromRepo(repoDir);
|
|
5046
|
-
let targetVersion;
|
|
5047
|
-
if (spec.version) {
|
|
5048
|
-
targetVersion = spec.version;
|
|
5049
|
-
} else {
|
|
5050
|
-
const versions = listVersionsFromManifest(manifest, name);
|
|
5051
|
-
if (versions.length === 0) {
|
|
5052
|
-
throw new Error(`No versions found for ${name} in registry manifest`);
|
|
5053
|
-
}
|
|
5054
|
-
const sorted = versions.map((v) => ({ raw: v, parts: parseSemverSimple(v) })).filter((v) => v.parts !== null).sort((a, b) => compareSemverSimple(a.parts, b.parts));
|
|
5055
|
-
targetVersion = sorted[sorted.length - 1].raw;
|
|
5056
|
-
}
|
|
5057
|
-
if (targetVersion === pkg.version) {
|
|
5058
|
-
log.info(`${name} is already at ${targetVersion}`);
|
|
5059
|
-
return;
|
|
5060
|
-
}
|
|
5061
|
-
log.step(`Comparing ${name} ${pkg.version} \u2192 ${targetVersion}`);
|
|
5062
|
-
const resolved = resolveVersionFromManifest(manifest, name, targetVersion);
|
|
5063
|
-
const tmpDir = await mkdtemp(join9(tmpdir(), "agent-pkg-diff-"));
|
|
5064
|
-
try {
|
|
5065
|
-
const targetDir = join9(tmpDir, "target");
|
|
5066
|
-
await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, targetDir);
|
|
5067
|
-
const currentDir = join9(projectDir, config.install.modulesDir, name);
|
|
5068
|
-
if (!existsSync7(currentDir)) {
|
|
5069
|
-
throw new Error(`Current package not installed at ${currentDir}. Run sync first.`);
|
|
5070
|
-
}
|
|
5071
|
-
const currentDsl = await loadYamlSafe(join9(currentDir, "agent-contracts.yaml"));
|
|
5072
|
-
const targetDsl = await loadYamlSafe(join9(targetDir, "agent-contracts.yaml"));
|
|
5073
|
-
const changes = computeDslDiff(currentDsl, targetDsl);
|
|
5074
|
-
if (input.format === "json") {
|
|
5075
|
-
console.log(JSON.stringify({
|
|
5076
|
-
package: name,
|
|
5077
|
-
fromVersion: pkg.version,
|
|
5078
|
-
toVersion: targetVersion,
|
|
5079
|
-
changes
|
|
5080
|
-
}, null, 2));
|
|
5081
|
-
} else {
|
|
5082
|
-
printTextDiff(name, pkg.version, targetVersion, changes);
|
|
5083
|
-
}
|
|
5084
|
-
const hasBreaking = changes.some((c) => c.breaking);
|
|
5085
|
-
if (hasBreaking) {
|
|
5086
|
-
process.exit(2);
|
|
5087
|
-
}
|
|
5088
|
-
} finally {
|
|
5089
|
-
await rm5(tmpDir, { recursive: true, force: true });
|
|
5090
|
-
}
|
|
5091
|
-
}
|
|
5092
|
-
function computeDslDiff(current, target) {
|
|
5093
|
-
const changes = [];
|
|
5094
|
-
if (!current || !target) return changes;
|
|
5095
|
-
const sections = ["agents", "tasks", "workflows", "guardrails", "handoff_types"];
|
|
5096
|
-
for (const section of sections) {
|
|
5097
|
-
const cur = current[section] || {};
|
|
5098
|
-
const tgt = target[section] || {};
|
|
5099
|
-
for (const key of Object.keys(tgt)) {
|
|
5100
|
-
if (!(key in cur)) {
|
|
5101
|
-
changes.push({ section, type: "added", key });
|
|
5102
|
-
} else if (JSON.stringify(cur[key]) !== JSON.stringify(tgt[key])) {
|
|
5103
|
-
changes.push({ section, type: "modified", key });
|
|
5104
|
-
}
|
|
5105
|
-
}
|
|
5106
|
-
for (const key of Object.keys(cur)) {
|
|
5107
|
-
if (!(key in tgt)) {
|
|
5108
|
-
changes.push({ section, type: "removed", key, breaking: true });
|
|
5109
|
-
}
|
|
5110
|
-
}
|
|
5111
|
-
}
|
|
5112
|
-
return changes;
|
|
5113
|
-
}
|
|
5114
|
-
function printTextDiff(name, fromVersion, toVersion, changes) {
|
|
5115
|
-
console.log(`${name} ${fromVersion} \u2192 ${toVersion}
|
|
5116
|
-
`);
|
|
5117
|
-
if (changes.length === 0) {
|
|
5118
|
-
console.log(" No semantic changes detected.");
|
|
5119
|
-
return;
|
|
5120
|
-
}
|
|
5121
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
5122
|
-
for (const c of changes) {
|
|
5123
|
-
const list = grouped.get(c.section) || [];
|
|
5124
|
-
list.push(c);
|
|
5125
|
-
grouped.set(c.section, list);
|
|
5126
|
-
}
|
|
5127
|
-
for (const [section, items] of grouped) {
|
|
5128
|
-
const label = section.charAt(0).toUpperCase() + section.slice(1);
|
|
5129
|
-
console.log(`${label}:`);
|
|
5130
|
-
for (const item of items) {
|
|
5131
|
-
const breaking = item.breaking ? " BREAKING" : "";
|
|
5132
|
-
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;
|
|
5133
5176
|
}
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
}
|
|
5140
|
-
}
|
|
5141
|
-
async function loadYamlSafe(path) {
|
|
5142
|
-
if (!existsSync7(path)) return null;
|
|
5143
|
-
const { parse } = await import("yaml");
|
|
5144
|
-
const content = await readFile5(path, "utf8");
|
|
5145
|
-
return parse(content) || {};
|
|
5146
|
-
}
|
|
5147
|
-
function parseSemverSimple(v) {
|
|
5148
|
-
const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
5149
|
-
if (!m) return null;
|
|
5150
|
-
return [+m[1], +m[2], +m[3]];
|
|
5151
|
-
}
|
|
5152
|
-
function compareSemverSimple(a, b) {
|
|
5153
|
-
if (a[0] !== b[0]) return a[0] - b[0];
|
|
5154
|
-
if (a[1] !== b[1]) return a[1] - b[1];
|
|
5155
|
-
return a[2] - b[2];
|
|
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
|
+
});
|
|
5156
5183
|
}
|
|
5157
5184
|
|
|
5158
|
-
// src/lib/commands/
|
|
5185
|
+
// src/lib/commands/check.ts
|
|
5159
5186
|
import { existsSync as existsSync8 } from "fs";
|
|
5160
|
-
import {
|
|
5187
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
5161
5188
|
import { join as join10 } from "path";
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
if (input.clean && existsSync8(buildDir)) {
|
|
5167
|
-
await rm6(buildDir, { recursive: true, force: true });
|
|
5168
|
-
log.step("Cleaned build directory");
|
|
5169
|
-
}
|
|
5170
|
-
await mkdir6(buildDir, { recursive: true });
|
|
5171
|
-
log.step("Resolving agent-contracts.yaml");
|
|
5172
|
-
const yamlPath = join10(projectDir, "agent-contracts.yaml");
|
|
5173
|
-
if (!existsSync8(yamlPath)) {
|
|
5174
|
-
throw new Error("agent-contracts.yaml not found in project root");
|
|
5175
|
-
}
|
|
5176
|
-
const { parse, stringify } = await import("yaml");
|
|
5177
|
-
const rootDoc = parse(await readFile6(yamlPath, "utf8"));
|
|
5178
|
-
const resolved = await resolveExtends(rootDoc, projectDir);
|
|
5179
|
-
if (config.vars) {
|
|
5180
|
-
resolved.vars = { ...resolved.vars || {}, ...config.vars };
|
|
5181
|
-
}
|
|
5182
|
-
const resolvedYaml = stringify(resolved, { lineWidth: 0 });
|
|
5183
|
-
const resolvedPath = join10(buildDir, "resolved.agent-contracts.yaml");
|
|
5184
|
-
await writeFile5(resolvedPath, resolvedYaml, "utf8");
|
|
5185
|
-
log.success(`Wrote ${resolvedPath}`);
|
|
5186
|
-
const resolvedHash = hashString(resolvedYaml);
|
|
5187
|
-
let validated = false;
|
|
5188
|
-
let linted = false;
|
|
5189
|
-
let generated = false;
|
|
5190
|
-
if (config.materialize?.runValidate !== false) {
|
|
5191
|
-
validated = await runExternalTool("agent-contracts", ["validate", "-f", resolvedPath], projectDir);
|
|
5192
|
-
}
|
|
5193
|
-
if (!input.noLint && config.materialize?.runLint !== false) {
|
|
5194
|
-
linted = await runExternalTool("agent-contracts", ["lint", "--strict", "-f", resolvedPath], projectDir);
|
|
5195
|
-
}
|
|
5196
|
-
if (!input.noGenerate && config.materialize?.runRuntimeGenerate !== false) {
|
|
5197
|
-
generated = await runExternalTool("agent-runtime", ["generate"], projectDir);
|
|
5198
|
-
}
|
|
5199
|
-
const buildManifest = {
|
|
5200
|
-
resolvedDsl: resolvedPath,
|
|
5201
|
-
resolvedDslHash: resolvedHash,
|
|
5202
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5203
|
-
packages: Object.keys(config.packages)
|
|
5204
|
-
};
|
|
5205
|
-
await writeFile5(join10(buildDir, "package-manifest.json"), JSON.stringify(buildManifest, null, 2) + "\n", "utf8");
|
|
5206
|
-
const result = {
|
|
5207
|
-
resolvedDslPath: resolvedPath,
|
|
5208
|
-
resolvedDslHash: resolvedHash,
|
|
5209
|
-
validated,
|
|
5210
|
-
linted,
|
|
5211
|
-
generated
|
|
5212
|
-
};
|
|
5213
|
-
log.success("Materialize completed");
|
|
5214
|
-
console.log(JSON.stringify(result, null, 2));
|
|
5215
|
-
}
|
|
5216
|
-
async function resolveExtends(doc, baseDir) {
|
|
5217
|
-
const extends_ = doc.extends;
|
|
5218
|
-
if (!extends_ || extends_.length === 0) return doc;
|
|
5219
|
-
const { parse } = await import("yaml");
|
|
5220
|
-
let merged = {};
|
|
5221
|
-
for (const ext of extends_) {
|
|
5222
|
-
const extPath = join10(baseDir, ext);
|
|
5223
|
-
if (!existsSync8(extPath)) {
|
|
5224
|
-
log.warn(`Extended file not found: ${extPath}`);
|
|
5225
|
-
continue;
|
|
5226
|
-
}
|
|
5227
|
-
const extContent = await readFile6(extPath, "utf8");
|
|
5228
|
-
const extDoc = parse(extContent);
|
|
5229
|
-
if (extDoc) {
|
|
5230
|
-
merged = deepMerge(merged, extDoc);
|
|
5231
|
-
}
|
|
5232
|
-
}
|
|
5233
|
-
const { extends: _removed, ...rest } = doc;
|
|
5234
|
-
merged = deepMerge(merged, rest);
|
|
5235
|
-
const refs = doc["$refs"];
|
|
5236
|
-
if (refs) {
|
|
5237
|
-
for (const ref of refs) {
|
|
5238
|
-
const refPath = join10(baseDir, ref);
|
|
5239
|
-
if (!existsSync8(refPath)) {
|
|
5240
|
-
log.warn(`Override file not found: ${refPath}`);
|
|
5241
|
-
continue;
|
|
5242
|
-
}
|
|
5243
|
-
const refContent = await readFile6(refPath, "utf8");
|
|
5244
|
-
const refDoc = parse(refContent);
|
|
5245
|
-
if (refDoc) {
|
|
5246
|
-
merged = deepMerge(merged, refDoc);
|
|
5247
|
-
}
|
|
5248
|
-
}
|
|
5249
|
-
delete merged["$refs"];
|
|
5250
|
-
}
|
|
5251
|
-
return merged;
|
|
5252
|
-
}
|
|
5253
|
-
function deepMerge(target, source) {
|
|
5254
|
-
const result = { ...target };
|
|
5255
|
-
for (const key of Object.keys(source)) {
|
|
5256
|
-
const tVal = result[key];
|
|
5257
|
-
const sVal = source[key];
|
|
5258
|
-
if (isPlainObject(tVal) && isPlainObject(sVal)) {
|
|
5259
|
-
result[key] = deepMerge(tVal, sVal);
|
|
5260
|
-
} else {
|
|
5261
|
-
result[key] = sVal;
|
|
5262
|
-
}
|
|
5263
|
-
}
|
|
5264
|
-
return result;
|
|
5265
|
-
}
|
|
5266
|
-
function isPlainObject(val) {
|
|
5267
|
-
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
5268
|
-
}
|
|
5269
|
-
function runExternalTool(cmd, args, cwd2) {
|
|
5189
|
+
|
|
5190
|
+
// src/lib/external-tools.ts
|
|
5191
|
+
import { execFile as execFileCb2 } from "child_process";
|
|
5192
|
+
function exec(cmd, args, cwd2) {
|
|
5270
5193
|
return new Promise((resolve2) => {
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
log.debug(stderr || err.message);
|
|
5275
|
-
resolve2(false);
|
|
5276
|
-
return;
|
|
5277
|
-
}
|
|
5278
|
-
if (stdout) log.debug(stdout);
|
|
5279
|
-
log.success(`${cmd} ${args.join(" ")} \u2014 ok`);
|
|
5280
|
-
resolve2(true);
|
|
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() ?? "" });
|
|
5281
5197
|
});
|
|
5282
5198
|
});
|
|
5283
5199
|
}
|
|
5200
|
+
async function isToolAvailable(cmd) {
|
|
5201
|
+
const { exitCode } = await exec("which", [cmd]);
|
|
5202
|
+
return exitCode === 0;
|
|
5203
|
+
}
|
|
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 };
|
|
5213
|
+
}
|
|
5284
5214
|
|
|
5285
5215
|
// src/lib/commands/check.ts
|
|
5286
|
-
import { existsSync as existsSync9 } from "fs";
|
|
5287
|
-
import { join as join11 } from "path";
|
|
5288
5216
|
async function runCheck(projectDir) {
|
|
5289
5217
|
const checks = [];
|
|
5290
5218
|
checks.push(await checkConfigSchema(projectDir));
|
|
5291
5219
|
checks.push(await checkLockSchema(projectDir));
|
|
5292
5220
|
checks.push(await checkVersionConsistency(projectDir));
|
|
5293
5221
|
checks.push(...await checkContentHashes(projectDir));
|
|
5222
|
+
checks.push(await checkResolvedDslHash(projectDir));
|
|
5223
|
+
checks.push(...await runExternalChecks(projectDir));
|
|
5294
5224
|
const allPassed = checks.every((c) => c.status !== "fail");
|
|
5295
5225
|
for (const check of checks) {
|
|
5296
5226
|
const icon = check.status === "pass" ? "\u2713" : check.status === "warn" ? "\u26A0" : "\u2717";
|
|
@@ -5368,8 +5298,8 @@ async function checkContentHashes(projectDir) {
|
|
|
5368
5298
|
try {
|
|
5369
5299
|
const lock = await readLockFile(projectDir);
|
|
5370
5300
|
for (const [name, entry] of Object.entries(lock.packages)) {
|
|
5371
|
-
const installDir =
|
|
5372
|
-
if (!
|
|
5301
|
+
const installDir = join10(projectDir, entry.installedTo);
|
|
5302
|
+
if (!existsSync8(installDir)) {
|
|
5373
5303
|
items.push({
|
|
5374
5304
|
name: `content_hash:${name}`,
|
|
5375
5305
|
status: "fail",
|
|
@@ -5393,14 +5323,62 @@ async function checkContentHashes(projectDir) {
|
|
|
5393
5323
|
}
|
|
5394
5324
|
return items;
|
|
5395
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
|
+
}
|
|
5396
5374
|
|
|
5397
5375
|
// src/lib/commands/publish.ts
|
|
5398
|
-
import { existsSync as
|
|
5399
|
-
import { cp } from "fs/promises";
|
|
5400
|
-
import { join as
|
|
5376
|
+
import { existsSync as existsSync9 } from "fs";
|
|
5377
|
+
import { cp, readFile as readFile7 } from "fs/promises";
|
|
5378
|
+
import { join as join11, resolve, basename } from "path";
|
|
5401
5379
|
async function runPublish(input, projectDir) {
|
|
5402
5380
|
const sourceDir = resolve(projectDir, input.path);
|
|
5403
|
-
if (!
|
|
5381
|
+
if (!existsSync9(sourceDir)) {
|
|
5404
5382
|
throw new Error(`Source directory not found: ${input.path}`);
|
|
5405
5383
|
}
|
|
5406
5384
|
const pkgJson = await readPackageJson(sourceDir);
|
|
@@ -5462,6 +5440,8 @@ async function runPublish(input, projectDir) {
|
|
|
5462
5440
|
console.log(JSON.stringify(result2, null, 2));
|
|
5463
5441
|
return;
|
|
5464
5442
|
}
|
|
5443
|
+
await runPrePublishValidation(sourceDir);
|
|
5444
|
+
await checkChangelog(sourceDir, version);
|
|
5465
5445
|
const workDir = await ensureWorkingCopy(owner, repo);
|
|
5466
5446
|
let registryManifest;
|
|
5467
5447
|
try {
|
|
@@ -5477,7 +5457,7 @@ async function runPublish(input, projectDir) {
|
|
|
5477
5457
|
}
|
|
5478
5458
|
const packageRoot = "packages";
|
|
5479
5459
|
const packagePath = `${packageRoot}/${packageName}`;
|
|
5480
|
-
const destDir =
|
|
5460
|
+
const destDir = join11(workDir, packagePath);
|
|
5481
5461
|
await cp(sourceDir, destDir, {
|
|
5482
5462
|
recursive: true,
|
|
5483
5463
|
filter: (src) => {
|
|
@@ -5509,16 +5489,51 @@ async function runPublish(input, projectDir) {
|
|
|
5509
5489
|
log.debug(`Manifest commit: ${manifestCommit.slice(0, 12)}`);
|
|
5510
5490
|
await pushBranch(workDir);
|
|
5511
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}`);
|
|
5512
5496
|
const result = {
|
|
5513
5497
|
package: packageName,
|
|
5514
5498
|
version,
|
|
5515
5499
|
registry: `github:${owner}/${repo}`,
|
|
5516
5500
|
commit: packageCommit,
|
|
5517
|
-
contentHash
|
|
5501
|
+
contentHash,
|
|
5502
|
+
tag: tagName
|
|
5518
5503
|
};
|
|
5519
5504
|
log.success(`Published ${packageName}@${version}`);
|
|
5520
5505
|
console.log(JSON.stringify(result, null, 2));
|
|
5521
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
|
+
}
|
|
5522
5537
|
|
|
5523
5538
|
// src/cli/index.ts
|
|
5524
5539
|
function setupGlobals(globals) {
|
|
@@ -5541,12 +5556,10 @@ var handlers = {
|
|
|
5541
5556
|
console.error("\u2717 Package specifier is required. Usage: agent-pkg add <name>@<version>");
|
|
5542
5557
|
process.exit(1);
|
|
5543
5558
|
}
|
|
5544
|
-
const o = opts;
|
|
5545
5559
|
await runAdd({
|
|
5546
5560
|
packageSpec: pkg,
|
|
5547
5561
|
registry: opts.registry,
|
|
5548
|
-
alias: opts.alias
|
|
5549
|
-
noMaterialize: o.materialize === false
|
|
5562
|
+
alias: opts.alias
|
|
5550
5563
|
}, cwd).catch(handleError);
|
|
5551
5564
|
},
|
|
5552
5565
|
sync: async (opts, globals) => {
|
|
@@ -5575,16 +5588,7 @@ var handlers = {
|
|
|
5575
5588
|
format: opts.format
|
|
5576
5589
|
}, cwd).catch(handleError);
|
|
5577
5590
|
},
|
|
5578
|
-
|
|
5579
|
-
setupGlobals(globals);
|
|
5580
|
-
const o = opts;
|
|
5581
|
-
await runMaterialize({
|
|
5582
|
-
noGenerate: o.generate === false,
|
|
5583
|
-
noLint: o.lint === false,
|
|
5584
|
-
clean: opts.clean
|
|
5585
|
-
}, cwd).catch(handleError);
|
|
5586
|
-
},
|
|
5587
|
-
check: async (globals) => {
|
|
5591
|
+
check: async (_opts, globals) => {
|
|
5588
5592
|
setupGlobals(globals);
|
|
5589
5593
|
await runCheck(cwd).catch(handleError);
|
|
5590
5594
|
},
|