pmx-canvas 0.4.6 → 0.4.7
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 +62 -0
- package/Readme.md +56 -33
- package/dist/canvas/global.css +101 -3
- package/dist/canvas/index.js +87 -83
- package/dist/types/cli/shared.d.ts +13 -1
- package/dist/types/client/canvas/CanvasNode.d.ts +11 -0
- package/dist/types/client/canvas/EdgeLayer.d.ts +8 -0
- package/dist/types/client/nodes/AxStepControls.d.ts +4 -0
- package/dist/types/client/nodes/FileNode.d.ts +14 -0
- package/dist/types/client/state/canvas-store.d.ts +10 -0
- package/dist/types/client/state/intent-bridge.d.ts +9 -0
- package/dist/types/server/ax-flow-loop.d.ts +5 -0
- package/dist/types/server/ax-interaction.d.ts +21 -2
- package/dist/types/server/canvas-operations.d.ts +5 -0
- package/dist/types/server/canvas-state.d.ts +8 -0
- package/dist/types/server/canvas-validation.d.ts +15 -21
- package/dist/types/server/file-content.d.ts +46 -0
- package/dist/types/server/html-primitives.d.ts +13 -1
- package/dist/types/server/operations/ops/ax-work.d.ts +1 -0
- package/dist/types/server/server.d.ts +1 -0
- package/dist/types/server/web-artifacts.d.ts +14 -0
- package/dist/types/shared/ax-flow.d.ts +51 -0
- package/dist/types/shared/node-sizes.d.ts +33 -0
- package/docs/cli.md +19 -2
- package/docs/environment.md +1 -0
- package/docs/http-api.md +17 -0
- package/docs/mcp.md +12 -0
- package/docs/node-types.md +45 -1
- package/docs/screenshot.png +0 -0
- package/package.json +2 -2
- package/skills/pmx-canvas/SKILL.md +68 -7
- package/skills/pmx-canvas/evals/evals.json +54 -3
- package/skills/pmx-canvas/references/full-reference.md +11 -6
- package/src/cli/commands/history.ts +1 -1
- package/src/cli/commands/nodes.ts +2 -2
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/view.ts +1 -1
- package/src/cli/index.ts +6 -0
- package/src/cli/shared.ts +34 -5
- package/src/client/App.tsx +28 -15
- package/src/client/canvas/CanvasNode.tsx +54 -5
- package/src/client/canvas/EdgeLayer.tsx +44 -24
- package/src/client/canvas/ExpandedNodeOverlay.tsx +11 -0
- package/src/client/canvas/auto-fit.ts +10 -1
- package/src/client/canvas/use-pan-zoom.ts +16 -1
- package/src/client/nodes/AxStepControls.tsx +226 -0
- package/src/client/nodes/FileNode.tsx +249 -51
- package/src/client/state/canvas-store.ts +19 -0
- package/src/client/state/intent-bridge.ts +32 -0
- package/src/client/state/sse-bridge.ts +4 -1
- package/src/client/theme/global.css +101 -3
- package/src/server/ax-flow-loop.ts +114 -0
- package/src/server/ax-interaction.ts +299 -4
- package/src/server/canvas-operations.ts +44 -17
- package/src/server/canvas-state.ts +20 -10
- package/src/server/canvas-validation.ts +50 -41
- package/src/server/demo-state.json +4605 -523
- package/src/server/demo.ts +24 -0
- package/src/server/file-content.ts +152 -0
- package/src/server/file-watcher.ts +7 -10
- package/src/server/html-primitives.ts +636 -0
- package/src/server/operations/ops/ax-work.ts +5 -0
- package/src/server/operations/ops/nodes.ts +15 -1
- package/src/server/operations/ops/viewport.ts +7 -1
- package/src/server/server.ts +106 -5
- package/src/server/web-artifacts.ts +109 -0
- package/src/shared/ax-flow.ts +102 -0
- package/src/shared/node-sizes.ts +52 -0
- package/dist/types/server/chart-template.d.ts +0 -29
- package/src/server/chart-template.ts +0 -448
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'preact/hooks';
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'preact/hooks';
|
|
2
2
|
import { updateNodeData } from '../state/canvas-store';
|
|
3
|
+
import { iframeMode } from '../state/iframe-mode';
|
|
3
4
|
import { fetchFile, updateNodeFromClient } from '../state/intent-bridge';
|
|
4
5
|
import type { CanvasNodeState } from '../types';
|
|
5
6
|
import { runNodeAxInteraction } from './ax-node-actions';
|
|
@@ -39,20 +40,125 @@ function langFromPath(path: string): string {
|
|
|
39
40
|
return map[ext] ?? (ext.toUpperCase() || 'Text');
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
/** Rendered-row ceiling for delimited files — a 200k-row CSV must not lock the browser. */
|
|
44
|
+
const MAX_TABLE_ROWS = 500;
|
|
45
|
+
|
|
46
|
+
export interface DelimitedTable {
|
|
47
|
+
header: string[];
|
|
48
|
+
/** Rectangular: every row padded (short) or truncated (long) to the header width. */
|
|
49
|
+
rows: string[][];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Column delimiter for a delimited-data path, or null when the file is not one. */
|
|
53
|
+
function delimiterForPath(path: string): string | null {
|
|
54
|
+
const lower = path.toLowerCase();
|
|
55
|
+
if (lower.endsWith('.csv')) return ',';
|
|
56
|
+
if (lower.endsWith('.tsv')) return '\t';
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* RFC4180-ish delimited-text parser. Quoted fields may contain the delimiter,
|
|
62
|
+
* newlines, and `""` escapes; CRLF, LF and lone CR all end a record; a trailing
|
|
63
|
+
* newline produces no phantom empty row. Ragged records are squared off against
|
|
64
|
+
* the header width instead of throwing.
|
|
65
|
+
*/
|
|
66
|
+
export function parseDelimitedText(text: string, delimiter: string): DelimitedTable {
|
|
67
|
+
const records: string[][] = [];
|
|
68
|
+
let row: string[] = [];
|
|
69
|
+
let field = '';
|
|
70
|
+
let quoted = false;
|
|
71
|
+
// Tracks whether the current record consumed anything — distinguishes a real
|
|
72
|
+
// empty-quoted record from the dangling state after a terminating newline.
|
|
73
|
+
let started = false;
|
|
74
|
+
|
|
75
|
+
for (let i = 0; i < text.length; i++) {
|
|
76
|
+
const char = text[i];
|
|
77
|
+
started = true;
|
|
78
|
+
if (quoted) {
|
|
79
|
+
if (char === '"') {
|
|
80
|
+
if (text[i + 1] === '"') {
|
|
81
|
+
field += '"';
|
|
82
|
+
i++;
|
|
83
|
+
} else {
|
|
84
|
+
quoted = false;
|
|
85
|
+
}
|
|
86
|
+
} else if (char === '\r' && text[i + 1] === '\n') {
|
|
87
|
+
field += '\n';
|
|
88
|
+
i++;
|
|
89
|
+
} else {
|
|
90
|
+
field += char;
|
|
91
|
+
}
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (char === '"' && field === '') {
|
|
95
|
+
quoted = true;
|
|
96
|
+
} else if (char === delimiter) {
|
|
97
|
+
row.push(field);
|
|
98
|
+
field = '';
|
|
99
|
+
} else if (char === '\n' || char === '\r') {
|
|
100
|
+
if (char === '\r' && text[i + 1] === '\n') i++;
|
|
101
|
+
row.push(field);
|
|
102
|
+
field = '';
|
|
103
|
+
records.push(row);
|
|
104
|
+
row = [];
|
|
105
|
+
started = false;
|
|
106
|
+
} else {
|
|
107
|
+
field += char;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (started) {
|
|
111
|
+
row.push(field);
|
|
112
|
+
records.push(row);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const header = records.shift() ?? [];
|
|
116
|
+
return {
|
|
117
|
+
header,
|
|
118
|
+
rows: records.map((record) => Array.from({ length: header.length }, (_, i) => record[i] ?? '')),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Human-readable byte size, e.g. `4.2 MB`. */
|
|
123
|
+
export function formatBytes(bytes: number): string {
|
|
124
|
+
if (!Number.isFinite(bytes) || bytes < 0) return '';
|
|
125
|
+
if (bytes < 1024) return `${Math.round(bytes)} B`;
|
|
126
|
+
const units = ['KB', 'MB', 'GB', 'TB'];
|
|
127
|
+
let value = bytes / 1024;
|
|
128
|
+
let unit = 0;
|
|
129
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
130
|
+
value /= 1024;
|
|
131
|
+
unit++;
|
|
132
|
+
}
|
|
133
|
+
return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
42
136
|
export function FileNode({ node, expanded = false }: { node: CanvasNodeState; expanded?: boolean }) {
|
|
43
137
|
const filePath = (node.data.path as string) || (node.data.content as string) || '';
|
|
44
138
|
const title = (node.data.title as string) || filePath.split('/').pop() || 'File';
|
|
45
139
|
const cachedContent = node.data.fileContent as string | undefined;
|
|
46
140
|
const updatedAt = node.data.updatedAt as string | undefined;
|
|
47
141
|
const lineCount = node.data.lineCount as number | undefined;
|
|
142
|
+
const byteSize = node.data.byteSize as number | undefined;
|
|
143
|
+
const isBinary = node.data.binary === true;
|
|
144
|
+
const truncated = node.data.truncated === true;
|
|
145
|
+
const mimeType = node.data.mimeType as string | undefined;
|
|
146
|
+
const isPdf = mimeType === 'application/pdf' || filePath.toLowerCase().endsWith('.pdf');
|
|
147
|
+
// Binary bytes and PDFs are served raw — never fetched or decoded as text.
|
|
148
|
+
const servesBytes = isBinary || isPdf;
|
|
48
149
|
|
|
49
150
|
const [content, setContent] = useState<string>(cachedContent ?? '');
|
|
50
|
-
const [loading, setLoading] = useState(!cachedContent && !!filePath);
|
|
151
|
+
const [loading, setLoading] = useState(!cachedContent && !!filePath && !servesBytes);
|
|
51
152
|
const [error, setError] = useState<string | null>(null);
|
|
153
|
+
const [bytesVersion, setBytesVersion] = useState(0);
|
|
52
154
|
|
|
53
155
|
// Load file content on mount or when path changes
|
|
54
156
|
useEffect(() => {
|
|
55
157
|
if (!filePath) return;
|
|
158
|
+
if (servesBytes) {
|
|
159
|
+
setLoading(false);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
56
162
|
// If we already have cached content from SSE, use it
|
|
57
163
|
if (cachedContent !== undefined) {
|
|
58
164
|
setContent(cachedContent);
|
|
@@ -86,7 +192,7 @@ export function FileNode({ node, expanded = false }: { node: CanvasNodeState; ex
|
|
|
86
192
|
return () => {
|
|
87
193
|
cancelled = true;
|
|
88
194
|
};
|
|
89
|
-
}, [filePath, cachedContent]);
|
|
195
|
+
}, [filePath, cachedContent, servesBytes]);
|
|
90
196
|
|
|
91
197
|
// Sync content when server pushes updates via SSE
|
|
92
198
|
useEffect(() => {
|
|
@@ -97,6 +203,11 @@ export function FileNode({ node, expanded = false }: { node: CanvasNodeState; ex
|
|
|
97
203
|
|
|
98
204
|
const handleReload = useCallback(() => {
|
|
99
205
|
if (!filePath) return;
|
|
206
|
+
if (servesBytes) {
|
|
207
|
+
// Byte-served files have no cached text — bust the frame URL instead.
|
|
208
|
+
setBytesVersion((v) => v + 1);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
100
211
|
setLoading(true);
|
|
101
212
|
setError(null);
|
|
102
213
|
// Clear cached content to force a fresh fetch
|
|
@@ -125,11 +236,31 @@ export function FileNode({ node, expanded = false }: { node: CanvasNodeState; ex
|
|
|
125
236
|
setError('Failed to reload');
|
|
126
237
|
setLoading(false);
|
|
127
238
|
});
|
|
128
|
-
}, [filePath, node.id]);
|
|
239
|
+
}, [filePath, node.id, servesBytes]);
|
|
129
240
|
|
|
130
241
|
const lang = langFromPath(filePath);
|
|
131
242
|
const lines = content.split('\n');
|
|
132
243
|
const gutterWidth = `${String(lines.length).length + 1}ch`;
|
|
244
|
+
const delimiter = delimiterForPath(filePath);
|
|
245
|
+
// A .csv that is not actually delimited (single column) stays plain text.
|
|
246
|
+
const table = useMemo(() => {
|
|
247
|
+
if (!delimiter || servesBytes || !content) return null;
|
|
248
|
+
const parsed = parseDelimitedText(content, delimiter);
|
|
249
|
+
return parsed.header.length >= 2 ? parsed : null;
|
|
250
|
+
}, [content, delimiter, servesBytes]);
|
|
251
|
+
const bytesUrl = `/api/canvas/file-bytes?nodeId=${encodeURIComponent(node.id)}${
|
|
252
|
+
bytesVersion ? `&v=${bytesVersion}` : ''
|
|
253
|
+
}`;
|
|
254
|
+
// Amp orb portals block src-URL child iframes and force srcdoc, which cannot
|
|
255
|
+
// inline a PDF — offer the raw URL instead of a dead frame.
|
|
256
|
+
const pdfFrameBlocked = iframeMode.value === 'srcdoc';
|
|
257
|
+
const fillsBody = servesBytes || table !== null;
|
|
258
|
+
|
|
259
|
+
const truncatedNotice = truncated ? (
|
|
260
|
+
<div class="file-node-notice">
|
|
261
|
+
Showing the first {formatBytes(content.length)} of {formatBytes(byteSize ?? content.length)}
|
|
262
|
+
</div>
|
|
263
|
+
) : null;
|
|
133
264
|
|
|
134
265
|
if (!filePath) {
|
|
135
266
|
return <div style={{ color: 'var(--c-dim)', fontStyle: 'italic', padding: '12px' }}>No file path set</div>;
|
|
@@ -236,57 +367,124 @@ export function FileNode({ node, expanded = false }: { node: CanvasNodeState; ex
|
|
|
236
367
|
<div
|
|
237
368
|
style={{
|
|
238
369
|
flex: 1,
|
|
239
|
-
|
|
240
|
-
|
|
370
|
+
minHeight: 0,
|
|
371
|
+
overflow: fillsBody ? 'hidden' : 'auto',
|
|
372
|
+
padding: fillsBody ? 0 : '8px 0',
|
|
241
373
|
background: expanded ? 'var(--c-panel-soft)' : undefined,
|
|
242
374
|
borderRadius: expanded ? '0 0 8px 8px' : undefined,
|
|
243
375
|
}}
|
|
244
376
|
>
|
|
245
|
-
{
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
377
|
+
{isPdf &&
|
|
378
|
+
(pdfFrameBlocked ? (
|
|
379
|
+
<div class="file-node-placeholder">
|
|
380
|
+
<div>PDF preview is unavailable in this embedded host.</div>
|
|
381
|
+
<a class="file-node-link" href={bytesUrl} target="_blank" rel="noreferrer">
|
|
382
|
+
Open PDF
|
|
383
|
+
</a>
|
|
384
|
+
</div>
|
|
385
|
+
) : (
|
|
386
|
+
<iframe
|
|
387
|
+
src={bytesUrl}
|
|
388
|
+
title={title}
|
|
389
|
+
// SECURITY: same-origin URL, so it must be sandboxed like every
|
|
390
|
+
// other iframe in the client. Without allow-same-origin the frame
|
|
391
|
+
// gets an opaque origin and cannot reach the canvas API even if
|
|
392
|
+
// the bytes turn out to be markup. The built-in PDF viewer needs
|
|
393
|
+
// no script permissions from us.
|
|
394
|
+
sandbox=""
|
|
395
|
+
style={{ width: '100%', height: '100%', border: 'none', display: 'block' }}
|
|
396
|
+
/>
|
|
397
|
+
))}
|
|
398
|
+
{!isPdf && isBinary && (
|
|
399
|
+
<div class="file-node-placeholder">
|
|
400
|
+
<div class="file-node-placeholder-name">{title}</div>
|
|
401
|
+
<div>Binary file</div>
|
|
402
|
+
{byteSize !== undefined && <div>{formatBytes(byteSize)}</div>}
|
|
403
|
+
</div>
|
|
404
|
+
)}
|
|
405
|
+
{!servesBytes && (
|
|
406
|
+
<>
|
|
407
|
+
{loading && <div style={{ color: 'var(--c-dim)', padding: '12px', fontStyle: 'italic' }}>Loading…</div>}
|
|
408
|
+
{error && <div style={{ color: 'var(--c-danger)', padding: '12px' }}>{error}</div>}
|
|
409
|
+
{!loading &&
|
|
410
|
+
!error &&
|
|
411
|
+
(table ? (
|
|
412
|
+
<div class="file-table-shell">
|
|
413
|
+
{truncatedNotice}
|
|
414
|
+
{table.rows.length > MAX_TABLE_ROWS && (
|
|
415
|
+
<div class="file-node-notice">
|
|
416
|
+
Showing {MAX_TABLE_ROWS} of {table.rows.length} rows
|
|
417
|
+
</div>
|
|
418
|
+
)}
|
|
419
|
+
<div class="file-table-wrap">
|
|
420
|
+
<table class="file-table">
|
|
421
|
+
<thead>
|
|
422
|
+
<tr>
|
|
423
|
+
{table.header.map((cell, i) => (
|
|
424
|
+
<th key={i}>{cell}</th>
|
|
425
|
+
))}
|
|
426
|
+
</tr>
|
|
427
|
+
</thead>
|
|
428
|
+
<tbody>
|
|
429
|
+
{table.rows.slice(0, MAX_TABLE_ROWS).map((row, rowIndex) => (
|
|
430
|
+
<tr key={rowIndex}>
|
|
431
|
+
{row.map((cell, cellIndex) => (
|
|
432
|
+
<td key={cellIndex}>{cell}</td>
|
|
433
|
+
))}
|
|
434
|
+
</tr>
|
|
435
|
+
))}
|
|
436
|
+
</tbody>
|
|
437
|
+
</table>
|
|
438
|
+
</div>
|
|
439
|
+
</div>
|
|
440
|
+
) : (
|
|
441
|
+
<>
|
|
442
|
+
{truncatedNotice}
|
|
443
|
+
<pre
|
|
444
|
+
style={{
|
|
445
|
+
margin: 0,
|
|
446
|
+
lineHeight: '1.55',
|
|
447
|
+
tabSize: 2,
|
|
448
|
+
}}
|
|
449
|
+
>
|
|
450
|
+
{lines.map((line, i) => (
|
|
451
|
+
<div
|
|
452
|
+
key={i}
|
|
453
|
+
style={{
|
|
454
|
+
display: 'flex',
|
|
455
|
+
minHeight: '1.55em',
|
|
456
|
+
}}
|
|
457
|
+
>
|
|
458
|
+
<span
|
|
459
|
+
style={{
|
|
460
|
+
width: gutterWidth,
|
|
461
|
+
minWidth: gutterWidth,
|
|
462
|
+
textAlign: 'right',
|
|
463
|
+
color: 'var(--c-dim)',
|
|
464
|
+
paddingRight: '12px',
|
|
465
|
+
paddingLeft: '10px',
|
|
466
|
+
userSelect: 'none',
|
|
467
|
+
flexShrink: 0,
|
|
468
|
+
opacity: 0.6,
|
|
469
|
+
}}
|
|
470
|
+
>
|
|
471
|
+
{i + 1}
|
|
472
|
+
</span>
|
|
473
|
+
<code
|
|
474
|
+
style={{
|
|
475
|
+
color: 'var(--c-text)',
|
|
476
|
+
whiteSpace: 'pre',
|
|
477
|
+
paddingRight: '10px',
|
|
478
|
+
}}
|
|
479
|
+
>
|
|
480
|
+
{line || '\n'}
|
|
481
|
+
</code>
|
|
482
|
+
</div>
|
|
483
|
+
))}
|
|
484
|
+
</pre>
|
|
485
|
+
</>
|
|
486
|
+
))}
|
|
487
|
+
</>
|
|
290
488
|
)}
|
|
291
489
|
</div>
|
|
292
490
|
</div>
|
|
@@ -466,6 +466,25 @@ function easeOutCubic(t: number): number {
|
|
|
466
466
|
* Cancels any in-flight animation. Direct manipulation (pan/zoom gestures)
|
|
467
467
|
* should use setViewport() instead for instant response.
|
|
468
468
|
*/
|
|
469
|
+
/**
|
|
470
|
+
* Zoom by a factor about the CENTRE of the viewport.
|
|
471
|
+
*
|
|
472
|
+
* The toolbar's +/- used to change `scale` alone and keep `x`/`y`, which anchors
|
|
473
|
+
* the zoom at the world origin — so zooming in visibly slid the board up-left and
|
|
474
|
+
* zooming out pushed it down-right, instead of magnifying what you were looking
|
|
475
|
+
* at. Same correction the pointer-anchored wheel zoom applies, with the viewport
|
|
476
|
+
* centre as the anchor.
|
|
477
|
+
*/
|
|
478
|
+
export function zoomByFactor(factor: number, duration = 150): void {
|
|
479
|
+
const v = viewport.value;
|
|
480
|
+
const scale = Math.min(4, Math.max(0.1, v.scale * factor));
|
|
481
|
+
if (scale === v.scale) return;
|
|
482
|
+
const ratio = scale / v.scale;
|
|
483
|
+
const cx = window.innerWidth / 2;
|
|
484
|
+
const cy = window.innerHeight / 2;
|
|
485
|
+
animateViewport({ x: cx - ratio * (cx - v.x), y: cy - ratio * (cy - v.y), scale }, duration);
|
|
486
|
+
}
|
|
487
|
+
|
|
469
488
|
export function animateViewport(
|
|
470
489
|
target: ViewportState,
|
|
471
490
|
duration = 300,
|
|
@@ -376,12 +376,44 @@ export async function updateViewportFromClient(
|
|
|
376
376
|
headers: { 'Content-Type': 'application/json' },
|
|
377
377
|
body: JSON.stringify({
|
|
378
378
|
...viewport,
|
|
379
|
+
...clientWindowSize(),
|
|
379
380
|
...(options.recordHistory === false ? { recordHistory: false } : {}),
|
|
380
381
|
}),
|
|
381
382
|
},
|
|
382
383
|
);
|
|
383
384
|
}
|
|
384
385
|
|
|
386
|
+
/**
|
|
387
|
+
* This window's size, sent alongside every viewport write so a later agent
|
|
388
|
+
* `fit` computes against the human's REAL window instead of a hardcoded
|
|
389
|
+
* 1440x900 (0.4.6 orb feedback #2: fit clipped nodes on both sides).
|
|
390
|
+
*/
|
|
391
|
+
function clientWindowSize(): { clientWidth: number; clientHeight: number } | Record<string, never> {
|
|
392
|
+
if (typeof window === 'undefined') return {};
|
|
393
|
+
const clientWidth = window.innerWidth;
|
|
394
|
+
const clientHeight = window.innerHeight;
|
|
395
|
+
if (!clientWidth || !clientHeight) return {};
|
|
396
|
+
return { clientWidth, clientHeight };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Report this window's size WITHOUT touching the stored viewport. The
|
|
401
|
+
* viewport op defaults every omitted coordinate to the server's CURRENT
|
|
402
|
+
* viewport, so a body carrying only the size records the size and leaves the
|
|
403
|
+
* viewport exactly as it was — never echoing a stale client viewport back over
|
|
404
|
+
* the server's. Called on connect and on resize so an agent `fit` has the real
|
|
405
|
+
* window size before the human ever pans or zooms.
|
|
406
|
+
*/
|
|
407
|
+
export async function reportClientViewportSize(): Promise<void> {
|
|
408
|
+
const size = clientWindowSize();
|
|
409
|
+
if (!('clientWidth' in size)) return;
|
|
410
|
+
await requestBestEffort('reportClientViewportSize', '/api/canvas/viewport', {
|
|
411
|
+
method: 'POST',
|
|
412
|
+
headers: { 'Content-Type': 'application/json' },
|
|
413
|
+
body: JSON.stringify({ ...size, recordHistory: false }),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
385
417
|
// ── Group API ─────────────────────────────────────────────────
|
|
386
418
|
|
|
387
419
|
/** Create a group containing the given child node IDs. */
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
updateNodeData,
|
|
26
26
|
workbenchConnectionEpoch,
|
|
27
27
|
} from './canvas-store';
|
|
28
|
-
import { fetchAxSurfaceState } from './intent-bridge';
|
|
28
|
+
import { fetchAxSurfaceState, reportClientViewportSize } from './intent-bridge';
|
|
29
29
|
import { initSessionThemeOverride, themeOverrideActive } from './theme-override';
|
|
30
30
|
import { DEFAULT_POSITIONS, makeNodeState } from './node-factory';
|
|
31
31
|
import { invalidateTokenCache } from '../theme/tokens';
|
|
@@ -435,6 +435,9 @@ function handleConnected(data: Record<string, unknown>): void {
|
|
|
435
435
|
// Reconnect marker for holders of server-minted URLs (Finding S).
|
|
436
436
|
workbenchConnectionEpoch.value += 1;
|
|
437
437
|
reloadIfServerUpgraded(data.version);
|
|
438
|
+
// Tell the server how big this window actually is, so an agent `fit` sizes
|
|
439
|
+
// the board to the human's window (0.4.6 orb feedback #2).
|
|
440
|
+
void reportClientViewportSize();
|
|
438
441
|
// A ?theme= session override (host-default theming) wins over the
|
|
439
442
|
// server-global theme for THIS client only.
|
|
440
443
|
if (typeof data.theme === 'string' && !themeOverrideActive()) {
|
|
@@ -643,6 +643,10 @@ body,
|
|
|
643
643
|
overflow: hidden;
|
|
644
644
|
text-overflow: ellipsis;
|
|
645
645
|
flex: 1;
|
|
646
|
+
/* The name is the one thing that must survive a cramped title bar. Everything
|
|
647
|
+
else in the bar is flex-shrink: 0, so without a floor the title absorbed all
|
|
648
|
+
the pressure and collapsed to an ellipsis on narrow nodes. */
|
|
649
|
+
min-width: 9ch;
|
|
646
650
|
min-width: 0;
|
|
647
651
|
}
|
|
648
652
|
|
|
@@ -670,6 +674,13 @@ body,
|
|
|
670
674
|
}
|
|
671
675
|
|
|
672
676
|
.canvas-node .node-ax-status {
|
|
677
|
+
/* A long status ("in-progress") must not push the node's NAME out of the bar;
|
|
678
|
+
the pill is a glance-level cue, the name is the identity. */
|
|
679
|
+
max-width: 11ch;
|
|
680
|
+
overflow: hidden;
|
|
681
|
+
text-overflow: ellipsis;
|
|
682
|
+
white-space: nowrap;
|
|
683
|
+
flex-shrink: 1;
|
|
673
684
|
font-size: calc(9px * var(--node-chrome-scale, 1));
|
|
674
685
|
padding: calc(1px * var(--node-chrome-scale, 1)) calc(6px * var(--node-chrome-scale, 1));
|
|
675
686
|
border-radius: calc(4px * var(--node-chrome-scale, 1));
|
|
@@ -1846,10 +1857,11 @@ html.is-node-resizing .ext-app-preview-catcher {
|
|
|
1846
1857
|
border-radius: 999px;
|
|
1847
1858
|
}
|
|
1848
1859
|
|
|
1849
|
-
/* Edge labels
|
|
1860
|
+
/* Edge labels — --edge-chrome-scale is set on the edge <svg> so labels keep a
|
|
1861
|
+
constant screen size while zoomed out (see edgeChromeScale in EdgeLayer). */
|
|
1850
1862
|
.edge-label {
|
|
1851
1863
|
font-family: var(--font);
|
|
1852
|
-
font-size: 11px;
|
|
1864
|
+
font-size: calc(11px * var(--edge-chrome-scale, 1));
|
|
1853
1865
|
pointer-events: none;
|
|
1854
1866
|
user-select: none;
|
|
1855
1867
|
}
|
|
@@ -1857,7 +1869,7 @@ html.is-node-resizing .ext-app-preview-catcher {
|
|
|
1857
1869
|
.edge-label-bg {
|
|
1858
1870
|
fill: var(--c-panel-glass);
|
|
1859
1871
|
stroke: var(--c-line);
|
|
1860
|
-
stroke-width: 0.5;
|
|
1872
|
+
stroke-width: calc(0.5 * var(--edge-chrome-scale, 1));
|
|
1861
1873
|
}
|
|
1862
1874
|
|
|
1863
1875
|
/* Trace nodes — compact pills for agent tool/subagent visualization */
|
|
@@ -1963,6 +1975,92 @@ html.is-node-resizing .ext-app-preview-catcher {
|
|
|
1963
1975
|
color: var(--c-text-soft);
|
|
1964
1976
|
}
|
|
1965
1977
|
|
|
1978
|
+
/* File nodes — delimited-data tables and non-text placeholders */
|
|
1979
|
+
.file-table-shell {
|
|
1980
|
+
display: flex;
|
|
1981
|
+
flex-direction: column;
|
|
1982
|
+
height: 100%;
|
|
1983
|
+
min-height: 0;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
.file-node-notice {
|
|
1987
|
+
flex-shrink: 0;
|
|
1988
|
+
padding: 4px 10px;
|
|
1989
|
+
color: var(--c-muted);
|
|
1990
|
+
font-size: 10px;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
/* Own scroll port so a wide CSV scrolls inside the node instead of blowing out
|
|
1994
|
+
the layout — and so the sticky header row has something to stick to. */
|
|
1995
|
+
.file-table-wrap {
|
|
1996
|
+
flex: 1;
|
|
1997
|
+
min-height: 0;
|
|
1998
|
+
overflow: auto;
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
/* The shell/wrap prefix is load-bearing: these rules must out-specify the markdown
|
|
2002
|
+
table styles (`.canvas-node .node-body table` / `th` / `td`), whose 0.5em
|
|
2003
|
+
margin and translucent header background break the sticky header. Borders are
|
|
2004
|
+
separate, not collapsed — collapsed borders belong to the table element, so
|
|
2005
|
+
the header leaks the rows scrolling beneath it. */
|
|
2006
|
+
.file-table-shell .file-table-wrap .file-table {
|
|
2007
|
+
margin: 0;
|
|
2008
|
+
border-collapse: separate;
|
|
2009
|
+
border-spacing: 0;
|
|
2010
|
+
width: max-content;
|
|
2011
|
+
min-width: 100%;
|
|
2012
|
+
font-family: var(--mono);
|
|
2013
|
+
color: var(--c-text);
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
.file-table-shell .file-table-wrap .file-table th,
|
|
2017
|
+
.file-table-shell .file-table-wrap .file-table td {
|
|
2018
|
+
max-width: 320px;
|
|
2019
|
+
padding: 3px 8px;
|
|
2020
|
+
border: none;
|
|
2021
|
+
border-right: 1px solid var(--c-line);
|
|
2022
|
+
border-bottom: 1px solid var(--c-line);
|
|
2023
|
+
text-align: left;
|
|
2024
|
+
white-space: nowrap;
|
|
2025
|
+
overflow: hidden;
|
|
2026
|
+
text-overflow: ellipsis;
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
.file-table-shell .file-table-wrap .file-table th {
|
|
2030
|
+
position: sticky;
|
|
2031
|
+
top: 0;
|
|
2032
|
+
z-index: 1;
|
|
2033
|
+
/* Opaque in every theme — rows must not bleed through while scrolling. */
|
|
2034
|
+
background: var(--c-panel);
|
|
2035
|
+
color: var(--c-text-soft);
|
|
2036
|
+
font-weight: 600;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
.file-table-shell .file-table-wrap .file-table tbody tr:nth-child(even) {
|
|
2040
|
+
background: var(--c-surface-subtle);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
.file-node-placeholder {
|
|
2044
|
+
display: flex;
|
|
2045
|
+
flex-direction: column;
|
|
2046
|
+
align-items: center;
|
|
2047
|
+
justify-content: center;
|
|
2048
|
+
gap: 4px;
|
|
2049
|
+
height: 100%;
|
|
2050
|
+
padding: 16px;
|
|
2051
|
+
color: var(--c-muted);
|
|
2052
|
+
text-align: center;
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
.file-node-placeholder-name {
|
|
2056
|
+
color: var(--c-text-soft);
|
|
2057
|
+
word-break: break-all;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
.file-node-link {
|
|
2061
|
+
color: var(--c-accent);
|
|
2062
|
+
}
|
|
2063
|
+
|
|
1966
2064
|
/* Docked node — compact toolbar-flanking panel */
|
|
1967
2065
|
.docked-node {
|
|
1968
2066
|
min-width: 200px;
|