Skip to content

Let agents hand drafts of copy to the human to edit - #333

Open
frenchie4111 wants to merge 14 commits into
mainfrom
human-editable-copy-drafts
Open

frenchie4111 wants to merge 14 commits into
mainfrom
human-editable-copy-drafts

Conversation

@frenchie4111

@frenchie4111 frenchie4111 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds an edit_copy tool to the ness-control MCP server. The agent sends a draft of human-facing copy (UI strings, release notes, a post…) plus an optional title and context. Ness shows it to the user in an editor, and the tool call blocks until they submit or dismiss it. The agent gets back the user's final text with instructions to use it verbatim. A dismissal comes back as an error, so the agent won't ship the draft. Either way it gets any note the user added.

  • Opt-in: the tool is off by default and turned on in Settings → Experimental → Copy editing, gated the same way as send_message. When it's off, the bridge leaves it out of tools/list and /copy-drafts returns a 403.
  • Chat tabs: the editor renders inline in the transcript under the edit_copy tool call, styled like an AskUserQuestion card. The permission bridge always allows edit_copy, because the editor already is the prompt and approving first would ask twice.
  • Terminal tabs: the editor is docked over the bottom of the tab and can be collapsed to a thin bar.
  • Status: both tab types show the needs-approval dot while a draft is waiting ("Edit copy: <title>").
  • Withdrawal: if the agent stops waiting (bridge timeout, notifications/cancelled on interrupt, process exit), the HTTP connection drops and the card is withdrawn.

How it's built

  • New copyDrafts slice holds the pending drafts, so every client renders them.
  • CopyDraftBroker (main) holds the POST /copy-drafts control-server response open until the user answers through the copyDrafts:resolve IPC.
  • resources/mcp-bridge.js adds the tool with a 30-minute timeout, matching Claude's MCP idle timeout. It also aborts in-flight calls on notifications/cancelled.
  • JsonClaudeStatusDeriver handles Chat-tab status. For Terminal tabs the broker sets the status itself, and hooks.ts won't let a late PreToolUse hook reset it to processing.

Test plan

  • npm run typecheck, npx electron-vite build
  • npx vitest run: new tests for the slice, broker, /copy-drafts route, bridge tool (edited / unchanged / dismissed / cancelled), approval-bridge auto-allow and status deriver. In the full run, the unrelated worktree-watcher.integration.test.ts flaked once; it passes on its own.
  • Manual: in dev, ask an agent to use edit_copy in a Chat tab and in a Terminal tab; edit, submit, dismiss, interrupt mid-wait.

🤖 Generated with Claude Code

frenchie4111 and others added 14 commits October 29, 2026 14:21
New ness-control MCP tool `edit_copy`: the agent sends a draft (plus an
optional title and context), Ness docks an editor over the bottom of the
calling tab, and the call blocks until the human submits or dismisses.
The agent gets back the human's final text to use verbatim, or an error
on dismissal, plus any note they added.

- copyDrafts slice holds pending drafts so every client renders them
- CopyDraftBroker parks the control server's HTTP response until answered;
  a dropped connection (bridge timeout, notifications/cancelled, process
  exit) withdraws the card
- Works in Chat and Terminal tabs; both get a needs-approval dot
- The permission bridge always allows edit_copy so Chat tabs don't prompt
  twice for the same decision

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chat tabs now render the editor under the edit_copy tool call instead of
docked over the composer. Terminal tabs keep the docked overlay since an
xterm has no transcript to put it in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same gate as send_message: off by default, the bridge hides the tool from
tools/list when it's off, and /copy-drafts refuses with a 403 pointing at
the setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rafts

# Conflicts:
#	CLAUDE.md
#	resources/mcp-bridge.js
#	src/main/build-initial-state.ts
#	src/main/control-server.test.ts
#	src/main/control-server.ts
#	src/main/persistence.ts
#	src/renderer/build-backend.ts
#	src/renderer/components/JsonModeChat.tsx
#	src/renderer/components/Settings.tsx
#	src/renderer/store.ts
#	src/renderer/types.ts
#	src/shared/state/index.ts
#	src/shared/state/settings.test.ts
#	src/shared/state/settings.ts
The bridge replies to the cancelled call before the server side sees the
socket close, so asserting immediately raced on slower CI runners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-ups on #333:

- Keep in-progress text per draft id outside the editor, so a mobile tab
  switch or the Chat card moving to its tool call no longer resets it.
- A draft the agent stops waiting on moves to copyDrafts.withdrawn instead
  of vanishing; the card says it wasn't sent and offers Copy text / Close.
- Claude Code aborts a silent stdio tool call after 30 min but resets that
  on progress notifications (hard cap ~27.8 h), so the bridge now sends a
  progress heartbeat while waiting and allows 24 h itself.
- A withdrawn Terminal tab goes to waiting, not processing: Esc in the TUI
  ends the turn with no later hook event to fix the dot.
- Anchor the Chat card only to an edit_copy call that has no result yet.
- Don't send a response for a call the client cancelled (per MCP).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A draft withdrawn because its tab closed is dropped on the spot, and the
  broker clears any withdrawn draft whose tab disappears on a pane change,
  so they no longer pile up in state and snapshots until restart.
- A withdrawn draft with no edits closes itself instead of leaving a
  "not sent" notice the user has to dismiss.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The renderer used to auto-clear an unedited withdrawn draft, but that
decision was per client while the clear was global: a desktop renderer
with no local edits would wipe a notice whose text was rewritten on a
phone. Clients now report their first edit with copyDrafts:markEdited,
and the broker only keeps a withdrawal as a "not sent" notice when some
client edited it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rafts

# Conflicts:
#	resources/mcp-bridge.js
#	src/main/build-initial-state.ts
#	src/main/control-server.test.ts
#	src/main/control-server.ts
#	src/main/persistence.ts
#	src/renderer/components/JsonModeChat.tsx
#	src/renderer/components/Settings.tsx
#	src/renderer/types.ts
#	src/shared/state/settings.test.ts
#	src/shared/state/settings.ts
…rafts

# Conflicts:
#	resources/mcp-bridge.test.js
#	src/main/control-server.ts
Main's #418 added shared/ness-tool-policy.ts as the one place that decides
which ness-control tools skip approval. edit_copy now lives in its allow
list instead of a special case in ApprovalBridge, which also puts it in
Terminal tabs' --allowedTools so they stop prompting for it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rafts

# Conflicts:
#	src/main/build-initial-state.ts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant