pmx-canvas 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +128 -0
- package/Readme.md +19 -6
- package/dist/canvas/global.css +35 -2
- package/dist/canvas/index.js +70 -69
- package/dist/json-render/index.js +109 -109
- package/dist/types/client/canvas/CanvasViewport.d.ts +1 -1
- package/dist/types/client/icons.d.ts +2 -0
- package/dist/types/client/state/canvas-store.d.ts +2 -0
- package/dist/types/client/types.d.ts +2 -1
- package/dist/types/json-render/charts/components.d.ts +5 -1
- package/dist/types/json-render/renderer/index.d.ts +1 -0
- package/dist/types/json-render/server.d.ts +1 -0
- package/dist/types/mcp/canvas-access.d.ts +3 -0
- package/dist/types/server/canvas-operations.d.ts +4 -0
- package/dist/types/server/canvas-schema.d.ts +19 -3
- package/dist/types/server/canvas-serialization.d.ts +1 -0
- package/dist/types/server/canvas-state.d.ts +8 -2
- package/dist/types/server/html-primitives.d.ts +34 -0
- package/dist/types/server/index.d.ts +19 -0
- package/docs/RELEASE.md +153 -0
- package/docs/bun-webview-integration.md +296 -0
- package/docs/cli.md +143 -0
- package/docs/evals/e2e-cli-coverage.md +61 -0
- package/docs/http-api.md +201 -0
- package/docs/mcp.md +137 -0
- package/docs/node-types.md +272 -0
- package/docs/plans/.gitkeep +0 -0
- package/docs/plans/plan-001-semantic-watch-mvp.md +335 -0
- package/docs/plans/plan-002-human-attention-layer-design-spec.md +679 -0
- package/docs/plans/plan-003-human-attention-layer-implementation-plan.md +572 -0
- package/docs/reactive-canvas-proposal.md +578 -0
- package/docs/release-review-0.1.0.md +38 -0
- package/docs/screenshot.png +0 -0
- package/docs/screenshots/demo-workbench-dark.png +0 -0
- package/docs/screenshots/demo-workbench-light.png +0 -0
- package/docs/screenshots/welcome-dark.png +0 -0
- package/docs/screenshots/welcome-light.png +0 -0
- package/docs/sdk.md +103 -0
- package/package.json +2 -1
- package/skills/pmx-canvas/SKILL.md +8 -0
- package/src/cli/agent.ts +167 -5
- package/src/client/App.tsx +20 -1
- package/src/client/canvas/AnnotationLayer.tsx +33 -12
- package/src/client/canvas/CanvasViewport.tsx +88 -7
- package/src/client/canvas/CommandPalette.tsx +1 -1
- package/src/client/canvas/ContextMenu.tsx +2 -2
- package/src/client/canvas/ExpandedNodeOverlay.tsx +7 -1
- package/src/client/icons.tsx +13 -0
- package/src/client/nodes/McpAppNode.tsx +12 -4
- package/src/client/state/canvas-store.ts +15 -5
- package/src/client/state/sse-bridge.ts +4 -3
- package/src/client/theme/global.css +35 -2
- package/src/client/types.ts +2 -1
- package/src/json-render/charts/components.tsx +41 -7
- package/src/json-render/charts/extra-components.tsx +13 -12
- package/src/json-render/renderer/index.tsx +1 -0
- package/src/json-render/server.ts +3 -1
- package/src/mcp/canvas-access.ts +25 -0
- package/src/mcp/server.ts +85 -27
- package/src/server/agent-context.ts +17 -0
- package/src/server/canvas-operations.ts +91 -38
- package/src/server/canvas-schema.ts +83 -3
- package/src/server/canvas-serialization.ts +9 -2
- package/src/server/canvas-state.ts +27 -9
- package/src/server/demo-state.json +1143 -0
- package/src/server/demo.ts +25 -777
- package/src/server/html-primitives.ts +990 -0
- package/src/server/index.ts +43 -2
- package/src/server/server.ts +140 -14
- package/src/server/spatial-analysis.ts +3 -3
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Semantic Watch CLI MVP
|
|
3
|
+
status: draft
|
|
4
|
+
date: 2026-04-18
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Semantic Watch CLI MVP
|
|
8
|
+
|
|
9
|
+
## Summary
|
|
10
|
+
|
|
11
|
+
Add a new agent-facing CLI command:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pmx-canvas watch
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The command connects to the existing `/api/workbench/events` SSE stream and emits
|
|
18
|
+
compact, low-token summaries of **meaningful human intent changes** on the canvas.
|
|
19
|
+
|
|
20
|
+
This is **not** a raw browser telemetry tap. The watcher consumes authoritative
|
|
21
|
+
server events, keeps prior layout state locally, computes semantic diffs locally,
|
|
22
|
+
and emits one compact line or one JSON object only when the canvas state makes a
|
|
23
|
+
changed intent legible.
|
|
24
|
+
|
|
25
|
+
## Problem
|
|
26
|
+
|
|
27
|
+
PMX Canvas promises that spatial arrangement is communication and that pinned
|
|
28
|
+
context closes the human-to-agent loop. In practice, only pins cross that
|
|
29
|
+
boundary reliably today.
|
|
30
|
+
|
|
31
|
+
The current gap:
|
|
32
|
+
|
|
33
|
+
- agents can poll resources like `canvas://pinned-context` and
|
|
34
|
+
`canvas://spatial-context`
|
|
35
|
+
- browsers receive rich SSE updates
|
|
36
|
+
- there is no CLI primitive that turns those updates into a low-noise,
|
|
37
|
+
low-token stream that an agent or hook can follow
|
|
38
|
+
|
|
39
|
+
## Goals
|
|
40
|
+
|
|
41
|
+
- Provide a long-running `watch` command for agents and hooks.
|
|
42
|
+
- Reuse the existing `/api/workbench/events` SSE stream.
|
|
43
|
+
- Reduce full layout snapshots into compact semantic deltas locally.
|
|
44
|
+
- Keep token cost low by suppressing raw gesture noise.
|
|
45
|
+
- Expose a machine-readable mode for hooks and automation.
|
|
46
|
+
|
|
47
|
+
## Non-Goals
|
|
48
|
+
|
|
49
|
+
- No new browser-only collaboration protocol.
|
|
50
|
+
- No raw pointer, drag-frame, or selection telemetry.
|
|
51
|
+
- No `select` event in v1.
|
|
52
|
+
- No `collapse` event in v1 until collapsed state is synced immediately and
|
|
53
|
+
authoritatively to the server.
|
|
54
|
+
- No node content/body text in watch output.
|
|
55
|
+
- No attempt to narrate every movement; only semantic movement changes.
|
|
56
|
+
|
|
57
|
+
## Authoritative Signal Sources
|
|
58
|
+
|
|
59
|
+
The command must only depend on signals the server can already observe.
|
|
60
|
+
|
|
61
|
+
### Existing sources
|
|
62
|
+
|
|
63
|
+
- `GET /api/workbench/events`
|
|
64
|
+
- initial `canvas-layout-update` snapshot on connect
|
|
65
|
+
- subsequent `canvas-layout-update` envelopes on node/edge/layout mutations
|
|
66
|
+
- `context-pins-changed` on pin updates
|
|
67
|
+
- `GET /api/canvas/pinned-context`
|
|
68
|
+
- initial current pin set on watcher startup
|
|
69
|
+
- local semantic derivation using `buildSpatialContext(...)`
|
|
70
|
+
|
|
71
|
+
### Explicitly excluded from v1
|
|
72
|
+
|
|
73
|
+
- client-only `selectedNodeIds`
|
|
74
|
+
- locally toggled `collapsed` state that has not yet been persisted
|
|
75
|
+
|
|
76
|
+
## CLI UX
|
|
77
|
+
|
|
78
|
+
### Command
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pmx-canvas watch [options]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Output modes
|
|
85
|
+
|
|
86
|
+
- Default: compact human-readable lines
|
|
87
|
+
- `--compact`: explicit compact mode (same as default)
|
|
88
|
+
- `--json`: emit one JSON object per semantic event, JSONL-style
|
|
89
|
+
|
|
90
|
+
`--compact` and `--json` are mutually exclusive.
|
|
91
|
+
|
|
92
|
+
### Filters
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
--events context-pin,move-end,group,connect,remove
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Supported semantic event kinds in v1:
|
|
99
|
+
|
|
100
|
+
- `context-pin`
|
|
101
|
+
- `move-end`
|
|
102
|
+
- `group`
|
|
103
|
+
- `connect`
|
|
104
|
+
- `remove`
|
|
105
|
+
|
|
106
|
+
If omitted, all v1 semantic kinds are enabled.
|
|
107
|
+
|
|
108
|
+
### Control flags
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
--max-events 3
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Stop after emitting N semantic events. This exists mainly to support scripted
|
|
115
|
+
usage and unit tests without changing the default streaming behavior.
|
|
116
|
+
|
|
117
|
+
## Event Model
|
|
118
|
+
|
|
119
|
+
### 1. `context-pin`
|
|
120
|
+
|
|
121
|
+
Source:
|
|
122
|
+
|
|
123
|
+
- direct `context-pins-changed` SSE event
|
|
124
|
+
|
|
125
|
+
Payload:
|
|
126
|
+
|
|
127
|
+
- added pinned node IDs/titles
|
|
128
|
+
- removed pinned node IDs/titles
|
|
129
|
+
|
|
130
|
+
Rules:
|
|
131
|
+
|
|
132
|
+
- emit only when the pin set actually changed
|
|
133
|
+
- do not emit on startup bootstrap
|
|
134
|
+
|
|
135
|
+
Compact example:
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
context-pin +2 -1: "Bug report", "auth.ts" | removed: "old note"
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
JSON example:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{"type":"context-pin","added":[{"id":"n1","title":"Bug report","nodeType":"markdown"}],"removed":[]}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 2. `connect`
|
|
148
|
+
|
|
149
|
+
Source:
|
|
150
|
+
|
|
151
|
+
- added edges in a `canvas-layout-update` diff
|
|
152
|
+
|
|
153
|
+
Payload:
|
|
154
|
+
|
|
155
|
+
- added edges with `from`, `to`, edge type, and node titles when available
|
|
156
|
+
|
|
157
|
+
Rules:
|
|
158
|
+
|
|
159
|
+
- emit for newly added edges only
|
|
160
|
+
- ignore unchanged edges
|
|
161
|
+
|
|
162
|
+
Compact example:
|
|
163
|
+
|
|
164
|
+
```text
|
|
165
|
+
connect 1: "Bug report" -> "auth.ts" (relation)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 3. `remove`
|
|
169
|
+
|
|
170
|
+
Source:
|
|
171
|
+
|
|
172
|
+
- removed nodes and removed edges in a `canvas-layout-update` diff
|
|
173
|
+
|
|
174
|
+
Payload:
|
|
175
|
+
|
|
176
|
+
- removed node summaries
|
|
177
|
+
- removed edge summaries
|
|
178
|
+
|
|
179
|
+
Rules:
|
|
180
|
+
|
|
181
|
+
- emit only for removals after bootstrap
|
|
182
|
+
- group all removals from one layout update into one semantic event
|
|
183
|
+
|
|
184
|
+
Compact example:
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
remove 2 nodes: "Old note", "scratch.ts"
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 4. `group`
|
|
191
|
+
|
|
192
|
+
Source:
|
|
193
|
+
|
|
194
|
+
- group node creation or group membership change detected from layout diffs
|
|
195
|
+
|
|
196
|
+
Payload:
|
|
197
|
+
|
|
198
|
+
- created groups
|
|
199
|
+
- membership changes for existing groups
|
|
200
|
+
- child additions/removals by group
|
|
201
|
+
|
|
202
|
+
Rules:
|
|
203
|
+
|
|
204
|
+
- treat new `group` nodes as group creation
|
|
205
|
+
- compare `group.data.children` arrays for membership deltas
|
|
206
|
+
- emit one grouped summary per layout update
|
|
207
|
+
|
|
208
|
+
Compact examples:
|
|
209
|
+
|
|
210
|
+
```text
|
|
211
|
+
group created: "API Group" (2 children)
|
|
212
|
+
group updated: "API Group" +1 -0 children
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 5. `move-end`
|
|
216
|
+
|
|
217
|
+
Source:
|
|
218
|
+
|
|
219
|
+
- node position changes between two `canvas-layout-update` snapshots
|
|
220
|
+
|
|
221
|
+
Important:
|
|
222
|
+
|
|
223
|
+
- derive from **layout diffs**, not pointer events
|
|
224
|
+
- emit only when movement caused a semantic change
|
|
225
|
+
|
|
226
|
+
Semantic triggers:
|
|
227
|
+
|
|
228
|
+
- the moved node’s proximity-cluster peers changed
|
|
229
|
+
- the moved node entered or left a pinned neighborhood
|
|
230
|
+
- a pinned node moved and its neighborhood changed
|
|
231
|
+
|
|
232
|
+
Rules:
|
|
233
|
+
|
|
234
|
+
- suppress pure coordinate churn
|
|
235
|
+
- suppress movement that did not change spatial meaning
|
|
236
|
+
- ignore newly created or removed nodes when computing move-end
|
|
237
|
+
|
|
238
|
+
Compact examples:
|
|
239
|
+
|
|
240
|
+
```text
|
|
241
|
+
move-end: "auth.ts" cluster changed
|
|
242
|
+
move-end: "session.ts" entered pinned neighborhood of "Bug report"
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Bootstrap Behavior
|
|
246
|
+
|
|
247
|
+
On startup:
|
|
248
|
+
|
|
249
|
+
1. fetch current pins from `/api/canvas/pinned-context`
|
|
250
|
+
2. connect to `/api/workbench/events`
|
|
251
|
+
3. accept the initial `canvas-layout-update` snapshot as the baseline
|
|
252
|
+
4. emit nothing during bootstrap
|
|
253
|
+
|
|
254
|
+
This avoids startup noise and prevents the watcher from replaying the whole
|
|
255
|
+
canvas as if it were a fresh user action stream.
|
|
256
|
+
|
|
257
|
+
## Local Reduction Algorithm
|
|
258
|
+
|
|
259
|
+
Maintain local watcher state:
|
|
260
|
+
|
|
261
|
+
- `currentLayout`
|
|
262
|
+
- `currentPinnedIds`
|
|
263
|
+
- derived `previousSpatialContext`
|
|
264
|
+
|
|
265
|
+
On each relevant SSE event:
|
|
266
|
+
|
|
267
|
+
### `context-pins-changed`
|
|
268
|
+
|
|
269
|
+
- diff old pin set vs new pin set
|
|
270
|
+
- emit `context-pin` if changed
|
|
271
|
+
- update `currentPinnedIds`
|
|
272
|
+
- recompute local spatial context baseline
|
|
273
|
+
|
|
274
|
+
### `canvas-layout-update`
|
|
275
|
+
|
|
276
|
+
- if no baseline exists, store it and stop
|
|
277
|
+
- diff previous layout vs next layout
|
|
278
|
+
- emit `connect`, `remove`, and `group` events from structural diffs
|
|
279
|
+
- compute old/new spatial context with the current pin set
|
|
280
|
+
- detect moved nodes
|
|
281
|
+
- emit `move-end` only for nodes whose movement changed:
|
|
282
|
+
- cluster peers
|
|
283
|
+
- pinned-neighborhood membership
|
|
284
|
+
- replace baseline with the new layout/spatial context
|
|
285
|
+
|
|
286
|
+
## Token Budget Rules
|
|
287
|
+
|
|
288
|
+
The watcher exists to save tokens, so its output contract must stay strict.
|
|
289
|
+
|
|
290
|
+
Rules:
|
|
291
|
+
|
|
292
|
+
- no full layout snapshots in emitted output
|
|
293
|
+
- no node body text or file content
|
|
294
|
+
- no duplicate emission for unchanged semantic state
|
|
295
|
+
- one semantic event object/line per meaning change, not per low-level SSE frame
|
|
296
|
+
- compact mode should usually stay under one short line per event
|
|
297
|
+
|
|
298
|
+
## Implementation Plan
|
|
299
|
+
|
|
300
|
+
### Files
|
|
301
|
+
|
|
302
|
+
- add a new CLI watcher module for:
|
|
303
|
+
- SSE parsing
|
|
304
|
+
- semantic reduction
|
|
305
|
+
- compact/JSON formatting
|
|
306
|
+
- wire the command into `src/cli/agent.ts`
|
|
307
|
+
- add `watch` to `src/cli/index.ts` command help/router
|
|
308
|
+
- add unit coverage for:
|
|
309
|
+
- context pin diffs
|
|
310
|
+
- connect/remove diffs
|
|
311
|
+
- group diffs
|
|
312
|
+
- move-end semantic suppression and emission
|
|
313
|
+
|
|
314
|
+
### Reuse
|
|
315
|
+
|
|
316
|
+
- reuse `/api/workbench/events`
|
|
317
|
+
- reuse `/api/canvas/pinned-context`
|
|
318
|
+
- reuse `buildSpatialContext(...)`
|
|
319
|
+
|
|
320
|
+
## Verification Plan
|
|
321
|
+
|
|
322
|
+
- unit tests for semantic reducer behavior
|
|
323
|
+
- unit tests for CLI watch output/filtering
|
|
324
|
+
- `bun run test`
|
|
325
|
+
|
|
326
|
+
If implementation touches browser-visible UI or client code later, escalate
|
|
327
|
+
verification. For this MVP, CLI/server-side verification is expected to be
|
|
328
|
+
sufficient.
|
|
329
|
+
|
|
330
|
+
## Deferred Work
|
|
331
|
+
|
|
332
|
+
- watchable `collapse` after immediate server sync exists
|
|
333
|
+
- explicit `cluster-changed` or `neighborhood-changed` top-level event kinds
|
|
334
|
+
- reconnect/backoff behavior for long-lived watches
|
|
335
|
+
- MCP-side semantic watcher surface if needed later
|