mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 01:39:51 +01:00
feat(cli): add agent clear-error (#19382)
## Thinking Path - The server already exposes a permission-checked agent clear-error endpoint. - The CLI previously required operators to call that endpoint manually. - A thin CLI wrapper provides the same action without duplicating lifecycle policy. ## Linked Issues or Issue Description **Problem or motivation** The CLI exposes pause and resume but not the existing `POST /api/agents/:id/clear-error` action. **Proposed solution** Expose `paperclipai agent clear-error <agent-id>` with standard authentication and output. **Alternatives considered** Direct REST calls work but bypass normal CLI ergonomics; generic agent PATCH is not equivalent. **Roadmap alignment** This exposes an existing server capability rather than adding a new lifecycle policy. ## What Changed - Add `agent clear-error` to the CLI and usage documentation. - Test the API path, JSON output, forbidden (403) and invalid-state (409) replies without retries or extra actions. ## Verification - CLI lifecycle tests **10/10 passed** and typecheck passed. - GitHub CI: **55 passed, 3 skipped, 0 failed** on `3b8fd71739b8`; Greptile **5/5**. ## Risks - The endpoint remains subject to server authorization and agent-state checks. Clearing an error does not cure its underlying cause. ## Model Used PR history records Anthropic Claude Sonnet 5.5 and OpenAI GPT-6.1 Sol with tool-assisted review. ## Checklist - [x] Searched similar open and closed PRs; no duplicate was found. - [x] Focused tests, changed behavior and risks are documented. - [x] All required CI checks pass on the current head. - [x] Greptile review is 5/5 with no open actionable findings. - [ ] Upstream maintainer approval (not yet requested as a merge). --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
81e2c50aa9
commit
f961287949
3 files changed
+50
No files matched your search
@@ -50,6 +50,7 @@ describe("agent lifecycle commands", () => {
|
||||
await run(["agent", "update", AGENT_ID, "--payload-json", JSON.stringify({ title: "Senior Builder" })]);
|
||||
await run(["agent", "pause", AGENT_ID]);
|
||||
await run(["agent", "resume", AGENT_ID]);
|
||||
await run(["agent", "clear-error", AGENT_ID]);
|
||||
await run(["agent", "approve", AGENT_ID]);
|
||||
await run(["agent", "terminate", AGENT_ID]);
|
||||
await run(["agent", "heartbeat:invoke", AGENT_ID]);
|
||||
@@ -62,6 +63,7 @@ describe("agent lifecycle commands", () => {
|
||||
["PATCH", `http://localhost:3100/api/agents/${AGENT_ID}`],
|
||||
["POST", `http://localhost:3100/api/agents/${AGENT_ID}/pause`],
|
||||
["POST", `http://localhost:3100/api/agents/${AGENT_ID}/resume`],
|
||||
["POST", `http://localhost:3100/api/agents/${AGENT_ID}/clear-error`],
|
||||
["POST", `http://localhost:3100/api/agents/${AGENT_ID}/approve`],
|
||||
["POST", `http://localhost:3100/api/agents/${AGENT_ID}/terminate`],
|
||||
["POST", `http://localhost:3100/api/agents/${AGENT_ID}/heartbeat/invoke`],
|
||||
@@ -70,6 +72,33 @@ describe("agent lifecycle commands", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("prints the server result when clearing an error with JSON output", async () => {
|
||||
const cleared = { id: AGENT_ID, status: "idle", errorReason: null };
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse(cleared));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
await run(["agent", "clear-error", AGENT_ID, "--json"]);
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
expect(fetchMock.mock.calls[0]?.[1]).toMatchObject({ method: "POST", body: "{}" });
|
||||
expect(console.log).toHaveBeenCalledWith(JSON.stringify(cleared, null, 2));
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ status: 403, message: "Insufficient permission to clear this agent's error" },
|
||||
{ status: 409, message: "Agent is not in error status" },
|
||||
])("reports a $status clear-error refusal without attempting another lifecycle action", async ({ status, message }) => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ error: message }, { status }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
vi.spyOn(process, "exit").mockImplementation(((code?: string | number | null) => {
|
||||
throw new Error(`exit:${code ?? 0}`);
|
||||
}) as typeof process.exit);
|
||||
|
||||
await expect(run(["agent", "clear-error", AGENT_ID])).rejects.toThrow("exit:1");
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("sends automatic selection when omitted and supports explicit runner overrides", async () => {
|
||||
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse()));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
@@ -405,6 +405,22 @@ export function registerAgentCommands(program: Command): void {
|
||||
}),
|
||||
);
|
||||
|
||||
addCommonClientOptions(
|
||||
agent
|
||||
.command("clear-error")
|
||||
.description("Clear an agent's error status")
|
||||
.argument("<agentId>", "Agent ID")
|
||||
.action(async (agentId: string, opts: BaseClientOptions) => {
|
||||
try {
|
||||
const ctx = resolveCommandContext(opts);
|
||||
const cleared = await ctx.api.post<Agent>(apiPath`/api/agents/${agentId}/clear-error`, {});
|
||||
printOutput(cleared, { json: ctx.json });
|
||||
} catch (err) {
|
||||
handleCommandError(err);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
addCommonClientOptions(
|
||||
agent
|
||||
.command("delete")
|
||||
|
||||
@@ -577,6 +577,7 @@ npx paperclipai agent inbox-mine --user-id <board-user-id>
|
||||
npx paperclipai agent wake <agent-id-or-shortname> [--company-id <company-id>] [--reason "..."] [--payload '{"issueId":"..."}']
|
||||
npx paperclipai agent pause <agent-id>
|
||||
npx paperclipai agent resume <agent-id>
|
||||
npx paperclipai agent clear-error <agent-id>
|
||||
npx paperclipai agent approve <agent-id>
|
||||
npx paperclipai agent terminate <agent-id>
|
||||
npx paperclipai agent heartbeat:invoke <agent-id>
|
||||
@@ -584,6 +585,10 @@ npx paperclipai agent claude-login <agent-id>
|
||||
npx paperclipai agent local-cli <agent-id-or-shortname> --company-id <company-id>
|
||||
```
|
||||
|
||||
`agent clear-error` uses the server's existing clear-error action. The server
|
||||
checks permissions and the agent state. Use it to clear an error after addressing
|
||||
its cause; use `agent resume` to resume a paused agent.
|
||||
|
||||
Agent configuration and runtime endpoints:
|
||||
|
||||
```sh
|
||||
|
||||
Reference in new issue
Block a user