Просмотр исходного кода

发布 v0.4.1:完善共享桌面与聊天文件管理

同步已验证构建提交 03632f198c0b977a5816c8ce326c4df6d1767973 的完整源码文件树,保留 GitHub 既有历史。
LSamien 2 месяцев назад
Родитель
Сommit
ca8bc10bac
69 измененных файлов с 1421 добавлено и 171 удалено
  1. 2 0
      .dockerignore
  2. 6 1
      Dockerfile
  3. 2 2
      README.md
  4. 109 0
      compose.desktops.yaml
  5. 2 1
      compose.yaml
  6. 4 0
      deploy/compose-desktops.json
  7. 4 0
      deploy/computer/Dockerfile
  8. 193 0
      deploy/computer/compose_bridge.py
  9. 5 0
      docker.env.example
  10. 47 1
      docs/docker-install.md
  11. 4 0
      docs/local-vm.md
  12. 2 2
      docs/macos-app.md
  13. 16 0
      docs/releases/v0.4.1.md
  14. 2 2
      docs/runner.md
  15. BIN
      docs/screenshots/compose-desktops/agent-desktop.png
  16. BIN
      docs/screenshots/docker-vm/agent-desktop.png
  17. 17 0
      docs/verification/2026-09-09-message-files/README.md
  18. BIN
      docs/verification/2026-09-09-message-files/web.png
  19. 2 2
      package-lock.json
  20. 1 1
      package.json
  21. 3 3
      release.json
  22. 22 0
      scripts/generate-desktop-compose.mjs
  23. 15 3
      src/client/components/app/FloatingResourceSearch.vue
  24. 10 6
      src/client/components/app/LocalVmSettingsPanel.vue
  25. 20 15
      src/client/components/app/RunnerSettingsPanel.vue
  26. 2 2
      src/client/components/app/SettingsCenterDialog.vue
  27. 11 4
      src/client/components/messages/MarkdownContent.vue
  28. 8 7
      src/client/components/messages/MessageTimeline.vue
  29. 1 1
      src/client/components/messages/TurnTrace.vue
  30. 35 6
      src/client/components/workspace/LocalVmChatPanel.vue
  31. 6 5
      src/client/components/workspace/viewModels.ts
  32. 1 1
      src/client/stores/artifacts.ts
  33. 7 28
      src/client/utils/artifacts.ts
  34. 3 0
      src/client/utils/messageDisplay.ts
  35. 37 3
      src/client/views/ConversationsView.vue
  36. 9 6
      src/runner/agent.ts
  37. 47 0
      src/runner/computers/compose.ts
  38. 3 0
      src/runner/computers/container.ts
  39. 11 1
      src/runner/computers/localVm.ts
  40. 2 1
      src/runner/computers/pool.ts
  41. 7 2
      src/runner/config.ts
  42. 2 1
      src/runner/worker/control.ts
  43. 10 3
      src/runner/worker/gateway.ts
  44. 14 2
      src/server/app.ts
  45. 6 0
      src/server/chatCache.ts
  46. 34 0
      src/server/composeDesktops.ts
  47. 8 0
      src/server/config.ts
  48. 39 9
      src/server/localVm.ts
  49. 32 6
      src/server/runnerHub.ts
  50. 14 2
      src/server/sharedComputers.ts
  51. 16 12
      src/server/workspaceAssets.ts
  52. 3 3
      src/server/workspaceRoutes.ts
  53. 22 3
      src/server/workspaceStore.ts
  54. 6 0
      src/shared/composeDesktops.ts
  55. 8 0
      src/shared/localVm.ts
  56. 89 0
      src/shared/messageFiles.ts
  57. 1 1
      src/shared/runner.ts
  58. 12 3
      tests/client/artifactStore.test.ts
  59. 78 0
      tests/client/conversationSearchDelete.test.ts
  60. 15 0
      tests/client/markdownContent.test.ts
  61. 11 0
      tests/client/workspacePresentation.test.ts
  62. 3 1
      tests/e2e/team-tools.spec.ts
  63. 39 7
      tests/e2e/workspace-chat.spec.ts
  64. 5 0
      tests/fixtures/workspace-server.ts
  65. 107 11
      tests/live/dockerPlatform.live.test.ts
  66. 73 0
      tests/server/composeDesktops.test.ts
  67. 27 1
      tests/server/localVmRoutes.test.ts
  68. 61 0
      tests/server/messageFiles.test.ts
  69. 8 0
      tests/server/runnerConfig.test.ts

+ 2 - 0
.dockerignore

@@ -17,6 +17,8 @@
 !third-party/**
 !third-party/**
 !scripts/
 !scripts/
 !scripts/**
 !scripts/**
+!bin/
+!bin/**
 !src/
 !src/
 !src/**
 !src/**
 
 

+ 6 - 1
Dockerfile

@@ -12,11 +12,14 @@ COPY tsconfig.json tsconfig.client.json tsconfig.client.build.json tsconfig.serv
 COPY index.html ./
 COPY index.html ./
 COPY public ./public
 COPY public ./public
 COPY scripts ./scripts
 COPY scripts ./scripts
+COPY bin ./bin
 COPY deploy ./deploy
 COPY deploy ./deploy
 COPY third-party ./third-party
 COPY third-party ./third-party
 COPY src ./src
 COPY src ./src
 
 
 RUN npm run build \
 RUN npm run build \
+  && npm run runner:build \
+  && tar -C .runner-build -czf runner-bundle.tar.gz . \
   && npm prune --omit=dev
   && npm prune --omit=dev
 
 
 FROM node:24-bookworm-slim AS runtime
 FROM node:24-bookworm-slim AS runtime
@@ -26,7 +29,8 @@ ENV NODE_ENV=production \
     HERMES_YAOYAO_PORT=15300 \
     HERMES_YAOYAO_PORT=15300 \
     HERMES_YAOYAO_HOME=/var/lib/hermes-yaoyao \
     HERMES_YAOYAO_HOME=/var/lib/hermes-yaoyao \
     HERMES_YAOYAO_CHAT_CACHE_MODE=prefer-local \
     HERMES_YAOYAO_CHAT_CACHE_MODE=prefer-local \
-    HERMES_YAOYAO_SUPERVISE_DASHBOARD=0
+    HERMES_YAOYAO_SUPERVISE_DASHBOARD=0 \
+    HERMES_YAOYAO_LOCAL_VM_HOST=runner
 
 
 WORKDIR /app
 WORKDIR /app
 
 
@@ -36,6 +40,7 @@ COPY --chown=node:node package.json package-lock.json release.json ./
 COPY --chown=node:node --from=builder /app/node_modules ./node_modules
 COPY --chown=node:node --from=builder /app/node_modules ./node_modules
 COPY --chown=node:node --from=builder /app/dist ./dist
 COPY --chown=node:node --from=builder /app/dist ./dist
 COPY --chown=node:node --from=builder /app/dist-server ./dist-server
 COPY --chown=node:node --from=builder /app/dist-server ./dist-server
+COPY --chown=node:node --from=builder /app/build-info.json /app/runner-bundle.tar.gz ./
 
 
 USER node
 USER node
 
 

+ 2 - 2
README.md

@@ -1,6 +1,6 @@
 # 夭夭 Web
 # 夭夭 Web
 
 
-当前 Web 与 macOS 桌面发布版本:**v0.4.0**。桌面版提供 Apple Silicon(arm64)DMG,详见 [发布说明](docs/releases/v0.4.0.md)。
+当前 Web 与 macOS 桌面发布版本:**v0.4.1**。桌面版提供 Apple Silicon(arm64)DMG,详见 [发布说明](docs/releases/v0.4.1.md)。
 
 
 夭夭 Web 为网页、iOS 和安卓提供统一的 Agent、群聊、文件库及语音配置服务。Hermes 通过标准 9119 HTTP/WebSocket 接口执行任务。
 夭夭 Web 为网页、iOS 和安卓提供统一的 Agent、群聊、文件库及语音配置服务。Hermes 通过标准 9119 HTTP/WebSocket 接口执行任务。
 
 
@@ -36,7 +36,7 @@ Web 数据默认保存在 `~/.hermes-yaoyao`,可用 `HERMES_YAOYAO_HOME` 指
 
 
 ## macOS 桌面版
 ## macOS 桌面版
 
 
-在 [v0.4.0 发布页](http://192.168.153.8:3000/samien/hermes-yaoyao/releases/tag/v0.4.0) 下载 `Yaoyao-0.4.0-arm64.dmg`,将“夭夭”拖到应用程序后打开。首次启动会核对并同步配套本机 Web 服务;普通退出保留后台运行,“停止后台服务并退出”可完整停止本应用管理的后台。详细说明见 [macOS App](docs/macos-app.md)。
+在 [v0.4.1 发布页](https://github.com/Lsamien/hermes-yaoyao/releases/tag/v0.4.1) 下载 `Yaoyao-0.4.1-arm64.dmg`,将“夭夭”拖到应用程序后打开。首次启动会核对并同步配套本机 Web 服务;普通退出保留后台运行,“停止后台服务并退出”可完整停止本应用管理的后台。详细说明见 [macOS App](docs/macos-app.md)。
 
 
 此 DMG 使用 Apple Development 开发签名,未做 Apple 公证。
 此 DMG 使用 Apple Development 开发签名,未做 Apple 公证。
 
 

+ 109 - 0
compose.desktops.yaml

@@ -0,0 +1,109 @@
+# Generated from compose.yaml and deploy/compose-desktops.json.
+name: hermes-yaoyao
+
+services:
+  web:
+    build:
+      context: .
+      dockerfile: Dockerfile
+    image: "${HERMES_YAOYAO_IMAGE:-hermes-yaoyao:local}"
+    restart: unless-stopped
+    init: true
+    read_only: true
+    security_opt:
+      - no-new-privileges:true
+    cap_drop:
+      - ALL
+    ports:
+      - "${HERMES_YAOYAO_BIND_ADDRESS:-127.0.0.1}:${HERMES_YAOYAO_PUBLISHED_PORT:-15300}:15300"
+    extra_hosts:
+      - "host.docker.internal:host-gateway"
+    environment:
+      NODE_ENV: production
+      HERMES_YAOYAO_HOST: 0.0.0.0
+      HERMES_YAOYAO_PORT: 15300
+      HERMES_YAOYAO_UPSTREAM: "${HERMES_YAOYAO_UPSTREAM:-http://host.docker.internal:9119}"
+      # Permit localhost access when the published host port differs from the
+      # container's fixed 15300 port; configured public host names remain opt-in.
+      HERMES_YAOYAO_ALLOWED_HOSTS: "localhost,127.0.0.1,${HERMES_YAOYAO_ALLOWED_HOSTS:-}"
+      HERMES_YAOYAO_ALLOW_INSECURE_LAN: "1"
+      HERMES_YAOYAO_SUPERVISE_DASHBOARD: "0"
+      HERMES_YAOYAO_LOCAL_VM_HOST: "runner"
+      HERMES_YAOYAO_COMPOSE_DESKTOPS: "[{\"id\":\"160fe7cd-e530-4ac5-a97f-26c19a362b11\",\"name\":\"共享桌面 1\",\"socketPath\":\"/run/yaoyao-desktops/desktop-1/desktop.sock\"},{\"id\":\"eba5caaf-744e-4f27-bcdd-1f1f35d05a42\",\"name\":\"共享桌面 2\",\"socketPath\":\"/run/yaoyao-desktops/desktop-2/desktop.sock\"}]"
+      HERMES_YAOYAO_CHAT_CACHE_MODE: "${HERMES_YAOYAO_CHAT_CACHE_MODE:-prefer-local}"
+      HERMES_YAOYAO_HOME: /var/lib/hermes-yaoyao
+      HERMES_YAOYAO_APNS_KEY_FILE: "${HERMES_YAOYAO_APNS_KEY_FILE:-}"
+      HERMES_YAOYAO_APNS_KEY_ID: "${HERMES_YAOYAO_APNS_KEY_ID:-}"
+      HERMES_YAOYAO_APNS_TEAM_ID: "${HERMES_YAOYAO_APNS_TEAM_ID:-}"
+      HERMES_YAOYAO_APNS_TOPIC: "${HERMES_YAOYAO_APNS_TOPIC:-}"
+    volumes:
+      - yaoyao-data:/var/lib/hermes-yaoyao
+      - desktop-1-ipc:/run/yaoyao-desktops/desktop-1:ro
+      - desktop-2-ipc:/run/yaoyao-desktops/desktop-2:ro
+    tmpfs:
+      - /tmp:mode=1777
+
+  desktop-1:
+    image: "${YAOYAO_DESKTOP_IMAGE:-hermes-yaoyao-desktop:0.4.0}"
+    build:
+      context: ./deploy/computer
+    hostname: desktop-1
+    extra_hosts:
+      - "desktop-1:127.0.0.1"
+    init: true
+    restart: unless-stopped
+    network_mode: none
+    shm_size: 512m
+    mem_limit: 4g
+    cpus: 2
+    pids_limit: 512
+    security_opt:
+      - no-new-privileges:true
+    cap_drop:
+      - ALL
+    cap_add:
+      - SETUID
+      - SETGID
+      - CHOWN
+      - KILL
+    environment:
+      YAOYAO_COMPOSE_DESKTOP_ID: "160fe7cd-e530-4ac5-a97f-26c19a362b11"
+    volumes:
+      - desktop-1-workspace:/home/cua/workspace
+      - desktop-1-ipc:/run/yaoyao-private/bridge
+  desktop-2:
+    image: "${YAOYAO_DESKTOP_IMAGE:-hermes-yaoyao-desktop:0.4.0}"
+    build:
+      context: ./deploy/computer
+    hostname: desktop-2
+    extra_hosts:
+      - "desktop-2:127.0.0.1"
+    init: true
+    restart: unless-stopped
+    network_mode: none
+    shm_size: 512m
+    mem_limit: 4g
+    cpus: 2
+    pids_limit: 512
+    security_opt:
+      - no-new-privileges:true
+    cap_drop:
+      - ALL
+    cap_add:
+      - SETUID
+      - SETGID
+      - CHOWN
+      - KILL
+    environment:
+      YAOYAO_COMPOSE_DESKTOP_ID: "eba5caaf-744e-4f27-bcdd-1f1f35d05a42"
+    volumes:
+      - desktop-2-workspace:/home/cua/workspace
+      - desktop-2-ipc:/run/yaoyao-private/bridge
+
+volumes:
+  yaoyao-data:
+
+  desktop-1-workspace:
+  desktop-1-ipc:
+  desktop-2-workspace:
+  desktop-2-ipc:

+ 2 - 1
compose.yaml

@@ -5,7 +5,7 @@ services:
     build:
     build:
       context: .
       context: .
       dockerfile: Dockerfile
       dockerfile: Dockerfile
-    image: hermes-yaoyao:local
+    image: "${HERMES_YAOYAO_IMAGE:-hermes-yaoyao:local}"
     restart: unless-stopped
     restart: unless-stopped
     init: true
     init: true
     read_only: true
     read_only: true
@@ -27,6 +27,7 @@ services:
       HERMES_YAOYAO_ALLOWED_HOSTS: "localhost,127.0.0.1,${HERMES_YAOYAO_ALLOWED_HOSTS:-}"
       HERMES_YAOYAO_ALLOWED_HOSTS: "localhost,127.0.0.1,${HERMES_YAOYAO_ALLOWED_HOSTS:-}"
       HERMES_YAOYAO_ALLOW_INSECURE_LAN: "1"
       HERMES_YAOYAO_ALLOW_INSECURE_LAN: "1"
       HERMES_YAOYAO_SUPERVISE_DASHBOARD: "0"
       HERMES_YAOYAO_SUPERVISE_DASHBOARD: "0"
+      HERMES_YAOYAO_LOCAL_VM_HOST: "runner"
       HERMES_YAOYAO_CHAT_CACHE_MODE: "${HERMES_YAOYAO_CHAT_CACHE_MODE:-prefer-local}"
       HERMES_YAOYAO_CHAT_CACHE_MODE: "${HERMES_YAOYAO_CHAT_CACHE_MODE:-prefer-local}"
       HERMES_YAOYAO_HOME: /var/lib/hermes-yaoyao
       HERMES_YAOYAO_HOME: /var/lib/hermes-yaoyao
       HERMES_YAOYAO_APNS_KEY_FILE: "${HERMES_YAOYAO_APNS_KEY_FILE:-}"
       HERMES_YAOYAO_APNS_KEY_FILE: "${HERMES_YAOYAO_APNS_KEY_FILE:-}"

+ 4 - 0
deploy/compose-desktops.json

@@ -0,0 +1,4 @@
+[
+  {"id":"160fe7cd-e530-4ac5-a97f-26c19a362b11","service":"desktop-1","name":"共享桌面 1"},
+  {"id":"eba5caaf-744e-4f27-bcdd-1f1f35d05a42","service":"desktop-2","name":"共享桌面 2"}
+]

+ 4 - 0
deploy/computer/Dockerfile

@@ -94,3 +94,7 @@ LABEL cn.samien.yaoyao.computer-image="1"
 COPY prepare-firefox.sh /usr/local/bin/prepare-yaoyao-firefox.sh
 COPY prepare-firefox.sh /usr/local/bin/prepare-yaoyao-firefox.sh
 RUN chmod 0755 /usr/local/bin/prepare-yaoyao-firefox.sh \
 RUN chmod 0755 /usr/local/bin/prepare-yaoyao-firefox.sh \
     && sed -i '2i /usr/local/bin/prepare-yaoyao-firefox.sh || exit 1' /usr/local/bin/start-openmausbot-cua-driver.sh
     && sed -i '2i /usr/local/bin/prepare-yaoyao-firefox.sh || exit 1' /usr/local/bin/start-openmausbot-cua-driver.sh
+
+COPY compose_bridge.py /usr/local/libexec/yaoyao/compose_bridge.py
+RUN printf '\n[program:yaoyao-compose-desktop]\ncommand=python3 /usr/local/libexec/yaoyao/compose_bridge.py\nuser=root\nautorestart=unexpected\nexitcodes=0\nstartsecs=0\nstdout_logfile=/var/log/supervisor/yaoyao-compose.log\nstderr_logfile=/var/log/supervisor/yaoyao-compose.error.log\npriority=40\n' >> /etc/supervisor/supervisord.conf
+LABEL cn.samien.yaoyao.compose-desktop="1"

+ 193 - 0
deploy/computer/compose_bridge.py

@@ -0,0 +1,193 @@
+"""Private Compose desktop transport. No network port or Docker socket."""
+import base64
+import http.server
+import json
+import os
+from pathlib import Path
+import secrets
+import signal
+import socketserver
+import subprocess
+import threading
+import time
+
+DESKTOP_ID = os.environ.get('YAOYAO_COMPOSE_DESKTOP_ID')
+if not DESKTOP_ID:
+    raise SystemExit(0)
+ROOT = Path('/run/yaoyao-private')
+ROOT.mkdir(exist_ok=True)
+ROOT.chmod(0o700)
+BRIDGE = ROOT / 'bridge'
+BRIDGE.mkdir(exist_ok=True)
+BRIDGE.chmod(0o755)
+SOCKET = BRIDGE / 'desktop.sock'
+INSTANCE = secrets.token_hex(24)
+PID1 = Path('/proc/1/stat').read_text().split()[21]
+RESET = BRIDGE / 'reset.json'
+if RESET.exists() and json.loads(RESET.read_text()).get('pid1') == PID1:
+    raise SystemExit(1)  # A new bridge process alone cannot fence old programs.
+RESET.unlink(missing_ok=True)
+SOCKET.unlink(missing_ok=True)
+LOCK = threading.RLock()
+LEASE = None
+RESTARTING = False
+DRIVER = '/usr/local/libexec/openmausbot/cua-driver'
+CUA_SOCKET = '/run/user/1000/openmausbot-cua.sock'
+ENV = {'PATH': '/opt/venv/bin:/usr/local/bin:/usr/bin:/bin', 'HOME': '/home/cua', 'USER': 'cua', 'DISPLAY': ':1'}
+
+def reset_desktop():
+    global RESTARTING, LEASE
+    with LOCK:
+        if RESTARTING:
+            return
+        RESTARTING = True
+        LEASE = None
+        RESET.write_text(json.dumps({'pid1': PID1}))
+    # Compose restarts the same service and retains its workspace volume.
+    threading.Timer(0.1, lambda: os.kill(1, signal.SIGTERM)).start()
+
+def current(body):
+    if RESTARTING or not LEASE or body.get('token') != LEASE['token'] or body.get('instance') != INSTANCE or LEASE['expires'] <= time.monotonic():
+        raise ValueError('桌面控制授权已失效')
+    return LEASE
+
+def start(argv, cwd):
+    # Change directory after dropping privileges: the persistent workspace is
+    # owned by cua and the bridge does not need DAC_OVERRIDE.
+    wrapper = 'import os,sys;os.chdir(sys.argv[1]);os.execvpe(sys.argv[2],sys.argv[2:],os.environ)'
+    return subprocess.Popen(['python3','-c',wrapper,cwd,*argv], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=ENV, user=1000, group=1000, extra_groups=[], start_new_session=True)
+
+def run(argv, cwd='/home/cua/workspace', data=None, timeout=30):
+    process = start(argv, cwd)
+    try:
+        stdout, stderr = process.communicate(data, timeout=timeout)
+    except subprocess.TimeoutExpired:
+        os.killpg(process.pid, signal.SIGKILL)
+        process.communicate()
+        raise ValueError('桌面画面服务尚未就绪')
+    if len(stdout) + len(stderr) > 8 * 1024 * 1024:
+        raise ValueError('桌面命令输出超过限制')
+    return {'stdout': stdout.decode('utf-8', 'replace'), 'stderr': stderr.decode('utf-8', 'replace'), 'exitCode': process.returncode}
+
+class Handler(http.server.BaseHTTPRequestHandler):
+    def log_message(self, *args):
+        pass
+
+    def do_POST(self):
+        global LEASE
+        try:
+            length = int(self.headers.get('Content-Length', '0'))
+            if length > 36 * 1024 * 1024:
+                raise ValueError('请求过大')
+            body = json.loads(self.rfile.read(length) or b'{}')
+            if body.get('desktopId') != DESKTOP_ID:
+                raise ValueError('桌面身份不匹配')
+            op = self.path
+            if op == '/health':
+                ready = False
+                if not RESTARTING:
+                    try:
+                        result = run([DRIVER, 'call', 'health_report', '{}', '--socket', CUA_SOCKET], timeout=5)
+                        ready = result['exitCode'] == 0
+                    except Exception:
+                        pass
+                result = {'id': DESKTOP_ID, 'protocol': 1, 'instance': INSTANCE, 'ready': ready}
+            elif op == '/acquire':
+                with LOCK:
+                    if RESTARTING:
+                        raise ValueError('桌面正在重置')
+                    if LEASE:
+                        if body.get('requestId') != LEASE['requestId'] or body.get('owner') != LEASE['owner']:
+                            raise ValueError('共享桌面正在使用')
+                        current({'token': LEASE['token'], 'instance': INSTANCE})
+                    else:
+                        if not isinstance(body.get('requestId'), str) or not isinstance(body.get('owner'), str):
+                            raise ValueError('缺少桌面授权身份')
+                        LEASE = {'requestId': body['requestId'], 'owner': body['owner'], 'token': secrets.token_hex(32), 'expires': time.monotonic() + 90, 'active': 0}
+                    result = {'token': LEASE['token'], 'instance': INSTANCE}
+            elif op == '/renew':
+                with LOCK:
+                    current(body)['expires'] = time.monotonic() + 90
+                    result = {'ok': True}
+            elif op == '/release':
+                with LOCK:
+                    current(body)
+                    if LEASE['active'] and not body.get('cancel'):
+                        raise ValueError('共享桌面仍有未结束操作')
+                    LEASE = None
+                    result = {'ok': True}
+                    if body.get('cancel'):
+                        reset_desktop()
+            elif op == '/frame':
+                path = '/tmp/yaoyao-compose-' + secrets.token_hex(12) + '.png'
+                try:
+                    frame = run([DRIVER, 'call', 'get_desktop_state', '{}', '--socket', CUA_SOCKET, '--screenshot-out-file', path], timeout=10)
+                    if frame['exitCode'] != 0:
+                        raise ValueError('桌面画面尚未就绪')
+                    data = Path(path).read_bytes()
+                    if data[1:4] != b'PNG':
+                        raise ValueError('桌面画面无效')
+                    result = {'data': base64.b64encode(data).decode(), 'width': int.from_bytes(data[16:20], 'big'), 'height': int.from_bytes(data[20:24], 'big'), 'capturedAt': int(time.time()*1000)}
+                finally:
+                    Path(path).unlink(missing_ok=True)
+            elif op == '/execute':
+                argv = body.get('argv')
+                if not isinstance(argv, list) or not argv or len(argv) > 64 or any(not isinstance(x, str) or '\0' in x for x in argv) or sum(map(len, argv)) > 65536:
+                    raise ValueError('桌面命令无效')
+                cwd = body.get('cwd', '/home/cua/workspace')
+                if not isinstance(cwd, str) or (cwd != '/home/cua/workspace' and not cwd.startswith('/home/cua/workspace/')) or '..' in Path(cwd).parts:
+                    raise ValueError('Compose 桌面工作目录必须位于 /home/cua/workspace')
+                with LOCK:
+                    lease = current(body)
+                    # Spawn while holding the lease lock, then release the lock
+                    # before waiting so revocation can stop the container.
+                    process = start(argv, cwd)
+                    lease['active'] += 1
+                try:
+                    data = base64.b64decode(body['input']) if body.get('input') else None
+                    stdout, stderr = process.communicate(data, timeout=min(60, max(1, body.get('timeout', 30000)/1000)))
+                    if len(stdout) + len(stderr) > 8*1024*1024:
+                        raise ValueError('桌面命令输出超过限制')
+                    with LOCK:
+                        current(body)
+                    result = {'stdout': stdout.decode('utf-8','replace'), 'stderr': stderr.decode('utf-8','replace'), 'exitCode': process.returncode}
+                except Exception:
+                    reset_desktop()
+                    raise
+                finally:
+                    with LOCK:
+                        if LEASE is lease:
+                            lease['active'] -= 1
+            else:
+                raise ValueError('桌面数量和创建删除由 Compose 管理')
+            payload = json.dumps(result).encode()
+            self.send_response(200)
+        except Exception as exc:
+            code = 'computer_busy' if str(exc) in ('共享桌面正在使用','共享桌面仍有未结束操作') else 'compose_desktop_error'
+            payload = json.dumps({'error': str(exc), 'code': code}, ensure_ascii=False).encode()
+            self.send_response(409)
+        self.send_header('Content-Type','application/json')
+        self.send_header('X-Yaoyao-Desktop-Id',DESKTOP_ID)
+        self.send_header('Content-Length',str(len(payload)))
+        self.end_headers()
+        try:
+            self.wfile.write(payload)
+        except BrokenPipeError:
+            pass
+
+class Server(socketserver.ThreadingMixIn, socketserver.UnixStreamServer):
+    daemon_threads = True
+
+def expire():
+    while True:
+        time.sleep(5)
+        with LOCK:
+            expired = LEASE and LEASE['expires'] <= time.monotonic()
+        if expired:
+            reset_desktop()
+
+server = Server(str(SOCKET), Handler)
+SOCKET.chmod(0o600)
+os.chown(SOCKET,1000,1000)
+threading.Thread(target=expire,daemon=True).start()
+server.serve_forever()

+ 5 - 0
docker.env.example

@@ -1,6 +1,9 @@
 # 宿主机仅在本机发布 15300;需要通过反向代理或可信局域网访问时再改为 0.0.0.0。
 # 宿主机仅在本机发布 15300;需要通过反向代理或可信局域网访问时再改为 0.0.0.0。
 HERMES_YAOYAO_BIND_ADDRESS=127.0.0.1
 HERMES_YAOYAO_BIND_ADDRESS=127.0.0.1
 HERMES_YAOYAO_PUBLISHED_PORT=15300
 HERMES_YAOYAO_PUBLISHED_PORT=15300
+# 可选:使用已经导入或发布的镜像;留空时使用本地构建名称。
+# HERMES_YAOYAO_IMAGE=hermes-yaoyao:local
+# YAOYAO_DESKTOP_IMAGE=hermes-yaoyao-desktop:0.4.0
 
 
 # 部署步骤见 docs/docker-install.md;使用 docker compose --env-file docker.env 启动。
 # 部署步骤见 docs/docker-install.md;使用 docker compose --env-file docker.env 启动。
 # 填写容器可访问的 Hermes Dashboard/Gateway 地址。
 # 填写容器可访问的 Hermes Dashboard/Gateway 地址。
@@ -8,6 +11,8 @@ HERMES_YAOYAO_PUBLISHED_PORT=15300
 HERMES_YAOYAO_UPSTREAM=http://host.docker.internal:9119
 HERMES_YAOYAO_UPSTREAM=http://host.docker.internal:9119
 HERMES_YAOYAO_CHAT_CACHE_MODE=prefer-local
 HERMES_YAOYAO_CHAT_CACHE_MODE=prefer-local
 # 首次登录后在 Web 系统设置中保存 Hermes 连接凭据。
 # 首次登录后在 Web 系统设置中保存 Hermes 连接凭据。
+# 使用 compose.desktops.yaml 可同时部署固定数量的共享桌面容器。
+# 桌面数量以 Compose 为准,Web 仅连接已有桌面;详见 docs/docker-install.md。
 
 
 # 使用域名访问时填写域名,多个值以英文逗号分隔;localhost 和私网 IP 无需填写。
 # 使用域名访问时填写域名,多个值以英文逗号分隔;localhost 和私网 IP 无需填写。
 HERMES_YAOYAO_ALLOWED_HOSTS=
 HERMES_YAOYAO_ALLOWED_HOSTS=

+ 47 - 1
docs/docker-install.md

@@ -46,9 +46,55 @@ docker compose --env-file docker.env logs --tail=100 web
 
 
 登录后创建会话、收发消息、上传并下载附件,验证实际使用流程。
 登录后创建会话、收发消息、上传并下载附件,验证实际使用流程。
 
 
+## 随 Web 一起部署固定共享桌面
+
+使用配套的 **单个 `compose.desktops.yaml`** 部署文件,同时创建 Web 和共享桌面容器。默认示例为两台桌面;不是在 Web 页面里临时创建虚拟机。
+
+```sh
+cp docker.env.example docker.env
+# 配置 Web 发布地址、端口和已有 Hermes 的 9119 地址。
+docker compose --env-file docker.env -f compose.desktops.yaml up -d --build
+docker compose --env-file docker.env -f compose.desktops.yaml ps
+```
+
+- Compose 创建几台,页面就显示几台;没有数量修改、镜像准备、创建、删除或重建按钮。
+- Agent 聊天右上角 **电脑 → 此 Agent 使用的电脑**,选择已有的“共享桌面 1 / 共享桌面 2”等目标。多个 Agent 可以连接同一台共享桌面,复用文件和浏览器资料。
+- 桌面连接使用专用 Unix socket 数据卷。Web 容器不挂载宿主 Docker socket,桌面也不发布 VNC、HTTP 或控制端口。
+- 每台桌面的工作文件放在独立的 `desktop-*-workspace` 命名卷内。Compose 桌面统一使用 `/home/cua/workspace`,不会更改基础 Profile 的工作目录配置。
+- 示例桌面使用 `network_mode: none`,默认没有桌面外网。网络、资源额度、镜像版本和服务数量均由部署者在 Compose 中管理;本机 App 的动态虚拟机模式保持原有方式。
+
+如部署前要调整数量或名称,编辑 `deploy/compose-desktops.json`,保留已有桌面 ID,重新生成配套文件:
+
+```sh
+node scripts/generate-desktop-compose.mjs
+node scripts/generate-desktop-compose.mjs --check
+docker compose --env-file docker.env -f compose.desktops.yaml up -d --build
+```
+
+生成器会把 Web 连接清单、桌面服务和数据卷同步写入同一个 Compose 文件。运行中不能通过 Web API 扩容。不要用 `down --volumes` 更新部署,否则会删除工作文件。
+
+### Hermes 执行连接
+
+Compose 管理桌面,Hermes 执行连接负责模型运行和工具调用。沿用已有执行节点;新部署可在 **设置 → 本地虚拟机 → 打开执行节点设置** 下载程序和注册配置。此部署生成的配置自动带 `managedBy: compose`,执行节点不再创建桌面,也不需要安装 Docker。
+
+执行节点只需已有 Hermes 和 Node.js 24+。默认 Hermes 路径可留空;自定义安装填写绝对路径。把下载的程序和 `runner.json` 放在运行 Hermes 的电脑:
+
+```sh
+mkdir -p yaoyao-runner
+tar -xzf yaoyao-runner.tar.gz -C yaoyao-runner
+chmod 600 runner.json
+node yaoyao-runner/runner.mjs --config /完整路径/runner.json
+```
+
+整份程序目录须保留。节点配置包含私有凭据,不要提交到仓库。运行中的任务或接管操作仍有独占授权;交还后其他成员才能操作。取消无法确认结束的命令时,会重置对应桌面服务来终止旧程序,数量与数据卷保持不变。
+
+只需要 Web 服务、继续使用既有外部动态桌面的部署仍可使用 `compose.yaml`;两种部署文件任选其一,不要让两套 Web 同时写同一数据卷。
+
+验收截图:[Docker Web 的 Agent 桌面](screenshots/compose-desktops/agent-desktop.png)。验收使用独立数据和测试模型服务,桌面与容器连接是真实运行。
+
 ## 数据与备份
 ## 数据与备份
 
 
-Compose 使用 `yaoyao-data` 命名卷,挂载到 `/var/lib/hermes-yaoyao`。账号、SQLite 数据库、聊天缓存、文件及密钥随数据卷持久保存。
+Compose 使用 `yaoyao-data` 命名卷,挂载到 `/var/lib/hermes-yaoyao`。账号、SQLite 数据库、聊天缓存、文件及密钥随数据卷持久保存。固定桌面部署还必须备份每台桌面的 `desktop-*-workspace` 卷;`desktop-*-ipc` 卷只是连接通道。
 
 
 备份时先停止 Web,然后复制完整数据目录,再启动服务:
 备份时先停止 Web,然后复制完整数据目录,再启动服务:
 
 

+ 4 - 0
docs/local-vm.md

@@ -42,3 +42,7 @@ iOS/Android 没有全局虚拟桌面清单、镜像设置或执行环境选择
 本轮验收结果:787 项单元/集成测试通过;7 项环境限定测试跳过。7 项浏览器流程、iOS 3 项界面流程、Android 2 项界面流程通过。真实 Hermes Worker + Docker 流程 2 项通过;自动准备本机 Runner、真实桌面键盘输入及快捷键、重启保留文件、双桌面控制切换的完整界面流程通过。
 本轮验收结果:787 项单元/集成测试通过;7 项环境限定测试跳过。7 项浏览器流程、iOS 3 项界面流程、Android 2 项界面流程通过。真实 Hermes Worker + Docker 流程 2 项通过;自动准备本机 Runner、真实桌面键盘输入及快捷键、重启保留文件、双桌面控制切换的完整界面流程通过。
 
 
 截图:[本地虚拟机设置](screenshots/local-vm/settings.png)、[Agent 聊天右侧电脑面板](screenshots/local-vm/agent-panel.png)、[交互桌面](screenshots/local-vm/interactive-desktop.png)、[双桌面工作区](screenshots/local-vm/two-desktops.png)、[手机聊天入口](screenshots/local-vm/phone-chat-entry.png)。
 截图:[本地虚拟机设置](screenshots/local-vm/settings.png)、[Agent 聊天右侧电脑面板](screenshots/local-vm/agent-panel.png)、[交互桌面](screenshots/local-vm/interactive-desktop.png)、[双桌面工作区](screenshots/local-vm/two-desktops.png)、[手机聊天入口](screenshots/local-vm/phone-chat-entry.png)。
+
+## Docker Web 的固定桌面
+
+Docker Web 使用配套 `compose.desktops.yaml` 时,桌面由 Compose 预先创建。数量固定为部署清单中的数量,全部作为已有共享桌面供 Agent 选择。页面和 API 都不提供数量修改、镜像准备或桌面增删;每个桌面独立保留工作数据。此模式不会改变 macOS 本机的动态虚拟机流程。部署步骤见 [Docker 部署](docker-install.md)。

+ 2 - 2
docs/macos-app.md

@@ -38,7 +38,7 @@ npm run desktop:build
 npm run desktop:test
 npm run desktop:test
 npm run desktop:pack
 npm run desktop:pack
 codesign --verify --deep --strict desktop-release/mac-arm64/夭夭.app
 codesign --verify --deep --strict desktop-release/mac-arm64/夭夭.app
-hdiutil verify desktop-release/Yaoyao-0.4.0-arm64.dmg
+hdiutil verify desktop-release/Yaoyao-0.4.1-arm64.dmg
 ```
 ```
 
 
 开发 App 的 6 项测试通过:真实内置服务启动、账号与 Runner 连接、关闭窗口保持运行、服务崩溃恢复、外部客户端不误停服务、退出清理、加密配置再次启动、偏好保存及手动重新打开、版本不符拒绝、钥匙串失败保护。另有更新器 14 项定向测试通过,包含 App 禁用源码更新及回退。
 开发 App 的 6 项测试通过:真实内置服务启动、账号与 Runner 连接、关闭窗口保持运行、服务崩溃恢复、外部客户端不误停服务、退出清理、加密配置再次启动、偏好保存及手动重新打开、版本不符拒绝、钥匙串失败保护。另有更新器 14 项定向测试通过,包含 App 禁用源码更新及回退。
@@ -56,4 +56,4 @@ Electron 初始化时设置其钥匙串项目名称([v43.4.0 源码](https://g
 
 
 最终实际签名 App 的完整 Runner 导入、加密保存、服务崩溃恢复、窗口关闭保持连接、退出清理和再次打开自动连接均已通过;另有独立的核心服务生命周期测试通过。新加密助手在实际签名 App 中验证所属路径和签名团队。安装包经挂载检查,开发专用助手没有进入分发包。
 最终实际签名 App 的完整 Runner 导入、加密保存、服务崩溃恢复、窗口关闭保持连接、退出清理和再次打开自动连接均已通过;另有独立的核心服务生命周期测试通过。新加密助手在实际签名 App 中验证所属路径和签名团队。安装包经挂载检查,开发专用助手没有进入分发包。
 
 
-v0.4.0 同时发布 Web 与 macOS Apple Silicon DMG,见 [发布说明](releases/v0.4.0.md)。正式 App 首次启动按上文同步规则升级较旧的本机 Web;已有更新版本保留。独立预览应指定独立 `HERMES_YAOYAO_HOME` 和 `HERMES_YAOYAO_DESKTOP_PORT`。
+v0.4.1 同时发布 Web 与 macOS Apple Silicon DMG,见 [发布说明](releases/v0.4.1.md)。正式 App 首次启动按上文同步规则升级较旧的本机 Web;已有更新版本保留。独立预览应指定独立 `HERMES_YAOYAO_HOME` 和 `HERMES_YAOYAO_DESKTOP_PORT`。

+ 16 - 0
docs/releases/v0.4.1.md

@@ -0,0 +1,16 @@
+# v0.4.1
+
+本次同时更新 Web 与 macOS Apple Silicon(arm64)桌面版。
+
+- 修复 Docker 镜像构建和执行节点接入,支持由 Compose 预先创建、数量固定的共享桌面,补充部署配置与生成工具。
+- 更新本地虚拟机图标,将聊天内电脑选择改为标签切换,保留键盘导航与控制权约束。
+- 精简聊天顶部操作,支持从搜索列表删除已归档 Bot 和群聊。
+- 修复聊天文件的来源归属,文件展示聚焦用户附件与实际交付产物,排除执行过程文件。
+
+## 安装与升级
+
+GitHub 发布附件提供 `Yaoyao-0.4.1-arm64.dmg` 和 `SHA256SUMS.txt`。桌面包使用 Apple Development 开发签名,未做 Apple 公证;适用于 macOS Apple Silicon。
+
+App 首次启动会按既有规则同步较旧的本机 Web,保留较新的服务及原有配置。Hermes 基础运行时需独立配置;本地虚拟机另需 Docker 或 Podman。Docker Compose 固定共享桌面配置见 [Docker 部署说明](../docker-install.md)。
+
+Web 可通过既有系统升级入口更新;源码部署切换到 `v0.4.1` 后重新构建并重启,Docker 部署重新构建镜像。升级前备份完整 Web 数据目录。详情见 [macOS App](../macos-app.md) 和 [本地虚拟机](../local-vm.md)。

+ 2 - 2
docs/runner.md

@@ -2,7 +2,7 @@
 
 
 Runner 在运行 Hermes 的电脑上主动连接夭夭服务。用于 Web 位于 Docker、另一台电脑或远程服务器时,将 Bot 会话和本轮组队工具交给 Hermes 所在电脑执行。Runner 源码、构建入口和管理页面均位于 hermes-yaoyao。
 Runner 在运行 Hermes 的电脑上主动连接夭夭服务。用于 Web 位于 Docker、另一台电脑或远程服务器时,将 Bot 会话和本轮组队工具交给 Hermes 所在电脑执行。Runner 源码、构建入口和管理页面均位于 hermes-yaoyao。
 
 
-普通执行方式继续使用原有 Hermes。配置电脑 Worker 后,Agent 可选择隔离电脑执行,模型工具不会退回宿主。具体链路与验证边界见 `docs/computer-worker.md`;公网代理已接入;屏幕接管与共享环境仍待完成。
+普通执行方式继续使用原有 Hermes。配置电脑 Worker 后,Agent 可选择隔离电脑执行,模型工具不会退回宿主。公网代理、屏幕接管和共享环境均已接入,使用流程见 `docs/local-vm.md`。Docker 部署与程序包下载见 `docs/docker-install.md`。
 
 
 ## 启用
 ## 启用
 
 
@@ -12,7 +12,7 @@ Runner 在运行 Hermes 的电脑上主动连接夭夭服务。用于 Web 位于
 4. 将配置放到执行电脑,执行 `chmod 600 /完整路径/runner.json`。
 4. 将配置放到执行电脑,执行 `chmod 600 /完整路径/runner.json`。
 5. 在项目目录执行 `npm run build`,然后执行 `npm run runner -- --config /完整路径/runner.json`。
 5. 在项目目录执行 `npm run build`,然后执行 `npm run runner -- --config /完整路径/runner.json`。
 
 
-也可执行 `npm run runner:build`,将 `.runner-build/runner.mjs` 复制到执行电脑,以 Node.js 24 或更高版本运行:
+也可执行 `npm run runner:build`,将整个 `.runner-build/` 目录复制到执行电脑,以 Node.js 24 或更高版本运行。不要只复制单个 `runner.mjs`,虚拟桌面还需要同目录的 Worker 和桌面资源:
 
 
 ```sh
 ```sh
 node runner.mjs --config /完整路径/runner.json
 node runner.mjs --config /完整路径/runner.json

BIN
docs/screenshots/compose-desktops/agent-desktop.png


BIN
docs/screenshots/docker-vm/agent-desktop.png


+ 17 - 0
docs/verification/2026-09-09-message-files/README.md

@@ -0,0 +1,17 @@
+# 聊天文件来源验收
+
+2026-09-09。Web、桌面壳及共享服务端只从聊天正文与明确发送的附件建立文件关联。停止扫描工具事件、工具参数、结果、预览和思考。列表、统计、消息附件查询及历史/实时展示共用规则。历史自动归档关联在读取时按正文核对,原始记录及文件内容保留。用户上传和明确发布到消息的附件继续可用。
+
+## 验证
+
+- `npm run typecheck`、`npm run build` 通过。
+- 文件提取/展示、工作区接口、消息缓存等 8 个测试文件共 85 项通过。
+- 另执行 messageFiles、workspace、workspaceRemoteAgents、workspacePairedNodes 共 71 项运行时测试通过(其中 messageFiles 的 2 项与上述重叠)。
+- Playwright:`npx playwright test -c playwright.workspace.config.ts -g 'only chat messages introduce files'`,1 项通过。
+- 隔离 fixture 实测:过程区只有文本、没有图片及文件卡;文件库只返回报告;正文报告可预览,刷新后仍然正确。
+- 旧关联回归证明:工具文件仍在磁盘,工具 JSON 未变;正文后来引用同一文件后可重新显示;跨用户隔离保持有效。
+- 日志:`/tmp/yaoyao-message-files-web-{typecheck,build,tests,runtime-tests,ui}.log`。
+
+本次没有部署或发布;界面证明使用隔离测试服务,不代表线上服务已更新。
+
+![Web 展开过程与聊天文件](web.png)

BIN
docs/verification/2026-09-09-message-files/web.png


+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
 {
   "name": "hermes-yaoyao",
   "name": "hermes-yaoyao",
-  "version": "0.4.0",
+  "version": "0.4.1",
   "lockfileVersion": 3,
   "lockfileVersion": 3,
   "requires": true,
   "requires": true,
   "packages": {
   "packages": {
     "": {
     "": {
       "name": "hermes-yaoyao",
       "name": "hermes-yaoyao",
-      "version": "0.4.0",
+      "version": "0.4.1",
       "license": "BSL-1.1",
       "license": "BSL-1.1",
       "dependencies": {
       "dependencies": {
         "@koa/bodyparser": "^5.0.0",
         "@koa/bodyparser": "^5.0.0",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "hermes-yaoyao",
   "name": "hermes-yaoyao",
-  "version": "0.4.0",
+  "version": "0.4.1",
   "private": true,
   "private": true,
   "license": "BSL-1.1",
   "license": "BSL-1.1",
   "description": "夭夭 Web:直连 Hermes 9119 的聊天、团队、文件库与产物工作台",
   "description": "夭夭 Web:直连 Hermes 9119 的聊天、团队、文件库与产物工作台",

+ 3 - 3
release.json

@@ -1,6 +1,6 @@
 {
 {
   "schemaVersion": 1,
   "schemaVersion": 1,
-  "releaseVersion": "0.4.0",
-  "webVersion": "0.4.0",
-  "gitTag": "v0.4.0"
+  "releaseVersion": "0.4.1",
+  "webVersion": "0.4.1",
+  "gitTag": "v0.4.1"
 }
 }

+ 22 - 0
scripts/generate-desktop-compose.mjs

@@ -0,0 +1,22 @@
+import {readFileSync,writeFileSync} from 'node:fs'
+import {resolve} from 'node:path'
+const root=resolve(import.meta.dirname,'..')
+const entries=JSON.parse(readFileSync(resolve(root,'deploy/compose-desktops.json'),'utf8'))
+if(!Array.isArray(entries)||entries.length<1||entries.length>32)throw new Error('Compose 桌面数量须为 1–32')
+for(const d of entries)if(!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(d.id)||!/^desktop-[a-z0-9-]+$/.test(d.service)||typeof d.name!=='string'||!d.name.trim())throw new Error('Compose 桌面定义无效')
+if(new Set(entries.map(d=>d.id)).size!==entries.length||new Set(entries.map(d=>d.service)).size!==entries.length)throw new Error('Compose 桌面定义重复')
+const q=JSON.stringify
+const targets=entries.map(d=>({id:d.id,name:d.name,socketPath:`/run/yaoyao-desktops/${d.service}/desktop.sock`}))
+const base=readFileSync(resolve(root,'compose.yaml'),'utf8')
+  .replace('      HERMES_YAOYAO_LOCAL_VM_HOST: "runner"','      HERMES_YAOYAO_LOCAL_VM_HOST: "runner"\n      HERMES_YAOYAO_COMPOSE_DESKTOPS: '+q(JSON.stringify(targets)))
+  .replace('      - yaoyao-data:/var/lib/hermes-yaoyao','      - yaoyao-data:/var/lib/hermes-yaoyao\n'+entries.map(d=>`      - ${d.service}-ipc:/run/yaoyao-desktops/${d.service}:ro`).join('\n'))
+const volumesAt=base.indexOf('\nvolumes:')
+if(volumesAt<0||!base.includes('HERMES_YAOYAO_COMPOSE_DESKTOPS'))throw new Error('compose.yaml 模板结构已变化')
+let yaml='# Generated from compose.yaml and deploy/compose-desktops.json.\n'+base.slice(0,volumesAt)+'\n'
+for(const d of entries)yaml+=`  ${d.service}:\n    image: "\${YAOYAO_DESKTOP_IMAGE:-hermes-yaoyao-desktop:0.4.0}"\n    build:\n      context: ./deploy/computer\n    hostname: ${d.service}\n    extra_hosts:\n      - "${d.service}:127.0.0.1"\n    init: true\n    restart: unless-stopped\n    network_mode: none\n    shm_size: 512m\n    mem_limit: 4g\n    cpus: 2\n    pids_limit: 512\n    security_opt:\n      - no-new-privileges:true\n    cap_drop:\n      - ALL\n    cap_add:\n      - SETUID\n      - SETGID\n      - CHOWN\n      - KILL\n    environment:\n      YAOYAO_COMPOSE_DESKTOP_ID: ${q(d.id)}\n    volumes:\n      - ${d.service}-workspace:/home/cua/workspace\n      - ${d.service}-ipc:/run/yaoyao-private/bridge\n`
+yaml+=base.slice(volumesAt)+'\n'
+for(const d of entries)yaml+=`  ${d.service}-workspace:\n  ${d.service}-ipc:\n`
+const output=resolve(root,'compose.desktops.yaml')
+if(process.argv.includes('--check')){if(readFileSync(output,'utf8')!==yaml)throw new Error('compose.desktops.yaml 与桌面定义不同步,请运行 node scripts/generate-desktop-compose.mjs')}
+else writeFileSync(output,yaml)
+console.log(`Compose 共享桌面:${entries.length} 台`)

+ 15 - 3
src/client/components/app/FloatingResourceSearch.vue

@@ -1,5 +1,5 @@
 <script setup lang="ts">
 <script setup lang="ts">
-import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
+import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
 import AppIcon from '@/components/common/AppIcon.vue'
 import AppIcon from '@/components/common/AppIcon.vue'
 import TeamAvatar from '@/components/common/TeamAvatar.vue'
 import TeamAvatar from '@/components/common/TeamAvatar.vue'
 import AgentAvatar from '@/components/common/AgentAvatar.vue'
 import AgentAvatar from '@/components/common/AgentAvatar.vue'
@@ -93,6 +93,10 @@ function containFocus(event: KeyboardEvent) {
   if (event.shiftKey && document.activeElement === elements[0]) { event.preventDefault(); elements.at(-1)?.focus() }
   if (event.shiftKey && document.activeElement === elements[0]) { event.preventDefault(); elements.at(-1)?.focus() }
   else if (!event.shiftKey && document.activeElement === elements.at(-1)) { event.preventDefault(); elements[0]?.focus() }
   else if (!event.shiftKey && document.activeElement === elements.at(-1)) { event.preventDefault(); elements[0]?.focus() }
 }
 }
+watch(results, async () => {
+  await nextTick()
+  if (open.value && document.activeElement === document.body) input.value?.focus()
+})
 onMounted(() => { document.addEventListener(SIDEBAR_SEARCH_EVENT, show); document.addEventListener(SIDEBAR_SEARCH_CLOSE_EVENT, close) })
 onMounted(() => { document.addEventListener(SIDEBAR_SEARCH_EVENT, show); document.addEventListener(SIDEBAR_SEARCH_CLOSE_EVENT, close) })
 onBeforeUnmount(() => { document.removeEventListener(SIDEBAR_SEARCH_EVENT, show); document.removeEventListener(SIDEBAR_SEARCH_CLOSE_EVENT, close) })
 onBeforeUnmount(() => { document.removeEventListener(SIDEBAR_SEARCH_EVENT, show); document.removeEventListener(SIDEBAR_SEARCH_CLOSE_EVENT, close) })
 </script>
 </script>
@@ -124,10 +128,11 @@ onBeforeUnmount(() => { document.removeEventListener(SIDEBAR_SEARCH_EVENT, show)
           </nav>
           </nav>
           <section :id="`${section}-search-results`" class="floating-resource-search__result-pane" :role="tabbed ? 'tabpanel' : undefined" :aria-label="tabbed ? activeParent?.title : undefined">
           <section :id="`${section}-search-results`" class="floating-resource-search__result-pane" :role="tabbed ? 'tabpanel' : undefined" :aria-label="tabbed ? activeParent?.title : undefined">
             <div v-if="activeParent && !tabbed" class="floating-resource-search__context"><strong>{{ activeParent.title }}</strong><span>{{ activeParent.subtitle }}</span></div>
             <div v-if="activeParent && !tabbed" class="floating-resource-search__context"><strong>{{ activeParent.title }}</strong><span>{{ activeParent.subtitle }}</span></div>
-            <div class="floating-resource-search__results" role="listbox" aria-label="搜索结果">
+            <div class="floating-resource-search__results" :role="$slots['item-actions'] ? 'list' : 'listbox'" aria-label="搜索结果">
               <template v-for="row in resultRows" :key="row.item.id">
               <template v-for="row in resultRows" :key="row.item.id">
                 <div v-if="row.showSection" class="floating-resource-search__section">{{ row.item.section }}</div>
                 <div v-if="row.showSection" class="floating-resource-search__section">{{ row.item.section }}</div>
-                <button type="button" role="option" :aria-haspopup="row.hasChildren ? 'listbox' : undefined" @click="choose(row.item)">
+                <div class="floating-resource-search__row" :role="$slots['item-actions'] ? 'listitem' : 'presentation'">
+                <button class="floating-resource-search__select" type="button" :role="$slots['item-actions'] ? undefined : 'option'" :aria-haspopup="row.hasChildren ? 'listbox' : undefined" @click="choose(row.item)">
                   <span v-if="row.item.avatar !== undefined || row.item.avatarMembers?.length" class="floating-resource-search__icon floating-resource-search__icon--avatar">
                   <span v-if="row.item.avatar !== undefined || row.item.avatarMembers?.length" class="floating-resource-search__icon floating-resource-search__icon--avatar">
                     <AgentAvatar v-if="row.item.avatarKind === 'agent'" :name="row.item.title" :avatar="row.item.avatar" :state="row.item.avatarState" :size="30" />
                     <AgentAvatar v-if="row.item.avatarKind === 'agent'" :name="row.item.title" :avatar="row.item.avatar" :state="row.item.avatarState" :size="30" />
                     <TeamAvatar v-else :name="row.item.title" :avatar="row.item.avatar || ''" :members="row.item.avatarMembers || []" :fallback-key="row.item.avatarFallbackKey || row.item.id" :size="30" />
                     <TeamAvatar v-else :name="row.item.title" :avatar="row.item.avatar || ''" :members="row.item.avatarMembers || []" :fallback-key="row.item.avatarFallbackKey || row.item.id" :size="30" />
@@ -136,11 +141,14 @@ onBeforeUnmount(() => { document.removeEventListener(SIDEBAR_SEARCH_EVENT, show)
                   <span class="floating-resource-search__copy"><strong>{{ row.item.title }}</strong><small v-if="row.item.subtitle">{{ row.item.subtitle }}</small></span>
                   <span class="floating-resource-search__copy"><strong>{{ row.item.title }}</strong><small v-if="row.item.subtitle">{{ row.item.subtitle }}</small></span>
                   <small v-if="row.item.meta">{{ row.item.meta }}</small>
                   <small v-if="row.item.meta">{{ row.item.meta }}</small>
                 </button>
                 </button>
+                <slot name="item-actions" :item="row.item" />
+                </div>
               </template>
               </template>
               <p v-if="!results.length">{{ activeParent?.emptyText || (activeParent ? `暂无${activeParent.title}内容` : '没有匹配结果') }}</p>
               <p v-if="!results.length">{{ activeParent?.emptyText || (activeParent ? `暂无${activeParent.title}内容` : '没有匹配结果') }}</p>
             </div>
             </div>
           </section>
           </section>
         </div>
         </div>
+        <slot name="footer" />
       </section>
       </section>
     </div>
     </div>
   </Teleport>
   </Teleport>
@@ -155,4 +163,8 @@ onBeforeUnmount(() => { document.removeEventListener(SIDEBAR_SEARCH_EVENT, show)
 .floating-resource-search__tabs button{display:flex;align-items:center;justify-content:center;gap:9px;min-height:34px;padding:6px 18px;border:0;border-radius:8px;background:transparent;color:var(--text-secondary);font:13px var(--font-ui);cursor:pointer}
 .floating-resource-search__tabs button{display:flex;align-items:center;justify-content:center;gap:9px;min-height:34px;padding:6px 18px;border:0;border-radius:8px;background:transparent;color:var(--text-secondary);font:13px var(--font-ui);cursor:pointer}
 .floating-resource-search__tabs button[aria-selected="true"]{background:var(--surface-hover);color:var(--text-primary);font-weight:650}
 .floating-resource-search__tabs button[aria-selected="true"]{background:var(--surface-hover);color:var(--text-primary);font-weight:650}
 .floating-resource-search__tabs small{color:var(--text-muted);font-size:11px}
 .floating-resource-search__tabs small{color:var(--text-muted);font-size:11px}
+.floating-resource-search__row{display:flex;align-items:center;gap:8px}
+.floating-resource-search__row .floating-resource-search__select{flex:1;min-width:0}
+.floating-resource-search__select>small{flex-shrink:0;color:var(--text-muted);font-size:10px}
+.floating-resource-search__select:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
 </style>
 </style>

+ 10 - 6
src/client/components/app/LocalVmSettingsPanel.vue

@@ -3,9 +3,11 @@ import {ref,onMounted,onBeforeUnmount} from 'vue'
 import {apiRequest} from '@/api/client'
 import {apiRequest} from '@/api/client'
 import {createUuid} from '@/utils/id'
 import {createUuid} from '@/utils/id'
 import AppIcon from '@/components/common/AppIcon.vue'
 import AppIcon from '@/components/common/AppIcon.vue'
+import RunnerSettingsPanel from './RunnerSettingsPanel.vue'
 import type {LocalVmStatus,LocalVmMode,LocalVmAction,LocalVmInstance} from '@shared/localVm'
 import type {LocalVmStatus,LocalVmMode,LocalVmAction,LocalVmInstance} from '@shared/localVm'
 import type {WorkspaceAgent} from '@shared/workspace'
 import type {WorkspaceAgent} from '@shared/workspace'
 const state=ref<LocalVmStatus>(),error=ref(''),loading=ref(false),acting=ref(false)
 const state=ref<LocalVmStatus>(),error=ref(''),loading=ref(false),acting=ref(false)
+const runnerSettingsOpen=ref(false)
 const instances=ref<Array<{agent:WorkspaceAgent;vm:LocalVmInstance}>>([])
 const instances=ref<Array<{agent:WorkspaceAgent;vm:LocalVmInstance}>>([])
 let closed=false,timer:ReturnType<typeof setTimeout>|undefined
 let closed=false,timer:ReturnType<typeof setTimeout>|undefined
 async function refresh(){
 async function refresh(){
@@ -35,22 +37,24 @@ onMounted(cycle);onBeforeUnmount(()=>{closed=true;clearTimeout(timer)})
 </script>
 </script>
 <template>
 <template>
  <section class="local-vm-settings" aria-label="本地虚拟机设置">
  <section class="local-vm-settings" aria-label="本地虚拟机设置">
-  <article><h3>本地虚拟机</h3><p>在这台电脑的隔离 Linux 桌面中运行 Agent,工作文件与浏览器资料持续保存。</p>
+  <article><h3>{{state?.fixedCapacity?'Compose 共享桌面':'本地虚拟机'}}</h3><p>{{state?.fixedCapacity?'桌面容器随 Web 的 Compose 文件部署,工作文件与浏览器资料保存在各桌面的数据卷中。':'在 Hermes 所在电脑的隔离 Linux 桌面中运行 Agent,工作文件与浏览器资料持续保存。'}}</p>
    <div class="row"><span class="status"><AppIcon :name="state?.image?'check':'monitor'"/>{{loading&&!state?'正在检查…':state?.image?'虚拟机环境已就绪':'尚未就绪'}}</span><button :disabled="loading||acting" @click="error='';refresh()"><AppIcon name="refresh"/>重新检查</button></div>
    <div class="row"><span class="status"><AppIcon :name="state?.image?'check':'monitor'"/>{{loading&&!state?'正在检查…':state?.image?'虚拟机环境已就绪':'尚未就绪'}}</span><button :disabled="loading||acting" @click="error='';refresh()"><AppIcon name="refresh"/>重新检查</button></div>
    <p v-if="state?.problem">{{state.problem}}</p><p v-if="error" role="alert">{{error}}</p>
    <p v-if="state?.problem">{{state.problem}}</p><p v-if="error" role="alert">{{error}}</p>
    <p v-if="state?.job" role="status">{{state.job.message}}</p>
    <p v-if="state?.job" role="status">{{state.job.message}}</p>
   </article>
   </article>
-  <article><h3>隔离方式</h3><p>按 Agent 创建独立桌面,或让可信的 Agent 共用一个桌面。</p>
-   <div class="segmented" role="group" aria-label="虚拟机隔离方式"><button :aria-pressed="state?.mode==='shared'" :disabled="!state?.configured||acting||state.busy" @click="policy('shared')">共享虚拟机</button><button :aria-pressed="state?.mode==='per-bot'" :disabled="!state?.configured||acting||state.busy" @click="policy('per-bot')">每个 Agent 独立</button></div>
-   <label class="row">最多同时运行的虚拟机<select aria-label="虚拟机数量上限" :value="state?.maxInstances??2" :disabled="!state?.configured||acting||state.busy" @change="policy(state!.mode,Number(($event.target as HTMLSelectElement).value))"><option v-for="n in [1,2,3,4]" :key="n" :value="n">{{n}}</option></select></label>
+  <article v-if="state?.executionHost==='runner'"><h3>Hermes 执行连接</h3><p>{{state.fixedCapacity?'执行连接负责 Hermes 模型与工具调用,桌面容器完全由这套 Compose 管理。':'虚拟桌面由运行 Hermes 的执行节点提供,Docker 版 Web 通过这条连接使用桌面。'}}{{state.runnerName?`当前节点:${state.runnerName}。`:''}}</p><button :aria-expanded="runnerSettingsOpen" @click="runnerSettingsOpen=!runnerSettingsOpen">{{runnerSettingsOpen?'收起执行节点设置':'打开执行节点设置'}}</button><RunnerSettingsPanel v-if="runnerSettingsOpen" computer-setup /></article>
+  <article v-if="state?.fixedCapacity"><h3>Compose 共享桌面</h3><p>已配置 {{state.maxInstances}} 台桌面,数量由 Compose 固定。请在 Agent 聊天的电脑面板选择已有桌面。</p><div v-for="desktop in state.desktops" :key="desktop.id" class="instance"><strong>{{desktop.name}}</strong><span>{{desktop.ready?'已就绪':desktop.online?'正在启动':'未连接'}}</span></div></article>
+  <article v-else-if="state"><h3>隔离方式</h3><p>按 Agent 创建独立桌面,或让可信的 Agent 共用一个桌面。</p>
+   <div class="segmented" role="group" aria-label="虚拟机隔离方式"><button :aria-pressed="state?.mode==='shared'" :disabled="!state?.configured||!!state?.setupRequired||acting||state.busy" @click="policy('shared')">共享虚拟机</button><button :aria-pressed="state?.mode==='per-bot'" :disabled="!state?.configured||!!state?.setupRequired||acting||state.busy" @click="policy('per-bot')">每个 Agent 独立</button></div>
+   <label class="row">最多同时运行的虚拟机<select aria-label="虚拟机数量上限" :value="state?.maxInstances??2" :disabled="!state?.configured||!!state?.setupRequired||acting||state.busy" @change="policy(state!.mode,Number(($event.target as HTMLSelectElement).value))"><option v-for="n in [1,2,3,4]" :key="n" :value="n">{{n}}</option></select></label>
   </article>
   </article>
-  <article><h3>准备运行环境</h3><ol>
+  <article v-if="state&&!state.fixedCapacity&&!state.setupRequired"><h3>准备运行环境</h3><p v-if="state?.executionHost==='runner'">以下检查和镜像准备均在执行节点所在电脑完成。</p><ol>
    <li><span class="step">{{state?.runtime?'✓':'1'}}</span><div><strong>安装 Docker 或 Podman</strong><p>{{state?.runtime?`已检测到 ${state.runtime}`:'请先安装 Docker Desktop 或 Podman。'}}</p></div></li>
    <li><span class="step">{{state?.runtime?'✓':'1'}}</span><div><strong>安装 Docker 或 Podman</strong><p>{{state?.runtime?`已检测到 ${state.runtime}`:'请先安装 Docker Desktop 或 Podman。'}}</p></div></li>
    <li><span class="step">{{state?.daemonUp?'✓':'2'}}</span><div><strong>启动容器运行环境</strong><p>{{state?.daemonUp?'运行环境已启动':'打开 Docker / Podman,等待它完成启动后重新检查。'}}</p></div></li>
    <li><span class="step">{{state?.daemonUp?'✓':'2'}}</span><div><strong>启动容器运行环境</strong><p>{{state?.daemonUp?'运行环境已启动':'打开 Docker / Podman,等待它完成启动后重新检查。'}}</p></div></li>
    <li><span class="step">{{state?.image?'✓':'3'}}</span><div><strong>准备本地虚拟机</strong><p>下载并检查托管桌面环境。后续创建虚拟机时会自动使用。</p><button class="primary" :disabled="acting||state?.busy||!state?.daemonUp" @click="prepare">{{state?.busy?'正在准备…':state?.image?'重新检查虚拟机镜像':'准备本地虚拟机'}}</button></div></li>
    <li><span class="step">{{state?.image?'✓':'3'}}</span><div><strong>准备本地虚拟机</strong><p>下载并检查托管桌面环境。后续创建虚拟机时会自动使用。</p><button class="primary" :disabled="acting||state?.busy||!state?.daemonUp" @click="prepare">{{state?.busy?'正在准备…':state?.image?'重新检查虚拟机镜像':'准备本地虚拟机'}}</button></div></li>
    <li><span class="step">4</span><div><strong>从 Agent 聊天中创建桌面</strong><p>打开聊天右上角的“电脑”,选择“本地虚拟机”,然后创建该 Agent 的虚拟机。</p></div></li>
    <li><span class="step">4</span><div><strong>从 Agent 聊天中创建桌面</strong><p>打开聊天右上角的“电脑”,选择“本地虚拟机”,然后创建该 Agent 的虚拟机。</p></div></li>
   </ol></article>
   </ol></article>
-  <article><h3>{{state?.mode==='shared'?'共享虚拟机':'Agent 虚拟机'}}</h3><p v-if="!instances.length">还没有 Agent 使用本地虚拟机。</p>
+  <article v-if="state&&!state.fixedCapacity"><h3>{{state?.mode==='shared'?'共享虚拟机':'Agent 虚拟机'}}</h3><p v-if="!instances.length">还没有 Agent 使用本地虚拟机。</p>
    <div v-for="row in instances" :key="row.agent.id" class="instance"><div><strong>{{row.agent.computerEnvironmentName??row.agent.name}}</strong><p>{{row.vm.inUse?'正在使用':({running:'运行中',stopped:'已停止',missing:'尚未创建'})[row.vm.container]}}</p></div><div class="row">
    <div v-for="row in instances" :key="row.agent.id" class="instance"><div><strong>{{row.agent.computerEnvironmentName??row.agent.name}}</strong><p>{{row.vm.inUse?'正在使用':({running:'运行中',stopped:'已停止',missing:'尚未创建'})[row.vm.container]}}</p></div><div class="row">
     <button v-if="row.vm.container==='running'" :disabled="acting||row.vm.inUse" @click="manage(row.agent,'stop')">停止</button>
     <button v-if="row.vm.container==='running'" :disabled="acting||row.vm.inUse" @click="manage(row.agent,'stop')">停止</button>
     <button v-else :disabled="acting||!state?.image" @click="manage(row.agent,row.vm.container==='missing'?'create':'start')">{{row.vm.container==='missing'?'创建':'启动'}}</button>
     <button v-else :disabled="acting||!state?.image" @click="manage(row.agent,row.vm.container==='missing'?'create':'start')">{{row.vm.container==='missing'?'创建':'启动'}}</button>

+ 20 - 15
src/client/components/app/RunnerSettingsPanel.vue

@@ -5,17 +5,19 @@ import { UNCONFIGURED_COMPUTER_IMAGE } from '@shared/runner'
 import type { RunnerConfiguration, RunnerRecord } from '@shared/runner'
 import type { RunnerConfiguration, RunnerRecord } from '@shared/runner'
 
 
 type Runner = Omit<RunnerRecord, 'tokenHash' | 'sourceOwner'> & {online: boolean}
 type Runner = Omit<RunnerRecord, 'tokenHash' | 'sourceOwner'> & {online: boolean}
+const props=defineProps<{computerSetup?:boolean}>()
+const bundleAvailable=ref(false),fixedDesktops=ref(false)
 const runners = ref<Runner[]>([]), sources = ref<Array<{id:string;name:string}>>([])
 const runners = ref<Runner[]>([]), sources = ref<Array<{id:string;name:string}>>([])
 const busy = ref(false), error = ref(''), notice = ref('')
 const busy = ref(false), error = ref(''), notice = ref('')
 const name = ref(''), source = ref('local'), profiles = ref('default')
 const name = ref(''), source = ref('local'), profiles = ref('default')
 const serverURL = ref(window.location.origin), hermesURL = ref('http://127.0.0.1:9119')
 const serverURL = ref(window.location.origin), hermesURL = ref('http://127.0.0.1:9119')
 const computerNetwork=ref<'none'|'public-proxy'>('public-proxy')
 const computerNetwork=ref<'none'|'public-proxy'>('public-proxy')
-const computers=ref(false),computerRuntime=ref<'docker'|'podman'>('docker'),computerImage=ref(''),computerPython=ref(''),hermesSource=ref(''),hermesHome=ref('')
+const computers=ref(!!props.computerSetup),computerRuntime=ref<'docker'|'podman'>('docker'),computerImage=ref(''),computerPython=ref(''),hermesSource=ref(''),hermesHome=ref('')
 const artifactRoots = ref(''), insecure = ref(false), configuration = ref<RunnerConfiguration>()
 const artifactRoots = ref(''), insecure = ref(false), configuration = ref<RunnerConfiguration>()
 
 
 async function refresh() {
 async function refresh() {
-  const data = await apiRequest<{runners:Runner[];sources:Array<{id:string;name:string}>}>('/api/app/admin/runners')
-  runners.value = data.runners; sources.value = data.sources
+  const data = await apiRequest<{runners:Runner[];sources:Array<{id:string;name:string}>;bundleAvailable?:boolean;fixedDesktops?:boolean}>('/api/app/admin/runners')
+  runners.value = data.runners; sources.value = data.sources;bundleAvailable.value=!!data.bundleAvailable;fixedDesktops.value=!!data.fixedDesktops
 }
 }
 async function action(work:()=>Promise<void>) {
 async function action(work:()=>Promise<void>) {
   if(busy.value) return
   if(busy.value) return
@@ -30,9 +32,9 @@ async function register() {
     if(web.protocol==='http:'&&!['localhost','127.0.0.1','[::1]'].includes(web.hostname)&&!insecure.value)throw new Error('远程节点请使用 HTTPS,或勾选可信局域网 HTTP')
     if(web.protocol==='http:'&&!['localhost','127.0.0.1','[::1]'].includes(web.hostname)&&!insecure.value)throw new Error('远程节点请使用 HTTPS,或勾选可信局域网 HTTP')
     if(!['127.0.0.1','[::1]'].includes(local.hostname)||!['http:','https:'].includes(local.protocol)||local.username||local.password)throw new Error('Hermes 地址必须指向 Runner 所在电脑的回环地址')
     if(!['127.0.0.1','[::1]'].includes(local.hostname)||!['http:','https:'].includes(local.protocol)||local.username||local.password)throw new Error('Hermes 地址必须指向 Runner 所在电脑的回环地址')
     const allowedProfiles = [...new Set(profiles.value.split(/[\s,,]+/).filter(Boolean))]
     const allowedProfiles = [...new Set(profiles.value.split(/[\s,,]+/).filter(Boolean))]
-    if(computers.value&&((!!computerImage.value&&!/^sha256:[a-f0-9]{64}$/.test(computerImage.value))||[computerPython.value,hermesSource.value,hermesHome.value].some(path=>!path.startsWith('/'))))throw new Error('请填写镜像完整 ID 和执行电脑上的绝对路径')
+    if(computers.value&&((!!computerImage.value&&!/^sha256:[a-f0-9]{64}$/.test(computerImage.value))||[computerPython.value,hermesSource.value,hermesHome.value].some(path=>path&&!path.startsWith('/'))))throw new Error('自定义路径必须为执行电脑上的绝对路径;默认安装可留空。镜像 ID 可留空或填写完整 sha256 ID。')
     const result = await apiRequest<{runner:Runner;token:string}>('/api/app/admin/runners', {method:'POST',body:{name:name.value.trim(),sourceNodeId:source.value,allowedProfiles}})
     const result = await apiRequest<{runner:Runner;token:string}>('/api/app/admin/runners', {method:'POST',body:{name:name.value.trim(),sourceNodeId:source.value,allowedProfiles}})
-    configuration.value = {protocol:1,serverURL:web.origin,runnerId:result.runner.id,token:result.token,hermesURL:local.toString(),allowedProfiles,artifactRoots:artifactRoots.value.split('\n').map(p=>p.trim()).filter(Boolean),...(insecure.value?{allowInsecureLan:true}:{}),...(computers.value?{computers:{network:computerNetwork.value,runtime:computerRuntime.value,imageId:computerImage.value||UNCONFIGURED_COMPUTER_IMAGE,python:computerPython.value,hermesSource:hermesSource.value,hermesHome:hermesHome.value}}:{})}
+    configuration.value = {protocol:1,serverURL:web.origin,runnerId:result.runner.id,token:result.token,hermesURL:local.toString(),allowedProfiles,artifactRoots:artifactRoots.value.split('\n').map(p=>p.trim()).filter(Boolean),...(insecure.value?{allowInsecureLan:true}:{}),...(computers.value?{computers:{...(fixedDesktops.value?{managedBy:'compose' as const}:{}),network:fixedDesktops.value?'none':computerNetwork.value,runtime:computerRuntime.value,imageId:computerImage.value||UNCONFIGURED_COMPUTER_IMAGE,python:computerPython.value,hermesSource:hermesSource.value,hermesHome:hermesHome.value}}:{})}
     notice.value = '节点已注册,请下载配置并在 Hermes 所在电脑启动 Runner。'
     notice.value = '节点已注册,请下载配置并在 Hermes 所在电脑启动 Runner。'
     await refresh()
     await refresh()
   })
   })
@@ -56,6 +58,7 @@ onMounted(()=>{void action(refresh)})
 <template>
 <template>
   <section class="runner-panel" aria-label="执行节点设置">
   <section class="runner-panel" aria-label="执行节点设置">
     <p>在运行 Hermes 的电脑上启动 Runner,它会主动连接夭夭,接收 Bot 任务并提供本轮团队工具。注册后,该来源的 Bot 任务会交给 Runner;节点离线时无法启动新任务,恢复连接后可重试。</p>
     <p>在运行 Hermes 的电脑上启动 Runner,它会主动连接夭夭,接收 Bot 任务并提供本轮团队工具。注册后,该来源的 Bot 任务会交给 Runner;节点离线时无法启动新任务,恢复连接后可重试。</p>
+    <p v-if="bundleAvailable"><a href="/api/app/admin/runners/bundle" download>下载配套执行节点程序</a>(包含桌面资源,需要 Node.js 24 或更高版本)。</p>
     <div class="runner-toolbar"><strong>已注册节点</strong><button type="button" :disabled="busy" @click="action(refresh)">刷新状态</button></div>
     <div class="runner-toolbar"><strong>已注册节点</strong><button type="button" :disabled="busy" @click="action(refresh)">刷新状态</button></div>
     <ul v-if="runners.length" class="runner-list">
     <ul v-if="runners.length" class="runner-list">
       <li v-for="runner in runners" :key="runner.id">
       <li v-for="runner in runners" :key="runner.id">
@@ -74,14 +77,15 @@ onMounted(()=>{void action(refresh)})
       <label class="runner-check"><input v-model="insecure" type="checkbox" :disabled="busy">使用可信局域网 HTTP</label>
       <label class="runner-check"><input v-model="insecure" type="checkbox" :disabled="busy">使用可信局域网 HTTP</label>
       <label class="runner-check"><input v-model="computers" type="checkbox" :disabled="busy">启用隔离电脑 Worker</label>
       <label class="runner-check"><input v-model="computers" type="checkbox" :disabled="busy">启用隔离电脑 Worker</label>
       <fieldset v-if="computers" class="runner-computer">
       <fieldset v-if="computers" class="runner-computer">
-        <legend>执行电脑配置</legend>
-        <label>容器运行时<select v-model="computerRuntime"><option value="docker">Docker</option><option value="podman">Podman</option></select></label>
-        <label>联网范围<select v-model="computerNetwork"><option value="public-proxy">公网网页(HTTP / HTTPS)</option><option value="none">不联网</option></select></label>
-        <small>公网模式通过受控代理访问,不开放宿主和内网地址。</small>
-        <label>兼容镜像 ID<input v-model.trim="computerImage" placeholder="可在本地虚拟机设置中准备"></label>
-        <label>Hermes Python 路径<input v-model.trim="computerPython" required placeholder="/完整路径/hermes-agent/venv/bin/python"></label>
-        <label>Hermes 源码目录<input v-model.trim="hermesSource" required placeholder="/完整路径/hermes-agent"></label>
-        <label>Hermes 配置目录<input v-model.trim="hermesHome" required placeholder="/完整路径/.hermes"></label>
+        <legend>执行电脑配置</legend><p v-if="fixedDesktops">桌面已由 Compose 创建。Runner 只转发执行和控制,不安装桌面镜像、不创建容器;联网方式由 Compose 指定。</p>
+        <label v-if="!fixedDesktops">容器运行时<select v-model="computerRuntime"><option value="docker">Docker</option><option value="podman">Podman</option></select></label>
+        <label v-if="!fixedDesktops">联网范围<select v-model="computerNetwork"><option value="public-proxy">公网网页(HTTP / HTTPS)</option><option value="none">不联网</option></select></label>
+        <small v-if="!fixedDesktops">公网模式通过受控代理访问,不开放宿主和内网地址。</small>
+        <label v-if="!fixedDesktops">兼容镜像 ID<input v-model.trim="computerImage" placeholder="可在本地虚拟机设置中准备"></label>
+        <label>Hermes Python 路径<input v-model.trim="computerPython" placeholder="留空使用默认安装"></label>
+        <label>Hermes 源码目录<input v-model.trim="hermesSource" placeholder="留空使用默认安装"></label>
+        <label>Hermes 配置目录<input v-model.trim="hermesHome" placeholder="留空使用默认安装"></label>
+        <small>留空时在执行电脑上查找 ~/.hermes/hermes-agent/venv/bin/python。自定义安装请填写绝对路径;镜像可在节点连接后于本页准备。</small>
         <small>这是外部执行节点的高级配置。本机虚拟机可直接在应用设置中准备,并从 Agent 聊天的电脑面板启用。</small>
         <small>这是外部执行节点的高级配置。本机虚拟机可直接在应用设置中准备,并从 Agent 聊天的电脑面板启用。</small>
       </fieldset>
       </fieldset>
       <button class="solid-button" :disabled="busy || !name.trim() || !profiles.trim()">注册节点</button>
       <button class="solid-button" :disabled="busy || !name.trim() || !profiles.trim()">注册节点</button>
@@ -89,8 +93,9 @@ onMounted(()=>{void action(refresh)})
     <div v-else class="runner-setup">
     <div v-else class="runner-setup">
       <button class="solid-button" type="button" @click="download">下载 Runner 配置</button>
       <button class="solid-button" type="button" @click="download">下载 Runner 配置</button>
       <p>配置包含本节点的连接凭据,仅本次可下载。将文件放在 Hermes 所在电脑,设置为仅自己可读:</p>
       <p>配置包含本节点的连接凭据,仅本次可下载。将文件放在 Hermes 所在电脑,设置为仅自己可读:</p>
-      <code>chmod 600 runner.json<br>npm run runner -- --config /完整路径/runner.json</code>
-      <small>在 hermes-yaoyao 项目中先运行 npm run build。配置丢失后可停用节点并重新注册。</small>
+      <code v-if="bundleAvailable">mkdir -p yaoyao-runner<br>tar -xzf yaoyao-runner.tar.gz -C yaoyao-runner<br>chmod 600 runner.json<br>node yaoyao-runner/runner.mjs --config /完整路径/runner.json</code>
+      <code v-else>chmod 600 runner.json<br>npm run runner -- --config /完整路径/runner.json</code>
+      <small>{{bundleAvailable?'在运行 Hermes 和 Docker/Podman 的电脑上执行,节点连接后返回本地虚拟机设置准备桌面。':'在 hermes-yaoyao 项目中先运行 npm run build。'}}配置丢失后可停用节点并重新注册。</small>
     </div>
     </div>
     <p v-if="error" class="runner-error" role="alert">{{ error }}</p>
     <p v-if="error" class="runner-error" role="alert">{{ error }}</p>
     <p v-if="notice" role="status">{{ notice }}</p>
     <p v-if="notice" role="status">{{ notice }}</p>

+ 2 - 2
src/client/components/app/SettingsCenterDialog.vue

@@ -32,7 +32,7 @@ type SettingsPage =
   | 'system-local-vm'
   | 'system-local-vm'
   | 'system-update'
   | 'system-update'
 
 
-type SettingsIcon = 'users' | 'model' | 'settings' | 'panel' | 'sun' | 'link' | 'bell' | 'audio' | 'refresh'
+type SettingsIcon = 'users' | 'model' | 'settings' | 'panel' | 'monitor' | 'sun' | 'link' | 'bell' | 'audio' | 'refresh'
 type ThemePreference = 'light' | 'dark' | 'system'
 type ThemePreference = 'light' | 'dark' | 'system'
 
 
 interface NavigationItem {
 interface NavigationItem {
@@ -106,7 +106,7 @@ const accountItems = computed<NavigationItem[]>(() => [
   { key: 'appearance', label: '外观', icon: 'sun' },
   { key: 'appearance', label: '外观', icon: 'sun' },
 ])
 ])
 const systemItems: NavigationItem[] = [
 const systemItems: NavigationItem[] = [
-  { key: 'system-local-vm', label: '本地虚拟机', icon: 'panel' },
+  { key: 'system-local-vm', label: '本地虚拟机', icon: 'monitor' },
   { key: 'system-overview', label: '系统概览', icon: 'panel' },
   { key: 'system-overview', label: '系统概览', icon: 'panel' },
   { key: 'system-users', label: '用户与权限', icon: 'users' },
   { key: 'system-users', label: '用户与权限', icon: 'users' },
   { key: 'system-connection', label: 'Hermes 连接', icon: 'link' },
   { key: 'system-connection', label: 'Hermes 连接', icon: 'link' },

+ 11 - 4
src/client/components/messages/MarkdownContent.vue

@@ -15,8 +15,9 @@ const props = withDefaults(defineProps<{
   plain?: boolean
   plain?: boolean
   mentionNames?: string[]
   mentionNames?: string[]
   fileCards?: boolean
   fileCards?: boolean
+  processContent?: boolean
   outlinePrefix?: string
   outlinePrefix?: string
-}>(), { streaming: false, legacyMedia: false, plain: false, fileCards: false, outlinePrefix: '' })
+}>(), { streaming: false, legacyMedia: false, plain: false, fileCards: false, processContent: false, outlinePrefix: '' })
 
 
 const emit = defineEmits<{ fileLink: [name: string, url: string]; rendered: [] }>()
 const emit = defineEmits<{ fileLink: [name: string, url: string]; rendered: [] }>()
 
 
@@ -88,13 +89,19 @@ const md = new MarkdownIt({
 // Dashboard 规范:保留原文引号,不做智能引号替换。
 // Dashboard 规范:保留原文引号,不做智能引号替换。
 md.disable('smartquotes')
 md.disable('smartquotes')
 
 
+const defaultImage = md.renderer.rules.image!
+md.renderer.rules.image = (tokens, index, options, env, self) => {
+  if (props.processContent) return escapeHtml(tokens[index].content || tokens[index].attrGet('src') || '图片')
+  return defaultImage(tokens, index, options, env, self)
+}
+
 const defaultLinkOpen = md.renderer.rules.link_open ?? ((tokens, index, options, _env, self) => self.renderToken(tokens, index, options))
 const defaultLinkOpen = md.renderer.rules.link_open ?? ((tokens, index, options, _env, self) => self.renderToken(tokens, index, options))
 md.renderer.rules.link_open = (tokens, index, options, env, self) => {
 md.renderer.rules.link_open = (tokens, index, options, env, self) => {
   const token = tokens[index]
   const token = tokens[index]
   // Some assistants wrap real Hermes workspace paths in a sandbox: URI.
   // Some assistants wrap real Hermes workspace paths in a sandbox: URI.
   // Resolve only this known file route before sanitizing the Markdown.
   // Resolve only this known file route before sanitizing the Markdown.
   const href = token.attrGet('href') || ''
   const href = token.attrGet('href') || ''
-  if (props.fileCards && /^sandbox:\/Users\/[^/]+\/\.hermes\/(?:profiles\/[^/]+\/)?workspace\/.+/i.test(href)) {
+  if (!props.processContent && props.fileCards && /^sandbox:\/Users\/[^/]+\/\.hermes\/(?:profiles\/[^/]+\/)?workspace\/.+/i.test(href)) {
     token.attrSet('href', href.slice('sandbox:'.length))
     token.attrSet('href', href.slice('sandbox:'.length))
   }
   }
   token.attrSet('target', '_blank')
   token.attrSet('target', '_blank')
@@ -176,7 +183,7 @@ function decorateCopyButtons() {
 }
 }
 
 
 function decorateFileLinks() {
 function decorateFileLinks() {
-  if (!props.fileCards || !root.value) return
+  if (props.processContent || !props.fileCards || !root.value) return
   root.value.querySelectorAll<HTMLAnchorElement>('a').forEach(link => {
   root.value.querySelectorAll<HTMLAnchorElement>('a').forEach(link => {
     if (link.dataset.fileCard) return
     if (link.dataset.fileCard) return
     let url: URL
     let url: URL
@@ -199,7 +206,7 @@ function decorateFileLinks() {
 }
 }
 
 
 function decorateMediaPreviews() {
 function decorateMediaPreviews() {
-  if (!props.fileCards || !root.value) return
+  if (props.processContent || !props.fileCards || !root.value) return
   root.value.querySelectorAll<HTMLImageElement>('img').forEach(image => {
   root.value.querySelectorAll<HTMLImageElement>('img').forEach(image => {
     if (image.dataset.mediaPreview) return
     if (image.dataset.mediaPreview) return
     let url: URL
     let url: URL

+ 8 - 7
src/client/components/messages/MessageTimeline.vue

@@ -284,25 +284,25 @@ defineExpose({ scrollToMessage, scrollToAnchor, scrollToBottom, isFollowingBotto
             <template v-if="message.timelineKind === 'delegation-complete'">
             <template v-if="message.timelineKind === 'delegation-complete'">
               <details class="delegation-event">
               <details class="delegation-event">
                 <summary><AppIcon name="groups" :size="14" /><span><strong>子任务已完成</strong><small>{{ delegationSummary(message.timelineMetadata) }}</small></span></summary>
                 <summary><AppIcon name="groups" :size="14" /><span><strong>子任务已完成</strong><small>{{ delegationSummary(message.timelineMetadata) }}</small></span></summary>
-                <MarkdownContent v-if="message.content" :content="message.content" />
+                <MarkdownContent process-content v-if="message.content" :content="message.content" />
               </details>
               </details>
             </template>
             </template>
             <template v-else-if="message.timelineKind === 'background-process'">
             <template v-else-if="message.timelineKind === 'background-process'">
               <details class="system-event background-process-event">
               <details class="system-event background-process-event">
                 <summary><AppIcon name="tools" :size="13" /><span>{{ backgroundProcessSummary(message.timelineMetadata) }}</span></summary>
                 <summary><AppIcon name="tools" :size="13" /><span>{{ backgroundProcessSummary(message.timelineMetadata) }}</span></summary>
-                <MarkdownContent v-if="message.content" :content="message.content" />
+                <MarkdownContent process-content v-if="message.content" :content="message.content" />
               </details>
               </details>
             </template>
             </template>
             <template v-else-if="message.timelineKind === 'system' && isCompactionEvent(message)">
             <template v-else-if="message.timelineKind === 'system' && isCompactionEvent(message)">
               <details class="delegation-event compaction-event">
               <details class="delegation-event compaction-event">
                 <summary><AppIcon name="archive" :size="14" /><span><strong>上下文已压缩</strong><small>压缩摘要已归档 · 点击查看</small></span></summary>
                 <summary><AppIcon name="archive" :size="14" /><span><strong>上下文已压缩</strong><small>压缩摘要已归档 · 点击查看</small></span></summary>
-                <MarkdownContent v-if="message.content" :content="message.content" />
+                <MarkdownContent process-content v-if="message.content" :content="message.content" />
               </details>
               </details>
             </template>
             </template>
             <template v-else-if="message.timelineKind === 'system'">
             <template v-else-if="message.timelineKind === 'system'">
               <details class="system-event">
               <details class="system-event">
                 <summary><AppIcon name="settings" :size="13" /><span>{{ systemSummary(message.content) }}</span></summary>
                 <summary><AppIcon name="settings" :size="13" /><span>{{ systemSummary(message.content) }}</span></summary>
-                <MarkdownContent v-if="message.content" :content="message.content" />
+                <MarkdownContent process-content v-if="message.content" :content="message.content" />
               </details>
               </details>
             </template>
             </template>
             <template v-else>
             <template v-else>
@@ -315,7 +315,7 @@ defineExpose({ scrollToMessage, scrollToAnchor, scrollToBottom, isFollowingBotto
 
 
             <details v-if="message.reasoning" class="message__reasoning">
             <details v-if="message.reasoning" class="message__reasoning">
               <summary><AppIcon name="brain" :size="13" />思考过程 · {{ message.reasoning.length }} 字</summary>
               <summary><AppIcon name="brain" :size="13" />思考过程 · {{ message.reasoning.length }} 字</summary>
-              <MarkdownContent :content="message.reasoning" :streaming="message.status === 'streaming'" @rendered="onMarkdownRendered" />
+              <MarkdownContent process-content :content="message.reasoning" :streaming="message.status === 'streaming'" @rendered="onMarkdownRendered" />
             </details>
             </details>
 
 
             <div v-if="message.role === 'user' && message.attachments?.length" class="message__attachments">
             <div v-if="message.role === 'user' && message.attachments?.length" class="message__attachments">
@@ -334,7 +334,8 @@ defineExpose({ scrollToMessage, scrollToAnchor, scrollToBottom, isFollowingBotto
                 :plain="message.role === 'user'"
                 :plain="message.role === 'user'"
                 :mention-names="mentionNames"
                 :mention-names="mentionNames"
                 :outline-prefix="message.role === 'assistant' ? `outline-${message.id}` : ''"
                 :outline-prefix="message.role === 'assistant' ? `outline-${message.id}` : ''"
-                file-cards
+                :file-cards="message.role === 'user' || message.role === 'assistant'"
+                :process-content="message.role !== 'user' && message.role !== 'assistant'"
                 @rendered="onMarkdownRendered"
                 @rendered="onMarkdownRendered"
                 @file-link="(name, url) => emit('previewFile', { name, url })"
                 @file-link="(name, url) => emit('previewFile', { name, url })"
               />
               />
@@ -351,7 +352,7 @@ defineExpose({ scrollToMessage, scrollToAnchor, scrollToBottom, isFollowingBotto
               {{ deliveryLabel(message.status) }}
               {{ deliveryLabel(message.status) }}
             </div>
             </div>
 
 
-            <div v-if="message.role !== 'user' && message.attachments?.length" class="message__attachments">
+            <div v-if="message.role === 'assistant' && message.attachments?.length" class="message__attachments">
               <button v-for="attachment in message.attachments" :key="attachment.id" type="button" @click="emit('preview', attachment)">
               <button v-for="attachment in message.attachments" :key="attachment.id" type="button" @click="emit('preview', attachment)">
                 <img v-if="attachment.kind === 'image' && attachment.url" :src="attachment.url" :alt="attachment.name" />
                 <img v-if="attachment.kind === 'image' && attachment.url" :src="attachment.url" :alt="attachment.name" />
                 <span v-else><AppIcon :name="attachment.kind || 'file'" :size="17" /></span>
                 <span v-else><AppIcon :name="attachment.kind || 'file'" :size="17" /></span>

+ 1 - 1
src/client/components/messages/TurnTrace.vue

@@ -28,7 +28,7 @@ const statusLabel = computed(() => props.group.status === 'running' ? '进行中
       <template v-for="entry in group.entries" :key="entry.id">
       <template v-for="entry in group.entries" :key="entry.id">
         <section v-if="entry.type === 'reasoning'" class="turn-trace__item turn-trace__reasoning">
         <section v-if="entry.type === 'reasoning'" class="turn-trace__item turn-trace__reasoning">
           <header><AppIcon name="brain" :size="12" />思考过程 · {{ entry.content.length }} 字</header>
           <header><AppIcon name="brain" :size="12" />思考过程 · {{ entry.content.length }} 字</header>
-          <MarkdownContent :content="entry.content" :streaming="group.status === 'running'" />
+          <MarkdownContent process-content :content="entry.content" :streaming="group.status === 'running'" />
         </section>
         </section>
         <ToolTrace v-else class="turn-trace__item turn-trace__tool" :tool="entry.tool" expanded />
         <ToolTrace v-else class="turn-trace__item turn-trace__tool" :tool="entry.tool" expanded />
       </template>
       </template>

Разница между файлами не показана из-за своего большого размера
+ 35 - 6
src/client/components/workspace/LocalVmChatPanel.vue


+ 6 - 5
src/client/components/workspace/viewModels.ts

@@ -1,3 +1,4 @@
+import { visibleMessageText, messageReasoningText } from '@shared/messageFiles'
 import type {
 import type {
   ApprovalRequest,
   ApprovalRequest,
   ChatMessage,
   ChatMessage,
@@ -122,8 +123,8 @@ export function chatMessageToUi(message: ChatMessage, agentNameFor?: (profile?:
     id: message.id,
     id: message.id,
     role: message.role,
     role: message.role,
     author: message.role === 'assistant' ? agentNameFor?.(message.profile) || message.profile : undefined,
     author: message.role === 'assistant' ? agentNameFor?.(message.profile) || message.profile : undefined,
-    content: message.content,
-    reasoning: message.reasoning,
+    content: message.role === 'assistant' ? visibleMessageText(message.content) : message.content,
+    reasoning: message.role === 'assistant' ? messageReasoningText(message.content, message.reasoning) : message.reasoning,
     createdAt: message.timestamp < 10_000_000_000 ? message.timestamp * 1000 : message.timestamp,
     createdAt: message.timestamp < 10_000_000_000 ? message.timestamp * 1000 : message.timestamp,
     status: message.isStreaming ? 'streaming' : message.stage,
     status: message.isStreaming ? 'streaming' : message.stage,
     error: message.error,
     error: message.error,
@@ -258,7 +259,7 @@ export function groupMessageToUi(message: GroupMessage, agents: GroupAgent[] = [
         : `node:${sender.nodeId}:${sender.profile}`
         : `node:${sender.nodeId}:${sender.profile}`
       : undefined,
       : undefined,
     content,
     content,
-    reasoning: message.reasoning,
+    reasoning: message.senderKind === 'agent' ? messageReasoningText(message.content, message.reasoning) : message.reasoning,
     createdAt: message.createdAt < 10_000_000_000 ? message.createdAt * 1000 : message.createdAt,
     createdAt: message.createdAt < 10_000_000_000 ? message.createdAt * 1000 : message.createdAt,
     status: message.status === 'completed' ? 'settled' : message.status === 'queued' ? 'pending' : message.status === 'streaming' ? 'streaming' : message.status === 'failed' ? 'failed' : message.status === 'unknown' ? 'unknown-receipt' : 'settled',
     status: message.status === 'completed' ? 'settled' : message.status === 'queued' ? 'pending' : message.status === 'streaming' ? 'streaming' : message.status === 'failed' ? 'failed' : message.status === 'unknown' ? 'unknown-receipt' : 'settled',
     error: message.error,
     error: message.error,
@@ -369,11 +370,11 @@ export function workspaceMessagesToUi(messages: import('@shared/workspace').Work
   return messages.filter(message => message.visible !== false).map(message => ({
   return messages.filter(message => message.visible !== false).map(message => ({
     id: message.id, role: message.role, author: message.agentName,
     id: message.id, role: message.role, author: message.agentName,
     profile: message.agentId, createdAt: message.createdAt,
     profile: message.agentId, createdAt: message.createdAt,
-    content: message.content.replace(/(!?\[[^\]]*\])\(<?([^)>]+)>?\)/g, (whole, label: string, path: string) => {
+    content: (message.role === 'assistant' ? visibleMessageText(message.content) : message.content).replace(/(!?\[[^\]]*\])\(<?([^)>]+)>?\)/g, (whole, label: string, path: string) => {
       const file = message.attachments.find(file => file.sourcePath === path)
       const file = message.attachments.find(file => file.sourcePath === path)
       return file ? `${label}(/api/app/files/${file.id}/${label.startsWith('!') ? 'preview' : 'download'})` : whole
       return file ? `${label}(/api/app/files/${file.id}/${label.startsWith('!') ? 'preview' : 'download'})` : whole
     }),
     }),
-    reasoning: message.reasoning,
+    reasoning: message.role === 'assistant' ? messageReasoningText(message.content, message.reasoning) : message.reasoning,
     status: message.status === 'complete' || message.status === 'interrupted' ? 'settled'
     status: message.status === 'complete' || message.status === 'interrupted' ? 'settled'
       : message.status === 'uncertain' ? 'unknown-receipt'
       : message.status === 'uncertain' ? 'unknown-receipt'
       : message.status === 'queued' ? 'pending' : message.status,
       : message.status === 'queued' ? 'pending' : message.status,

+ 1 - 1
src/client/stores/artifacts.ts

@@ -179,7 +179,7 @@ export const useArtifactsStore = defineStore('artifacts', () => {
         } catch {
         } catch {
           failedSessionCount.value += 1
           failedSessionCount.value += 1
           loadedSessionCount.value += 1
           loadedSessionCount.value += 1
-          return cached?.artifacts ?? []
+          return cached?.extractorVersion === ARTIFACT_EXTRACTOR_VERSION ? cached.artifacts : []
         }
         }
       })
       })
       artifacts.value = enrichPreview(batches.flat(), files).sort((a, b) => b.timestamp - a.timestamp)
       artifacts.value = enrichPreview(batches.flat(), files).sort((a, b) => b.timestamp - a.timestamp)

+ 7 - 28
src/client/utils/artifacts.ts

@@ -1,6 +1,7 @@
-import type { ChatMessage, ConversationArtifact, JsonValue, SessionSummary } from '@shared/types'
+import { visibleMessageText } from '@shared/messageFiles'
+import type { ChatMessage, ConversationArtifact, SessionSummary } from '@shared/types'
 
 
-export const ARTIFACT_EXTRACTOR_VERSION = 2
+export const ARTIFACT_EXTRACTOR_VERSION = 3
 
 
 const markdownImage = /!\[([^\]]*)\]\(([^)\s]+)\)/gi
 const markdownImage = /!\[([^\]]*)\]\(([^)\s]+)\)/gi
 const markdownLink = /(?<!!)\[([^\]]+)\]\(([^)\s]+)\)/gi
 const markdownLink = /(?<!!)\[([^\]]+)\]\(([^)\s]+)\)/gi
@@ -8,7 +9,7 @@ const rawUrl = /https?:\/\/[^\s<>"')]+/gi
 const localPath = /(?:^|[\s(:"'`])((?:\/|~\/|\.\.?\/)[^\s"'`<>]+(?:\.[a-z0-9]{1,8})?)/gim
 const localPath = /(?:^|[\s(:"'`])((?:\/|~\/|\.\.?\/)[^\s"'`<>]+(?:\.[a-z0-9]{1,8})?)/gim
 const imageExtensions = new Set(['avif', 'bmp', 'gif', 'heic', 'heif', 'jpeg', 'jpg', 'png', 'svg', 'tif', 'tiff', 'webp'])
 const imageExtensions = new Set(['avif', 'bmp', 'gif', 'heic', 'heif', 'jpeg', 'jpg', 'png', 'svg', 'tif', 'tiff', 'webp'])
 const fileExtensions = new Set([...imageExtensions, 'pdf', 'txt', 'json', 'md', 'csv', 'zip', 'tar', 'gz', 'mp3', 'wav', '3gp', 'avi', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'webm', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'])
 const fileExtensions = new Set([...imageExtensions, 'pdf', 'txt', 'json', 'md', 'csv', 'zip', 'tar', 'gz', 'mp3', 'wav', '3gp', 'avi', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'webm', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'])
-const keyHints = ['path', 'file', 'url', 'image', 'artifact', 'output', 'download', 'result', 'target']
+
 
 
 interface Candidate { value: string; label?: string; mimeType?: string; attachment?: ConversationArtifact['attachment'] }
 interface Candidate { value: string; label?: string; mimeType?: string; attachment?: ConversationArtifact['attachment'] }
 
 
@@ -58,42 +59,20 @@ function textCandidates(text: string): Candidate[] {
   return result
   return result
 }
 }
 
 
-function collectStringValues(value: JsonValue, keyPath: string, output: Candidate[]): void {
-  if (typeof value === 'string') {
-    const normalized = normalize(value)
-    if ((keyHints.some(hint => keyPath.toLowerCase().includes(hint)) || looksLikePathOrUrl(normalized)) && looksLikeArtifact(normalized)) {
-      output.push({ value: normalized })
-    }
-    return
-  }
-  if (Array.isArray(value)) return value.forEach((child, index) => collectStringValues(child, `${keyPath}.${index}`, output))
-  if (value && typeof value === 'object') {
-    for (const key of Object.keys(value).sort()) collectStringValues(value[key], `${keyPath}.${key}`, output)
-  }
-}
-
 function candidates(message: ChatMessage): Candidate[] {
 function candidates(message: ChatMessage): Candidate[] {
-  const result = textCandidates(message.content)
+  const result = textCandidates(visibleMessageText(message.content))
   for (const attachment of message.attachments ?? []) {
   for (const attachment of message.attachments ?? []) {
     const value = attachment.path || attachment.url
     const value = attachment.path || attachment.url
     if (value) result.push({ value, mimeType: attachment.mimeType, attachment })
     if (value) result.push({ value, mimeType: attachment.mimeType, attachment })
   }
   }
-  for (const call of message.toolCalls ?? []) {
-    if (call.arguments !== undefined) collectStringValues(call.arguments, 'tool.arguments', result)
-    if (call.result !== undefined) collectStringValues(call.result, 'tool.result', result)
-    if (call.preview) result.push(...textCandidates(call.preview))
-  }
-  if (message.role === 'tool') {
-    try { collectStringValues(JSON.parse(message.content) as JsonValue, 'tool.result', result) } catch { /* plain tool text is already scanned */ }
-  }
   return result
   return result
 }
 }
 
 
