跳到内容

参考 API 方法

本页列出 Paneflow 0.20.0 中 paneflow api docs 显示的 Paneflow API 全部方法。说明来自方法注册表,保留英文。可以用 paneflow api call <method> key=value 调用方法,也可以在 Lua 中写 paneflow.<namespace>.<method>{...},或通过 Paneflow 本地套接字发送 JSON-RPC 2.0,每行一条 JSON 消息。用法见 CLI 自动化。

每个方法都标明提供它的进程:window(应用)、worker(paneflow serve)或 host(拥有终端会话的 paneflow host)。标有 scripting 或 orchestration 的方法需要在 paneflow.json 的 ipc 中打开该门控,或为调用的窗格授予权限。左侧带竖线的注释标出代码的实际响应与方法声明不同之处。

action

action.invoke

worker

Run an action of init.lua with arguments and return what it returned. Arguments are checked against its schema first; a run is stopped after 30 seconds. With wait_ms, a run still going past it answers {status: running, run_id} for action.wait. With ctx.origin agent, only an action declared with agents = true runs.

字段类型必填说明
argstableThe action's arguments, checked against its declared schema
ctxtable
namestring是
wait_msintegerMilliseconds to wait for the run to end, at most 25000; past it the reply is {status: running, run_id} and action.wait keeps waiting. Absent waits for the end
结果类型
resultany?
run_idstring?
status"done"|"running"|"rate_limited"?
local result = paneflow.action.invoke{ name = "dev_layout", args = { file = "app.log" }, ctx = { origin = "cli" } }
{
  "result": {
    "surface_id": 12
  }
}

action.list

worker

List the actions init.lua declared, with their titles, argument schemas and sources.

结果类型
actionstable[]
local result = paneflow.action.list()
{
  "actions": [
    {
      "name": "dev_layout",
      "title": "Dev layout",
      "category": "Actions",
      "keywords": [
        "split"
      ],
      "args": {
        "type": "object",
        "properties": {
          "file": {
            "type": "string"
          }
        },
        "required": [
          "file"
        ],
        "additionalProperties": false
      },
      "agents": false,
      "source": "init.lua:3"
    }
  ]
}

action.wait

worker

Keep waiting on an action run that action.invoke returned as {status: running, run_id}: the run's result with status done, the same running status, or the action's error.

字段类型必填说明
run_idstring是
wait_msintegerMilliseconds to wait, 0 by default, at most 25000
结果类型
resultany?
run_idstring?
status"done"|"running"|"rate_limited"?
local result = paneflow.action.wait{ run_id = "6f1c0e9a2b7d4c3e8f5a1b2c3d4e5f60", wait_ms = 20000 }
{
  "result": {
    "surface_id": 12
  },
  "status": "done"
}

agent

agent.acknowledge

worker

Clear the unread mark of sessions and publish the lowered rows.

字段类型必填说明
sessionstringOne session, when sessions is absent
sessionsstring[]
结果类型
acknowledgedstring[]
local result = paneflow.agent.acknowledge{ sessions = { "123e4567-e89b-42d3-a456-426614174000" } }
{
  "acknowledged": [
    "123e4567-e89b-42d3-a456-426614174000"
  ]
}

agent.activity_log

worker

Read the most recent agent activity entries.

字段类型必填说明
limitintegerEntries to return, 50 by default
结果类型
entriesany[]
local result = paneflow.agent.activity_log{ limit = 2 }
{
  "entries": []
}

agent.follow

worker

Stream the session projection: a snapshot header, then one frame per reduced transition.

A stream: Lua cannot call it. React to events with paneflow.on or paneflow.wait.

结果类型
capabilitiesstring[]
core_connectedboolean
followingboolean?
sessionsany[]
usageany
workertable
local result = paneflow.agent.follow()
{
  "worker": {
    "name": "paneflow-serve",
    "version": "0.20.0",
    "build_id": "9f2c",
    "protocol": 1,
    "required_core_protocol": 1,
    "pid": 4242,
    "home": "/home/me/.paneflow",
    "endpoint": "/home/me/.paneflow/serve/worker.sock",
    "started_at_ms": 1763600000000,
    "capabilities": [
      "agent.follow"
    ]
  },
  "capabilities": [
    "agent.follow"
  ],
  "core_connected": true,
  "sessions": [],
  "usage": {},
  "following": true
}

agent.snapshot

worker

Read every session's reduced agent row and the usage frame.

结果类型
capabilitiesstring[]
core_connectedboolean
followingboolean?
sessionsany[]
usageany
workertable
local result = paneflow.agent.snapshot()
{
  "worker": {
    "name": "paneflow-serve",
    "version": "0.20.0",
    "build_id": "9f2c",
    "protocol": 1,
    "required_core_protocol": 1,
    "pid": 4242,
    "home": "/home/me/.paneflow",
    "endpoint": "/home/me/.paneflow/serve/worker.sock",
    "started_at_ms": 1763600000000,
    "capabilities": [
      "agent.follow"
    ]
  },
  "capabilities": [
    "agent.follow"
  ],
  "core_connected": true,
  "sessions": [],
  "usage": {}
}

