Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/planning/feat-auto-handle-plain-accepts-3c9a51e7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Changed

- The interview server marks a plain accept (no text) and a plain confirm handled when it saves them, so the watcher wakes only for events that need a reply. The responses document, `sync-ledger` and `export-brief` record them as before. The accept that settles the last open question of a round stays unhandled, so the agent learns the round is complete. Undo of an auto-handled accept still works until the agent handles a later event; the "Claude already handled it" refusal applies to agent-handled events. The interview surface reference lists which events are auto-handled.
8 changes: 6 additions & 2 deletions plugins/planning/skills/interview/context/surface.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ A decision event names the content revision it answered: the `contentRev` the pa

| `kind` | `id` | Records a decision | Handling |
|---|---|---|---|
| `accept` | question | yes | Record in the ledger. No `text`, or the note already recorded for that question: `handle`, no reply. New non-empty `text`: `reply` with its `seq`, answering the note |
| `accept` | question | yes | Record in the ledger. No `text`, or the note already recorded for that question: `handle`, no reply (a plain accept the server auto-handled never reaches you, see [Auto-handled events](#auto-handled-events)). New non-empty `text`: `reply` with its `seq`, answering the note |
| `alt` | question | yes (`alt` is the key) | Record; reply only when the choice changes other questions |
| `own` | question | yes (`text` required) | Record; read back a dictated answer in one line (R-D) |
| `defer` | question | yes | Record as deferred |
Expand All @@ -148,10 +148,14 @@ A decision event names the content revision it answered: the `contentRev` the pa
| `note` | none | no | `note-reply` with its `seq`, or `reply` on a question |
| `undo` | question, `undoSeq` | withdraws `undoSeq` | Drop that decision from the ledger; `handle` both seqs |
| `wrapup` | none; a forced one carries `text` | no | Run [Wrap-up](#wrap-up), then `handle`. A `text` starting `Skipped before wrap-up:` lists, one line each, starting with a dash, what the user left outstanding when they pressed Wrap up anyway (an unconfirmed understanding, unticked commitments by question, an unanswered Notes post, open questions); `round.sh status` prints it. When running Wrap-up, name each skipped item to the user |
| `confirm` | question, `alt` is the commitment index | no; ticks one commitment | `handle` |
| `confirm` | question, `alt` is the commitment index | no; ticks one commitment | None: the server auto-handles it, see [Auto-handled events](#auto-handled-events) |
| `accept-audit` | none; `alt` is the round id, `items` lists the accepted questions | yes, once per listed question (each has its own `accept` event carrying `auditSeq`) | Record each accepted question, `handle` the `accept-audit` seq and every fanned-out accept seq with no reply, then run `/planning:audit-answers` on the event's `items` only, so questions outside the round stay open. The audit returns only the doubtful ones as human questions |
| `confirm-understanding` | none; `alt` is `confirm` or `off`, `contentRev` is the restatement `rev` | no | `confirm`: the gate passed, `handle`. `off`: `note-reply` to its `text` with its `seq`, see [Confirmation gate](#confirmation-gate) |

### Auto-handled events

The server marks a plain `accept` (no `text`) and a plain `confirm` handled when it saves them (the event carries `autoHandled: true`), so the watcher wakes only for events that need a reply. They are recorded in `responses.json` as usual, so `sync-ledger` and `export-brief` count them like any other. Every other kind stays unhandled until you `handle` or reply to it: `ask`, `own`, `rephrase`, `note`, `research`, `cancel-research`, `undo`, `wrapup`, `confirm-understanding`, `accept-audit`, and an `accept` with `text`. The accept that leaves no open question in its round is not auto-handled, so it wakes you and you learn the round is complete. An auto-handled accept stays undoable until you handle a later event; after that, the undo is refused with `Claude already handled it`, as for an event you handled yourself.

"Accept all and have agents check them" arrives as one `accept-audit` event plus its accepts; the page holds no validation logic, so the skill routes the round to `/planning:audit-answers`. The page leaves a question that carries a note out of that event, so every fanned-out accept is plain.

The page labels each option once. `Rec` is the recommendation (an `accept`, ledger `accepted:`), `Accept with note` is its own row (an `accept` whose `text` is the note), and each alternative is its key, `(a)`, `(b)` (an `alt`, ledger `alt <key>:`). Number keys are shortcuts only, counted from the top row, and are never shown. Name an option in a reply by that label, not by a number. The note box starts empty and never takes a stored decision's text: a recorded note shows read-only under `Your earlier answer`, and an `accept` carries `text` only when the user typed it in that edit. When an own answer or an Ask names one option by a label (`Rec`, `#1`, `option 2` for the first alternative, `(a)`), the page asks `Did you mean Accept with note?` (or `Choose (a)`) before saving: accepting records that option with the note as typed, `Save as own answer` or `Send as a question` keeps the note as typed, and closing the dialog sends nothing. A note naming several options, or a bare `#123`, is saved as typed without asking.
Expand Down
2 changes: 1 addition & 1 deletion plugins/planning/surface/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ <h1 id="title">Interview</h1>
}
const waitText = q => (stateOf(q) === "need" ? "Needs your answer: " : "Pending research: ") + (q.waitsOn || "");
function parents(q){ return [...new Set([...(q.dependsOn || []), ...(q.followUpOf ? [q.followUpOf] : [])])].filter(id => Q[id] && id !== q.id); }
const isHandled = seq => seq <= (S.doc.handledSeq || 0) || (S.doc.handled || []).includes(seq);
const isHandled = seq => seq <= (S.doc.handledSeq || 0) || (S.doc.handled || []).includes(seq) || !!(events().find(e => e.seq === seq) || {}).autoHandled; // the server handles a plain accept or confirm at save time
const queued = () => S.online && !stalled() && pending().some(delivered) ? " Queued, Claude is busy." : ""; // a wake is in flight: an event was delivered and not yet handled
const delivered = e => !!e.deliveredAt || (S.watchSeq > 0 && e.seq <= S.watchSeq) || isHandled(e.seq);
const events = () => S.resp.events || [];
Expand Down
8 changes: 6 additions & 2 deletions plugins/planning/surface/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ def guard_revision(d, doc, qid, seq, force):
newer = [
e["seq"]
for e in events
if not is_handled(doc, e["seq"]) and not e.get("withdrawn")
if not is_handled(doc, e["seq"])
and not e.get("withdrawn")
and not e.get("autoHandled")
]
why = "an unhandled user event"
else:
Expand Down Expand Up @@ -1635,7 +1637,9 @@ def unhandled_events(doc, r):
return [
e
for e in r.get("events", [])
if not e.get("withdrawn") and not is_handled(doc, e.get("seq", 0))
if not e.get("withdrawn")
and not e.get("autoHandled")
and not is_handled(doc, e.get("seq", 0))
]


Expand Down
1 change: 1 addition & 0 deletions plugins/planning/surface/schema/event.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"at": {"type": "string"},
"deliveredAt": {"type": "string"},
"withdrawn": {"type": "boolean"},
"autoHandled": {"type": "boolean", "description": "Set by the server on a plain accept (no text) or plain confirm, except an accept that settles its round's last open question: it wakes no agent. The agent never handles it, and an undo of it holds until the agent handles a later event."},
"undoSeq": {"type": "integer"},
"auditSeq": {"type": "integer"},
"contentRev": {"type": "integer"},
Expand Down
37 changes: 34 additions & 3 deletions plugins/planning/surface/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ def upstream(qid): # stale ancestors, nearest first, ties by id
revising = {
e["id"]
for e in events
if e.get("deliveredAt") and not is_handled(doc, e.get("seq", 0))
if e.get("deliveredAt")
and not e.get("autoHandled")
and not is_handled(doc, e.get("seq", 0))
}
out, up = {}, {}
for qid in deps:
Expand Down Expand Up @@ -546,6 +548,20 @@ def is_handled(doc, seq):
return seq <= (doc.get("handledSeq") or 0) or seq in set(doc.get("handled") or [])


def round_complete(doc, r, qid):
"""True when every live question in qid's round has a decision in r (this accept included)."""
qs = [q for q in doc.get("questions") or [] if isinstance(q, dict)]
rnd = next((q.get("round") for q in qs if q.get("id") == qid), None)
return not any(
q.get("round") == rnd
and not q.get("archived")
and not q.get("supersededBy")
and not (r["responses"].get(q.get("id")) or {}).get("decision")
and not (q.get("terminal") or {}).get("decision")
for q in qs
)


def release_user_holds(doc, r):
"""Drop, in this loaded copy only, each `by: user` hold that the user has since answered: a
live accept, alt or own on the question with a seq above the hold's setAsideSeq, or, on a hold
Expand Down Expand Up @@ -1037,6 +1053,13 @@ def record(self, msg):
"updatedAt": now,
"seq": seq,
}
# A plain accept or confirm needs no reply, so it wakes no agent; the accept that
# settles its round's last question stays unhandled, so the agent learns the round is done.
if not text.strip() and (
kind == "confirm"
or (kind == "accept" and not round_complete(doc, r, qid))
):
event["autoHandled"] = True
r["events"].append(event)
if qid:
line = {
Expand Down Expand Up @@ -1090,7 +1113,13 @@ def _undo(self, r, doc, msg, event):
raise ValueError("undoSeq is not a decision")
if target.get("withdrawn"):
raise Conflict({"error": "already undone"})
if is_handled(doc, target_seq):
if is_handled(doc, target_seq) or (
target.get("autoHandled")
and any(
e.get("seq", 0) > target_seq and is_handled(doc, e.get("seq", 0))
for e in r["events"]
)
):
raise Conflict({"error": "Claude already handled it"})
qid = target["id"]
live = [
Expand All @@ -1117,7 +1146,9 @@ def unhandled(self, r):
return [
e
for e in r.get("events", [])
if not e.get("withdrawn") and not is_handled(doc, e.get("seq", 0))
if not e.get("withdrawn")
and not e.get("autoHandled")
and not is_handled(doc, e.get("seq", 0))
]


Expand Down
33 changes: 33 additions & 0 deletions plugins/planning/surface/test_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,39 @@ def test_only_accept_and_own_carry_risks(self):
self.assertNotIn("Part of Q2", risks)


class TestAutoHandledAccepts(SessionCase):
"""A plain accept the server handled at save time exports the same as one the agent handled."""

def outputs(self, auto):
qs = [question("Q1", commits=["One writer only"]), question("Q2")]
plain = [event(1, "Q1", "accept"), event(3, "Q2", "accept")]
events = [
*[{**e, "autoHandled": True} if auto else e for e in plain],
event(2, "Q1", "confirm", alt="0"),
]
self.session(qs, sorted(events, key=lambda e: e["seq"]))
if not auto:
doc = json.loads((self.dir / "questions.json").read_text(encoding="utf-8"))
doc["handledSeq"] = 3
(self.dir / "questions.json").write_text(json.dumps(doc), encoding="utf-8")
ledger = self.export("ledger")
synced = self.tmp / f"synced-{auto}.md"
synced.write_text(ledger.read_text(encoding="utf-8"), encoding="utf-8")
rc, out = self.rp("sync-ledger", "--ledger", str(synced))
self.assertEqual(rc, 0, out)
return (
ledger.read_text(encoding="utf-8"),
self.export("brief").read_text(encoding="utf-8"),
synced.read_text(encoding="utf-8"),
)

def test_ledger_brief_and_sync_ledger_match_either_way(self):
by_agent = self.outputs(auto=False)
by_server = self.outputs(auto=True)
self.assertEqual(by_server, by_agent)
self.assertIn("answer:: accepted: ", by_server[0])


class TestExportReport(SessionCase):
def test_report_is_self_contained_html(self):
svg = "<svg xmlns='http://www.w3.org/2000/svg'><script>alert(1)</script></svg>"
Expand Down
78 changes: 77 additions & 1 deletion plugins/planning/surface/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ def test_1_confirm_is_saved_as_a_user_line_without_a_decision(self):
line = r["history"]["A"][-1]
self.assertEqual((line["kind"], line["alt"]), ("confirm", "1"))
code, body, _ = self.wait("after=handled&replayed=0&timeout=5")
self.assertIn(data["seq"], seqs(body["events"]))
self.assertNotIn(data["seq"], seqs(body["events"]))
rc, out = self.rp("validate")
self.assertEqual(rc, 0, out)

Expand Down Expand Up @@ -1868,6 +1868,82 @@ def test_5_a_confirm_carrying_an_old_question_rev_is_stale(self):
self.assertEqual(code, 200, data)


class TestAutoHandle(WaitCase):
"""A plain accept or confirm is handled at save time; the accept that settles the round is not."""

@classmethod
def prepare(cls):
seed_questions(
cls.dir, question("A"), question("B"), question("C"), question("D")
)

def accept(self, qid, **extra):
code, data = self.post({"id": qid, "kind": "accept", **extra})
self.assertEqual(code, 200, data)
return data["seq"]

def woken(self, timeout=2):
code, body, _ = self.wait(f"after=handled&replayed=0&timeout={timeout}")
self.assertEqual(code, 200, body)
return seqs(body["events"])

def test_1_a_plain_accept_is_recorded_and_absent_from_unhandled(self):
seq = self.accept("A")
r = self.state()["responses"]
self.assertEqual(r["responses"]["A"]["decision"], "accept")
event = next(e for e in r["events"] if e["seq"] == seq)
self.assertIs(event.get("autoHandled"), True)
self.assertEqual(self.woken(), [])

def test_2_an_accept_with_text_is_unhandled(self):
seq = self.accept("B", text="Keep the second commitment.")
self.assertEqual(self.woken(), [seq])
rc, out = self.rp("handle", "--seq", str(seq))
self.assertEqual(rc, 0, out)

def test_3_a_plain_confirm_is_absent_from_unhandled(self):
code, data = self.post({"id": "A", "kind": "confirm", "alt": "1"})
self.assertEqual(code, 200, data)
self.assertEqual(self.woken(), [])

def test_4_the_accept_that_settles_the_round_produces_a_wake(self):
self.accept("C")
last = self.accept("D")
self.assertEqual(self.woken(), [last])
type(self).last = last

def test_5_undo_of_an_auto_handled_accept_succeeds(self):
seq = next(
e["seq"]
for e in self.state()["responses"]["events"]
if e["id"] == "C" and e["kind"] == "accept"
)
code, data = self.post({"id": "C", "kind": "undo", "undoSeq": seq})
self.assertEqual(code, 200, data)
self.assertNotIn("C", self.state()["responses"]["responses"])

def test_6_undo_of_an_agent_handled_accept_is_409(self):
rc, out = self.rp("handle", "--seq", str(self.last))
self.assertEqual(rc, 0, out)
code, data = self.post({"id": "D", "kind": "undo", "undoSeq": self.last})
self.assertEqual(code, 409, data)
self.assertIn("handled", data.get("error", ""))

def test_7_undo_of_an_auto_handled_accept_is_409_once_the_agent_handles_a_later_event(
self,
):
code, data = self.post({"id": "A", "kind": "reopen"})
self.assertEqual(code, 200, data)
seq = self.accept("C")
code, data = self.post({"kind": "note", "text": "A later event."})
self.assertEqual(code, 200, data)
rc, out = self.rp("handle", "--seq", str(data["seq"]))
self.assertEqual(rc, 0, out)
code, data = self.post({"id": "C", "kind": "undo", "undoSeq": seq})
self.assertEqual(code, 409, data)
self.assertIn("handled", data.get("error", ""))


def seed_restatement(d, rev):
doc = json.loads((Path(d) / "questions.json").read_text(encoding="utf-8"))
doc["restatement"] = {"rev": rev, "at": "t", "sections": {"goal": "Ship it."}}
Expand Down
4 changes: 2 additions & 2 deletions plugins/planning/surface/tests/ui_c.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ async page => {
ok("Reconfirm sends the note typed over the kept one", /^Reconfirm/.test(r6) && ev6.id === "P2" && ev6.kind === "alt" && ev6.alt === "b" && ev6.text === "Weekdays too", r6 + " " + JSON.stringify(ev6));
await pick("P2");

// SPEC 5.2: revising while an upstream decision is delivered and unhandled
const r5 = await (await post({id: "P1", kind: "accept", alt: null, text: ""})).json();
// SPEC 5.2: revising while an upstream decision is delivered and unhandled (an accept with a note: the server auto-handles a plain one)
const r5 = await (await post({id: "P1", kind: "accept", alt: null, text: "Fine for now"})).json();
await page.request.get(base + "api/wait?after=" + (r5.seq - 1) + "&timeout=2", {headers: {"X-Interview-Token": await token()}});
await page.waitForTimeout(900);
ok("revising chip on the answered question, not its dependent", /Answer not handled yet/.test(await page.textContent('.qbtn[data-q="P1"]')) && !/Answer not handled yet/.test(await page.textContent('.qbtn[data-q="P2"]')));
Expand Down
3 changes: 2 additions & 1 deletion plugins/planning/surface/tests/ui_live.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ async page => { // an open tab shows every change Claude applies without a reloa
await page.waitForSelector(".qbtn", {state: "attached"});
await page.evaluate(() => localStorage.clear());
await page.reload(); await page.waitForSelector(".qbtn", {state: "attached"}); await page.waitForTimeout(400);
// Q3 is accepted from the page, so its event waits for Claude to handle it.
// Q3 is accepted from the page with a note, so its event waits for Claude to handle it (the server auto-handles a plain accept).
await page.click('.rail-list .qbtn[data-q="Q3"]'); await page.waitForTimeout(200);
await page.fill("#note", "Fine for now"); await page.waitForTimeout(200);
await page.click("#qhead"); await page.keyboard.press("a"); await page.keyboard.press("Control+Enter");
ok("Q3 shows Sent to Claude after the page's accept", await until(() => /Sent/.test(document.querySelector('.rail-list .qbtn[data-q="Q3"]').textContent)), await rail("Q3"));
await page.click('.rail-list .qbtn[data-q="Q1"]'); await page.waitForTimeout(200);
Expand Down
Loading