Skip to content

Autonomous AI sales agent powered by Claude Code or Codex. Finds prospects, writes cold emails, sends campaigns, handles replies, books meetings. No API keys needed — runs on your Claude or Codex subscriptions.

Keep the desk on the draft being edited; a reply's stored subject is kept exactly

Ethanac0213590de8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49b9acf..30e4acd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,8 +40,11 @@ minor versions can still change behaviour.
tech / agency / hiring / ads / booking signals, and the Writer's notes, so
every claim can be checked against what Harvey actually found. **Edit** (or
`E`) turns subject and body into fields; Save rewrites the draft only while
- it is still `pending_review` and never approves it.
- `POST /api/outbox/{id}/edit` backs it.
+ it is still `pending_review` and never approves it. An edit the sender
+ would block (merge tags, HTML, banned phrases) is refused on save with the
+ reason; a reply keeps its subject so it stays in the thread; every edit is
+ logged with what it replaced. While editing, the shortcuts and Approve all
+ can't act on the unedited draft. `POST /api/outbox/{id}/edit` backs it.
- **Microsoft 365 mail provider.** Set `channels.email.provider: microsoft` to
send and read through a Microsoft 365 / Outlook mailbox via Microsoft Graph,
diff --git a/harvey/dashboard.py b/harvey/dashboard.py
index c8dfe6c..7612aac 100644
--- a/harvey/dashboard.py
+++ b/harvey/dashboard.py
@@ -895,32 +895,35 @@ async def outbox_edit(item_id: str, request: Request):
body = {}
subject = str(body.get("subject") or "").strip()
text = str(body.get("body") or "").strip()
- if not subject or not text:
- return JSONResponse({"success": False, "message": "Subject and body are both required."},
- status_code=400)
- # The sender re-checks every email before it goes out; an edit it would
- # block is refused now, while the reviewer can still fix it, instead of
- # failing quietly at send time. Content rules only: the recipient isn't
- # something an edit can change.
- from harvey.gate import pre_send_check
- gate = pre_send_check("[email protected]", subject, text)
- if not gate:
- return JSONResponse({"success": False,
- "message": "The sender would have blocked this: "
- + "; ".join(gate.reasons)},
- status_code=400)
try:
state = _state()
await state.init_db()
item = await state.get_outbox_item(item_id)
- if item and item.get("kind") == "reply" and subject != (item.get("subject") or "").strip():
+ if not item or item.get("status") != "pending_review":
+ return JSONResponse({"success": False,
+ "message": "Only drafts awaiting review can be edited."},
+ status_code=409)
+ if item.get("kind") == "reply":
# Gmail threads a reply by its subject: a new one would land as a
- # fresh, unthreaded email to someone who wrote in.
+ # fresh, unthreaded email to someone who wrote in. Only the body
+ # of a reply is editable; its stored subject is kept exactly.
+ subject = item.get("subject") or ""
+ if not subject.strip() or not text:
+ return JSONResponse({"success": False,
+ "message": "Subject and body are both required."},
+ status_code=400)
+ # The sender re-checks every email before it goes out; an edit it
+ # would block is refused now, while the reviewer can still fix it,
+ # instead of failing quietly at send time. Content rules only: the
+ # recipient isn't something an edit can change.
+ from harvey.gate import pre_send_check
+ gate = pre_send_check("[email protected]", subject, text)
+ if not gate:
return JSONResponse({"success": False,
- "message": "A reply keeps its subject so it stays in the "
- "thread. Edit the body only."},
+ "message": "The sender would have blocked this: "
+ + "; ".join(gate.reasons)},
status_code=400)
- if not item or not await state.edit_outbox_draft(item_id, subject, text):
+ if not await state.edit_outbox_draft(item_id, subject, text):
return JSONResponse({"success": False,
"message": "Only drafts awaiting review can be edited."},
status_code=409)
diff --git a/harvey/web/app.js b/harvey/web/app.js
index 5665754..92420b9 100644
--- a/harvey/web/app.js
+++ b/harvey/web/app.js
@@ -1193,7 +1193,10 @@ async function loadOutbox() {
const pending = data.pending || [];
_desk.items = pending;
- if (_desk.editing && !pending.some(p => p.id === _desk.editing)) {
+ // Keep the desk on the draft being edited even if the list shifted.
+ const editingAt = _desk.editing ? pending.findIndex(p => p.id === _desk.editing) : -1;
+ if (editingAt >= 0) _desk.i = editingAt;
+ else if (_desk.editing) {
_desk.editing = null;
_desk.unsaved = null;
}
diff --git a/tests/test_outbox_review.py b/tests/test_outbox_review.py
index ebed84c..93c9ffc 100644
--- a/tests/test_outbox_review.py
+++ b/tests/test_outbox_review.py
@@ -127,12 +127,26 @@ def test_a_reply_keeps_its_subject_so_it_stays_in_the_thread(client):
state, item_id = asyncio.run(_seed(client.db_path, kind="reply"))
r = client.post(f"/api/outbox/{item_id}/edit",
json={"subject": "something new", "body": "Thanks, Tuesday works."})
- assert r.status_code == 400
- assert "thread" in r.json()["message"]
+ assert r.json() == {"success": True}
+ item = asyncio.run(state.get_outbox_item(item_id))
+ assert item["subject"] == "your client portal"
+ assert item["body"] == "Thanks, Tuesday works."
+
+
+def test_a_reply_with_a_folded_subject_can_still_have_its_body_edited(client):
+ state, item_id = asyncio.run(_seed(client.db_path, kind="reply"))
+
+ async def fold():
+ async with aiosqlite.connect(client.db_path) as db:
+ await db.execute("UPDATE outbox SET subject = 'Re: your client\n portal' WHERE id = ?",
+ (item_id,))
+ await db.commit()
+ asyncio.run(fold())
+ # The browser's <input> drops the newline; the server keeps the original.
r = client.post(f"/api/outbox/{item_id}/edit",
- json={"subject": "your client portal", "body": "Thanks, Tuesday works."})
+ json={"subject": "Re: your client portal", "body": "Tuesday works."})
assert r.json() == {"success": True}
- assert asyncio.run(state.get_outbox_item(item_id))["body"] == "Thanks, Tuesday works."
+ assert asyncio.run(state.get_outbox_item(item_id))["subject"] == "Re: your client\n portal"
@pytest.mark.parametrize("payload", [[], "text", 5])