agent_prompt

agent_prompt.resolve

worker

Ask the user, in the window, the question or the permission request a coding agent's hook received, when agent_prompts is paneflow in paneflow.json. Holds one 300 second deadline for the whole call and replies answered with the JSON the hook prints, or declined, after which the agent asks in its own terminal.

reason can also be busy.

字段类型必填说明
agentstringThe agent's runtime name, such as claude or codex
event"ask_user_question"|"permission_request"是
payloadany是The hook's input JSON, as the agent wrote it
sessionstringThe Paneflow session of the agent; the worker replaces it with the caller's own session when the caller runs in a pane
结果类型
outputany?
reasonstring?
status"answered"|"declined"
local result = paneflow.agent_prompt.resolve{ event = "permission_request", agent = "claude", payload = { tool_name = "Bash", tool_input = { command = "rm -rf build" } } }
{
  "status": "answered",
  "output": {
    "hookSpecificOutput": {
      "hookEventName": "PermissionRequest",
      "decision": {
        "behavior": "allow"
      }
    }
  }
}

client

client.dispatch_action

window

Dispatch a built-in action in the window as the command palette does, and reply once it is dispatched.

字段类型必填说明
namestring是A name from client.list_actions, such as toggle_zoom
结果类型
dispatchedboolean
namestring
local result = paneflow.client.dispatch_action{ name = "toggle_zoom" }
{
  "dispatched": true,
  "name": "toggle_zoom"
}

client.list_actions

window

List the window's built-in actions: the names key bindings and client.dispatch_action accept.

结果类型
actionstable[]
local result = paneflow.client.list_actions()
{
  "actions": [
    {
      "name": "toggle_zoom",
      "description": "Zoom the focused pane",
      "group": "Panes & splits"
    }
  ]
}

config

config.reload

worker

Load init.lua again now and return the status; a failed load keeps the previous configuration active.

结果类型
actionsinteger
bindingsinteger
foundboolean
handler_errorsinteger
handlersinteger
loaded_at_msinteger?
okboolean
pathstring
problemstable[]
timer_errorsinteger
timersinteger
local result = paneflow.config.reload()
{
  "path": "/home/me/.paneflow/init.lua",
  "found": false,
  "ok": true,
  "actions": 0,
  "bindings": 0,
  "handlers": 0,
  "timers": 0,
  "handler_errors": 0,
  "timer_errors": 0,
  "problems": []
}

config.status

worker

Read the state of init.lua: its path, whether it was found, when it loaded, what it declared and its load problems.

结果类型
actionsinteger
bindingsinteger
foundboolean
handler_errorsinteger
handlersinteger
loaded_at_msinteger?
okboolean
pathstring
problemstable[]
timer_errorsinteger
timersinteger
local result = paneflow.config.status()
{
  "path": "/home/me/.paneflow/init.lua",
  "found": true,
  "loaded_at_ms": 1763600000000,
  "ok": false,
  "actions": 2,
  "bindings": 1,
  "handlers": 1,
  "timers": 0,
  "handler_errors": 0,
  "timer_errors": 0,
  "problems": [
    {
      "file": "init.lua",
      "line": 7,
      "severity": "error",
      "message": "unexpected symbol near 'end'"
    }
  ]
}

events

events.follow

worker

Stream the worker's numbered event log: a following header, then every event with consecutive seq values, keepalive frames when quiet, and an end frame when the worker closes the stream. A since that left the ring, or an epoch from another worker start, is refused with -32040 and data {reason: evicted, seq, epoch}.

A stream: Lua cannot call it. React to events with paneflow.on or paneflow.wait.

字段类型必填说明
epochstringThe epoch since belongs to; a different epoch is refused with an evicted error
sinceintegerReplay the events after this seq first; refused with an evicted error when they left the ring
typesstring[]Only send these types: exact names or a family such as terminal.*
workspace_idintegerOnly send events about this layout workspace id
结果类型
epochstring
seqinteger
type"following"
local result = paneflow.events.follow{ types = { "terminal.*", "pane.closed" } }
{
  "type": "following",
  "seq": 41,
  "epoch": "1a2b-19a7c3f0e00-0"
}

events.subscribe

window

Stream surface and agent events as JSON lines: a subscribed frame, then events, heartbeat and dropped frames.

A stream: Lua cannot call it. React to events with paneflow.on or paneflow.wait.

字段类型必填说明
surfacesinteger[]Only stream events about these surfaces
typesstring[]Only stream these event types: surface_changed and the ai.* lifecycle types
结果类型
idinteger
type"subscribed"
local result = paneflow.events.subscribe{ types = { "surface_changed" } }
{
  "type": "subscribed",
  "id": 1
}

fleet

fleet.list

window

List the agents running in every workspace.

When no window is open, the host answers, and each row also carries session and generation.

结果类型
agentstable[]
local result = paneflow.fleet.list()
{
  "agents": [
    {
      "pid": 4242,
      "tool": "claude",
      "state": "waiting_for_input",
      "hooked": true,
      "reason": null,
      "surface_id": 7,
      "surface_name": "claude",
      "workspace": 0,
      "active_tool_name": null,
      "message": "needs a decision",
      "last_result": null,
      "waiting_ms": 3000,
      "idle_ms": 3000
    }
  ]
}

grant

grant.delegate

worker

Give a pane the caller spawned a grant no wider than one the caller holds.

字段类型必填说明
duration_secsintegerSeconds the delegated grant lasts, until the delegator's grant ends by default
rights("write"|"spawn"|"layout")[]是
scope"workspace"|"instance"
sessionstring是The session of a pane the caller spawned with surface.split
结果类型
expires_at_msinteger?
grantedboolean
idstring?
reasonstring?
local result = paneflow.grant.delegate{ session = "223e4567-e89b-42d3-a456-426614174000", rights = { "write" } }
{
  "granted": true,
  "id": "g-2",
  "expires_at_ms": 1800000000000
}

grant.list

worker

List the grants panes hold, with the revision of the set; a pane sees the grants it holds or delegated.

结果类型
grantstable[]
revisioninteger
local result = paneflow.grant.list()
{
  "revision": 4,
  "grants": []
}

grant.request

worker

Ask the human for rights the calling pane does not hold, for a scope and a time.

字段类型必填说明
duration_secsintegerSeconds the grant lasts once allowed, 3600 by default; 0 asks for a grant with no expiry
reasonstringWhy the agent needs it, shown to the human
rights("write"|"spawn"|"layout")[]是Rights asked for, among write, spawn and layout
scope"workspace"|"instance"workspace reaches the calling pane's own workspace, instance every workspace
结果类型
expires_at_msinteger?
grantedboolean
idstring?
reasonstring?
local result = paneflow.grant.request{ rights = { "write" }, scope = "workspace", duration_secs = 600 }
{
  "granted": true,
  "id": "g-1",
  "expires_at_ms": 1800000000000
}

grant.revoke

worker

Revoke a grant and every grant delegated from it.

字段类型必填说明
idstring是The grant to revoke; every grant delegated from it is revoked too
结果类型
revisioninteger
revokedstring[]
local result = paneflow.grant.revoke{ id = "g-1" }
{
  "revoked": [
    "g-1",
    "g-2"
  ],
  "revision": 5
}

keymap

keymap.list

worker

List the key bindings init.lua declared and the keys it unbound, for the window to apply.

结果类型
bindingstable[]
unboundtable[]
local result = paneflow.keymap.list()
{
  "bindings": [
    {
      "key": "ctrl-alt-d",
      "action": "dev_layout",
      "args": {
        "file": "app.log"
      },
      "source": "init.lua:9",
      "target": "lua"
    }
  ],
  "unbound": [
    {
      "key": "ctrl-shift-w",
      "source": "init.lua:10"
    }
  ]
}

layout

layout.adopt

worker

Hand the worker a client's model after an outage. The worker takes it when its own revision is not greater than the revision it last acknowledged to the client, and otherwise returns its own view.

字段类型必填说明
acknowledgedinteger是The last revision the worker acknowledged to this client
viewtable是The layout model as plain data: {revision, state: {version, workspaces, active_workspace, active_space}, undo}, every workspace, tab, pane, split and surface carrying its stable id
结果类型
acceptedboolean
revisioninteger
viewtable?
local result = paneflow.layout.adopt{ view = { revision = 14, state = { version = 3, workspaces = {  }, active_workspace = 0, active_space = nil } }, acknowledged = 12 }
{
  "accepted": true,
  "revision": 14,
  "view": null
}

layout.apply

workerorchestration

Apply one layout op to the worker's model and return the new revision and its events. A refused op fails with -32070 and data {reason}: not_found, zoomed, pane_limit, tab_limit, surface_limit, ids_exhausted, invalid, or window_owns_layout while a window of an earlier build owns the layout.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

字段类型必填说明
ids_fromintegerThe client's next id when it applied the op; ids the op allocates are taken from the client's leases from here
optable是One layout operation, named by its op field: split, close_pane, focus_pane, rename_surface, set_ratios, bind_session and the others of paneflow-layout, with the ids it acts on
spawned_bystringThe session of the pane that asked the window for this op; the worker records it as the spawner of the terminals the op creates. Only the attached window may send it
结果类型
eventstable[]
revisioninteger
local result = paneflow.layout.apply{ op = { op = "focus_pane", pane = 5 } }
{
  "revision": 13,
  "events": [
    {
      "type": "pane.focused",
      "workspace_id": 1,
      "tab_id": 2,
      "pane_id": 5,
      "data": {}
    },
    {
      "type": "layout.changed",
      "workspace_id": 1,
      "tab_id": 2,
      "data": {
        "revision": 13
      }
    }
  ]
}

