skip to content
$worker

editor

v0.1.8

A shared code workspace — open buffers, a file tree, unified diffs, fuzzy find and conflict-safe saves that an agent and a person see the same view of, plus a console editor page.

iiiverified
35 installs9 in 7d0 today
install
$iii worker add editor
binarylicense: Apache-2.0editordiffgitcodereview
  • macOS: arm64 · x64
  • Linux: arm64 · armv7 · x64
  • Windows: arm64 · x64 · x86

exact versions are immutable; binary and bundle artifacts are digest-pinned.

functions

24

editor::buffers::close

function

Close one open buffer. The file on disk is untouched.

request
  • pathstringrequired

    Root-relative path of the buffer to close.

response
  • buffersobject[]required
    • languagestringrequired

      Monaco language id for the path.

    • mtimeinteger· int64required

      Last-modified time this buffer was read at, Unix seconds.

    • pathstringrequired

      Path relative to the workspace root.

    • versionstring

      Opaque version of the content this buffer was read at — the same fact `mtime` carries, in the form that survives two writes inside one second. A surface saves against it by sending it as `expected_version`. Defaulted so a session persisted before this field existed still loads. Empty means "unknown": a surface holding an empty version has only the mtime to save against, which is the behaviour it had all along.

  • closedbooleanrequired

    False when nothing was open at that path.

  • rootstringrequired

editor::buffers::list

function

Files currently open in the workspace.

request
empty object
response
  • buffersobject[]required
    • languagestringrequired

      Monaco language id for the path.

    • mtimeinteger· int64required

      Last-modified time this buffer was read at, Unix seconds.

    • pathstringrequired

      Path relative to the workspace root.

    • versionstring

      Opaque version of the content this buffer was read at — the same fact `mtime` carries, in the form that survives two writes inside one second. A surface saves against it by sending it as `expected_version`. Defaulted so a session persisted before this field existed still loads. Empty means "unknown": a surface holding an empty version has only the mtime to save against, which is the behaviour it had all along.

  • rootstringrequired

editor::changes

function

Recent file changes in the workspace, newest first, one entry per path. Recorded by the observer for every change however it was made, so it answers what happened while nothing was watching. Each entry carries the patch, the line counts, the function that performed the write, and the harness session and turn it happened in.

request
empty object
response
  • changesobject[]required

    Newest first, one entry per path.

    • addedinteger· uint32requiredmin 0
    • causestringrequired

      Function that performed the write, e.g. `shell::fs::write`.

    • kindstringrequired

      `created`, `modified`, `deleted`, or `moved`.

    • patchstring

      Unified patch for the change, empty when there was nothing to compare.

    • pathstringrequired

      Path relative to the workspace root the change was recorded against.

    • removedinteger· uint32requiredmin 0
    • rootstring
    • session_idstring

      The harness session and turn the write happened in, absent when it happened outside a turn.

    • truncatedboolean
    • turn_idstring

editor::create

function

Create a file or folder in the workspace, with parents as needed. A file may be seeded with content.

request
  • contentstring

    Initial contents for a file. Ignored for a folder.

  • kindall of

    What to create. Defaults to a file.

    all of (1)
    variant 1
    valuestringenum: file, folder
  • pathstringrequired

    Root-relative path to create. Missing parent folders are created.

response
  • createdbooleanrequired

    Always true on success; the call errors rather than reporting false.

  • kindstringrequiredenum: file, folder

    Create a file or a folder.

  • pathstringrequired

editor::delete

function

Remove a path and close any buffer it held. An open buffer for a deleted file would recreate it on the next save.

request
  • pathstringrequired

    Root-relative path to remove.

  • recursiveboolean

    Required to remove a non-empty folder.

response
  • buffersobject[]required
    • languagestringrequired

      Monaco language id for the path.

    • mtimeinteger· int64required

      Last-modified time this buffer was read at, Unix seconds.

    • pathstringrequired

      Path relative to the workspace root.

    • versionstring

      Opaque version of the content this buffer was read at — the same fact `mtime` carries, in the form that survives two writes inside one second. A surface saves against it by sending it as `expected_version`. Defaulted so a session persisted before this field existed still loads. Empty means "unknown": a surface holding an empty version has only the mtime to save against, which is the behaviour it had all along.

  • buffers_closedstring[]required

    Buffers closed because their file is gone. Leaving them open would let the next save recreate a file the user just deleted.

  • deletedbooleanrequired
  • pathstringrequired

editor::diff

function

Unified diff between two texts. Pure: nothing is read from disk. Use it to show what an edit will do before writing it, or to explain what a write did.

request
  • afterstringrequired

    The text as it will be.

  • beforestringrequired

    The text as it was.

  • context_linesinteger· uint32min 0

    Unchanged lines kept around each hunk (`-U` of `git diff`). Defaults to the worker's `diff_context_lines`.

  • pathstring

    Path used to label the patch header. Nothing is read from disk — this is presentation only.

response
  • addedinteger· uint32requiredmin 0

    Total lines added across every hunk.

  • hunksobject[]required

    One entry per `@@` block, in file order.

    • addedinteger· uint32requiredmin 0

      Lines added within this hunk.

    • new_linesinteger· uint32requiredmin 0

      Number of "after" lines the hunk spans.

    • new_startinteger· uint32requiredmin 0

      First line of the hunk on the "after" side, 1-based.

    • old_linesinteger· uint32requiredmin 0

      Number of "before" lines the hunk spans.

    • old_startinteger· uint32requiredmin 0

      First line of the hunk on the "before" side, 1-based. `0` when the before side is empty (pure addition), matching unified-diff convention.

    • removedinteger· uint32requiredmin 0

      Lines removed within this hunk.

  • identicalbooleanrequired

    True when `before` and `after` are byte-identical.

  • patchstringrequired

    Unified diff. Empty when the two sides are identical.

  • removedinteger· uint32requiredmin 0

    Total lines removed across every hunk.

  • truncatedbooleanrequired

    True when either side exceeded `max_bytes` and the diff was skipped. `patch` and `hunks` are empty in that case — a caller that ignores this flag would read "no changes" from a file that was simply too big.

editor::find

function

Fuzzy file finder over the workspace, ranked the way an editor's open-file palette ranks. Candidates come from git when the root is a repository and from the folder listing when it is not.

request
  • include_untrackedboolean

    Include files git does not track yet (still honouring `.gitignore`). On by default — a file the agent just created is exactly the one you are looking for. Ignored outside a repository, where the workspace listing is the source of candidates.

  • limitinteger· uint32min 0

    Rows to return. Defaults to the worker's `find_limit`.

  • querystringrequired

    Fuzzy query. Matched as a subsequence against every tracked path, with basename and word-boundary hits ranked highest. Empty returns the first `limit` paths unranked.

response
  • from_gitbooleanrequired

    True when candidates came from git's listing (so `.gitignore` was honoured), false when they came from the folder walk.

  • matchesobject[]required
    • pathstringrequired
    • positionsinteger[]· uint32requiredmin 0

      Byte offsets into `path` that matched, in order — enough to highlight the match without re-running the matcher in the UI.

    • scoreinteger· int32required

      Higher is better. Comparable only within one response.

  • scannedinteger· uint32requiredmin 0

    Paths considered. Compare against `truncated` to know whether the whole repo was ranked.

  • truncatedbooleanrequired

    True when not every path in the workspace was ranked: it held more than `max_find_candidates`, or the folder walk stopped at its visit budget. Either way this ranking is over a prefix of the workspace.

editor::git::commit

function

Stage and commit. Returns the new SHA, or committed:false when there was nothing staged.

request
  • cwdstring

    Repository to run in. Defaults to the workspace root.

  • messagestringrequired

    Commit message. Passed as a single `-m` argument.

  • stage_allboolean

    Stage every change first (`git add -A`). On by default, matching what an editor's commit command does; pass false to commit only the index.

response
  • committedbooleanrequired

    False when there was nothing staged to commit.

  • shastring

    Full SHA of the new commit, when one was made.

  • summarystringrequired

    git's own summary line, verbatim.

editor::git::hunks

function

What changed in one file: the rendered patch plus its line ranges. Compares the working tree against the index, the index against HEAD, or the working tree against HEAD — so it shows an edit made by anything, including an agent that never called this worker.

request
  • againstall of

    Which comparison to make. Defaults to `worktree`.

    all of (1)
    variant 1
    one of (4)
    variant 1
    valuestringenum: worktree
    variant 2
    valuestringenum: index
    variant 3
    valuestringenum: head
    variant 4
    valuestringenum: upstream
  • context_linesinteger· uint32min 0

    Unchanged lines kept around each hunk in `patch`. Defaults to 0, which keeps `hunks` exactly the lines that changed — the ranges a gutter paints. Pass 3 or so for a patch a person will read, and note that the reported ranges widen to include the context you asked for.

  • cwdstring

    Directory to run git in. Defaults to the workspace root.

  • pathstringrequired

    Repository-relative path to inspect.

response
  • addedinteger· uint32requiredmin 0
  • againstall ofrequired

    Echo of the comparison performed, so a cached response is self-describing.

    all of (1)
    variant 1
    one of (4)
    variant 1
    valuestringenum: worktree
    variant 2
    valuestringenum: index
    variant 3
    valuestringenum: head
    variant 4
    valuestringenum: upstream
  • hunksobject[]required

    Changed ranges, in file order. Empty when the file matches.

    • addedinteger· uint32requiredmin 0

      Lines added within this hunk.

    • new_linesinteger· uint32requiredmin 0

      Number of "after" lines the hunk spans.

    • new_startinteger· uint32requiredmin 0

      First line of the hunk on the "after" side, 1-based.

    • old_linesinteger· uint32requiredmin 0

      Number of "before" lines the hunk spans.

    • old_startinteger· uint32requiredmin 0

      First line of the hunk on the "before" side, 1-based. `0` when the before side is empty (pure addition), matching unified-diff convention.

    • removedinteger· uint32requiredmin 0

      Lines removed within this hunk.

  • patchstringrequired

    The rendered unified patch, for showing a person what changed. Empty when there is no difference, and capped by `max_diff_bytes` — a caller that only wants the ranges can ignore it.

  • pathstringrequired
  • removedinteger· uint32requiredmin 0
  • untrackedbooleanrequired

    True when git reports the path as untracked, in which case there is nothing to compare against and `hunks` is empty.

editor::git::show

function

Read a file's contents at a revision (HEAD by default). Pair it with the working copy to render a real side-by-side or unified diff, rather than parsing a patch.

request
  • cwdstring

    Repository to run in. Defaults to the workspace root.

  • pathstringrequired

    Root-relative path.

  • revstring

    Revision to read the file at. Defaults to `HEAD`.

response
  • contentstringrequired

    The file's contents at that revision. Empty when the path did not exist there — which is what `exists: false` distinguishes from an empty file.

  • existsbooleanrequired

    False when the path is absent at that revision (a file being added).

  • pathstringrequired
  • revstringrequired

editor::git::stash

function

Stash the working tree, or pop the most recent stash.

request
  • actionall ofrequired

    Stash the working tree, or restore the most recent stash.

    all of (1)
    variant 1
    valuestringenum: push, pop
  • cwdstring

    Repository to run in. Defaults to the workspace root.

response
  • actionstringrequiredenum: push, pop
  • okbooleanrequired
  • summarystringrequired

editor::git::status

function

Working-tree status as typed rows: branch, upstream, ahead/behind, and one entry per changed path. Fails when the root is not a repository — that is an absent overlay, not a broken workspace.

request
  • cwdstring

    Directory to run git in. Defaults to the workspace root. Confined by shell's jail exactly like any other `shell::exec` call.

