@app-vitals/agent-runtime 1.54.0 → 1.54.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/gh-helpers.ts +21 -0
- package/gh-helpers.unit.test.ts +44 -0
- package/package.json +3 -3
- package/setup.ts +27 -7
- package/setup.unit.test.ts +146 -0
package/gh-helpers.ts
CHANGED
|
@@ -29,6 +29,27 @@ export function ownerOfRepo(repo: string): string {
|
|
|
29
29
|
return repo.slice(0, idx);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* The `owner/repo` slug of a GitHub marketplace source, or null for any other
|
|
34
|
+
* host or unparseable source. Accepts `owner/repo` and
|
|
35
|
+
* `https://github.com/owner/repo` (optional `.git` / trailing slash).
|
|
36
|
+
*/
|
|
37
|
+
export function githubRepoSlugOfSource(source: string): string | null {
|
|
38
|
+
const slug = source
|
|
39
|
+
.trim()
|
|
40
|
+
.replace(/^https:\/\/github\.com\//i, "")
|
|
41
|
+
.replace(/\/+$/, "")
|
|
42
|
+
.replace(/\.git$/i, "");
|
|
43
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(slug) || slug.startsWith(".")) return null;
|
|
44
|
+
return slug;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The GitHub owner of a marketplace source, or null (see githubRepoSlugOfSource). */
|
|
48
|
+
export function githubOwnerOfSource(source: string): string | null {
|
|
49
|
+
const slug = githubRepoSlugOfSource(source);
|
|
50
|
+
return slug === null ? null : ownerOfRepo(slug);
|
|
51
|
+
}
|
|
52
|
+
|
|
32
53
|
/**
|
|
33
54
|
* Run a gh CLI command and return the parsed JSON output.
|
|
34
55
|
* Throws on non-zero exit.
|
package/gh-helpers.unit.test.ts
CHANGED
|
@@ -20,6 +20,8 @@ import {
|
|
|
20
20
|
ghGraphql,
|
|
21
21
|
ghJson,
|
|
22
22
|
ghRun,
|
|
23
|
+
githubOwnerOfSource,
|
|
24
|
+
githubRepoSlugOfSource,
|
|
23
25
|
ownerOfRepo,
|
|
24
26
|
} from "./gh-helpers.ts";
|
|
25
27
|
|
|
@@ -251,3 +253,45 @@ describe("ownerOfRepo", () => {
|
|
|
251
253
|
expect(() => ownerOfRepo("widgets")).toThrow("Cannot derive GitHub owner");
|
|
252
254
|
});
|
|
253
255
|
});
|
|
256
|
+
|
|
257
|
+
describe("githubOwnerOfSource", () => {
|
|
258
|
+
test("owner/repo shorthand", () => {
|
|
259
|
+
expect(githubOwnerOfSource("example-org/private-plugins")).toBe(
|
|
260
|
+
"example-org",
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("github https URLs, with or without .git or trailing slash", () => {
|
|
265
|
+
for (const s of [
|
|
266
|
+
"https://github.com/example-org/private-plugins",
|
|
267
|
+
"https://github.com/example-org/private-plugins.git",
|
|
268
|
+
"https://github.com/example-org/private-plugins/",
|
|
269
|
+
"https://GitHub.com/example-org/private-plugins.git",
|
|
270
|
+
]) {
|
|
271
|
+
expect(githubOwnerOfSource(s)).toBe("example-org");
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("null for other hosts and unparseable sources", () => {
|
|
276
|
+
for (const s of [
|
|
277
|
+
"https://gitlab.com/example-org/private-plugins.git",
|
|
278
|
+
"git@github.com:example-org/private-plugins.git",
|
|
279
|
+
"https://github.com.evil.test/example-org/private-plugins",
|
|
280
|
+
"plugins",
|
|
281
|
+
"",
|
|
282
|
+
"./local/path",
|
|
283
|
+
"/abs/path/to/repo",
|
|
284
|
+
]) {
|
|
285
|
+
expect(githubOwnerOfSource(s)).toBeNull();
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("githubRepoSlugOfSource", () => {
|
|
291
|
+
test("normalises to owner/repo preserving case", () => {
|
|
292
|
+
expect(
|
|
293
|
+
githubRepoSlugOfSource("https://github.com/Example-Org/Plugins.git"),
|
|
294
|
+
).toBe("Example-Org/Plugins");
|
|
295
|
+
expect(githubRepoSlugOfSource("https://example.test/a/b")).toBeNull();
|
|
296
|
+
});
|
|
297
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-runtime",
|
|
3
|
-
"version": "1.54.
|
|
3
|
+
"version": "1.54.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"./workspace-paths": "./workspace-paths.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@app-vitals/agent-admin": "1.54.
|
|
44
|
-
"@app-vitals/agent-lib": "1.54.
|
|
43
|
+
"@app-vitals/agent-admin": "1.54.1",
|
|
44
|
+
"@app-vitals/agent-lib": "1.54.1",
|
|
45
45
|
"@octokit/auth-app": "^8.2.0",
|
|
46
46
|
"@sentry/bun": "^10.63.0",
|
|
47
47
|
"@slack/bolt": "^5.0.0",
|
package/setup.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
resolveSpecialtiesDir,
|
|
28
28
|
} from "@app-vitals/agent-lib/default-specialty";
|
|
29
29
|
import { SPECIALIST_TYPE } from "@app-vitals/agent-lib/specialist-type";
|
|
30
|
+
import { githubOwnerOfSource, githubRepoSlugOfSource } from "./gh-helpers.ts";
|
|
30
31
|
|
|
31
32
|
// ---------------------------------------------------------------------------
|
|
32
33
|
// Template loading
|
|
@@ -333,19 +334,19 @@ export function discoverBakedMarketplaces(conventionRoot: string): string[] {
|
|
|
333
334
|
type ExecFn = (
|
|
334
335
|
cmd: string,
|
|
335
336
|
args: string[],
|
|
336
|
-
opts: { cwd: string },
|
|
337
|
+
opts: { cwd: string; env?: Record<string, string | undefined> },
|
|
337
338
|
) => Promise<{ stdout: string; exitCode: number }>;
|
|
338
339
|
|
|
339
340
|
async function defaultExec(
|
|
340
341
|
cmd: string,
|
|
341
342
|
args: string[],
|
|
342
|
-
opts: { cwd: string },
|
|
343
|
+
opts: { cwd: string; env?: Record<string, string | undefined> },
|
|
343
344
|
): Promise<{ stdout: string; exitCode: number }> {
|
|
344
345
|
// env: process.env is required — Bun.spawn otherwise snapshots env at Bun
|
|
345
346
|
// startup and misses runtime mutations (MISE_CACHE_DIR, etc.).
|
|
346
347
|
const proc = Bun.spawn([cmd, ...args], {
|
|
347
348
|
cwd: opts.cwd,
|
|
348
|
-
env: process.env,
|
|
349
|
+
env: opts.env ?? process.env,
|
|
349
350
|
stdout: "pipe",
|
|
350
351
|
stderr: "pipe",
|
|
351
352
|
});
|
|
@@ -469,18 +470,25 @@ function registeredMatchesRow(
|
|
|
469
470
|
);
|
|
470
471
|
}
|
|
471
472
|
|
|
472
|
-
/**
|
|
473
|
+
/**
|
|
474
|
+
* Runs `claude plugin marketplace <args>`; a non-zero exit warns, never throws.
|
|
475
|
+
* `opts.env` overrides the spawn env; `opts.failureHint` is appended to the
|
|
476
|
+
* warning, so a failed command still logs exactly one line.
|
|
477
|
+
*/
|
|
473
478
|
async function runMarketplaceCommand(
|
|
474
479
|
execFn: ExecFn,
|
|
475
480
|
cwd: string,
|
|
476
481
|
args: string[],
|
|
482
|
+
opts: { env?: Record<string, string | undefined>; failureHint?: string } = {},
|
|
477
483
|
): Promise<boolean> {
|
|
478
484
|
const result = await execFn("claude", ["plugin", "marketplace", ...args], {
|
|
479
485
|
cwd,
|
|
486
|
+
...(opts.env ? { env: opts.env } : {}),
|
|
480
487
|
});
|
|
481
488
|
if (result.exitCode !== 0) {
|
|
489
|
+
const hint = opts.failureHint ? ` — ${opts.failureHint}` : "";
|
|
482
490
|
console.warn(
|
|
483
|
-
`[agent] claude plugin marketplace ${args.join(" ")} exited ${result.exitCode}: ${result.stdout}`,
|
|
491
|
+
`[agent] claude plugin marketplace ${args.join(" ")} exited ${result.exitCode}: ${result.stdout}${hint}`,
|
|
484
492
|
);
|
|
485
493
|
}
|
|
486
494
|
return result.exitCode === 0;
|
|
@@ -529,11 +537,23 @@ async function reconcileRemoteMarketplace(
|
|
|
529
537
|
}
|
|
530
538
|
}
|
|
531
539
|
|
|
540
|
+
// Under GitHub App auth the git credential helper only answers when
|
|
541
|
+
// SHIPWRIGHT_GH_OWNER is set, so hand it the owner of a GitHub source.
|
|
542
|
+
const slug = githubRepoSlugOfSource(row.source);
|
|
543
|
+
const owner = githubOwnerOfSource(row.source);
|
|
544
|
+
const gh =
|
|
545
|
+
owner !== null
|
|
546
|
+
? {
|
|
547
|
+
env: { ...process.env, SHIPWRIGHT_GH_OWNER: owner },
|
|
548
|
+
failureHint: `remote marketplace ${row.name} (${slug}) could not be cloned or updated: install the GitHub App on ${owner} or add a repo from ${owner} to the agent's repo scope; under PAT auth, check the token can read ${slug}`,
|
|
549
|
+
}
|
|
550
|
+
: {};
|
|
551
|
+
|
|
532
552
|
if (!registered) {
|
|
533
553
|
const spec = row.ref ? `${row.source}#${row.ref}` : row.source;
|
|
534
|
-
await runMarketplaceCommand(execFn, cwd, ["add", spec]);
|
|
554
|
+
await runMarketplaceCommand(execFn, cwd, ["add", spec], gh);
|
|
535
555
|
}
|
|
536
|
-
await runMarketplaceCommand(execFn, cwd, ["update", row.name]);
|
|
556
|
+
await runMarketplaceCommand(execFn, cwd, ["update", row.name], gh);
|
|
537
557
|
|
|
538
558
|
// The CLI registers a marketplace under its manifest name, so a mismatch
|
|
539
559
|
// leaves the registry without an entry for the row's name.
|
package/setup.unit.test.ts
CHANGED
|
@@ -453,3 +453,149 @@ describe("installPlugins — ledger reconciliation (PUI-1.1)", () => {
|
|
|
453
453
|
expect(existsSync(ledgerPath())).toBe(false);
|
|
454
454
|
});
|
|
455
455
|
});
|
|
456
|
+
|
|
457
|
+
describe("installPlugins — remote marketplace owner hint (TMK-1.1)", () => {
|
|
458
|
+
let dir: string;
|
|
459
|
+
let manifest: string;
|
|
460
|
+
beforeEach(() => {
|
|
461
|
+
dir = mkdtempSync(join(tmpdir(), "owner-hint-"));
|
|
462
|
+
manifest = join(dir, "installed_plugins.json");
|
|
463
|
+
});
|
|
464
|
+
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
465
|
+
|
|
466
|
+
type Call = {
|
|
467
|
+
args: string[];
|
|
468
|
+
env: Record<string, string | undefined> | undefined;
|
|
469
|
+
};
|
|
470
|
+
const recordEnv = (failOn: (args: string[]) => boolean = () => false) => {
|
|
471
|
+
const calls: Call[] = [];
|
|
472
|
+
const exec = async (
|
|
473
|
+
_c: string,
|
|
474
|
+
args: string[],
|
|
475
|
+
opts: { cwd: string; env?: Record<string, string | undefined> },
|
|
476
|
+
) => {
|
|
477
|
+
calls.push({ args, env: opts.env });
|
|
478
|
+
return failOn(args)
|
|
479
|
+
? { stdout: "fatal: auth", exitCode: 1 }
|
|
480
|
+
: { stdout: "", exitCode: 0 };
|
|
481
|
+
};
|
|
482
|
+
return { calls, exec };
|
|
483
|
+
};
|
|
484
|
+
const run = (
|
|
485
|
+
exec: ReturnType<typeof recordEnv>["exec"],
|
|
486
|
+
marketplaces: Array<{ name: string; source: string; ref: string | null }>,
|
|
487
|
+
extra: string[] = [],
|
|
488
|
+
) =>
|
|
489
|
+
installPlugins(
|
|
490
|
+
exec,
|
|
491
|
+
"/tmp/cwd",
|
|
492
|
+
[],
|
|
493
|
+
"/tmp/no-such-repo-root",
|
|
494
|
+
manifest,
|
|
495
|
+
extra,
|
|
496
|
+
"/tmp/nonexistent-baked-root",
|
|
497
|
+
{},
|
|
498
|
+
marketplaces,
|
|
499
|
+
);
|
|
500
|
+
const sub = (calls: Call[], verb: string) =>
|
|
501
|
+
calls.filter((c) => c.args[2] === verb);
|
|
502
|
+
|
|
503
|
+
it("passes SHIPWRIGHT_GH_OWNER for add and update of an owner/repo source", async () => {
|
|
504
|
+
const { calls, exec } = recordEnv();
|
|
505
|
+
await run(exec, [
|
|
506
|
+
{ name: "priv", source: "example-org/private-plugins", ref: null },
|
|
507
|
+
]);
|
|
508
|
+
const add = sub(calls, "add");
|
|
509
|
+
const update = sub(calls, "update");
|
|
510
|
+
expect(add).toHaveLength(1);
|
|
511
|
+
expect(update).toHaveLength(1);
|
|
512
|
+
expect(add[0]?.env?.SHIPWRIGHT_GH_OWNER).toBe("example-org");
|
|
513
|
+
expect(update[0]?.env?.SHIPWRIGHT_GH_OWNER).toBe("example-org");
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it("derives the owner from a github https .git URL", async () => {
|
|
517
|
+
const { calls, exec } = recordEnv();
|
|
518
|
+
await run(exec, [
|
|
519
|
+
{
|
|
520
|
+
name: "priv",
|
|
521
|
+
source: "https://github.com/example-org/private-plugins.git",
|
|
522
|
+
ref: null,
|
|
523
|
+
},
|
|
524
|
+
]);
|
|
525
|
+
expect(sub(calls, "add")[0]?.env?.SHIPWRIGHT_GH_OWNER).toBe("example-org");
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it("passes no env override for a non-GitHub source", async () => {
|
|
529
|
+
const { calls, exec } = recordEnv();
|
|
530
|
+
await run(exec, [
|
|
531
|
+
{ name: "x", source: "https://gitlab.example.test/a/b.git", ref: null },
|
|
532
|
+
]);
|
|
533
|
+
expect(sub(calls, "add")[0]?.env).toBeUndefined();
|
|
534
|
+
expect(sub(calls, "update")[0]?.env).toBeUndefined();
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
it("passes no env override for remove or baked adds", async () => {
|
|
538
|
+
// Registered under a different source, so reconcile removes then re-adds.
|
|
539
|
+
const registry = join(dir, "known_marketplaces.json");
|
|
540
|
+
mkdirSync(join(dir, "mk", ".claude-plugin"), { recursive: true });
|
|
541
|
+
writeFileSync(join(dir, "mk", ".claude-plugin", "marketplace.json"), "{}");
|
|
542
|
+
writeFileSync(
|
|
543
|
+
registry,
|
|
544
|
+
JSON.stringify({
|
|
545
|
+
priv: {
|
|
546
|
+
source: { source: "github", repo: "example-org/other" },
|
|
547
|
+
installLocation: join(dir, "mk"),
|
|
548
|
+
},
|
|
549
|
+
}),
|
|
550
|
+
);
|
|
551
|
+
const { calls, exec } = recordEnv();
|
|
552
|
+
await run(
|
|
553
|
+
exec,
|
|
554
|
+
[{ name: "priv", source: "example-org/private-plugins", ref: null }],
|
|
555
|
+
["/opt/shipwright/marketplaces/baked"],
|
|
556
|
+
);
|
|
557
|
+
const bakedAdd = calls.find(
|
|
558
|
+
(c) => c.args[2] === "add" && c.args[3]?.startsWith("/opt/"),
|
|
559
|
+
);
|
|
560
|
+
expect(bakedAdd).toBeDefined();
|
|
561
|
+
expect(bakedAdd?.env).toBeUndefined();
|
|
562
|
+
const removes = sub(calls, "remove");
|
|
563
|
+
expect(removes.length).toBeGreaterThan(0);
|
|
564
|
+
for (const c of removes) expect(c.env).toBeUndefined();
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
for (const verb of ["add", "update"]) {
|
|
568
|
+
it(`logs exactly one remediation warning when ${verb} fails, and carries on`, async () => {
|
|
569
|
+
const { calls, exec } = recordEnv(
|
|
570
|
+
(args) =>
|
|
571
|
+
args[2] === verb &&
|
|
572
|
+
args[3] !== "second" &&
|
|
573
|
+
args[3] !== "example-org/second",
|
|
574
|
+
);
|
|
575
|
+
const warns: string[] = [];
|
|
576
|
+
const orig = console.warn;
|
|
577
|
+
console.warn = (...a: unknown[]) => {
|
|
578
|
+
warns.push(a.join(" "));
|
|
579
|
+
};
|
|
580
|
+
try {
|
|
581
|
+
await run(exec, [
|
|
582
|
+
{ name: "priv", source: "example-org/private-plugins", ref: null },
|
|
583
|
+
{ name: "second", source: "example-org/second", ref: null },
|
|
584
|
+
]);
|
|
585
|
+
} finally {
|
|
586
|
+
console.warn = orig;
|
|
587
|
+
}
|
|
588
|
+
const failing = warns.filter((w) => w.includes("priv"));
|
|
589
|
+
expect(failing).toHaveLength(1);
|
|
590
|
+
expect(failing[0]).toContain("priv");
|
|
591
|
+
expect(failing[0]).toContain("example-org/private-plugins");
|
|
592
|
+
expect(failing[0]).toContain("GitHub App");
|
|
593
|
+
expect(failing[0]).toContain("PAT");
|
|
594
|
+
expect(
|
|
595
|
+
calls.some(
|
|
596
|
+
(c) => c.args[2] === "add" && c.args[3] === "example-org/second",
|
|
597
|
+
),
|
|
598
|
+
).toBe(true);
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
});
|