layout.attach

worker

Attach this connection as a layout client until it closes, and return the view, its revision and the worker's epoch.

字段类型必填说明
clientstringA name for the client in worker.status
结果类型
epochstring
revisioninteger
viewtable
local result = paneflow.layout.attach{ client = "window" }
{
  "epoch": "1a2b-19a7c3f0e00-0",
  "revision": 12,
  "view": {
    "revision": 12,
    "state": {
      "version": 3,
      "workspaces": [],
      "active_workspace": 0,
      "active_space": null
    }
  }
}

layout.launch

workerorchestration

Start the terminal of a surface for the attached layout client that created it: the worker builds the launch from its configuration and the layout and creates the session under the id the client chose, which the client binds with bind_session. The surface must have no session or this one. Fails with -32070 and data {reason}: not_attached, not_found, invalid, host_unreachable or launch_failed with the host's message.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

字段类型必填说明
appearanceanyThe colors the terminal answers color queries with: {foreground, background, cursor, palette of 256 [r, g, b], dark}
cellanyThe cell size in pixels: {width, height}
colsintegerInitial width in cells; 120 when absent
confine_tostringA worktree the working directory must stay inside; a cwd outside it starts at the worktree
cwdstringThe working directory the client asks for
envtable<string, string>Variables for this terminal, above the global and space ones
fallbackstringThe directory used when cwd no longer exists
rowsintegerInitial height in cells; 40 when absent
sessionstring是The session id the client chose for the new terminal
surface_idinteger是The terminal surface to start
结果类型
eventstable[]
noticesstring[]
revisioninteger
local result = paneflow.layout.launch{ surface_id = 7, session = "0190e4d2-7b2a-7c3d-8e4f-a1b2c3d4e5f6", cwd = "/home/me/project" }
{
  "revision": 15,
  "events": [
    {
      "type": "layout.changed",
      "workspace_id": 1,
      "tab_id": 2,
      "data": {
        "revision": 15
      }
    }
  ],
  "notices": []
}

layout.lease_ids

worker

Grant this connection a contiguous block of 1,024 ids for the elements it creates; the worker never grants an id twice, across restarts included.

结果类型
endinteger
startinteger
local result = paneflow.layout.lease_ids()
{
  "start": 4097,
  "end": 5121
}

layout.sweep

worker

Remove the records of ended sessions that no surface of the layout, no undo hold and no pending launch names, and with live, also stop the live sessions this host started that nothing holds. The attached layout client calls it after it restores; the worker runs the host requests. Fails with -32070 and data {reason}: not_attached or host_unreachable.

字段类型必填说明
keepstring[]Sessions the client holds outside the layout, such as dock terminals, which the sweep must keep
livebooleanAlso stop the live sessions this host started that nothing holds, as the first sweep after a restore does
结果类型
forgottenstring[]
stoppedstring[]
local result = paneflow.layout.sweep{ live = true, keep = {  } }
{
  "forgotten": [
    "0190e4d2-7b2a-7c3d-8e4f-a1b2c3d4e5f6"
  ],
  "stopped": []
}

layout.view

worker

Return the layout model the worker holds, with its revision and the worker's epoch.

字段类型必填说明
unless_revisionintegerThe revision the client holds; when it is still the worker's, view is null
结果类型
attachedboolean
epochstring
revisioninteger
viewtable?
local result = paneflow.layout.view()
{
  "epoch": "1a2b-19a7c3f0e00-0",
  "revision": 12,
  "attached": true,
  "view": {
    "revision": 12,
    "state": {
      "version": 3,
      "workspaces": [],
      "active_workspace": 0,
      "active_space": null
    },
    "undo": {
      "records": [],
      "held": []
    }
  }
}

pane

pane.write

host

Relay a message from one agent's pane into another's, once a human allows the pair.

request arrives as a number. With submit, the reply also carries delivered, started, reason and, when known, state.

字段类型必填说明
scope"workspace"|"all"
sessionstring是The session to write into
source_sessionstring是The calling pane's session (PANEFLOW_SESSION_ID)
submitboolean
textstring是Text to relay, prefixed with a provenance line
结果类型
bytesinteger?
messagestring?
requeststring?
statusstring
submit_modestring?
submittedboolean?
local result = paneflow.pane.write{ source_session = "123e4567-e89b-42d3-a456-426614174000", session = "223e4567-e89b-42d3-a456-426614174000", text = "the tests pass on main" }
{
  "status": "approval_pending",
  "request": "7",
  "message": "a human must allow it"
}

peer

peer.classify

host

Say whether a process runs inside one of the host's panes, and which one.

