Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xsline OpenChatCut OfflineExternalEditRuntime

From Leeroopedia
Knowledge Sources
Domains Editing, Concurrency, Agent
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete runtime for managing atomic, revision-checked, undoable edit sessions that let external agents (CLI, MCP) modify a project without holding a long-lived lock.

Description

The OfflineExternalEditRuntime class provides the full lifecycle of an offline edit session: it claims project ownership, creates a draft fork, dispatches editor tools against the draft, and atomically commits or discards the result. It enforces:

  • Revision checking: The session's base revision is compared against the store at commit time (compare-and-swap).
  • Draft isolation: All tool operations act on a forked draft; the shared document is untouched until review.
  • Ownership: A project ownership claim is held while the session lives, blocking concurrent browser edits.
  • Checkpoint persistence: Drafts are checkpointed so a crashed session can resume.
  • Auto-approval only: Offline sessions require `approvalMode="auto"` — manual review needs the browser editor.

The runtime is used by both the CLI (`occ` command) and the MCP external-agent bridge, sharing the exact same editing contract.

Usage

  • CLI editing: `occ` uses `runToolSession` which wraps this runtime to apply or dry-run tool invocations.
  • MCP agent editing: The MCP external-agent bridge calls `execute()` directly to run tools over the streamable HTTP transport.
  • Draft-safe reads: Call `execute('get_edit_session', { editSessionId })` to inspect session state without committing.

Code Reference

Source Location

  • Repository: OpenChatCut
  • File: server/external-agent/offline-runtime.ts

Signature

export class OfflineExternalEditRuntime {
  static async create(
    projectId: string,
    editorUrl: string,
    dependencies?: OfflineRuntimeDependencies,
  ): Promise<OfflineExternalEditRuntime>;

  async execute(
    name: string,
    rawArgs: Record<string, unknown>,
  ): Promise<unknown>;

  async dispose(): Promise<void>;

  binding(): OfflineEditorBinding;
  async validateAvailability(): Promise<void>;
}

Import

import { OfflineExternalEditRuntime } from '../server/external-agent/offline-runtime.ts';

I/O Contract

Inputs

Name Type Required Description
projectId string Yes Target project ID to edit
editorUrl string Yes Editor URL for session binding and error messages
dependencies OfflineRuntimeDependencies No Optional overrides for persistence, browser-connection check, and executor
name string Yes Tool name to execute (e.g. `begin_edit_session`, `review_edit_session`, `discard_edit_session`, or any headless editor tool)
rawArgs Record<string, unknown> Yes Tool arguments, must include `editSessionId` for session-scoped tools

Outputs

Name Type Description
create() returns OfflineExternalEditRuntime Runtime instance with claimed ownership
execute('begin_edit_session') returns Record<string, unknown> Session info including `editSessionId`, `status`, `resumed`
execute('review_edit_session') returns Record<string, unknown> Applied commit info with new revision, or rejection error
execute('discard_edit_session') returns Record<string, unknown> Cancelled session info
execute(tool) returns unknown Tool execution result with checkpointed outcome
dispose() returns void Releases ownership and fails active sessions

Usage Examples

Basic CLI Session

import { OfflineExternalEditRuntime } from '../server/external-agent/offline-runtime.ts';

// 1. Create runtime and claim ownership
const runtime = await OfflineExternalEditRuntime.create(
  'my-project-id',
  'http://localhost:5199/#/editor/my-project-id',
);

try {
  // 2. Begin an edit session (auto-approval required for offline)
  const begun = await runtime.execute('begin_edit_session', {
    clientName: 'my-agent',
    approvalMode: 'auto',
  }) as { editSessionId: string };

  // 3. Run editor tools against the draft
  await runtime.execute('import_media', {
    editSessionId: begun.editSessionId,
    path: '/path/to/video.mp4',
  });

  // 4. Review and commit atomically
  const result = await runtime.execute('review_edit_session', {
    editSessionId: begun.editSessionId,
    summary: 'Imported video clip',
  });
  console.log('Committed:', result);
} finally {
  // 5. Always release ownership
  await runtime.dispose();
}

Dry-Run (Discard)

// Run tools but discard the draft — project stays byte-identical
const runtime = await OfflineExternalEditRuntime.create(projectId, editorUrl);
try {
  const begun = await runtime.execute('begin_edit_session', {
    clientName: 'preview',
    approvalMode: 'auto',
  });
  await runtime.execute('some_tool', { editSessionId: begun.editSessionId, ... });
  // Discard instead of review
  await runtime.execute('discard_edit_session', { editSessionId: begun.editSessionId });
} finally {
  await runtime.dispose();
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment