@aiti-ai/ext-shared 0.1.12 → 0.1.16

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.
@@ -0,0 +1,27 @@
1
+ # @aiti-ai/ext-shared
2
+
3
+ > aiti-agent 扩展的服务端共享层:agent-spawn-env(spawn env 治理 / resolveCliLaunch)、seed-tool(历史回放种子)、cursor-cli-store(Cursor CLI 会话读取器)、exec-async、git-ops-client 等共享模块。扩展 package.json 声明依赖后由 extman reconcile 统一装进共享根 node_modules,jiti walk-up 解析。
4
+
5
+ [English](./README.md) · 简体中文
6
+
7
+ ## 关于 aiti
8
+
9
+ 本包是 **aiti** 生态的组成部分——以 [pi](https://pi.dev) 为引擎的个人 AI 开发工作台与本地调试注入生态:**aiti-agent**(自托管 Web 工作台,基于开源项目 [pi-web](https://github.com/aiti-ai/pi-web) 构建,浏览器为主操作面)+ 各开发工具内的调试注入(aiti-devtools)+ 丰富的扩展体系。
10
+
11
+ - 工作台(aiti-agent,基于 pi-web): <https://github.com/aiti-ai/pi-web>
12
+ - 生态仓库: <https://github.com/aiti-ai/aiti-ai>
13
+ - 官网: <https://aiti.pw>
14
+
15
+ ## 安装
16
+
17
+ 不直接安装——aiti 扩展的运行时共享依赖。扩展在各自 `package.json` 的 dependencies 里声明本包;extman reconcile 统一装入共享根 `node_modules`(jiti walk-up 解析)。
18
+
19
+ ## 文档
20
+
21
+ - 中文文档: <https://aiti.pw/guide/ext-services.html>
22
+ - Documentation (English): <https://aiti.pw/en/guide/ext-services.html>
23
+ - 扩展注册表: <https://aiti.pw/extensions.html> · machine-readable <https://aiti.pw/extensions.json>
24
+
25
+ ## 许可证
26
+
27
+ MIT
@@ -18,9 +18,39 @@ import {
18
18
  registerSpawnEnvDefaults,
19
19
  spawnEnvList,
20
20
  spawnEnvFeature,
21
+ spawnDisplayEnvFeature,
21
22
  captureSpawnEnvFeatures,
22
23
  resolveCliLaunch,
24
+ readUiEnvSnapshot,
25
+ uiEnvDataRoot,
23
26
  } from "./agent-spawn-env.ts";
27
+ import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
28
+ import { tmpdir } from "node:os";
29
+ import { join } from "node:path";
30
+
31
+ // ---------------- aiti-ui-env session-env snapshot ----------------
32
+
33
+ function makeSnapshotRoot(target, envOverrides = {}) {
34
+ const root = mkdtempSync(join(tmpdir(), "ui-env-snap-test-"));
35
+ mkdirSync(join(root, "aiti-ui-env", "cache"), { recursive: true });
36
+ writeFileSync(
37
+ join(root, "aiti-ui-env", "cache", "session-env.json"),
38
+ JSON.stringify({
39
+ target,
40
+ mode: "prefer-headless",
41
+ rationale: "test",
42
+ env: { DISPLAY: ":154", XAUTHORITY: "/tmp/ui-env-154/Xauthority", PATH: "/usr/bin", ...envOverrides },
43
+ updatedAt: new Date().toISOString(),
44
+ }),
45
+ );
46
+ return root;
47
+ }
48
+
49
+ test("uiEnvDataRoot:PI_WEB_DATA_DIR 优先,dev/prod 隔离", () => {
50
+ assert.equal(uiEnvDataRoot({ PI_WEB_DATA_DIR: "/x" }), "/x");
51
+ assert.match(uiEnvDataRoot({ PI_WEB_DEV_DIST: "1", HOME: tmpdir() }), /web-dev/);
52
+ assert.match(uiEnvDataRoot({ HOME: tmpdir() }), /\.pi.web..?data|\.pi\/web\/data|\.pi\/web-dev\/data/);
53
+ });
24
54
 
25
55
  test("piWebSelfBase:PORT + PI_WEB_BASE_PATH 归一(尾斜杠剥除)", () => {
26
56
  assert.equal(piWebSelfBase({ PORT: "3001", PI_WEB_BASE_PATH: "/dev/" }), "http://127.0.0.1:3001/dev");
@@ -157,6 +187,68 @@ test("spawnEnvFeature:声明形状(id/type=textlist,含 -NAME 语法说明
157
187
  assert.ok(f.description.includes("-NAME"));
158
188
  });
159
189
 
190
+ test("readUiEnvSnapshot:白名单键过滤 + 坏快照返回 null", () => {
191
+ const root = makeSnapshotRoot("headless");
192
+ const snap = readUiEnvSnapshot({ PI_WEB_DATA_DIR: root });
193
+ assert.ok(snap);
194
+ assert.equal(snap.target, "headless");
195
+ assert.equal(snap.env.DISPLAY, ":154");
196
+ assert.equal(snap.env.XAUTHORITY, "/tmp/ui-env-154/Xauthority");
197
+ assert.equal("PATH" in snap.env, false, "白名单外键(PATH)不注入");
198
+ // corrupt JSON / bad target → null
199
+ writeFileSync(join(root, "aiti-ui-env", "cache", "session-env.json"), "{broken");
200
+ assert.equal(readUiEnvSnapshot({ PI_WEB_DATA_DIR: root }), null);
201
+ writeFileSync(join(root, "aiti-ui-env", "cache", "session-env.json"), JSON.stringify({ target: "bogus", env: {} }));
202
+ assert.equal(readUiEnvSnapshot({ PI_WEB_DATA_DIR: root }), null);
203
+ assert.equal(readUiEnvSnapshot({ PI_WEB_DATA_DIR: join(root, "missing") }), null, "缺文件 → null");
204
+ rmSync(root, { recursive: true, force: true });
205
+ });
206
+
207
+ test("agentSpawnEnv:快照默认注入(auto),off 关闭,target 过滤开关生效", () => {
208
+ const root = makeSnapshotRoot("headless");
209
+ const pe = { PI_WEB_DATA_DIR: root, FOO: "f" };
210
+ captureSpawnEnvFeatures(null); // no feature → default auto
211
+ const out = agentSpawnEnv({ extId: "aiti-pi-agent", envList: "K=1", processEnv: pe, warn: () => {} });
212
+ assert.equal(out.DISPLAY, ":154", "默认 auto:快照 DISPLAY 注入");
213
+ assert.equal(out.K, "1");
214
+ captureSpawnEnvFeatures({ get: (_e, fid) => (fid === "spawn.displayEnv" ? "off" : undefined) });
215
+ const outOff = agentSpawnEnv({ extId: "aiti-pi-agent", processEnv: pe, warn: () => {} });
216
+ assert.equal("DISPLAY" in outOff, false, "off:不注入");
217
+ captureSpawnEnvFeatures({ get: (_e, fid) => (fid === "spawn.displayEnv" ? "desktop" : undefined) });
218
+ const outMismatch = agentSpawnEnv({ extId: "aiti-pi-agent", processEnv: pe, warn: () => {} });
219
+ assert.equal("DISPLAY" in outMismatch, false, "desktop 开关 + headless 快照 → 不注入");
220
+ const rootD = makeSnapshotRoot("desktop", { DISPLAY: ":1" });
221
+ const outMatch = agentSpawnEnv({ extId: "aiti-pi-agent", processEnv: { PI_WEB_DATA_DIR: rootD }, warn: () => {} });
222
+ assert.equal(outMatch.DISPLAY, ":1", "desktop 开关 + desktop 快照 → 注入");
223
+ captureSpawnEnvFeatures(null);
224
+ // no snapshot → zero behavior change (PI_WEB_DATA_DIR points at an empty dir so
225
+ // the test never reads the real ~/.pi snapshot written by a running instance)
226
+ const emptyRoot = mkdtempSync(join(tmpdir(), "ui-env-snap-empty-"));
227
+ const outNone = agentSpawnEnv({ extId: "aiti-pi-agent", envList: "K=1", processEnv: { PI_WEB_DATA_DIR: emptyRoot, FOO: "f" }, warn: () => {} });
228
+ assert.equal("DISPLAY" in outNone, false, "无快照 → 零变化");
229
+ rmSync(root, { recursive: true, force: true });
230
+ rmSync(rootD, { recursive: true, force: true });
231
+ rmSync(emptyRoot, { recursive: true, force: true });
232
+ });
233
+
234
+ test("agentSpawnEnv:用户 spawn.env 仍最高优先(覆盖 / -DISPLAY 拔除快照注入)", () => {
235
+ const root = makeSnapshotRoot("headless");
236
+ const pe = { PI_WEB_DATA_DIR: root };
237
+ const outOv = agentSpawnEnv({ extId: "aiti-pi-agent", envList: "DISPLAY=:0", processEnv: pe, warn: () => {} });
238
+ assert.equal(outOv.DISPLAY, ":0", "用户列表覆盖快照");
239
+ const outRm = agentSpawnEnv({ extId: "aiti-pi-agent", envList: "-DISPLAY", processEnv: pe, warn: () => {} });
240
+ assert.equal("DISPLAY" in outRm, false, "-DISPLAY 拔除快照注入");
241
+ rmSync(root, { recursive: true, force: true });
242
+ });
243
+
244
+ test("spawnDisplayEnvFeature:声明形状(id/type=string)", () => {
245
+ const f = spawnDisplayEnvFeature("G");
246
+ assert.equal(f.id, "spawn.displayEnv");
247
+ assert.equal(f.type, "string");
248
+ assert.equal(f.group, "G");
249
+ assert.ok(f.description.includes("headless"));
250
+ });
251
+
160
252
  test("resolveCliLaunch:win32 下 .cmd/.bat command → shell:true(lessons §0.1 欠账收口)", () => {
161
253
  const r = resolveCliLaunch({ defaultCommand: "cli", command: process.platform === "win32" ? "C:\tools\agent.cmd" : "cli", driverArgs: ["--flag"] });
162
254
  if (process.platform === "win32") {
@@ -29,6 +29,10 @@
29
29
  * spawn.command / spawn.argsPrefix extman feature(spawnCommandFeature/spawnArgsPrefixFeature)。
30
30
  */
31
31
 
32
+ import { readFileSync } from "node:fs";
33
+ import { homedir } from "node:os";
34
+ import { join } from "node:path";
35
+
32
36
  /** extman feature 源(ctx.features,startup 捕获;DI 方案 P1 同款,缺省走 __piWebExt 兜底) */
33
37
  type FeaturesLike = { get(extId: string, fid: string): boolean | string | undefined };
34
38
 
@@ -170,12 +174,70 @@ export function spawnArgsPrefix(extId: string): string {
170
174
  return readStringFeature(extId, "spawn.argsPrefix");
171
175
  }
172
176
 
177
+ // ---------------- UI environment session snapshot (aiti-ui-env) ----------------
178
+
179
+ /**
180
+ * aiti-ui-env writes a snapshot of its mode-arbiter decision
181
+ * (<dataRoot>/aiti-ui-env/cache/session-env.json: which target — Xvfb headless
182
+ * display or the real desktop — is active, plus the env to reach it) whenever
183
+ * the resolution changes. agentSpawnEnv merges the snapshot's display keys into
184
+ * every spawned agent session, so a fresh session's bash tools and stdio MCP
185
+ * servers land on the chosen display. This is the piece that makes the
186
+ * extension panel's "display mode" actually take effect for sessions.
187
+ *
188
+ * Merge position: after `extra`, BEFORE the registered defaults and the user's
189
+ * extman spawn.env list — the user can always override (DISPLAY=:0) or remove
190
+ * (-DISPLAY) the injected keys.
191
+ *
192
+ * Per-extension opt-out via the extman feature `spawn.displayEnv`:
193
+ * "" / auto (default) → inject whenever a snapshot exists
194
+ * off → never inject
195
+ * headless / desktop → inject only when the snapshot's target matches
196
+ *
197
+ * No snapshot (extension absent / display resolution never succeeded) → zero
198
+ * behavior change, so defaulting to auto is safe.
199
+ */
200
+
201
+ const UI_ENV_SNAPSHOT_KEYS = [
202
+ "DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "XDG_RUNTIME_DIR",
203
+ "XDG_SESSION_TYPE", "GDK_BACKEND", "WAYLAND_DISPLAY",
204
+ "GTK_MODULES", "QT_ACCESSIBILITY", "NO_AT_BRIDGE",
205
+ "UI_ENV_VNC_PORT", "UI_ENV_VNC_WEB_PORT",
206
+ ] as const;
207
+
208
+ /** Extension data root (<webRoot>/data with the same dev/prod isolation as lib/ext/data-dir.ts) */
209
+ export function uiEnvDataRoot(processEnv: Record<string, string | undefined>): string {
210
+ const explicit = processEnv.PI_WEB_DATA_DIR;
211
+ if (explicit) return explicit;
212
+ const root = processEnv.PI_WEB_DEV_DIST === "1" ? join(homedir(), ".pi", "web-dev", "data") : join(homedir(), ".pi", "web", "data");
213
+ return root;
214
+ }
215
+
216
+ export interface UiEnvSnapshot { target: string; mode?: string; rationale?: string; env: Record<string, string>; updatedAt?: string; }
217
+
218
+ /** Read the aiti-ui-env session-env snapshot; null = absent/corrupt (never throws). */
219
+ export function readUiEnvSnapshot(processEnv?: Record<string, string | undefined>): UiEnvSnapshot | null {
220
+ const env = processEnv ?? (process.env as Record<string, string | undefined>);
221
+ try {
222
+ const raw = readFileSync(join(uiEnvDataRoot(env), "aiti-ui-env", "cache", "session-env.json"), "utf8");
223
+ const d = JSON.parse(raw) as UiEnvSnapshot;
224
+ if ((d.target !== "headless" && d.target !== "desktop") || !d.env || typeof d.env !== "object") return null;
225
+ const out: Record<string, string> = {};
226
+ for (const k of UI_ENV_SNAPSHOT_KEYS) {
227
+ const v = (d.env as Record<string, unknown>)[k];
228
+ if (typeof v === "string") out[k] = v;
229
+ }
230
+ return { target: d.target, mode: d.mode, rationale: d.rationale, env: out, updatedAt: d.updatedAt };
231
+ } catch { return null; }
232
+ }
233
+
173
234
  /**
174
235
  * spawn env 统一构造。
175
236
  * - cli + governance:走治理白名单(external-governance.ts 的 governanceEnv)为基底,
176
237
  * 自动 bridgeEnv 进 extra(白名单外仍注入);
177
238
  * - 无 governance(cursor/qoder 等全量透传派):processEnv 基底 + bridgeEnv + extra;
178
- * - 再按序叠加:扩展注册侧默认列表(registerSpawnEnvDefaults)→ 用户 extman spawn.env
239
+ * - merged in order: aiti-ui-env display-env snapshot (spawn.displayEnv switch, default auto)
240
+ * → registered defaults (registerSpawnEnvDefaults) → user extman spawn.env
179
241
  * (可覆盖/可 -NAME 排除一切,含自动注入项——逃生口)。
180
242
  */
181
243
  export function agentSpawnEnv(opts: {
@@ -195,6 +257,16 @@ export function agentSpawnEnv(opts: {
195
257
  } else {
196
258
  out = { ...(processEnv as Record<string, string>), ...bridge, ...opts.extra };
197
259
  }
260
+ // aiti-ui-env display snapshot (per-extension spawn.displayEnv switch; default auto)
261
+ const displayMode = String(readStringFeature(opts.extId ?? "", "spawn.displayEnv") || "auto").trim().toLowerCase();
262
+ if (displayMode !== "off") {
263
+ const snap = readUiEnvSnapshot(processEnv);
264
+ if (snap && (displayMode === "" || displayMode === "auto" || displayMode === snap.target)) {
265
+ for (const k of UI_ENV_SNAPSHOT_KEYS) {
266
+ if (k in snap.env) out[k] = snap.env[k];
267
+ }
268
+ }
269
+ }
198
270
  const onWarning = opts.warn ?? ((m: string) => console.warn(`[spawn.env] ${m}`));
199
271
  const warnings: string[] = [];
200
272
  const defaultsList = opts.extId ? registeredDefaults.get(opts.extId) || "" : "";
@@ -225,6 +297,25 @@ export function spawnEnvFeature(group?: string): {
225
297
  };
226
298
  }
227
299
 
300
+ /** extman feature declaration: spawn.displayEnv (aiti-ui-env display snapshot injection switch) */
301
+ export function spawnDisplayEnvFeature(group?: string): {
302
+ id: string; type: "string"; label: string; description: string; value: string; placeholder: string; group?: string;
303
+ } {
304
+ return {
305
+ id: "spawn.displayEnv",
306
+ ...(group ? { group } : {}),
307
+ type: "string",
308
+ label: "显示环境注入",
309
+ description:
310
+ "把 aiti-ui-env 显示模式裁决出的显示环境(DISPLAY/XAUTHORITY/DBUS 等)注入本扩展 spawn 的会话进程," +
311
+ "新会话里的 GUI 程序与 MCP 即落在对应屏幕(虚拟屏可经浏览器 VNC 查看)。取值:留空或 auto = 跟随显示模式(快照存在即注入);" +
312
+ "off = 不注入;headless = 仅虚拟屏快照注入;desktop = 仅真实桌面快照注入。改完下一轮 spawn 生效;" +
313
+ "spawn.env 里同名变量仍可覆盖(如 DISPLAY=:0)或 -DISPLAY 排除。",
314
+ value: "",
315
+ placeholder: "auto",
316
+ };
317
+ }
318
+
228
319
  /** extman feature 声明:spawn.command(启动命令覆盖;P1' 启动包装,方案 docs/aiti-custom-agent-plan.md §3.5) */
229
320
  export function spawnCommandFeature(group?: string): {
230
321
  id: string; type: "string"; label: string; description: string; value: string; placeholder: string; group?: string;
package/dev-pack.mjs CHANGED
@@ -77,7 +77,7 @@ export function agentsMdTemplate(extId) {
77
77
 
78
78
  /** 默认 tools/build.mjs(esbuild 单包零配置;扩展自带 tools/build.mjs 则不走到这里)。 */
79
79
  function buildMjsTemplate(extId, extRoot, clientOut, entryRel) {
80
- const repoHint = "/home/pi/workspace/pi-work"; // 现场构建探测源码仓 node_modules 用(三机各不同,缺失时走 npm exec)
80
+ // No hardcoded checkout path: candidates are resolved at run time (see the template below).
81
81
  return `/**
82
82
  * ${extId} · 现场构建入口(dev-pack 默认模板,esbuild 单包零配置)
83
83
  * 用法:node tools/build.mjs
@@ -96,12 +96,25 @@ const entryRel = ${JSON.stringify(entryRel || "")};
96
96
 
97
97
  // esbuild 解析:部署目录 node_modules → 源码仓 node_modules(本机开发场景)→ PATH 上的 esbuild → npm exec 现拉。
98
98
  // 注意:node_modules/esbuild/bin/esbuild 是原生二进制(ELF/Mach-O),必须直接执行(不能当 JS 跑)。
99
+ // Checkout roots are discovered by walking up from the extension dir (a root has node_modules/),
100
+ // plus AITI_REPO_ROOT when set — no machine-specific absolute paths baked into generated files.
101
+ function repoCandidates() {
102
+ const out = [];
103
+ if (process.env.AITI_REPO_ROOT) out.push(process.env.AITI_REPO_ROOT.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
104
+ let d = extRoot;
105
+ for (let i = 0; i < 8; i++) {
106
+ out.push(d.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
107
+ const up = dirname(d);
108
+ if (up === d) break;
109
+ d = up;
110
+ }
111
+ return out;
112
+ }
99
113
  function findEsbuild() {
100
114
  const home = (process.env.HOME || process.env.USERPROFILE || "").split(pathSep).join("/");
101
115
  const candidates = [
102
116
  extRoot + "/node_modules/esbuild/bin/esbuild",
103
- home + "/workspace/pi-work/node_modules/esbuild/bin/esbuild",
104
- "D:/workspace/pi-work/node_modules/esbuild/bin/esbuild", // 155 win(源码在 D 盘)
117
+ ...repoCandidates(),
105
118
  ];
106
119
  for (const c of candidates) {
107
120
  if (!existsSync(c)) continue;
package/dock-icons.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  /**
2
- * _shared/dock-icons.ts — dock 体系操作图标(方位 / 移动 / 导航)的**单一数据源**。
2
+ * _shared/dock-icons.ts — single source of truth for dock system icons:
3
+ * operational icons (position / move / navigate) + block semantic icons
4
+ * (collapsed-header title icon, consumed by the DockBody icon prop and
5
+ * manifest static-entry meta.icon).
3
6
  *
4
- * 用途(方案 docs/pi-web-dock-icon-row-plan.md):
5
- * · 位置菜单「方位图标排」(浮窗 / 左栏 / 右栏 / 预留底部)——D1 React / D2·D3 DOM 多端一致;
6
- * · DockBody ⋮「上移 / 下移」移动图标;
7
- * · 导航类字符按钮图标化(chevron-left/right、arrow-up)。
7
+ * Usage (plan docs/pi-web-dock-icon-row-plan.md):
8
+ * · position menu icon rows (float / left / right / reserved bottom) — D1 React / D2·D3 DOM consistent;
9
+ * · DockBody ⋮ "move up / down" icons;
10
+ * · navigation character buttons as icons (chevron-left/right, arrow-up);
11
+ * · block semantic icons (folder/clock/bot/…): sidebar block-header icon + lazy-extension
12
+ * static shell (manifest entry icon field, name string → rendered by DockBody dockIconEl).
8
13
  *
9
14
  * 设计约定:
10
15
  * · 不依赖 react、不读部署资产——区别于 `_shared/icons/*.svg`(扩展条目图标契约,需宿主
@@ -18,9 +23,14 @@
18
23
  export type DockIconName =
19
24
  | "float" | "new-window" | "panel-left" | "panel-right" | "panel-bottom"
20
25
  | "chevron-up" | "chevron-down" | "chevron-left" | "chevron-right" | "arrow-up"
21
- | "pin" | "x" | "trash" | "move-diagonal-2";
26
+ | "pin" | "pin-off" | "x" | "trash" | "move-diagonal-2"
27
+ | "folder" | "clock" | "bot" | "library" | "shield-check"
28
+ | "git-branch" | "history" | "file" | "plug" | "mic" | "box"
29
+ | "aiti-ai-logo";
22
30
 
23
- /** 单个 SVG 子节点(attrs 用 SVG 原生名;全部小写、React/DOM 双兼容)。 */
31
+ /** Single SVG child node. attrs use native SVG kebab-case names (verbatim for DOM
32
+ * setAttribute; for React JSX spread them through dockIconReactAttrs — React rejects
33
+ * kebab-case SVG props with an "Invalid DOM property" warning). */
24
34
  export interface DockIconNode {
25
35
  tag: "path" | "rect" | "circle" | "line" | "polyline";
26
36
  attrs: Record<string, string | number>;
@@ -29,6 +39,10 @@ export interface DockIconNode {
29
39
  const P = (d: string): DockIconNode => ({ tag: "path", attrs: { d } });
30
40
  const R = (x: number, y: number, width: number, height: number, rx = 2): DockIconNode =>
31
41
  ({ tag: "rect", attrs: { x, y, width, height, rx } });
42
+ /** 节点级细线覆盖:stroke-width 1.5(24 viewBox)→ 13px 渲染 ≈0.81px,与 Catppuccin
43
+ * 文件夹图标(16 viewBox / stroke 1)同线宽。子节点显式属性优先于根继承,三端
44
+ * (dockIconEl / createDockIconSvg / dockIconDecl 序列化)attrs 全透传,零特判。 */
45
+ const thin = (n: DockIconNode): DockIconNode => ({ ...n, attrs: { ...n.attrs, "stroke-width": 1.5 } });
32
46
 
33
47
  /** 图标节点表(lucide 图形;「方框+粗边」= panel-* 家族,与截图同款语言)。 */
34
48
  export const DOCK_ICON_NODES: Record<DockIconName, DockIconNode[]> = {
@@ -64,6 +78,12 @@ export const DOCK_ICON_NODES: Record<DockIconName, DockIconNode[]> = {
64
78
  ],
65
79
  /** 关闭:×(lucide x;⋮ 区块操作「关闭」)。 */
66
80
  x: [P("M18 6 6 18"), P("m6 6 12 12")],
81
+ /** 取消钉住态:图钉 + 斜删除线(lucide pin-off;移动行钉住钮已钉态,与 MiPin 同语义族)。 */
82
+ "pin-off": [
83
+ { tag: "line", attrs: { x1: 12, y1: 17, x2: 12, y2: 22 } },
84
+ P("M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16h14v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1v4.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24Z"),
85
+ { tag: "line", attrs: { x1: 2, y1: 2, x2: 22, y2: 22 } },
86
+ ],
67
87
  /** 移除本实例:垃圾桶(lucide trash;多实例区块 ⋮「移除本实例」,与 aiti-folder MiTrash 同形)。 */
68
88
  trash: [
69
89
  { tag: "polyline", attrs: { points: "3 6 5 6 21 6" } },
@@ -77,8 +97,108 @@ export const DOCK_ICON_NODES: Record<DockIconName, DockIconNode[]> = {
77
97
  P("M19 13v6h-6"),
78
98
  P("M5 5l14 14"),
79
99
  ],
100
+
101
+ /* ── Block semantic icons (collapsed-header icons; lucide line style) ── */
102
+ /** Projects block (session-manager projects): the aiti-ai logo as line art (chosen by
103
+ * the user 2026-11-26 from the icon candidates preview; prototype = aiti-docs
104
+ * docs/.vuepress/public/logo.svg). Three brand elements: large-rounded square (the
105
+ * gradient tile) + geometric letter a (circle + stem) + top-right spark (from the
106
+ * logo's yellow dot). Visual weight kept on par with the folder/file glyph family:
107
+ * the spark dot is stroked, not filled (a filled node reads much heavier at 13px),
108
+ * and the letter circle stays small so line density matches single-outline glyphs. */
109
+ "aiti-ai-logo": [
110
+ thin(R(3, 3, 18, 18, 4)),
111
+ thin({ tag: "circle", attrs: { cx: 10, cy: 14, r: 2.8 } }),
112
+ thin(P("M12.8 11.2v5.6")),
113
+ thin({ tag: "circle", attrs: { cx: 16.8, cy: 7.2, r: 1.2 } }),
114
+ thin(P("m18.8 5.3 1.5-1.6")),
115
+ thin(P("m19.2 8.2 2.1-.4")),
116
+ ],
117
+ /** Folder block (aiti-folder faces): single folder (lucide folder). */
118
+ folder: [
119
+ P("M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z"),
120
+ ],
121
+ /** Scheduled tasks block (aiti-ai-schedule tasks): clock (lucide clock). */
122
+ clock: [
123
+ { tag: "circle", attrs: { cx: 12, cy: 12, r: 10 } },
124
+ { tag: "polyline", attrs: { points: "12 6 12 12 16 14" } },
125
+ ],
126
+ /** Subagent fleet block (aiti-subagents fleet): robot (lucide bot). */
127
+ bot: [
128
+ P("M12 8V4H8"),
129
+ R(4, 8, 16, 12),
130
+ P("M2 14h2"),
131
+ P("M20 14h2"),
132
+ P("M15 13v2"),
133
+ P("M9 13v2"),
134
+ ],
135
+ /** Prompt library block (aiti-prompts panel): bookshelf lines (lucide library). */
136
+ library: [
137
+ P("m16 6 4 14"),
138
+ P("M12 6v14"),
139
+ P("M8 8v12"),
140
+ P("M4 4v16"),
141
+ ],
142
+ /** Model availability block (aiti-model-check panel): shield + check (lucide shield-check). */
143
+ "shield-check": [
144
+ P("M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"),
145
+ P("m9 12 2 2 4-4"),
146
+ ],
147
+ /** Watch paths block (aiti-git-trace watch): branch (lucide git-branch). */
148
+ "git-branch": [
149
+ { tag: "line", attrs: { x1: 6, y1: 3, x2: 6, y2: 15 } },
150
+ { tag: "circle", attrs: { cx: 18, cy: 6, r: 3 } },
151
+ { tag: "circle", attrs: { cx: 6, cy: 18, r: 3 } },
152
+ P("M18 9a9 9 0 0 1-9 9"),
153
+ ],
154
+ /** Timeline block (aiti-git-trace timeline): clock + counterclockwise arrow (lucide history). */
155
+ history: [
156
+ P("M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"),
157
+ P("M3 3v5h5"),
158
+ P("M12 7v5l4 2"),
159
+ ],
160
+ /** File panel block (aiti-editor file faces): document (lucide file). */
161
+ file: [
162
+ P("M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"),
163
+ P("M14 2v4a2 2 0 0 0 2 2h4"),
164
+ ],
165
+ /** ACP management block (aiti-acp-agent manage): plug (lucide plug). */
166
+ plug: [
167
+ P("M12 22v-5"),
168
+ P("M9 8V2"),
169
+ P("M15 8V2"),
170
+ P("M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z"),
171
+ ],
172
+ /** Speech recognition block (aiti-ai-input asr): microphone (lucide mic). */
173
+ mic: [
174
+ P("M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"),
175
+ P("M19 10v2a7 7 0 0 1-14 0v-2"),
176
+ { tag: "line", attrs: { x1: 12, y1: 19, x2: 12, y2: 22 } },
177
+ ],
178
+ /** Dock demo block (demo): 3D box (lucide box). */
179
+ box: [
180
+ P("M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"),
181
+ P("m3.3 7 8.7 5 8.7-5"),
182
+ P("M12 22V12"),
183
+ ],
80
184
  };
81
185
 
186
+ /* ── Host-contract form export (for registering-entry meta.icon) ── */
187
+
188
+ /* ── Host-contract form export (for registering-entry meta.icon) ── */
189
+
190
+ /** Name-table glyph → host ExtUiItemIcon contract form `{ svg: markup }` (inner markup,
191
+ * 24×24 line style). For extensions declaring icons on registering entries
192
+ * (rightFileDock meta.icon → dock tab semantic icon): the host's renderExtItemIcon
193
+ * renders it — no dependency on the extension-side DockBody; the glyph definition
194
+ * still has its single source in this name table. */
195
+ export function dockIconDecl(name: DockIconName): { svg: string } {
196
+ const markup = DOCK_ICON_NODES[name]
197
+ .map((n) => `<${n.tag} ${Object.entries(n.attrs).map(([k, v]) => `${k}="${v}"`).join(" ")} />`)
198
+ .join("");
199
+ return { svg: markup };
200
+ }
201
+
82
202
  /** zone / 位置 → 方位图标名(D1/D2/D3 位置菜单数据共用)。 */
83
203
  export function dockIconOfZone(zone: string): DockIconName {
84
204
  if (zone === "float" || zone === "floating") return "float";
@@ -111,12 +231,11 @@ export function createDockIconSvg(name: DockIconName, size = 16): SVGElement {
111
231
  return svg;
112
232
  }
113
233
 
114
- /* ── React 端(D1 ext-float-dock.ts 与各扩展):消费方以 ctx.h / JSX 组装 ──
115
- * 用法(h 版):
116
- * h("svg", { width: 16, height: 16, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
117
- * strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" },
118
- * ...DOCK_ICON_NODES[name].map((n, i) => h(n.tag, { key: i, ...n.attrs })))
119
- * 此处提供 SVG 根属性常量,避免两端漂移。 */
234
+ /* ── React side (D1 ext-float-dock.ts + extensions): consumers assemble via ctx.h / JSX ──
235
+ * Usage (h flavor):
236
+ * h("svg", { width: 16, height: 16, ...DOCK_ICON_SVG_ROOT_PROPS, "aria-hidden": "true" },
237
+ * ...DOCK_ICON_NODES[name].map((n, i) => h(n.tag, { key: i, ...dockIconReactAttrs(n.attrs) })))
238
+ * Root props constant lives here so both render flavors never drift. */
120
239
  export const DOCK_ICON_SVG_ROOT_PROPS = {
121
240
  viewBox: "0 0 24 24",
122
241
  fill: "none",
@@ -125,3 +244,16 @@ export const DOCK_ICON_SVG_ROOT_PROPS = {
125
244
  strokeLinecap: "round",
126
245
  strokeLinejoin: "round",
127
246
  } as const;
247
+
248
+ /** React-side attr-name adaptation: native kebab-case SVG names ("stroke-width",
249
+ * "stroke-linecap", ...) → JSX camelCase, so node data can stay DOM-native while
250
+ * React consumers stay warning-free. aria-/data- prefixed keys pass through unchanged. */
251
+ export function dockIconReactAttrs(attrs: Record<string, string | number>): Record<string, string | number> {
252
+ const out: Record<string, string | number> = {};
253
+ for (const [k, v] of Object.entries(attrs)) {
254
+ out[!k.includes("-") || k.startsWith("aria-") || k.startsWith("data-")
255
+ ? k
256
+ : k.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase())] = v;
257
+ }
258
+ return out;
259
+ }