response
  • aheadinteger· uint32requiredmin 0

    Commits on this branch the upstream does not have.

  • behindinteger· uint32requiredmin 0

    Commits on the upstream this branch does not have.

  • branchstring

    Current branch, or `None` on a detached HEAD.

  • cleanbooleanrequired

    True when nothing is modified, staged, or untracked.

  • entriesobject[]required

    One row per changed path, in git's order.

    • indexstringrequired

      Status of the staged copy: `modified`, `added`, `deleted`, `renamed`, `copied`, `untracked`, `ignored`, `conflicted`, or `unchanged`.

    • pathstringrequired

      Path relative to the repository root.

    • renamed_fromstring

      Original path for a rename or copy.

    • stagedbooleanrequired

      True when the staged copy differs from HEAD.

    • worktreestringrequired

      Status of the working-tree copy, same vocabulary as `index`.

  • upstreamstring

    Configured upstream, e.g. `origin/main`.

editor::git::sync

function

Fetch, fast-forward pull, or push. Pull is --ff-only on purpose: a merge under open buffers is how an editor ends up showing a conflicted tree it never asked for.

request
  • actionall ofrequired

    Which remote operation to run.

    all of (1)
    variant 1
    one of (2)
    variant 1
    valuestringenum: fetch, push
    variant 2
    valuestringenum: pull
  • cwdstring

    Repository to run in. Defaults to the workspace root.

response
  • actionone ofrequired

    Which remote operation to run.

    one of (2)
    variant 1
    valuestringenum: fetch, push
    variant 2
    valuestringenum: pull
  • aheadinteger· uint32requiredmin 0

    Ahead/behind after the operation, so a caller does not need a second round trip to find out whether it changed anything.

  • behindinteger· uint32requiredmin 0
  • okbooleanrequired
  • summarystringrequired

    git's output, trimmed. Both streams: git reports progress on stderr.

editor::git::undo-commit

function

Undo the last commit, keeping its changes staged (reset --soft HEAD~1). Returns the SHA and message that were undone.

request
  • cwdstring

    Repository to run in. Defaults to the workspace root.

response
  • messagestringrequired

    Its message, so a caller can put it straight back in a commit box.

  • undone_shastringrequired

    SHA that was undone.

editor::move

function

Move or rename a path and rewrite every open buffer and expanded folder at or under it. Moving a folder with `shell::fs::mv` alone leaves buffers pointing at the old location, which silently recreates it on the next save.

request
  • fromstringrequired

    Existing root-relative path.

  • tostringrequired

    Destination root-relative path.

response
  • buffersobject[]required
    • languagestringrequired

      Monaco language id for the path.

    • mtimeinteger· int64required

      Last-modified time this buffer was read at, Unix seconds.

    • pathstringrequired

      Path relative to the workspace root.

    • versionstring

      Opaque version of the content this buffer was read at — the same fact `mtime` carries, in the form that survives two writes inside one second. A surface saves against it by sending it as `expected_version`. Defaulted so a session persisted before this field existed still loads. Empty means "unknown": a surface holding an empty version has only the mtime to save against, which is the behaviour it had all along.

  • fromstringrequired
  • remappedinteger· uint32requiredmin 0

    Open buffers and expanded folders rewritten to the new location. A folder move rewrites everything beneath it, which is the whole reason moves go through this function instead of `shell::fs::mv` directly.

  • rootstringrequired
  • tostringrequired

editor::on-config-change

function

Internal: hot-reload the editor's limits from the authoritative configuration when it changes.

request
  • idstring

    Configuration id that changed (advisory; the handler re-fetches).

response
  • okbooleanrequired

editor::on-file-change

function

Internal: turns a filesystem call made by anything into an editor::changed event. Observes only — always continues.

request
  • callany of
    any of (2)
    variant 1
    • argumentsunknown
    • function_idstringrequired
    variant 2
    valuenull
  • metadataunknown
  • resultany of

    Outcome of the call this hook is reporting on. A write that failed did not change anything, and the hook fires either way.

    any of (2)
    variant 1
    • is_errorboolean
    variant 2
    valuenull
  • session_idstring
  • turn_idstring
