From c03e9a323e266c6a9a7ccb17bbbb7841296bbd5c Mon Sep 17 00:00:00 2001 From: soryu Date: Thu, 30 Apr 2026 17:09:45 +0100 Subject: feat(directives): amendment lifecycle — inactive status, new draft, before/after diff (#113) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stage 4 of the doc-mode revamp. Closes the loop on living-spec contracts: once a contract ships (PR raised) it becomes 'inactive', editing it kicks off an amendment cycle, the planner sees the previously-merged content as context, and "New draft" lets users abandon amendment and start the next contract on a clean slate. ## inactive lifecycle - New status `'inactive'`. Set automatically when `update_directive` detects a `pr_url` transition None → Some, alongside the revision snapshot (set_directive_inactive: idempotent, only flips active/idle/paused). - `update_directive_goal` extends its CASE flip to include 'inactive', so editing a shipped contract's goal reactivates it for the planner. - Frontend: `DirectiveStatus` gains 'inactive'; STATUS_DOT and the legacy STATUS_BADGEs (DirectiveDetail, DirectiveList) get color/label entries. Sidebar sort puts inactive after draft / before archived. ## Amendment diff to the orchestrator `build_planning_prompt` takes a new `previous_merged_revision` parameter. When set, it prepends an "AMENDMENT TO A PREVIOUSLY-MERGED CONTRACT" header that shows the merged content and the amended content explicitly, with guidance to plan a delta rather than a from-scratch rebuild. Both the planning and replanning phases call `get_latest_merged_revision` and pass it through. ## "New draft" affordance - New `repository::reset_directive_for_new_draft`: clears goal to '', status → 'draft', detaches pr_url / pr_branch / orchestrator linkage. Past revisions stay in directive_revisions as history. - New `POST /api/v1/directives/{id}/new-draft` handler. - DirectiveContextMenu surfaces "New draft" only when status === 'inactive', via an optional onNewDraft callback (legacy tabular UI doesn't have to wire it up). After reset, the page navigates to the contract so the user starts typing the next iteration immediately. ## PR-state-aware updates The user's spec — "open ⇒ update, merged ⇒ new PR, closed ⇒ new PR" — is already implemented in `build_completion_prompt`'s `gh pr view` runtime check, so no code change was needed here. The amendment cycle naturally flows through it: inactive → goal save → status flips to active → phase_replanning spawns a planner → completion task picks up the existing pr_url, sees the GitHub state, and decides update vs new PR accordingly. Co-authored-by: Claude Opus 4.7 (1M context) --- .../components/directives/DirectiveContextMenu.tsx | 28 ++++++++ .../src/components/directives/DirectiveDetail.tsx | 1 + .../src/components/directives/DirectiveList.tsx | 1 + makima/frontend/src/lib/api.ts | 26 +++++++- makima/frontend/src/routes/document-directives.tsx | 15 ++++- makima/src/db/repository.rs | 74 ++++++++++++++++++++-- makima/src/orchestration/directive.rs | 52 ++++++++++++++- makima/src/server/handlers/directives.rs | 60 ++++++++++++++++++ makima/src/server/mod.rs | 1 + makima/src/server/openapi.rs | 1 + 10 files changed, 249 insertions(+), 10 deletions(-) diff --git a/makima/frontend/src/components/directives/DirectiveContextMenu.tsx b/makima/frontend/src/components/directives/DirectiveContextMenu.tsx index 07322e2..3f24ce1 100644 --- a/makima/frontend/src/components/directives/DirectiveContextMenu.tsx +++ b/makima/frontend/src/components/directives/DirectiveContextMenu.tsx @@ -11,6 +11,12 @@ interface DirectiveContextMenuProps { onArchive: () => void; onDelete: () => void; onGoToPR: () => void; + /** + * Reset the contract to a fresh empty draft (clears goal + pr_url, status + * back to 'draft'). Past revisions stay as history. Optional so the legacy + * tabular UI doesn't have to wire it up. + */ + onNewDraft?: () => void; } export function DirectiveContextMenu({ @@ -23,6 +29,7 @@ export function DirectiveContextMenu({ onArchive, onDelete, onGoToPR, + onNewDraft, }: DirectiveContextMenuProps) { const menuRef = useRef(null); @@ -73,6 +80,10 @@ export function DirectiveContextMenu({ const showPause = directive.status === "active"; const showArchive = directive.status !== "archived"; const showGoToPR = !!directive.prUrl; + // "New draft" appears once the contract is inactive (its iteration has + // shipped) — that's the explicit affordance for starting the next cycle + // on a clean slate while keeping prior revisions as history. + const showNewDraft = !!onNewDraft && directive.status === "inactive"; return (
+ {/* New draft — the canonical action on an inactive (shipped) contract. */} + {showNewDraft && ( + <> + +
+ + )} + {/* Status actions */} {showStart && (