agent-package-manager 0.3.1 → 0.4.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 +14 -2
- package/cli-contract.yaml +0 -6
- package/dist/cli/index.js +142 -73
- package/dist/cli/index.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -91,11 +91,23 @@ Each package must contain an `agent-pkg.package.json` with a strict schema (no a
|
|
|
91
91
|
"id": "my-package",
|
|
92
92
|
"version": "1.0.0",
|
|
93
93
|
"description": "Optional description",
|
|
94
|
-
"entrypoint": "agent-contracts.yaml"
|
|
94
|
+
"entrypoint": "agent-contracts.yaml",
|
|
95
|
+
"dependencies": {
|
|
96
|
+
"guardrails-base": ">=0.1.0"
|
|
97
|
+
}
|
|
95
98
|
}
|
|
96
99
|
```
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
| Field | Required | Description |
|
|
102
|
+
|-------|----------|-------------|
|
|
103
|
+
| `schemaVersion` | yes | Must be `1` |
|
|
104
|
+
| `id` | yes | Package identifier |
|
|
105
|
+
| `version` | yes | Semver version |
|
|
106
|
+
| `description` | no | Human-readable description |
|
|
107
|
+
| `entrypoint` | yes | Root DSL file relative to the package |
|
|
108
|
+
| `dependencies` | no | Map of package ID → semver range |
|
|
109
|
+
|
|
110
|
+
When `agent-pkg add` installs a package with `dependencies`, all required packages are automatically resolved and installed. Dependencies are added to the root `agent-contracts.yaml` extends list before the dependent package to ensure correct merge order. Circular dependencies are detected and rejected.
|
|
99
111
|
|
|
100
112
|
## How It Works
|
|
101
113
|
|
package/cli-contract.yaml
CHANGED
|
@@ -465,7 +465,6 @@ commandSets:
|
|
|
465
465
|
- agent-pkg publish ./agent-kit-lite --registry github:myorg/agent-pkg-registry
|
|
466
466
|
- agent-pkg publish ../aidev-skeleton/agent-kit --version 1.0.0
|
|
467
467
|
- agent-pkg publish ./packages/backend-api --dry-run
|
|
468
|
-
- agent-pkg publish ./my-pkg --no-push
|
|
469
468
|
|
|
470
469
|
arguments:
|
|
471
470
|
- name: path
|
|
@@ -508,11 +507,6 @@ commandSets:
|
|
|
508
507
|
type: boolean
|
|
509
508
|
default: false
|
|
510
509
|
|
|
511
|
-
- name: no-push
|
|
512
|
-
description: Commit locally but do not push to remote.
|
|
513
|
-
schema:
|
|
514
|
-
type: boolean
|
|
515
|
-
default: false
|
|
516
510
|
|
|
517
511
|
exits:
|
|
518
512
|
"0":
|
package/dist/cli/index.js
CHANGED
|
@@ -31,7 +31,7 @@ function createProgram(handlers2, version) {
|
|
|
31
31
|
program2.command("check").description("Run full verification pipeline for CI.").action(async (opts, cmd) => {
|
|
32
32
|
await handlers2.check({}, cmd.optsWithGlobals());
|
|
33
33
|
});
|
|
34
|
-
program2.command("publish").description("Publish a package to a registry repository.").argument("<path>", "Path to the local package directory to publish.").option("--version <semver>", "Override version for this publish.").option("-r, --registry <url>", "Target registry in the format github:<owner>/<repo>. Falls back to the default registry in agent-pkg.json if not specified.").option("--name <name>", "Override package name (defaults to id in agent-pkg.package.json).").option("--dry-run", "Show what would be published without making changes.", false).
|
|
34
|
+
program2.command("publish").description("Publish a package to a registry repository.").argument("<path>", "Path to the local package directory to publish.").option("--version <semver>", "Override version for this publish.").option("-r, --registry <url>", "Target registry in the format github:<owner>/<repo>. Falls back to the default registry in agent-pkg.json if not specified.").option("--name <name>", "Override package name (defaults to id in agent-pkg.package.json).").option("--dry-run", "Show what would be published without making changes.", false).action(async (path, opts, cmd) => {
|
|
35
35
|
await handlers2.publish(path, opts, cmd.optsWithGlobals());
|
|
36
36
|
});
|
|
37
37
|
return program2;
|
|
@@ -4174,7 +4174,8 @@ var PackageManifestSchema = external_exports.strictObject({
|
|
|
4174
4174
|
id: external_exports.string().min(1),
|
|
4175
4175
|
version: external_exports.string().min(1),
|
|
4176
4176
|
description: external_exports.string().optional(),
|
|
4177
|
-
entrypoint: external_exports.string().min(1)
|
|
4177
|
+
entrypoint: external_exports.string().min(1),
|
|
4178
|
+
dependencies: external_exports.record(external_exports.string()).optional()
|
|
4178
4179
|
});
|
|
4179
4180
|
var CONFIG_FILE = "agent-pkg.json";
|
|
4180
4181
|
var LOCK_FILE = "agent-pkg.lock.json";
|
|
@@ -4272,6 +4273,7 @@ active_guardrail_policy: default
|
|
|
4272
4273
|
import { existsSync as existsSync4 } from "fs";
|
|
4273
4274
|
import { mkdir as mkdir3, rm, readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
4274
4275
|
import { join as join6 } from "path";
|
|
4276
|
+
import semver2 from "semver";
|
|
4275
4277
|
|
|
4276
4278
|
// src/lib/config.ts
|
|
4277
4279
|
import { readFile, writeFile as writeFile2 } from "fs/promises";
|
|
@@ -4443,6 +4445,7 @@ async function pushBranch(cwd2, remote = "origin", branch = "main") {
|
|
|
4443
4445
|
// src/lib/registry.ts
|
|
4444
4446
|
import { readFile as readFile2, writeFile as writeFile3 } from "fs/promises";
|
|
4445
4447
|
import { join as join4 } from "path";
|
|
4448
|
+
import semver from "semver";
|
|
4446
4449
|
function createEmptyManifest(name) {
|
|
4447
4450
|
return {
|
|
4448
4451
|
schemaVersion: 1,
|
|
@@ -4491,6 +4494,11 @@ function listVersionsFromManifest(manifest, packageName) {
|
|
|
4491
4494
|
if (!pkg) return [];
|
|
4492
4495
|
return Object.keys(pkg.versions);
|
|
4493
4496
|
}
|
|
4497
|
+
function resolveVersionRange(manifest, packageName, range) {
|
|
4498
|
+
const versions = listVersionsFromManifest(manifest, packageName);
|
|
4499
|
+
if (versions.length === 0) return null;
|
|
4500
|
+
return semver.maxSatisfying(versions, range);
|
|
4501
|
+
}
|
|
4494
4502
|
function addVersionToManifest(manifest, packageName, packagePath, version, commit, contentHash, description) {
|
|
4495
4503
|
if (!manifest.packages[packageName]) {
|
|
4496
4504
|
manifest.packages[packageName] = {
|
|
@@ -4566,45 +4574,9 @@ async function runAdd(input, projectDir) {
|
|
|
4566
4574
|
);
|
|
4567
4575
|
}
|
|
4568
4576
|
}
|
|
4569
|
-
|
|
4577
|
+
const registryName = input.registry || "default";
|
|
4570
4578
|
const repoDir = await ensureCloned(registry.owner, registry.repo);
|
|
4571
4579
|
const manifest = await readManifestFromRepo(repoDir);
|
|
4572
|
-
const resolved = resolveVersionFromManifest(manifest, spec.name, spec.version);
|
|
4573
|
-
log.step(`Resolved commit: ${resolved.commit.slice(0, 12)}`);
|
|
4574
|
-
const modulesDir = config.install.modulesDir;
|
|
4575
|
-
const installDir = join6(projectDir, modulesDir, packageName);
|
|
4576
|
-
if (existsSync4(installDir)) {
|
|
4577
|
-
await rm(installDir, { recursive: true, force: true });
|
|
4578
|
-
}
|
|
4579
|
-
await mkdir3(installDir, { recursive: true });
|
|
4580
|
-
log.step(`Extracting ${resolved.path} \u2192 ${modulesDir}/${packageName}`);
|
|
4581
|
-
await extractPackageAtCommit(repoDir, resolved.commit, resolved.path, installDir);
|
|
4582
|
-
const contentHash = await hashDirectory(installDir);
|
|
4583
|
-
log.debug(`Content hash: ${contentHash}`);
|
|
4584
|
-
if (contentHash !== resolved.contentHash) {
|
|
4585
|
-
log.warn(
|
|
4586
|
-
`Content hash mismatch: manifest=${resolved.contentHash}, extracted=${contentHash}. The registry manifest may be stale.`
|
|
4587
|
-
);
|
|
4588
|
-
}
|
|
4589
|
-
const pkgManifest = await readPackageManifest(installDir);
|
|
4590
|
-
const entrypoint = pkgManifest?.entrypoint ?? DEFAULT_ENTRYPOINT;
|
|
4591
|
-
const registryName = input.registry || "default";
|
|
4592
|
-
config.packages[packageName] = {
|
|
4593
|
-
registry: registryName,
|
|
4594
|
-
path: resolved.path,
|
|
4595
|
-
version: spec.version
|
|
4596
|
-
};
|
|
4597
|
-
if (!config.registries[registryName]) {
|
|
4598
|
-
config.registries[registryName] = {
|
|
4599
|
-
type: "github",
|
|
4600
|
-
owner: registry.owner,
|
|
4601
|
-
repo: registry.repo,
|
|
4602
|
-
packageRoot: registry.packageRoot,
|
|
4603
|
-
tagFormat: registry.tagFormat
|
|
4604
|
-
};
|
|
4605
|
-
}
|
|
4606
|
-
await writeProjectConfig(projectDir, config);
|
|
4607
|
-
log.success(`Updated config with ${packageName}@${spec.version}`);
|
|
4608
4580
|
let lock;
|
|
4609
4581
|
try {
|
|
4610
4582
|
lock = await readLockFile(projectDir);
|
|
@@ -4616,6 +4588,27 @@ async function runAdd(input, projectDir) {
|
|
|
4616
4588
|
packages: {}
|
|
4617
4589
|
};
|
|
4618
4590
|
}
|
|
4591
|
+
const ctx = {
|
|
4592
|
+
projectDir,
|
|
4593
|
+
config,
|
|
4594
|
+
lock,
|
|
4595
|
+
registry,
|
|
4596
|
+
registryName,
|
|
4597
|
+
repoDir,
|
|
4598
|
+
manifest,
|
|
4599
|
+
resolving: /* @__PURE__ */ new Set(),
|
|
4600
|
+
installOrder: []
|
|
4601
|
+
};
|
|
4602
|
+
await installPackage(ctx, packageName, spec.name, spec.version);
|
|
4603
|
+
if (!config.registries[registryName]) {
|
|
4604
|
+
config.registries[registryName] = {
|
|
4605
|
+
type: "github",
|
|
4606
|
+
owner: registry.owner,
|
|
4607
|
+
repo: registry.repo,
|
|
4608
|
+
packageRoot: registry.packageRoot,
|
|
4609
|
+
tagFormat: registry.tagFormat
|
|
4610
|
+
};
|
|
4611
|
+
}
|
|
4619
4612
|
lock.generatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4620
4613
|
lock.registries[registryName] = {
|
|
4621
4614
|
type: "github",
|
|
@@ -4623,43 +4616,126 @@ async function runAdd(input, projectDir) {
|
|
|
4623
4616
|
repo: registry.repo,
|
|
4624
4617
|
url: `https://github.com/${registry.owner}/${registry.repo}.git`
|
|
4625
4618
|
};
|
|
4626
|
-
|
|
4627
|
-
registry: registryName,
|
|
4628
|
-
path: resolved.path,
|
|
4629
|
-
version: spec.version,
|
|
4630
|
-
tag: `${spec.name}/v${spec.version}`,
|
|
4631
|
-
commit: resolved.commit,
|
|
4632
|
-
contentHash,
|
|
4633
|
-
installedTo: `${modulesDir}/${packageName}`,
|
|
4634
|
-
entrypoint: `${modulesDir}/${packageName}/${entrypoint}`
|
|
4635
|
-
};
|
|
4619
|
+
await writeProjectConfig(projectDir, config);
|
|
4636
4620
|
await writeLockFile(projectDir, lock);
|
|
4637
|
-
|
|
4638
|
-
await updateExtendsInYaml(projectDir, modulesDir, packageName, entrypoint);
|
|
4621
|
+
await reorderExtendsInYaml(ctx);
|
|
4639
4622
|
const result = {
|
|
4640
4623
|
package: packageName,
|
|
4641
4624
|
version: spec.version,
|
|
4642
|
-
commit:
|
|
4643
|
-
installedTo: `${modulesDir}/${packageName}`,
|
|
4625
|
+
commit: lock.packages[packageName]?.commit,
|
|
4626
|
+
installedTo: `${config.install.modulesDir}/${packageName}`,
|
|
4627
|
+
dependencies: ctx.installOrder.filter((p) => p !== packageName),
|
|
4644
4628
|
materialized: false
|
|
4645
4629
|
};
|
|
4646
4630
|
log.success(`Added ${packageName}@${spec.version}`);
|
|
4647
4631
|
console.log(JSON.stringify(result, null, 2));
|
|
4648
4632
|
}
|
|
4649
|
-
async function
|
|
4650
|
-
|
|
4633
|
+
async function installPackage(ctx, packageName, registryId, version) {
|
|
4634
|
+
if (ctx.resolving.has(registryId)) {
|
|
4635
|
+
const chain = [...ctx.resolving, registryId].join(" \u2192 ");
|
|
4636
|
+
throw new Error(`Circular dependency detected: ${chain}`);
|
|
4637
|
+
}
|
|
4638
|
+
ctx.resolving.add(registryId);
|
|
4639
|
+
log.step(`Resolving ${registryId}@${version} from manifest`);
|
|
4640
|
+
const resolved = resolveVersionFromManifest(ctx.manifest, registryId, version);
|
|
4641
|
+
log.step(`Resolved commit: ${resolved.commit.slice(0, 12)}`);
|
|
4642
|
+
const modulesDir = ctx.config.install.modulesDir;
|
|
4643
|
+
const installDir = join6(ctx.projectDir, modulesDir, packageName);
|
|
4644
|
+
if (existsSync4(installDir)) {
|
|
4645
|
+
await rm(installDir, { recursive: true, force: true });
|
|
4646
|
+
}
|
|
4647
|
+
await mkdir3(installDir, { recursive: true });
|
|
4648
|
+
log.step(`Extracting ${resolved.path} \u2192 ${modulesDir}/${packageName}`);
|
|
4649
|
+
await extractPackageAtCommit(ctx.repoDir, resolved.commit, resolved.path, installDir);
|
|
4650
|
+
const contentHash = await hashDirectory(installDir);
|
|
4651
|
+
log.debug(`Content hash: ${contentHash}`);
|
|
4652
|
+
if (contentHash !== resolved.contentHash) {
|
|
4653
|
+
log.warn(
|
|
4654
|
+
`Content hash mismatch: manifest=${resolved.contentHash}, extracted=${contentHash}. The registry manifest may be stale.`
|
|
4655
|
+
);
|
|
4656
|
+
}
|
|
4657
|
+
const pkgManifest = await readPackageManifest(installDir);
|
|
4658
|
+
const entrypoint = pkgManifest?.entrypoint ?? DEFAULT_ENTRYPOINT;
|
|
4659
|
+
ctx.config.packages[packageName] = {
|
|
4660
|
+
registry: ctx.registryName,
|
|
4661
|
+
path: resolved.path,
|
|
4662
|
+
version
|
|
4663
|
+
};
|
|
4664
|
+
ctx.lock.packages[packageName] = {
|
|
4665
|
+
registry: ctx.registryName,
|
|
4666
|
+
path: resolved.path,
|
|
4667
|
+
version,
|
|
4668
|
+
tag: `${registryId}/v${version}`,
|
|
4669
|
+
commit: resolved.commit,
|
|
4670
|
+
contentHash,
|
|
4671
|
+
installedTo: `${modulesDir}/${packageName}`,
|
|
4672
|
+
entrypoint: `${modulesDir}/${packageName}/${entrypoint}`
|
|
4673
|
+
};
|
|
4674
|
+
log.success(`Installed ${packageName}@${version}`);
|
|
4675
|
+
if (pkgManifest?.dependencies) {
|
|
4676
|
+
await installDependencies(ctx, pkgManifest.dependencies);
|
|
4677
|
+
}
|
|
4678
|
+
ctx.resolving.delete(registryId);
|
|
4679
|
+
ctx.installOrder.push(packageName);
|
|
4680
|
+
}
|
|
4681
|
+
async function installDependencies(ctx, dependencies) {
|
|
4682
|
+
for (const [depId, range] of Object.entries(dependencies)) {
|
|
4683
|
+
if (ctx.resolving.has(depId)) {
|
|
4684
|
+
const chain = [...ctx.resolving, depId].join(" \u2192 ");
|
|
4685
|
+
throw new Error(`Circular dependency detected: ${chain}`);
|
|
4686
|
+
}
|
|
4687
|
+
const existing = ctx.config.packages[depId];
|
|
4688
|
+
if (existing && !ctx.resolving.has(depId) && semver2.satisfies(existing.version, range)) {
|
|
4689
|
+
log.debug(`Dependency ${depId}@${existing.version} already satisfies ${range}`);
|
|
4690
|
+
if (!ctx.installOrder.includes(depId)) {
|
|
4691
|
+
ctx.installOrder.push(depId);
|
|
4692
|
+
}
|
|
4693
|
+
continue;
|
|
4694
|
+
}
|
|
4695
|
+
const resolvedVersion = resolveVersionRange(ctx.manifest, depId, range);
|
|
4696
|
+
if (!resolvedVersion) {
|
|
4697
|
+
throw new Error(
|
|
4698
|
+
`No version of "${depId}" satisfies range "${range}". Available: ${Object.keys(ctx.manifest.packages[depId]?.versions ?? {}).join(", ") || "(none)"}`
|
|
4699
|
+
);
|
|
4700
|
+
}
|
|
4701
|
+
log.step(`Dependency: ${depId}@${resolvedVersion} (required: ${range})`);
|
|
4702
|
+
await installPackage(ctx, depId, depId, resolvedVersion);
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
async function reorderExtendsInYaml(ctx) {
|
|
4706
|
+
const yamlPath = join6(ctx.projectDir, "agent-contracts.yaml");
|
|
4651
4707
|
if (!existsSync4(yamlPath)) return;
|
|
4652
|
-
const content = await readFile4(yamlPath, "utf8");
|
|
4653
|
-
const extendEntry = `./${modulesDir}/${packageName}/${entrypoint}`;
|
|
4654
|
-
if (content.includes(extendEntry)) return;
|
|
4655
4708
|
const { parse, stringify } = await import("yaml");
|
|
4709
|
+
const content = await readFile4(yamlPath, "utf8");
|
|
4656
4710
|
const doc = parse(content);
|
|
4657
4711
|
if (!doc.extends) doc.extends = [];
|
|
4658
|
-
if (Array.isArray(doc.extends)
|
|
4659
|
-
|
|
4660
|
-
|
|
4712
|
+
if (!Array.isArray(doc.extends)) return;
|
|
4713
|
+
const modulesDir = ctx.config.install.modulesDir;
|
|
4714
|
+
for (const pkgName of ctx.installOrder) {
|
|
4715
|
+
const lockEntry = ctx.lock.packages[pkgName];
|
|
4716
|
+
if (!lockEntry) continue;
|
|
4717
|
+
const entrypoint = lockEntry.entrypoint.replace(`${modulesDir}/${pkgName}/`, "");
|
|
4718
|
+
const extendEntry = `./${modulesDir}/${pkgName}/${entrypoint}`;
|
|
4719
|
+
if (!doc.extends.includes(extendEntry)) {
|
|
4720
|
+
doc.extends.push(extendEntry);
|
|
4721
|
+
log.success(`Added extends entry: ${extendEntry}`);
|
|
4722
|
+
}
|
|
4723
|
+
}
|
|
4724
|
+
const entryIndex = (entry) => {
|
|
4725
|
+
const match = entry.match(/\.\/[^/]+\/([^/]+)\//);
|
|
4726
|
+
if (!match) return -1;
|
|
4727
|
+
const name = match[1];
|
|
4728
|
+
return ctx.installOrder.indexOf(name);
|
|
4729
|
+
};
|
|
4730
|
+
doc.extends.sort((a, b) => {
|
|
4731
|
+
const ia = entryIndex(a);
|
|
4732
|
+
const ib = entryIndex(b);
|
|
4733
|
+
if (ia === -1 && ib === -1) return 0;
|
|
4734
|
+
if (ia === -1) return -1;
|
|
4735
|
+
if (ib === -1) return 1;
|
|
4736
|
+
return ia - ib;
|
|
4737
|
+
});
|
|
4661
4738
|
await writeFile4(yamlPath, stringify(doc, { lineWidth: 0 }), "utf8");
|
|
4662
|
-
log.success(`Added extends entry: ${extendEntry}`);
|
|
4663
4739
|
}
|
|
4664
4740
|
|
|
4665
4741
|
// src/lib/commands/sync.ts
|
|
@@ -5319,19 +5395,14 @@ async function runPublish(input, projectDir) {
|
|
|
5319
5395
|
`Register ${packageName}@${version} in manifest`
|
|
5320
5396
|
);
|
|
5321
5397
|
log.debug(`Manifest commit: ${manifestCommit.slice(0, 12)}`);
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
await pushBranch(workDir);
|
|
5325
|
-
pushed = true;
|
|
5326
|
-
log.success("Pushed to remote");
|
|
5327
|
-
}
|
|
5398
|
+
await pushBranch(workDir);
|
|
5399
|
+
log.success("Pushed to remote");
|
|
5328
5400
|
const result = {
|
|
5329
5401
|
package: packageName,
|
|
5330
5402
|
version,
|
|
5331
5403
|
registry: `github:${owner}/${repo}`,
|
|
5332
5404
|
commit: packageCommit,
|
|
5333
|
-
contentHash
|
|
5334
|
-
pushed
|
|
5405
|
+
contentHash
|
|
5335
5406
|
};
|
|
5336
5407
|
log.success(`Published ${packageName}@${version}`);
|
|
5337
5408
|
console.log(JSON.stringify(result, null, 2));
|
|
@@ -5411,14 +5482,12 @@ var handlers = {
|
|
|
5411
5482
|
console.error("\u2717 Package path is required. Usage: agent-pkg publish <path>");
|
|
5412
5483
|
process.exit(1);
|
|
5413
5484
|
}
|
|
5414
|
-
const o = opts;
|
|
5415
5485
|
await runPublish({
|
|
5416
5486
|
path,
|
|
5417
5487
|
version: opts.version,
|
|
5418
5488
|
registry: opts.registry,
|
|
5419
5489
|
name: opts.name,
|
|
5420
|
-
dryRun: opts.dryRun
|
|
5421
|
-
noPush: o.push === false
|
|
5490
|
+
dryRun: opts.dryRun
|
|
5422
5491
|
}, cwd).catch(handleError);
|
|
5423
5492
|
}
|
|
5424
5493
|
};
|