Live collaboration target: invariants, probes, identity table

Target document for the brokkr-live campaign: the agent works in the same
live Blender scene the operator is looking at. Records the Blender 5.3
timer-undo and viewport-capture probes the invariants stand on, and the
identity, lifecycle and authority table for every kind the layer adds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 18:02:26 +01:00
commit a975f99a90
3 changed files with 417 additions and 0 deletions

203
docs/live-collab-target.md Normal file
View file

@ -0,0 +1,203 @@
# Brokkr live collaboration: target
Campaign `brokkr-live` (Nibu's mind). Working branch `nibu/live-collab-target`, base
`origin/main` 5e279b2. This document holds the rationale, the design truths the
campaign produces, and the identity, lifecycle and authority table. The typed
`target` in the mind holds the labelled invariants and the not-in-scope list; the
text below is their source.
## Why
Operator, 2026-11-27: Brokkr "is meant to give an agent hands into the same Blender
scene I'm looking at, enabling live collaboration work". Brokkr already runs inside
her live Blender: a `depsgraph_update_post` handler publishes a host snapshot and a
persistent 1 s `bpy.app.timers` callback drains command intents
(`surfaces/blender/brokkr_bridge/__init__.py:610-647`, `:668-671`). What it lacks is
everything that makes two people in one scene a collaboration rather than a remote
control:
- an agent edit is not an undo step (research `nibu-body:research:blender-live-collab.brokkr-undo`);
- nobody can tell who made an edit: the Blender side reads no `requestedBy`
(`.brokkr-attribution-gate`);
- the human cannot stop an agent except by unticking a preference, and a queued intent
still runs if she ticks it back;
- the agent sees names and counts, not the viewport and not the Edit Mode selection
(`.brokkr-perception`);
- nothing stops an agent intent planned against an old scene from overwriting what she
did since;
- the agent has no hands: `brokkr-ctl` has no source (`.brokkr-no-agent-surface`).
Its strengths stay: typed, validated actions with no free-form Python, path
confinement, loopback bind and an optional session token (`.brokkr-security`).
## Prior art the design stands on
- **mcp-for-blender's `UserEditRecorder`** (`.mcp4b-human-edits`): buffers human
operator and undo/redo events with `undo_post`/`redo_post` handlers, attributes events
during an agent command to the agent, and hands the agent the human's activity before
its next action. We take the idea (the agent learns what the human did) and drop the
trajectory log: the snapshot carries per-object human-edit sequence numbers instead.
- **blender-copilot** (`.copilot-undo-cancel`): one undo step per agent turn, a Stop
button, visible turns and an undo receipt, no approval gate. Its Stop cannot interrupt
a blocking native call. We take all four and accept the same limit.
- **Multi-User** (`.humans-multiuser`) and the paid collab add-ons (`.humans-others`):
presence of the other party in the 3D view, rights and object locks. We take presence
as a panel, derived from intents and receipts; human-to-human replication is theirs,
not ours.
- **Blender Lab MCP and mcp-for-blender** (`.lab-official`, `.mcp4b-perception-safe`):
viewport screenshots as perception; arbitrary code with a weak or default-off
sandbox, and no undo. The perception we copy; the code path is fork Q1.
- **ceeyang/blender_mcp** (`.ceeyang-159`): 159 typed tools, every write undoable. The
existence proof that a typed vocabulary can be wide.
- The brush-tree campaign's `one-commit-primitive` (Libby's mind): a stale base is
refused, never merged. The conflict rule below is the same rule applied to a live scene.
## What probing established (Blender 5.3.0, Starfire, GUI, `--factory-startup`)
Probe scripts: `docs/research/live-collab/probe_timer_undo.py` and `probe_look.py`.
Each step runs in its own timer tick, as Brokkr's drain does.
1. **A write from a timer with no undo push is not a step, and it survives undo.** The
cube moved to x=1 with no push; one `ed.undo` left it at x=1. The next push captured
it, so the agent's write became part of the next step, whoever made it (case A). The
vendor warning (`.undo-timer-warning`) is real for unpushed writes, and the failure is
worse than "not undoable": the edit is misattributed.
2. **An explicit `ed.undo_push` from a timer makes a correct step.** x=2 pushed, x=3
pushed; undo gave 2, undo gave 1 (the earlier step), redo gave 2 (case B).
3. **An UNDO-flagged operator called from a timer pushes its own step.** A sphere added
by `primitive_uv_sphere_add` vanished on one undo with no explicit push (case C). An
action that calls two operators therefore makes two steps unless told otherwise.
4. **Operators called with `undo=False` push nothing; one explicit push then covers
them.** Cube and cone added with `("EXEC_DEFAULT", False)`, one push, one undo removed
both, a second undo changed nothing (case E). This is the mechanism for "one intent,
one step".
5. **Edit Mode:** a bmesh write plus push in Edit Mode is reverted by one undo, and that
undo also left Edit Mode (the agent had entered it in the same probe); the mesh kept
its original vertex (case D). Mode entry and the agent step are not cleanly separable
when the agent itself changed mode. Not yet probed: the human in Edit Mode and the
agent writing.
6. **Driving `ed.undo`/`ed.redo` programmatically from timers crashed Blender 2 of 2
times** in the long sequence (A through E in one session), with
`EXCEPTION_ACCESS_VIOLATION` in UI draw code after a memfile undo
(`outliner_draw_restrictbuts`, then `psys_get_current` from the properties editor). The
short sequences (C alone, D alone, E alone) did not crash. Cause not isolated; the
probe's own `temp_override` with a captured region is a suspect.
7. **The agent can see what the human sees.** `bpy.ops.screen.screenshot_area` on the
3D view from a timer: 7 of 7 `FINISHED`, median 72.5 ms over runs 2-7 at 1574x888,
about 609 KB PNG, and it captured the splash screen over the viewport, so it is the
human's view, overlays and popups included. Each capture stalls her UI for that long.
8. **Edit Mode selection reads live** through `bmesh.from_edit_mesh` without leaving Edit
Mode: selected vertices `[0, 3]`, 0.013 ms, mode still `EDIT_MESH`.
Not yet probed, and owed before the cut that depends on it: whether depsgraph updates
caused by an agent intent arrive inside the timer callback or after it returns (this
decides how human edits are told from agent edits); and whether a human Ctrl+Z inside a
pending agent intent's base window can be detected reliably by `undo_post`.
## Design truths
**One agent turn primitive.** Every agent mutation in Blender goes through one function
in the add-on: admit (sink enabled, `requestedBy` present, id unused, base fresh), run
the action with every operator called `undo=False`, push exactly one undo step labelled
`Brokkr <requestedBy>: <action> <commandId[:8]>`, write the receipt. A refusal or a
failure pushes nothing and leaves the scene as it was. Typed actions, the node actions,
and `run` if Q1 keeps it, all use it; there is no second writer.
**Undo belongs to the human.** Blender's one linear stack is the shared history. The
agent's steps sit in it, labelled, between hers; she undoes them with Ctrl+Z like her
own. The agent never calls `ed.undo` or `ed.redo` (probe 6); an agent that wants to back
out sends a new compensating intent, which is one more step. Undoing an agent step that
sits under later human steps is not offered: Blender's stack is linear and per-user undo
is out of scope.
**Stop is one control, and only the human holds it.** The Brokkr panel's Stop turns the
command sink off and gives every pending intent a `stopped` receipt without running it.
An action already running finishes (a blocking native call cannot be interrupted, as in
blender-copilot); it is one undo step, so Stop plus Ctrl+Z always returns her scene. No
intent can turn the sink on. Re-enabling is a fresh decision, and intents queued before
Stop never run.
**The agent sees her view and her edits.** `look` is a read intent: it captures her 3D
view to a scratch PNG named by command id (ruling `brush-tree:ruling:look-files-are-scratch`)
and returns the path; it pushes no undo step. The snapshot gains the Edit Mode selection
and a Blender session id plus human-edit sequence numbers: one counter for the session,
the last sequence at which the human touched each object, and the last sequence at which
she undid or redid. The agent reads "what changed since I last looked" from those.
**A human edit is never silently overwritten.** Every mutating intent names the base
sequence it was planned against. If the human touched any datablock the intent targets
since that base, or undid or redid since it, or the session id changed, the intent is
refused with a `conflict` receipt naming what changed, and nothing is applied. The
agent looks again and re-plans. Granularity is fork Q3.
**Presence is derived.** The panel shows which agents have intents or receipts in the
last minutes, the running or last intent with its one-line `note`, and the recent
receipts with their undo labels. It reads the intent and receipt documents; it owns no
state of its own.
**Hands are a CLI.** `brokkr-ctl blender` (Rust, ruling `brush-tree:ruling:fitting-home-ruled`)
writes intents and reads receipts and snapshots through the Blender mirror store
(`brush-tree:ruling:blender-transport-ruled`), prints plain text or paths, and its
`--help` is the schema (`brush-tree:ruling:cli-not-mcp`, `:help-is-the-schema`). It owns
no state, policy or ledger (brush-tree target invariant `brokkr-authority-holds`).
## Authority map
- **Owner.** The add-on's agent turn primitive owns whether and how an agent intent
changes the live scene. Blender owns scene truth and the undo stack. The human owns
the sink toggle, Stop, and undo.
- **Inputs.** Intent documents; the snapshot's human-edit sequences; the sink toggle.
- **Outputs.** One undo step per accepted mutating intent; one receipt per intent;
the refreshed snapshot; look PNG paths.
- **Derived state.** Presence (from intents and receipts). Human-edit sequences
(from depsgraph and undo handlers, observations only). Look PNGs (telemetry).
- **Forbidden writers.** `execute_command` called outside the primitive; operators
called with undo on inside an agent action; any raw RNA write by an agent without the
closing push; `ed.undo`/`ed.redo` from add-on code; the debug-mirror JSON import
(`blender_target.py` `_import_debug_command_files`) as a second door for intents;
`brokkr-ctl` opening the store to decide anything.
- **Shared paths.** brokkr-ctl intents, panel buttons that act on the scene, sync-organ
intents from `brokkr-daemon sync-once`, and replayed intents use the one primitive.
- **Deletion line.** The debug-mirror intent import goes before the primitive lands;
`drain_commands` stops calling `execute_command` directly.
## Identity, lifecycle and authority
| Persistent kind | What names it | What happens to it over time | Who decides |
|---|---|---|---|
| Blender command intent `brokkr.blender.command_intent.v0` (gains `requestedBy`, `baseSeq`, `note`) | `blender/commands/{commandId}`; ids single-use, minted by the writer (Unity F6 A, `brush-tree:ruling:blender-sink-mirrors-unity`) | Written once by a caller. Executed at most once or refused. Removed when its receipt is written, as today. Never rewritten. | Callers write. The agent turn primitive alone decides admission and execution. |
| Blender command receipt `brokkr.blender.command_receipt.v0` (gains `requestedBy`, `outcome` in accepted, denied, conflict, stopped, failed, `undoLabel`, `lookPath`, and for `run` the script text and SHA-256) | `blender/receipts/{commandId}`, one per intent | Written once, after the primitive decides. Pruned by count with Unity's cap and prune rule. The only proof an intent ran. | The primitive alone. Callers and the panel read. |
| Agent identity `requestedBy` | `<mind>/<agent>` stated by the caller (brokkr-ctl takes it from `EUREKA_INSTANCE` and a flag) | Carried on each intent into its receipt and undo label; not stored on its own. | The caller states it; the primitive refuses an intent without it. The session token proves admission, not identity. |
| Agent undo step | Blender undo stack entry labelled `Brokkr <requestedBy>: <action> <commandId[:8]>` | Pushed once per accepted mutating intent; lives as Blender's stack does (step limit, file load); never persisted by Brokkr. | Blender owns the stack. The primitive pushes. Only the human undoes or redoes. |
| Blender session id | uuid minted at add-on register and on each `load_post` | Replaced when Blender restarts or a file loads; every older base is then stale. | The add-on alone. |
| Human-edit sequences (snapshot fields: `humanEditSeq`, per-object `lastHumanEditSeq`, `lastUndoSeq`) | Integers within a session id | Monotonic within a session; reset with it. Observations, never scene truth. | The add-on's depsgraph and undo handlers alone. |
| Host snapshot `brokkr.blender.host_snapshot.v0` (gains Edit Mode selection, session id, the sequences above, sink state) | `blender/host/current`, overwritten | Refreshed on depsgraph update and after each intent. | The add-on alone. |
| Command sink toggle (the existing `auto_drain_commands` preference) | Add-on preference, echoed in the snapshot | Off by default. Stop turns it off; only the human turns it on. | The human only. No intent writes it. |
| Script toggle (only if Q1 = b) | A second add-on preference, echoed in the snapshot | Off by default, independent of the sink. | The human only. |
| Look PNG | `<scratch>/look/{commandId}.png` | Pruned by count; never read back as truth. | The primitive writes; `brush-tree:ruling:look-files-are-scratch` governs. |
## Not in scope
Human-to-human replication or several Blender instances in one session (Multi-User's
domain). Agents on another host reaching the operator's Blender: the transport is not
widened beyond what the add-on serves today. Per-user or selective undo. An approval gate
before each agent action (unless Q2 rules otherwise). A 3D-view overlay of the agent's
presence; the panel carries presence in this revision. The Unity surface and
`brokkr-command`. The brush-tree vocabulary, Geometry.Csg and OpenSCAD text (brush-tree
owns them). Agent-initiated save and quit (`brush-tree:ruling:run-admitted-when-enabled`
keeps them off the allowed list). Asset libraries and generators. An MCP server.
## Open forks (draft questions; Self admits)
- **Q1. Free-form Python.** Today the Blender add-on has no script action. Libby's
Defaulted ruling `brush-tree:ruling:run-admitted-when-enabled` would add `run`, admitted
whenever agent commands are on. Options: (a) typed actions only; (b) `run` behind its
own off-by-default toggle, one undo step, script text in the receipt; (c) the Defaulted
ruling as written. Recommend (b).
- **Q2. Act then undo, or approve first.** Recommend act then undo, with Stop.
- **Q3. Conflict granularity.** (a) any human edit since the base refuses; (b) only edits to
the intent's targets, plus any undo or redo. Recommend (b), after the depsgraph
attribution probe.
- **Q4. Who builds `brokkr-ctl blender`.** Recommend this campaign builds the session
subcommands in Rust per Libby's rulings, and brush-tree adds its tree commands to the
same binary later.

View file

@ -0,0 +1,68 @@
"""Probe: can a timer callback capture the 3D viewport the human sees, and read Edit Mode selection?
blender --factory-startup --python probe_look.py -- <out.json> <png_dir>
"""
import json
import os
import statistics
import sys
import time
import traceback
import bmesh
import bpy
args = sys.argv[sys.argv.index("--") + 1:]
OUT, PNG_DIR = args[0], args[1]
log = {"blender": bpy.app.version_string}
def ctx():
win = bpy.context.window_manager.windows[0]
area = next(a for a in win.screen.areas if a.type == "VIEW_3D")
region = next(r for r in area.regions if r.type == "WINDOW")
return win, area, region
def run():
win, area, region = ctx()
log["view3d_px"] = [region.width, region.height]
times = []
for n in range(7):
path = os.path.join(PNG_DIR, f"look-{n}.png")
t = time.perf_counter()
with bpy.context.temp_override(window=win, area=area, region=region):
r = bpy.ops.screen.screenshot_area(filepath=path)
times.append((time.perf_counter() - t) * 1000)
log.setdefault("results", []).append(list(r))
log["screenshot_ms"] = [round(x, 1) for x in times]
log["screenshot_ms_median"] = round(statistics.median(times[1:]), 1)
log["png_bytes"] = os.path.getsize(os.path.join(PNG_DIR, "look-6.png"))
# Edit Mode selection read, live, without leaving Edit Mode.
with bpy.context.temp_override(window=win, area=area, region=region):
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_all(action="DESELECT")
bm = bmesh.from_edit_mesh(bpy.data.objects["Cube"].data)
bm.verts.ensure_lookup_table()
bm.verts[0].select = True
bm.verts[3].select = True
bm.select_flush_mode()
t = time.perf_counter()
sel = [v.index for v in bmesh.from_edit_mesh(bpy.data.objects["Cube"].data).verts if v.select]
log["edit_selection_read_ms"] = round((time.perf_counter() - t) * 1000, 3)
log["edit_selected_verts"] = sel
log["mode_after_read"] = bpy.context.mode
def tick():
try:
run()
except Exception:
log["error"] = traceback.format_exc()
with open(OUT, "w") as f:
json.dump(log, f, indent=1)
bpy.ops.wm.quit_blender()
return None
bpy.app.timers.register(tick, first_interval=3.0)

