feat(cli): add harper agent — CLI client for the built-in agent (#626)#1553
feat(cli): add harper agent — CLI client for the built-in agent (#626)#1553kriszyp wants to merge 2 commits into
harper agent — CLI client for the built-in agent (#626)#1553Conversation
A thin CLI front-end over the agent operations API, so operators can talk to the built-in agent (#626) locally or on a remote instance without hand-rolling curl. This is the transport/UI role #626 anticipated for the harper-agent CLI. - bin/agentCli.ts (new): resolves the ops-API connection the same way the rest of the CLI does (local domain socket by default; remote via --target / stored `harper login` tokens / env credentials), then: * one-shot: `harper agent "build a Product table"` → prints the reply and exits; also reads a single piped prompt from stdin when not a TTY. * interactive: `harper agent` → a REPL; each line is a turn on one session, with /new, /exit, /help. Streams a transcript delta after each turn (assistant text, `▸ tool(args)` calls, `⤷` results) and, on `awaiting_approval`, prompts to approve/deny each pending tool call before resuming. --session resumes an existing session; --json prints the raw session for scripting. - bin/harper.ts + utility/hdbTerms.ts: register the `agent` subcommand and help. super_user required (same as the underlying ops). Reuses cliCredentials + httpRequest; no changes to the deploy/ops CLI path. Verified against a live instance: one-shot, piped stdin, and --json all drive agent_prompt → get_agent_session and render the tool-calling transcript. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a new harper agent CLI client (bin/agentCli.ts) that allows users to interact with the built-in Harper agent in either one-shot or interactive REPL modes, integrating it into the main CLI. The review feedback highlights several critical issues in the implementation, including redundant JSON output during polling, potential hangs in non-interactive environments when prompting for approvals, URL parsing errors when ports are already present, credential interpolation bugs, REPL hangs on Ctrl-D exit, and missing null-safety guards when rendering session messages.
|
Reviewed; no blockers found. The prior finding (hang in piped stdin when |
dawsontoth
left a comment
There was a problem hiding this comment.
Lots of AI comments to resolve. We can work through the list of features of harper-agent vs the advantages we are moving toward here to see what gaps that are.
One thing I should have made more clear: This is really not intended to replace |
- pollUntilIdle: emit raw --json session only on pause/terminal, not every poll - resolveApprovals: fail loudly instead of hanging when no TTY/piped stdin - resolveConnection: avoid double :port and undefined credential interpolation - repl: resolve pending prompt on Ctrl-D/EOF so the loop unwinds - renderDelta/resolveApprovals: guard null session messages/approvals Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
CI triage on the two red checks — neither looks caused by this PR:
The PR's only reachable runtime change is the |
Summary
Adds a
harper agentCLI subcommand — a thin client for the built-in agent (#626), so operators can chat with the agent on a local or remote instance without hand-rolling curl against the operations API. This is the transport/UI role #626 anticipated theharper-agentCLI compressing into.Usage
Interactive commands:
/new(reset session),/exit(quit),/help.How it works
resolveConnection) mirrors the core ofcliOperationswithout the deploy-specific transport: local unix domain socket by default, or a remote target from--target/HARPER_CLI_TARGET/ storedlast_target, authenticated with--username/--password(or env), or a storedharper loginoperation token (Bearer). No changes to the existing deploy/ops CLI path.agent_prompt→ pollget_agent_session→ render only the transcript items appended since the last poll — assistant text,▸ tool(args)calls, and⤷results. Onawaiting_approvalit prints each pending tool call and promptsapprove? [y/N]→approve_agent_action, then resumes.--sessionresumes;--jsondumps the raw session.Verification
Driven against a live instance:
harper agent "…") → renders▸ describe_all({})→⤷ {…}→agent › The database 'data' contains one table named 'Product'.--json→ raw session withstatus+messages.The interactive REPL and the approval prompt reuse the same turn/render/approve logic (validated one-shot); they need a TTY so they aren't exercised in the automated run above.
🤖 Generated with Claude Code