Skip to content

feat(harness): agentic coding core (Phase 1) - #102

Merged
mlubbad merged 40 commits into
mainfrom
feat/harness
Jul 21, 2026
Merged

mlubbad merged 40 commits into
mainfrom
feat/harness

Conversation

@mlubbad

@mlubbad mlubbad commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Harness v1 — agentic coding core (Phase 1)

Attach a chat to a local folder and the agent becomes a Claude-Code-style coding agent scoped to that folder, layered on the existing multi-provider run_turn loop (no rewrite, no new provider dependency). This is Phase 1 of the design in docs/superpowers/specs/2026-07-20-harness-design.md; the roadmap (P2–P4: hooks, subagents, memory hierarchy, sandbox/ACP) is tracked there.

What's in it

Backend — new backend/ocd_core/harness/ package + additive wiring into run_turn:

  • Path jail (workspace_fs.resolve_in_workspace) — symlink/junction-safe, defeats ..-traversal, sibling-prefix roots (C:\ws vs C:\ws2), and absolute-path escapes on both Windows and POSIX.
  • File tools — read_file (numbered, offset/limit), edit_file (unique-old_string guard + read-before-edit + unified diff), write_file (read-before-overwrite), glob, grep (jailed, bounded).
  • Permission engine (rules.py) — modes default/acceptEdits/plan/strict/bypass (+ legacy auto/ask aliases) and allow/deny/ask rules (bash(git *), precedence deny > ask > allow > mode). Reads a workspace's .claude/settings.json permissions. Mode-independent catastrophic-bash breaker (rm -rf /, fork bombs, mkfs, disk-device writes).
  • Checkpoints & rewind — files snapshotted before each edit; per-message file restore. Checkpoints are workspace-bound (manifest stamps its owner; restore/list verify it), so one folder can never restore into another.
  • Plan tool + env-context assembly (platform, git state, file map — git-optional).
  • Workspace registry + /harness/workspaces routes (CRUD, rules, checkpoint list/restore).

Desktop — AgentEvent union extensions + WorkspaceBar, ToolTimeline, FileDiffCard, PlanCard, RewindMenu, the restoreCheckpoint client, and chat wiring (each message stamped with its workspace so rewind targets the right folder; workspace_detached banner).

Safety posture (integration with existing gates)

  • The mode/rule gate governs only the harness tools (file suite + task_plan + bash); pre-existing sensitive built-ins (code_execution, authenticate, memory mutations) keep their existing HITL prompt. bypass auto-runs the coding tools (minus the breaker) but a sensitive built-in still prompts — only legacy auto turns the gate fully off. (A deliberate, safety-positive deviation from the spec's "bypass = auto", recorded in spec §14.)
  • Protected paths (.env, *.pem, id_*) stay write-gated even in acceptEdits.
  • Unknown/stale workspace_id degrades to a normal folderless chat and emits a workspace_detached event + workspace_attach_failed audit — the model never silently over-claims folder access.
  • Non-workspace chats are byte-for-byte unchanged (every new path guarded by workspace_root/ws).

Honest scope note

bash still runs in the existing read-only sandbox (SANDBOX_ROOT), not the attached folder — running commands/tests in the workspace is a deliberate fast-follow (needs a jailed workspace cwd + a broader gated allowlist, adjacent to the P4 container runner). The file tools cover the core edit/search loop. Other deferrals (in spec §14): checkpoint FIFO pruning, glob/grep walk-then-filter perf on large .git/node_modules.

Testing

  • Backend: 124 harness + integration tests (jail adversarial suite incl. junctions/8.3/symlinks; rules precedence; checkpoint round-trip + cross-workspace binding; loop-level edit→diff→checkpoint; the HITL regression suite stayed green throughout).
  • Desktop: 379 vitest tests + typecheck + build.
  • Full-repo ruff clean (CI-pinned 0.15.22).

Process

Built subagent-driven with two-stage (spec + code-quality) review per task. Reviews caught and fixed, before merge: three jail escapes, a silent grep count bug, an acceptEdits auto-git push, a Critical bypass-mode HITL skip for sensitive built-ins, a Critical cross-workspace checkpoint overwrite, an unenforced protected-paths gap, and a desktop transcript regression that dropped the rewind UI. Plan + as-built notes: docs/superpowers/plans/2026-07-20-harness-phase1.md.

🤖 Generated with Claude Code

mlubbad and others added 30 commits July 21, 2026 13:18
Approved design for Claude-Code-style harness support: workspace file tool
suite behind a path jail, permission modes + allow/deny/ask rules layered on
the existing HITL gate, checkpoints/rewind, model-driven plan tool, env
context assembly, ACP-shaped SSE events, and a tracked P2-P4 parity roadmap
(hooks, subagents, compaction/memory, sandbox/ACP).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
22 TDD tasks implementing Harness P1 from the approved spec: harness package,
Windows-safe path jail, file tool suite (read/edit/write/glob/grep), permission
modes + allow/deny/ask rules (+ .claude/settings.json import + registry merge),
per-turn checkpoints/restore, task_plan tool, env-context builder, workspace
registry + routes, run_turn integration, and desktop UI (workspace bar, tool
timeline, diff/plan cards, rewind). Documents the Windows-local test baseline.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Match the plan's jail code to the shipped fix (resolve(strict=False), no
lstrip, `from None`) + the new regression test, after code review found two
POSIX escapes in the first draft.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Match the plan's glob() to the shipped fix (try/except on Path.glob +
resolve-then-relative_to jail per hit) + 3 escape tests, after spec review
found ../ pattern traversal and an absolute-pattern crash.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…low-up

Consolidated note of the glob/grep/edit/read fixes from two-stage review
(commits 2e27af8, fc134cb) and the deferred walk-then-filter scalability
fast-follow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…eaker requirement

Note the acceptEdits git push/reset auto-approval fix (a557ac8) and add a
REQUIRED safety note to Task 14: a gate `allow` for bash must still hit the
catastrophic-command circuit breaker (bash args are not jailed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…layout

Record the reliability fixes (5409c8e) and fix the checkpoint path so the
store root is turn-agnostic (checkpoints/<turn_id>/manifest.json), removing
the double-nesting both implementers flagged for Task 14/17.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…sk 14b breaker

Env context appends to extra_sections (not a system var); tools/gate/events
anchored to verified agent.py locations; events via _completion_events + drain
loop; ws context dict threaded to _run_one_tool. Split the catastrophic-bash
circuit breaker into Task 14b (no existing breaker to reuse).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
run_turn gains workspace_root/workspace_rules: when set, the five file
tools + task_plan are registered, an env-context section is appended to
the system prompt, and a merged permission ruleset (workspace_rules +
.claude/settings.json) is built into a per-turn `ws` context threaded
through _run_one_tool (dispatch + per-edit checkpoint snapshot) and the
tool-call loop's gate.

The harness rule gate runs BEFORE the existing HITL gate, guarded by
`if workspace_root:` so non-workspace turns are byte-for-byte unchanged:
deny -> tool_error + blocked_outcome (skip_breaker) + continue; allow ->
calls.append + continue (skips the HITL prompt); ask -> falls through to
the existing permissions.requires_approval check untouched.

_completion_events gains tool_call/file_diff/plan_update for the six
harness tool names; a checkpoint event fires after a successful
edit_file/write_file. Checkpoints live under config.REPO_ROOT/checkpoints
(gitignored, same pattern as projects/ and knowledge/).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…s HITL skip) + checkpoint id

Code review (empirically verified) found the Task 14 gate insertion had
no tool-name filter: `if workspace_root:` applied rules.gate() to EVERY
tool call, not just the 5 file tools + task_plan. rules.gate's mode
defaults are calibrated for that set only:

