From e11759447b1ac00becfb1e979e488f7f9c9cf478 Mon Sep 17 00:00:00 2001
From: soryu <soryu@soryu.co>
Date: Fri, 1 May 2026 23:56:51 +0100
Subject: chore(cleanup): Phase 5 contracts removal + tmp directive + 30-day
 expiry + scroll fix (#118)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Sweeping cleanup across the surface and the wire. Net: -14k LOC of legacy
contracts code, plus the tmp/scroll/UX fixes the user asked for.

## Sidebar/editor independent scroll
Replace `height: calc(100vh - 80px)` (which assumed an 80px masthead and
quietly clipped or pushed the whole page below the fold when the masthead
was taller) with `h-screen + overflow-hidden` on the page root and proper
`flex-1 min-h-0` sizing on `<main>`. Sidebar and editor pane now manage
their own scroll independently; the page itself never scrolls.

Same fix in /tmp/:taskId.

## tmp directive — real backing for orphans/ephemerals

New migration `20260501100000_tmp_directive_and_clear_orphans.sql`:
  * Adds `directives.is_tmp` BOOLEAN NOT NULL DEFAULT false.
  * Partial unique index `(owner_id) WHERE is_tmp` — at most ONE tmp
    directive per owner.
  * Hard-deletes every existing orphan task (`directive_id IS NULL`).
    Per the user spec: "ALSO there are TOO MANY old tasks in tmp, we
    need to remove all of them as well."

New repository helpers:
  * `get_or_create_tmp_directive(pool, owner_id) -> Directive`
    INSERT ON CONFLICT DO NOTHING + fallback SELECT, race-safe.
  * `list_all_tmp_directives` — drives the expiry sweep.
  * `delete_expired_tmp_tasks(tmp_directive_id) -> u64`.
  * `list_tmp_tasks_for_owner` (replaces `list_orphan_tasks_for_owner`).

`mesh::create_task`: every top-level task must have a directive. If a
caller doesn't supply `directive_id` and isn't a subtask, attach to the
caller's tmp directive (auto-creating it on first use).

`list_directives_for_owner` filters out `is_tmp=true` so the scratchpad
directive doesn't pollute the contract list — surfaced via the sidebar's
`tmp/` folder instead.

## 30-day expiry on tmp tasks

New `phase_tmp_expiry` in the directive reconciler. Throttled to once per
hour: enumerates every tmp directive, calls `delete_expired_tmp_tasks`,
logs the count. The actual delete is `WHERE created_at < NOW() - INTERVAL
'30 days'` and is fast on the existing index. Subtasks die via FK cascade.

## Phase 5 — contracts removed

### Frontend
Deleted entire `/contracts` surface:
  * routes: `contracts.tsx`, `contract-file.tsx`
  * components/contracts: ContractList, ContractDetail, ContractCliInput,
    ContractContextMenu, CommandModePanel, PhaseBadge, PhaseHint,
    PhaseDeliverablesPanel, PhaseProgressBar, QuickActionButtons,
    RepositoryPanel, TaskDerivationPreview
  * (Kept `PhaseConfirmationModal` — used outside the contracts surface
    by `TaskOutput` and `PhaseConfirmationNotification`.)
  * Routes deregistered from `main.tsx`; nav entry removed from
    `NavStrip`.

### Backend handlers
Deleted: `contracts.rs` (2.4k LOC), `contract_chat.rs` (3.2k LOC),
`contract_daemon.rs` (~940 LOC), `contract_discuss.rs` (~590 LOC),
`transcript_analysis.rs` (~690 LOC). All `/api/v1/contracts/*` routes
deregistered. OpenAPI entries dropped. Module declarations removed from
`server/handlers/mod.rs`.

### CLI
Removed `makima contract` and `makima supervisor` subcommands. Deleted
`daemon/cli/contract.rs` and `daemon/cli/supervisor.rs`. Bin dispatch
trimmed (~377 LOC).

### Orchestrator
Removed the contract-spawn path from `phase_execution`
(`spawn_step_contract` and its caller). `directive_steps.contract_type`
now logs a warning and falls through to standalone-task spawn. Column
itself stays — old data still reads, just no longer triggers a
contract+supervisor spawn.

### TUI
`Action::PerformCreateContract` is now a no-op that surfaces a status
message: "Contracts have been removed. Use directives instead." The TUI
form is dead code pending a wider refresh.

## Out of scope (deliberately left)

* Contracts DB tables (`contracts`, `contract_repositories`,
  `contract_chat_history`, `contract_events`, `contract_templates`) are
  retained for historical data + because some peripheral code still
  joins to them in TaskSummary queries.
* `mesh_supervisor` handlers are retained — they aren't only used by
  contracts (some mesh-level supervisor behaviour persists), and the
  cross-cutting cleanup is bigger than this PR.
* `directive_steps.contract_type` column itself isn't dropped; just no
  longer functional.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
 .../src/components/contracts/ContractList.tsx      | 223 ---------------------
 1 file changed, 223 deletions(-)
 delete mode 100644 makima/frontend/src/components/contracts/ContractList.tsx

(limited to 'makima/frontend/src/components/contracts/ContractList.tsx')

diff --git a/makima/frontend/src/components/contracts/ContractList.tsx b/makima/frontend/src/components/contracts/ContractList.tsx
deleted file mode 100644
index 1eee6a3..0000000
--- a/makima/frontend/src/components/contracts/ContractList.tsx
+++ /dev/null
@@ -1,223 +0,0 @@
-import { useState } from "react";
-import type { ContractSummary, ContractStatus } from "../../lib/api";
-import { PhaseBadge } from "./PhaseBadge";
-import { PhaseProgressBarCompact } from "./PhaseProgressBar";
-import { ContractContextMenu } from "./ContractContextMenu";
-
-interface ContractListProps {
-  contracts: ContractSummary[];
-  loading: boolean;
-  onSelect: (id: string) => void;
-  onCreate: () => void;
-  selectedId?: string;
-  onMarkComplete?: (contract: ContractSummary) => void;
-  onMarkActive?: (contract: ContractSummary) => void;
-  onArchive?: (contract: ContractSummary) => void;
-  onDelete?: (contract: ContractSummary) => void;
-  onGoToSupervisor?: (contract: ContractSummary) => void;
-}
-
-const statusColors: Record<ContractStatus, string> = {
-  active: "text-green-400",
-  completed: "text-blue-400",
-  archived: "text-[#555]",
-};
-
-export function ContractList({
-  contracts,
-  loading,
-  onSelect,
-  onCreate,
-  selectedId,
-  onMarkComplete,
-  onMarkActive,
-  onArchive,
-  onDelete,
-  onGoToSupervisor,
-}: ContractListProps) {
-  const [filter, setFilter] = useState<ContractStatus | "all">("all");
-  const [contextMenuPosition, setContextMenuPosition] = useState<{ x: number; y: number } | null>(null);
-  const [contextMenuContract, setContextMenuContract] = useState<ContractSummary | null>(null);
-
-  const handleContextMenu = (e: React.MouseEvent, contract: ContractSummary) => {
-    e.preventDefault();
-    setContextMenuPosition({ x: e.clientX, y: e.clientY });
-    setContextMenuContract(contract);
-  };
-
-  const closeContextMenu = () => {
-    setContextMenuPosition(null);
-    setContextMenuContract(null);
-  };
-
-  const filteredContracts =
-    filter === "all"
-      ? contracts
-      : contracts.filter((c) => c.status === filter);
-
-  if (loading) {
-    return (
-      <div className="panel h-full flex items-center justify-center">
-        <div className="font-mono text-[#9bc3ff] text-sm">Loading...</div>
-      </div>
-    );
-  }
-
-  return (
-    <div className="panel h-full flex flex-col min-h-0">
-      {/* Header */}
-      <div className="p-4 border-b border-dashed border-[rgba(117,170,252,0.35)]">
-        <div className="flex items-center justify-between mb-3">
-          <h2 className="font-mono text-sm text-[#75aafc] uppercase tracking-wider">
-            Contracts
-          </h2>
-          <button
-            onClick={onCreate}
-            className="px-3 py-1.5 font-mono text-xs text-[#dbe7ff] bg-[#0f3c78] border border-[#3f6fb3] hover:bg-[#153667] transition-colors uppercase"
-          >
-            + New
-          </button>
-        </div>
-
-        {/* Filter tabs */}
-        <div className="flex gap-1">
-          {(["all", "active", "completed", "archived"] as const).map((status) => (
-            <button
-              key={status}
-              onClick={() => setFilter(status)}
-              className={`
-                px-2 py-1 font-mono text-[10px] uppercase tracking-wider transition-colors
-                ${
-                  filter === status
-                    ? "bg-[rgba(117,170,252,0.1)] text-[#9bc3ff] border border-[rgba(117,170,252,0.3)]"
-                    : "text-[#555] hover:text-[#75aafc]"
-                }
-              `}
-            >
-              {status}
-            </button>
-          ))}
-        </div>
-      </div>
-
-      {/* Contract list */}
-      <div className="flex-1 min-h-0 overflow-y-auto">
-        {filteredContracts.length === 0 ? (
-          <div className="p-4 text-center">
-            <p className="font-mono text-sm text-[#555]">
-              {filter === "all"
-                ? "No contracts yet"
-                : `No ${filter} contracts`}
-            </p>
-          </div>
-        ) : (
-          <div className="divide-y divide-[rgba(117,170,252,0.15)]">
-            {filteredContracts.map((contract) => (
-              <button
-                key={contract.id}
-                onClick={() => onSelect(contract.id)}
-                onContextMenu={(e) => handleContextMenu(e, contract)}
-                className={`
-                  w-full text-left p-4 transition-colors
-                  ${
-                    selectedId === contract.id
-                      ? "bg-[rgba(117,170,252,0.1)]"
-                      : "hover:bg-[rgba(117,170,252,0.05)]"
-                  }
-                `}
-              >
-                <div className="flex items-start justify-between gap-2 mb-2">
-                  <div className="flex items-center gap-2 min-w-0">
-                    <h3 className="font-mono text-sm text-[#dbe7ff] truncate">
-                      {contract.name}
-                    </h3>
-                    {contract.localOnly && (
-                      <span className="px-1.5 py-0.5 font-mono text-[9px] uppercase text-amber-400 border border-amber-400/30 bg-amber-400/10 shrink-0">
-                        Local
-                      </span>
-                    )}
-                  </div>
-                  <span
-                    className={`text-[10px] font-mono uppercase shrink-0 ${
-                      statusColors[contract.status]
-                    }`}
-                  >
-                    {contract.status}
-                  </span>
-                </div>
-
-                {contract.description && (
-                  <p className="font-mono text-xs text-[#555] mb-2 line-clamp-2">
-                    {contract.description}
-                  </p>
-                )}
-
-                <div className="flex items-center justify-between">
-                  <PhaseProgressBarCompact currentPhase={contract.phase} contractType={contract.contractType} />
-                  <div className="flex items-center gap-3 text-[10px] font-mono text-[#555]">
-                    {contract.fileCount > 0 && (
-                      <span>{contract.fileCount} files</span>
-                    )}
-                    {contract.taskCount > 0 && (
-                      <span>{contract.taskCount} tasks</span>
-                    )}
-                    {contract.repositoryCount > 0 && (
-                      <span>{contract.repositoryCount} repos</span>
-                    )}
-                  </div>
-                </div>
-              </button>
-            ))}
-          </div>
-        )}
-      </div>
-
-      {/* Context Menu */}
-      {contextMenuPosition && contextMenuContract && (
-        <ContractContextMenu
-          x={contextMenuPosition.x}
-          y={contextMenuPosition.y}
-          contract={contextMenuContract}
-          onClose={closeContextMenu}
-          onMarkComplete={() => onMarkComplete?.(contextMenuContract)}
-          onMarkActive={() => onMarkActive?.(contextMenuContract)}
-          onArchive={() => onArchive?.(contextMenuContract)}
-          onDelete={() => onDelete?.(contextMenuContract)}
-          onGoToSupervisor={() => onGoToSupervisor?.(contextMenuContract)}
-        />
-      )}
-    </div>
-  );
-}
-
-export function ContractCard({
-  contract,
-  onClick,
-}: {
-  contract: ContractSummary;
-  onClick: () => void;
-}) {
-  return (
-    <button
-      onClick={onClick}
-      className="w-full text-left p-4 border border-[rgba(117,170,252,0.2)] hover:border-[rgba(117,170,252,0.4)] transition-colors"
-    >
-      <div className="flex items-start justify-between gap-2 mb-2">
-        <h3 className="font-mono text-sm text-[#dbe7ff]">{contract.name}</h3>
-        <PhaseBadge phase={contract.phase} />
-      </div>
-
-      {contract.description && (
-        <p className="font-mono text-xs text-[#555] mb-3 line-clamp-2">
-          {contract.description}
-        </p>
-      )}
-
-      <div className="flex items-center gap-4 text-[10px] font-mono text-[#555]">
-        <span>{contract.fileCount} files</span>
-        <span>{contract.taskCount} tasks</span>
-        <span>{contract.repositoryCount} repos</span>
-      </div>
-    </button>
-  );
-}
-- 
cgit v1.2.3

