feat: 完善 N7 智能座舱交互与控制链路

This commit is contained in:
vee
2026-09-07 15:34:59 +08:00
parent 32d179143f
commit c96970f068
100 changed files with 30088 additions and 1174 deletions
+31 -2
View File
@@ -1,12 +1,28 @@
FROM node:22-bookworm-slim AS codex-cli
ARG CODEX_CLI_VERSION=0.150.0-alpha.8
RUN npm install --global "@openai/codex@${CODEX_CLI_VERSION}" \
&& codex --version
FROM python:3.12-slim-bookworm
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PYTHONPATH=/app/src:/app/domains/seat/src
PYTHONPATH=/app/src:/app/domains/seat/src \
HOME=/home/cognitive-agent \
CODEX_HOME=/var/lib/codex
WORKDIR /app
RUN apt-get update \
&& apt-get install --yes --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY --from=codex-cli /usr/local/bin/node /usr/local/bin/node
COPY --from=codex-cli /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s ../lib/node_modules/@openai/codex/bin/codex.js /usr/local/bin/codex
COPY pyproject.toml ./
COPY src ./src
COPY apps ./apps
@@ -15,7 +31,20 @@ COPY contracts ./contracts
COPY domains ./domains
COPY platforms ./platforms
RUN python -m pip install --no-cache-dir ".[llm]"
RUN node --version \
&& codex --version \
&& python -m pip install --no-cache-dir ".[llm,speech]" \
&& groupadd --gid 10001 cognitive-agent \
&& useradd --uid 10001 --gid 10001 --create-home cognitive-agent \
&& mkdir -p /var/lib/codex \
/app/artifacts/runs \
/app/artifacts/user-presets \
/app/artifacts/server \
/app/artifacts/tmp \
/app/artifacts/self-repair \
&& chown -R 10001:10001 /var/lib/codex /app/artifacts /home/cognitive-agent
USER 10001:10001
EXPOSE 8000
+51 -3
View File
@@ -13,7 +13,10 @@ The server layout is:
├── .env.auth # Web authentication settings, mode 0600
├── deploy/server/
├── artifacts/runs/ # Persistent request artifacts
└── artifacts/user-presets/
├── artifacts/user-presets/
├── artifacts/server/ # GSCU infrared catalog and server-side state
├── artifacts/tmp/ # Runtime gateway and calibration state
└── artifacts/self-repair/
```
Vehicle-specific user-created function modes are persisted from
@@ -23,12 +26,57 @@ Build and start the service:
```bash
cd /opt/511-project
chown -R root:root artifacts/runs artifacts/user-presets
chmod 0700 artifacts/runs artifacts/user-presets
mkdir -p \
artifacts/runs \
artifacts/user-presets \
artifacts/server \
artifacts/tmp \
artifacts/self-repair \
config/modes/vehicles/denza_n7/user
chown -R 10001:10001 \
artifacts/runs \
artifacts/user-presets \
artifacts/server \
artifacts/tmp \
artifacts/self-repair \
config/modes/vehicles/denza_n7/user
chmod 0700 \
artifacts/runs \
artifacts/user-presets \
artifacts/server \
artifacts/tmp \
artifacts/self-repair \
config/modes/vehicles/denza_n7/user
docker compose -f deploy/server/compose.yaml up -d --build
docker compose -f deploy/server/compose.yaml ps
```
镜像固定安装 `@openai/codex@0.150.0-alpha.8`。AI 助手使用命名卷
`codex_home` 保存 Codex 运行状态;生产环境优先通过只读环境注入
`OPENAI_API_KEY`。若使用 ChatGPT 账号认证,可在首次启动后进入容器完成
Codex 登录,再重启服务。不要把 `auth.json` 复制进镜像或提交到仓库。
```bash
docker compose -f deploy/server/compose.yaml exec web codex login status
curl -fsS http://127.0.0.1:8511/api/health
```
App Server 线程采用 `read-only` sandbox 和线程级 `approvalPolicy=never`,并关闭
内置 shell、统一执行器、浏览器和应用工具;因此命令执行或文件修改不能通过交互式
审批获得额外权限。Codex 子进程只继承启动及模型认证所需的环境变量。容器使用无特权
UID `10001` 和只读根文件系统。
唯一启用的 `n7_vehicle` MCP 服务将工具级
`default_tools_approval_mode=approve` 固定为 `approve`。这与
`approvalPolicy=never` 不矛盾:前者仅避免 App Server 对已经进入 N7Web 安全边界的
MCP 调用再发起一次当前嵌入式网页无法响应的审批,后者仍让 App Server 自身的命令和
文件权限失败关闭。MCP 只开放运行时能力目录查询和回环地址上的座舱执行桥,其中只有
执行桥有副作用。工具令牌绑定原始用户请求,结构化候选计划还会经过原文证据、能力
注册表、参数 Schema、执行模式、车辆硬件审批与安全策略校验;模型不能提交替代指令
或原始 CAN,`approve` 也不会绕过这些应用层门禁。审批字段语义见
[Codex App Server 官方文档](https://learn.chatgpt.com/docs/app-server) 与
[Codex 配置参考](https://learn.chatgpt.com/zh-Hans/docs/config-file/config-reference)。
Add `deploy/server/Caddyfile.example` to the host Caddyfile, validate, and
reload Caddy:
+19 -1
View File
@@ -7,6 +7,7 @@ services:
dockerfile: deploy/server/Dockerfile
image: cognitive-agent-511:latest
container_name: cognitive-agent-511
user: "10001:10001"
restart: unless-stopped
init: true
env_file:
@@ -20,12 +21,26 @@ services:
PYTHONDONTWRITEBYTECODE: "1"
PYTHONUNBUFFERED: "1"
PYTHONPATH: /app/src:/app/domains/seat/src
CODEX_HOME: /var/lib/codex
CODEX_ASSISTANT_WORKSPACE: /tmp/codex-assistant-workspace
CODEX_ASSISTANT_MODEL: gpt-5.6-luna
CODEX_ASSISTANT_REASONING_EFFORT: low
CODEX_ASSISTANT_DISABLE_WEBSOCKETS: "true"
CODEX_ASSISTANT_STREAM_MAX_RETRIES: "1"
CODEX_ASSISTANT_TURN_TIMEOUT_SECONDS: "300"
SPEECH_MODEL_FILE: model.int8.onnx
SPEECH_NUM_THREADS: "2"
ports:
- "127.0.0.1:8511:8000"
volumes:
- ../../artifacts/runs:/app/artifacts/runs
- ../../artifacts/user-presets:/app/artifacts/user-presets
- ../../artifacts/server:/app/artifacts/server
- ../../artifacts/tmp:/app/artifacts/tmp
- ../../artifacts/self-repair:/app/artifacts/self-repair
- ../../artifacts/models:/app/artifacts/models:ro
- ../../config/modes/vehicles/denza_n7/user:/app/config/modes/vehicles/denza_n7/user
- codex_home:/var/lib/codex
read_only: true
tmpfs:
- /tmp:size=64m,mode=1777
@@ -39,7 +54,7 @@ services:
- CMD
- python
- -c
- import urllib.request; urllib.request.urlopen("http://127.0.0.1:8000/login", timeout=3)
- import urllib.request; urllib.request.urlopen("http://127.0.0.1:8000/api/health", timeout=3)
interval: 30s
timeout: 5s
retries: 3
@@ -49,3 +64,6 @@ services:
options:
max-size: 10m
max-file: "3"
volumes:
codex_home: