dsh-agent-floor 0.1.0 → 0.3.0
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/README.md +23 -40
- package/client.js +200 -672
- package/icon.svg +8 -9
- package/package.json +2 -4
- package/scripts/README.md +15 -61
- package/scripts/harness.js +30 -17
- package/scripts/raster.py +0 -218
- package/scripts/render.js +0 -226
package/icon.svg
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" width="128" height="128" role="img" aria-label="Agent Floor">
|
|
2
2
|
<rect width="128" height="128" rx="28" fill="#111827"/>
|
|
3
|
-
<rect x="20" y="
|
|
4
|
-
<
|
|
5
|
-
<rect x="
|
|
6
|
-
<rect x="
|
|
7
|
-
<rect x="
|
|
8
|
-
<rect x="
|
|
9
|
-
<rect x="
|
|
10
|
-
<rect x="
|
|
11
|
-
<rect x="61" y="64" width="6" height="6" rx="1" fill="#7FE3FF"/>
|
|
3
|
+
<rect x="20" y="26" width="88" height="76" rx="12" fill="#1B2033" stroke="#2B3350" stroke-width="2"/>
|
|
4
|
+
<circle cx="34" cy="42" r="4" fill="#4ADE80"/>
|
|
5
|
+
<rect x="44" y="38" width="30" height="8" rx="4" fill="#4C6FFF"/>
|
|
6
|
+
<rect x="80" y="38" width="18" height="8" rx="4" fill="#2B3350"/>
|
|
7
|
+
<rect x="28" y="58" width="8" height="8" rx="4" fill="#4ADE80"/>
|
|
8
|
+
<rect x="42" y="58" width="44" height="8" rx="4" fill="#3A4158"/>
|
|
9
|
+
<rect x="28" y="76" width="8" height="8" rx="4" fill="#9AA0A6"/>
|
|
10
|
+
<rect x="42" y="76" width="34" height="8" rx="4" fill="#3A4158"/>
|
|
12
11
|
</svg>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agent-floor",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Agent Floor — a
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Agent Floor — a compact always-on dock for DeepSeek Harness: which session is running, how far along, how many tokens, which files changed.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
@@ -31,8 +31,6 @@
|
|
|
31
31
|
"icon.svg",
|
|
32
32
|
"README.md",
|
|
33
33
|
"scripts/harness.js",
|
|
34
|
-
"scripts/render.js",
|
|
35
|
-
"scripts/raster.py",
|
|
36
34
|
"scripts/README.md"
|
|
37
35
|
],
|
|
38
36
|
"dsh": {
|
package/scripts/README.md
CHANGED
|
@@ -1,70 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 自检脚本
|
|
2
2
|
|
|
3
|
-
改 `client.js`
|
|
3
|
+
改 `client.js` 之后,不用开浏览器就能验证它没炸。
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
node scripts/harness.js
|
|
7
|
-
node scripts/
|
|
8
|
-
python3 scripts/raster.py
|
|
6
|
+
node scripts/harness.js # 默认检查 ../client.js
|
|
7
|
+
node scripts/harness.js path/to.js # 检查别的构建产物
|
|
9
8
|
```
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
它做四件事:
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
1. 桩掉 `window.__ModuleLoader__` / `React` / `document` / `localStorage` / `fetch`,
|
|
13
|
+
2. 真的执行 `client.js`,走一遍 `apply()` 的 `ctx.inject(['slots'])` → `slots.register('shell.overlay', …)` 链路,
|
|
14
|
+
3. 把注册出来的 **MonitorBar** 真渲染一次(带假会话数据),再单独渲染一行 **MonitorRow**,
|
|
15
|
+
4. 顺带验证 `deriveAgents` 的分组与排序(子代理挂到组长后面、depth=1)。
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
然后
|
|
17
|
+
成功时末行固定打印 `render ok` 并以 0 退出;失败打印堆栈、退出码 1。
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
2. 真的调用一次注册出来的 `FloorDock`(跑一遍所有 hooks、effect);
|
|
20
|
-
3. 用 5 个假 agent 调 `IsoFloor`,确认场景 SVG 能画出来、`deriveAgents` 能排出子代理层级。
|
|
19
|
+
常见失败:
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
- `client.js: 找不到 return { inject, apply };` → 导出语句被改了,同步修改 `harness.js` / `render.js` 顶部的 `EXPORT_RE`;
|
|
27
|
-
- `unexpected require("...")` → 客户端新增了 npm 依赖,需要给 harness 的 `React` 桩补上对应导出;
|
|
28
|
-
- 堆栈指向 `useState called outside a component render` → 组件在 `apply()` 之外被调用,或渲染器需要支持新的 hook(目前只桩了 `useState/useRef/useEffect`)。
|
|
29
|
-
|
|
30
|
-
## 2. `node scripts/render.js`
|
|
31
|
-
|
|
32
|
-
同样的宿主桩,用 5 个假 agent(1 个 RUNNING 组长、1 个带 `parent` 的子代理、其余 IDLE,每个都带 `tool` / `files` 字段)
|
|
33
|
-
渲染 `IsoFloor`,把 React 元素树序列化成静态 SVG:
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
scripts/out/iso.svg
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
目录会自动创建。所有 `var(--dsw-*)` 会替换成主题兜底色,所以产物是**浅色皮肤**快照。
|
|
40
|
-
生成后会自检:agent 数 / RUNNING 数 / 子代理层级 / SVG 字节数(> 5000),任何一项不对就 exit 1。
|
|
41
|
-
|
|
42
|
-
- 可选参数:`node scripts/render.js [clientPath] [outPath]`。
|
|
43
|
-
- 失败先看:
|
|
44
|
-
- `还有 var(--*) 没兜底色` → `client.js` 新增的颜色变量没有写 fallback,补一个 `var(--dsw-xxx, #hex)`;
|
|
45
|
-
- `生成的 SVG 只有 N 字节` → `IsoFloor` 没渲染出东西(props 形状或 `seats` 计算变了),先跑 `harness.js` 定位;
|
|
46
|
-
- 鼠标悬停等交互态不会出现在快照里,这是静态序列化的预期行为。
|
|
47
|
-
|
|
48
|
-
## 3. `python3 scripts/raster.py`
|
|
49
|
-
|
|
50
|
-
Pillow 写的极简 SVG → PNG 光栅化器,是**唯一**不打开 DSH 就能看画面的手段:
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
scripts/out/iso.svg → scripts/out/iso.png (默认路径,可省略参数)
|
|
54
|
-
python3 scripts/raster.py in.svg out.png
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
支持 `polygon` / `rect` / `circle` / `line` / `text` / `path`(二次贝塞尔)、
|
|
58
|
-
`translate/scale/matrix/rotate` 变换,以及 hex / `hsl()` / `rgba()` / `color-mix()` 颜色。
|
|
59
|
-
只跳过 `animateMotion` 这类动画节点的直属父级(小人传送动画不会出现在静帧里)。
|
|
60
|
-
|
|
61
|
-
- 失败先看:
|
|
62
|
-
- `ModuleNotFoundError: No module named 'PIL'` → `python3 -m pip install pillow`;
|
|
63
|
-
- `ParseError: unbound prefix` → SVG 里出现了 `xlink:` 等未声明前缀,检查 `render.js` 的属性映射;
|
|
64
|
-
- 画面空白/错位 → 多半是某个 `transform` 复合写法没被解析,或整棵节点被误判成动画节点;
|
|
65
|
-
- 字体和真实 DSH 有差异(fallback 到 Hiragino / PingFang / DejaVu),只用于看布局和配色,不是像素级还原。
|
|
66
|
-
|
|
67
|
-
## 提示
|
|
68
|
-
|
|
69
|
-
- 只读检查:三个脚本都只读 `client.js` 并在内存里改写导出语句,不会落盘改客户端代码。
|
|
70
|
-
- 改完 `client.js` 后不用重启 DSH:到插件设置里把 Agent Floor 关一次再开,即完成热重载。
|
|
21
|
+
- `client.js 没有调用 window.__ModuleLoader__.load(...)` —— 文件头被改坏了。
|
|
22
|
+
- `apply() 没有注册任何组件到 shell.overlay` —— `inject`/`apply` 链路断了。
|
|
23
|
+
- `MonitorBar 顶层不是 div` / `缺少 fg-* className` —— 组件根节点被换了。
|
|
24
|
+
- `ReferenceError: xxx is not defined` —— 改代码时删掉了函数还在被引用(`node --check` 查不出来这种)。
|
package/scripts/harness.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* harness.js — 无需 DSH / 浏览器的客户端自检。
|
|
4
4
|
*
|
|
5
5
|
* 桩掉 window.__ModuleLoader__、React、document 等宿主环境,真的加载 ../client.js,
|
|
6
|
-
* 走一遍 apply()
|
|
7
|
-
*
|
|
6
|
+
* 走一遍 apply() 的注册链路,然后把注册出来的监控条(MonitorBar)真渲染一次,
|
|
7
|
+
* 再用假会话验证 deriveAgents 的分组与排序。任何一步抛错都以 exit 1 结束并打印堆栈。
|
|
8
8
|
*
|
|
9
9
|
* 用法:
|
|
10
10
|
* node scripts/harness.js # 默认检查 ../client.js
|
|
@@ -104,8 +104,9 @@ function findTag(nodes, tag) {
|
|
|
104
104
|
// 宿主环境桩
|
|
105
105
|
// ---------------------------------------------------------------------------
|
|
106
106
|
function createStubs() {
|
|
107
|
+
const store = { 'dsh.agent-floor.open': '1' };
|
|
107
108
|
const storage = {
|
|
108
|
-
getItem: () => null,
|
|
109
|
+
getItem: (k) => (k in store ? store[k] : null),
|
|
109
110
|
setItem: () => {},
|
|
110
111
|
removeItem: () => {},
|
|
111
112
|
};
|
|
@@ -146,12 +147,14 @@ function main() {
|
|
|
146
147
|
let src = fs.readFileSync(target, 'utf8');
|
|
147
148
|
|
|
148
149
|
// 只在内存里改写导出语句,把内部组件暴露给自检;不落盘。
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (src.indexOf('__dshTest') < 0) {
|
|
151
|
+
const EXPORT_RE = /return\s*\{\s*inject\s*,\s*apply\s*\};/;
|
|
152
|
+
if (!EXPORT_RE.test(src)) {
|
|
153
|
+
throw new Error('client.js: 既没有 __dshTest,也找不到 `return { inject, apply };` —— 导出结构变了?');
|
|
154
|
+
}
|
|
155
|
+
src = src.replace(EXPORT_RE,
|
|
156
|
+
'return { inject, apply, __dshTest: { deriveAgents: deriveAgents, MonitorBar: MonitorBar } };');
|
|
152
157
|
}
|
|
153
|
-
src = src.replace(EXPORT_RE,
|
|
154
|
-
'return { inject, apply, __dshTest: { IsoFloor: IsoFloor, deriveAgents: deriveAgents, FloorDock: FloorDock } };');
|
|
155
158
|
|
|
156
159
|
const factoryFn = new Function(
|
|
157
160
|
'window', 'document', 'localStorage', 'fetch', 'console', '__filename', '__dirname', src,
|
|
@@ -199,8 +202,8 @@ function main() {
|
|
|
199
202
|
|
|
200
203
|
// 3) 用 5 个假 agent 渲染 IsoFloor(满屏场景),确保场景层也能画出来。
|
|
201
204
|
const test = mod.__dshTest;
|
|
202
|
-
if (!test || typeof test.
|
|
203
|
-
throw new Error('client.js 没有暴露 __dshTest
|
|
205
|
+
if (!test || typeof test.MonitorBar !== 'function' || typeof test.deriveAgents !== 'function') {
|
|
206
|
+
throw new Error('client.js 没有暴露 __dshTest.MonitorBar / deriveAgents');
|
|
204
207
|
}
|
|
205
208
|
const now = Date.now();
|
|
206
209
|
const sessions = [
|
|
@@ -214,12 +217,22 @@ function main() {
|
|
|
214
217
|
if (ordered.length !== 5) throw new Error('deriveAgents 期望 5 个 agent,实际 ' + ordered.length);
|
|
215
218
|
if (ordered.filter((o) => o.depth === 1).length !== 1) throw new Error('deriveAgents 没把子代理排成 depth 1');
|
|
216
219
|
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
const bar = renderNode(React.createElement(test.MonitorBar, { ctx: ctx }));
|
|
221
|
+
if (!bar.length || bar[0].tag !== 'div') throw new Error('MonitorBar 顶层不是 div');
|
|
222
|
+
const barNodes = countNodes(bar);
|
|
223
|
+
const expanded = renderNode(React.createElement(test.MonitorBar, { ctx: ctx, initialData: { sessions } }));
|
|
224
|
+
let rowCount = 0;
|
|
225
|
+
(function walk3(n) {
|
|
226
|
+
if (!n || typeof n !== 'object') return;
|
|
227
|
+
const cls = n.props && n.props.className;
|
|
228
|
+
if (typeof cls === 'string' && cls.indexOf('fg-row') === 0) rowCount++;
|
|
229
|
+
for (const c of n.children || []) walk3(c);
|
|
230
|
+
})(expanded[0]);
|
|
231
|
+
if (rowCount !== 5) throw new Error('展开状态应渲染 5 行,实际 ' + rowCount);
|
|
232
|
+
|
|
233
|
+
const row = renderNode(React.createElement(test.MonitorRow, { agent: ordered[0], onOpen: () => {} }));
|
|
234
|
+
if (!row.length || row[0].tag !== 'div') throw new Error('MonitorRow 顶层不是 div');
|
|
235
|
+
if (String(row[0].props.className).indexOf('fg-row') !== 0) throw new Error('MonitorRow 缺少 fg-row className');
|
|
223
236
|
|
|
224
237
|
// 4) 跑一次 effect(useFloor 会发起一次假 fetch),确认轮询逻辑不炸。
|
|
225
238
|
for (const fn of effects) {
|
|
@@ -229,7 +242,7 @@ function main() {
|
|
|
229
242
|
|
|
230
243
|
console.log(' client : ' + target);
|
|
231
244
|
console.log(' dock : <' + rootTag + ' class="' + tree[0].props.className + '"> (' + dockNodes + ' nodes)');
|
|
232
|
-
console.log('
|
|
245
|
+
console.log(' bar : <div fg-root> (' + barNodes + ' nodes, ' + ordered.length + ' agents)');
|
|
233
246
|
console.log(' effects: ' + effects.length + ' 个已执行');
|
|
234
247
|
console.log('render ok');
|
|
235
248
|
}
|
package/scripts/raster.py
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"""极简 SVG → PNG 光栅化器(Pillow),只覆盖 IsoFloor 用到的子集:
|
|
2
|
-
polygon / rect / circle / text / path(二次贝塞尔),颜色支持 hex、hsl()、rgba()、color-mix()。
|
|
3
|
-
|
|
4
|
-
用法:
|
|
5
|
-
python3 scripts/raster.py # scripts/out/iso.svg → scripts/out/iso.png
|
|
6
|
-
python3 scripts/raster.py in.svg out.png
|
|
7
|
-
"""
|
|
8
|
-
import os, re, sys, math
|
|
9
|
-
import xml.etree.ElementTree as ET
|
|
10
|
-
from PIL import Image, ImageDraw, ImageFont
|
|
11
|
-
|
|
12
|
-
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
13
|
-
SRC = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HERE, 'out', 'iso.svg')
|
|
14
|
-
OUT = sys.argv[2] if len(sys.argv) > 2 else os.path.join(HERE, 'out', 'iso.png')
|
|
15
|
-
SCALE = 2.0
|
|
16
|
-
FONTS = [
|
|
17
|
-
"/System/Library/Fonts/Hiragino Sans GB.ttc",
|
|
18
|
-
"/System/Library/Fonts/PingFang.ttc",
|
|
19
|
-
"/Library/Fonts/Arial Unicode.ttf",
|
|
20
|
-
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
|
21
|
-
]
|
|
22
|
-
fonts = {}
|
|
23
|
-
def font(size):
|
|
24
|
-
key = int(size)
|
|
25
|
-
if key not in fonts:
|
|
26
|
-
fonts[key] = None
|
|
27
|
-
for path in FONTS:
|
|
28
|
-
if not os.path.exists(path):
|
|
29
|
-
continue
|
|
30
|
-
try:
|
|
31
|
-
fonts[key] = ImageFont.truetype(path, key)
|
|
32
|
-
break
|
|
33
|
-
except Exception:
|
|
34
|
-
continue
|
|
35
|
-
if fonts[key] is None:
|
|
36
|
-
fonts[key] = ImageFont.load_default()
|
|
37
|
-
return fonts[key]
|
|
38
|
-
|
|
39
|
-
def parse_color(c):
|
|
40
|
-
if not c or c == 'none' or c == 'transparent': return None
|
|
41
|
-
c = c.strip()
|
|
42
|
-
m = re.match(r'rgba?\(([^)]+)\)', c)
|
|
43
|
-
if m:
|
|
44
|
-
parts = [p.strip() for p in re.split(r'[,\s/]+', m.group(1)) if p.strip()]
|
|
45
|
-
r, g, b = (float(parts[0]), float(parts[1]), float(parts[2]))
|
|
46
|
-
a = float(parts[3]) if len(parts) > 3 else 1.0
|
|
47
|
-
if a < 1: return None
|
|
48
|
-
return (int(r), int(g), int(b), 255)
|
|
49
|
-
m = re.match(r'color-mix\(in srgb,\s*(.+?)\s+(\d+(?:\.\d+)?)%,\s*(.+)\)$', c)
|
|
50
|
-
if m:
|
|
51
|
-
c1, p1, c2 = m.group(1), float(m.group(2)) / 100.0, m.group(3)
|
|
52
|
-
a1 = parse_color(c1); a2 = parse_color(c2)
|
|
53
|
-
if a1 and a2:
|
|
54
|
-
return tuple(int(a1[i] * p1 + a2[i] * (1 - p1)) for i in range(3)) + (255,)
|
|
55
|
-
return a1 or a2
|
|
56
|
-
m = re.match(r'hsla?\(\s*(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)%\s+(\d+(?:\.\d+)?)%', c)
|
|
57
|
-
if m:
|
|
58
|
-
hue, sat, lig = (float(m.group(i)) for i in (1, 2, 3))
|
|
59
|
-
sat /= 100.0; lig /= 100.0
|
|
60
|
-
def f(n):
|
|
61
|
-
k = (n + hue / 30.0) % 12
|
|
62
|
-
a = sat * min(lig, 1 - lig)
|
|
63
|
-
return int(255 * (lig - a * max(-1, min(k - 3, min(9 - k, 1)))))
|
|
64
|
-
return (f(0), f(8), f(4), 255)
|
|
65
|
-
m = re.match(r'#([0-9a-fA-F]{3,8})$', c)
|
|
66
|
-
if m:
|
|
67
|
-
h = m.group(1)
|
|
68
|
-
if len(h) == 3: h = ''.join(ch * 2 for ch in h)
|
|
69
|
-
return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4)) + (255,)
|
|
70
|
-
return (128, 128, 128, 255)
|
|
71
|
-
|
|
72
|
-
def style_of(el):
|
|
73
|
-
st = {}
|
|
74
|
-
raw = el.get('style')
|
|
75
|
-
if raw:
|
|
76
|
-
for part in raw.split(';'):
|
|
77
|
-
if ':' in part:
|
|
78
|
-
k, v = part.split(':', 1)
|
|
79
|
-
st[k.strip()] = v.strip()
|
|
80
|
-
for k, v in el.attrib.items():
|
|
81
|
-
st.setdefault(k, v)
|
|
82
|
-
return st
|
|
83
|
-
|
|
84
|
-
def num(v, d=0.0):
|
|
85
|
-
try: return float(str(v).replace('px', ''))
|
|
86
|
-
except Exception: return d
|
|
87
|
-
|
|
88
|
-
has_motion = {}
|
|
89
|
-
def is_motion_carrier(el):
|
|
90
|
-
"""只有『直接包含 animateMotion』的节点整棵跳过;不能因为某个大 g 的后代里有动画就把整屏都丢了。"""
|
|
91
|
-
if id(el) in has_motion: return has_motion[id(el)]
|
|
92
|
-
r = any(c.tag.split('}')[-1] in ('animateMotion', 'animate', 'animateTransform') for c in el)
|
|
93
|
-
has_motion[id(el)] = r
|
|
94
|
-
return r
|
|
95
|
-
|
|
96
|
-
def pts(s):
|
|
97
|
-
vals = [float(x) for x in re.findall(r'-?\d+(?:\.\d+)?', s)]
|
|
98
|
-
return [(vals[i], vals[i + 1]) for i in range(0, len(vals) - 1, 2)]
|
|
99
|
-
|
|
100
|
-
tree = ET.parse(SRC)
|
|
101
|
-
root = tree.getroot()
|
|
102
|
-
vb = [float(x) for x in (root.get('viewBox') or '0 0 900 500').split()]
|
|
103
|
-
W, H = int(vb[2] * SCALE), int(vb[3] * SCALE)
|
|
104
|
-
img = Image.new('RGB', (W, H), (247, 247, 249))
|
|
105
|
-
dr = ImageDraw.Draw(img)
|
|
106
|
-
|
|
107
|
-
def mat_identity(): return (1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
|
|
108
|
-
|
|
109
|
-
def mat_mul(m, n):
|
|
110
|
-
a, b, c, d, e, f = m
|
|
111
|
-
A, B, C, D, E, F = n
|
|
112
|
-
return (a * A + b * C, a * B + b * D, c * A + d * C, c * B + d * D,
|
|
113
|
-
e * A + f * C + E, e * B + f * D + F)
|
|
114
|
-
|
|
115
|
-
def mat_apply(m, pt):
|
|
116
|
-
a, b, c, d, e, f = m
|
|
117
|
-
x, y = pt
|
|
118
|
-
return (a * x + c * y + e, b * x + d * y + f)
|
|
119
|
-
|
|
120
|
-
def mat_scale(m):
|
|
121
|
-
return math.sqrt(abs(m[0] * m[3] - m[1] * m[2])) or 1.0
|
|
122
|
-
|
|
123
|
-
def parse_transform(s):
|
|
124
|
-
"""支持 translate / scale / matrix / rotate(绕原点)。"""
|
|
125
|
-
m = mat_identity()
|
|
126
|
-
for name, args in re.findall(r'(translate|scale|matrix|rotate)\(([^)]*)\)', s or ''):
|
|
127
|
-
vals = [float(v) for v in re.findall(r'-?\d+(?:\.\d+)?', args)]
|
|
128
|
-
if not vals:
|
|
129
|
-
continue
|
|
130
|
-
if name == 'translate':
|
|
131
|
-
t = (1, 0, 0, 1, vals[0], vals[1] if len(vals) > 1 else 0)
|
|
132
|
-
elif name == 'scale':
|
|
133
|
-
sx = vals[0]
|
|
134
|
-
sy = vals[1] if len(vals) > 1 else sx
|
|
135
|
-
t = (sx, 0, 0, sy, 0, 0)
|
|
136
|
-
elif name == 'matrix' and len(vals) >= 6:
|
|
137
|
-
t = tuple(vals[:6])
|
|
138
|
-
elif name == 'rotate':
|
|
139
|
-
ang = math.radians(vals[0])
|
|
140
|
-
ca, sa = math.cos(ang), math.sin(ang)
|
|
141
|
-
t = (ca, sa, -sa, ca, 0, 0)
|
|
142
|
-
else:
|
|
143
|
-
continue
|
|
144
|
-
m = mat_mul(m, t)
|
|
145
|
-
return m
|
|
146
|
-
|
|
147
|
-
root_tf = (SCALE, 0, 0, SCALE, 0, 0)
|
|
148
|
-
|
|
149
|
-
def draw(el, M):
|
|
150
|
-
tag = el.tag.split('}')[-1]
|
|
151
|
-
st = style_of(el)
|
|
152
|
-
tr = st.get('transform')
|
|
153
|
-
if tr:
|
|
154
|
-
M = mat_mul(M, parse_transform(tr))
|
|
155
|
-
if tag == 'svg':
|
|
156
|
-
for c in el: draw(c, M)
|
|
157
|
-
return
|
|
158
|
-
if tag in ('animateMotion', 'animate', 'animateTransform', 'defs', 'title', 'desc', 'style'): return
|
|
159
|
-
if is_motion_carrier(el): return
|
|
160
|
-
sf = mat_scale(M)
|
|
161
|
-
def P(pt): return mat_apply(M, pt)
|
|
162
|
-
fill = parse_color(st.get('fill'))
|
|
163
|
-
stroke = parse_color(st.get('stroke'))
|
|
164
|
-
if tag == 'polygon':
|
|
165
|
-
dr.polygon([P(p) for p in pts(st.get('points', ''))], fill=fill, outline=stroke)
|
|
166
|
-
elif tag == 'polyline':
|
|
167
|
-
pts_ = [P(p) for p in pts(st.get('points', ''))]
|
|
168
|
-
if stroke and len(pts_) > 1:
|
|
169
|
-
dr.line(pts_, fill=stroke, width=max(1, int(num(st.get('stroke-width'), 1) * sf)))
|
|
170
|
-
elif tag == 'rect':
|
|
171
|
-
x, y = num(st.get('x')), num(st.get('y'))
|
|
172
|
-
w, hh = num(st.get('width')), num(st.get('height'))
|
|
173
|
-
corners = [P((x, y)), P((x + w, y)), P((x + w, y + hh)), P((x, y + hh))]
|
|
174
|
-
xs = [p[0] for p in corners]; ys = [p[1] for p in corners]
|
|
175
|
-
box = [min(xs), min(ys), max(xs), max(ys)]
|
|
176
|
-
r = num(st.get('rx'), 0) * sf
|
|
177
|
-
dr.rounded_rectangle(box, radius=r, fill=fill, outline=stroke)
|
|
178
|
-
elif tag == 'circle':
|
|
179
|
-
c = P((num(st.get('cx')), num(st.get('cy'))))
|
|
180
|
-
r = num(st.get('r')) * sf
|
|
181
|
-
dr.ellipse([c[0] - r, c[1] - r, c[0] + r, c[1] + r], fill=fill, outline=stroke)
|
|
182
|
-
elif tag == 'line':
|
|
183
|
-
p1 = P((num(st.get('x1')), num(st.get('y1'))))
|
|
184
|
-
p2 = P((num(st.get('x2')), num(st.get('y2'))))
|
|
185
|
-
if stroke:
|
|
186
|
-
dr.line([p1, p2], fill=stroke, width=max(1, int(num(st.get('stroke-width'), 1) * sf)))
|
|
187
|
-
elif tag == 'text':
|
|
188
|
-
size = num(st.get('font-size'), 11) * sf
|
|
189
|
-
col = fill or (30, 30, 35, 255)
|
|
190
|
-
anchor = st.get('text-anchor', 'start')
|
|
191
|
-
text = ''.join(el.itertext())
|
|
192
|
-
f = font(size)
|
|
193
|
-
x, y = P((num(st.get('x')), num(st.get('y'))))
|
|
194
|
-
if anchor == 'middle':
|
|
195
|
-
w = dr.textlength(text, font=f); x -= w / 2
|
|
196
|
-
elif anchor == 'end':
|
|
197
|
-
w = dr.textlength(text, font=f); x -= w
|
|
198
|
-
dr.text((x, y - size * 0.82), text, font=f, fill=col)
|
|
199
|
-
elif tag == 'path':
|
|
200
|
-
d = st.get('d', '')
|
|
201
|
-
m = re.match(r'M ([-\d.]+) ([-\d.]+) Q ([-\d.]+) ([-\d.]+) ([-\d.]+) ([-\d.]+)', d)
|
|
202
|
-
if m:
|
|
203
|
-
p0, pc, p1 = (float(m.group(1)), float(m.group(2))), (float(m.group(3)), float(m.group(4))), (float(m.group(5)), float(m.group(6)))
|
|
204
|
-
line = []
|
|
205
|
-
for i in range(25):
|
|
206
|
-
t = i / 24.0
|
|
207
|
-
x = (1 - t) ** 2 * p0[0] + 2 * (1 - t) * t * pc[0] + t * t * p1[0]
|
|
208
|
-
y = (1 - t) ** 2 * p0[1] + 2 * (1 - t) * t * pc[1] + t * t * p1[1]
|
|
209
|
-
line.append(P((x, y)))
|
|
210
|
-
if stroke: dr.line(line, fill=stroke, width=max(1, int(num(st.get('stroke-width'), 1) * sf)))
|
|
211
|
-
if tag != 'g':
|
|
212
|
-
return
|
|
213
|
-
for c in el: draw(c, M)
|
|
214
|
-
|
|
215
|
-
draw(root, root_tf)
|
|
216
|
-
os.makedirs(os.path.dirname(os.path.abspath(OUT)), exist_ok=True)
|
|
217
|
-
img.save(OUT)
|
|
218
|
-
print('wrote', OUT, img.size, 'from', SRC)
|
package/scripts/render.js
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* render.js — 把 IsoFloor 场景用假数据序列化成静态 SVG,供 raster.py 转 PNG。
|
|
4
|
-
*
|
|
5
|
-
* 同样桩掉宿主环境后加载 ../client.js,用 5 个假 agent(1 个 RUNNING 组长、
|
|
6
|
-
* 1 个带 parent 的子代理、其余 IDLE,每个都带 tool / files 字段)渲染一次 IsoFloor,
|
|
7
|
-
* 再把 React 元素树序列化成 SVG。所有 var(--dsw-*) 都换成主题兜底色,
|
|
8
|
-
* 所以产物是浅色皮肤的静态快照。
|
|
9
|
-
*
|
|
10
|
-
* 用法:
|
|
11
|
-
* node scripts/render.js # ../client.js → scripts/out/iso.svg
|
|
12
|
-
* node scripts/render.js ../client.js out/iso.svg
|
|
13
|
-
*/
|
|
14
|
-
import fs from 'node:fs';
|
|
15
|
-
import path from 'node:path';
|
|
16
|
-
import { fileURLToPath } from 'node:url';
|
|
17
|
-
|
|
18
|
-
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
-
const clientPath = path.resolve(process.argv[2] || path.join(HERE, '..', 'client.js'));
|
|
20
|
-
const outPath = path.resolve(process.argv[3] || path.join(HERE, 'out', 'iso.svg'));
|
|
21
|
-
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// 宿主环境桩(与 harness.js 保持同样的形状)
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
let captured = null;
|
|
26
|
-
const hookStates = [];
|
|
27
|
-
let hookIndex = 0;
|
|
28
|
-
const React = {
|
|
29
|
-
createElement(tag, props, ...kids) { return { tag, props: props || {}, kids }; },
|
|
30
|
-
useState(initial) {
|
|
31
|
-
const i = hookIndex++;
|
|
32
|
-
if (!(i in hookStates)) hookStates[i] = typeof initial === 'function' ? initial() : initial;
|
|
33
|
-
return [hookStates[i], () => {}];
|
|
34
|
-
},
|
|
35
|
-
useRef(value) { return { current: value }; },
|
|
36
|
-
useEffect() {},
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const win = {
|
|
40
|
-
__ModuleLoader__: { load(mod) { captured = mod; } },
|
|
41
|
-
setTimeout: () => 0,
|
|
42
|
-
clearTimeout: () => {},
|
|
43
|
-
innerWidth: 1440,
|
|
44
|
-
innerHeight: 900,
|
|
45
|
-
};
|
|
46
|
-
const doc = {
|
|
47
|
-
head: { appendChild: () => {} },
|
|
48
|
-
getElementById: () => null,
|
|
49
|
-
createElement: () => ({ style: {}, set id(v) {}, set textContent(v) {} }),
|
|
50
|
-
};
|
|
51
|
-
const storage = { getItem: () => null, setItem: () => {}, removeItem: () => {} };
|
|
52
|
-
const fakeFetch = () => new Promise(() => {});
|
|
53
|
-
|
|
54
|
-
// ---------------------------------------------------------------------------
|
|
55
|
-
// 元素树 → SVG 字符串
|
|
56
|
-
// ---------------------------------------------------------------------------
|
|
57
|
-
// 只有这些 SVG 属性本身是驼峰;其余(strokeWidth / fontSize / textAnchor…)要转成 kebab-case。
|
|
58
|
-
const KEEP_CAMEL = new Set([
|
|
59
|
-
'viewBox', 'preserveAspectRatio', 'gradientUnits', 'patternUnits', 'patternContentUnits',
|
|
60
|
-
]);
|
|
61
|
-
// 注:animateMotion 的 xlinkHref 用 SVG2 的 href 输出,避免 XML 里出现未声明的 xlink 前缀。
|
|
62
|
-
const ATTR_MAP = { className: 'class', htmlFor: 'for', xlinkHref: 'href' };
|
|
63
|
-
|
|
64
|
-
function esc(value) {
|
|
65
|
-
return String(value)
|
|
66
|
-
.replace(/&/g, '&')
|
|
67
|
-
.replace(/</g, '<')
|
|
68
|
-
.replace(/>/g, '>')
|
|
69
|
-
.replace(/"/g, '"');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function styleString(style) {
|
|
73
|
-
return Object.keys(style || {})
|
|
74
|
-
.map((prop) => prop.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase()) + ':' + style[prop])
|
|
75
|
-
.join(';');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function attrsOf(props) {
|
|
79
|
-
const out = [];
|
|
80
|
-
for (const key of Object.keys(props || {})) {
|
|
81
|
-
if (key === 'key' || key === 'children' || key === 'ref') continue;
|
|
82
|
-
if (/^on[A-Z]/.test(key)) continue; // 事件回调不进 SVG
|
|
83
|
-
const value = props[key];
|
|
84
|
-
if (value === undefined || value === null || value === false) continue;
|
|
85
|
-
if (key === 'style') {
|
|
86
|
-
if (value && typeof value === 'object') out.push(' style="' + esc(styleString(value)) + '"');
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
let name = ATTR_MAP[key] || key;
|
|
90
|
-
if (!KEEP_CAMEL.has(name)) {
|
|
91
|
-
name = name.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
|
|
92
|
-
}
|
|
93
|
-
out.push(' ' + name + '="' + esc(value) + '"');
|
|
94
|
-
}
|
|
95
|
-
return out.join('');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function serialize(node) {
|
|
99
|
-
if (node === null || node === undefined || node === false) return '';
|
|
100
|
-
if (typeof node === 'string' || typeof node === 'number') return esc(node);
|
|
101
|
-
if (Array.isArray(node)) return node.map(serialize).join('');
|
|
102
|
-
const { tag, props, kids } = node;
|
|
103
|
-
if (typeof tag === 'function') {
|
|
104
|
-
hookIndex = 0;
|
|
105
|
-
return serialize(tag(props || {}));
|
|
106
|
-
}
|
|
107
|
-
return '<' + tag + attrsOf(props) + '>' + (kids || []).map(serialize).join('') + '</' + tag + '>';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
// 假数据:5 个 agent,覆盖 RUNNING / 子代理 / IDLE,全部带 tool + files
|
|
112
|
-
// ---------------------------------------------------------------------------
|
|
113
|
-
function sampleData() {
|
|
114
|
-
const now = Date.now();
|
|
115
|
-
const files = (list) => list.map((f) => ({ name: f[0], write: !!f[1] }));
|
|
116
|
-
const mk = (agent) => Object.assign({
|
|
117
|
-
turn: 1, step: 1, tools: 0, tokens: 0, updatedAt: now,
|
|
118
|
-
files: [], tool: null, parent: null,
|
|
119
|
-
}, agent, {
|
|
120
|
-
sessionId: agent.id,
|
|
121
|
-
files: files(agent.files || []),
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
agents: [
|
|
126
|
-
mk({
|
|
127
|
-
id: 's1', name: 'MY', status: 'RUNNING',
|
|
128
|
-
step: 10, turn: 2, tools: 68, tokens: 120000,
|
|
129
|
-
tool: { name: 'bash', target: 'pnpm run build' },
|
|
130
|
-
files: [['client.js', true], ['index.js', false]],
|
|
131
|
-
}),
|
|
132
|
-
mk({
|
|
133
|
-
id: 's2', name: 'dsh-skill-pilot', status: 'IDLE',
|
|
134
|
-
step: 1, tools: 41, tokens: 22000, updatedAt: now - 120000,
|
|
135
|
-
tool: { name: 'read', target: 'SKILL.md' },
|
|
136
|
-
files: [['SKILL.md', false]],
|
|
137
|
-
}),
|
|
138
|
-
mk({
|
|
139
|
-
id: 's3', name: 'Mnemon · Idle review', status: 'IDLE',
|
|
140
|
-
step: 3, tools: 3, tokens: 8000, updatedAt: now - 3 * 600000,
|
|
141
|
-
tool: { name: 'mnemon_recall', target: 'review' },
|
|
142
|
-
files: [['MEMORY.md', true]],
|
|
143
|
-
}),
|
|
144
|
-
mk({
|
|
145
|
-
id: 's4', name: '执行一条 bash 命令:sleep 25', status: 'IDLE',
|
|
146
|
-
step: 1, tools: 1, tokens: 1200, updatedAt: now - 4 * 600000,
|
|
147
|
-
tool: { name: 'bash', target: 'sleep 25' },
|
|
148
|
-
files: [['run.log', false]],
|
|
149
|
-
}),
|
|
150
|
-
mk({
|
|
151
|
-
id: 's5', name: '子代理 · token-econ', status: 'IDLE', parent: 's1',
|
|
152
|
-
step: 4, tools: 12, tokens: 9000, updatedAt: now - 60000,
|
|
153
|
-
tool: { name: 'grep', target: 'token' },
|
|
154
|
-
files: [['token.md', true], ['index.js', false]],
|
|
155
|
-
}),
|
|
156
|
-
],
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function main() {
|
|
161
|
-
if (!fs.existsSync(clientPath)) throw new Error('client file not found: ' + clientPath);
|
|
162
|
-
let src = fs.readFileSync(clientPath, 'utf8');
|
|
163
|
-
|
|
164
|
-
const EXPORT_RE = /return\s*\{\s*inject\s*,\s*apply\s*\};/;
|
|
165
|
-
if (!EXPORT_RE.test(src)) {
|
|
166
|
-
throw new Error('client.js: 找不到 `return { inject, apply };` —— 导出结构变了?请同步更新 scripts/render.js / harness.js 的 EXPORT_RE。');
|
|
167
|
-
}
|
|
168
|
-
src = src.replace(EXPORT_RE,
|
|
169
|
-
'return { inject, apply, __dshTest: { IsoFloor: IsoFloor, deriveAgents: deriveAgents } };');
|
|
170
|
-
|
|
171
|
-
const factoryFn = new Function(
|
|
172
|
-
'window', 'document', 'localStorage', 'fetch', 'console', '__filename', '__dirname', src,
|
|
173
|
-
);
|
|
174
|
-
factoryFn(win, doc, storage, fakeFetch, console, clientPath, path.dirname(clientPath));
|
|
175
|
-
|
|
176
|
-
if (!captured || typeof captured.factory !== 'function') {
|
|
177
|
-
throw new Error('client.js 没有调用 window.__ModuleLoader__.load({ factory })');
|
|
178
|
-
}
|
|
179
|
-
const mod = captured.factory((name) => {
|
|
180
|
-
if (name === 'react' || name === 'React') return React;
|
|
181
|
-
throw new Error('unexpected require("' + name + '") — render 只桩了 react');
|
|
182
|
-
});
|
|
183
|
-
const test = mod && mod.__dshTest;
|
|
184
|
-
if (!test || typeof test.IsoFloor !== 'function' || typeof test.deriveAgents !== 'function') {
|
|
185
|
-
throw new Error('client.js 没有暴露 __dshTest.IsoFloor / deriveAgents');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const ordered = test.deriveAgents(sampleData());
|
|
189
|
-
if (ordered.length !== 5) throw new Error('假数据应得到 5 个 agent,实际 ' + ordered.length);
|
|
190
|
-
const running = ordered.filter((o) => o.agent.status === 'RUNNING').length;
|
|
191
|
-
if (running !== 1) throw new Error('假数据应有 1 个 RUNNING,实际 ' + running);
|
|
192
|
-
if (!ordered.some((o) => o.depth === 1 && o.agent.parent)) throw new Error('假数据缺少带 parent 的子代理');
|
|
193
|
-
|
|
194
|
-
const COLS = 4;
|
|
195
|
-
const seats = ordered.map((o, i) => ({ agent: o.agent, row: Math.floor(i / COLS), col: i % COLS }));
|
|
196
|
-
|
|
197
|
-
hookIndex = 0;
|
|
198
|
-
const tree = React.createElement(test.IsoFloor, { seats, onOpen: () => {} });
|
|
199
|
-
let svg = serialize(tree);
|
|
200
|
-
|
|
201
|
-
// 1) CSS var() → 主题兜底色(浅色皮肤快照)
|
|
202
|
-
svg = svg.replace(/var\(\s*--[a-z0-9-]+\s*,\s*([^)]+)\)/g, (m, fallback) => fallback.trim());
|
|
203
|
-
if (/var\(\s*--/.test(svg)) throw new Error('还有 var(--*) 没兜底色,raster.py 无法解析;请给 client.js 的变量补 fallback');
|
|
204
|
-
// 2) 渐变/滤镜引用直接置空(旧版本有 fg-iso-glow)
|
|
205
|
-
svg = svg.replace(/url\(#[a-zA-Z0-9_-]+\)/g, 'none');
|
|
206
|
-
// 3) 补 SVG 根属性 + 浅色页面底色
|
|
207
|
-
const vb = /viewBox="0 0 ([0-9.]+) ([0-9.]+)"/.exec(svg);
|
|
208
|
-
const W = vb ? Math.ceil(Number(vb[1])) : 1280;
|
|
209
|
-
const H = vb ? Math.ceil(Number(vb[2])) : 900;
|
|
210
|
-
svg = svg.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg" width="' + W + '" height="' + H + '"');
|
|
211
|
-
svg = svg.replace(/(<svg[^>]*>)/, '$1<rect x="0" y="0" width="' + W + '" height="' + H + '" fill="#f7f7f9"/>');
|
|
212
|
-
|
|
213
|
-
const bytes = Buffer.byteLength(svg, 'utf8');
|
|
214
|
-
if (bytes <= 5000) throw new Error('生成的 SVG 只有 ' + bytes + ' 字节,疑似场景没渲染出来(期望 > 5000)');
|
|
215
|
-
|
|
216
|
-
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
217
|
-
fs.writeFileSync(outPath, svg, 'utf8');
|
|
218
|
-
console.log('wrote ' + outPath + ' (' + bytes + ' bytes, ' + W + 'x' + H + ', ' + ordered.length + ' agents)');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
main();
|
|
223
|
-
} catch (err) {
|
|
224
|
-
console.error(err && err.stack ? err.stack : String(err));
|
|
225
|
-
process.exit(1);
|
|
226
|
-
}
|