字段类型必填说明
pidinteger是PID of the process to classify
started_atinteger是Start time the caller read for that PID, in the host's process clock
结果类型
in_paneboolean
sessionstring?
staleboolean?
unverifiedstring?
workspacestring?
local result = paneflow.peer.classify{ pid = 4242, started_at = 9876543 }
{
  "in_pane": true,
  "session": "123e4567-e89b-42d3-a456-426614174000",
  "workspace": "223e4567-e89b-42d3-a456-426614174000"
}

prompt

prompt.follow

worker

Stream the prompts this client can show: a following header, a requested frame for each pending prompt oldest first, then requested frames (id, spec, origin, remaining time, token) and ended frames (id, reason), keepalive frames when quiet. A pane never receives an agent's prompt.

字段类型必填说明
kinds("input"|"pick")[]是The prompt kinds this client can show
结果类型
kinds("input"|"pick")[]
pendinginteger
type"following"
local result = paneflow.prompt.follow{ kinds = { "input", "pick" } }
{
  "type": "following",
  "kinds": [
    "input",
    "pick"
  ],
  "pending": 1
}

prompt.reply

worker

Answer or cancel a pending prompt. The first reply wins and every follower receives ended; a later one is refused with -32060 and data {reason: not_pending}. An agent's prompt takes a reply only with its token, from outside every pane.

字段类型必填说明
answerstring|string[]|tableThe text, the id, the list of ids or {text}, as the prompt's kind takes
cancelbooleanDismiss the prompt; the asker receives cancelled
idinteger是
tokenstringThe requested frame's token; required for an agent's prompt
结果类型
idinteger
reason"answered"|"cancelled"|"timeout"|"no_client"|"failed"
local result = paneflow.prompt.reply{ id = 3, answer = "feature/login" }
{
  "id": 3,
  "reason": "answered"
}

prompt.request

worker

Ask the user through every attached client that can show the prompt; the first answer wins. Returns {status: answered, answer} within wait_ms, {status: pending, id} when wait_ms passes first, or the reason it ended: cancelled, timeout, no_client, unsupported, busy, rate_limited (an agent asking more than 3 times in a burst or more than once a second after it) or failed with a detail.

字段类型必填说明
allow_otherbooleanAccept typed text that matches no item; the answer is {text}
bodystringShown under the title, line breaks kept; at most 16384 bytes
confirmstringLabel of the confirming row
items(string|table)[]The choices of a pick prompt, at most 2000: an id string or an item
kind"input"|"pick"是input asks for a line of text, pick for a choice among items
multiplebooleanLet the user tick several items; the answer is the list of ids
origintableWho asks, shown under the title
placeholderstring
timeoutnumberSeconds before the prompt ends with timeout: 300 by default, at most 3600
titlestring是
valuestringText the field starts with
wait_msintegerMilliseconds to wait for the answer before returning pending with the id, 0 by default, at most 25000
结果类型
answerstring|string[]|table?
detailstring?
idinteger?
status"answered"|"pending"|"cancelled"|"timeout"|"no_client"|"unsupported"|"busy"|"rate_limited"|"failed"
local result = paneflow.prompt.request{ kind = "input", title = "New branch", value = "feature/", wait_ms = 20000, origin = { kind = "action", name = "new_branch", title = "New branch" } }
{
  "status": "answered",
  "id": 3,
  "answer": "feature/login"
}

prompt.wait

worker

Keep waiting on a pending prompt by id, with the same outcomes as prompt.request.

字段类型必填说明
idinteger是
wait_msintegerMilliseconds to wait, 0 by default, at most 25000
结果类型
answerstring|string[]|table?
detailstring?
idinteger?
status"answered"|"pending"|"cancelled"|"timeout"|"no_client"|"unsupported"|"busy"|"rate_limited"|"failed"
local result = paneflow.prompt.wait{ id = 4, wait_ms = 20000 }
{
  "status": "answered",
  "id": 4,
  "answer": "web"
}

surface

surface.focus

worker

Reveal a surface and give it the keyboard focus.

字段类型必填说明
surface_idinteger是
结果类型
focusedboolean
scopestring
surface_idinteger
workspaceinteger
local result = paneflow.surface.focus{ surface_id = 7 }
{
  "focused": true,
  "surface_id": 7,
  "workspace": 0,
  "scope": "workspace"
}

surface.list

window

List the surfaces of the shown workspace, or of one workspace, with their identity.

字段类型必填说明
scope"workspace"|"all""all" reads beyond the calling pane's workspace when orchestration is open for it
scope_sessionstringList the workspace that holds this session
workspace_idintegerList this workspace instead of the shown one
结果类型
pane_countinteger
scope_workspace_idinteger?
surfacestable[]
workspaceinteger
local result = paneflow.surface.list()
{
  "pane_count": 1,
  "workspace": 0,
  "scope_workspace_id": null,
  "surfaces": [
    {
      "surface_id": 7,
      "name": "shell",
      "title": "~/dev",
      "cwd": "/home/me/dev",
      "cmd": "zsh",
      "workspace_id": 1,
      "workspace": 0,
      "scope": "workspace",
      "tab_id": 1,
      "tab_title": "Terminal",
      "space": null,
      "sandboxed": false
    }
  ]
}

