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.

No thanks within one line only; remember every footer Harvey used

Ethan6ca5ec9e84ee
diff --git a/README.md b/README.md
index b584568..a54b5f1 100644
--- a/README.md
+++ b/README.md
@@ -485,7 +485,7 @@ What to know:
Harvey automates outreach, but **you are the sender.** Cold email is legal in most places when done right and expensive when done wrong — CAN-SPAM penalties run to $53,088 per email. Harvey ships with compliant defaults. Keep them.
-**CAN-SPAM (US).** Truthful subject line and accurate from-address — Harvey's copywriting rules forbid fake "re:" threads and impersonation. A working opt-out, honored fast: every cold email ends with an opt-out line (`compliance.opt_out_line`, default *Not interested? Reply "no thanks" and I won't email again.*), and Harvey treats any opt-out wording as immediate and permanent, wherever in the reply the person wrote it (including a bare "STOP" or "No thanks"). Your physical mailing address in the footer: set `compliance.postal_address` in `harvey.yaml` before your first campaign. Harvey adds both lines under every cold email when it sends (replies don't get them), shows them under each draft in the Outbox, and warns on `harvey run`, `harvey status` and the Outbox tab until the address is set. Text in a reply that repeats what Harvey wrote for that person (its emails, footers as sent, campaign templates) is set aside as quoted, not read as their words, so quoting Harvey's own footer isn't an opt-out; the model also reads replies without the quoted email. The opt-out line must ask for a reply Harvey recognises (`Reply "no thanks"`, `Reply STOP`, also "unsubscribe", "remove me", "opt out") and can't contain a link or email address.
+**CAN-SPAM (US).** Truthful subject line and accurate from-address — Harvey's copywriting rules forbid fake "re:" threads and impersonation. A working opt-out, honored fast: every cold email ends with an opt-out line (`compliance.opt_out_line`, default *Not interested? Reply "no thanks" and I won't email again.*), and Harvey treats any opt-out wording as immediate and permanent, wherever in the reply the person wrote it (including a bare "STOP" or "No thanks"). Your physical mailing address in the footer: set `compliance.postal_address` in `harvey.yaml` before your first campaign. Harvey adds both lines under every cold email when it sends (replies don't get them), shows them under each draft in the Outbox, and warns on `harvey run`, `harvey status` and the Outbox tab until the address is set. Text in a reply that repeats what Harvey wrote for that person (its emails, campaign templates, and every footer it has used) is set aside as quoted, not read as their words, so quoting Harvey's own footer isn't an opt-out; the model also reads replies without the quoted email. The opt-out line must ask for a reply Harvey recognises (`Reply "no thanks"`, `Reply STOP`, also "unsubscribe", "remove me", "opt out") and can't contain a link or email address.
**GDPR / PECR (EU & UK).** B2B cold email needs a defensible legitimate interest: the pitch must be genuinely relevant to that person's role, you must know where the data came from, and objecting must be effortless. If you can't say why a specific person would care, Harvey shouldn't email them — and its qualification rules say so.
diff --git a/harvey/agents/handler.py b/harvey/agents/handler.py
index bf77824..b4f56ef 100644
--- a/harvey/agents/handler.py
+++ b/harvey/agents/handler.py
@@ -67,7 +67,9 @@ OPT_OUT_PATTERNS = (
)
# "No thanks" (what cold email's footer asks for) as a phrase: not "no
# Thanksgiving", "Bruno / Thanks," or "yes or no, thanks".
-NO_THANKS_RE = re.compile(r"(?<!\bor )\bno,?[ \t]+thank(?:s|[ \t]+you)\b")
+# Checked one line at a time: "...the answer is no / Thanks!" is a sign-off.
+NO_THANKS_RE = re.compile(
+ r"(?<!\bor )\bno,?[ \t]+thank(?:s|[ \t]+you)\b(?![ \t]+(?:needed|necessary|required))")
# A reply that says only this (signature aside) is an opt-out ("Reply STOP").
BARE_OPT_OUTS = {"stop", "unsubscribe", "remove", "remove me", "opt out",
"no thanks", "no thank you"}
@@ -134,10 +136,13 @@ class OurText:
return "\n".join(kept)
-def _is_opt_out(keyword_text: str, own_words: str) -> bool:
- """keyword_text: everything they wrote, flattened (phrases can span a
- line wrap). own_words: their reply without the quote."""
- if any(p in keyword_text for p in OPT_OUT_PATTERNS) or NO_THANKS_RE.search(keyword_text):
+def _is_opt_out(their_text: str, own_words: str) -> bool:
+ """their_text: everything they wrote, our text removed. own_words: their
+ reply without the quote. Longer phrases match across a line wrap; "no
+ thanks" only within a line."""
+ if any(p in _flat(their_text) for p in OPT_OUT_PATTERNS):
+ return True
+ if any(NO_THANKS_RE.search(_flat(line)) for line in their_text.split("\n")):
return True
bare = _flat(_MOBILE_SIGNATURE_RE.sub("", own_words or ""))
return re.sub(r"[^\w\s-]", "", bare).strip() in BARE_OPT_OUTS
@@ -282,6 +287,7 @@ class Handler:
compliance = compliance_of(self.config)
return OurText([
*await self.state.get_texts_for_prospect(prospect.id),
+ *await self.state.get_footer_history(),
compliance.postal_address, compliance.opt_out_line, DEFAULT_OPT_OUT_LINE,
])
@@ -306,7 +312,8 @@ class Handler:
# without the quoted email. Either way, a line repeating what we
# sent (our footer says "no thanks") is ours, not theirs.
ours = await self._our_text(prospect)
- keyword_text = _flat(ours.remove(reply_text))
+ their_text = ours.remove(reply_text)
+ keyword_text = _flat(their_text)
stripped = strip_quoted_reply(reply_text) or reply_text
reply_text = ours.remove(stripped).strip() or stripped
@@ -325,7 +332,7 @@ class Handler:
# 1. Classify intent. Hard keyword checks run FIRST and override
# the LLM — opt-outs and legal threats must never be missed.
- if _is_opt_out(keyword_text, reply_text):
+ if _is_opt_out(their_text, reply_text):
intent = "unsubscribe"
elif any(p in keyword_text for p in ESCALATION_PATTERNS):
intent = "escalate"
diff --git a/harvey/agents/sender.py b/harvey/agents/sender.py
index 4f6707b..9eea509 100644
--- a/harvey/agents/sender.py
+++ b/harvey/agents/sender.py
@@ -181,6 +181,7 @@ class Sender:
for step in campaign.sequence
]
+ await self.state.remember_footer_lines(compliance_footer_lines(self.config))
result = await self.instantly.set_campaign_emails(campaign_id, sequences)
if result is None:
logger.error(f"Sender: Failed to set emails for campaign {campaign_id}")
@@ -658,6 +659,7 @@ class Sender:
await asyncio.sleep(random.uniform(*SEND_JITTER_SECONDS))
if sent_cold:
+ await self.state.remember_footer_lines(compliance_footer_lines(self.config))
notice = compliance_notice(self.config)
if notice:
logger.warning(f"Sender: {notice}")
diff --git a/harvey/dashboard.py b/harvey/dashboard.py
index 1c2537d..61d001f 100644
--- a/harvey/dashboard.py
+++ b/harvey/dashboard.py
@@ -1114,6 +1114,10 @@ async def mark_prospect_sent(prospect_id: str, request: Request):
# What marking sent cancelled comes back for review, never straight out.
changed = await state.restore_hand_cancelled_outbox(
prospect_id, reason=HAND_SENT_REASON)
+ if sent:
+ # Open in Gmail adds today's footer; remember it as Harvey's text.
+ footer = _compliance_view()["footer"]
+ await state.remember_footer_lines(footer.split("\n"))
await state.log_action(
action_type="manual_send" if sent else "manual_send_undone",
agent="user",
diff --git a/harvey/state.py b/harvey/state.py
index 63083f8..853b20f 100644
--- a/harvey/state.py
+++ b/harvey/state.py
@@ -912,7 +912,7 @@ class StateManager:
async with db.execute(sql, params) as cursor:
return [dict(r) for r in await cursor.fetchall()]
- async def get_texts_for_prospect(self, prospect_id: str, limit: int = 20) -> list[str]:
+ async def get_texts_for_prospect(self, prospect_id: str, limit: int = 50) -> list[str]:
"""Everything Harvey wrote for this person, which a reply may quote
back: their Outbox emails (a sent one with its footer, whatever it
said then) and the templates of campaigns they're in (Instantly and
@@ -1564,6 +1564,32 @@ class StateManager:
# ── Settings (operational flags: kill switch, counters) ──
+ FOOTER_HISTORY_KEY = "compliance_footer_history"
+
+ async def remember_footer_lines(self, lines) -> None:
+ """Keep every footer line Harvey has sent under a cold email, so a
+ reply quoting an old one (since reworded) is still known as ours."""
+ lines = [l.strip() for l in lines if l and l.strip()]
+ if not lines:
+ return
+ try:
+ known = json.loads(await self.get_setting(self.FOOTER_HISTORY_KEY) or "[]")
+ except (json.JSONDecodeError, TypeError):
+ known = []
+ if not isinstance(known, list):
+ known = []
+ merged = [l for l in known if isinstance(l, str)]
+ merged += [l for l in lines if l not in merged]
+ if merged != known:
+ await self.set_setting(self.FOOTER_HISTORY_KEY, json.dumps(merged[-50:]))
+
+ async def get_footer_history(self) -> list[str]:
+ try:
+ known = json.loads(await self.get_setting(self.FOOTER_HISTORY_KEY) or "[]")
+ except (json.JSONDecodeError, TypeError):
+ return []
+ return [l for l in known if isinstance(l, str)] if isinstance(known, list) else []
+
async def get_setting(self, key: str, default: str = "") -> str:
async with self._connect() as db:
async with db.execute(
diff --git a/tests/test_compliance_footer.py b/tests/test_compliance_footer.py
index a7157d5..77325f5 100644
--- a/tests/test_compliance_footer.py
+++ b/tests/test_compliance_footer.py
@@ -484,7 +484,12 @@ async def test_campaign_text_counts_as_ours_without_an_outbox_row(state):
@pytest.mark.asyncio
@pytest.mark.parametrize("body", [
"Is it month to month, yes or no, thanks",
-], ids=["yes-or-no-comma"])
+ # "no" ending a line, then a "Thanks" sign-off: never joined into a phrase.
+ "Do you require a long contract? Hoping the answer is no\nThanks!\nBob",
+ "Monday works, Tuesday no\nThanks, Jim",
+ "Is it month to month? yes/no\nThanks,\nBob",
+ "Happy to chat Tuesday, no thanks needed for the note!",
+], ids=["yes-or-no-comma", "answer-is-no", "tuesday-no", "yes-slash-no", "no-thanks-needed"])
async def test_a_question_ending_in_or_no_thanks_is_not_an_opt_out(state, body):
status, _ = await _reply(state, body)
assert status != "opted_out"
@@ -495,8 +500,7 @@ async def test_a_question_ending_in_or_no_thanks_is_not_an_opt_out(state, body):
"STOP\n\nSent from my iPhone",
"Stop\n\nGet Outlook for iOS",
"I'd ask that you do not\ncontact me again.",
- "Appreciate it, but we're set, so no\nthanks.",
-], ids=["stop-iphone", "stop-outlook-ios", "wrapped-do-not-contact", "wrapped-no-thanks"])
+], ids=["stop-iphone", "stop-outlook-ios", "wrapped-do-not-contact"])
async def test_opt_outs_with_signatures_or_wrapped_lines_are_caught(state, body):
status, prompts = await _reply(state, body)
assert status == "opted_out" and prompts == []
@@ -510,3 +514,47 @@ def test_opt_out_line_must_ask_for_a_reply_harvey_catches():
for good in (LINE, "Reply STOP to opt out.", "Not a fit? Just reply with unsubscribe.",
"Reply 'remove me' and you won't hear from me again."):
assert ComplianceConfig(opt_out_line=good).opt_out_line == good
+
+
+# ── Review round 3 ──
+
+async def test_every_footer_harvey_used_stays_ours_after_the_line_changes(state):
+ # Instantly keeps the footer in its own copy; Harvey remembers what it used.
+ old = 'Reply "unsubscribe" to stop hearing from me.'
+ config = SimpleNamespace(
+ channels=SimpleNamespace(email=SimpleNamespace(
+ enabled=True, provider="instantly", require_approval=False,
+ max_daily_sends=50, send_to_risky=False)),
+ compliance=ComplianceConfig(postal_address=ADDRESS, opt_out_line=old))
+ sender = Sender(None, state, config, EnvConfig())
+ sender.instantly = AsyncMock()
+ sender.instantly.set_campaign_emails.return_value = None
+ await sender._deploy_campaign(Campaign(
+ id="c", name="Draft", instantly_campaign_id="existing",
+ sequence=[EmailStep(step=1, subject="a note", body="Would this help?")]))
+ # The line is changed afterwards; a reply quotes the old one.
+ status, _ = await _reply(state, "Yes let's talk.\n\nOn Tue Harvey wrote:\n> Would this help?\n> " + old)
+ assert status != "opted_out"
+
+
+async def test_template_lines_with_merge_tags_are_recognised_when_quoted(state):
+ import json
+ import sqlite3
+ pid = await seed_prospect(state, status="contacted")
+ with sqlite3.connect(state.db_path) as db:
+ db.execute(
+ "INSERT INTO campaigns (id, name, channel, sequence_json, prospect_ids_json, status) "
+ "VALUES ('c9', 'x', 'email', ?, ?, 'active')",
+ (json.dumps([{"step": 1, "subject": "hi", "delay_days": 0,
+ "body": "We help {{company}} attorney offices grow."}]),
+ json.dumps([pid])))
+ provider = FakeProvider()
+ provider.inbound = [InboundMessage(
+ provider_id="in1", from_email="[email protected]", subject="Re: hi",
+ body="Yes please.\n\nOn Tue Harvey wrote:\n> We help Acme attorney offices grow.")]
+ handler = make_handler(state, provider, intent="interested")
+ handler.brain = RecordingBrain("interested")
+ await handler._run_native()
+ assert handler.brain.prompts # our pitch's "attorney" didn't escalate