View file

@ -0,0 +1,146 @@
"""Probe: do edits made from a bpy.app.timers callback land on Blender's undo stack?
Run in GUI Blender: blender --factory-startup --python probe_timer_undo.py -- <out.json> [cases, e.g. AB]
Each step is its own timer tick so the event loop runs between steps, as it does
for Brokkr's 1 s drain. Results are written to the JSON path, then Blender quits.
"""
import json
import sys
import traceback
import bmesh
import bpy
OUT = sys.argv[sys.argv.index("--") + 1]
log = {"blender": bpy.app.version_string, "background": bpy.app.background, "steps": []}
def win_ctx():
win = bpy.context.window_manager.windows[0]
area = next(a for a in win.screen.areas if a.type == "VIEW_3D")
return bpy.context.temp_override(window=win, area=area, region=area.regions[-1])
def cube():
return bpy.data.objects.get("Cube")
def state(tag):
c = cube()
s = {
"tag": tag,
"cube_x": round(c.location.x, 3) if c else None,
"objects": sorted(o.name for o in bpy.data.objects),
"mode": bpy.context.mode,
"mesh_v0_z": round(c.data.vertices[0].co.z, 3) if c else None,
}
if c and c.mode == "EDIT":
bm = bmesh.from_edit_mesh(c.data)
bm.verts.ensure_lookup_table()
s["edit_v0_z"] = round(bm.verts[0].co.z if bm.verts else 0, 3)
log["steps"].append(s)
return s
def push(msg):
with win_ctx():
r = bpy.ops.ed.undo_push(message=msg)
log["steps"].append({"tag": f"undo_push:{msg}", "result": list(r)})
def undo():
with win_ctx():
r = bpy.ops.ed.undo()
log["steps"].append({"tag": "undo", "result": list(r)})
def redo():
with win_ctx():
r = bpy.ops.ed.redo()
log["steps"].append({"tag": "redo", "result": list(r)})
# Case A: raw RNA write from a timer, no push. Does Ctrl+Z see it as its own step?
# Case B: RNA write then an explicit undo_push from the timer.
# Case C: an UNDO-flagged operator called from a timer, no explicit push.
# Case D: Edit Mode bmesh write from a timer then undo_push.
# Case E: two operators called with undo=False, then one explicit undo_push.
ONLY = sys.argv[sys.argv.index("--") + 2] if len(sys.argv) > sys.argv.index("--") + 2 else "ABCDE"
steps = [
lambda: (push("baseline"), state("A0 baseline")),
lambda: (setattr(cube().location, "x", 1.0), state("A1 raw write x=1, no push")),
lambda: (undo(), state("A2 after one undo")),
lambda: (push("rebase-B"), state("B0")),
lambda: (setattr(cube().location, "x", 2.0), push("agent: x=2"), state("B1 x=2 pushed")),
lambda: (setattr(cube().location, "x", 3.0), push("agent: x=3"), state("B2 x=3 pushed")),
lambda: (undo(), state("B3 after undo (expect x=2)")),
lambda: (undo(), state("B4 after second undo (expect x=0)")),
lambda: (redo(), state("B5 after redo (expect x=2)")),
lambda: (push("rebase-C"), state("C0")),
lambda: (_add_sphere(), state("C1 op add sphere, no push")),
lambda: (undo(), state("C2 after undo (sphere gone?)")),
lambda: (bpy.context.view_layer.objects.__setattr__("active", cube()), cube().select_set(True), push("rebase-D"), state("D0")),
lambda: (_edit_enter(), state("D1 edit mode")),
lambda: (_edit_write(), push("agent: edit v0"), state("D2 v0 moved, pushed")),
lambda: (undo(), state("D3 after undo (expect v0 back)")),
lambda: (undo(), state("D4 after second undo")),
lambda: (_edit_exit(), push("rebase-E"), state("E0")),
lambda: (_two_ops_one_step(), push("agent: two ops"), state("E1 two ops undo=False + one push")),
lambda: (undo(), state("E2 after one undo (expect both gone)")),
lambda: (undo(), state("E3 after second undo (expect no change)")),
]
def _add_sphere():
with win_ctx():
bpy.ops.mesh.primitive_uv_sphere_add(location=(5, 0, 0))
def _edit_exit():
if bpy.context.mode != "OBJECT":
with win_ctx():
bpy.ops.object.mode_set(mode="OBJECT")
def _two_ops_one_step():
with win_ctx():
bpy.ops.mesh.primitive_cube_add("EXEC_DEFAULT", False, location=(0, 4, 0))
bpy.ops.mesh.primitive_cone_add("EXEC_DEFAULT", False, location=(0, -4, 0))
def _edit_enter():
with win_ctx():
bpy.ops.object.mode_set(mode="EDIT")
def _edit_write():
c = cube()
bm = bmesh.from_edit_mesh(c.data)
bm.verts.ensure_lookup_table()
bm.verts[0].co.z += 5.0
bmesh.update_edit_mesh(c.data)
i = 0
_all = steps
steps = [f for f, c in zip(_all, "AAABBBBBBCCCDDDDDEEEE") if c in ONLY]
def tick():
global i
if i < len(steps):
try:
steps[i]()
except Exception:
log["steps"].append({"tag": f"step {i} error", "error": traceback.format_exc()})
i += 1
with open(OUT, "w") as f:
json.dump(log, f, indent=1)
return 0.3
with open(OUT, "w") as f:
json.dump(log, f, indent=1)
bpy.ops.wm.quit_blender()
return None
bpy.app.timers.register(tick, first_interval=2.0)