surface.read

window

Read a surface's trailing scrollback lines.

字段类型必填说明
fencedbooleanWrap the text in an untrusted-output fence; the ai_injection_fence setting decides when absent
linesintegerTrailing lines to return, clamped to 1..4000
namestringPick the surface by its unique name instead of its id
offsetintegerLines to skip back from the end of the buffer
scope"workspace"|"all""all" reads beyond the calling pane's workspace when orchestration is open for it
scope_sessionstring
surface_idintegerThe surface to read; the first surface of the shown tab when absent
workspace_idinteger
结果类型
eofboolean
linesinteger
output_generationinteger
textstring
total_linesinteger
truncatedboolean
local result = paneflow.surface.read{ surface_id = 7, lines = 2, fenced = false }
{
  "text": "cargo test\nok",
  "lines": 2,
  "total_lines": 40,
  "eof": false,
  "output_generation": 12,
  "truncated": false
}

surface.rename

worker

Give a surface a custom name, or clear it.

字段类型必填说明
namestringThe new name; an absent or empty name clears the custom name
new_namestringAlias of name
surface_idinteger
结果类型
namestring?
renamedboolean
local result = paneflow.surface.rename{ surface_id = 7, name = "tests" }
{
  "renamed": true,
  "name": "tests"
}
window

Find the scrollback lines of a surface that contain a pattern.

字段类型必填说明
fencedbooleanAdd a text field holding every match in one untrusted-output fence; the ai_injection_fence setting decides when absent
max_matchesintegerMatches to return, clamped to 1..1000
namestring
patternstring是Substring or pattern to find, at most 512 bytes
scope"workspace"|"all""all" reads beyond the calling pane's workspace when orchestration is open for it
scope_sessionstring
surface_idinteger
workspace_idinteger
结果类型
matchestable[]
textstring?
truncatedboolean
local result = paneflow.surface.search{ surface_id = 7, pattern = "error" }
{
  "matches": [
    {
      "line": 31,
      "text": "error[E0308]: mismatched types"
    }
  ],
  "truncated": false
}

surface.send_keystroke

windowscripting

Send a named key such as escape or ctrl-c to a surface.

Refused with -32601 unless ipc.scripting or ai_unrestricted is true in paneflow.json, or a write grant covers the calling pane.

字段类型必填说明
keystrokestringDash-separated key such as escape, ctrl-c or alt-f; required, and never one that submits a line
scope"workspace"|"all"
scope_sessionstring
surface_idinteger
结果类型
sentboolean
local result = paneflow.surface.send_keystroke{ surface_id = 7, keystroke = "ctrl-c" }
{
  "sent": true
}

surface.send_text

windowscripting

Write text into a surface, submitting it only when asked.

Refused with -32601 unless ipc.scripting or ai_unrestricted is true in paneflow.json, or a write grant covers the calling pane.

字段类型必填说明
forcebooleanWrite even when the agent waits for a decision; the write is logged
pastebooleanForce or refuse bracketed paste; decided from the target when absent
scope"workspace"|"all"
scope_sessionstringThe calling pane's session; writes stay in its workspace
submitbooleanSubmit with a carriage return after the text
surface_idinteger
textstringText to write; required unless submit is true. At most 64 KiB
结果类型
agent_targetboolean
agent_toolstring?
lengthinteger
pasteboolean
sentboolean
submit_mode"deferred_paste_cr"|"inline_cr"?
submittedboolean
terminal_bracketed_pasteboolean
local result = paneflow.surface.send_text{ surface_id = 7, text = "cargo test" }
{
  "sent": true,
  "length": 10,
  "submitted": false,
  "paste": false,
  "submit_mode": null,
  "agent_target": false,
  "agent_tool": null,
  "terminal_bracketed_paste": false
}

surface.split

workerorchestration

Split the pane holding a surface and start a terminal in the new pane.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

字段类型必填说明
commandstring
cwdstring
direction"horizontal"|"vertical"是horizontal stacks the panes, vertical puts them side by side
envtable<string, string>
labelstring
managed_worktreetable
namestringAlias of label
profile"normal"|"agent"|"cached"
promptstring
surface_idintegerSplit the pane holding this surface; the shown tab's first pane when absent
worktreetableCreate or reuse a Paneflow worktree for the new pane, which then starts in it; exclusive with managed_worktree
结果类型
directionstring
new_tabboolean
noticesstring[]?
panesinteger
splitboolean
surface_idinteger
tab_idinteger
local result = paneflow.surface.split{ surface_id = 7, direction = "vertical" }
{
  "split": true,
  "new_tab": false,
  "tab_id": 3,
  "direction": "vertical",
  "panes": 2,
  "surface_id": 9
}

surface.status

window

Read a surface's agent state, hook status and output generation.

字段类型必填说明
namestring
surface_idinteger
结果类型
active_tool_namestring?
hookedboolean
idle_msinteger?
last_resultstring?
messagestring?
output_generationinteger
sessionstring
statestring?
state_seqinteger?
surface_idinteger
toolstring?
waiting_msinteger?
local result = paneflow.surface.status{ surface_id = 7 }
{
  "surface_id": 7,
  "state": "thinking",
  "state_seq": 4,
  "hooked": true,
  "tool": "claude",
  "active_tool_name": "Bash",
  "message": null,
  "last_result": null,
  "waiting_ms": null,
  "idle_ms": 1200,
  "output_generation": 12,
  "session": "123e4567-e89b-42d3-a456-426614174000"
}

system

system.capabilities

window

List the methods this endpoint serves and whether its gates are open.

When no window is open, the host answers: its reply carries controller and host in place of methods.

结果类型
methodsstring[]
orchestrationboolean
scriptingboolean
local result = paneflow.system.capabilities()
{
  "scripting": false,
  "orchestration": false,
  "methods": [
    "system.ping",
    "surface.list"
  ]
}

system.counters

window

Read the app's work counters: renders, git spawns, process spawns.

结果类型
counterstable
local result = paneflow.system.counters()
{
  "counters": {
    "root_renders": 120,
    "sidebar_renders": 40,
    "host_agent_snapshots_applied": 3,
    "session_list_calls": 2,
    "git_spawns": {
      "total": 5,
      "probe": 4,
      "user_action": 1,
      "by_subcommand": {
        "status": 4,
        "other": 1
      }
    },
    "process_spawns": 7,
    "process_identity": {
      "pid": 4242,
      "started_at": 1763600000000
    }
  }
}

system.describe

window

Describe every method, or one: owner, gate, params and result schemas, examples.

字段类型必填说明
methodstringDescribe only this method
结果类型
callableboolean
examplestable[]
fallbackstring?
gatestring
gate_notestring?
in_capabilitiesboolean
methodstable[]
namestring
ownerstring
paramsany
replystring
resultany
streamboolean
summarystring
local result = paneflow.system.describe{ method = "system.ping" }
{
  "name": "system.ping",
  "summary": "Check that the endpoint answers.",
  "owner": "window",
  "fallback": null,
  "gate": "none",
  "gate_note": null,
  "reply": "inline",
  "stream": false,
  "in_capabilities": true,
  "callable": true,
  "params": {
    "type": "object"
  },
  "result": {
    "type": "object",
    "properties": {
      "pong": {
        "type": "boolean"
      }
    }
  },
  "examples": [
    {
      "params": {},
      "result": {
        "pong": true
      }
    }
  ]
}

system.identify

window

Name the running app, its version and its wire protocol.

结果类型
namestring
protocolstring
versionstring
local result = paneflow.system.identify()
{
  "name": "PaneFlow",
  "version": "0.20.0",
  "protocol": "jsonrpc-2.0"
}

system.ping

window

Check that the endpoint answers.

结果类型
pongboolean
local result = paneflow.system.ping()
{
  "pong": true
}

system.whoami

window

Say how the answering process identifies the caller: window, worker, pane, external or unverified.

结果类型
principalstring
reasonstring?
sessionstring?
workspacestring?
local result = paneflow.system.whoami()
{
  "principal": "pane",
  "session": "123e4567-e89b-42d3-a456-426614174000",
  "workspace": "223e4567-e89b-42d3-a456-426614174000"
}

tmux

tmux.compat

window

Run a tmux command for an agent team, as the paneflow tmux shim does.

字段类型必填说明
argvstring[]是The tmux command line, at most 256 arguments and 256 KiB
scope_sessionstring
surface_idinteger是The calling pane's surface
teamstring是Team name, 1 to 64 bytes
结果类型
exitinteger
stderrstring
stdoutstring
local result = paneflow.tmux.compat{ team = "review", surface_id = 7, argv = { "display-message", "-p", "#{pane_id}" } }
{
  "stdout": "%0\n",
  "stderr": "",
  "exit": 0
}

usage

usage.import

worker

Start importing past activity from the agents' local logs.

accounts[].agent takes claude-code, codex or grok.

字段类型必填说明
accountstable[]
forcebooleanusage.import only: start again even when an import already ran

A value with no declared fields.

local result = paneflow.usage.import{ force = false }
{}

usage.refresh

worker

Read fresh usage for the running agents and the listed accounts.

accounts[].agent takes claude-code, codex or grok.

字段类型必填说明
accountstable[]
forcebooleanusage.import only: start again even when an import already ran

A value with no declared fields.

