#!/usr/bin/env node /** * seewo-kit MCP server(stdio) * * 补希沃自带 MCP 的缺口: * 动画三件套 · 课件自检 · 备份/恢复 · 跨课件复制页面 · 批量改文字 * * 启动方式(OpenCode 配置): * "seewokit": { "type": "local", "command": ["node", "D:\\Documents\\Default Project\\seewo-anim\\kit\\server.mjs"] } * * 写操作内部会:关课件(不保存) → 自动备份 → 改缓存文件 → 更新索引/DB → 重新打开。 * 前提:目标课件的未同步改动必须已经同步(内存页数/大小与磁盘不一致时会拒绝,除非 force=true)。 */ import { createInterface } from 'node:readline'; import { setAnimations, getAnimations, clearAnimations, replaceText, verifyCourseware, backupCourseware, restoreCourseware, copySlides, listCoursewares, syncCourseware, pruneOrphanFiles, removeLocalCourseware, inspectCourseware, setTextStyle, listBackups, deleteSlides, moveSlides, diffCourseware, preflightCourseware, undoLastEdit, batchReplaceText, batchSetTextStyle, batchInspect, layoutElements, setSlideTransition, exportSlides, styleTextRange, } from './core.mjs'; const log = (...a) => console.error('[seewo-kit]', ...a); const TOOLS = [ { name: 'set_animations', description: '给页面元素加「点击淡入」等动画(FadeIn/Click 默认 0.3 秒)。只改指定元素,其它元素动画保留。\n' + '写操作会先关闭目标课件(不保存内存改动)、自动备份、改缓存、重开课件。\n' + '用 elementIds 或 textMatches 选元素;order 可指定点击顺序(元素 Id 数组)。\n' + '注意:课件若有未同步的新页/改动会被拒绝,请先同步或传 force=true。', inputSchema: { type: 'object', properties: { courseware: { type: 'string', description: '课件名片段或 LocalId;不传取最近修改的课件' }, page: { type: 'integer', minimum: 1, description: '页码(1-based,按 Board.xml 页序)' }, elementIds: { type: 'array', items: { type: 'string' }, description: '元素 Id(32 位 hex)' }, textMatches: { type: 'array', items: { type: 'string' }, description: '按文字包含匹配元素;多个命中会报错' }, matchAll: { type: 'boolean', default: false, description: 'textMatches 命中多个时全部选中' }, type: { type: 'string', enum: ['FadeIn', 'FadeOut', 'WipeIn', 'WipeOut', 'ZoomIn', 'ZoomOut', 'FlyIn', 'FloatIn', 'Appear'], default: 'FadeIn', }, trigger: { type: 'string', enum: ['Click', 'WithPrevious', 'AfterPrevious'], default: 'Click' }, duration: { type: 'number', default: 0.3, description: '秒' }, delay: { type: 'number', default: 0, description: '秒' }, order: { type: 'array', items: { type: 'string' }, description: '点击顺序(元素 Id 数组),可选' }, reopen: { type: 'boolean', default: true, description: '改完重新打开课件' }, sync: { type: 'boolean', default: false, description: '重开后立即云同步' }, force: { type: 'boolean', default: false, description: '忽略未同步检查(会丢内存里未保存的改动)' }, backup: { type: 'boolean', default: true, description: '改动前自动备份' }, }, required: ['page'], }, }, { name: 'get_animations', description: '读取某页的动画:每个动画的类型/触发方式/时长/延迟/点击顺序,以及 AnimationOrders 的一致性问题。只读。', inputSchema: { type: 'object', properties: { courseware: { type: 'string', description: '课件名片段或 LocalId' }, page: { type: 'integer', minimum: 1, description: '页码(1-based)' }, }, required: ['page'], }, }, { name: 'clear_animations', description: '清除动画:传 elementIds 只清这些元素;不传则清整页;allPages=true 清全部页面。\n' + '会同步重建 AnimationOrders。写操作流程同 set_animations。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, allPages: { type: 'boolean', default: false }, elementIds: { type: 'array', items: { type: 'string' } }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, }, }, { name: 'replace_text', description: '批量修改文本内容(希沃自带 edit_text_element 不能改文字)。\n' + 'replacements 每项:{ elementId 或 find, text 或 (find+replace), width? }\n' + '· text:整段替换(要求该元素只有一个不同文本片段)\n' + '· find+replace:子串替换;同一页命中多个时加 elementId 或 matchAll=true\n' + '· width:可选,传了就按「固定框宽 + 单行折行」重排(适合正文 1160)\n' + 'page 单页,或 pages 多页,或 allPages=true 全部页。\n' + 'dryRun=true 只预览改动,不关课件、不写文件。写操作流程同 set_animations。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 }, description: '多页模式:页码数组' }, allPages: { type: 'boolean', default: false, description: '全部页面' }, replacements: { type: 'array', items: { type: 'object', properties: { elementId: { type: 'string' }, find: { type: 'string' }, replace: { type: 'string' }, text: { type: 'string' }, width: { type: 'number' }, }, }, }, matchAll: { type: 'boolean', default: false, description: 'find 命中多个时全部替换' }, dryRun: { type: 'boolean', default: false, description: '只预览,不写文件、不关/开课件' }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, required: ['replacements'], }, }, { name: 'inspect_courseware', description: '按 Board 页序检查课件内容(只读):每页元素 Id、文字、字号、加粗、颜色、位置、是否带动画、点击顺序,' + '以及可能的超宽行。\n' + 'page 单页;pages 多页;不传则全部页(多页默认只给摘要,不展开每页元素)。\n' + 'query 可全课件搜索文字,返回匹配的页码/元素 Id;format="text" 返回人读清单。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, query: { type: 'string', description: '按文字包含搜索(全课件)' }, includeElements: { type: 'boolean', description: '是否展开每页元素;默认单页/双页展开,多页只给摘要' }, includeAnimations: { type: 'boolean', default: true }, format: { type: 'string', enum: ['json', 'text'], default: 'json' }, }, }, }, { name: 'set_text_style', description: '批量改文本样式(不换文字):字号、加粗、颜色、对齐、文本框宽度。\n' + '用 elementIds / textMatches 选元素;都不传则改所选页的全部文本(建议先 dryRun 预览)。\n' + 'page 单页,或 pages 多页,或 allPages=true 全部页。\n' + '颜色用 #RRGGBB 或 #AARRGGBB;改字号后会自动更新折行缓存。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, allPages: { type: 'boolean', default: false }, elementIds: { type: 'array', items: { type: 'string' } }, textMatches: { type: 'array', items: { type: 'string' } }, matchAll: { type: 'boolean', default: false }, fontSize: { type: 'number', minimum: 1 }, bold: { type: 'boolean' }, color: { type: 'string', description: '#RRGGBB 或 #AARRGGBB' }, align: { type: 'string', enum: ['Left', 'Center', 'Right'] }, width: { type: 'number', minimum: 1, description: '文本块宽度,可选' }, dryRun: { type: 'boolean', default: false, description: '只预览,不写文件、不关/开课件' }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, }, }, { name: 'list_backups', description: '列出本地备份快照(backupId / 时间 / 备注 / 页数 / Revision),可按课件过滤。' + 'restore_courseware 需要的 backupId 就从这个列表取。只读。', inputSchema: { type: 'object', properties: { courseware: { type: 'string', description: '课件名片段或 LocalId;不传列全部' }, limit: { type: 'integer', minimum: 1, default: 50 }, }, }, }, { name: 'delete_slides', description: '按页删除页面:重写 Board.xml 页序、索引 Slides\\Slide_N 映射和 DB。\n' + '页面文件默认移到 %TEMP%\\opencode\\seewo-kit-trash,不会硬删除;至少保留 1 页。\n' + '删除后可用 prune_orphan_files 清理不再被索引引用的资源文件。写操作流程同 set_animations。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, pages: { type: 'array', items: { type: 'integer', minimum: 1 }, description: '要删除的页码(按当前页序)' }, trash: { type: 'boolean', default: true, description: 'true=移到回收目录,false=直接删除' }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, required: ['pages'], }, }, { name: 'move_slides', description: '调整页面顺序:from+to 把第 from 页移到第 to 个位置;或用 order 传完整新页序(当前页码数组)。\n' + '只重写 Board.xml 和索引映射,不改页面内容。写操作流程同 set_animations。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, from: { type: 'integer', minimum: 1, description: '当前页码' }, to: { type: 'integer', minimum: 1, description: '移动后的新位置' }, order: { type: 'array', items: { type: 'integer', minimum: 1 }, description: '完整新页序(当前页码),如 [3,1,2]' }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, }, }, { name: 'verify_courseware', description: '课件自检(只读):页数、Board.xml 页序、索引与磁盘文件的 MD5/大小、重复 Id、图片资源引用、' + 'DB 里的 Revision/行数是否一致、孤儿文件,以及每页动画数(animations / animationTotal)。' + '返回 { ok, issues[] }。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, hashes: { type: 'boolean', default: true, description: '是否逐文件校验 MD5(大课件会慢一点)' }, deep: { type: 'boolean', default: true, description: '是否跨页检查重复元素 Id' }, }, }, }, { name: 'backup_courseware', description: '把课件的全部缓存文件 + 索引 JSON + DB 行快照到临时目录,返回 backupId(可用于 restore_courseware)。只读不改课件。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, note: { type: 'string', description: '备注,写进 manifest' }, }, }, }, { name: 'restore_courseware', description: '从 backup_courseware 的快照恢复(覆盖当前缓存文件与索引/DB)。必须传 confirm=true。\n' + '默认 keepIdentity=true:只恢复内容,保留当前课件的 Name/RemoteId,避免把本地指针指到备份里的另一份云端副本。\n' + '恢复是本地操作:Revision 会比当前值再 +1,不会自动上传;需要时传 sync=true。', inputSchema: { type: 'object', properties: { backupId: { type: 'string', description: 'backup_courseware 返回的 backupId' }, courseware: { type: 'string', description: '覆盖到哪份课件;默认用备份里的 LocalId' }, confirm: { type: 'boolean', description: '必须为 true' }, keepIdentity: { type: 'boolean', default: true, description: '保留当前 Name/RemoteId(推荐)' }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, }, required: ['backupId', 'confirm'], }, }, { name: 'prune_orphan_files', description: '清理课件目录里「存在但未被索引引用」的旧文件(每次恢复/复制都会堆积)。\n' + '默认 dryRun=true 只预览;真正清理需要 dryRun=false + confirm=true。\n' + '清理前会自动备份,文件移进 %TEMP%\\opencode\\seewo-kit-orphans,不会硬删除。', inputSchema: { type: 'object', properties: { courseware: { type: 'string', description: '课件名片段或 LocalId' }, dryRun: { type: 'boolean', default: true, description: 'true=只列出将要清理的文件' }, confirm: { type: 'boolean', default: false, description: 'dryRun=false 时必须为 true' }, force: { type: 'boolean', default: false, description: '忽略未同步检查' }, backup: { type: 'boolean', default: true }, reopen: { type: 'boolean', default: true, description: '原本开着的话,清理后重新打开' }, }, }, }, { name: 'remove_local_courseware', description: '移除本地重复课件:关闭课件 → 把缓存目录移到 %TEMP%\\opencode\\seewo-kit-trash → 删除 Courseware / CoursewareFile 记录。\n' + '只影响本地缓存和 DB,不会删除云端课件。必须传 confirm=true。', inputSchema: { type: 'object', properties: { courseware: { type: 'string', description: '课件名片段或 LocalId(重名时必须用 LocalId)' }, confirm: { type: 'boolean', description: '必须为 true' }, force: { type: 'boolean', default: false, description: '忽略未同步检查' }, trash: { type: 'boolean', default: true, description: 'true=移到回收目录,false=直接删除' }, }, required: ['confirm'], }, }, { name: 'copy_slides', description: '把源课件的指定页复制到目标课件(可跨课件),保留图片/音频等资源、动画和备注。\n' + 'position:插入到目标第几页之后(0=最前面,不传=末尾)。\n' + '会重建目标课件的 Board.xml 页序、索引和 DB;复制页的页面/元素/动画 Id 全部重新生成,避免冲突。\n' + '写操作流程同 set_animations(自动备份 + 重开)。', inputSchema: { type: 'object', properties: { source: { type: 'string', description: '源课件名片段或 LocalId' }, target: { type: 'string', description: '目标课件名片段或 LocalId' }, pages: { type: 'array', items: { type: 'integer', minimum: 1 }, description: '源课件页码(按页序)' }, position: { type: 'integer', minimum: 0, description: '插入到目标第几页之后,0=最前,不传=末尾' }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, required: ['source', 'target', 'pages'], }, }, { name: 'list_coursewares', description: '列出本地缓存里的课件(名称、LocalId、页数、Revision),排错时用。只读。', inputSchema: { type: 'object', properties: {} }, }, { name: 'sync_courseware', description: '只做云同步,不改内容:课件没开会先打开,然后做一次无害改动(加页+删页)让希沃认为「有更新」,再上传。\n' + '用于把本地 Revision 脏状态清干净,或把本地改动推上云。返回同步结果与 isSynced。', inputSchema: { type: 'object', properties: { courseware: { type: 'string', description: '课件名片段或 LocalId' }, }, }, }, { name: 'diff_courseware', description: '对比两份课件,或「某次备份 vs 当前课件」。按 Board 页序逐页比较文字、字号/加粗/颜色、动画、页面切换;' + '可选比较位置尺寸。默认只返回有变化的页。pages 可只看指定页码。只读。', inputSchema: { type: 'object', properties: { a: { type: 'string', description: '课件 A:名称片段或 LocalId' }, b: { type: 'string', description: '课件 B:名称片段或 LocalId' }, backupId: { type: 'string', description: '传了就对比「备份(A)vs 当前课件(B)」' }, courseware: { type: 'string', description: 'backupId 模式下对比的当前课件;默认用备份里的 LocalId' }, pages: { type: 'array', items: { type: 'integer', minimum: 1 }, description: '只对比这些页码' }, maxPages: { type: 'integer', minimum: 1, default: 300, description: '最多对比多少页' }, includeGeometry: { type: 'boolean', default: false, description: '是否比较 X/Y/宽/高' }, includeUnchanged: { type: 'boolean', default: false, description: '是否连没变化的页一起返回' }, }, }, }, { name: 'preflight_courseware', description: '课前自检(只读):在 verify_courseware 基础上检查字号是否统一、文本是否超宽、挖空答案是否一开始就可见、' + '动画是否漏进 AnimationOrders、页面切换覆盖情况,以及本地是否还没同步。' + '返回 { ok, ready, counts, issues, transitions };ready=false 时建议先处理 warnings。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, expectedFontSize: { type: 'number', default: 28, description: '期望正文字号;传 0 可跳过字号检查' }, bodyMinY: { type: 'number', default: 90, description: '只检查 Y ≥ 该值的正文,跳过顶部标题/页眉' }, hashes: { type: 'boolean', default: true, description: '是否逐文件校验 MD5' }, deep: { type: 'boolean', default: true, description: '是否跨页检查重复元素 Id' }, }, }, }, { name: 'undo_last_edit', description: '撤销最近一次 kit 写操作:找到该课件最新一份 note=auto-before-write 的自动备份并恢复。' + '必须传 confirm=true。只恢复内容,保留当前 Name/RemoteId。', inputSchema: { type: 'object', properties: { courseware: { type: 'string', description: '课件名片段或 LocalId' }, confirm: { type: 'boolean', description: '必须为 true' }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, }, required: ['confirm'], }, }, { name: 'batch_replace_text', description: '跨课件批量改文字:对 coursewares 里的每份课件执行 replace_text。\n' + '每份课件各自自动备份(backup=true);默认改完不重新打开(reopen=false),避免批量时反复开关。\n' + 'dryRun=true 只读预览。返回每份课件的成功/失败明细。', inputSchema: { type: 'object', properties: { coursewares: { type: 'array', items: { type: 'string' }, description: '课件名片段或 LocalId 列表' }, allCoursewares: { type: 'boolean', default: false, description: '对本地全部课件批量操作' }, filter: { type: 'string', description: '与 allCoursewares 搭配:只处理名字/LocalId 含这段文字的课件' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, allPages: { type: 'boolean', default: false }, replacements: { type: 'array', items: { type: 'object', properties: { elementId: { type: 'string' }, find: { type: 'string' }, replace: { type: 'string' }, text: { type: 'string' }, width: { type: 'number' }, }, }, }, matchAll: { type: 'boolean', default: false }, dryRun: { type: 'boolean', default: false }, stopOnError: { type: 'boolean', default: false }, reopen: { type: 'boolean', default: false }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, required: ['replacements'], }, }, { name: 'batch_set_text_style', description: '跨课件批量改文本样式:对 coursewares 里的每份课件执行 set_text_style(字号/加粗/颜色/对齐/宽度)。\n' + '默认每份各自备份、改完不重开;dryRun=true 只读预览。', inputSchema: { type: 'object', properties: { coursewares: { type: 'array', items: { type: 'string' } }, allCoursewares: { type: 'boolean', default: false }, filter: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, allPages: { type: 'boolean', default: false }, elementIds: { type: 'array', items: { type: 'string' } }, textMatches: { type: 'array', items: { type: 'string' } }, matchAll: { type: 'boolean', default: false }, fontSize: { type: 'number', minimum: 1 }, bold: { type: 'boolean' }, color: { type: 'string' }, align: { type: 'string', enum: ['Left', 'Center', 'Right'] }, width: { type: 'number', minimum: 1 }, dryRun: { type: 'boolean', default: false }, stopOnError: { type: 'boolean', default: false }, reopen: { type: 'boolean', default: false }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, }, }, { name: 'batch_inspect', description: '跨课件批量检查:对每份课件执行 inspect_courseware,返回各自结果。常与 batch_replace_text 的 dryRun 配合做批量核对。只读。', inputSchema: { type: 'object', properties: { coursewares: { type: 'array', items: { type: 'string' } }, allCoursewares: { type: 'boolean', default: false }, filter: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, query: { type: 'string' }, includeElements: { type: 'boolean' }, includeAnimations: { type: 'boolean', default: true }, format: { type: 'string', enum: ['json', 'text'], default: 'json' }, stopOnError: { type: 'boolean', default: false }, }, }, }, { name: 'layout_elements', description: '页面元素排版:对齐(left/hcenter/right/top/vcenter/bottom)、等距分布、批量缩放/改尺寸、批量移动。\n' + '用 elementIds / textMatches 选元素,或 allElements=true;默认跳过锁定元素。\n' + 'relativeTo=slide(相对页面,可加 margin)/ selection(相对选中元素包围盒)/ element(配合 referenceElementId)。\n' + 'action=distribute 至少 3 个元素;resize 用 scale 或 width/height;move 用 x/y 或 dx/dy。\n' + 'dryRun=true 只预览 before/after,不写文件。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, allPages: { type: 'boolean', default: false }, action: { type: 'string', enum: ['align', 'distribute', 'resize', 'move'], default: 'align' }, align: { type: 'string', enum: ['left', 'hcenter', 'center', 'right', 'top', 'vcenter', 'middle', 'bottom'] }, distribute: { type: 'string', enum: ['horizontal', 'vertical'], default: 'horizontal' }, width: { type: 'number', minimum: 1 }, height: { type: 'number', minimum: 1 }, scale: { type: 'number', minimum: 0.01 }, x: { type: 'number' }, y: { type: 'number' }, dx: { type: 'number' }, dy: { type: 'number' }, elementIds: { type: 'array', items: { type: 'string' } }, textMatches: { type: 'array', items: { type: 'string' } }, matchAll: { type: 'boolean', default: false }, allElements: { type: 'boolean', default: false }, referenceElementId: { type: 'string', description: 'relativeTo=element 时的参考元素 Id' }, relativeTo: { type: 'string', enum: ['slide', 'selection', 'element'], default: 'slide' }, margin: { type: 'number', default: 0, description: 'relativeTo=slide 时距边缘的距离' }, anchor: { type: 'string', enum: ['topleft', 'center'], default: 'topleft', description: 'resize 时以左上角还是中心为基准' }, skipLocked: { type: 'boolean', default: true }, dryRun: { type: 'boolean', default: false }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, }, }, { name: 'set_slide_transition', description: '设置页面切换:transition 可用 none / dissolve / fade / slide-left / circle-out / random-lines,' + '也可直接传希沃的原始 TransitionKey;duration 单位秒。\n' + 'page 单页,或 pages 多页,或 allPages=true。dryRun=true 只预览。写操作流程同 set_animations。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, allPages: { type: 'boolean', default: false }, transition: { type: 'string', default: 'fade', description: '别名或原始 TransitionKey;none=清除切换' }, duration: { type: 'number', minimum: 0, description: '秒;不传则保留原时长' }, dryRun: { type: 'boolean', default: false }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, }, }, { name: 'export_slides', description: '把页面导成 PNG:打开课件(没开会自动打开),逐页调用希沃原生截图接口。\n' + '默认导出全部页;outDir 不传则写到 %TEMP%\\opencode\\seewo-kit-export\\-<时间>。\n' + 'fileNamePattern 支持 {page} 和 {index}(补零)。\n' + '注意:首次截图可能很慢(渲染冷启动)。默认 180 秒超时,超时会停止后续页面并提示重启希沃;' + '确认希沃窗口在前台、课件完整加载后可调大 timeoutSec 重试。只读不改课件。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, allPages: { type: 'boolean', description: '默认 true;也可用 page/pages 指定' }, outDir: { type: 'string', description: '绝对路径,或相对 %TEMP%\\opencode\\seewo-kit-export 的目录名' }, prefix: { type: 'string', default: 'slide' }, fileNamePattern: { type: 'string', description: '如 page-{index}.png' }, openIfNeeded: { type: 'boolean', default: true }, retries: { type: 'integer', minimum: 1, default: 2, description: '非超时错误的重试次数' }, timeoutSec: { type: 'integer', minimum: 30, default: 180, description: '单页截图超时(秒)' }, minBytes: { type: 'integer', minimum: 0, default: 2048, description: '小于这个字节数视为失败并删除空文件' }, stopOnError: { type: 'boolean', default: true, description: '失败后是否停止后续页面(推荐 true)' }, settleMs: { type: 'integer', minimum: 0, default: 600 }, }, }, }, { name: 'style_text_range', description: '段内富文本:只给元素里匹配 find 的那一段文字改字号/加粗/颜色,其余文字样式不变。\n' + '只处理匹配完整落在单个 TextRun 内的情况;跨 TextRun 会报 missing 并说明原因。\n' + '用 elementIds / textMatches 选元素;都不传则在该页所有文本里找 find。支持 dryRun。', inputSchema: { type: 'object', properties: { courseware: { type: 'string' }, page: { type: 'integer', minimum: 1 }, pages: { type: 'array', items: { type: 'integer', minimum: 1 } }, allPages: { type: 'boolean', default: false }, elementIds: { type: 'array', items: { type: 'string' } }, textMatches: { type: 'array', items: { type: 'string' } }, matchAll: { type: 'boolean', default: false }, find: { type: 'string', description: '要单独上样式的那段文字' }, fontSize: { type: 'number', minimum: 1 }, bold: { type: 'boolean' }, color: { type: 'string', description: '#RRGGBB 或 #AARRGGBB' }, dryRun: { type: 'boolean', default: false }, reopen: { type: 'boolean', default: true }, sync: { type: 'boolean', default: false }, force: { type: 'boolean', default: false }, backup: { type: 'boolean', default: true }, }, required: ['find'], }, }, ]; const HANDLERS = { set_animations: setAnimations, get_animations: getAnimations, clear_animations: clearAnimations, replace_text: replaceText, inspect_courseware: inspectCourseware, set_text_style: setTextStyle, list_backups: listBackups, delete_slides: deleteSlides, move_slides: moveSlides, verify_courseware: verifyCourseware, backup_courseware: backupCourseware, restore_courseware: restoreCourseware, copy_slides: copySlides, sync_courseware: syncCourseware, prune_orphan_files: pruneOrphanFiles, remove_local_courseware: removeLocalCourseware, diff_courseware: diffCourseware, preflight_courseware: preflightCourseware, undo_last_edit: undoLastEdit, batch_replace_text: batchReplaceText, batch_set_text_style: batchSetTextStyle, batch_inspect: batchInspect, layout_elements: layoutElements, set_slide_transition: setSlideTransition, export_slides: exportSlides, style_text_range: styleTextRange, list_coursewares: () => { const all = listCoursewares(); let dbCountHint = null; return { dbCountHint, coursewares: all.slice(0, 50).map(c => ({ name: c.name, localId: c.localId, pages: (c.json.CoursewareFiles || []).filter(f => /^Slides[\\/]Slide_\d+\.xml$/i.test(f.RelativePath)).length, revision: c.json.Courseware.Revision, syncedRevision: c.json.Courseware.SyncedRevision, size: c.json.Courseware.Size, modified: new Date(c.mtime).toISOString(), })), }; }, }; function send(msg) { process.stdout.write(JSON.stringify(msg) + '\n'); } async function handle(msg) { const { id, method, params = {} } = msg; if (method === 'initialize') { return send({ jsonrpc: '2.0', id, result: { protocolVersion: params.protocolVersion || '2025-06-18', capabilities: { tools: { listChanged: false } }, serverInfo: { name: 'seewo-kit', version: '1.0.0' }, }, }); } if (method === 'notifications/initialized' || !('id' in msg)) return; if (method === 'ping') return send({ jsonrpc: '2.0', id, result: {} }); if (method === 'tools/list') return send({ jsonrpc: '2.0', id, result: { tools: TOOLS } }); if (method === 'tool.call') { /* 有些客户端用这个别名 */ } if (method === 'tools/call') { const name = params.name; const fn = HANDLERS[name]; if (!fn) { return send({ jsonrpc: '2.0', id, error: { code: -32602, message: `未知工具:${name}` } }); } try { const out = await fn(params.arguments ?? {}); return send({ jsonrpc: '2.0', id, result: { content: [{ type: 'text', text: JSON.stringify(out, null, 2) }] }, }); } catch (e) { log(name, '失败:', e.stack || e.message); return send({ jsonrpc: '2.0', id, result: { content: [{ type: 'text', text: '错误:' + (e.message || String(e)) }], isError: true }, }); } } send({ jsonrpc: '2.0', id, error: { code: -32601, message: `不支持的方法:${method}` } }); } const rl = createInterface({ input: process.stdin, crlfDelay: Infinity }); rl.on('line', line => { const s = line.trim(); if (!s) return; let msg; try { msg = JSON.parse(s); } catch (e) { log('坏消息:', s.slice(0, 200)); return; } handle(msg).catch(e => { log('处理失败:', e.stack || e.message); if ('id' in msg) send({ jsonrpc: '2.0', id: msg.id, error: { code: -32603, message: String(e.message || e) } }); }); }); rl.on('close', () => process.exit(0)); log('ready');