response
  • decisionstringrequired

editor::open

function

Read a text file and record it as an open buffer, with the metadata needed to write it back safely: its language id, and the mtime and content version to hand to editor::save.

request
  • pathstringrequired

    Jail-relative when `shell`'s `fs.host_roots` are set, else absolute — the same path vocabulary as `shell::fs::read`.

response
  • contentstringrequired

    File contents as text. Binary files are refused rather than mangled.

  • languagestringrequired

    Monaco language id for the path, e.g. `rust`, `typescript`, `plaintext`.

  • mtimeinteger· int64required

    Last-modified time, Unix seconds. Pass it back as `expected_mtime` on `editor::save` to get the conflict guard.

  • pathstringrequired
  • sizeinteger· uint64requiredmin 0
  • truncatedbooleanrequired

    True when the file exceeded `max_file_bytes` and `content` holds only its beginning. Saving a truncated buffer back would delete the rest of the file, so `editor::save` refuses one.

  • versionstringrequired

    Opaque version of the `content` above. Pass it back as `expected_version` on `editor::save` for a guard that does not depend on the filesystem's timestamp resolution: it catches a write that landed inside the same second, which `mtime` cannot. Compare it for equality only — the encoding is this worker's business and may change.

editor::save

function

Write a file, refusing the write when it changed underneath since the editor::open it started from. On refusal the divergence comes back as a patch.

request
  • contentstringrequired

    Full new contents. This is a whole-file write, not a patch.

  • expected_mtimeinteger· int64

    The `mtime` from the `editor::open` this edit started from. When it no longer matches the file on disk, the write is refused and the divergence comes back as a patch. Omit only when deliberately overwriting whatever is there. Resolution is one second, which is all the filesystem reports. Two writes inside the same second are therefore indistinguishable to this field, and the second one wins silently — send `expected_version` instead to close that window.

  • expected_versionstring

    The `version` from the `editor::open` — or from the previous `editor::save` — this edit started from. It is a version of the *content*, so it catches a write that landed inside the same filesystem second and it does not care whether a clock or a checkout moved the mtime. When this is present it is the guard and `expected_mtime` is ignored. When it is absent the `expected_mtime` comparison applies exactly as before, so a caller that has never heard of a version is unaffected.

  • pathstringrequired
response
  • addedinteger· uint32requiredmin 0

    Lines this save added relative to what was on disk before it.

  • conflictbooleanrequired

    True when the write was refused because the file changed underneath.

  • conflict_patchstring

    On conflict: a unified diff from the current disk contents to the contents you tried to write, so the divergence is reviewable without a second round trip.

  • createdbooleanrequired

    True when the file did not exist and was created.

  • disk_mtimeinteger· int64

    What was on disk when a conflict was detected.

  • disk_versionstring

    Version of the disk contents when a conflict was detected — the value to send as `expected_version` once you have reconciled with them.

  • mtimeinteger· int64required

    Last-modified time after the write. Feed it into the next save.

  • pathstringrequired
  • removedinteger· uint32requiredmin 0

    Lines this save removed.

  • savedbooleanrequired

    True when the file was written.

  • versionstringrequired

    Version of the content this file now holds: what was written on success, what is on disk on a conflict. Feed it into the next save as `expected_version`.

editor::search

function

Search file contents across the workspace, grouped by file — the shell worker's recursive grep, shaped into what a results panel renders.

request
  • ignore_caseboolean

    Match case-insensitively.

  • include_globstring[]

    Glob filters restricting which files are searched, e.g. `["**/*.rs"]`.

  • max_matchesinteger· uint64min 0

    Stop after this many matching lines. Defaults to the worker's `search_max_matches`.

  • patternstringrequired

    Rust regex matched against each line.