-/** Extracts assistant/tool artifacts and intentionally ignores user rows. */
+/** Extracts files delivered in assistant messages, never execution details. */
 export function extractArtifacts(session: SessionSummary, messages: ChatMessage[]): ConversationArtifact[] {
 export function extractArtifacts(session: SessionSummary, messages: ChatMessage[]): ConversationArtifact[] {
   const found = new Map<string, ConversationArtifact>()
   const found = new Map<string, ConversationArtifact>()
   for (const message of messages) {
   for (const message of messages) {
-    if (message.role !== 'assistant' && message.role !== 'tool') continue
+    if (message.role !== 'assistant' || Boolean(message.displayKind)) continue
     for (const candidate of candidates(message)) {
     for (const candidate of candidates(message)) {
       const value = normalize(candidate.value)
       const value = normalize(candidate.value)
       if (!value || !looksLikeArtifact(value)) continue
       if (!value || !looksLikeArtifact(value)) continue

+ 3 - 0
src/client/utils/messageDisplay.ts

@@ -1,3 +1,5 @@
+import { visibleMessageText } from '@shared/messageFiles'
+
 const ATTACHED_CONTEXT_MARKER_RE = /(?:^|\n)--- Attached Context ---\s*\n/
 const ATTACHED_CONTEXT_MARKER_RE = /(?:^|\n)--- Attached Context ---\s*\n/
 const CONTEXT_WARNINGS_MARKER_RE = /(?:^|\n)--- Context Warnings ---[\s\S]*$/
 const CONTEXT_WARNINGS_MARKER_RE = /(?:^|\n)--- Context Warnings ---[\s\S]*$/
 const CONTEXT_REF_RE = /@(file|folder|url|image|tool|terminal):(?:"[^"\n]+"|'[^'\n]+'|`[^`\n]+`|\S+)/g
 const CONTEXT_REF_RE = /@(file|folder|url|image|tool|terminal):(?:"[^"\n]+"|'[^'\n]+'|`[^`\n]+`|\S+)/g
@@ -11,6 +13,7 @@ const CONTEXT_REF_RE = /@(file|folder|url|image|tool|terminal):(?:"[^"\n]+"|'[^'
  * apply this projection only at display/copy boundaries.
  * apply this projection only at display/copy boundaries.
  */
  */
 export function displayContentForMessage(role: string, content: string): string {
 export function displayContentForMessage(role: string, content: string): string {
+  if (role === 'assistant') return visibleMessageText(content)
   if (role !== 'user') return content
   if (role !== 'user') return content
 
 
   const marker = content.match(ATTACHED_CONTEXT_MARKER_RE)
   const marker = content.match(ATTACHED_CONTEXT_MARKER_RE)

+ 37 - 3
src/client/views/ConversationsView.vue

@@ -77,6 +77,8 @@ const searchItems = computed<SidebarItem[]>(() => [false, true].map(archived =>
   const items = conversations.value.filter(c => c.archived === archived).map(c => workspaceConversationItem(c, agents.value))
   const items = conversations.value.filter(c => c.archived === archived).map(c => workspaceConversationItem(c, agents.value))
   return { id: archived ? 'archived' : 'unarchived', title: archived ? '已归档' : '未归档', children: items, emptyText: archived ? '没有已归档聊天' : '没有未归档聊天' }
   return { id: archived ? 'archived' : 'unarchived', title: archived ? '已归档' : '未归档', children: items, emptyText: archived ? '没有已归档聊天' : '没有未归档聊天' }
 }))
 }))
+const archivedIds = computed(() => new Set(conversations.value.filter(c => c.archived).map(c => c.id)))
+const deletingId = ref(''), deleteError = ref('')
 const composer = ref<InstanceType<typeof ComposerShell>>()
 const composer = ref<InstanceType<typeof ComposerShell>>()
 const timeline = ref<InstanceType<typeof MessageTimeline>>()
 const timeline = ref<InstanceType<typeof MessageTimeline>>()
 const quoted = ref<UiMessage | null>(null)
 const quoted = ref<UiMessage | null>(null)
@@ -553,6 +555,28 @@ async function action(operation: 'pin' | 'archive', id = active.value?.id) {
     error.value = String(e)
     error.value = String(e)
   }
   }
 }
 }
+async function deleteArchivedConversation(id: string) {
+  const conversation = conversations.value.find(c => c.id === id)
+  if (!conversation?.archived || deletingId.value) return
+  deleteError.value = ''
+  const direct = conversation.kind === 'direct'
+  const message = direct
+    ? `永久删除 Bot「${conversation.name}」及其聊天记录?此操作无法撤销,文件库中的文件会保留。`
+    : `永久删除群聊「${conversation.name}」及其聊天记录?此操作无法撤销,成员 Bot 和文件库中的文件会保留。`
+  if (!confirm(message)) return
+  deletingId.value = id
+  try {
+    await apiRequest(direct ? `/api/app/agents/${conversation.memberIds[0]}` : `/api/app/conversations/${id}`, { method: 'DELETE' })
+    conversations.value = conversations.value.filter(c => c.id !== id)
+    if (direct) agents.value = agents.value.filter(a => a.id !== conversation.memberIds[0])
+    if (selected.value === id) await router.replace('/conversations')
+    await refresh()
+  } catch (cause) {
+    deleteError.value = cause instanceof Error ? cause.message : '删除失败,请重试'
+  } finally {
+    deletingId.value = ''
+  }
+}
 async function stopMember(id: string) {
 async function stopMember(id: string) {
   if (!active.value) return
   if (!active.value) return
   try {
   try {
@@ -683,9 +707,7 @@ onBeforeUnmount(() => {
             <select v-if="active.kind === 'group' && tasks.length" class="task-picker" aria-label="当前任务" :value="activeTask?.id" @change="router.push({query:{...route.query,taskId:($event.target as HTMLSelectElement).value}})">
             <select v-if="active.kind === 'group' && tasks.length" class="task-picker" aria-label="当前任务" :value="activeTask?.id" @change="router.push({query:{...route.query,taskId:($event.target as HTMLSelectElement).value}})">
               <option v-for="task in tasks" :key="task.id" :value="task.id">{{ task.title }}</option>
               <option v-for="task in tasks" :key="task.id" :value="task.id">{{ task.title }}</option>
             </select>
             </select>
-            <button class="icon-button" :aria-label="active.pinned ? '取消置顶' : '置顶聊天'" :title="active.pinned ? '取消置顶' : '置顶聊天'" @click="action('pin')"><AppIcon :name="active.pinned ? 'pin-off' : 'pin'" /></button>
             <button class="icon-button" aria-label="聊天设置" title="聊天设置" @click="openDialog(active.kind === 'direct' ? 'editAgent' : 'editGroup')"><AppIcon name="settings" /></button>
             <button class="icon-button" aria-label="聊天设置" title="聊天设置" @click="openDialog(active.kind === 'direct' ? 'editAgent' : 'editGroup')"><AppIcon name="settings" /></button>
-            <button class="icon-button" :aria-label="active.archived ? '恢复聊天' : '归档聊天'" :title="active.archived ? '恢复聊天' : '归档聊天'" @click="action('archive')"><AppIcon name="archive" /></button>
           </div>
           </div>
         </template>
         </template>
       </MessageTimeline>
       </MessageTimeline>
@@ -702,7 +724,14 @@ onBeforeUnmount(() => {
     </div>
     </div>
     <ComputerPanel ref="desktopViewer" v-if="computerOpen&&desktopAgent" :agents="[desktopAgent]" auto-take @changed="load()" @close="computerOpen=false" />
     <ComputerPanel ref="desktopViewer" v-if="computerOpen&&desktopAgent" :agents="[desktopAgent]" auto-take @changed="load()" @close="computerOpen=false" />
     <LocalVmWorkspace ref="vmWorkspace" v-if="twoDesktops&&desktopAgent" :agents="agents.filter(a=>a.execution==='computer'&&!a.archived&&!a.computerEnvironmentId)" :primary="desktopAgent.id" @close="twoDesktops=false" />
     <LocalVmWorkspace ref="vmWorkspace" v-if="twoDesktops&&desktopAgent" :agents="agents.filter(a=>a.execution==='computer'&&!a.archived&&!a.computerEnvironmentId)" :primary="desktopAgent.id" @close="twoDesktops=false" />
-    <FloatingResourceSearch section="groups" label="搜索聊天" :items="searchItems" tabbed @select="select" />
+    <FloatingResourceSearch section="groups" label="搜索聊天" :items="searchItems" tabbed @open="deleteError = ''" @select="select">
+      <template #item-actions="{ item }">
+        <button v-if="archivedIds.has(item.id)" type="button" class="search-delete" :aria-label="`删除聊天:${item.title}`" :disabled="!!deletingId" :aria-busy="deletingId === item.id" @click="deleteArchivedConversation(item.id)">
+          <AppIcon name="trash" :size="15" />{{ deletingId === item.id ? '删除中…' : '删除' }}
+        </button>
+      </template>
+      <template #footer><p v-if="deleteError" class="search-delete-error" role="alert">{{ deleteError }}</p></template>
+    </FloatingResourceSearch>
     <PreviewModal v-if="preview" :item="preview" :items="media" @close="preview = null" />
     <PreviewModal v-if="preview" :item="preview" :items="media" @close="preview = null" />
     <ImagePreviewLightbox v-model="mediaIndex" :images="lightboxMedia" />
     <ImagePreviewLightbox v-model="mediaIndex" :images="lightboxMedia" />
     <RemoteAgentPicker v-if="remotePickerOpen && !auth.isBotOnly" @close="remotePickerOpen = false" @added="remoteAdded" />
     <RemoteAgentPicker v-if="remotePickerOpen && !auth.isBotOnly" @close="remotePickerOpen = false" @added="remoteAdded" />
@@ -906,4 +935,9 @@ onBeforeUnmount(() => {
   margin-top: 8px;
   margin-top: 8px;
 }
 }
 .workspace-list-back{display:none}@media(max-width:900px){.workspace-list-back{display:grid}}
 .workspace-list-back{display:none}@media(max-width:900px){.workspace-list-back{display:grid}}
+.search-delete{display:inline-flex;flex:0 0 auto;align-items:center;justify-content:center;gap:5px;min-width:64px;min-height:44px;margin-right:4px;padding:6px 9px;border:0;border-radius:8px;background:transparent;color:var(--danger);font:12px var(--font-ui);cursor:pointer}
+.search-delete:hover:not(:disabled){background:var(--surface-hover)}
+.search-delete:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
+.search-delete:disabled{opacity:.5;cursor:wait}
+.search-delete-error{margin:0;padding:10px 16px 14px;color:var(--danger);font-size:12px;line-height:1.5}
 </style>
 </style>

+ 9 - 6
src/runner/agent.ts

@@ -46,18 +46,21 @@ export class RunnerAgent {
     this.target={url:hermes,client,session:new UpstreamServiceSession(client,()=>config.hermesCredentials)}
     this.target={url:hermes,client,session:new UpstreamServiceSession(client,()=>config.hermesCredentials)}
     this.db=new DatabaseSync(join(home,'runner-commands.sqlite3'))
     this.db=new DatabaseSync(join(home,'runner-commands.sqlite3'))
     this.db.exec('CREATE TABLE IF NOT EXISTS commands(id TEXT PRIMARY KEY,fingerprint TEXT NOT NULL,state TEXT NOT NULL,result TEXT,created INTEGER NOT NULL)')
     this.db.exec('CREATE TABLE IF NOT EXISTS commands(id TEXT PRIMARY KEY,fingerprint TEXT NOT NULL,state TEXT NOT NULL,result TEXT,created INTEGER NOT NULL)')
-    if(config.computers){this.computers=new ComputerRuntime(this.db,config,home);this.localVm=new LocalVmImages(this.computers,this.db)}
+    if(config.computers){this.computers=new ComputerRuntime(this.db,config,home,undefined,(id,operation,body)=>this.api('desktop',{id,operation,...body}));this.localVm=new LocalVmImages(this.computers,this.db)}
     this.compactReceipts()
     this.compactReceipts()
   }
   }
   private async api(path:string,body?:unknown):Promise<any> {
   private async api(path:string,body?:unknown):Promise<any> {
     const url=new URL(`/api/runner/v1/${this.config.runnerId}/${path}`,this.config.serverURL)
     const url=new URL(`/api/runner/v1/${this.config.runnerId}/${path}`,this.config.serverURL)
     if(url.hostname==='localhost')url.hostname='127.0.0.1'
     if(url.hostname==='localhost')url.hostname='127.0.0.1'
     const response=await (isLocalAuthorizationTarget(url)&&this.fetchImpl===fetch?this.controlTransport.fetch.bind(this.controlTransport):this.fetchImpl)(url,{
     const response=await (isLocalAuthorizationTarget(url)&&this.fetchImpl===fetch?this.controlTransport.fetch.bind(this.controlTransport):this.fetchImpl)(url,{
-      method:body===undefined?'GET':'POST',redirect:'error',signal:AbortSignal.any([this.controlAbort.signal,AbortSignal.timeout(25000)]),
-      headers:{Authorization:`Bearer ${this.config.token}`,'x-runner-instance':this.instance,'x-runner-protocol':'1','x-runner-features':this.computers?'computer-worker-v1,artifact-chunks-v1,helper-retirement-v1,computer-control-v1,shared-computer-v1,local-vm-v1'+(this.computers.config.imageId!==UNCONFIGURED_COMPUTER_IMAGE?',image-ready-v1':''):'',...(this.serverEpoch?{'x-runner-epoch':this.serverEpoch}:{}),'Content-Type':'application/json',...(path==='poll'&&!this.connected?{'x-runner-reset':'1'}:{})},
+      method:body===undefined?'GET':'POST',redirect:'error',signal:AbortSignal.any([this.controlAbort.signal,AbortSignal.timeout(path==='desktop'?75000:25000)]),
+      headers:{Authorization:`Bearer ${this.config.token}`,'x-runner-instance':this.instance,'x-runner-protocol':'1','x-runner-features':this.computers?'computer-worker-v1,artifact-chunks-v1,computer-control-v1,shared-computer-v1,local-vm-v1'+(this.computers.provider.fixedCapacity?',compose-desktops-v1':',helper-retirement-v1')+(this.computers.config.imageId!==UNCONFIGURED_COMPUTER_IMAGE?',image-ready-v1':''):'',...(this.serverEpoch?{'x-runner-epoch':this.serverEpoch}:{}),'Content-Type':'application/json',...(path==='poll'&&!this.connected?{'x-runner-reset':'1'}:{})},
       ...(body===undefined?{}:{body:JSON.stringify(body)}),
       ...(body===undefined?{}:{body:JSON.stringify(body)}),
     })
     })
-    if(!response.ok)throw new HttpError(response.status,`执行节点连接被拒绝(HTTP ${response.status})`,response.status===403?'runner_unauthorized':'runner_request_failed')
+    if(!response.ok){
+      if(path==='desktop'){const error=await response.json().catch(()=>({})) as {error?:string;code?:string};throw new HttpError(response.status,error.error?.slice(0,300)||'Compose 桌面连接失败',error.code||'compose_desktop_error')}
+      throw new HttpError(response.status,`执行节点连接被拒绝(HTTP ${response.status})`,response.status===403?'runner_unauthorized':'runner_request_failed')
+    }
     const reader=response.body?.getReader();const chunks:Uint8Array[]=[];let bytes=0
     const reader=response.body?.getReader();const chunks:Uint8Array[]=[];let bytes=0
     if(!reader)throw new Error('执行节点响应为空')
     if(!reader)throw new Error('执行节点响应为空')
     try{for(;;){const part=await reader.read();if(part.done)break;bytes+=part.value.length;if(bytes>40*1024*1024)throw new Error('执行节点响应超过大小限制');chunks.push(part.value)}}finally{await reader.cancel()}
     try{for(;;){const part=await reader.read();if(part.done)break;bytes+=part.value.length;if(bytes>40*1024*1024)throw new Error('执行节点响应超过大小限制');chunks.push(part.value)}}finally{await reader.cancel()}
@@ -112,12 +115,12 @@ export class RunnerAgent {
       const authorize=()=>{if(!this.connected||!this.active||Date.now()>command.expiresAt)throw new HttpError(403,'电脑请求已失效','computer_control_expired')}
       const authorize=()=>{if(!this.connected||!this.active||Date.now()>command.expiresAt)throw new HttpError(403,'电脑请求已失效','computer_control_expired')}
       await this.computers.ready
       await this.computers.ready
       if(input.op==='detail'){
       if(input.op==='detail'){
-        const vm=await this.localVm!.status(),spec=this.computers.pool.definition(input.target.ownerKey,input.target.environmentId)
+        const vm=await this.localVm!.status(),spec=this.computers.pool.definition(input.target.ownerKey,input.target.environmentId)??(this.computers.provider.fixedCapacity?{id:input.target.environmentId,ownerKey:input.target.ownerKey,imageId:this.computers.config.imageId}:undefined)
         const state=await this.computers.controls.status(input.target)
         const state=await this.computers.controls.status(input.target)
         const actual=spec?await this.computers.provider.inspect(spec):undefined
         const actual=spec?await this.computers.provider.inspect(spec):undefined
         let ready=false
         let ready=false
         if(actual?.running)try{await this.computers.provider.health(spec!,authorize);ready=true}catch{}
         if(actual?.running)try{await this.computers.provider.health(spec!,authorize);ready=true}catch{}
-        return {...state,container:actual?.running?'running':spec?'stopped':'missing',ready,inUse:['agent','pausing','human','resuming'].includes(state.mode),mode:vm.mode,maxInstances:vm.maxInstances,image:vm.image,controlMode:state.mode}
+        return {...state,container:actual?.running?'running':spec?'stopped':'missing',ready,inUse:['agent','pausing','human','resuming'].includes(state.mode),mode:vm.mode,maxInstances:vm.maxInstances,image:vm.image,controlMode:state.mode,fixedCapacity:vm.fixedCapacity}
       }
       }
       if(input.op==='lifecycle'){
       if(input.op==='lifecycle'){
         const action=z.enum(['create','start','stop','recreate','remove']).parse(input.action)
         const action=z.enum(['create','start','stop','recreate','remove']).parse(input.action)

+ 47 - 0
src/runner/computers/compose.ts

@@ -0,0 +1,47 @@
+import {randomUUID} from 'node:crypto'
+import {ContainerComputerProvider,ComputerError,type ComputerSpecification,type ComputerState,type CommandResult} from './container.js'
+import type {DesktopRelay} from '../../shared/composeDesktops.js'
+
+/** Uses only the fixed desktops declared by Compose; never calls a container engine. */
+export class ComposeComputerProvider extends ContainerComputerProvider {
+  readonly fixedCapacity=true
+  private leases=new Map<string,{token:string;instance:string}>()
+  constructor(runnerId:string,home:string,readonly relay:DesktopRelay){super('docker',runnerId,home)}
+  async inventory(){return this.relay('','list',{})}
+  async verifyRuntime(){await this.inventory()}
+  async inspect(spec:ComputerSpecification):Promise<ComputerState|undefined>{
+    this.validateSpecification(spec)
+    const state=await this.relay(spec.id,'health',{ownerKey:spec.ownerKey})
+    return {id:spec.id,containerId:state.instance,workspace:'/home/cua/workspace',running:state.ready===true,isolation:'container'}
+  }
+  async ensure(spec:ComputerSpecification,authorize:()=>void):Promise<ComputerState>{
+    authorize();const state=await this.inspect(spec);authorize()
+    if(!state?.running)throw new ComputerError('compose_desktop_offline','Compose 桌面尚未就绪,请检查对应桌面容器')
+    if(!this.leases.has(spec.id)){
+      const lease=await this.relay(spec.id,'acquire',{ownerKey:spec.ownerKey,requestId:randomUUID()})
+      this.leases.set(spec.id,lease)
+      try{authorize()}catch(error){await this.stop(spec);throw error}
+    }
+    return state
+  }
+  async releaseFence(spec:ComputerSpecification,keepRunning=false){
+    const lease=this.leases.get(spec.id);if(!lease)return
+    try{await this.relay(spec.id,'release',{ownerKey:spec.ownerKey,...lease,cancel:!keepRunning})}
+    catch(error){const state=await this.relay(spec.id,'health',{ownerKey:spec.ownerKey}).catch(()=>undefined);if(!state||state.instance===lease.instance)throw error}
+    this.leases.delete(spec.id)
+  }
+  async renewFence(spec:ComputerSpecification){const lease=this.leases.get(spec.id);if(lease)await this.relay(spec.id,'renew',{ownerKey:spec.ownerKey,...lease})}
+  async stop(spec:ComputerSpecification){await this.releaseFence(spec)}
+  async remove(spec:ComputerSpecification){await this.stop(spec)}
+  async deleteWorkspace(_spec:ComputerSpecification){} // Compose owns the named volume.
+  async execute(spec:ComputerSpecification,argv:string[],options:{authorize():void;signal?:AbortSignal;timeout?:number;input?:Buffer}):Promise<CommandResult>{
+    options.authorize();if(options.signal?.aborted)throw new ComputerError('computer_cancelled','操作已停止')
+    const lease=this.leases.get(spec.id);if(!lease)throw new ComputerError('computer_lease_stale','需要当前共享桌面的控制权')
+    const result=await this.relay(spec.id,'execute',{ownerKey:spec.ownerKey,...lease,argv,cwd:spec.cwd??'/home/cua/workspace',timeout:options.timeout??30000,...(options.input?{input:options.input.toString('base64')}:{})})
+    options.authorize();if(result.exitCode)throw Object.assign(new ComputerError('computer_command_failed','桌面命令执行失败'),{code:result.exitCode,stdout:result.stdout,stderr:result.stderr})
+    return result
+  }
+  async capture(spec:ComputerSpecification,authorize:()=>void){authorize();const result=await this.relay(spec.id,'frame',{ownerKey:spec.ownerKey});authorize();return result}
+  async health(spec:ComputerSpecification,authorize:()=>void){authorize();const result=await this.relay(spec.id,'health',{ownerKey:spec.ownerKey});if(!result.ready)throw new ComputerError('compose_desktop_offline','Compose 桌面尚未就绪');return result}
+  async configureNetwork(_spec:ComputerSpecification,authorize:()=>void){authorize()}
+}

+ 3 - 0
src/runner/computers/container.ts

@@ -34,6 +34,8 @@ export type ComputerSpecification=z.input<typeof schema>
 type Spec=z.output<typeof schema>
 type Spec=z.output<typeof schema>
 export interface ComputerState {id:string;containerId:string;running:boolean;workspace:string;isolation:'container'|'vm'}
 export interface ComputerState {id:string;containerId:string;running:boolean;workspace:string;isolation:'container'|'vm'}
 export interface ComputerProvider {
 export interface ComputerProvider {
+  releaseFence?(spec:ComputerSpecification,keepRunning?:boolean):Promise<void>
+  renewFence?(spec:ComputerSpecification):Promise<void>
   validateSpecification(spec:ComputerSpecification):ComputerSpecification
   validateSpecification(spec:ComputerSpecification):ComputerSpecification
   readonly capabilities:{isolation:'container'|'vm';shell:boolean;desktop:boolean;persistentWorkspace:boolean;sharedDesktop:boolean;snapshots:boolean;network:'none'|'public-proxy'}
   readonly capabilities:{isolation:'container'|'vm';shell:boolean;desktop:boolean;persistentWorkspace:boolean;sharedDesktop:boolean;snapshots:boolean;network:'none'|'public-proxy'}
   inspect(spec:ComputerSpecification):Promise<ComputerState|undefined>
   inspect(spec:ComputerSpecification):Promise<ComputerState|undefined>
@@ -50,6 +52,7 @@ const capabilities=(values:unknown)=>Array.isArray(values)?values.map(value=>Str
 /** A private container per environment. No tools, filesystem operations or
 /** A private container per environment. No tools, filesystem operations or
  * process execution fall back to the host. Remote hosts run their own Runner. */
  * process execution fall back to the host. Remote hosts run their own Runner. */
 export class ContainerComputerProvider implements ComputerProvider {
 export class ContainerComputerProvider implements ComputerProvider {
+  readonly fixedCapacity:boolean=false
   private queue=new Map<string,Promise<unknown>>()
   private queue=new Map<string,Promise<unknown>>()
   readonly capabilities={isolation:'container',shell:true,desktop:true,persistentWorkspace:true,sharedDesktop:false,snapshots:false,network:'none'} as const
   readonly capabilities={isolation:'container',shell:true,desktop:true,persistentWorkspace:true,sharedDesktop:false,snapshots:false,network:'none'} as const
   constructor(readonly runtime:'docker'|'podman',readonly runnerId:string,readonly home:string,readonly run:ContainerCommand=command,readonly environment:NodeJS.ProcessEnv=process.env) {
   constructor(readonly runtime:'docker'|'podman',readonly runnerId:string,readonly home:string,readonly run:ContainerCommand=command,readonly environment:NodeJS.ProcessEnv=process.env) {

+ 11 - 1
src/runner/computers/localVm.ts

@@ -6,6 +6,8 @@ import { ComputerError } from './container.js'
 import { UNCONFIGURED_COMPUTER_IMAGE } from '../../shared/runner.js'
 import { UNCONFIGURED_COMPUTER_IMAGE } from '../../shared/runner.js'
 import type { LocalVmMode, LocalVmStatus } from '../../shared/localVm.js'
 import type { LocalVmMode, LocalVmStatus } from '../../shared/localVm.js'
 import type { ComputerRuntime } from '../worker/gateway.js'
 import type { ComputerRuntime } from '../worker/gateway.js'
+import {ComposeComputerProvider} from './compose.js'
+import {COMPOSE_DESKTOP_IMAGE} from '../../shared/composeDesktops.js'
 
 
 type State = { imageId: string; mode: LocalVmMode; maxInstances: number; job?: LocalVmStatus['job'] }
 type State = { imageId: string; mode: LocalVmMode; maxInstances: number; job?: LocalVmStatus['job'] }
 
 
@@ -22,8 +24,9 @@ export class LocalVmImages {
     db.exec('CREATE TABLE IF NOT EXISTS local_vm_runtime(id INTEGER PRIMARY KEY CHECK(id=1),value TEXT NOT NULL)')
     db.exec('CREATE TABLE IF NOT EXISTS local_vm_runtime(id INTEGER PRIMARY KEY CHECK(id=1),value TEXT NOT NULL)')
     const row = db.prepare('SELECT value FROM local_vm_runtime WHERE id=1').get() as {value:string}|undefined
     const row = db.prepare('SELECT value FROM local_vm_runtime WHERE id=1').get() as {value:string}|undefined
     this.state = row ? JSON.parse(row.value) : {imageId:runtime.config.imageId,mode:'per-bot',maxInstances:runtime.config.maxConcurrent ?? 2}
     this.state = row ? JSON.parse(row.value) : {imageId:runtime.config.imageId,mode:'per-bot',maxInstances:runtime.config.maxConcurrent ?? 2}
+    if(runtime.provider.fixedCapacity)this.state={imageId:COMPOSE_DESKTOP_IMAGE,mode:'shared',maxInstances:2}
     // Preserve an already selected image when migrating; old archives and workspaces are untouched.
     // Preserve an already selected image when migrating; old archives and workspaces are untouched.
-    if (!row && db.prepare("SELECT name FROM sqlite_master WHERE name='managed_image_selection'").get()) {
+    if (!runtime.provider.fixedCapacity && !row && db.prepare("SELECT name FROM sqlite_master WHERE name='managed_image_selection'").get()) {
       const old = db.prepare('SELECT value FROM managed_image_selection WHERE id=1').get() as {value:string}|undefined
       const old = db.prepare('SELECT value FROM managed_image_selection WHERE id=1').get() as {value:string}|undefined
       if (old) this.state.imageId = JSON.parse(old.value).active ?? this.state.imageId
       if (old) this.state.imageId = JSON.parse(old.value).active ?? this.state.imageId
     }
     }
@@ -50,6 +53,11 @@ export class LocalVmImages {
   }
   }
   async status(owner?:string): Promise<LocalVmStatus> {
   async status(owner?:string): Promise<LocalVmStatus> {
     await this.ready
     await this.ready
+    if(this.runtime.provider instanceof ComposeComputerProvider){
+      const desktops=await this.runtime.provider.inventory()
+      this.runtime.pool.limits.concurrent=Math.max(1,desktops.length)
+      return {configured:true,executionHost:'runner',fixedCapacity:true,desktops,daemonUp:true,image:desktops.some((d:any)=>d.ready),imageId:COMPOSE_DESKTOP_IMAGE,mode:'shared',maxInstances:desktops.length,busy:false}
+    }
     if(this.releaseMaintenance&&!this.pending&&this.state.job?.state==='failed') {
     if(this.releaseMaintenance&&!this.pending&&this.state.job?.state==='failed') {
       try{await this.cleanup(this.state.job.id);this.releaseMaintenance();this.releaseMaintenance=undefined}catch{}
       try{await this.cleanup(this.state.job.id);this.releaseMaintenance();this.releaseMaintenance=undefined}catch{}
     }
     }
@@ -64,6 +72,7 @@ export class LocalVmImages {
       instances:owner?this.runtime.pool.status(owner).map(row=>({id:row.environmentId,status:row.status})):[]}
       instances:owner?this.runtime.pool.status(owner).map(row=>({id:row.environmentId,status:row.status})):[]}
   }
   }
   async policy(mode:LocalVmMode,maxInstances:number) {
   async policy(mode:LocalVmMode,maxInstances:number) {
+    if(this.runtime.provider.fixedCapacity)throw new ComputerError('compose_desktop_managed','桌面数量与共享方式由 Compose 固定,不能在界面修改')
     await this.ready
     await this.ready
     // Sharing changes future Agent bindings; an idle desktop can keep running.
     // Sharing changes future Agent bindings; an idle desktop can keep running.
     // Image preparation still requires every desktop to be stopped.
     // Image preparation still requires every desktop to be stopped.
@@ -73,6 +82,7 @@ export class LocalVmImages {
     return this.status()
     return this.status()
   }
   }
   async prepare(id:string,check:()=>Promise<void>) {
   async prepare(id:string,check:()=>Promise<void>) {
+    if(this.runtime.provider.fixedCapacity)throw new ComputerError('compose_desktop_managed','桌面镜像由 Compose 配置,无需在界面准备')
     await this.ready;await check()
     await this.ready;await check()
     if(this.state.job?.id===id)return this.status()
     if(this.state.job?.id===id)return this.status()
     if(this.pending||this.closed)throw new ComputerError('local_vm_busy','本地虚拟机正在准备,请稍后查看')
     if(this.pending||this.closed)throw new ComputerError('local_vm_busy','本地虚拟机正在准备,请稍后查看')

+ 2 - 1
src/runner/computers/pool.ts

@@ -107,7 +107,7 @@ export class ComputerPool {
     })
     })
   }
   }
   authorize(lease:ComputerLease){this.assert(lease)}
   authorize(lease:ComputerLease){this.assert(lease)}
-  renew(lease:ComputerLease):void{this.assert(lease);const entry=this.require(lease);entry.expiresAt=this.now()+this.limits.ttlMs;this.save(entry)}
+  renew(lease:ComputerLease):void{this.assert(lease);const entry=this.require(lease);entry.expiresAt=this.now()+this.limits.ttlMs;this.save(entry);void this.provider.renewFence?.(entry.spec).catch(()=>{try{this.invalidate(this.require(lease))}catch{}})}
   use<T>(lease:ComputerLease,action:(context:{signal:AbortSignal;authorize():void})=>Promise<T>):Promise<T>{
   use<T>(lease:ComputerLease,action:(context:{signal:AbortSignal;authorize():void})=>Promise<T>):Promise<T>{
     this.assert(lease)
     this.assert(lease)
     const active=this.active.get(lease.id)!
     const active=this.active.get(lease.id)!
@@ -120,6 +120,7 @@ export class ComputerPool {
       this.assert(lease)
       this.assert(lease)
       const entry=this.require(lease),active=this.active.get(lease.id)!
       const entry=this.require(lease),active=this.active.get(lease.id)!
       if(active.operations.size)throw new ComputerError('computer_busy','电脑仍有未结束操作,暂不能进入空闲状态')
       if(active.operations.size)throw new ComputerError('computer_busy','电脑仍有未结束操作,暂不能进入空闲状态')
+      if(this.provider.releaseFence)await this.provider.releaseFence(entry.spec,true)
       active.detach();active.controller.abort();this.active.delete(lease.id)
       active.detach();active.controller.abort();this.active.delete(lease.id)
       entry.status='idle';entry.generation++;entry.lease=undefined;entry.expiresAt=0;this.save(entry)
       entry.status='idle';entry.generation++;entry.lease=undefined;entry.expiresAt=0;this.save(entry)
     })
     })

+ 7 - 2
src/runner/config.ts

@@ -1,13 +1,18 @@
-import { isAbsolute } from 'node:path'
+import { isAbsolute, join } from 'node:path'
+import { homedir } from 'node:os'
 import { z } from 'zod'
 import { z } from 'zod'
 import type { RunnerConfiguration } from '../shared/runner.js'
 import type { RunnerConfiguration } from '../shared/runner.js'
 
 
+const localPath=z.string().refine(value=>!value||isAbsolute(value),'路径必须为绝对路径').default('')
 const schema=z.object({
 const schema=z.object({
   protocol:z.literal(1),serverURL:z.string().url(),runnerId:z.string().uuid(),token:z.string().min(32).max(4096),
   protocol:z.literal(1),serverURL:z.string().url(),runnerId:z.string().uuid(),token:z.string().min(32).max(4096),
   hermesURL:z.string().url().default('http://127.0.0.1:9119'),
   hermesURL:z.string().url().default('http://127.0.0.1:9119'),
   allowedProfiles:z.array(z.string().trim().min(1).max(256).regex(/^[^/\\\u0000-\u001f]+$/)).min(1).max(256),
   allowedProfiles:z.array(z.string().trim().min(1).max(256).regex(/^[^/\\\u0000-\u001f]+$/)).min(1).max(256),
   artifactRoots:z.array(z.string().refine(isAbsolute,'产物目录必须为绝对路径')).max(64).default([]),
   artifactRoots:z.array(z.string().refine(isAbsolute,'产物目录必须为绝对路径')).max(64).default([]),
-  computers:z.object({network:z.enum(['none','public-proxy']).default('none'),runtime:z.enum(['docker','podman']),imageId:z.string().regex(/^sha256:[a-f0-9]{64}$/),python:z.string().refine(isAbsolute),hermesSource:z.string().refine(isAbsolute),hermesHome:z.string().refine(isAbsolute),maxConcurrent:z.number().int().min(1).max(8).optional()}).strict().optional(),
+  computers:z.object({managedBy:z.literal('compose').optional(),network:z.enum(['none','public-proxy']).default('none'),runtime:z.enum(['docker','podman']),imageId:z.string().regex(/^sha256:[a-f0-9]{64}$/),python:localPath,hermesSource:localPath,hermesHome:localPath,maxConcurrent:z.number().int().min(1).max(8).optional()}).strict().transform(value=>{
+    const hermesHome=value.hermesHome||join(homedir(),'.hermes'),hermesSource=value.hermesSource||join(hermesHome,'hermes-agent')
+    return {...value,hermesHome,hermesSource,python:value.python||join(hermesSource,'venv','bin','python')}
+  }).optional(),
   allowInsecureLan:z.boolean().optional(),hermesCredentials:z.object({username:z.string().max(256),password:z.string().max(4096)}).strict().optional(),
   allowInsecureLan:z.boolean().optional(),hermesCredentials:z.object({username:z.string().max(256),password:z.string().max(4096)}).strict().optional(),
 }).strict()
 }).strict()
 export function parseRunnerConfiguration(value:unknown):RunnerConfiguration {
 export function parseRunnerConfiguration(value:unknown):RunnerConfiguration {

+ 2 - 1
src/runner/worker/control.ts

@@ -37,11 +37,12 @@ export class ComputerControls {
     const state=this.state(meta)
     const state=this.state(meta)
     if(state)return {mode:state.mode,controlId:state.id,generation:state.lease?.generation,canResume:!!state.gateway,error:state.error}
     if(state)return {mode:state.mode,controlId:state.id,generation:state.lease?.generation,canResume:!!state.gateway,error:state.error}
     const resource=this.runtime.pool.status(meta.ownerKey).find(item=>item.environmentId===meta.environmentId)
     const resource=this.runtime.pool.status(meta.ownerKey).find(item=>item.environmentId===meta.environmentId)
+    if(this.runtime.provider.fixedCapacity&&(!resource||['free','idle'].includes(resource.status))){const state=await this.runtime.provider.inspect({id:meta.environmentId,ownerKey:meta.ownerKey,imageId:this.runtime.config.imageId});return {mode:state?.running?'idle':'off',generation:resource?.generation??0}}
     return {mode:resource?.status==='active'?'agent':resource?.status==='idle'?'idle':'off',generation:resource?.generation}
     return {mode:resource?.status==='active'?'agent':resource?.status==='idle'?'idle':'off',generation:resource?.generation}
   }
   }
   async frame(meta:ComputerTarget,authorize:()=>void):Promise<ComputerFrame>{
   async frame(meta:ComputerTarget,authorize:()=>void):Promise<ComputerFrame>{
     this.runtime.assertTarget(meta);authorize()
     this.runtime.assertTarget(meta);authorize()
-    const spec=this.runtime.pool.definition(meta.ownerKey,meta.environmentId)
+    const spec=this.runtime.pool.definition(meta.ownerKey,meta.environmentId)??(this.runtime.provider.fixedCapacity?{id:meta.environmentId,ownerKey:meta.ownerKey,imageId:this.runtime.config.imageId}:undefined)
     if(!spec)throw new HttpError(409,'电脑尚未启动','computer_not_running')
     if(!spec)throw new HttpError(409,'电脑尚未启动','computer_not_running')
     const status=await this.status(meta),cached=this.frames.get(meta.environmentId)?.at(-1)
     const status=await this.status(meta),cached=this.frames.get(meta.environmentId)?.at(-1)
     if(cached&&cached.generation===status.generation&&Date.now()-cached.capturedAt<700)return cached
     if(cached&&cached.generation===status.generation&&Date.now()-cached.capturedAt<700)return cached

+ 10 - 3
src/runner/worker/gateway.ts

@@ -11,6 +11,8 @@ import {UNCONFIGURED_COMPUTER_IMAGE} from '../../shared/runner.js'
 import type {RunnerConfiguration} from '../../shared/runner.js'
 import type {RunnerConfiguration} from '../../shared/runner.js'
 import {ContainerComputerProvider,COMPUTER_WORKSPACE,CUA_DRIVER,CUA_SOCKET,type ComputerSpecification} from '../computers/container.js'
 import {ContainerComputerProvider,COMPUTER_WORKSPACE,CUA_DRIVER,CUA_SOCKET,type ComputerSpecification} from '../computers/container.js'
 import {ComputerPool,type ComputerLease} from '../computers/pool.js'
 import {ComputerPool,type ComputerLease} from '../computers/pool.js'
+import {ComposeComputerProvider} from '../computers/compose.js'
+import {COMPOSE_DESKTOP_IMAGE,type DesktopRelay} from '../../shared/composeDesktops.js'
 import {ComputerControls} from './control.js'
 import {ComputerControls} from './control.js'
 import {ComputerPublicProxy} from '../network/computerProxy.js'
 import {ComputerPublicProxy} from '../network/computerProxy.js'
 import {HermesWorkerProcess,type WorkerModel,type WorkerTool,type WorkerFrame} from './process.js'
 import {HermesWorkerProcess,type WorkerModel,type WorkerTool,type WorkerFrame} from './process.js'
@@ -40,12 +42,16 @@ export class ComputerRuntime {
   readonly workers=new Map<string,{environmentId:string;ownerKey:string;process:HermesWorkerProcess}>()
   readonly workers=new Map<string,{environmentId:string;ownerKey:string;process:HermesWorkerProcess}>()
   readonly script:string
   readonly script:string
   readonly proxyScript:string
   readonly proxyScript:string
-  constructor(readonly db:DatabaseSync,config:RunnerConfiguration,readonly home:string,script?:string){
+  constructor(readonly db:DatabaseSync,config:RunnerConfiguration,readonly home:string,script?:string,relay?:DesktopRelay){
     if(!config.computers)throw new HttpError(409,'执行节点尚未配置隔离电脑','computer_unavailable')
     if(!config.computers)throw new HttpError(409,'执行节点尚未配置隔离电脑','computer_unavailable')
     this.config=config.computers
     this.config=config.computers
     this.script=script??join(dirname(fileURLToPath(import.meta.url)),'hermes_worker.py')
     this.script=script??join(dirname(fileURLToPath(import.meta.url)),'hermes_worker.py')
     this.proxyScript=existsSync(join(dirname(this.script),'guest_proxy.py'))?join(dirname(this.script),'guest_proxy.py'):join(dirname(this.script),'../network/guest_proxy.py')
     this.proxyScript=existsSync(join(dirname(this.script),'guest_proxy.py'))?join(dirname(this.script),'guest_proxy.py'):join(dirname(this.script),'../network/guest_proxy.py')
-    this.provider=new ContainerComputerProvider(this.config.runtime,config.runnerId,home)
+    if(this.config.managedBy==='compose'){
+      if(!relay)throw new HttpError(409,'缺少 Compose 桌面连接','compose_desktop_unavailable')
+      this.config.imageId=COMPOSE_DESKTOP_IMAGE;this.config.network='none'
+      this.provider=new ComposeComputerProvider(config.runnerId,home,relay)
+    }else this.provider=new ContainerComputerProvider(this.config.runtime,config.runnerId,home)
     this.pool=new ComputerPool(db,this.provider,{concurrent:this.config.maxConcurrent??2,environments:32,ttlMs:30000})
     this.pool=new ComputerPool(db,this.provider,{concurrent:this.config.maxConcurrent??2,environments:32,ttlMs:30000})
     db.exec('CREATE TABLE IF NOT EXISTS retired_computers(id TEXT PRIMARY KEY,owner_key TEXT NOT NULL,spec TEXT)')
     db.exec('CREATE TABLE IF NOT EXISTS retired_computers(id TEXT PRIMARY KEY,owner_key TEXT NOT NULL,spec TEXT)')
     db.exec('CREATE TABLE IF NOT EXISTS computer_sessions(id TEXT PRIMARY KEY,value TEXT NOT NULL)')
     db.exec('CREATE TABLE IF NOT EXISTS computer_sessions(id TEXT PRIMARY KEY,value TEXT NOT NULL)')
@@ -86,9 +92,10 @@ export class ComputerRuntime {
   private async resolveProfile(profile:string,mode:'resolve'|'resolve-workspace',signal?:AbortSignal){
   private async resolveProfile(profile:string,mode:'resolve'|'resolve-workspace',signal?:AbortSignal){
     const resolver=new HermesWorkerProcess(this.config.python,this.script,{mode,profile,defaultCwd:COMPUTER_WORKSPACE,hermesSource:this.config.hermesSource,hermesHome:this.config.hermesHome})
     const resolver=new HermesWorkerProcess(this.config.python,this.script,{mode,profile,defaultCwd:COMPUTER_WORKSPACE,hermesSource:this.config.hermesSource,hermesHome:this.config.hermesHome})
     const abort=()=>{void resolver.close()};signal?.addEventListener('abort',abort,{once:true});if(signal?.aborted)abort()
     const abort=()=>{void resolver.close()};signal?.addEventListener('abort',abort,{once:true});if(signal?.aborted)abort()
-    try{return await resolver.wait('resolved')}finally{signal?.removeEventListener('abort',abort);await resolver.close()}
+    try{const result=await resolver.wait('resolved');return this.provider.fixedCapacity?{...result,cwd:COMPUTER_WORKSPACE}:result}finally{signal?.removeEventListener('abort',abort);await resolver.close()}
   }
   }
   async desktop(meta:ComputerTarget,profile:string,action:'create'|'start'|'stop'|'recreate'|'remove',authorize:()=>void){
   async desktop(meta:ComputerTarget,profile:string,action:'create'|'start'|'stop'|'recreate'|'remove',authorize:()=>void){
+    if(this.provider.fixedCapacity)throw new HttpError(409,'桌面由 Compose 创建和管理,不能在界面增删或重建','compose_desktop_managed')
     this.assertTarget(meta);authorize()
     this.assertTarget(meta);authorize()
     // Stopping/removing an existing desktop must remain possible even when
     // Stopping/removing an existing desktop must remain possible even when
     // its Profile or model was removed or is temporarily misconfigured.
     // its Profile or model was removed or is temporarily misconfigured.

+ 14 - 2
src/server/app.ts

@@ -1,3 +1,4 @@
+import { nativeMessageFileText } from '../shared/messageFiles.js'
 import { hermesBotRelay } from './hermesBotRelay.js'
 import { hermesBotRelay } from './hermesBotRelay.js'
 import { remoteAgentExports } from './workspaceRemoteAgents.js'
 import { remoteAgentExports } from './workspaceRemoteAgents.js'
 import { randomBytes, createHash } from 'node:crypto'
 import { randomBytes, createHash } from 'node:crypto'
@@ -212,6 +213,7 @@ export function createApplication(options: ApplicationOptions = {}): Application
   const workspaceNodes = new WorkspaceNodes(workspace, config, { url: config.upstream, client: upstream, session: upstreamSession }, pairings.nodeID)
   const workspaceNodes = new WorkspaceNodes(workspace, config, { url: config.upstream, client: upstream, session: upstreamSession }, pairings.nodeID)
   workspaceNodes.sourceAllowed = (owner, nodeId, profile) => auth.canUseSource(owner, nodeId, profile)
   workspaceNodes.sourceAllowed = (owner, nodeId, profile) => auth.canUseSource(owner, nodeId, profile)
   const runners=new RunnerHub(workspace,auth,workspaceNodes.local)
   const runners=new RunnerHub(workspace,auth,workspaceNodes.local)
+  runners.composeDesktops.desktops.push(...(config.composeDesktops??[]))
   const sharedComputers=new SharedComputers(workspace,auth,workspaceNodes,runners)
   const sharedComputers=new SharedComputers(workspace,auth,workspaceNodes,runners)
   const computerControls=new ComputerControlService(workspace,auth,workspaceNodes,runners)
   const computerControls=new ComputerControlService(workspace,auth,workspaceNodes,runners)
   const localVm=new LocalVmService(workspace,auth,workspaceNodes,runners,sharedComputers,config)
   const localVm=new LocalVmService(workspace,auth,workspaceNodes,runners,sharedComputers,config)
@@ -239,11 +241,21 @@ export function createApplication(options: ApplicationOptions = {}): Application
   realtime.broker.onNativeEvent = (owner, profile, storedId, frame) => {
   realtime.broker.onNativeEvent = (owner, profile, storedId, frame) => {
     chatCache?.observe(owner, profile, storedId, frame)
     chatCache?.observe(owner, profile, storedId, frame)
     if (owner.startsWith('device:')) return
     if (owner.startsWith('device:')) return
-    if (!['message.complete', 'tool.complete', 'tool.completed', 'attachment.staged'].includes(frame.type)) return
-    const data = frame.payload ?? {}, text = JSON.stringify(data)
+    if (!['message.complete', 'attachment.staged'].includes(frame.type)) return
+    const data = frame.payload ?? {}, text = frame.type === 'attachment.staged' ? JSON.stringify(data) : nativeMessageFileText(data)
     const messageId = String(data.row_id ?? data.message_id ?? data.id ?? createHash('sha256').update(text).digest('hex'))
     const messageId = String(data.row_id ?? data.message_id ?? data.id ?? createHash('sha256').update(text).digest('hex'))
     void workspaceAssets.archiveText(owner, text, 'local', profile, storedId, messageId, frame.type === 'attachment.staged' ? 'user' : 'agent').catch(() => {})
     void workspaceAssets.archiveText(owner, text, 'local', profile, storedId, messageId, frame.type === 'attachment.staged' ? 'user' : 'agent').catch(() => {})
   }
   }
+  workspace.nativeMessageForFile = (owner, file) => {
+    const message = chatCache?.store.fileSourceMessage(owner, file.profile ?? 'default', file.conversationId ?? '', file.messageId ?? '')
+    if (!message) return undefined
+    return {
+      id: file.messageId!, conversationId: file.conversationId!, seq: 0,
+      role: message.role === 'assistant' ? 'assistant' : message.role === 'user' ? 'user' : 'system',
+      content: nativeMessageFileText(message), reasoning: '', status: 'complete',
+      attachments: [], tools: [], createdAt: file.createdAt,
+    }
+  }
   realtime.broker.onNativeGlobalEvent = (owner, type) => chatCache?.observeGlobal(owner, type)
   realtime.broker.onNativeGlobalEvent = (owner, type) => chatCache?.observeGlobal(owner, type)
   chatCache.onSynchronized = (owner, profile, sessionID) => {
   chatCache.onSynchronized = (owner, profile, sessionID) => {
     realtime.broker.publishOwnerSessionsChanged(owner, 'cache.synced', profile, sessionID)
     realtime.broker.publishOwnerSessionsChanged(owner, 'cache.synced', profile, sessionID)

+ 6 - 0
src/server/chatCache.ts

@@ -501,6 +501,12 @@ export class ChatCacheStore {
       .run(owner, sessionID)
       .run(owner, sessionID)
   }
   }
 
 
+  fileSourceMessage(owner: string, profile: string, sessionID: string, messageID: string): Record<string, unknown> | undefined {
+    const row = this.db.prepare('SELECT data FROM chat_messages WHERE owner=? AND profile=? AND session_id=? AND message_id=?')
+      .get(owner, profile, sessionID, messageID)
+    return row ? JSON.parse(String(row.data)) : undefined
+  }
+
   markListsStale(owner: string): void {
   markListsStale(owner: string): void {
     this.db.prepare("UPDATE chat_snapshots SET sync_state='stale' WHERE owner=? AND kind='list'").run(owner)
     this.db.prepare("UPDATE chat_snapshots SET sync_state='stale' WHERE owner=? AND kind='list'").run(owner)
   }
   }

+ 34 - 0
src/server/composeDesktops.ts

@@ -0,0 +1,34 @@
+import {request} from 'node:http'
+import {z} from 'zod'
+import {HttpError} from './errors.js'
+import type {ComposeDesktop,ComposeDesktopState} from '../shared/composeDesktops.js'
+
+export function parseComposeDesktops(value:string|undefined):ComposeDesktop[]{
+  if(!value?.trim())return []
+  let input:unknown
+  try{input=JSON.parse(value)}catch{throw new Error('HERMES_YAOYAO_COMPOSE_DESKTOPS 必须为有效 JSON')}
+  const parsed=z.array(z.object({id:z.string().uuid(),name:z.string().trim().min(1).max(100),socketPath:z.string().regex(/^\/run\/yaoyao-desktops\/[a-z0-9_-]+\/desktop\.sock$/)}).strict()).min(1).max(32).parse(input)
+  if(new Set(parsed.map(x=>x.id)).size!==parsed.length||new Set(parsed.map(x=>x.socketPath)).size!==parsed.length)throw new Error('Compose 桌面 ID 和连接路径不能重复')
+  return parsed
+}
+
+/** Only deployment-owned Unix sockets are addressable. No Docker daemon access. */
+export class ComposeDesktops {
+  constructor(readonly desktops:ComposeDesktop[]){}
+  async call(id:string,operation:string,body:Record<string,unknown>={}):Promise<any>{
+    const desktop=this.desktops.find(x=>x.id===id)
+    if(!desktop)throw new HttpError(404,'该桌面不在 Compose 配置中','compose_desktop_missing')
+    if(!['health','frame','acquire','renew','release','execute'].includes(operation))throw new HttpError(409,'Compose 管理桌面数量和生命周期','compose_desktop_managed')
+    return new Promise((resolve,reject)=>{
+      const data=JSON.stringify({...body,desktopId:id}),req=request({socketPath:desktop.socketPath,path:`/${operation}`,method:'POST',headers:{'Content-Type':'application/json','Content-Length':Buffer.byteLength(data)},timeout:70000},res=>{
+        const chunks:Buffer[]=[];let size=0
+        res.on('data',chunk=>{size+=chunk.length;if(size>40*1024*1024)req.destroy(new Error('桌面回应过大'));else chunks.push(chunk)})
+        res.on('end',()=>{try{if(res.headers['x-yaoyao-desktop-id']!==id)throw new HttpError(502,'Compose 桌面连接身份不匹配','compose_desktop_mismatch');const value=JSON.parse(Buffer.concat(chunks).toString());if(res.statusCode!==200)throw new HttpError(res.statusCode??502,value.error||'桌面操作失败',value.code||'compose_desktop_error');resolve(value)}catch(error){reject(error)}})
+      })
+      req.on('timeout',()=>req.destroy(new Error('桌面回应超时')))
+      req.on('error',()=>reject(new HttpError(503,`无法连接「${desktop.name}」,请检查对应 Compose 桌面容器`,'compose_desktop_offline')))
+      req.end(data)
+    })
+  }
+  async status():Promise<ComposeDesktopState[]>{return Promise.all(this.desktops.map(async d=>{try{const state=await this.call(d.id,'health');if(state.id!==d.id||state.protocol!==1)throw new Error('身份不匹配');return {id:d.id,name:d.name,online:true,ready:state.ready===true}}catch{return {id:d.id,name:d.name,online:false,ready:false}}}))}
+}

+ 8 - 0
src/server/config.ts

@@ -10,6 +10,8 @@ import {
   type AllowedHostsConfigurationSnapshot,
   type AllowedHostsConfigurationSnapshot,
 } from './allowedHostsConfiguration.js'
 } from './allowedHostsConfiguration.js'
 import type { ChatCacheMode } from './chatCache.js'
 import type { ChatCacheMode } from './chatCache.js'
+import {parseComposeDesktops} from './composeDesktops.js'
+import type {ComposeDesktop} from '../shared/composeDesktops.js'
 export { DEFAULT_APNS_TOPIC } from './apnsConfiguration.js'
 export { DEFAULT_APNS_TOPIC } from './apnsConfiguration.js'
 
 
 export interface APNsProviderConfig {
 export interface APNsProviderConfig {
@@ -42,6 +44,8 @@ export interface ServerConfig {
   insecureLan: boolean
   insecureLan: boolean
   production: boolean
   production: boolean
   superviseDashboard?: boolean
   superviseDashboard?: boolean
+  localVmHost?: 'server' | 'runner'
+  composeDesktops?: ComposeDesktop[]
   releaseSource?: string
   releaseSource?: string
   releaseRoot?: string
   releaseRoot?: string
   allowRemoteUpdate?: boolean
   allowRemoteUpdate?: boolean
@@ -162,6 +166,8 @@ export function loadServerConfig(
   const allowInsecureLan = flag(env.HERMES_YAOYAO_ALLOW_INSECURE_LAN)
   const allowInsecureLan = flag(env.HERMES_YAOYAO_ALLOW_INSECURE_LAN)
   const production = env.NODE_ENV === 'production'
   const production = env.NODE_ENV === 'production'
   const superviseDashboard = flag(env.HERMES_YAOYAO_SUPERVISE_DASHBOARD)
   const superviseDashboard = flag(env.HERMES_YAOYAO_SUPERVISE_DASHBOARD)
+  const localVmHost = env.HERMES_YAOYAO_LOCAL_VM_HOST?.trim() || 'server'
+  if(localVmHost!=='server'&&localVmHost!=='runner')throw new Error('HERMES_YAOYAO_LOCAL_VM_HOST must be server or runner')
   const chatCacheMode = parseChatCacheMode(env.HERMES_YAOYAO_CHAT_CACHE_MODE)
   const chatCacheMode = parseChatCacheMode(env.HERMES_YAOYAO_CHAT_CACHE_MODE)
   const releaseSource = parseReleaseSource(env.HERMES_YAOYAO_RELEASE_SOURCE)
   const releaseSource = parseReleaseSource(env.HERMES_YAOYAO_RELEASE_SOURCE)
   const releaseRoot = resolve(env.HERMES_YAOYAO_RELEASE_ROOT?.trim() || `${homedir()}/.local/share/hermes-yaoyao`)
   const releaseRoot = resolve(env.HERMES_YAOYAO_RELEASE_ROOT?.trim() || `${homedir()}/.local/share/hermes-yaoyao`)
@@ -200,6 +206,8 @@ export function loadServerConfig(
     insecureLan,
     insecureLan,
     production,
     production,
     superviseDashboard,
     superviseDashboard,
+    localVmHost,
+    composeDesktops:parseComposeDesktops(env.HERMES_YAOYAO_COMPOSE_DESKTOPS),
     chatCacheMode,
     chatCacheMode,
     releaseSource,
     releaseSource,
     releaseRoot,
     releaseRoot,

+ 39 - 9
src/server/localVm.ts

@@ -28,16 +28,23 @@ export class LocalVmService {
   private problem?:string
   private problem?:string
   constructor(readonly store:WorkspaceStore,readonly auth:LocalAuthStore,readonly nodes:WorkspaceNodes,
   constructor(readonly store:WorkspaceStore,readonly auth:LocalAuthStore,readonly nodes:WorkspaceNodes,
     readonly hub:RunnerHub,readonly shared:SharedComputers,readonly config:ServerConfig) {
     readonly hub:RunnerHub,readonly shared:SharedComputers,readonly config:ServerConfig) {
-    store.prepareAgent=(owner,agent)=>{const record=this.record();if(record&&this.mode(owner)==='shared')this.shared.attachLocalVm(owner,agent,record.id)}
+    store.prepareAgent=(owner,agent)=>{
+      const record=this.record()
+      if(this.fixed){const parent=agent.createdByAgentId?store.get<WorkspaceAgent>(owner,'agent',agent.createdByAgentId):undefined,desktop=this.config.composeDesktops?.find(d=>d.id===parent?.computerEnvironmentId);if(record&&desktop&&agent.execution==='computer'){if(agent.nodeId!=='local')throw new HttpError(409,'Compose 桌面成员须使用当前 Web 的 Hermes 来源','compose_source_required');this.shared.bindCompose(owner,agent,desktop,record.id,false)}return}
+      if(record&&this.mode(owner)==='shared')this.shared.attachLocalVm(owner,agent,record.id)
+    }
   }
   }
+  private get fixed(){return !!this.config.composeDesktops?.length}
+  private assertManaged(){if(this.fixed)throw new HttpError(409,'桌面由 Compose 创建和管理,数量和镜像不能在界面修改','compose_desktop_managed')}
   allowed(id:string,runnerId:string){
   allowed(id:string,runnerId:string){
     const grant=this.store.get<Grant>('_system','local-vm-grant',id)
     const grant=this.store.get<Grant>('_system','local-vm-grant',id)
     return !!grant&&grant.runnerId===runnerId&&grant.expiresAt>Date.now()&&this.auth.isAdminActive(grant.owner)&&this.auth.pushAuthorizationVersion(grant.owner)===grant.version
     return !!grant&&grant.runnerId===runnerId&&grant.expiresAt>Date.now()&&this.auth.isAdminActive(grant.owner)&&this.auth.pushAuthorizationVersion(grant.owner)===grant.version
   }
   }
-  private mode(owner:string):LocalVmMode { return this.store.get<{mode:LocalVmMode}>(owner,'local-vm-preferences','local')?.mode??'per-bot' }
+  private mode(owner:string):LocalVmMode { return this.fixed?'shared':this.store.get<{mode:LocalVmMode}>(owner,'local-vm-preferences','local')?.mode??'per-bot' }
   private record(){return this.hub.records().find(r=>r.enabled&&r.sourceNodeId==='local'&&r.sourceOwner==='_system')}
   private record(){return this.hub.records().find(r=>r.enabled&&r.sourceNodeId==='local'&&r.sourceOwner==='_system')}
   async start(url:string) {
   async start(url:string) {
     this.url=url
     this.url=url
+    if(this.fixed||this.config.localVmHost==='runner')return
     const stored=this.store.get<{sealed:string}>('_system','local-vm-managed','local')
     const stored=this.store.get<{sealed:string}>('_system','local-vm-managed','local')
     if(!stored||this.managed)return
     if(!stored||this.managed)return
     const config=this.nodes.open<RunnerConfiguration>(stored.sealed)
     const config=this.nodes.open<RunnerConfiguration>(stored.sealed)
@@ -70,6 +77,7 @@ export class LocalVmService {
       if(this.url&&!this.managed)await this.start(this.url)
       if(this.url&&!this.managed)await this.start(this.url)
       return this.record()!
       return this.record()!
     }
     }
+    if(this.config.localVmHost==='runner')throw new HttpError(409,'Docker 版需要先连接运行 Hermes 的执行节点,并启用虚拟桌面。请在本页打开执行节点设置。','local_vm_runner_required')
     this.starting=(async()=>{
     this.starting=(async()=>{
       if(!this.url)throw new HttpError(503,'本机 Web 服务尚未启动','local_vm_unavailable')
       if(!this.url)throw new HttpError(503,'本机 Web 服务尚未启动','local_vm_unavailable')
       const detected=await this.discover()
       const detected=await this.discover()
@@ -98,19 +106,29 @@ export class LocalVmService {
   }
   }
   async status(owner:string):Promise<LocalVmStatus> {
   async status(owner:string):Promise<LocalVmStatus> {
     const record=this.record()
     const record=this.record()
+    if(this.fixed){
+      const desktops=(await this.hub.composeDesktops.status()).map(d=>{const claim=this.store.get<{owner:string}>('_system','compose-desktop-owner',d.id);return {...d,available:!claim||claim.owner===owner}})
+      const runner=record?this.hub.summary(record):undefined,connected=runner?.online&&runner.features.includes('compose-desktops-v1')
+      return {configured:!!connected,executionHost:'runner',runnerName:record?.name,fixedCapacity:true,desktops,daemonUp:true,image:desktops.some(d=>d.ready),mode:'shared',maxInstances:desktops.length,busy:false,...(!connected?{setupRequired:'runner' as const,problem:'Compose 桌面数量已固定。请连接启用 Compose 桌面模式的 Hermes 执行节点。'}:{})}
+    }
+    const executionHost=this.config.localVmHost==='runner'||(record&&!this.store.get('_system','local-vm-managed','local'))?'runner':'server'
     if(record){
     if(record){
       if(this.url&&!this.managed)await this.start(this.url)
       if(this.url&&!this.managed)await this.start(this.url)
-      if(!this.hub.summary(record).online){
+      const summary=this.hub.summary(record)
+      if(!summary.online){
+        if(executionHost==='runner')return {configured:true,executionHost,runnerName:record.name,setupRequired:'runner',daemonUp:false,image:false,mode:this.mode(owner),maxInstances:2,busy:false,problem:`执行节点「${record.name}」尚未连接,请在运行 Hermes 的电脑上启动 Runner。`}
         const detected=await this.discover()
         const detected=await this.discover()
         return {configured:true,...detected,image:false,mode:this.mode(owner),maxInstances:2,busy:false,problem:this.problem??'本机执行环境正在连接,请稍后重新检查'}
         return {configured:true,...detected,image:false,mode:this.mode(owner),maxInstances:2,busy:false,problem:this.problem??'本机执行环境正在连接,请稍后重新检查'}
       }
       }
+      if(!summary.features?.includes('local-vm-v1'))return {configured:true,executionHost,runnerName:record.name,setupRequired:'worker',daemonUp:false,image:false,mode:this.mode(owner),maxInstances:2,busy:false,problem:'执行节点已连接,但未启用虚拟桌面或版本过旧。请启用隔离电脑 Worker 并使用配套版本的 Runner。'}
       const state=await this.hub.localVm(owner,record.id,{op:'status'}) as LocalVmStatus
       const state=await this.hub.localVm(owner,record.id,{op:'status'}) as LocalVmStatus
       const agents=this.store.list<WorkspaceAgent>(owner,'agent'),groups=this.store.list<{id:string;name:string}>(owner,'shared-computer')
       const agents=this.store.list<WorkspaceAgent>(owner,'agent'),groups=this.store.list<{id:string;name:string}>(owner,'shared-computer')
-      return {...state,mode:this.mode(owner),instances:state.instances?.map(instance=>{
+      return {...state,executionHost,runnerName:record.name,mode:this.mode(owner),instances:state.instances?.map(instance=>{
         const agent=agents.find(a=>!a.archived&&(a.computerEnvironmentId??a.id)===instance.id&&a.execution==='computer')
         const agent=agents.find(a=>!a.archived&&(a.computerEnvironmentId??a.id)===instance.id&&a.execution==='computer')
         return {...instance,name:agent?.computerEnvironmentName??agent?.name??groups.find(g=>g.id===instance.id)?.name??'保留的虚拟机',orphaned:!agent}
         return {...instance,name:agent?.computerEnvironmentName??agent?.name??groups.find(g=>g.id===instance.id)?.name??'保留的虚拟机',orphaned:!agent}
       })}
       })}
     }
     }
+    if(executionHost==='runner')return {configured:false,executionHost,setupRequired:'runner',daemonUp:false,image:false,mode:this.mode(owner),maxInstances:2,busy:false,problem:'Docker 版通过执行节点提供虚拟桌面。请在运行 Hermes 的电脑上连接执行节点。'}
     const detected=await this.discover()
     const detected=await this.discover()
     return {configured:false,...detected,image:false,mode:this.mode(owner),maxInstances:2,busy:false,problem:this.problem}
     return {configured:false,...detected,image:false,mode:this.mode(owner),maxInstances:2,busy:false,problem:this.problem}
   }
   }
@@ -118,11 +136,13 @@ export class LocalVmService {
     const router=new Router()
     const router=new Router()
     router.get('/api/app/admin/local-vm',async ctx=>{ctx.body=await this.status(this.auth.requireAdmin(ctx).id)})
     router.get('/api/app/admin/local-vm',async ctx=>{ctx.body=await this.status(this.auth.requireAdmin(ctx).id)})
     router.post('/api/app/admin/local-vm/prepare',async ctx=>{
     router.post('/api/app/admin/local-vm/prepare',async ctx=>{
+      this.auth.requireAdmin(ctx);this.assertManaged()
       const actor=this.auth.requireAdmin(ctx),body=parse(z.object({requestId:z.string().uuid()}).strict(),(ctx.request as any).body)
       const actor=this.auth.requireAdmin(ctx),body=parse(z.object({requestId:z.string().uuid()}).strict(),(ctx.request as any).body)
       const record=await this.ensure(actor.id);this.grant(actor.id,body.requestId,record.id)
       const record=await this.ensure(actor.id);this.grant(actor.id,body.requestId,record.id)
       ctx.body=await this.hub.localVm(actor.id,record.id,{op:'prepare',id:body.requestId})
       ctx.body=await this.hub.localVm(actor.id,record.id,{op:'prepare',id:body.requestId})
     })
     })
     router.put('/api/app/admin/local-vm/policy',async ctx=>{
     router.put('/api/app/admin/local-vm/policy',async ctx=>{
+      this.auth.requireAdmin(ctx);this.assertManaged()
       const owner=this.auth.requireAdmin(ctx).id,body=parse(z.object({requestId:z.string().uuid(),mode:z.enum(['shared','per-bot']),maxInstances:z.number().int().min(1).max(4)}).strict(),(ctx.request as any).body)
       const owner=this.auth.requireAdmin(ctx).id,body=parse(z.object({requestId:z.string().uuid(),mode:z.enum(['shared','per-bot']),maxInstances:z.number().int().min(1).max(4)}).strict(),(ctx.request as any).body)
       const record=await this.ensure(owner);this.shared.assertLocalVmIdle(owner)
       const record=await this.ensure(owner);this.shared.assertLocalVmIdle(owner)
       this.grant(owner,body.requestId,record.id)
       this.grant(owner,body.requestId,record.id)
@@ -132,6 +152,7 @@ export class LocalVmService {
       ctx.body=await this.status(owner)
       ctx.body=await this.status(owner)
     })
     })
     router.post('/api/app/admin/local-vm/instances/:id/:action',async ctx=>{
     router.post('/api/app/admin/local-vm/instances/:id/:action',async ctx=>{
+      this.auth.requireAdmin(ctx);this.assertManaged()
       const owner=this.auth.requireAdmin(ctx).id,id=parse(z.string().uuid(),ctx.params.id),action=parse(z.enum(['stop','remove']),ctx.params.action)
       const owner=this.auth.requireAdmin(ctx).id,id=parse(z.string().uuid(),ctx.params.id),action=parse(z.enum(['stop','remove']),ctx.params.action)
       const body=parse(z.object({requestId:z.string().uuid()}).strict(),(ctx.request as any).body),record=this.record()
       const body=parse(z.object({requestId:z.string().uuid()}).strict(),(ctx.request as any).body),record=this.record()
       if(!record)throw new HttpError(409,'本地虚拟机尚未配置','local_vm_unavailable')
       if(!record)throw new HttpError(409,'本地虚拟机尚未配置','local_vm_unavailable')
@@ -141,23 +162,32 @@ export class LocalVmService {
     router.get('/api/app/agents/:id/local-vm',async ctx=>{
     router.get('/api/app/agents/:id/local-vm',async ctx=>{
       const owner=this.auth.require(ctx).id,agent=this.store.require<WorkspaceAgent>(owner,'agent',ctx.params.id)
       const owner=this.auth.require(ctx).id,agent=this.store.require<WorkspaceAgent>(owner,'agent',ctx.params.id)
       this.nodes.requireSource(owner,agent)
       this.nodes.requireSource(owner,agent)
-      if(agent.execution!=='computer'){ctx.body={enabled:false,agent};return}
-      try { ctx.body={enabled:true,agent,...await this.hub.computer(owner,agent,'detail',{},()=>this.nodes.requireSource(owner,agent)),mode:agent.computerEnvironmentId?'shared':'per-bot'} }
-      catch(error){ctx.body={enabled:true,agent,container:'missing',ready:false,image:false,problem:error instanceof Error?error.message:'本地虚拟机不可用'}}
+      const fixed=this.fixed?{fixedCapacity:true,desktopId:agent.computerEnvironmentId,desktops:(await this.status(owner)).desktops}:{}
+      if(agent.execution!=='computer'||(this.fixed&&!agent.computerEnvironmentId)){ctx.body={enabled:false,agent,...fixed};return}
+      try { ctx.body={enabled:true,agent,...await this.hub.computer(owner,agent,'detail',{},()=>this.nodes.requireSource(owner,agent)),mode:agent.computerEnvironmentId?'shared':'per-bot',...fixed} }
+      catch(error){ctx.body={enabled:true,agent,container:'missing',ready:false,image:false,problem:error instanceof Error?error.message:'本地虚拟机不可用',...fixed}}
     })
     })
     router.put('/api/app/agents/:id/local-vm',ctx=>{
     router.put('/api/app/agents/:id/local-vm',ctx=>{
-      const owner=this.auth.require(ctx).id,body=parse(z.object({enabled:z.boolean()}).strict(),(ctx.request as any).body)
+      const owner=this.auth.require(ctx).id,body=parse(z.object({enabled:z.boolean(),desktopId:z.string().uuid().optional()}).strict(),(ctx.request as any).body)
       const agent=this.store.require<WorkspaceAgent>(owner,'agent',ctx.params.id);this.nodes.requireSource(owner,agent)
       const agent=this.store.require<WorkspaceAgent>(owner,'agent',ctx.params.id);this.nodes.requireSource(owner,agent)
       if(agent.remoteAgentId||agent.temporaryGoalId)throw new HttpError(409,'请在该 Agent 所属的电脑上设置虚拟机','local_vm_remote')
       if(agent.remoteAgentId||agent.temporaryGoalId)throw new HttpError(409,'请在该 Agent 所属的电脑上设置虚拟机','local_vm_remote')
       this.shared.assertLocalVmIdle(owner,[agent.id])
       this.shared.assertLocalVmIdle(owner,[agent.id])
+      if(this.fixed&&body.enabled){
+        if(agent.nodeId!=='local')throw new HttpError(409,'Compose 桌面成员须使用当前 Web 的 Hermes 来源','compose_source_required')
+        const desktop=this.config.composeDesktops!.find(d=>d.id===body.desktopId),record=this.record()
+        if(!desktop)throw new HttpError(400,'请选择 Compose 中已有的共享桌面','compose_desktop_required')
+        if(!record||!this.hub.summary(record).features.includes('compose-desktops-v1'))throw new HttpError(409,'请连接启用 Compose 桌面模式的执行节点','compose_runner_required')
+        ctx.body=this.store.atomic(()=>{this.shared.bindCompose(owner,agent,desktop,record.id);return {agent:this.store.agentSummary(agent)}});return
+      }
       ctx.body=this.store.atomic(()=>{
       ctx.body=this.store.atomic(()=>{
         if(!body.enabled)this.shared.detachLocalVm(owner,agent)
         if(!body.enabled)this.shared.detachLocalVm(owner,agent)
         this.store.updateAgent(owner,agent.id,{execution:body.enabled?'computer':'profile'})
         this.store.updateAgent(owner,agent.id,{execution:body.enabled?'computer':'profile'})
-        if(body.enabled&&this.mode(owner)==='shared'){const record=this.record();if(record)this.shared.setLocalVmMode(owner,'shared',record.id)}
+        if(body.enabled&&!this.fixed&&this.mode(owner)==='shared'){const record=this.record();if(record)this.shared.setLocalVmMode(owner,'shared',record.id)}
         return {agent:this.store.agentSummary(this.store.require<WorkspaceAgent>(owner,'agent',agent.id))}
         return {agent:this.store.agentSummary(this.store.require<WorkspaceAgent>(owner,'agent',agent.id))}
       })
       })
     })
     })
     router.post('/api/app/agents/:id/local-vm/:action',async ctx=>{
     router.post('/api/app/agents/:id/local-vm/:action',async ctx=>{
+      this.auth.require(ctx);this.assertManaged()
       const owner=this.auth.require(ctx).id,action=parse(z.enum(['create','start','stop','recreate','remove']),ctx.params.action)
       const owner=this.auth.require(ctx).id,action=parse(z.enum(['create','start','stop','recreate','remove']),ctx.params.action)
       const agent=this.store.require<WorkspaceAgent>(owner,'agent',ctx.params.id)
       const agent=this.store.require<WorkspaceAgent>(owner,'agent',ctx.params.id)
       if(agent.temporaryGoalId)throw new HttpError(409,'临时助手的虚拟机由当前任务管理','helper_task_bound')
       if(agent.temporaryGoalId)throw new HttpError(409,'临时助手的虚拟机由当前任务管理','helper_task_bound')

+ 32 - 6
src/server/runnerHub.ts

@@ -1,6 +1,9 @@
 import { createHash, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto'
 import { createHash, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto'
 import Router from '@koa/router'
 import Router from '@koa/router'
 import type Koa from 'koa'
 import type Koa from 'koa'
+import {createReadStream,existsSync} from 'node:fs'
+import {dirname,resolve} from 'node:path'
+import {fileURLToPath} from 'node:url'
 import { z } from 'zod'
 import { z } from 'zod'
 import { HttpError } from './errors.js'
 import { HttpError } from './errors.js'
 import { parse, type WorkspaceStore } from './workspaceStore.js'
 import { parse, type WorkspaceStore } from './workspaceStore.js'
@@ -9,16 +12,19 @@ import type { GatewayFrame, GatewayTarget } from './workspaceGateway.js'
 import type { UpstreamRequestOptions, UpstreamResponse } from './upstream.js'
 import type { UpstreamRequestOptions, UpstreamResponse } from './upstream.js'
 import type { LeaseInput, WorkspaceToolLease } from './workspaceToolLease.js'
 import type { LeaseInput, WorkspaceToolLease } from './workspaceToolLease.js'
 import { RUNNER_PROTOCOL, type RunnerCommand, type RunnerRecord } from '../shared/runner.js'
 import { RUNNER_PROTOCOL, type RunnerCommand, type RunnerRecord } from '../shared/runner.js'
+import {ComposeDesktops} from './composeDesktops.js'
 
 
 const hash = (value: string) => createHash('sha256').update(value).digest('hex')
 const hash = (value: string) => createHash('sha256').update(value).digest('hex')
+const runnerBundle=()=>[resolve(dirname(fileURLToPath(import.meta.url)),'runner-bundle.tar.gz'),resolve(dirname(fileURLToPath(import.meta.url)),'../../runner-bundle.tar.gz')].find(existsSync)
 const input = z.object({ name:z.string().trim().min(1).max(100),sourceNodeId:z.string().min(1).max(100).default('local'),
 const input = z.object({ name:z.string().trim().min(1).max(100),sourceNodeId:z.string().min(1).max(100).default('local'),
   allowedProfiles:z.array(z.string().min(1).max(100)).min(1).max(256) }).strict()
   allowedProfiles:z.array(z.string().min(1).max(100)).min(1).max(256) }).strict()
 interface Pending { command:RunnerCommand; resolve(value:any):void; reject(error:Error):void; timer:ReturnType<typeof setTimeout>; nextDelivery:number; valid():boolean }
 interface Pending { command:RunnerCommand; resolve(value:any):void; reject(error:Error):void; timer:ReturnType<typeof setTimeout>; nextDelivery:number; valid():boolean }
-interface GatewayConnection { runnerId:string;cleanupOnly?:boolean;publishArtifact?:(name:string,bytes:Buffer)=>Promise<unknown>; valid():boolean; onEvent(frame:GatewayFrame):void; onDisconnect():void }
+interface GatewayConnection { runnerId:string;computer?:{environmentId:string;ownerKey:string;agentId:string};cleanupOnly?:boolean;publishArtifact?:(name:string,bytes:Buffer)=>Promise<unknown>; valid():boolean; onEvent(frame:GatewayFrame):void; onDisconnect():void }
 interface Lease { runnerId:string; input:LeaseInput; calls:Map<string,{fingerprint:string;result:Promise<unknown>}> }
 interface Lease { runnerId:string; input:LeaseInput; calls:Map<string,{fingerprint:string;result:Promise<unknown>}> }
 
 
 /** Outbound-only machine transport. Browser auth and machine auth remain separate. */
 /** Outbound-only machine transport. Browser auth and machine auth remain separate. */
 export class RunnerHub {
 export class RunnerHub {
+  composeDesktops=new ComposeDesktops([])
   get idleForUpdate(): boolean { return this.localVmActivity.size === 0 && [...this.pending.values()].every(commands => commands.size === 0) && [...this.artifacts.values()].every(upload => upload.result !== undefined) }
   get idleForUpdate(): boolean { return this.localVmActivity.size === 0 && [...this.pending.values()].every(commands => commands.size === 0) && [...this.artifacts.values()].every(upload => upload.result !== undefined) }
   private localVmActivity = new Map<string, { owner: string; runnerId: string }>()
   private localVmActivity = new Map<string, { owner: string; runnerId: string }>()
   private localVmChecks = new Set<string>()
   private localVmChecks = new Set<string>()
@@ -109,6 +115,11 @@ export class RunnerHub {
       if(!this.auth.canUseSource(owner,sourceNodeId,profile)||!record.allowedProfiles.includes(profile))throw new HttpError(403,'执行节点未授权这个基础 Profile','runner_profile_forbidden')
       if(!this.auth.canUseSource(owner,sourceNodeId,profile)||!record.allowedProfiles.includes(profile))throw new HttpError(403,'执行节点未授权这个基础 Profile','runner_profile_forbidden')
     }
     }
     const requireComputer=()=>{
     const requireComputer=()=>{
+      if(computer&&this.composeDesktops.desktops.length){
+        if(!this.online.get(record.id)?.features.includes('compose-desktops-v1'))throw new HttpError(409,'当前部署需要 Compose 桌面执行节点','compose_runner_required')
+        const claim=this.store.get<{owner:string;runnerId:string}>('_system','compose-desktop-owner',computer.environmentId)
+        if(!this.composeDesktops.desktops.some(d=>d.id===computer.environmentId)||claim?.owner!==owner||claim.runnerId!==record.id)throw new HttpError(409,'请先为 Agent 选择已有 Compose 共享桌面','compose_desktop_required')
+      }
       if(computer&&!this.online.get(record.id)?.features.includes('computer-worker-v1'))throw new HttpError(409,'执行节点未提供隔离 Worker 能力,请检查配置或更新 Runner','computer_unavailable')
       if(computer&&!this.online.get(record.id)?.features.includes('computer-worker-v1'))throw new HttpError(409,'执行节点未提供隔离 Worker 能力,请检查配置或更新 Runner','computer_unavailable')
       if(computer&&computer.environmentId!==computer.agentId&&!this.online.get(record.id)?.features.includes('shared-computer-v1'))throw new HttpError(409,'执行节点不支持共享电脑,请更新 Runner','shared_computer_unavailable')
       if(computer&&computer.environmentId!==computer.agentId&&!this.online.get(record.id)?.features.includes('shared-computer-v1'))throw new HttpError(409,'执行节点不支持共享电脑,请更新 Runner','shared_computer_unavailable')
     }
     }
@@ -134,7 +145,7 @@ export class RunnerHub {
           if(computer&&!scope)throw new HttpError(403,'隔离执行缺少任务授权','computer_scope_required')
           if(computer&&!scope)throw new HttpError(403,'隔离执行缺少任务授权','computer_scope_required')
           const version=this.auth.pushAuthorizationVersion(owner)
           const version=this.auth.pushAuthorizationVersion(owner)
           const valid=()=>{try{scope?.authorize();return (scope?.cleanupOnly||(this.auth.isUserActive(owner)&&this.auth.pushAuthorizationVersion(owner)===version))&&this.store.get<RunnerRecord>('_system','runner',record.id)?.enabled===true}catch{return false}}
           const valid=()=>{try{scope?.authorize();return (scope?.cleanupOnly||(this.auth.isUserActive(owner)&&this.auth.pushAuthorizationVersion(owner)===version))&&this.store.get<RunnerRecord>('_system','runner',record.id)?.enabled===true}catch{return false}}
-          const id=randomUUID();this.connections.set(id,{runnerId:record.id,valid,onEvent,onDisconnect,publishArtifact:scope?.publishArtifact,cleanupOnly:scope?.cleanupOnly})
+          const id=randomUUID();this.connections.set(id,{runnerId:record.id,computer,valid,onEvent,onDisconnect,publishArtifact:scope?.publishArtifact,cleanupOnly:scope?.cleanupOnly})
           try {await this.request(record.id,'gateway.open',{connectionId:id,computer,workId:scope?.workId,cleanupOnly:scope?.cleanupOnly})} catch(error){this.connections.delete(id);void this.request(record.id,'gateway.close',{connectionId:id}).catch(()=>{});throw error}
           try {await this.request(record.id,'gateway.open',{connectionId:id,computer,workId:scope?.workId,cleanupOnly:scope?.cleanupOnly})} catch(error){this.connections.delete(id);void this.request(record.id,'gateway.close',{connectionId:id}).catch(()=>{});throw error}
           let closed=false
           let closed=false
           return {rpc:async(method,params)=>{
           return {rpc:async(method,params)=>{
@@ -168,6 +179,7 @@ export class RunnerHub {
   computerRunner(owner:string,agent:import('../shared/workspace.js').WorkspaceAgent){
   computerRunner(owner:string,agent:import('../shared/workspace.js').WorkspaceAgent){
     const record=this.records().find(record=>record.enabled&&record.sourceNodeId===agent.nodeId&&(record.sourceOwner==='_system'||record.sourceOwner===owner))
     const record=this.records().find(record=>record.enabled&&record.sourceNodeId===agent.nodeId&&(record.sourceOwner==='_system'||record.sourceOwner===owner))
     if(!record||!this.online.get(record.id)?.features.includes('computer-control-v1'))throw new HttpError(409,'执行节点不支持电脑查看与控制,请更新 Runner','computer_control_unavailable')
     if(!record||!this.online.get(record.id)?.features.includes('computer-control-v1'))throw new HttpError(409,'执行节点不支持电脑查看与控制,请更新 Runner','computer_control_unavailable')
+    if(this.composeDesktops.desktops.length&&!this.online.get(record.id)?.features.includes('compose-desktops-v1'))throw new HttpError(409,'当前部署需要 Compose 桌面执行节点','compose_runner_required')
     if(!record.allowedProfiles.includes(agent.profile)||!this.auth.canUseSource(owner,agent.nodeId,agent.profile))throw new HttpError(403,'电脑 Profile 未授权','computer_profile_forbidden')
     if(!record.allowedProfiles.includes(agent.profile)||!this.auth.canUseSource(owner,agent.nodeId,agent.profile))throw new HttpError(403,'电脑 Profile 未授权','computer_profile_forbidden')
     return record
     return record
   }
   }
@@ -190,14 +202,15 @@ export class RunnerHub {
   }
   }
   adminRouter():Router {
   adminRouter():Router {
     const router=new Router()
     const router=new Router()
-    router.get('/api/app/admin/runners',ctx=>{const actor=this.auth.requireAdmin(ctx);ctx.body={protocol:RUNNER_PROTOCOL,runners:this.records().map(r=>this.summary(r)),sources:[{id:'local',name:'本地来源'},...this.store.list<import('./workspaceGateway.js').WorkspaceNode>(actor.id,'node').filter(n=>n.transport!=='paired-web').map(n=>({id:n.id,name:n.name}))]}})
+    router.get('/api/app/admin/runners',ctx=>{const actor=this.auth.requireAdmin(ctx);ctx.body={protocol:RUNNER_PROTOCOL,fixedDesktops:this.composeDesktops.desktops.length>0,bundleAvailable:!!runnerBundle(),runners:this.records().map(r=>this.summary(r)),sources:[{id:'local',name:'本地来源'},...this.store.list<import('./workspaceGateway.js').WorkspaceNode>(actor.id,'node').filter(n=>n.transport!=='paired-web').map(n=>({id:n.id,name:n.name}))]}})
+    router.get('/api/app/admin/runners/bundle',ctx=>{this.auth.requireAdmin(ctx);const path=runnerBundle();if(!path)throw new HttpError(404,'当前服务未打包执行节点程序,请使用配套 App 或从源码构建 Runner','runner_bundle_missing');ctx.set('Cache-Control','no-store');ctx.attachment('yaoyao-runner.tar.gz');ctx.type='application/gzip';ctx.body=createReadStream(path)})
     router.post('/api/app/admin/runners',ctx=>{const actor=this.auth.requireAdmin(ctx);ctx.body=this.enroll(actor.id,(ctx.request as any).body);ctx.status=201})
     router.post('/api/app/admin/runners',ctx=>{const actor=this.auth.requireAdmin(ctx);ctx.body=this.enroll(actor.id,(ctx.request as any).body);ctx.status=201})
     router.delete('/api/app/admin/runners/:id',ctx=>{this.auth.requireAdmin(ctx);this.remove(ctx.params.id);ctx.body={ok:true}})
     router.delete('/api/app/admin/runners/:id',ctx=>{this.auth.requireAdmin(ctx);this.remove(ctx.params.id);ctx.body={ok:true}})
     return router
     return router
   }
   }
   middleware():Koa.Middleware {
   middleware():Koa.Middleware {
     return async(ctx,next)=>{
     return async(ctx,next)=>{
-      const match=/^\/api\/runner\/v1\/([0-9a-f-]{36})\/(poll|admit|result|event|tool|check|artifact|control-check|local-vm-check)$/.exec(ctx.path)
+      const match=/^\/api\/runner\/v1\/([0-9a-f-]{36})\/(poll|admit|result|event|tool|check|artifact|control-check|local-vm-check|desktop)$/.exec(ctx.path)
       if(!match)return next()
       if(!match)return next()
       const record=this.store.get<RunnerRecord>('_system','runner',match[1]!),token=ctx.get('authorization').replace(/^Bearer /,'')
       const record=this.store.get<RunnerRecord>('_system','runner',match[1]!),token=ctx.get('authorization').replace(/^Bearer /,'')
       if(ctx.get('origin')||!record?.enabled||!ctx.get('authorization').startsWith('Bearer ')||!timingSafeEqual(Buffer.from(record.tokenHash),Buffer.from(hash(token))))
       if(ctx.get('origin')||!record?.enabled||!ctx.get('authorization').startsWith('Bearer ')||!timingSafeEqual(Buffer.from(record.tokenHash),Buffer.from(hash(token))))
@@ -214,7 +227,7 @@ export class RunnerHub {
         retired.add(previous.instance);this.retired.set(record.id,retired);this.disconnect(record.id);previous=undefined
         retired.add(previous.instance);this.retired.set(record.id,retired);this.disconnect(record.id);previous=undefined
       }
       }
       if(match[2]!=='poll'&&ctx.get('x-runner-epoch')!==previous?.epoch)throw new HttpError(409,'执行连接代次已改变','runner_epoch_changed')
       if(match[2]!=='poll'&&ctx.get('x-runner-epoch')!==previous?.epoch)throw new HttpError(409,'执行连接代次已改变','runner_epoch_changed')
-      const state=this.online.get(record.id)??{instance,seen:Date.now(),features:[],epoch:`${this.epoch}:${randomUUID()}`};state.seen=Date.now();if(ctx.get('x-runner-features'))state.features=ctx.get('x-runner-features').split(',').filter(value=>['computer-worker-v1','artifact-chunks-v1','helper-retirement-v1','computer-control-v1','shared-computer-v1','local-vm-v1','image-ready-v1'].includes(value));this.online.set(record.id,state)
+      const state=this.online.get(record.id)??{instance,seen:Date.now(),features:[],epoch:`${this.epoch}:${randomUUID()}`};state.seen=Date.now();if(ctx.get('x-runner-features'))state.features=ctx.get('x-runner-features').split(',').filter(value=>['computer-worker-v1','artifact-chunks-v1','helper-retirement-v1','computer-control-v1','shared-computer-v1','local-vm-v1','image-ready-v1','compose-desktops-v1'].includes(value));this.online.set(record.id,state)
       ctx.set('Cache-Control','no-store')
       ctx.set('Cache-Control','no-store')
       if(match[2]==='poll') {
       if(match[2]==='poll') {
         if(ctx.method!=='GET')throw new HttpError(405,'仅允许 GET','method_not_allowed')
         if(ctx.method!=='GET')throw new HttpError(405,'仅允许 GET','method_not_allowed')
@@ -231,10 +244,23 @@ export class RunnerHub {
       }
       }
       if(ctx.method!=='POST')throw new HttpError(405,'仅允许 POST','method_not_allowed')
       if(ctx.method!=='POST')throw new HttpError(405,'仅允许 POST','method_not_allowed')
       let size=0;const chunks:Buffer[]=[]
       let size=0;const chunks:Buffer[]=[]
-      for await(const chunk of ctx.req){size+=chunk.length;if(size>16*1024*1024)throw new HttpError(413,'执行节点响应过大','runner_payload_limit');chunks.push(Buffer.from(chunk))}
+      for await(const chunk of ctx.req){size+=chunk.length;if(size>(match[2]==='desktop'?40:16)*1024*1024)throw new HttpError(413,'执行节点响应过大','runner_payload_limit');chunks.push(Buffer.from(chunk))}
       let body:any
       let body:any
       try {body=JSON.parse(Buffer.concat(chunks).toString())}catch{throw new HttpError(400,'JSON 无效','invalid_json')}
       try {body=JSON.parse(Buffer.concat(chunks).toString())}catch{throw new HttpError(400,'JSON 无效','invalid_json')}
       if(!body||typeof body!=='object'||Array.isArray(body))throw new HttpError(400,'请求必须是对象','invalid_json')
       if(!body||typeof body!=='object'||Array.isArray(body))throw new HttpError(400,'请求必须是对象','invalid_json')
+      if(match[2]==='desktop'){
+        if(record.sourceNodeId!=='local'||record.sourceOwner!=='_system'||!state.features.includes('compose-desktops-v1'))throw new HttpError(403,'该节点不能访问 Compose 桌面','compose_desktop_forbidden')
+        const {id,operation,ownerKey,...payload}=parse(z.object({id:z.string(),operation:z.enum(['list','health','frame','acquire','renew','release','execute']),ownerKey:z.string().optional()}).passthrough(),body)
+        if(operation==='list'){ctx.body=await this.composeDesktops.status();return}
+        const claim=this.store.get<{owner:string;runnerId:string}>('_system','compose-desktop-owner',id)
+        if(!claim||claim.runnerId!==record.id||hash(claim.owner)!==ownerKey)throw new HttpError(403,'没有该共享桌面的使用权限','compose_desktop_forbidden')
+        const valid=()=>this.auth.isUserActive(claim.owner)&&this.store.list<import('../shared/workspace.js').WorkspaceAgent>(claim.owner,'agent').some(a=>!a.archived&&a.computerEnvironmentId===id&&this.auth.canUseSource(claim.owner,a.nodeId,a.profile))
+        const active=()=>[...this.connections.values()].some(c=>c.runnerId===record.id&&c.computer?.environmentId===id&&c.computer.ownerKey===ownerKey&&c.valid())||this.store.list<any>('_system','computer-control').some(g=>g.owner===claim.owner&&g.runnerId===record.id&&g.environmentId===id&&this.controlAllowed(g.id,record.id))
+        if(operation!=='release'&&(!valid()||(!['health','frame'].includes(operation)&&!active())))throw new HttpError(403,'桌面操作缺少当前任务或接管授权','compose_desktop_forbidden')
+        const result=await this.composeDesktops.call(id,operation,{...payload,owner:ownerKey})
+        if(operation==='acquire'&&(!valid()||!active())){await this.composeDesktops.call(id,'release',{...result,cancel:true}).catch(()=>{});throw new HttpError(410,'桌面操作已取消','computer_control_expired')}
+        ctx.body=result;return
+      }
       if(match[2]==='local-vm-check'){ctx.body={allowed:typeof body.id==='string'&&this.localVmAllowed(body.id,record.id)};return}
       if(match[2]==='local-vm-check'){ctx.body={allowed:typeof body.id==='string'&&this.localVmAllowed(body.id,record.id)};return}
       if(match[2]==='control-check'){ctx.body={allowed:typeof body.controlId==='string'&&this.controlAllowed(body.controlId,record.id)};return}
       if(match[2]==='control-check'){ctx.body={allowed:typeof body.controlId==='string'&&this.controlAllowed(body.controlId,record.id)};return}
       if(match[2]==='artifact'){
       if(match[2]==='artifact'){

+ 14 - 2
src/server/sharedComputers.ts

@@ -8,11 +8,11 @@ import {HttpError} from './errors.js'
 import type {WorkspaceNodes} from './workspaceGateway.js'
 import type {WorkspaceNodes} from './workspaceGateway.js'
 import type {RunnerHub} from './runnerHub.js'
 import type {RunnerHub} from './runnerHub.js'
 import type {LocalAuthStore} from './localAuth.js'
 import type {LocalAuthStore} from './localAuth.js'
-export interface SharedComputer {managedLocalVm?:boolean;id:string;name:string;memberIds:string[];nodeId:string;profile:string;runnerId:string;archived:boolean;createdAt:number}
+export interface SharedComputer {managedCompose?:boolean;managedLocalVm?:boolean;id:string;name:string;memberIds:string[];nodeId:string;profile:string;runnerId:string;archived:boolean;createdAt:number}
 export function requireSharedComputer(store:WorkspaceStore,owner:string,agent:{id?:string;nodeId:string;profile:string;computerEnvironmentId?:string}){
 export function requireSharedComputer(store:WorkspaceStore,owner:string,agent:{id?:string;nodeId:string;profile:string;computerEnvironmentId?:string}){
   if(!agent.computerEnvironmentId)return
   if(!agent.computerEnvironmentId)return
   const shared=store.require<SharedComputer>(owner,'shared-computer',agent.computerEnvironmentId)
   const shared=store.require<SharedComputer>(owner,'shared-computer',agent.computerEnvironmentId)
-  if(shared.archived||!agent.id||!shared.memberIds.includes(agent.id)||shared.nodeId!==agent.nodeId||shared.profile!==agent.profile)throw new HttpError(403,'当前成员没有这台共享电脑的授权','shared_computer_forbidden')
+  if(shared.archived||!agent.id||!shared.memberIds.includes(agent.id)||shared.nodeId!==agent.nodeId||(!shared.managedCompose&&shared.profile!==agent.profile))throw new HttpError(403,'当前成员没有这台共享电脑的授权','shared_computer_forbidden')
 }
 }
 export class SharedComputers {
 export class SharedComputers {
   constructor(readonly store:WorkspaceStore,readonly auth:LocalAuthStore,readonly nodes:WorkspaceNodes,readonly hub:RunnerHub){}
   constructor(readonly store:WorkspaceStore,readonly auth:LocalAuthStore,readonly nodes:WorkspaceNodes,readonly hub:RunnerHub){}
@@ -28,6 +28,18 @@ export class SharedComputers {
   }
   }
   private localVmAgents(owner:string){return this.store.list<WorkspaceAgent>(owner,'agent').filter(a=>a.nodeId==='local'&&!a.archived&&!a.remoteAgentId&&!a.temporaryGoalId&&(a.execution==='computer'||!!a.computerEnvironmentId))}
   private localVmAgents(owner:string){return this.store.list<WorkspaceAgent>(owner,'agent').filter(a=>a.nodeId==='local'&&!a.archived&&!a.remoteAgentId&&!a.temporaryGoalId&&(a.execution==='computer'||!!a.computerEnvironmentId))}
   assertLocalVmIdle(owner:string,ids?:string[]){this.idle(owner,ids??this.localVmAgents(owner).map(a=>a.id))}
   assertLocalVmIdle(owner:string,ids?:string[]){this.idle(owner,ids??this.localVmAgents(owner).map(a=>a.id))}
+  bindCompose(owner:string,agent:WorkspaceAgent,desktop:{id:string;name:string},runnerId:string,persist=true){
+    this.idle(owner,[agent.id])
+    const claim=this.store.get<{owner:string;runnerId:string}>('_system','compose-desktop-owner',desktop.id)
+    if(claim&&(claim.owner!==owner||claim.runnerId!==runnerId))throw new HttpError(403,'这台共享桌面已分配给其他账号或执行节点','compose_desktop_forbidden')
+    if(agent.computerEnvironmentId&&agent.computerEnvironmentId!==desktop.id)this.detachLocalVm(owner,agent)
+    const group=this.store.get<SharedComputer>(owner,'shared-computer',desktop.id)??{id:desktop.id,name:desktop.name,nodeId:'local',profile:'*',runnerId,memberIds:[],archived:false,createdAt:Date.now(),managedCompose:true}
+    group.archived=false;if(!group.memberIds.includes(agent.id))group.memberIds.push(agent.id)
+    this.store.put('_system','compose-desktop-owner',desktop.id,{owner,runnerId})
+    this.store.put(owner,'shared-computer',group.id,group)
+    agent.execution='computer';agent.computerEnvironmentId=desktop.id;agent.computerEnvironmentName=desktop.name
+    if(persist){agent.revision++;agent.updatedAt=Date.now();this.store.put(owner,'agent',agent.id,agent);this.store.event(owner,'agent.changed',agent)}
+  }
   attachLocalVm(owner:string,agent:WorkspaceAgent,runnerId:string){
   attachLocalVm(owner:string,agent:WorkspaceAgent,runnerId:string){
     if(agent.nodeId!=='local'||agent.execution!=='computer'||agent.temporaryGoalId||agent.remoteAgentId||agent.computerEnvironmentId)return
     if(agent.nodeId!=='local'||agent.execution!=='computer'||agent.temporaryGoalId||agent.remoteAgentId||agent.computerEnvironmentId)return
     this.nodes.requireSource(owner,agent)
     this.nodes.requireSource(owner,agent)

+ 16 - 12
src/server/workspaceAssets.ts

@@ -3,16 +3,17 @@ import { mkdirSync, writeFileSync } from 'node:fs'
 import { join, basename } from 'node:path'
 import { join, basename } from 'node:path'
 import {HttpError} from './errors.js'
 import {HttpError} from './errors.js'
 import { lookup } from 'mime-types'
 import { lookup } from 'mime-types'
+import { messageFileReferences, type MessageFileOrigin } from '../shared/messageFiles.js'
 import { WorkspaceStore } from './workspaceStore.js'
 import { WorkspaceStore } from './workspaceStore.js'
 import { WorkspaceNodes } from './workspaceGateway.js'
 import { WorkspaceNodes } from './workspaceGateway.js'
 import type { WorkspaceAgent, WorkspaceFile, WorkspaceMessage } from '../shared/workspace.js'
 import type { WorkspaceAgent, WorkspaceFile, WorkspaceMessage } from '../shared/workspace.js'
-export interface StoredWorkspaceFile extends WorkspaceFile {
+export interface StoredWorkspaceFile extends WorkspaceFile, MessageFileOrigin {
   path: string
   path: string
   digest?: string
   digest?: string
   sourceNodeId?:string
   sourceNodeId?:string
 }
 }
 export function publicFile(f: StoredWorkspaceFile): WorkspaceFile {
 export function publicFile(f: StoredWorkspaceFile): WorkspaceFile {
-  const { path: _path, digest: _digest, ...result } = f
+  const { path: _path, digest: _digest, messageFileSource: _source, ...result } = f
   return result
   return result
 }
 }
 export function libraryFile(
 export function libraryFile(
@@ -94,16 +95,16 @@ export class WorkspaceAssets {
     const dir=join(this.home,'workspace-files',owner);mkdirSync(dir,{recursive:true,mode:0o700})
     const dir=join(this.home,'workspace-files',owner);mkdirSync(dir,{recursive:true,mode:0o700})
     const path=join(dir,digest)
     const path=join(dir,digest)
     try{writeFileSync(path,bytes,{mode:0o600,flag:'wx'})}catch(error){if((error as NodeJS.ErrnoException).code!=='EEXIST')throw error}
     try{writeFileSync(path,bytes,{mode:0o600,flag:'wx'})}catch(error){if((error as NodeJS.ErrnoException).code!=='EEXIST')throw error}
-    const file:StoredWorkspaceFile={id:randomUUID(),name,mimeType:lookup(name)||'application/octet-stream',path,digest,size:bytes.length,sender:'agent',profile:agent.profile,sourceNodeId:agent.nodeId,conversationId:message.conversationId,messageId:message.id,createdAt:Date.now()}
+    const file:StoredWorkspaceFile={id:randomUUID(),name,mimeType:lookup(name)||'application/octet-stream',path,digest,size:bytes.length,sender:'agent',messageFileSource:'attachment',profile:agent.profile,sourceNodeId:agent.nodeId,conversationId:message.conversationId,messageId:message.id,createdAt:Date.now()}
     this.store.atomic(()=>{this.store.put(owner,'file',file.id,file);this.store.event(owner,'files.changed',publicFile(file),message.conversationId)})
     this.store.atomic(()=>{this.store.put(owner,'file',file.id,file);this.store.event(owner,'files.changed',publicFile(file),message.conversationId)})
     return publicFile(file)
     return publicFile(file)
   }
   }
   async archive(owner: string, message: WorkspaceMessage): Promise<void> {
   async archive(owner: string, message: WorkspaceMessage): Promise<void> {
-    if (!message.agentId) return
+    if (!message.agentId || message.role !== 'assistant' || message.visible === false) return
     const agent = this.store.require<WorkspaceAgent>(owner, 'agent', message.agentId)
     const agent = this.store.require<WorkspaceAgent>(owner, 'agent', message.agentId)
     await this.archiveText(
     await this.archiveText(
       owner,
       owner,
-      message.content + '\n' + JSON.stringify(message.tools),
+      message.content,
       agent.nodeId,
       agent.nodeId,
       agent.profile,
       agent.profile,
       message.conversationId,
       message.conversationId,
@@ -113,10 +114,10 @@ export class WorkspaceAssets {
     )
     )
     if (this.stopped) return
     if (this.stopped) return
     const attachments = this.store
     const attachments = this.store
-      .list<StoredWorkspaceFile>(owner, 'file')
+      .visibleFiles(owner)
       .filter((f) => f.messageId === message.id)
       .filter((f) => f.messageId === message.id)
       .map(publicFile)
       .map(publicFile)
-    if (attachments.length) {
+    if (attachments.length || message.attachments.length) {
       message.attachments = attachments
       message.attachments = attachments
       this.store.saveMessage(owner, message)
       this.store.saveMessage(owner, message)
     }
     }
@@ -134,11 +135,13 @@ export class WorkspaceAssets {
     if (this.stopped) return
     if (this.stopped) return
     const message=this.store.get<WorkspaceMessage>(owner,'message',messageId)
     const message=this.store.get<WorkspaceMessage>(owner,'message',messageId)
     if(message?.execution==='computer'||(!message?.execution&&message?.agentId&&this.store.get<WorkspaceAgent>(owner,'agent',message.agentId)?.execution==='computer'))return
     if(message?.execution==='computer'||(!message?.execution&&message?.agentId&&this.store.get<WorkspaceAgent>(owner,'agent',message.agentId)?.execution==='computer'))return
-    const paths = new Set<string>()
-    for (const m of text.matchAll(
-      /(?:MEDIA:\s*|\]\(<?|"(?:path|file_path|output_path)"\s*:\s*")((?:\/|~\/)[^\n"<>)]{1,4096})/g,
-    ))
-      paths.add(m[1]!.replace(/\\n.*$/, '').trim())
+    const paths = new Set([...messageFileReferences(text)].filter(path => /^(?:\/|~\/)/.test(path)))
+    // User attachment staging is explicit upload metadata, not a tool result.
+    if (sender === 'user') {
+      for (const match of text.matchAll(/"(?:path|file_path|output_path)"\s*:\s*"((?:\/|~\/)[^"\n<>]+)"/g)) {
+        paths.add(match[1]!)
+      }
+    }
     for (const path of [...paths].slice(0, 8)) {
     for (const path of [...paths].slice(0, 8)) {
       const key = createHash('sha256')
       const key = createHash('sha256')
         .update(JSON.stringify([nodeId, profile, messageId, path]))
         .update(JSON.stringify([nodeId, profile, messageId, path]))
@@ -164,6 +167,7 @@ export class WorkspaceAssets {
         const file: StoredWorkspaceFile = {
         const file: StoredWorkspaceFile = {
           id,
           id,
           sourcePath: path,
           sourcePath: path,
+          messageFileSource: 'reference',
           path: saved,
           path: saved,
           digest,
           digest,
           name,
           name,

+ 3 - 3
src/server/workspaceRoutes.ts

@@ -351,7 +351,7 @@ export function workspaceRouter(
   })
   })
   router.get('/api/app/files', (ctx) => {
   router.get('/api/app/files', (ctx) => {
     const files = store
     const files = store
-      .list<StoredWorkspaceFile>(owner(ctx), 'file')
+      .visibleFiles(owner(ctx))
       .filter(
       .filter(
         (f) =>
         (f) =>
           (!ctx.query.search ||
           (!ctx.query.search ||
@@ -372,7 +372,7 @@ export function workspaceRouter(
     }
     }
   })
   })
   router.get('/api/app/files/stats', (ctx) => {
   router.get('/api/app/files/stats', (ctx) => {
-    const files = store.list<StoredWorkspaceFile>(owner(ctx), 'file')
+    const files = store.visibleFiles(owner(ctx))
     ctx.body = { count: files.length, totalBytes: files.reduce((sum, f) => sum + f.size, 0) }
     ctx.body = { count: files.length, totalBytes: files.reduce((sum, f) => sum + f.size, 0) }
   })
   })
   router.post('/api/app/message-files/query', (ctx) => {
   router.post('/api/app/message-files/query', (ctx) => {
@@ -380,7 +380,7 @@ export function workspaceRouter(
       z.object({ messageIds: z.array(z.union([z.string(), z.number()])).max(500) }),
       z.object({ messageIds: z.array(z.union([z.string(), z.number()])).max(500) }),
       body(ctx),
       body(ctx),
     ).messageIds.map(String)
     ).messageIds.map(String)
-    const files = store.list<StoredWorkspaceFile>(owner(ctx), 'file')
+    const files = store.visibleFiles(owner(ctx))
     ctx.body = {
     ctx.body = {
       messages: Object.fromEntries(
       messages: Object.fromEntries(
         ids.map((id) => [
         ids.map((id) => [

+ 22 - 3
src/server/workspaceStore.ts

@@ -5,6 +5,8 @@ import { DatabaseSync } from 'node:sqlite'
 import { EventEmitter } from 'node:events'
 import { EventEmitter } from 'node:events'
 import { z } from 'zod'
 import { z } from 'zod'
 import { HttpError } from './errors.js'
 import { HttpError } from './errors.js'
+import { isVisibleMessageFile } from '../shared/messageFiles.js'
+import type { StoredWorkspaceFile } from './workspaceAssets.js'
 import { notificationPlainText } from './notificationText.js'
 import { notificationPlainText } from './notificationText.js'
 import { decodeAgentMascotAvatar, isAgentImageAvatar, defaultAgentIdentity, encodeAgentAvatar, normalizeAvatar, randomAgentIdentity, MAX_AVATAR_DESCRIPTOR_LENGTH } from '../shared/agentIdentity.js'
 import { decodeAgentMascotAvatar, isAgentImageAvatar, defaultAgentIdentity, encodeAgentAvatar, normalizeAvatar, randomAgentIdentity, MAX_AVATAR_DESCRIPTOR_LENGTH } from '../shared/agentIdentity.js'
 import type {
 import type {
@@ -235,7 +237,7 @@ export class WorkspaceStore {
         .prepare('INSERT INTO workspace_events(owner,type,conversation_id,data) VALUES(?,?,?,?)')
         .prepare('INSERT INTO workspace_events(owner,type,conversation_id,data) VALUES(?,?,?,?)')
         .run(owner, type, conversationId ?? null, JSON.stringify(data)).lastInsertRowid,
         .run(owner, type, conversationId ?? null, JSON.stringify(data)).lastInsertRowid,
     )
     )
-    const event = { seq, type, conversationId, data }
+    const event = { seq, type, conversationId, data: this.eventDataForDisplay(owner, type, data) }
     if (this.transactionEvents) this.transactionEvents.push({ owner, event })
     if (this.transactionEvents) this.transactionEvents.push({ owner, event })
     else this.publish(owner, event)
     else this.publish(owner, event)
     return seq
     return seq
@@ -248,7 +250,7 @@ export class WorkspaceStore {
         seq: Number(r.seq),
         seq: Number(r.seq),
         type: String(r.type),
         type: String(r.type),
         conversationId: r.conversation_id ? String(r.conversation_id) : undefined,
         conversationId: r.conversation_id ? String(r.conversation_id) : undefined,
-        data: JSON.parse(String(r.data)),
+        data: this.eventDataForDisplay(owner, String(r.type), JSON.parse(String(r.data))),
       }))
       }))
   }
   }
   cursor(owner: string): number {
   cursor(owner: string): number {
@@ -725,9 +727,26 @@ export class WorkspaceStore {
         `SELECT data FROM workspace_entities WHERE owner=? AND kind='message' AND json_extract(data,'$.conversationId')=? ${taskClause} AND json_extract(data,'$.seq')<? ${includeHidden ? '' : "AND coalesce(json_extract(data,'$.visible'),1) != 0"} ORDER BY json_extract(data,'$.seq') DESC LIMIT ?`,
         `SELECT data FROM workspace_entities WHERE owner=? AND kind='message' AND json_extract(data,'$.conversationId')=? ${taskClause} AND json_extract(data,'$.seq')<? ${includeHidden ? '' : "AND coalesce(json_extract(data,'$.visible'),1) != 0"} ORDER BY json_extract(data,'$.seq') DESC LIMIT ?`,
       )
       )
       .all(...(conversationTaskId ? [owner, conversationId, conversationTaskId, before, limit] : [owner, conversationId, before, limit]))
       .all(...(conversationTaskId ? [owner, conversationId, conversationTaskId, before, limit] : [owner, conversationId, before, limit]))
-      .map((r) => JSON.parse(String(r.data)) as Message)
+      .map((r) => this.messageForDisplay(owner, JSON.parse(String(r.data)) as Message))
       .reverse()
       .reverse()
   }
   }
+  nativeMessageForFile?: (owner: string, file: StoredWorkspaceFile) => Message | undefined
+  visibleFiles(owner: string): StoredWorkspaceFile[] {
+    const messages = new Map(this.list<Message>(owner, 'message').map(message => [message.id, message]))
+    return this.list<StoredWorkspaceFile>(owner, 'file').filter(file =>
+      isVisibleMessageFile(file, messages.get(file.messageId ?? '') ?? this.nativeMessageForFile?.(owner, file)))
+  }
+  messageForDisplay(owner: string, message: Message): Message {
+    const attachments = message.role === 'user' || message.role === 'assistant'
+      ? message.attachments.filter(file => isVisibleMessageFile(
+        this.get<StoredWorkspaceFile>(owner, 'file', file.id) ?? file, message))
+      : []
+    return { ...message, attachments }
+  }
+  private eventDataForDisplay(owner: string, type: string, data: unknown): unknown {
+    if (type === 'message.changed') return this.messageForDisplay(owner, data as Message)
+    return data
+  }
   saveMessage(owner: string, message: Message): void {
   saveMessage(owner: string, message: Message): void {
     this.atomic(() => {
     this.atomic(() => {
       const c = this.require<Conversation>(owner, 'conversation', message.conversationId)
       const c = this.require<Conversation>(owner, 'conversation', message.conversationId)

+ 6 - 0
src/shared/composeDesktops.ts

@@ -0,0 +1,6 @@
+export interface ComposeDesktop {id:string;name:string;socketPath:string}
+export interface ComposeDesktopState {id:string;name:string;online:boolean;ready:boolean}
+export interface DesktopRelay {
+  (id:string,operation:string,body:Record<string,unknown>):Promise<any>
+}
+export const COMPOSE_DESKTOP_IMAGE='sha256:'+'c'.repeat(64)

+ 8 - 0
src/shared/localVm.ts

@@ -1,6 +1,11 @@
 export type LocalVmMode = 'shared' | 'per-bot'
 export type LocalVmMode = 'shared' | 'per-bot'
 export type LocalVmAction = 'create' | 'start' | 'stop' | 'recreate' | 'remove'
 export type LocalVmAction = 'create' | 'start' | 'stop' | 'recreate' | 'remove'
 export interface LocalVmStatus {
 export interface LocalVmStatus {
+  fixedCapacity?:boolean
+  desktops?:Array<{id:string;name:string;online:boolean;ready:boolean;available?:boolean}>
+  executionHost?: 'server' | 'runner'
+  runnerName?: string
+  setupRequired?: 'runner' | 'worker'
   configured: boolean
   configured: boolean
   runtime?: 'docker' | 'podman'
   runtime?: 'docker' | 'podman'
   daemonUp: boolean
   daemonUp: boolean
@@ -14,6 +19,9 @@ export interface LocalVmStatus {
   instances?: Array<{id:string;status:string;name?:string;orphaned?:boolean}>
   instances?: Array<{id:string;status:string;name?:string;orphaned?:boolean}>
 }
 }
 export interface LocalVmInstance {
 export interface LocalVmInstance {
+  desktopId?:string
+  fixedCapacity?:boolean
+  desktops?:Array<{id:string;name:string;online:boolean;ready:boolean;available?:boolean}>
   container: 'missing' | 'stopped' | 'running'
   container: 'missing' | 'stopped' | 'running'
   ready: boolean
   ready: boolean
   inUse: boolean
   inUse: boolean

+ 89 - 0
src/shared/messageFiles.ts

@@ -0,0 +1,89 @@
+import MarkdownIt from 'markdown-it'
+import type Token from 'markdown-it/lib/token.mjs'
+import type { WorkspaceFile, WorkspaceMessage } from './workspace.js'
+
+/** Only the conversational body can introduce a visible file reference. */
+export function visibleMessageText(text: string): string {
+  return text
+    .replace(/<(think|thinking|reasoning)>[\s\S]*?<\/\1>/gi, '')
+    .replace(/<(?:think|thinking|reasoning)>[\s\S]*$/gi, '')
+}
+
+export function messageReasoningText(text: string, reasoning = ''): string {
+  const inline = [...text.matchAll(/<(think|thinking|reasoning)>([\s\S]*?)(?:<\/\1>|$)/gi)]
+    .map(match => match[2]!.trim()).filter(Boolean)
+  return [...new Set([reasoning.trim(), ...inline].filter(Boolean))].join('\n\n')
+}
+
+const markdown = new MarkdownIt({ html: false })
+
+export function normalizedMessagePath(value: string): string {
+  const path = value.replace(/^sandbox:/i, '')
+  try { return decodeURIComponent(path) } catch { return path }
+}
+
+export function messageFileReferences(text: string): Set<string> {
+  const paths = new Set<string>()
+  const visit = (tokens: Token[]) => {
+    for (const token of tokens) {
+      const destination = token.type === 'link_open' ? token.attrGet('href')
+        : token.type === 'image' ? token.attrGet('src') : undefined
+      if (destination) paths.add(normalizedMessagePath(destination))
+      if (token.type === 'text') {
+        for (const match of token.content.matchAll(/\bMEDIA:\s*(?:`([^`\n]+)`|"([^"\n]+)"|'([^'\n]+)'|([^\s]+))/gi)) {
+          paths.add(normalizedMessagePath(match[1] ?? match[2] ?? match[3] ?? match[4]!))
+        }
+      }
+      if (token.children) visit(token.children)
+    }
+  }
+  visit(markdown.parse(visibleMessageText(text), {}))
+  return paths
+}
+
+export interface MessageFileOrigin {
+  /** Absent on legacy records; references are reconciled against the body. */
+  messageFileSource?: 'attachment' | 'reference'
+}
+
+export function isVisibleMessageFile(
+  file: WorkspaceFile & MessageFileOrigin,
+  message?: WorkspaceMessage,
+): boolean {
+  // Explicit user uploads also belong in the library before a draft is sent.
+  if (file.sender === 'user') return true
+  if (message && (message.visible === false || message.role !== 'assistant')) return false
+  if (file.messageFileSource === 'attachment') return true
+  if (!message) return file.messageFileSource === 'reference'
+  // Older explicitly published attachments have no sourcePath; the archive
+  // scanner always recorded one. Do not trust an old attachment array alone.
+  if (!file.sourcePath) return message.attachments.some(item => item.id === file.id)
+  const references = messageFileReferences(message.content)
+  return references.has(normalizedMessagePath(file.sourcePath))
+    || references.has(`/api/app/files/${file.id}/download`)
+    || references.has(`/api/app/files/${file.id}/preview`)
+}
+
+/** Extract only the declared body/attachments of a native message payload. */
+export function nativeMessageFileText(data: Record<string, unknown>): string {
+  if (data.role && data.role !== 'assistant' && data.role !== 'user') return ''
+  if (data.display_kind || data.displayKind) return ''
+  const content = data.content ?? data.text ?? data.output ?? ''
+  const blocks = Array.isArray(content) ? content : []
+  const texts = typeof content === 'string' ? [content] : []
+  const attachments = [
+    ...blocks,
+    ...(Array.isArray(data.attachments) ? data.attachments : []),
+    ...(Array.isArray(data.files) ? data.files : []),
+  ]
+  for (const value of attachments) {
+    if (!value || typeof value !== 'object') continue
+    const block = value as Record<string, unknown>
+    if (block.type === 'text' && typeof block.text === 'string') texts.push(block.text)
+    if (block.type && !['image', 'image_url', 'file', 'audio', 'video'].includes(String(block.type))) continue
+    const image = block.image_url as { url?: string } | undefined
+    const path = block.path ?? block.url ?? image?.url
+    if (typeof path === 'string' && !/[<>\r\n]/.test(path)) texts.push(`[附件](<${path}>)`)
+  }
+  return visibleMessageText(texts.join('\n'))
+}

+ 1 - 1
src/shared/runner.ts

@@ -24,7 +24,7 @@ export interface RunnerConfiguration {
   allowedProfiles: string[]
   allowedProfiles: string[]
   artifactRoots: string[]
   artifactRoots: string[]
   allowInsecureLan?: boolean
   allowInsecureLan?: boolean
-  computers?: {network?:'none'|'public-proxy';runtime:'docker'|'podman';imageId:string;python:string;hermesSource:string;hermesHome:string;maxConcurrent?:number}
+  computers?: {managedBy?:'compose';network?:'none'|'public-proxy';runtime:'docker'|'podman';imageId:string;python:string;hermesSource:string;hermesHome:string;maxConcurrent?:number}
   hermesCredentials?: {username:string;password:string}
   hermesCredentials?: {username:string;password:string}
 }
 }
 export const UNCONFIGURED_COMPUTER_IMAGE='sha256:'+'0'.repeat(64)
 export const UNCONFIGURED_COMPUTER_IMAGE='sha256:'+'0'.repeat(64)

+ 12 - 3
tests/client/artifactStore.test.ts

@@ -30,12 +30,21 @@ describe('artifact extractor', () => {
     expect(artifacts[0].attachment?.id).toBe('attachment-1')
     expect(artifacts[0].attachment?.id).toBe('attachment-1')
   })
   })
 
 
-  it('extracts hinted tool result paths and deduplicates within a session', () => {
+  it('excludes files mentioned only in tool results', () => {
     const artifacts = extractArtifacts(session, [row('tool', 'tool', '{"output_path":"/tmp/result.pdf"}', {
     const artifacts = extractArtifacts(session, [row('tool', 'tool', '{"output_path":"/tmp/result.pdf"}', {
       toolCalls: [{ id: 'tool-1', name: 'write', status: 'completed', result: { output_path: '/tmp/result.pdf' } }],
       toolCalls: [{ id: 'tool-1', name: 'write', status: 'completed', result: { output_path: '/tmp/result.pdf' } }],
     })])
     })])
-    expect(artifacts).toHaveLength(1)
-    expect(artifacts[0]).toMatchObject({ kind: 'file', value: '/tmp/result.pdf', label: 'result.pdf' })
+    expect(artifacts).toEqual([])
+  })
+
+  it('collects the delivered body while ignoring reasoning and attached tool details', () => {
+    const artifacts = extractArtifacts(session, [row('assistant', 'assistant',
+      '<think>[过程](/tmp/private.pdf)</think>[交付](/tmp/result.pdf)', {
+        reasoning: '![过程图片](/tmp/process.png)',
+        toolCalls: [{ id: 'tool', name: 'read', status: 'completed', arguments: { path: '/tmp/input.pdf' }, result: { path: '/tmp/result.pdf' }, preview: '/tmp/preview.pdf' }],
+      })])
+    expect(artifacts.map(item => item.value)).toEqual(['/tmp/result.pdf'])
+    expect(artifacts[0].messageId).toBe('assistant')
   })
   })
 
 
   it('keeps the same artifact path when it was produced by distinct messages', () => {
   it('keeps the same artifact path when it was produced by distinct messages', () => {

+ 78 - 0
tests/client/conversationSearchDelete.test.ts

@@ -0,0 +1,78 @@
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { flushPromises, shallowMount, type VueWrapper } from '@vue/test-utils'
+import { shallowRef } from 'vue'
+import { createMemoryHistory, createRouter, matchedRouteKey } from 'vue-router'
+import ConversationsView from '../../src/client/views/ConversationsView.vue'
+import { apiRequest } from '../../src/client/api/client'
+
+vi.mock('../../src/client/api/client', () => ({ apiRequest: vi.fn(), ApiError: class extends Error {} }))
+vi.mock('../../src/client/stores/auth', () => ({ useAuthStore: () => ({ user: { id: 'owner' }, profiles: [], refreshProfileAvatars: async () => {} }) }))
+vi.mock('../../src/client/stores/theme', () => ({ useThemeStore: () => ({}) }))
+
+let wrapper: VueWrapper | undefined
+afterEach(() => { wrapper?.unmount(); wrapper = undefined; vi.restoreAllMocks(); vi.mocked(apiRequest).mockReset() })
+
+async function setup(kind: 'direct' | 'group', remove: () => Promise<void> = async () => {}) {
+  let archived = [{ id: 'archived', name: '旧聊天', kind, archived: true, memberIds: ['bot'], updatedAt: 1 }]
+  const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/conversations/:id?', component: { template: '<div />' } }] })
+  await router.push('/conversations'); await router.isReady()
+  vi.mocked(apiRequest).mockImplementation(async (path, options) => {
+    if (options?.method === 'DELETE') { await remove(); archived = []; return {} as never }
+    if (path === '/api/app/agents') return { agents: [{ id: 'bot', name: '旧聊天', archived: true }] } as never
+    if (path === '/api/app/conversations') return { conversations: archived, cursor: 1 } as never
+    if (path.startsWith('/api/app/events')) return { events: [], cursor: 1 } as never
+    return {} as never
+  })
+  wrapper = shallowMount(ConversationsView, { attachTo: document.body, global: {
+    provide: { [matchedRouteKey as symbol]: shallowRef(router.currentRoute.value.matched[0]) },
+    plugins: [router], stubs: { WorkspaceShell: { template: '<div><slot /></div>' }, FloatingResourceSearch: false, Teleport: false },
+  } })
+  await flushPromises()
+  document.dispatchEvent(new CustomEvent('hermes-yaoyao:sidebar-search', { detail: { section: 'groups' } }))
+  await flushPromises()
+  expect(document.querySelector('.search-delete')).toBeNull()
+  document.querySelector<HTMLButtonElement>('[role="tab"][aria-label="已归档"]')!.click()
+  await flushPromises()
+  return router
+}
+
+describe('archived chat deletion from search', () => {
+  it('keeps the archived result and route when confirmation is cancelled', async () => {
+    const router = await setup('direct')
+    const confirm = vi.spyOn(window, 'confirm').mockReturnValue(false)
+    document.querySelector<HTMLButtonElement>('.search-delete')!.click()
+    await flushPromises()
+    expect(confirm).toHaveBeenCalledWith(expect.stringContaining('永久删除 Bot「旧聊天」'))
+    expect(vi.mocked(apiRequest).mock.calls.some(([, options]) => options?.method === 'DELETE')).toBe(false)
+    expect(router.currentRoute.value.path).toBe('/conversations')
+    expect(document.querySelector('[role="dialog"]')?.textContent).toContain('旧聊天')
+  })
+
+  it.each([['direct', '/api/app/agents/bot'], ['group', '/api/app/conversations/archived']] as const)('deletes an archived %s through its own endpoint and updates the open search', async (kind, endpoint) => {
+    await setup(kind)
+    vi.spyOn(window, 'confirm').mockReturnValue(true)
+    const button = document.querySelector<HTMLButtonElement>('.search-delete')!
+    button.focus(); button.click()
+    await flushPromises()
+    expect(apiRequest).toHaveBeenCalledWith(endpoint, { method: 'DELETE' })
+    expect(document.querySelector('[role="dialog"]')?.textContent).toContain('没有已归档聊天')
+    expect(document.querySelector('[role="tab"][aria-label="已归档"]')?.textContent).toContain('0')
+    expect(document.activeElement).toBe(document.querySelector('[role="dialog"] input'))
+  })
+
+  it('disables repeated deletion and keeps server errors inside search', async () => {
+    let reject!: (error: Error) => void
+    await setup('direct', () => new Promise<void>((_, fail) => { reject = fail }))
+    vi.spyOn(window, 'confirm').mockReturnValue(true)
+    const button = document.querySelector<HTMLButtonElement>('.search-delete')!
+    button.click(); await flushPromises()
+    expect(button.disabled).toBe(true)
+    button.click()
+    expect(vi.mocked(apiRequest).mock.calls.filter(([, options]) => options?.method === 'DELETE')).toHaveLength(1)
+    reject(new Error('此 Bot 仍是群聊成员'))
+    await flushPromises()
+    expect(document.querySelector('[role="dialog"] [role="alert"]')?.textContent).toBe('此 Bot 仍是群聊成员')
+    expect(button.disabled).toBe(false)
+    expect(document.querySelector('[role="dialog"]')?.textContent).toContain('旧聊天')
+  })
+})

+ 15 - 0
tests/client/markdownContent.test.ts

@@ -165,3 +165,18 @@ describe('streaming Markdown', () => {
     wrapper.unmount()
     wrapper.unmount()
   })
   })
 })
 })
+
+it('renders process media as text while retaining message media previews', async () => {
+  const content = '![过程图](/tmp/process.png) [过程文件](/Users/test/Agents/process.pdf)'
+  const process = mount(MarkdownContent, { props: { content, processContent: true, fileCards: true } })
+  await nextTick()
+  expect(process.find('img').exists()).toBe(false)
+  expect(process.find('.file-link-card').exists()).toBe(false)
+  expect(process.text()).toContain('过程图')
+  const message = mount(MarkdownContent, { props: { content, fileCards: true } })
+  await nextTick()
+  expect(message.find('img').exists()).toBe(true)
+  expect(message.find('.file-link-card').exists()).toBe(true)
+  process.unmount()
+  message.unmount()
+})

+ 11 - 0
tests/client/workspacePresentation.test.ts

@@ -46,3 +46,14 @@ it('composes real member avatars and refreshes them without changing group membe
   expect(wrapper.find('.sidebar-item .agent-avatar--waiting').exists()).toBe(true)
   expect(wrapper.find('.sidebar-item .agent-avatar--waiting').exists()).toBe(true)
   wrapper.unmount()
   wrapper.unmount()
 })
 })
+
+
+it('keeps inline thinking in the process trace and its media out of the message body', () => {
+  const messages = workspaceMessagesToUi([{
+    id: 'inline-thinking', conversationId: 'chat', seq: 1, role: 'assistant',
+    content: '<think>![过程图](/tmp/process.png)</think>[报告](/tmp/report.pdf)',
+    reasoning: '', status: 'complete', attachments: [], tools: [], createdAt: 1,
+  }])
+  expect(messages[0].content).toBe('[报告](/tmp/report.pdf)')
+  expect(messages[0].reasoning).toBe('![过程图](/tmp/process.png)')
+})

+ 3 - 1
tests/e2e/team-tools.spec.ts

@@ -122,7 +122,9 @@ test('configures the Agent computer in its chat panel and keeps preparation in a
  await editor.getByRole('button',{name:'保存',exact:true}).click()
  await editor.getByRole('button',{name:'保存',exact:true}).click()
  await page.getByRole('button',{name:'电脑',exact:true}).click()
  await page.getByRole('button',{name:'电脑',exact:true}).click()
  const dock=page.getByRole('complementary',{name:'Agent 电脑面板'})
  const dock=page.getByRole('complementary',{name:'Agent 电脑面板'})
- await dock.getByRole('combobox',{name:'此 Agent 使用的电脑'}).selectOption('vm')
+ const vmTab=dock.getByRole('tab',{name:'本地虚拟机',exact:true})
+ await vmTab.click()
+ await expect(vmTab).toHaveAttribute('aria-selected','true')
  await expect(dock.getByRole('button',{name:'设置本地虚拟机',exact:true})).toBeVisible()
  await expect(dock.getByRole('button',{name:'设置本地虚拟机',exact:true})).toBeVisible()
  await page.screenshot({path:testInfo.outputPath('local-vm-unconfigured-agent.png')})
  await page.screenshot({path:testInfo.outputPath('local-vm-unconfigured-agent.png')})
 })
 })

+ 39 - 7
tests/e2e/workspace-chat.spec.ts

@@ -263,8 +263,12 @@ test('created roles and editable teams share a durable chat list without plugin
   await expect(textPreview).toBeVisible()
   await expect(textPreview).toBeVisible()
   await expect(textPreview).toContainText('Fixture report')
   await expect(textPreview).toContainText('Fixture report')
   await textPreview.getByRole('button', { name: '关闭预览' }).click()
   await textPreview.getByRole('button', { name: '关闭预览' }).click()
-  await page.getByRole('button', {name:'置顶聊天',exact:true}).click()
-  await expect(page.getByRole('button', {name:'取消置顶',exact:true})).toBeVisible()
+  const managerRow = rail.getByRole('option').filter({ hasText: '产品经理' })
+  await managerRow.click({ button: 'right' })
+  await page.getByRole('menuitem', {name:'置顶聊天',exact:true}).click()
+  await managerRow.click({ button: 'right' })
+  await expect(page.getByRole('menuitem', {name:'取消置顶',exact:true})).toBeVisible()
+  await page.getByRole('menuitem', {name:'取消置顶',exact:true}).press('Escape')
   const directURL = page.url()
   const directURL = page.url()
   await createAgent(page, '开发工程师')
   await createAgent(page, '开发工程师')
   await expect(page.locator('.message')).toHaveCount(0)
   await expect(page.locator('.message')).toHaveCount(0)
@@ -336,20 +340,21 @@ test('created roles and editable teams share a durable chat list without plugin
   await page.goto('/files')
   await page.goto('/files')
   await page.getByRole('button',{name:'查看来源',exact:true}).first().click()
   await page.getByRole('button',{name:'查看来源',exact:true}).first().click()
   await expect(page).toHaveURL(groupURL)
   await expect(page).toHaveURL(groupURL)
-  await page.getByRole('button', { name: '归档聊天', exact: true }).click()
+  await groupRow.click({ button: 'right' })
+  await page.getByRole('menuitem', { name: '归档聊天', exact: true }).click()
   await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3)
   await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3)
   await page.locator('.desktop-sidebar .sidebar-search-trigger').click()
   await page.locator('.desktop-sidebar .sidebar-search-trigger').click()
   const search = page.getByRole('dialog', { name: '搜索聊天', exact: true })
   const search = page.getByRole('dialog', { name: '搜索聊天', exact: true })
   await expect(search).toBeVisible()
   await expect(search).toBeVisible()
   await search.getByRole('searchbox', { name: '搜索聊天', exact: true }).fill('产品开发')
   await search.getByRole('searchbox', { name: '搜索聊天', exact: true }).fill('产品开发')
-  await expect(search.getByRole('option')).toHaveCount(0)
+  await expect(search.getByRole('listitem')).toHaveCount(0)
   await search.getByRole('tab', { name: '已归档', exact: true }).click()
   await search.getByRole('tab', { name: '已归档', exact: true }).click()
   await expect(search.getByRole('searchbox')).toHaveValue('产品开发')
   await expect(search.getByRole('searchbox')).toHaveValue('产品开发')
-  await expect(search.getByRole('option')).toHaveCount(1)
+  await expect(search.getByRole('listitem')).toHaveCount(1)
   await page.screenshot({ path: testInfo.outputPath('archived-chat-search.png'), fullPage: true })
   await page.screenshot({ path: testInfo.outputPath('archived-chat-search.png'), fullPage: true })
-  await search.getByRole('option').click()
+  await search.getByRole('listitem').getByRole('button').filter({ hasText: '产品开发团队' }).click()
   await expect(search).not.toBeVisible()
   await expect(search).not.toBeVisible()
-  await page.getByRole('button', { name: '恢复聊天', exact: true }).click()
+  await expect(page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行')).toBeDisabled()
   await page.goto(directURL)
   await page.goto(directURL)
   await expect(page.locator('.message--assistant')).toHaveCount(1)
   await expect(page.locator('.message--assistant')).toHaveCount(1)
   await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
   await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
@@ -519,3 +524,30 @@ for (const mode of ['普通聊天', 'Bot 单聊', '群聊', '普通长回复'] a
     }
     }
   })
   })
 }
 }
+
+
+test('only chat messages introduce files across transcript and library', async ({ page }, testInfo) => {
+  await login(page)
+  await createAgent(page, '文件展示验收')
+  await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('[message-files] 请发送报告')
+  await page.getByRole('button', { name: '发送消息', exact: true }).click()
+  const report = page.locator('.message--assistant .file-link-card').first()
+  await expect(report).toBeVisible()
+  const process = page.locator('.turn-trace')
+  await expect(process).toHaveCount(1)
+  await process.locator('summary').first().click()
+  await expect(process).toContainText('/tmp/process.pdf')
+  await expect(process.locator('img, .file-link-card')).toHaveCount(0)
+  const conversationId = new URL(page.url()).pathname.split('/').at(-1)!
+  const files = await (await page.request.get(`/api/app/files?session_id=${encodeURIComponent(conversationId)}`)).json()
+  expect(files.items.map((file: { name: string }) => file.name)).toEqual(['workspace-report.txt'])
+  await report.click()
+  const preview = page.getByRole('dialog', { name: '预览 workspace-report.txt', exact: true })
+  await expect(preview).toContainText('Fixture report')
+  await preview.getByRole('button', { name: '关闭预览' }).click()
+  await page.reload()
+  await expect(page.locator('.message--assistant .file-link-card')).toHaveCount(1)
+  await page.locator('.turn-trace summary').first().click()
+  await page.setViewportSize({ width: 1280, height: 1100 })
+  await page.screenshot({ path: testInfo.outputPath('message-files-web.png') })
+})

+ 5 - 0
tests/fixtures/workspace-server.ts

@@ -261,6 +261,11 @@ wss.on('connection', (socket) => {
       const markdownFinal = `${markdownPrefix}\n\x60\x60\x60\n\n| 名称 | 数量 |\n| --- | --- |\n| 项目 | 2 |\n\n最终完整标记`
       const markdownFinal = `${markdownPrefix}\n\x60\x60\x60\n\n| 名称 | 数量 |\n| --- | --- |\n| 项目 | 2 |\n\n最终完整标记`
       const text = markdownStream ? markdownFinal : `我是${name}。已按角色规则处理这条消息。\n\n- 会话独立保存\n- 可以继续交流\n\n[报告](/tmp/workspace-report.txt)${delegates ? `\n请${requested}处理任务。` : ''}`
       const text = markdownStream ? markdownFinal : `我是${name}。已按角色规则处理这条消息。\n\n- 会话独立保存\n- 可以继续交流\n\n[报告](/tmp/workspace-report.txt)${delegates ? `\n请${requested}处理任务。` : ''}`
       event('message.start', {}, f.params.session_id)
       event('message.start', {}, f.params.session_id)
+      if (String(f.params.text).includes('[message-files]')) {
+        event('reasoning.delta', { text: '![过程图](/tmp/process.png)' }, f.params.session_id)
+        event('tool.start', { tool_id: 'process-file', name: 'read_file', arguments: { path: '/tmp/input.pdf' } }, f.params.session_id)
+        event('tool.complete', { tool_id: 'process-file', name: 'read_file', result: { path: '/tmp/process.pdf' } }, f.params.session_id)
+      }
       if (crossClientRun) event('tool.start', { tool_id: 'cross-client-tool', name: 'read_file' }, f.params.session_id)
       if (crossClientRun) event('tool.start', { tool_id: 'cross-client-tool', name: 'read_file' }, f.params.session_id)
       else setTimeout(() => event('message.delta', { text: markdownStream ? markdownPrefix : text.slice(0, 12) }, f.params.session_id), 80)
       else setTimeout(() => event('message.delta', { text: markdownStream ? markdownPrefix : text.slice(0, 12) }, f.params.session_id), 80)
       const complete = () => {
       const complete = () => {

+ 107 - 11
tests/live/dockerPlatform.live.test.ts

@@ -8,10 +8,16 @@ import {createServer} from 'node:http'
 import {execFile,spawn} from 'node:child_process'
 import {execFile,spawn} from 'node:child_process'
 import {promisify} from 'node:util'
 import {promisify} from 'node:util'
 import request from 'supertest'
 import request from 'supertest'
+import {chromium} from '@playwright/test'
+import {UNCONFIGURED_COMPUTER_IMAGE} from '../../src/shared/runner'
 const exec=promisify(execFile)
 const exec=promisify(execFile)
 it.skipIf(!process.env.YAOYAO_PLATFORM_IMAGE||!process.env.YAOYAO_COMPUTER_IMAGE||!process.env.YAOYAO_HERMES_PYTHON)('executes an isolated task through the packaged Docker control plane and an external Runner',async()=>{
 it.skipIf(!process.env.YAOYAO_PLATFORM_IMAGE||!process.env.YAOYAO_COMPUTER_IMAGE||!process.env.YAOYAO_HERMES_PYTHON)('executes an isolated task through the packaged Docker control plane and an external Runner',async()=>{
   const home=await mkdtemp(join(tmpdir(),'yaoyao-docker-platform-')),name=`yaoyao-platform-${randomUUID()}`,webHome=join(home,'web'),hermesHome=join(home,'hermes')
   const home=await mkdtemp(join(tmpdir(),'yaoyao-docker-platform-')),name=`yaoyao-platform-${randomUUID()}`,webHome=join(home,'web'),hermesHome=join(home,'hermes')
   await mkdir(webHome);await mkdir(hermesHome)
   await mkdir(webHome);await mkdir(hermesHome)
+  const fixed=!!process.env.YAOYAO_COMPOSE_DESKTOP_IMAGE
+  let webContainer=name,composeIds:string[]=[],desktopId=''
+  const override=join(home,'compose.override.json')
+  const compose=(args:string[])=>exec('docker',['compose','--project-name',name,'--project-directory',resolve('.'),'--env-file',resolve('docker.env.example'),'-f',resolve('compose.desktops.yaml'),'-f',override,...args],{env:{...process.env,HERMES_YAOYAO_PUBLISHED_PORT:'0',HERMES_YAOYAO_BIND_ADDRESS:'127.0.0.1',HERMES_YAOYAO_UPSTREAM:`http://host.docker.internal:${upstreamPort}`}})
   const upstream=createServer(async(req,res)=>{
   const upstream=createServer(async(req,res)=>{
     res.setHeader('Content-Type','application/json')
     res.setHeader('Content-Type','application/json')
     if(req.method==='GET'){res.end(JSON.stringify(req.url?.startsWith('/api/profiles')?{profiles:[{name:'default'}]}:req.url?.startsWith('/api/config')?{terminal:{cwd:'/workspace/docker-proof'}}:{ok:true}));return}
     if(req.method==='GET'){res.end(JSON.stringify(req.url?.startsWith('/api/profiles')?{profiles:[{name:'default'}]}:req.url?.startsWith('/api/config')?{terminal:{cwd:'/workspace/docker-proof'}}:{ok:true}));return}
@@ -22,28 +28,80 @@ it.skipIf(!process.env.YAOYAO_PLATFORM_IMAGE||!process.env.YAOYAO_COMPUTER_IMAGE
     else res.end(JSON.stringify({id:randomUUID(),object:'chat.completion',model:'fixture-model',choices:[{index:0,message,finish_reason:message.tool_calls?'tool_calls':'stop'}]}))
     else res.end(JSON.stringify({id:randomUUID(),object:'chat.completion',model:'fixture-model',choices:[{index:0,message,finish_reason:message.tool_calls?'tool_calls':'stop'}]}))
   })
   })
   await new Promise<void>(done=>upstream.listen(0,'0.0.0.0',done));const upstreamPort=(upstream.address() as {port:number}).port
   await new Promise<void>(done=>upstream.listen(0,'0.0.0.0',done));const upstreamPort=(upstream.address() as {port:number}).port
-  let child:ReturnType<typeof spawn>|undefined,exited:Promise<void>|undefined
+  let child:ReturnType<typeof spawn>|undefined,exited:Promise<void>|undefined,browser:Awaited<ReturnType<typeof chromium.launch>>|undefined
   try{
   try{
-    await exec('docker',['run','-d','--name',name,'--init','--read-only','--cap-drop','ALL','--security-opt','no-new-privileges:true','--tmpfs','/tmp:mode=1777','--add-host','host.docker.internal:host-gateway','-p','127.0.0.1::15300','--mount',`type=volume,source=${name}-data,target=/var/lib/hermes-yaoyao`,'-e','HERMES_YAOYAO_ALLOW_INSECURE_LAN=1','-e','HERMES_YAOYAO_ALLOWED_HOSTS=localhost,127.0.0.1','-e',`HERMES_YAOYAO_UPSTREAM=http://host.docker.internal:${upstreamPort}`,process.env.YAOYAO_PLATFORM_IMAGE!])
-    const detail=JSON.parse((await exec('docker',['inspect',name])).stdout)[0],port=detail.NetworkSettings.Ports['15300/tcp'][0].HostPort,address=`http://127.0.0.1:${port}`,client=request.agent(address)
+    if(fixed){
+      await writeFile(override,JSON.stringify({services:{web:{image:process.env.YAOYAO_PLATFORM_IMAGE},'desktop-1':{image:process.env.YAOYAO_COMPOSE_DESKTOP_IMAGE},'desktop-2':{image:process.env.YAOYAO_COMPOSE_DESKTOP_IMAGE}}}))
+      await compose(['up','-d','--no-build'])
+      webContainer=(await compose(['ps','-q','web'])).stdout.trim()
+      composeIds=(await compose(['ps','-q','desktop-1','desktop-2'])).stdout.trim().split(/\s+/)
+      expect(composeIds).toHaveLength(2)
+    }else await exec('docker',['run','-d','--name',name,'--init','--read-only','--cap-drop','ALL','--security-opt','no-new-privileges:true','--tmpfs','/tmp:mode=1777','--add-host','host.docker.internal:host-gateway','-p','127.0.0.1::15300','--mount',`type=volume,source=${name}-data,target=/var/lib/hermes-yaoyao`,'-e','HERMES_YAOYAO_ALLOW_INSECURE_LAN=1','-e','HERMES_YAOYAO_ALLOWED_HOSTS=localhost,127.0.0.1','-e',`HERMES_YAOYAO_UPSTREAM=http://host.docker.internal:${upstreamPort}`,process.env.YAOYAO_PLATFORM_IMAGE!])
+    const detail=JSON.parse((await exec('docker',['inspect',webContainer])).stdout)[0],port=detail.NetworkSettings.Ports['15300/tcp'][0].HostPort,address=`http://127.0.0.1:${port}`,client=request.agent(address)
     await expect.poll(async()=>{try{return (await client.get('/healthz')).status}catch{return 0}},{timeout:30000}).toBe(200)
     await expect.poll(async()=>{try{return (await client.get('/healthz')).status}catch{return 0}},{timeout:30000}).toBe(200)
     expect(detail.Config.User).toBe('node');expect(detail.HostConfig.ReadonlyRootfs).toBe(true);expect(detail.HostConfig.CapDrop).toContain('ALL')
     expect(detail.Config.User).toBe('node');expect(detail.HostConfig.ReadonlyRootfs).toBe(true);expect(detail.HostConfig.CapDrop).toContain('ALL')
-    expect((await exec('docker',['exec',name,'id','-u'])).stdout.trim()).toBe('1000')
+    expect((await exec('docker',['exec',webContainer,'id','-u'])).stdout.trim()).toBe('1000')
+    expect(detail.Mounts.every((mount:any)=>!mount.Destination.includes('docker.sock')&&!mount.Destination.includes('.hermes'))).toBe(true)
+    if(fixed){
+      for(const id of composeIds){
+        const desktop=JSON.parse((await exec('docker',['inspect',id])).stdout)[0]
+        expect(Object.values(desktop.NetworkSettings.Ports??{}).every(value=>value===null)).toBe(true)
+
+      }
+    }
+    await client.get('/api/app/admin/runners/bundle').expect(401)
     const bootstrap=await client.get('/api/app/bootstrap').expect(200)
     const bootstrap=await client.get('/api/app/bootstrap').expect(200)
     const setup=await client.post('/api/app/setup').set('Origin',address).set('X-CSRF-Token',bootstrap.body.csrfToken).send({username:'docker-fixture',password:'docker-fixture-password'}).expect(200)
     const setup=await client.post('/api/app/setup').set('Origin',address).set('X-CSRF-Token',bootstrap.body.csrfToken).send({username:'docker-fixture',password:'docker-fixture-password'}).expect(200)
     expect(setup.body.user.id).toBeTruthy()
     expect(setup.body.user.id).toBeTruthy()
     const fresh=await client.get('/api/app/bootstrap').expect(200)
     const fresh=await client.get('/api/app/bootstrap').expect(200)
     const post=(path:string,body:unknown)=>client.post(path).set('Origin',address).set('X-CSRF-Token',fresh.body.csrfToken).send(body)
     const post=(path:string,body:unknown)=>client.post(path).set('Origin',address).set('X-CSRF-Token',fresh.body.csrfToken).send(body)
+    const localVm='/api/app/admin/local-vm'
+    expect((await client.get(localVm).expect(200)).body).toMatchObject({configured:false,executionHost:'runner',setupRequired:'runner'})
+    await post(localVm+'/prepare',{requestId:randomUUID()}).expect(409)
+    const bundle=await client.get('/api/app/admin/runners/bundle').buffer(true).parse((response,done)=>{const chunks:Buffer[]=[];response.on('data',chunk=>chunks.push(chunk));response.on('end',()=>done(null,Buffer.concat(chunks)))}).expect(200)
+    const bundlePath=join(home,'yaoyao-runner.tar.gz'),runnerHome=join(home,'runner')
+    await writeFile(bundlePath,bundle.body);await mkdir(runnerHome)
+    await exec('tar',['-xzf',bundlePath,'-C',runnerHome])
+    for(const file of ['runner.mjs','hermes_worker.py','guest_proxy.py','computer-image/Dockerfile','third-party/openmausbot/LICENSE'])expect((await readFile(join(runnerHome,file))).length).toBeGreaterThan(0)
+    browser=await chromium.launch({headless:true})
+    const page=await browser.newPage({viewport:{width:1440,height:960}})
+    await page.goto(address+'/conversations')
+    await page.getByRole('textbox',{name:'账号',exact:true}).fill('docker-fixture')
+    await page.getByRole('textbox',{name:'密码',exact:true}).fill('docker-fixture-password')
+    await page.getByRole('button',{name:'登录',exact:true}).click()
+    await page.getByRole('button',{name:'设置与模式',exact:true}).first().click()
+    await page.getByRole('menuitem',{name:'进入设置',exact:true}).click()
+    const settings=page.getByRole('dialog',{name:'设置中心'})
+    await settings.getByRole('button',{name:'本地虚拟机',exact:true}).click()
+    await settings.getByRole('button',{name:'打开执行节点设置',exact:true}).click()
+    await expect.poll(()=>settings.getByRole('link',{name:'下载配套执行节点程序'}).count()).toBe(1)
+    expect(await settings.getByRole('checkbox',{name:'启用隔离电脑 Worker',exact:true}).isChecked()).toBe(true)
     const registration=await post('/api/app/admin/runners',{name:'容器外执行节点',allowedProfiles:['default']}).expect(201)
     const registration=await post('/api/app/admin/runners',{name:'容器外执行节点',allowedProfiles:['default']}).expect(201)
     const runnerID=registration.body.runner.id
     const runnerID=registration.body.runner.id
     await writeFile(join(hermesHome,'config.yaml'),`model:\n  provider: custom\n  default: fixture-model\n  base_url: http://127.0.0.1:${upstreamPort}/v1\n  api_key: fixture-key\n  api_mode: chat_completions\nterminal:\n  cwd: /workspace/docker-proof\n`,{mode:0o600})
     await writeFile(join(hermesHome,'config.yaml'),`model:\n  provider: custom\n  default: fixture-model\n  base_url: http://127.0.0.1:${upstreamPort}/v1\n  api_key: fixture-key\n  api_mode: chat_completions\nterminal:\n  cwd: /workspace/docker-proof\n`,{mode:0o600})
-    const config={protocol:1,serverURL:address,runnerId:runnerID,token:registration.body.token,hermesURL:`http://127.0.0.1:${upstreamPort}`,allowedProfiles:['default'],artifactRoots:[],computers:{runtime:'docker',network:'none',imageId:process.env.YAOYAO_COMPUTER_IMAGE,python:process.env.YAOYAO_HERMES_PYTHON,hermesSource:process.env.YAOYAO_HERMES_SOURCE,hermesHome}}
+    const config={protocol:1,serverURL:address,runnerId:runnerID,token:registration.body.token,hermesURL:`http://127.0.0.1:${upstreamPort}`,allowedProfiles:['default'],artifactRoots:[],computers:{...(fixed?{managedBy:'compose'}:{}),runtime:'docker',network:'none',imageId:UNCONFIGURED_COMPUTER_IMAGE,python:process.env.YAOYAO_HERMES_PYTHON,hermesSource:process.env.YAOYAO_HERMES_SOURCE,hermesHome}}
     const path=join(home,'runner.json');await writeFile(path,JSON.stringify(config),{mode:0o600})
     const path=join(home,'runner.json');await writeFile(path,JSON.stringify(config),{mode:0o600})
-    child=spawn(process.execPath,[resolve('.runner-build/runner.mjs'),'--config',path],{stdio:'ignore'})
+    child=spawn(process.execPath,[join(runnerHome,'runner.mjs'),'--config',path],{stdio:'ignore'})
     exited=new Promise(done=>child!.once('exit',()=>done()))
     exited=new Promise(done=>child!.once('exit',()=>done()))
     await expect.poll(async()=>(await client.get('/api/app/admin/runners')).body.runners?.some((runner:any)=>runner.id===runnerID&&runner.online),{timeout:15000}).toBe(true)
     await expect.poll(async()=>(await client.get('/api/app/admin/runners')).body.runners?.some((runner:any)=>runner.id===runnerID&&runner.online),{timeout:15000}).toBe(true)
+    await settings.getByRole('button',{name:'收起执行节点设置',exact:true}).click()
+    await settings.getByRole('button',{name:'重新检查',exact:true}).click()
+    if(fixed){
+      expect(await settings.getByRole('combobox',{name:'虚拟机数量上限'}).count()).toBe(0)
+      expect(await settings.getByRole('button',{name:'准备本地虚拟机',exact:true}).count()).toBe(0)
+      const inventory=(await client.get(localVm)).body;expect(inventory.fixedCapacity).toBe(true);expect(inventory.maxInstances).toBe(2);desktopId=inventory.desktops[0].id
+    }else await settings.getByRole('button',{name:'准备本地虚拟机',exact:true}).click()
+    await expect.poll(async()=>(await client.get(localVm)).body.image,{timeout:90000}).toBe(true)
+    if(fixed){
+      await expect.poll(async()=>(await client.get(localVm)).body.desktops.every((d:any)=>d.ready),{timeout:90000}).toBe(true)
+      for(const id of composeIds){
+        const denied=await exec('docker',['exec','--user','1000:1000',id,'python3','-c',"import socket; s=socket.socket(socket.AF_UNIX);\ntry:s.connect('/run/yaoyao-private/bridge/desktop.sock');print('accessible')\nexcept PermissionError:print('blocked')"])
+        expect(denied.stdout.trim()).toBe('blocked')
+      }
+    }
     const created=await post('/api/app/agents',{name:'Docker 隔离成员',profile:'default',execution:'computer'}).expect(201)
     const created=await post('/api/app/agents',{name:'Docker 隔离成员',profile:'default',execution:'computer'}).expect(201)
     const agentID=created.body.agent.id,conversations=await client.get('/api/app/conversations').expect(200),conversation=conversations.body.conversations.find((item:any)=>item.memberIds.includes(agentID))
     const agentID=created.body.agent.id,conversations=await client.get('/api/app/conversations').expect(200),conversation=conversations.body.conversations.find((item:any)=>item.memberIds.includes(agentID))
+    if(fixed)await client.put(`/api/app/agents/${agentID}/local-vm`).set('Origin',address).set('X-CSRF-Token',fresh.body.csrfToken).send({enabled:true,desktopId}).expect(200)
     const sent=await post(`/api/app/conversations/${conversation.id}/messages`,{requestId:randomUUID(),content:'执行当前隔离工具并导出结果。'}).expect(202)
     const sent=await post(`/api/app/conversations/${conversation.id}/messages`,{requestId:randomUUID(),content:'执行当前隔离工具并导出结果。'}).expect(202)
     let result:any,message:any
     let result:any,message:any
     await expect.poll(async()=>{result=(await client.get(`/api/app/conversations/${conversation.id}`)).body;message=result.messages?.find((item:any)=>item.role==='assistant'&&item.runId===sent.body.run.id);return message?.status??'pending'},{timeout:45000}).toMatch(/complete|failed|uncertain/)
     await expect.poll(async()=>{result=(await client.get(`/api/app/conversations/${conversation.id}`)).body;message=result.messages?.find((item:any)=>item.role==='assistant'&&item.runId===sent.body.run.id);return message?.status??'pending'},{timeout:45000}).toMatch(/complete|failed|uncertain/)
@@ -52,13 +110,51 @@ it.skipIf(!process.env.YAOYAO_PLATFORM_IMAGE||!process.env.YAOYAO_COMPUTER_IMAGE
     const file=message.attachments?.[0]
     const file=message.attachments?.[0]
     expect(file?.id).toBeTruthy()
     expect(file?.id).toBeTruthy()
     expect((await client.get(`/api/app/files/${file.id}/download`).expect(200)).text).toBe('docker-control-plane-proof')
     expect((await client.get(`/api/app/files/${file.id}/download`).expect(200)).text).toBe('docker-control-plane-proof')
-    expect(await readFile(join(home,'state',runnerID,'computer-workspaces',agentID,'docker-proof.txt'),'utf8')).toBe('docker-control-plane-proof')
+    if(fixed)expect((await exec('docker',['exec','--user','1000:1000',composeIds[0]!,'cat','/home/cua/workspace/docker-proof.txt'])).stdout).toBe('docker-control-plane-proof')
+    else expect(await readFile(join(home,'state',runnerID,'computer-workspaces',agentID,'docker-proof.txt'),'utf8')).toBe('docker-control-plane-proof')
+    const computerBase=`/api/app/agents/${agentID}/computer`
+    // Shell tasks can finish before the desktop capture service is ready.
+    await expect.poll(async()=>(await client.get(`/api/app/agents/${agentID}/local-vm`)).body.ready,{timeout:30000}).toBe(true)
+    const frame=(await client.get(computerBase+'/frame').expect(200)).body
+    expect(frame.width).toBeGreaterThan(1000);expect(frame.data.length).toBeGreaterThan(1000)
+    const taken=await post(computerBase+'/take',{requestId:randomUUID()}).expect(200)
+    await expect.poll(async()=>(await client.get(computerBase)).body.mode,{timeout:15000}).toBe('human')
+    await post(computerBase+'/giveback',{controlId:taken.body.controlId,token:taken.body.token}).expect(200)
+    const changeMode=(mode:string)=>client.put(localVm+'/policy').set('Origin',address).set('X-CSRF-Token',fresh.body.csrfToken).send({requestId:randomUUID(),mode,maxInstances:2})
+    await changeMode('shared').expect(fixed?409:200);await changeMode('per-bot').expect(fixed?409:200)
+    if(fixed){
+      for(const action of ['create','recreate','remove','start','stop'])await post(`/api/app/agents/${agentID}/local-vm/${action}`,{}).expect(409)
+      const second=(await post('/api/app/agents',{name:'共用桌面的第二个成员',profile:'default'}).expect(201)).body.agent
+      await client.put(`/api/app/agents/${second.id}/local-vm`).set('Origin',address).set('X-CSRF-Token',fresh.body.csrfToken).send({enabled:true,desktopId}).expect(200)
+      expect((await client.get(`/api/app/agents/${second.id}/local-vm`)).body.desktopId).toBe(desktopId)
+      const secondChat=(await client.get('/api/app/conversations')).body.conversations.find((c:any)=>c.memberIds.includes(second.id))
+      const task=await post(`/api/app/conversations/${secondChat.id}/messages`,{requestId:randomUUID(),content:'在同一共享桌面执行并导出结果。'}).expect(202)
+      await expect.poll(async()=>(await client.get(`/api/app/conversations/${secondChat.id}`)).body.messages.find((m:any)=>m.role==='assistant'&&m.runId===task.body.run.id)?.status,{timeout:45000}).toBe('complete')
+      expect((await compose(['ps','-q','desktop-1','desktop-2'])).stdout.trim().split(/\s+/).sort()).toEqual([...composeIds].sort())
+    }
+    await settings.getByRole('button',{name:'关闭设置中心'}).click()
+    await page.goto(address+`/conversations/${conversation.id}`)
+    await page.getByRole('button',{name:'电脑',exact:true}).click()
+    await expect.poll(()=>page.getByRole('complementary',{name:'Agent 电脑面板'}).getByRole('img').count(),{timeout:20000}).toBe(1)
+    if(fixed){
+      const dock=page.getByRole('complementary',{name:'Agent 电脑面板'})
+      expect(await dock.getByRole('button',{name:'停止虚拟机',exact:true}).count()).toBe(0)
+      const otherDesktop=(await client.get(localVm)).body.desktops[1].id
+      page.once('dialog',dialog=>{void dialog.accept()})
+      await dock.getByRole('combobox',{name:'此 Agent 使用的电脑'}).selectOption(otherDesktop)
+      await expect.poll(async()=>(await client.get(`/api/app/agents/${agentID}/local-vm`)).body.desktopId).toBe(otherDesktop)
+      await expect.poll(()=>dock.getByRole('img').count(),{timeout:15000}).toBe(1)
+      expect((await compose(['ps','-q','desktop-1','desktop-2'])).stdout.trim().split(/\s+/).sort()).toEqual([...composeIds].sort())
+    }
+    const evidence=resolve(process.env.YAOYAO_DOCKER_EVIDENCE??'test-results/docker-platform')
+    await mkdir(evidence,{recursive:true});await page.screenshot({path:join(evidence,'docker-agent-desktop.png')})
     const identity=await client.get('/api/status').expect(200);expect(identity.body.server_kind).toBe('yaoyao-web')
     const identity=await client.get('/api/status').expect(200);expect(identity.body.server_kind).toBe('yaoyao-web')
-  }catch(error){const logs=await exec('docker',['logs','--tail','35',name]).catch(()=>({stdout:'',stderr:''}));console.error(logs.stdout,logs.stderr);throw error}finally{
+  }catch(error){if(fixed){for(const id of composeIds){const log=await exec('docker',['exec',id,'sh','-c','tail -n 25 /var/log/supervisor/yaoyao-compose.error.log; ls -ld /run/yaoyao-private /run/yaoyao-private/bridge /run/yaoyao-private/bridge/desktop.sock']).catch(()=>({stdout:'desktop unavailable',stderr:''}));console.error(log.stdout,log.stderr)}}const logs=await exec('docker',['logs','--tail','35',webContainer]).catch(()=>({stdout:'',stderr:''}));console.error(logs.stdout,logs.stderr);throw error}finally{
     child?.kill('SIGTERM');await exited
     child?.kill('SIGTERM');await exited
-    await exec('docker',['rm','-f',name]).catch(()=>{})
-    await exec('docker',['volume','rm',name+'-data']).catch(()=>{})
+    await browser?.close()
+    if(fixed)await compose(['down','--volumes','--remove-orphans']).catch(()=>{})
+    else{await exec('docker',['rm','-f',name]).catch(()=>{});await exec('docker',['volume','rm',name+'-data']).catch(()=>{})}
     await new Promise<void>(done=>{upstream.close(()=>done());upstream.closeAllConnections()})
     await new Promise<void>(done=>{upstream.close(()=>done());upstream.closeAllConnections()})
     await rm(home,{recursive:true,force:true})
     await rm(home,{recursive:true,force:true})
   }
   }
-},100000)
+},200000)

+ 73 - 0
tests/server/composeDesktops.test.ts

@@ -0,0 +1,73 @@
+// @vitest-environment node
+import {it,expect,vi} from 'vitest'
+import {randomUUID} from 'node:crypto'
+import {mkdtempSync,rmSync} from 'node:fs'
+import {tmpdir} from 'node:os'
+import {join} from 'node:path'
+import {DatabaseSync} from 'node:sqlite'
+import Koa from 'koa'
+import {bodyParser} from '@koa/bodyparser'
+import request from 'supertest'
+import {WorkspaceStore} from '../../src/server/workspaceStore'
+import {WorkspaceNodes} from '../../src/server/workspaceGateway'
+import {SharedComputers} from '../../src/server/sharedComputers'
+import {LocalVmService} from '../../src/server/localVm'
+import {loadServerConfig} from '../../src/server/config'
+import {ComposeDesktops,parseComposeDesktops} from '../../src/server/composeDesktops'
+import {ComposeComputerProvider} from '../../src/runner/computers/compose'
+import {ComputerPool} from '../../src/runner/computers/pool'
+import {COMPOSE_DESKTOP_IMAGE} from '../../src/shared/composeDesktops'
+
+it('accepts only fixed deployment socket paths and rejects undeclared desktop targets',async()=>{
+ const desktop={id:randomUUID(),name:'共享桌面',socketPath:'/run/yaoyao-desktops/desktop-1/desktop.sock'}
+ expect(parseComposeDesktops(JSON.stringify([desktop]))).toEqual([desktop])
+ for(const path of ['/var/run/docker.sock','http://host:1234','/run/yaoyao-desktops/../../docker.sock'])expect(()=>parseComposeDesktops(JSON.stringify([{...desktop,socketPath:path}]))).toThrow()
+ expect(()=>parseComposeDesktops(JSON.stringify([desktop,desktop]))).toThrow()
+ await expect(new ComposeDesktops([desktop]).call(randomUUID(),'health')).rejects.toMatchObject({code:'compose_desktop_missing'})
+ await expect(new ComposeDesktops([desktop]).call(desktop.id,'remove')).rejects.toMatchObject({code:'compose_desktop_managed'})
+})
+
+it('locks Compose capacity and binds existing desktops without allowing cross-account reuse',async()=>{
+ const home=mkdtempSync(join(tmpdir(),'yaoyao-compose-routes-')),store=new WorkspaceStore(home)
+ const desktops=[1,2].map(n=>({id:randomUUID(),name:`共享桌面 ${n}`,socketPath:`/run/yaoyao-desktops/desktop-${n}/desktop.sock`}))
+ const config=loadServerConfig({HERMES_YAOYAO_HOME:home,HERMES_YAOYAO_COMPOSE_DESKTOPS:JSON.stringify(desktops)})
+ const nodes=new WorkspaceNodes(store,config,{} as any),runner={id:randomUUID(),name:'执行端',enabled:true,sourceNodeId:'local',sourceOwner:'_system'}
+ const auth:any={require:(ctx:any)=>({id:ctx.get('x-owner')||'alice'}),requireAdmin:(ctx:any)=>{if(ctx.get('x-admin')!=='yes')throw Object.assign(new Error('管理员权限'),{status:403});return {id:'alice'}}}
+ const hub:any={records:()=>[runner],summary:()=>({online:true,features:['compose-desktops-v1']}),composeDesktops:{status:async()=>desktops.map(d=>({...d,online:true,ready:true}))},localVm:vi.fn()}
+ const shared=new SharedComputers(store,auth,nodes,hub),service=new LocalVmService(store,auth,nodes,hub,shared,config),app=new Koa()
+ app.use(async(ctx,next)=>{try{await next()}catch(e){ctx.status=(e as any).status||500;ctx.body={code:(e as any).code}}});app.use(bodyParser());app.use(service.router().routes())
+ try{
+  expect(await service.status('alice')).toMatchObject({fixedCapacity:true,maxInstances:2,mode:'shared'})
+  for(const [verb,path,body] of [['post','/prepare',{requestId:randomUUID()}],['put','/policy',{requestId:randomUUID(),maxInstances:4,mode:'per-bot'}],['post',`/instances/${desktops[0]!.id}/remove`,{requestId:randomUUID()}]] as const){await request(app.callback())[verb]('/api/app/admin/local-vm'+path).set('x-admin','yes').send(body).expect(409,{code:'compose_desktop_managed'})}
+  const first=store.createAgent('alice',{name:'研究员',profile:'default'}),second=store.createAgent('alice',{name:'写作者',profile:'writer'}),other=store.createAgent('bob',{name:'其他账号',profile:'default'})
+  const bind=(id:string,desktopId:string,owner='alice')=>request(app.callback()).put(`/api/app/agents/${id}/local-vm`).set('x-owner',owner).send({enabled:true,desktopId})
+  await bind(first.id,randomUUID()).expect(400)
+  await bind(first.id,desktops[0]!.id).expect(200);await bind(second.id,desktops[0]!.id).expect(200)
+  for(const id of [first.id,second.id])expect(()=>nodes.requireSource('alice',store.require('alice','agent',id))).not.toThrow()
+  await bind(other.id,desktops[0]!.id,'bob').expect(403)
+  expect((await service.status('bob')).desktops?.[0]?.available).toBe(false)
+  for(const op of ['create','start','stop','recreate','remove'])await request(app.callback()).post(`/api/app/agents/${first.id}/local-vm/${op}`).send({}).expect(409)
+  const child=store.createAgent('alice',{name:'团队新成员',profile:'default',execution:'computer'},{createdByAgentId:first.id,createdFromRunId:randomUUID()})
+  expect(child.computerEnvironmentId).toBe(desktops[0]!.id)
+  expect(hub.localVm).not.toHaveBeenCalled()
+  expect((await service.status('alice')).maxInstances).toBe(2)
+ }finally{nodes.close();await service.close();store.close();rmSync(home,{recursive:true,force:true})}
+})
+
+it('reuses a fixed desktop, rotates authorization and never creates or deletes its container',async()=>{
+ const id=randomUUID(),db=new DatabaseSync(':memory:'),operations:any[]=[],tokens:string[]=[]
+ const relay=vi.fn(async(target:string,op:string,body:any)=>{operations.push({target,op,body});if(op==='list')return [{id,name:'固定桌面',ready:true}];if(target!==id)throw new Error('unknown desktop');if(op==='health')return {instance:'boot-1',ready:true};if(op==='acquire'){const token=randomUUID();tokens.push(token);return {token,instance:'boot-1'}};if(op==='execute')return {stdout:'ok',stderr:'',exitCode:0};return {ok:true}})
+ const provider=new ComposeComputerProvider(randomUUID(),'/fixture',relay),engine=vi.spyOn(provider,'run'),pool=new ComputerPool(db,provider),spec={id,ownerKey:'owner',imageId:COMPOSE_DESKTOP_IMAGE}
+ try{
+  await pool.recover()
+  const first=await pool.acquire(spec,'agent-a',()=>{})
+  await pool.use(first,c=>provider.execute(spec,['pwd'],c))
+  await pool.release(first,true)
+  expect(()=>pool.use(first,async()=>{})).toThrow()
+  const second=await pool.acquire(spec,'agent-b',()=>{})
+  expect(tokens[0]).not.toBe(tokens[1])
+  await pool.release(second)
+  expect(operations.filter(x=>x.op==='release').map(x=>x.body.cancel)).toEqual([false,true])
+  expect(engine).not.toHaveBeenCalled()
+ }finally{await pool.close();db.close()}
+})

+ 27 - 1
tests/server/localVmRoutes.test.ts

@@ -11,6 +11,7 @@ import {WorkspaceStore} from '../../src/server/workspaceStore'
 import {LocalVmService} from '../../src/server/localVm'
 import {LocalVmService} from '../../src/server/localVm'
 import {SharedComputers} from '../../src/server/sharedComputers'
 import {SharedComputers} from '../../src/server/sharedComputers'
 import {HttpError} from '../../src/server/errors'
 import {HttpError} from '../../src/server/errors'
+import {loadServerConfig} from '../../src/server/config'
 
 
 it('protects preparation, removes the old catalog API and scopes sharing to the account and profile',async()=>{
 it('protects preparation, removes the old catalog API and scopes sharing to the account and profile',async()=>{
  const home=mkdtempSync(join(tmpdir(),'local-vm-routes-')),store=new WorkspaceStore(home)
  const home=mkdtempSync(join(tmpdir(),'local-vm-routes-')),store=new WorkspaceStore(home)
@@ -18,7 +19,7 @@ it('protects preparation, removes the old catalog API and scopes sharing to the
  const auth:any={require:(ctx:any)=>({id:ctx.get('x-owner')||'alice'}),requireAdmin:(ctx:any)=>{if(ctx.get('x-admin')!=='yes'||!active)throw new HttpError(403,'需要管理员权限','admin_required');return {id:'alice'}},isAdminActive:()=>active,pushAuthorizationVersion:()=>version}
  const auth:any={require:(ctx:any)=>({id:ctx.get('x-owner')||'alice'}),requireAdmin:(ctx:any)=>{if(ctx.get('x-admin')!=='yes'||!active)throw new HttpError(403,'需要管理员权限','admin_required');return {id:'alice'}},isAdminActive:()=>active,pushAuthorizationVersion:()=>version}
  const runner={id:randomUUID(),enabled:true,sourceNodeId:'local',sourceOwner:'_system'}
  const runner={id:randomUUID(),enabled:true,sourceNodeId:'local',sourceOwner:'_system'}
  const nodes:any={requireSource:vi.fn()}
  const nodes:any={requireSource:vi.fn()}
- const hub:any={records:()=>[runner],summary:()=>({online:true}),localVm:vi.fn(async()=>({configured:true,daemonUp:true,image:true,mode:'per-bot',maxInstances:2,busy:false})),computer:vi.fn(async()=>({container:'running',ready:true}))}
+ const hub:any={records:()=>[runner],summary:()=>({online:true,features:['local-vm-v1']}),localVm:vi.fn(async()=>({configured:true,daemonUp:true,image:true,mode:'per-bot',maxInstances:2,busy:false})),computer:vi.fn(async()=>({container:'running',ready:true}))}
  const shared=new SharedComputers(store,auth,nodes,hub),service=new LocalVmService(store,auth,nodes,hub,shared,{home} as any),app=new Koa()
  const shared=new SharedComputers(store,auth,nodes,hub),service=new LocalVmService(store,auth,nodes,hub,shared,{home} as any),app=new Koa()
  app.use(async(ctx,next)=>{try{await next()}catch(e){ctx.status=(e as any).status||500;ctx.body={error:String(e)}}});app.use(bodyParser());app.use(service.router().routes())
  app.use(async(ctx,next)=>{try{await next()}catch(e){ctx.status=(e as any).status||500;ctx.body={error:String(e)}}});app.use(bodyParser());app.use(service.router().routes())
  try{
  try{
@@ -58,3 +59,28 @@ it('protects preparation, removes the old catalog API and scopes sharing to the
   active=false;expect(service.allowed(id,runner.id)).toBe(false)
   active=false;expect(service.allowed(id,runner.id)).toBe(false)
  }finally{store.close();rmSync(home,{recursive:true,force:true})}
  }finally{store.close();rmSync(home,{recursive:true,force:true})}
 })
 })
+it('uses the external Runner in Docker and reports missing, offline and incompatible nodes without probing the Web container',async()=>{
+ const home=mkdtempSync(join(tmpdir(),'local-vm-docker-')),store=new WorkspaceStore(home)
+ let records:any[]=[],online=false,features:string[]=[]
+ const auth:any={requireAdmin:()=>({id:'alice'})},nodes:any={open:vi.fn(),requireSource:vi.fn()}
+ const hub:any={records:()=>records,summary:()=>({online,features}),localVm:vi.fn(async()=>({configured:true,runtime:'docker',daemonUp:true,image:true,mode:'per-bot',maxInstances:2,busy:false})),enroll:vi.fn()}
+ const config=loadServerConfig({HERMES_YAOYAO_HOME:home,HERMES_YAOYAO_LOCAL_VM_HOST:'runner'})
+ const shared=new SharedComputers(store,auth,nodes,hub),service=new LocalVmService(store,auth,nodes,hub,shared,config)
+ const discover=vi.spyOn(service as any,'discover')
+ const app=new Koa();app.use(async(ctx,next)=>{try{await next()}catch(e){ctx.status=(e as any).status||500;ctx.body={code:(e as any).code}}});app.use(bodyParser());app.use(service.router().routes())
+ try{
+  expect((await service.status('alice'))).toMatchObject({configured:false,executionHost:'runner',setupRequired:'runner'})
+  await request(app.callback()).post('/api/app/admin/local-vm/prepare').send({requestId:randomUUID()}).expect(409,{code:'local_vm_runner_required'})
+  expect(hub.enroll).not.toHaveBeenCalled()
+  records=[{id:randomUUID(),name:'Hermes 所在电脑',enabled:true,sourceNodeId:'local',sourceOwner:'_system'}]
+  expect(await service.status('alice')).toMatchObject({setupRequired:'runner',runnerName:'Hermes 所在电脑'})
+  online=true
+  expect(await service.status('alice')).toMatchObject({setupRequired:'worker'})
+  features=['local-vm-v1']
+  expect(await service.status('alice')).toMatchObject({executionHost:'runner',image:true,daemonUp:true})
+  // Migrated desktop state must not launch a host-specific Python path in Docker.
+  store.put('_system','local-vm-managed','local',{sealed:'unusable-desktop-config'})
+  await service.start('http://127.0.0.1:15300')
+  expect(nodes.open).not.toHaveBeenCalled();expect(discover).not.toHaveBeenCalled()
+ }finally{await service.close();store.close();rmSync(home,{recursive:true,force:true})}
+})

+ 61 - 0
tests/server/messageFiles.test.ts

@@ -0,0 +1,61 @@
+// @vitest-environment node
+import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { expect, it, vi } from 'vitest'
+import { WorkspaceStore } from '../../src/server/workspaceStore'
+import { WorkspaceAssets, type StoredWorkspaceFile } from '../../src/server/workspaceAssets'
+import type { WorkspaceNodes } from '../../src/server/workspaceGateway'
+import type { WorkspaceMessage, WorkspaceConversation } from '../../src/shared/workspace'
+import { messageFileReferences, nativeMessageFileText } from '../../src/shared/messageFiles'
+
+it('archives only message references and reconciles legacy associations without deleting bytes or logs', async () => {
+  const home = mkdtempSync(join(tmpdir(), 'yaoyao-message-files-'))
+  const store = new WorkspaceStore(home)
+  const request = vi.fn(async (_route: string, _options: { search: URLSearchParams }) => ({ status: 200, body: Buffer.from('report'), headers: new Headers({ 'content-type': 'text/plain' }) }))
+  const assets = new WorkspaceAssets(store, { target: () => ({ session: { request } }) } as unknown as WorkspaceNodes, home)
+  try {
+    const agent = store.createAgent('owner', { name: 'Agent', profile: 'default' })
+    const conversation = store.list<WorkspaceConversation>('owner', 'conversation')[0]!
+    const message: WorkspaceMessage = {
+      id: 'reply', conversationId: conversation.id, agentId: agent.id, seq: 0, role: 'assistant',
+      content: '<think>[hidden](/tmp/thinking.pdf)</think>[报告](sandbox:/tmp/report.txt)',
+      reasoning: '[思考](/tmp/reasoning.pdf)', tools: [{ arguments: { path: '/tmp/input.pdf' }, result: { path: '/tmp/process.pdf' } }],
+      status: 'complete', attachments: [], createdAt: Date.now(),
+    }
+    store.saveMessage('owner', message)
+    await assets.archive('owner', message)
+    expect(request).toHaveBeenCalledTimes(1)
+    expect(request.mock.calls[0]?.[1]?.search.get('path')).toBe('/tmp/report.txt')
+    // Reproduce an old archive which mixed a tool path into the message.
+    await assets.archiveText('owner', '[old](/tmp/process.pdf)', 'local', 'default', conversation.id, message.id)
+    const all = store.list<StoredWorkspaceFile>('owner', 'file')
+    for (const file of all) {
+      delete file.messageFileSource
+      store.put('owner', 'file', file.id, file)
+    }
+    message.attachments = all
+    store.saveMessage('owner', message)
+    expect(store.messages('owner', conversation.id)[0]?.attachments.map(file => file.name)).toEqual(['report.txt'])
+    expect(store.visibleFiles('owner').map(file => file.name)).toEqual(['report.txt'])
+    const replay = store.events('owner', 0).filter(event => event.type === 'message.changed').at(-1)!
+    expect((replay.data as WorkspaceMessage).attachments.map(file => file.name)).toEqual(['report.txt'])
+    expect(store.get<WorkspaceMessage>('owner', 'message', message.id)?.tools).toEqual(message.tools)
+    expect(all.every(file => readFileSync(file.path, 'utf8') === 'report')).toBe(true)
+    message.content += '\n[交付过程文件](/tmp/process.pdf)'
+    store.saveMessage('owner', message)
+    expect(store.visibleFiles('owner')).toHaveLength(2)
+    expect(store.visibleFiles('another-owner')).toEqual([])
+  } finally { assets.close(); store.close(); rmSync(home, { recursive: true, force: true }) }
+})
+
+it('does not scan native reasoning, tool data, code examples or unfinished thinking', () => {
+  const text = nativeMessageFileText({
+    text: '[交付](/tmp/report.pdf)', reasoning: '/tmp/reasoning.pdf',
+    tools: [{ result: { path: '/tmp/process.pdf' } }],
+    attachments: [{ path: '/tmp/attached.pdf', name: 'attached.pdf' }],
+  })
+  expect([...messageFileReferences(text)]).toEqual(['/tmp/report.pdf', '/tmp/attached.pdf'])
+  expect(nativeMessageFileText({ role: 'tool', content: '[过程](/tmp/process.pdf)' })).toBe('')
+  expect([...messageFileReferences('```json\n{"path":"/tmp/process.pdf"}\n```\n<think>![图](/tmp/hidden.png)')]).toEqual([])
+})

+ 8 - 0
tests/server/runnerConfig.test.ts

@@ -1,6 +1,8 @@
 // @vitest-environment node
 // @vitest-environment node
 import {expect,it} from 'vitest'
 import {expect,it} from 'vitest'
 import {randomUUID} from 'node:crypto'
 import {randomUUID} from 'node:crypto'
+import {homedir} from 'node:os'
+import {join} from 'node:path'
 import {parseRunnerConfiguration} from '../../src/runner/config'
 import {parseRunnerConfiguration} from '../../src/runner/config'
 const config={protocol:1,runnerId:randomUUID(),token:'secret-fixture-'.repeat(3),serverURL:'https://example.invalid',hermesURL:'http://127.0.0.1:9119',allowedProfiles:['default'],artifactRoots:[]}
 const config={protocol:1,runnerId:randomUUID(),token:'secret-fixture-'.repeat(3),serverURL:'https://example.invalid',hermesURL:'http://127.0.0.1:9119',allowedProfiles:['default'],artifactRoots:[]}
 it.each([
 it.each([
@@ -27,3 +29,9 @@ it('keeps existing computer configurations offline unless public access is expli
   expect(parseRunnerConfiguration({...config,computers:{...computers,network:'public-proxy'}}).computers?.network).toBe('public-proxy')
   expect(parseRunnerConfiguration({...config,computers:{...computers,network:'public-proxy'}}).computers?.network).toBe('public-proxy')
   expect(()=>parseRunnerConfiguration({...config,computers:{...computers,network:'host'}})).toThrow()
   expect(()=>parseRunnerConfiguration({...config,computers:{...computers,network:'host'}})).toThrow()
 })
 })
+it('resolves optional Hermes paths on the execution host while preserving explicit installation paths',()=>{
+ const computers={runtime:'docker',imageId:'sha256:'+'0'.repeat(64)}
+ expect(parseRunnerConfiguration({...config,computers}).computers).toMatchObject({hermesHome:join(homedir(),'.hermes'),hermesSource:join(homedir(),'.hermes','hermes-agent'),python:join(homedir(),'.hermes','hermes-agent','venv','bin','python')})
+ expect(parseRunnerConfiguration({...config,computers:{...computers,hermesHome:'/custom/hermes',hermesSource:'/custom/source',python:''}}).computers?.python).toBe('/custom/source/venv/bin/python')
+ expect(()=>parseRunnerConfiguration({...config,computers:{...computers,hermesHome:'relative'}})).toThrow()
+})

Некоторые файлы не были показаны из-за большого количества измененных файлов