Thesis Workshop redesign: edit/choose/delete + approve-as-current (v0.1.0:56)

Addresses Grant's feedback that the Workshop was confusing and underbuilt (no delete,
no approve, redundant generate-vs-feedback panels, and a stray "0" on segment lines).

Backend (architect_tools.py + server.py routes/handlers):
- retire_node: soft-delete a node + its subtree (reversible). DELETE /api/thesis/nodes/{id}.
- choose_variant: 'Use this' — keep this option, soft-delete the others in its group,
  mark it approved. POST /api/thesis/nodes/{id}/choose.
- upsert_thesis_node gains actor_type so a manual human edit is recorded as 'human'.
  PUT /api/thesis/nodes/{id} edits a part's text directly.
- handle_approve_line: one-click 'approve as current' — records this admin's approval on
  the line's in-review version (creating + submitting one from the live tree if none),
  promoting to canonical at the required distinct-approval count. POST /api/thesis/lines/{key}/approve.

Frontend (ThesisWorkshop redesign):
- Merged the redundant "Generate options" + "Give feedback" panels into one "Ask the
  Architect for options" box (revise was just generate-with-guidance).
- Per option: Use this / Edit (inline) / Delete. Per part: edit + delete via the same.
- "Approve as current" bar with dual-sign-off state + a "Current ✓" badge, and a one-line
  "how it works" hint. Refreshes the tree after every action.
- Fixed the stray "0": `{line.is_core && <badge>}` rendered 0 for non-core lines (SQLite
  integer 0); now `{!!line.is_core && ...}`.

Verified: backend test_thesis_actions.py (choose/edit/retire-subtree/dual-approval->canonical),
and a live in-browser smoke test (JSX compiles, Workshop renders, options show Use/Edit/Delete,
approve returns 1-of-2, no runtime errors).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Keysat
2026-06-05 18:29:47 -05:00
parent 8338c34ac0
commit 6d6f4bcc7e
7 changed files with 389 additions and 110 deletions
+75
View File
@@ -1898,6 +1898,10 @@ class CRMHandler(BaseHTTPRequestHandler):
return self.handle_node_feedback(user, path.split('/')[-2], body)
if path == '/api/architect/ground':
return self.handle_architect_ground(user, body)
if re.match(r'^/api/thesis/nodes/[^/]+/choose$', path):
return self.handle_choose_variant(user, path.split('/')[-2])
if re.match(r'^/api/thesis/lines/[^/]+/approve$', path):
return self.handle_approve_line(user, path.split('/')[-2])
if path == '/api/thesis/lines':
return self.handle_create_thesis_line(user, body)
if re.match(r'^/api/thesis/lines/[^/]+/nodes$', path):
@@ -1938,6 +1942,8 @@ class CRMHandler(BaseHTTPRequestHandler):
return self.handle_update_lp_profile(user, path.split('/')[-1], body)
if path == '/api/fundraising/state':
return self.handle_update_fundraising_state(user, body)
if re.match(r'^/api/thesis/nodes/[^/]+$', path):
return self.handle_edit_thesis_node(user, path.split('/')[-1], body)
self.send_error_json("Not found", 404)
@@ -1987,6 +1993,8 @@ class CRMHandler(BaseHTTPRequestHandler):
return self.handle_delete_opportunity(user, path.split('/')[-1])
if re.match(r'^/api/communications/[^/]+$', path):
return self.handle_delete_communication(user, path.split('/')[-1])
if re.match(r'^/api/thesis/nodes/[^/]+$', path):
return self.handle_retire_thesis_node(user, path.split('/')[-1])
self.send_error_json("Not found", 404)
# ═══════════════════════════════════════════════════════════════════════════
@@ -3669,6 +3677,73 @@ class CRMHandler(BaseHTTPRequestHandler):
conn.close()
return row['line_key'] if row else None
def handle_edit_thesis_node(self, user, node_id, body):
"""Manual human edit of a node's title/body (no Architect)."""
if not require_admin(user):
return self.send_error_json("Admin required", 403)
if _architect_tools is None:
return self.send_error_json("Unavailable", 503)
node = _architect_tools.get_node(node_id, db=DB_PATH)
if node.get('error'):
return self.send_error_json("Node not found", 404)
body = body or {}
res = _architect_tools.upsert_thesis_node(
node['line_id'], node['node_type'], body.get('body', node.get('body') or ''),
title=body.get('title', node.get('title')), node_id=node_id,
change_reason='manual edit', actor_id=user['user_id'], actor_type='human', db=DB_PATH)
return self.send_json({"data": res})
def handle_retire_thesis_node(self, user, node_id):
"""Soft-delete a node + its subtree."""
if not require_admin(user):
return self.send_error_json("Admin required", 403)
if _architect_tools is None:
return self.send_error_json("Unavailable", 503)
res = _architect_tools.retire_node(node_id, actor_id=user['user_id'], db=DB_PATH)
if res.get('error'):
return self.send_error_json("Node not found", 404)
return self.send_json({"data": res})
def handle_choose_variant(self, user, node_id):
"""'Use this option' — keep this variant, retire its siblings."""
if not require_admin(user):
return self.send_error_json("Admin required", 403)
if _architect_tools is None:
return self.send_error_json("Unavailable", 503)
res = _architect_tools.choose_variant(node_id, actor_id=user['user_id'], db=DB_PATH)
if res.get('error'):
return self.send_error_json("Node not found", 404)
return self.send_json({"data": res})
def handle_approve_line(self, user, line_key):
"""One-click 'approve as current': record this admin's approval on the line's
in-review version (creating + submitting one from the live tree if none exists);
promotes to canonical once the required distinct approvals are reached."""
if not require_admin(user):
return self.send_error_json("Admin required", 403)
if _architect_tools is None or thesis_review is None:
return self.send_error_json("Unavailable", 503)
conn = get_db()
line = conn.execute("SELECT id FROM thesis_lines WHERE line_key=? AND deleted_at IS NULL", (line_key,)).fetchone()
v = None
if line:
v = conn.execute("SELECT id FROM thesis_versions WHERE line_id=? AND status='in_review' ORDER BY version_no DESC LIMIT 1",
(line['id'],)).fetchone()
conn.close()
if not line:
return self.send_error_json("Line not found", 404)
if v:
version_id = v['id']
else:
ver = _architect_tools.create_thesis_version(line_key, rationale="Approved as current (Workshop)",
created_by=user['user_id'], db=DB_PATH)
if ver.get('error'):
return self.send_error_json(ver['error'], 400)
_architect_tools.submit_version_for_review(ver['id'], db=DB_PATH)
version_id = ver['id']
res = thesis_review.record_review(DB_PATH, version_id, user['user_id'], 'approve')
return self.send_json({"data": res})
def handle_generate_options(self, user, node_id, body):
if not require_admin(user):
return self.send_error_json("Admin required", 403)