officecli 迁入技能层:skills/office 封装 + executor 预览托管,双盘同步整条退役

- skills/office:SKILL.md + scripts/office 封装层(命令闸门/help 对齐/get-pos 语义糖/create、open 出 ui_card
  marker);install.sh 按技能双跑约定把二进制拉到技能卷 bin/(不进 git/不进镜像,GitHub→gh-proxy 备源)
- executor/preview.js:预览槽位+网关(原 mcp 侧 watch/gateway 移植),工作区=tasks 卷真实文件,
  /__session-kill 供 core 清槽;Dockerfile 零 officecli 痕迹,入口符号链接进 /usr/local/bin/office
- core:preview-proxy 默认上游改 agent-executor:3100;tools/executor.js 通用 drainUiCards(terminal 输出
  ::ui_card 标记行 → 剥离 + ctx.onCard,任意命令可产卡);engine 删会话改走 rexec.killPreviewSession
- compose:agent-executor expose 3100(只走内网);.gitignore 排除技能二进制
This commit is contained in:
2026-10-19 11:30:12 +08:00
parent 6c1aebd01f
commit 5f4b3ec28b
13 changed files with 624 additions and 54 deletions
+37
View File
@@ -0,0 +1,37 @@
---
name: office
description: Office 文档(docx/xlsx/pptx)创建、精确编辑、结构检视与聊天实时预览
---
## 功能
Word / Excel / PPT(.docx/.xlsx/.pptx)的创建、读取、精确修改与结构检视。文档直接读写当前任务目录的文件,无需任何同步动作。
## 调用方式
所有操作通过 terminal 工具执行同一个入口脚本(cwd 已是任务目录,直接用相对文件名):
```
office <command> [args...]
```
先用 `office help` 看命令清单,用 `office help <主题>`(如 `office help docx paragraph`)查具体元素的属性 schema——参数与属性以 help 为准,不要凭记忆猜。
常用动线:
- `office create <file>` 新建文档(成功后聊天流出现预览卡片,用户点击即可实时预览)
- `office open <file>` 打开已有文档(同样出预览卡片)
- `office set / get / query <file> ...` 按 schema 精确改动与读取;每次改动自动落盘
- `office view <file> outline|stats|issues|text` 结构/语义自检(交付前建议跑一遍 issues)
- `office save / close <file>` 收尾(改动已自动落盘,save 只是显式冲刷)
- `office get-pos <file>` 回读用户在预览里选中的内容(返回 JSON,path 里的 @id 可稳定用于后续 set/get 定位)
## 预览协作
create/open 成功后无需拼链接、无需等待:聊天流自动出可点击的预览卡片,用户点开即是该文档的实时预览(预览页上的选区、标注类交互之后都能被 get-pos 读到)。用户反馈"看第几段/选中了哪里"时,用 get-pos 读回再针对性改。
## 注意
- 文档就在任务目录里:文件面板、预览、下载指向同一份文件;不要用 curl 或中转链搬运待编辑的文档。
- `view` 的渲染族(html/screenshot/pdf 等)本环境不可用;要 PDF 用 x2pdf 技能。
- 命令报"文件不存在"时先确认文件是否已在任务目录(`ls`),不要猜路径。
+53
View File
@@ -0,0 +1,53 @@
#!/bin/bash
# office 技能资产与入口(skills/README 5.2 约定:本脚本在「镜像构建(skills 阶段)」与「启动 init」两处都跑,必须幂等):
#
# 1) 资产 bin/officecli —— officecli 官方 .NET 单文件二进制(v1.0.157 linux-x64)。
# 不进 git(.gitignore 已排除 skills/office/bin/)、不进镜像:init 阶段写进宿主 ./skills 卷,
# executor 容器以 :ro 挂到 /workspace/skills —— 运行期只读执行,改动版本=改本文件 pin 重启。
# 构建阶段($HERE 在 /tmp 下,产物即弃)跳过下载,只烘 PATH 入口。
# 主源 GitHub,备源 gh-proxy(国内网络);sha256 必须等于 pin,宁缺毋错。
# 2) PATH 入口 /usr/local/bin/office -> <运行期技能根>/scripts/office —— 构建阶段写进镜像层持久;
# init 阶段根只读,|| true 静默(镜像里已就位)。officecli 二进制刻意不进 PATH:模型只见封装层。
#
# 两个源都拉不到:exit 1(init 不写 marker,下次启动自动重试);救急可手动放置同名二进制到
# skills/office/bin/officecli(sha 对上即认),再 docker compose up -d 重跑 init。
set -u
HERE="$(cd "$(dirname "$0")" && pwd)"
VER=v1.0.157
SHA=f8eefe88dbfa7464bee421e5421efe57fc26bc3180b30e56eef58594c8245c94
ASSET="$HERE/bin/officecli"
ln -sfn "${EXECUTOR_SKILLS_DIR:-/workspace/skills}/office/scripts/office" /usr/local/bin/office 2>/dev/null || true
# 构建阶段:PATH 入口已烘,资产交给 init(避免每次 skills 层重建白拉 35MB)
case "$HERE" in
/tmp/*) echo "[office] build stage: PATH 入口就位;bin/officecli 资产由 init 阶段落到技能卷"; exit 0 ;;
esac
verify() { [ -f "$ASSET" ] && echo "$SHA $ASSET" | sha256sum -c - >/dev/null 2>&1; }
if verify; then
echo "[office] 资产已就位(sha 匹配):$ASSET"
exit 0
fi
mkdir -p "$HERE/bin"
for u in "https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/officecli-linux-x64" \
"https://gh-proxy.com/https://github.com/iOfficeAI/OfficeCLI/releases/download/$VER/officecli-linux-x64"; do
echo "[office] 拉取 $u"
if curl -fsSL --retry 2 -o "$ASSET.tmp" "$u" \
&& echo "$SHA $ASSET.tmp" | sha256sum -c - >/dev/null 2>&1; then
mv -f "$ASSET.tmp" "$ASSET"
chmod 755 "$ASSET"
break
fi
rm -f "$ASSET.tmp"
done
if verify; then
echo "[office] 就绪:$ASSET"
exit 0
else
echo "[office] 两个源都拉不到 bin/officecli —— 手动放置 $ASSET(sha 对上即认)后 docker compose up -d 重试" >&2
exit 1
fi
+117
View File
@@ -0,0 +1,117 @@
#!/usr/bin/env node
// office: officecli 的封装层(技能唯一入口)。
// - 二进制不进 PATH、SKILL.md 不提及:可见面 = 可调用面,模型只认识本脚本;路径可用 OFFICECLI_BIN 覆盖。
// - 命令治理移植自原 MCP 桥:隐去命令报原生风格 unrecognized;view 渲染族拦截给替代路径;
// watch 族不透传(预览由平台托管)。
// - create/open 成功在 stdout 尾行发 ui_card marker(::ui_card {json}::):core 剥离后转聊天流卡片,
// 模型面不感知 marker;arg 为相对 cwd(会话目录)的文件路径。
'use strict';
const { spawnSync } = require('node:child_process');
const path = require('node:path');
const BIN = process.env.OFFICECLI_BIN || path.resolve(__dirname, '..', 'bin', 'officecli');
// 本部署不合适的命令(自锁死 / 装配环境族):原生风格报错,help 清单同步删行(见 help 段)。
const unrecognized = (v) => "Unrecognized command or argument '" + v + "'.";
const HIDDEN_TOP = /^(mcp|skills|install|plugins)(?:\s|$)/;
const HIDDEN_LINE = /^ {2}(?:mcp|skills|install|plugins)\b/; // '\b' 绝不能用字符串拼 RegExp(会变退格符)
const HELP_STRIP = /^ {2}(?:watch|unwatch)\b/;
const HIDDEN_SUBS = new Set(['mark', 'unmark', 'marks', 'goto']); // 标注/滚动族:预览交互由 get-pos 单点覆盖
const VIEW_BLOCKED = new Set(['html', 'screenshot', 'svg', 'pdf', 'forms']); // 需无头浏览器/导出插件,本环境没有
const OFFICE_EXT_RE = /\.(?:docx|xlsx|pptx)$/i;
const CARD_NOTE = { create: '已创建', open: '已打开' };
const err = (msg) => { process.stderr.write(msg + '\n'); process.exit(1); };
// vendor 异常包装拆掉只留内层真错(与原桥 scrubErr 同源)
function scrub(text) {
return String(text).replace(/Resident process exited\.\s*Unhandled exception:\s*[\w.]*Exception:\s*/g, '');
}
function runVendor(argv) {
// 关自动 resident(实测时延零增益,还会堆常驻进程/撞 file_locked);每次改动命令返回前落盘。
const env = Object.assign({}, process.env, {
OFFICECLI_NO_AUTO_RESIDENT: '1',
OFFICECLI_RESIDENT_FLUSH: 'each',
// slim 镜像无 ICU;executor 的 env 白名单不透传,必须在这里自己声明 .NET 不变式模式
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: '1',
});
return spawnSync(BIN, argv, { encoding: 'utf8', env, maxBuffer: 64 * 1024 * 1024 });
}
const argv = process.argv.slice(2);
if (!argv.length) {
process.stdout.write('Usage: office <command> [args...]\nRun `office help` for the full command list.\n');
process.exit(0);
}
const cmd = argv.join(' ');
const first = String(argv[0] || '');
// ---------- 命令面闸门 ----------
let m = HIDDEN_TOP.exec(cmd);
if (m || (first === 'help' && HIDDEN_TOP.test(argv.slice(1).join(' ')))) err(unrecognized(m ? m[1] : argv[1]));
if (HIDDEN_SUBS.has(first)) err(unrecognized(first));
if (first === 'watch' || first === 'unwatch') {
err('Preview slots are managed by the platform: create/open a document, then click the preview card in the chat.');
}
const helpCmd = first === 'help' || /(?:^|\s)(?:--help|-h)(?:\s|$)/.test(cmd);
// view 放开结构/语义模式(outline/stats/issues/text/annotated),只拦渲染族,并给替代路径。
if (!helpCmd && first === 'view') {
const vpos = argv.slice(1).filter((t) => !String(t).startsWith('-')); // [file, mode, ...]
const vmode = String(vpos[1] || '').toLowerCase();
if (VIEW_BLOCKED.has(vmode)) {
err("view " + vmode + " is disabled by environment policy. Use 'view <file> outline' or 'view <file> issues' for structural/semantic checks.");
}
}
// get-pos:语义糖,改写为原生选中回读(用户没在预览里选过时 vendor 返回空结果,不是错误)。
if (first === 'get-pos') {
const file = argv[1];
if (!file) err('Usage: get-pos <file> (works once the user opens the preview and selects something)');
argv = ['get', file, 'selected', '--json'];
}
// ---------- 透传 ----------
let r;
try {
r = runVendor(argv);
} catch (e) {
err(String(e && e.message || e));
}
if (r.error) {
if (r.error.code === 'ENOENT') {
err('officecli binary missing: ' + BIN + ' (skill asset not fetched: docker compose up -d agent-executor-init to retry, or place it per skills/office/install.sh)');
}
err(String(r.error.message || r.error));
}
let outRaw = scrub(r.stdout || '');
// help 文本对齐可调用面:隐去的命令删行(原生 cwd 已是会话目录,无扩展命令需补录)
if (helpCmd && outRaw.includes('Commands:')) {
outRaw = outRaw.split('\n').filter((ln) => !HIDDEN_LINE.test(ln) && !HELP_STRIP.test(ln)).join('\n');
}
if (outRaw) process.stdout.write(outRaw);
if (r.stderr) process.stderr.write(scrub(r.stderr || ''));
// create/open 成功尾行发预览卡片 marker(core 解析后剥离;模型面无感)
if (r.status === 0 && /^(create|open)$/.test(first)) {
let file = null;
for (const t of argv) {
const s = String(t);
if (s.startsWith('-') || s.includes('=')) continue;
if (OFFICE_EXT_RE.test(s)) {
const rel = path.relative(process.cwd(), path.resolve(s));
if (rel && rel !== '.' && !rel.startsWith('..')) file = rel;
break;
}
}
if (file) {
process.stdout.write('\n::ui_card ' + JSON.stringify({
action: 'open_preview', arg: file, title: file, note: CARD_NOTE[first] || '',
}) + '::\n');
}
}
process.exit(r.status === null ? 1 : r.status);