feat(paperclip-runtime): route Paperclip calls through paperclipai CLI in Local CLI mode

The Paperclip runtime card's Local CLI tab previously only derived an apiUrl
from the local config and then made HTTP calls itself, so the Test action and
the company/agent pickers ignored the user's onboarded CLI auth context.

Add CLI-backed variants for every Paperclip call that has a `paperclipai`
counterpart, and route through them when transport=cli — both from the
settings card and from the runtime adapter's prompt path.

- New plugin functions spawning `paperclipai … --json`:
  * probePaperclipViaCli, listCompaniesViaCli, listCompanyAgentsViaCli
    (settings card test + pickers)
  * createIssueViaCli, getIssueViaCli, agentsMeViaCli (runtime hot path)
- New dashboard routes: /providers/paperclip/cli-status, /cli-companies,
  /cli-agents (read-only façades over the plugin's CLI helpers)
- PaperclipRuntimeCard: branches on transport=cli to use the cli-* fetchers
- PaperclipRuntimeAdapter: stores transport on the session and routes
  createIssue/getIssue + identity derivation through CLI variants in CLI mode;
  raises a clear error when agentId is unset in CLI mode (paperclipai has no
  /agents/me equivalent)
- getIssueComments / wakeAgent / getRunEvents stay on HTTP (no matching
  paperclipai subcommands) and continue to use the apiKey discovered from
  the local paperclipai config, so CLI mode still works end-to-end
- Tests: 9 new paperclip-client tests covering each CLI variant + 5 new
  adapter tests for the Local-CLI transport branch (64/64 plugin tests pass)
- Update routes.test for the existing BUNDLED_PLUGIN_RUNTIMES fallback so
  the bundled hermes/openclaw/paperclip entries are expected alongside
  installed plugins

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-27 23:06:20 -07:00
parent 3c18f481f8
commit a3102080c4
11 changed files with 968 additions and 43 deletions

View File

@@ -4,16 +4,24 @@ import type { RunEvent } from "../paperclip-client.js";
const {
mockAgentsMe,
mockAgentsMeViaCli,
mockCreateIssue,
mockCreateIssueViaCli,
mockDiscoverPaperclipCliConfig,
mockGetIssue,
mockGetIssueViaCli,
mockGetIssueComments,
mockGetRunEvents,
mockWakeAgent,
mockResolveConfig,
} = vi.hoisted(() => ({
mockAgentsMe: vi.fn(),
mockAgentsMeViaCli: vi.fn(),
mockCreateIssue: vi.fn(),
mockCreateIssueViaCli: vi.fn(),
mockDiscoverPaperclipCliConfig: vi.fn(),
mockGetIssue: vi.fn(),
mockGetIssueViaCli: vi.fn(),
mockGetIssueComments: vi.fn(),
mockGetRunEvents: vi.fn(),
mockWakeAgent: vi.fn(),
@@ -35,8 +43,12 @@ const {
vi.mock("../paperclip-client.js", () => ({
agentsMe: mockAgentsMe,
agentsMeViaCli: mockAgentsMeViaCli,
createIssue: mockCreateIssue,
createIssueViaCli: mockCreateIssueViaCli,
discoverPaperclipCliConfig: mockDiscoverPaperclipCliConfig,
getIssue: mockGetIssue,
getIssueViaCli: mockGetIssueViaCli,
getIssueComments: mockGetIssueComments,
getRunEvents: mockGetRunEvents,
wakeAgent: mockWakeAgent,
@@ -262,6 +274,104 @@ describe("PaperclipRuntimeAdapter — comment fallback", () => {
});
});
describe("PaperclipRuntimeAdapter — Local CLI transport", () => {
beforeEach(() => {
mockDiscoverPaperclipCliConfig.mockResolvedValue({
ok: true,
apiUrl: "http://127.0.0.1:3100",
apiKey: "cli-discovered-key",
configPath: "/cfg.json",
deploymentMode: "local_trusted",
});
mockCreateIssueViaCli.mockResolvedValue({ id: "ISS-CLI", status: "todo" });
mockGetIssueViaCli.mockResolvedValue({ id: "ISS-CLI", status: "done" });
mockAgentsMeViaCli.mockResolvedValue({
agentId: "AG-cli",
agentName: "cli-bot",
role: "engineer",
companyId: "CO-cli",
companyName: "Acme",
});
});
it("createSession runs CLI discovery and stores transport on the session", async () => {
const adapter = makeAdapter({
transport: "cli",
cliBinaryPath: "/opt/bin/paperclipai",
cliConfigPath: "/cfg.json",
agentId: "AG-1",
companyId: "CO-1",
});
const { session } = await adapter.createSession({ ...baseSessionOpts });
expect(mockDiscoverPaperclipCliConfig).toHaveBeenCalledWith({
configPath: "/cfg.json",
});
expect(session.transport).toBe("cli");
expect(session.cliBinaryPath).toBe("/opt/bin/paperclipai");
expect(session.cliConfigPath).toBe("/cfg.json");
// Discovered apiKey is plumbed through to the session for HTTP-only fallbacks.
expect(session.apiKey).toBe("cli-discovered-key");
});
it("derives companyId via agentsMeViaCli when missing in CLI mode", async () => {
const adapter = makeAdapter({ transport: "cli", agentId: "AG-cli" });
const { session } = await adapter.createSession({ ...baseSessionOpts });
expect(mockAgentsMe).not.toHaveBeenCalled();
expect(mockAgentsMeViaCli).toHaveBeenCalledWith(
expect.objectContaining({ agentId: "AG-cli" }),
);
expect(session.companyId).toBe("CO-cli");
});
it("throws a clear error when agentId is missing in CLI mode", async () => {
const adapter = makeAdapter({ transport: "cli" });
await expect(adapter.createSession({ ...baseSessionOpts })).rejects.toThrow(
/agentId is required in Local CLI mode/i,
);
expect(mockAgentsMe).not.toHaveBeenCalled();
});
it("createIssue and getIssue are routed through the CLI variants on prompt", async () => {
const adapter = makeAdapter({
transport: "cli",
agentId: "AG-1",
companyId: "CO-1",
});
const { session } = await adapter.createSession({ ...baseSessionOpts });
await adapter.promptWithFallback(session, "do thing");
expect(mockCreateIssue).not.toHaveBeenCalled();
expect(mockGetIssue).not.toHaveBeenCalled();
expect(mockCreateIssueViaCli).toHaveBeenCalledWith(
expect.objectContaining({
companyId: "CO-1",
body: expect.objectContaining({
title: expect.any(String),
assigneeAgentId: "AG-1",
status: "todo",
}),
}),
);
expect(mockGetIssueViaCli).toHaveBeenCalledWith(
expect.objectContaining({ issueId: "ISS-CLI" }),
);
});
it("aborts createSession when CLI discovery fails", async () => {
mockDiscoverPaperclipCliConfig.mockResolvedValueOnce({
ok: false,
reason: "config not found",
});
const adapter = makeAdapter({
transport: "cli",
agentId: "AG-1",
companyId: "CO-1",
});
await expect(adapter.createSession({ ...baseSessionOpts })).rejects.toThrow(
/Paperclip CLI mode failed.*config not found/,
);
});
});
describe("PaperclipRuntimeAdapter — describeModel/dispose", () => {
it("describeModel returns paperclip/<agentId>", async () => {
const adapter = makeAdapter({ agentId: "AG-XYZ", companyId: "CO-1" });