feat(cli): surface plugin install target host + add plugin target (#8575)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The CLI (`paperclipai plugin ...`) installs and manages plugins
against a Paperclip server resolved from `--api-base` /
`PAPERCLIP_API_URL` / the active profile / an inferred default
> - During local plugin development you can have more than one Paperclip
running (a released host plus a branch build on another port), and
nothing told you *which* instance a command actually talked to
> - So a plugin that depends on a route or response field only present
on a feature branch could be silently installed/tested against a stale
host, returning `API route not found`, and look broken when the real
problem was the test target
> - This pull request makes the install target explicit: it probes `GET
/api/health` and prints the resolved API URL + server
status/version/mode/exposure before installing, and adds a `plugin
target` command plus docs for running and verifying against a branch
service
> - The benefit is that local plugin authors can confirm they are
exercising the runtime they intend to, instead of debugging phantom
plugin bugs caused by hitting the wrong server

## Linked Issues or Issue Description

No public GitHub issue exists, so the underlying problem is described
inline following the feature-request template.

**Problem or motivation**

Local plugin development assumes a single Paperclip on
`http://127.0.0.1:3100`. When a plugin depends on server code that only
exists on a feature branch (a new scoped route, a new response field, a
new managed-resource capability), installing it into a long-lived host
still on older code makes the route/field missing there. The plugin
falls back or errors and *looks* broken, when the real cause is that it
was tested against the wrong runtime. The CLI already let you point at
any server, but it never surfaced which server you ended up on — so the
mistake was invisible.

**Proposed solution**

Make the install target explicit. Before `plugin install` runs, probe
`GET /api/health` and print the resolved API URL plus server
status/version/deploymentMode/exposure, so the developer can confirm
which Paperclip they are installing into. Add a standalone `plugin
target` command to inspect the target without installing, a
`--no-verify-target` escape hatch, and docs covering how to run a branch
service on its own port and verify a branch route end-to-end.

**Alternatives considered**

- Do nothing and rely on the existing `--api-base` / `PAPERCLIP_API_URL`
resolution — rejected because the gap was never the inability to point
at a branch server, it was the lack of feedback about which server was
actually hit.
- Fail the install when the target looks stale — rejected as too
aggressive; the probe is advisory and degrades gracefully when health
details are not exposed or the server is unreachable.

## Dedup Search

- [x] I searched the open and recently closed GitHub PRs for similar or
duplicate PRs — this is not a duplicate

## What Changed

- Add `probeTargetDiagnostics` / `formatTargetDiagnostics` helpers
(`cli/src/commands/client/plugin.ts`) that read `GET /api/health` and
report the resolved API URL plus server `status` / `version` /
`deploymentMode` / `deploymentExposure`.
- `plugin install` now prints these target diagnostics before
installing, so you can confirm which instance you are installing into.
Skippable with `--no-verify-target`.
- `plugin install --json` keeps its original flat `PluginRecord` shape
(top-level `id` / `pluginKey` / `version` / `status` are unchanged);
when the target was probed it gains an additional top-level `target`
field. Existing automation that reads the plugin fields keeps working.
- Add a standalone `paperclipai plugin target` command to inspect the
install target without installing anything.
- Update `doc/plugins/LOCAL_PLUGIN_DEVELOPMENT.md`: how the CLI resolves
its target, how to run a branch service on its own port and point the
CLI at it explicitly, an end-to-end check that the branch route is
actually served, and a troubleshooting entry for the stale-target
symptom.
- Unit tests for the diagnostics helpers (reachable + unreachable probe,
and both render paths).

## Verification

- `npx vitest run cli/src/__tests__/plugin-init.test.ts` — 10/10 pass
(covers `probeTargetDiagnostics` success/failure and
`formatTargetDiagnostics` rendering).
- CLI typecheck (`tsc --noEmit` in `cli/`) — clean.
- Manual: with a server running, `paperclipai plugin target` prints
`Target Paperclip: <url>` and the health line; `plugin install` prints
the same block before installing and `--no-verify-target` skips it.

## Risks

Low risk. The probe is read-only (`GET /api/health`) and runs before
install; if the server does not expose details it degrades to `ok (no
details exposed)`, and an unreachable target prints a remediation hint
rather than failing the command. The `--json` output keeps its original
flat shape, so existing scripts are unaffected. No server or schema
changes.

## Model Used

Claude Opus 4.7 (`claude-opus-4-7`), extended thinking + tool use, via
Claude Code.
This commit is contained in:
Devin Foley authored and GitHub committed 2026-06-25 01:07:35 -07:00
1 parent 721541c41d
commit 1951c80237
3 files changed
+262 -2

No files matched your search

+63
View File
@@ -23,6 +23,8 @@ import {
buildPluginInstallRequest,
buildPluginInitNextCommands,
buildPluginInitScaffoldOptions,
formatTargetDiagnostics,
probeTargetDiagnostics,
registerPluginCommands,
} from "../commands/client/plugin.js";
@@ -162,3 +164,64 @@ describe("plugin install", () => {
});
});
});
describe("plugin target diagnostics", () => {
it("probes /api/health and reports the resolved api base on success", async () => {
const get = vi.fn(async () => ({
status: "ok",
version: "1.2.3",
deploymentMode: "local_trusted",
deploymentExposure: "private",
}));
const diag = await probeTargetDiagnostics({ apiBase: "http://127.0.0.1:3100", get });
expect(get).toHaveBeenCalledWith("/api/health");
expect(diag).toEqual({
apiBase: "http://127.0.0.1:3100",
reachable: true,
health: {
status: "ok",
version: "1.2.3",
deploymentMode: "local_trusted",
deploymentExposure: "private",
},
});
});
it("marks the target unreachable when the health probe throws", async () => {
const get = vi.fn(async () => {
throw new Error("Could not reach the Paperclip API.\nRequest: GET ...");
});
const diag = await probeTargetDiagnostics({ apiBase: "http://other-host:9999", get });
expect(diag.apiBase).toBe("http://other-host:9999");
expect(diag.reachable).toBe(false);
expect(diag.error).toContain("Could not reach the Paperclip API.");
});
it("formats reachable diagnostics with version and mode", () => {
const rendered = formatTargetDiagnostics({
apiBase: "http://127.0.0.1:3100",
reachable: true,
health: { status: "ok", version: "9.9.9", deploymentMode: "local_trusted" },
});
expect(rendered).toContain("http://127.0.0.1:3100");
expect(rendered).toContain("version=9.9.9");
expect(rendered).toContain("mode=local_trusted");
});
it("formats unreachable diagnostics with a remediation hint", () => {
const rendered = formatTargetDiagnostics({
apiBase: "http://127.0.0.1:3100",
reachable: false,
error: "ECONNREFUSED",
});
expect(rendered).toContain("unreachable");
expect(rendered).toContain("--api-base");
expect(rendered).toContain("PAPERCLIP_API_URL");
});
});
+124 -1
View File
@@ -31,6 +31,22 @@ interface PluginRecord {
updatedAt: string;
}
/** Subset of `GET /api/health` we surface as install/target diagnostics. */
interface TargetHealth {
status?: string;
version?: string;
deploymentMode?: string;
deploymentExposure?: string;
}
/** Result of probing the Paperclip instance the CLI is about to talk to. */
interface TargetDiagnostics {
apiBase: string;
reachable: boolean;
health?: TargetHealth;
error?: string;
}
// ---------------------------------------------------------------------------
// Option types
@@ -43,6 +59,8 @@ interface PluginListOptions extends BaseClientOptions {
interface PluginInstallOptions extends BaseClientOptions {
local?: boolean;
version?: string;
/** When false, skip the pre-install target-host health probe. Defaults true. */
verifyTarget?: boolean;
}
interface PluginInstallRequest {
@@ -154,6 +172,63 @@ export function renderLocalPluginInstallHint(packagePath: string): string {
].join("\n");
}
/**
* Probe `GET /api/health` on the instance the CLI is configured to talk to so a
* developer can confirm *which* Paperclip they are about to install into. This
* exists because a local-path plugin can otherwise be silently installed into a
* stale control-plane host that does not serve the branch's routes; surfacing
* the API URL plus the server version/status catches that mismatch before the
* plugin is exercised against the wrong runtime.
*/
export async function probeTargetDiagnostics(
api: { apiBase: string; get(path: string): Promise<TargetHealth | null> },
): Promise<TargetDiagnostics> {
try {
const health = await api.get("/api/health");
return {
apiBase: api.apiBase,
reachable: true,
health: health ?? undefined,
};
} catch (err) {
return {
apiBase: api.apiBase,
reachable: false,
error: err instanceof Error ? err.message : String(err),
};
}
}
/**
* Render the target-host diagnostics as human-readable lines. Pure so it can be
* unit-tested without a live server.
*/
export function formatTargetDiagnostics(diag: TargetDiagnostics): string {
const lines = [pc.dim(`Target Paperclip: ${pc.cyan(diag.apiBase)}`)];
if (!diag.reachable) {
lines.push(pc.yellow(` health: unreachable${diag.error ? ` (${diag.error.split("\n")[0]})` : ""}`));
lines.push(
pc.dim(
` Verify the right instance is running, then pass ${pc.cyan("--api-base <url>")} or set ${pc.cyan("PAPERCLIP_API_URL")} if it lives elsewhere.`,
),
);
return lines.join("\n");
}
const health = diag.health ?? {};
const detailParts: string[] = [];
if (health.status) detailParts.push(`status=${health.status}`);
if (health.version) detailParts.push(`version=${health.version}`);
if (health.deploymentMode) detailParts.push(`mode=${health.deploymentMode}`);
if (health.deploymentExposure) detailParts.push(`exposure=${health.deploymentExposure}`);
lines.push(
pc.dim(` health: ${detailParts.length > 0 ? detailParts.join(" ") : "ok (no details exposed)"}`),
);
return lines.join("\n");
}
function formatPlugin(p: PluginRecord): string {
const statusColor =
p.status === "ready"
@@ -323,12 +398,28 @@ export function registerPluginCommands(program: Command): void {
)
.option("-l, --local", "Treat <package> as a local filesystem path", false)
.option("--version <version>", "Specific npm version to install (npm packages only)")
.option(
"--no-verify-target",
"Skip the pre-install probe that reports which Paperclip instance the plugin installs into",
)
.action(async (packageArg: string, opts: PluginInstallOptions) => {
try {
const ctx = resolveCommandContext(opts);
const installRequest = buildPluginInstallRequest(packageArg, opts);
// Make the install target explicit before sending the plugin to it. A
// local-path plugin can otherwise be silently installed into a stale
// control-plane host that lacks this branch's routes; printing the API
// URL + server version/health lets the developer catch that mismatch.
let target: TargetDiagnostics | undefined;
if (opts.verifyTarget !== false) {
target = await probeTargetDiagnostics(ctx.api);
if (!ctx.json) {
console.log(formatTargetDiagnostics(target));
}
}
if (!ctx.json) {
console.log(
pc.dim(
@@ -342,7 +433,10 @@ export function registerPluginCommands(program: Command): void {
const installedPlugin = await ctx.api.post<PluginRecord>("/api/plugins/install", installRequest);
if (ctx.json) {
printOutput(installedPlugin, { json: true });
// Preserve the original flat PluginRecord shape so existing
// automation reading top-level fields (id/pluginKey/version/status)
// keeps working; attach target diagnostics as an additive field.
printOutput({ ...installedPlugin, ...(target ? { target } : {}) }, { json: true });
return;
}
@@ -370,6 +464,35 @@ export function registerPluginCommands(program: Command): void {
}),
);
// -------------------------------------------------------------------------
// plugin target
// -------------------------------------------------------------------------
addCommonClientOptions(
plugin
.command("target")
.description(
"Show which Paperclip instance plugin commands will talk to.\n" +
" Reports the resolved API URL plus the server status/version/mode from\n" +
" GET /api/health so you can confirm you are installing into the branch\n" +
" runtime and not a stale control-plane host.",
)
.action(async (opts: BaseClientOptions) => {
try {
const ctx = resolveCommandContext(opts);
const diag = await probeTargetDiagnostics(ctx.api);
if (ctx.json) {
printOutput(diag, { json: true });
return;
}
console.log(formatTargetDiagnostics(diag));
} catch (err) {
handleCommandError(err);
}
}),
);
// -------------------------------------------------------------------------
// plugin uninstall <plugin-key-or-id>
// -------------------------------------------------------------------------