local result = paneflow.usage.refresh{ accounts = { { agent = "codex", config_dir = "/home/me/.codex" } } }
{}

usage.snapshot

worker

Read the usage ledger snapshot.

A value with no declared fields.

local result = paneflow.usage.snapshot()
{}

worker

worker.hello

worker

Open a worker connection and read the worker's identity and capabilities.

结果类型
build_idstring
capabilitiesstring[]
endpointstring
homestring
namestring
pidinteger
protocolinteger
required_core_protocolinteger
started_at_msinteger
versionstring
local result = paneflow.worker.hello()
{
  "name": "paneflow-serve",
  "version": "0.20.0",
  "build_id": "9f2c",
  "protocol": 1,
  "required_core_protocol": 1,
  "pid": 4242,
  "home": "/home/me/.paneflow",
  "endpoint": "/home/me/.paneflow/serve/worker.sock",
  "started_at_ms": 1763600000000,
  "capabilities": [
    "agent.follow"
  ]
}

worker.shutdown

worker

Ask the worker to stop; terminals keep running in the host.

结果类型
pidinteger
stoppingboolean
local result = paneflow.worker.shutdown()
{
  "stopping": true,
  "pid": 4242
}

worker.status

worker

Read the worker's pid, version, session count and counters.

The reply also carries a layout object.

结果类型
capabilitiesstring[]
core_connectedboolean
countersany
endpointstring
homestring
pidinteger
protocolinteger
session_countinteger
versionstring
local result = paneflow.worker.status()
{
  "pid": 4242,
  "protocol": 1,
  "home": "/home/me/.paneflow",
  "endpoint": "/home/me/.paneflow/serve/worker.sock",
  "version": "0.20.0",
  "session_count": 3,
  "core_connected": true,
  "capabilities": [
    "agent.follow"
  ],
  "counters": {
    "sweeps": 10
  }
}

workspace

workspace.close

worker

Close the workspace at an index; the last workspace cannot be closed.

字段类型必填说明
indexinteger是Zero-based workspace index
结果类型
closedinteger
local result = paneflow.workspace.close{ index = 1 }
{
  "closed": 1
}

workspace.create

workerorchestration

Open a workspace with one terminal, or with a layout document.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

字段类型必填说明
cwdstringDirectory of the first pane; it must exist
layouttable
namestringWorkspace title
spacestringSpace by name or id; the active space when absent
结果类型
indexinteger
panesinteger
titlestring
local result = paneflow.workspace.create{ name = "review" }
{
  "index": 1,
  "title": "review",
  "panes": 1
}

workspace.current

window

Describe the shown workspace with its layout document, or null when none is shown.

结果类型
cwdstring
indexinteger
layouttable?
panesinteger
spacetable?
titlestring
local result = paneflow.workspace.current()
{
  "index": 0,
  "title": "paneflow",
  "cwd": "/home/me/dev/paneflow",
  "panes": 1,
  "space": null,
  "layout": {
    "type": "pane",
    "surfaces": [
      {
        "surface_type": "terminal",
        "name": "shell"
      }
    ]
  }
}

workspace.list

window

List every workspace with its title, directory, pane count and space.

结果类型
workspacestable[]
local result = paneflow.workspace.list()
{
  "workspaces": [
    {
      "index": 0,
      "title": "paneflow",
      "cwd": "/home/me/dev/paneflow",
      "panes": 2,
      "active": true,
      "space": null
    }
  ]
}

workspace.restore_layout

workerorchestration

Conform the shown tab to a layout document, reusing its panes.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

字段类型必填说明
layouttable是Holds between 1 and 32 panes
结果类型
panesinteger
restoredboolean
local result = paneflow.workspace.restore_layout{ layout = { type = "split", direction = "vertical", children = { { type = "pane", surfaces = { {} } }, { type = "pane", surfaces = { {} } } } } }
{
  "restored": true,
  "panes": 2
}

workspace.select

worker

Show the workspace at an index.

字段类型必填说明
indexinteger是Zero-based workspace index
结果类型
selectedinteger
local result = paneflow.workspace.select{ index = 1 }
{
  "selected": 1
}

workspace.up

workerorchestration

Open a workspace from pane specs, each with its own directory, command or prompt.

A request that sets a command, a prompt or an env is refused with -32601 unless ipc.orchestration, ipc.scripting or ai_unrestricted is true in paneflow.json, or a spawn or layout grant covers the calling pane.

字段类型必填说明
layoutstringLayout preset
namestringWorkspace title
panestable[]是
spacestring
结果类型
indexinteger
labelsstring[]
noticesstring[]?
panesinteger
surface_idsinteger[]
titlestring
local result = paneflow.workspace.up{ name = "agents", panes = { { label = "api" }, { label = "web" } } }
{
  "index": 1,
  "title": "agents",
  "panes": 2,
  "surface_ids": [
    11,
    12
  ],
  "labels": [
    "api",
    "web"
  ]
}