response
  • filesobject[]required

    Matches grouped by file, in first-match order — the shape a result panel renders, rather than a flat list every caller has to group.

    • hitsobject[]required
      • lineinteger· uint64requiredmin 0

        1-based line number.

      • textstringrequired

        The matching line, as shell returned it.

    • pathstringrequired
  • totalinteger· uint32requiredmin 0

    Total matching lines across every file.

  • truncatedbooleanrequired

    True when the search stopped at `max_matches`.

editor::tree

function

List a folder in the workspace, with the expansion state the workspace remembers. The walk, the noise-folder excludes and the jail are the shell worker's.

request
  • collapsestring[]

    Root-relative folders to collapse. Collapsing takes its descendants with it.

  • expandstring[]

    Root-relative folders to mark expanded before listing. Expansion is part of the shared workspace, so it survives a reload and both surfaces agree on it.

  • max_depthinteger· uint32min 0

    Levels to descend. Defaults to 4 — deep enough to navigate, shallow enough that one call does not walk a whole monorepo.

  • pathstring

    Folder to list, relative to the workspace root. Defaults to the root.

response
  • expandedstring[]required

    Folders the workspace has expanded, root-relative.

  • pathstringrequired

    Canonical absolute path of the listed folder, as shell resolved it.

  • rootstringrequired
  • treeunknownrequired

    The listing exactly as the shell worker returned it (nested `{name, kind, size, mtime, children}` nodes). Passed through rather than re-modelled so this worker does not pin shell's response shape.

editor::ui-content

function

Serve the editor worker's injected console UI assets (content function for its console:script / console:style triggers).

request
  • pathstringrequired

    The asset path from the trigger config (e.g. `state/page.js`).

response
  • contentstringrequired

    The asset source, verbatim.

  • content_typestringrequired

    MIME type the console should serve the asset with.

editor::workspace::get

function

The active workspace: its root, the files open against it, and which folders are expanded. Shared by every surface, so this is what the agent and the console both see.

request
empty object
response
  • buffersobject[]required

    Files currently open against this root, shared by every surface.

    • languagestringrequired

      Monaco language id for the path.

    • mtimeinteger· int64required

      Last-modified time this buffer was read at, Unix seconds.

    • pathstringrequired

      Path relative to the workspace root.

    • versionstring

      Opaque version of the content this buffer was read at — the same fact `mtime` carries, in the form that survives two writes inside one second. A surface saves against it by sending it as `expected_version`. Defaulted so a session persisted before this field existed still loads. Empty means "unknown": a surface holding an empty version has only the mtime to save against, which is the behaviour it had all along.

  • expandedstring[]required

    Folders expanded in the tree, root-relative.

  • rootstringrequired

    The active root every other path in this response is relative to.

editor::workspace::open

function

Set the directory the editor works in. Any folder will do — a git repository is an overlay, not a requirement. Returns the buffers and expanded folders remembered for it.

request
  • rootstringrequired

    Directory to work in. Jail-relative when shell's `fs.host_roots` are set, else absolute. A plain folder is enough — a git repository is an overlay, never a requirement.

response
  • buffersobject[]required

    Files currently open against this root, shared by every surface.

    • languagestringrequired

      Monaco language id for the path.

    • mtimeinteger· int64required

      Last-modified time this buffer was read at, Unix seconds.

    • pathstringrequired

      Path relative to the workspace root.

    • versionstring

      Opaque version of the content this buffer was read at — the same fact `mtime` carries, in the form that survives two writes inside one second. A surface saves against it by sending it as `expected_version`. Defaulted so a session persisted before this field existed still loads. Empty means "unknown": a surface holding an empty version has only the mtime to save against, which is the behaviour it had all along.

  • expandedstring[]required

    Folders expanded in the tree, root-relative.

  • rootstringrequired

    The active root every other path in this response is relative to.

triggers

1

editor::changed

trigger

Fires when a file in the workspace changes, whoever changed it — including an agent that never called this worker.

invocation
valueunknown
return
valueunknown