Skip to content

feat(opencode): agent-driven context editing with CAS, edit graph, and focus agent#1

Merged
e6qu merged 3 commits intodevfrom
feat/context-editing
Mar 15, 2026
Merged

feat(opencode): agent-driven context editing with CAS, edit graph, and focus agent#1
e6qu merged 3 commits intodevfrom
feat/context-editing

Conversation

@e6qu
Copy link
Copy Markdown
Owner

@e6qu e6qu commented Mar 15, 2026

Issue for this PR

N/A — founding feature for the Frankencode fork.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds agent-driven context editing to OpenCode. Agents can surgically edit their own conversation context — hiding stale tool output, replacing incorrect statements, externalizing verbose content to a content-addressable store — while preserving all original content in a git-like versioned DAG. A focus agent runs post-turn to keep conversations on-topic by parking side discoveries.

Components:

  • CAS (SQLite): cas_object table stores original content by SHA-256 hash. Atomic with part updates via Database.transaction().
  • Edit operations: hide, unhide, replace, annotate, externalize with ownership validation, budget enforcement (max 10/turn, 70% cap), recency protection (last 2 turns immutable).
  • Edit graph: edit_graph_node + edit_graph_head tables model edit history as a DAG with parent pointers, named branches, checkout, fork.
  • Focus agent: Hidden post-turn agent (temp 0, max 8 steps) that parks off-topic findings. Enabled via OPENCODE_EXPERIMENTAL_FOCUS_AGENT=1.
  • Side threads: Project-level side_thread table for deferred discoveries that survive across sessions.
  • Objective tracker: Extracts user's goal from first message, injected into system prompt.
  • Plugin hooks: context.edit.before / context.edit.after.
  • CI: Stripped to pre-merge only (test + typecheck on ubuntu-latest).

New tools: context_edit, context_deref, context_history, thread_park, thread_list

New files: 13 new files, 8 modified, ~1365 LOC. All paths under packages/opencode/src/.

How did you verify your code works?

  • All 1313 existing unit tests pass (bun test)
  • Typecheck passes (bun turbo typecheck — all 13 packages)
  • CI green (test + typecheck)

Screenshots / recordings

N/A — backend/tooling change, no UI modifications.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

A fork of anomalyco/opencode that adds surgical, reversible context
editing with content-addressable storage and a conversation history graph.

New capabilities:
- CAS (SQLite): content-addressable store preserving original content
- Edit operations: hide, unhide, replace, annotate, externalize
- Edit graph: DAG of edit versions with branching and checkout
- Focus agent: hidden post-turn agent that parks off-topic side threads
- Side threads: project-level deferred findings (SQLite)
- Objective tracker: extracts and tracks the user's goal
- Tools: context_edit, context_deref, context_history, thread_park, thread_list
- Plugin hooks: context.edit.before / context.edit.after
- CI: stripped to test + typecheck on ubuntu-latest (no third-party runners)

13 new files, 8 modified files, ~1365 lines of new code.
All 1310 existing tests pass.
- Use SessionID.make(), MessageID.make(), PartID.ascending() instead of
  plain strings for branded type safety
- Add context.edit.before/after hooks to plugin Hooks interface
- Wire Plugin.trigger() calls in context-edit operations
Repository owner deleted a comment from github-actions bot Mar 15, 2026
@e6qu e6qu changed the title feat: agent-driven context editing with CAS, edit graph, and focus agent Frankencode: agent-driven context editing with CAS, edit graph, and focus agent Mar 15, 2026
@e6qu e6qu changed the title Frankencode: agent-driven context editing with CAS, edit graph, and focus agent feat(opencode): agent-driven context editing with CAS, edit graph, and focus agent Mar 15, 2026
Repository owner deleted a comment from github-actions bot Mar 15, 2026
Repository owner deleted a comment from github-actions bot Mar 15, 2026
@e6qu e6qu merged commit 9bac4ab into dev Mar 15, 2026
4 checks passed
@e6qu e6qu deleted the feat/context-editing branch March 15, 2026 13:44
e6qu added a commit that referenced this pull request Mar 18, 2026
…d focus agent (#1)

* feat: Frankencode — agent-driven context editing on top of OpenCode

A fork of anomalyco/opencode that adds surgical, reversible context
editing with content-addressable storage and a conversation history graph.

New capabilities:
- CAS (SQLite): content-addressable store preserving original content
- Edit operations: hide, unhide, replace, annotate, externalize
- Edit graph: DAG of edit versions with branching and checkout
- Focus agent: hidden post-turn agent that parks off-topic side threads
- Side threads: project-level deferred findings (SQLite)
- Objective tracker: extracts and tracks the user's goal
- Tools: context_edit, context_deref, context_history, thread_park, thread_list
- Plugin hooks: context.edit.before / context.edit.after
- CI: stripped to test + typecheck on ubuntu-latest (no third-party runners)

13 new files, 8 modified files, ~1365 lines of new code.
All 1310 existing tests pass.

* fix: type safety for branded IDs and plugin hooks

- Use SessionID.make(), MessageID.make(), PartID.ascending() instead of
  plain strings for branded type safety
- Add context.edit.before/after hooks to plugin Hooks interface
- Wire Plugin.trigger() calls in context-edit operations

* ci: add pre-commit hooks for typecheck, tests, and conventional commits

---------

Co-authored-by: Adrian Mârza <adi11235 at gmail dot com>
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