- CRITICAL: in "bypass" mode, gate() returns "allow" unconditionally for
  ANY tool name, so a workspace turn in bypass mode skipped the existing
  HITL prompt for sensitive built-ins (code_execution, authenticate,
  memory mutations). Reproduced concretely: code_execution ran for real
  via the docker engine with zero approval. Task 15 exposes "bypass"
  publicly, so this had to land first.
- Also: "plan" mode hard-denied safe non-file tools like web_search
  instead of falling through to the existing (already-correct) fails-
  closed HITL handling for unrecognized modes.

Fix: scope the gate to `_wfs.FILE_TOOL_NAMES | {"task_plan", "bash"}` —
the set rules.py's mode/rule engine actually governs. Every other tool
name now falls straight through to the existing HITL gate, unchanged.

Also fixes the checkpoint event emitting the raw `turn_id` instead of
`ws["ckpt_turn"]` (turn_id or "adhoc") — they can diverge when turn_id
is falsy, which would point the Task 17 restore route at a checkpoint
id that was never written.

Two new regression tests in test_agent_workspace.py exercise both bugs
end-to-end through run_turn (code_exec=True / web_search=True are
required on the run_turn() calls — without them the H6 "tool not
enabled" check intercepts the call before it ever reaches the gate
under test, which was verified empirically while writing these).

Plan doc: recorded the Task 14b/Task 15 ordering dependency this fix
creates (Task 15 must not land before this + the bash circuit breaker).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mlubbad and others added 10 commits July 21, 2026 13:18
…ontract, bypass semantics)

/harness/workspaces prefix (tenancy owns /workspaces); case-insensitive
canonical permission modes with un-aliased legacy literals; deliberate
safety-positive bypass semantics (built-ins still prompt) to be recorded in
the spec at Task 22.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ly restore, detach banner)

Match the desktop plan to the shipped route fixes (8aaa79c): restoreCheckpoint
uses /harness/workspaces, RewindMenu offers file restore only (conversation
deferred), and render the workspace_detached banner.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds the five harness SSE events (tool_call, file_diff, plan_update,
checkpoint, workspace_detached) as members of the existing AgentEvent
discriminated union (events.ts), and WorkspaceBar: folder name +
permission-mode selector + detach, for the composer.
ToolTimeline (condensed harness tool-call list), FileDiffCard
(unified diff with add/del/context line styling), and PlanCard
(task_plan's current plan, latest plan_update wins) -- the three
harness activity renderers, independently unit-tested.
Wire WorkspaceBar into the composer, render tool timeline / file diffs / plan
card / rewind from a message''s accumulated harness events, add the
workspace_detached banner, and the restoreCheckpoint client method
(/harness/workspaces prefix, file restore only). Full desktop gate green
(typecheck + 365 tests + build).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ewind workspace (review)

Four transcript reducers rebuilt assistant messages as narrow {role,blocks}
literals, silently dropping toolCalls/fileDiffs/planItems/checkpointTurnId (the
RewindMenu/diffs vanished after an artifact/approval/question on the same
message) — now spread ...m. Each assistant message records its workspaceId so
rewind restores the folder the message was produced under, not a stale closure.
Plus ToolTimeline/PlanCard sr-only status for a11y and a stale Composer comment.
Desktop gate green (typecheck + 379 tests + build).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…uilt deltas

README gains a "Harness (code workspaces)" section; the spec marks P1 shipped and
records the review-hardened as-built deltas (safety-scoped bypass, catastrophic-bash
breaker, enforced protected paths, /harness routes, workspace-bound checkpoints,
file-only rewind) and the deliberate deferrals (workspace-cwd bash, FIFO pruning).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mlubbad
mlubbad merged commit ee1ac9b into main Jul 21, 2026
6 checks passed
@mlubbad
mlubbad deleted the feat/harness branch July 21, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant