@steerable/steer 0.3.13 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @steerable/steer
2
2
 
3
- Official command-line interface and terminal TUI (`steer`) for [Steer Agent](https://steeragent.app) (v0.3.13).
3
+ Official command-line interface and terminal TUI (`steer`) for [Steer Agent](https://steeragent.app) (v0.3.15).
4
4
 
5
5
  Runs directly on macOS, Linux (`x64` / `arm64`), and Windows — including headless SSH servers — and automatically pulls the portable Python sidecar runtime for your platform. When installed alongside the Steer desktop app, `steer` shares the same local `~/.steer` workspace history, skills, and model configuration.
6
6
 
@@ -16,6 +16,7 @@ import { EtownStore } from './store.js';
16
16
  import { getChatFilesWorkspace, getChatMaskWorkspace, getChatWordWorkspace, resolveMaskPythonCommand, resolveWordPythonCommand, } from './workspace.js';
17
17
  import { isWordMasterToolCall, listWordDocuments, wordDocumentsSignature, } from './word-preview.js';
18
18
  import { createEtownWordRoutes } from './word-routes.js';
19
+ import { createDocPreviewDeliverableVerifiers } from './deliverable-verifiers.js';
19
20
  /**
20
21
  * 建存储与服务,并注册预览路由和回合钩子。
21
22
  * 同一进程只调用一次;重复调用会让路由匹配先命中先注册者。
@@ -174,6 +175,7 @@ export function createDocumentPreviewPack(deps, packId) {
174
175
  */
175
176
  export function assembleDocumentPreview(deps) {
176
177
  const { pptEditService } = createDocumentPreviewPack(deps, 'doc-preview');
178
+ deps.registerDeliverableVerifiers?.(createDocPreviewDeliverableVerifiers());
177
179
  void pptEditService.restore().then(({ restored, interrupted }) => {
178
180
  if (restored > 0 || interrupted > 0) {
179
181
  deps.onLog(`[ppt-edit] 恢复队列:${restored} 条继续排队,${interrupted} 条标记为已中断`);
@@ -0,0 +1,480 @@
1
+ /**
2
+ * PPT (.pptx) 与 Word (.docx) 标准交付质检器(R6 `DeliverableVerifier`)。
3
+ *
4
+ * 在 `present_files(purpose: 'output')` 归档交付物前执行确定性结构与版式核验:
5
+ * - `doc-preview-ppt`:校验 `.pptx` OOXML/幻灯片结构完整性,并联动会话 PPT 项目的
6
+ * `validation/svg_quality_report.json` 拦截文本溢出、越界等 blocking 版式问题;
7
+ * - `doc-preview-word`:校验 `.docx` OOXML 结构与非空正文、联动 `word_format_report.json`,
8
+ * 并核查公文标准字体(仿宋 / 黑体 / 小标宋)在当前宿主环境的命中与回退情况。
9
+ */
10
+ import { execFile } from 'node:child_process';
11
+ import { access, readFile, readdir } from 'node:fs/promises';
12
+ import path from 'node:path';
13
+ import { promisify } from 'node:util';
14
+ import { unzipSync } from 'fflate';
15
+ import { readPptQualityBlockingIssues, refreshPptQualityReport, } from './export.js';
16
+ import { getChatPptWorkspace } from './preview.js';
17
+ const execFileAsync = promisify(execFile);
18
+ const OFFICIAL_FONT_SPECS = [
19
+ {
20
+ canonical: '仿宋_GB2312',
21
+ matchDeclared: /仿宋|fangsong/i,
22
+ matchInstalled: /仿宋|fangsong/i,
23
+ },
24
+ {
25
+ canonical: '黑体',
26
+ matchDeclared: /^黑体$|^simhei$/i,
27
+ matchInstalled: /黑体|simhei|noto sans cjk|wenquanyi/i,
28
+ },
29
+ {
30
+ canonical: '方正小标宋简体',
31
+ matchDeclared: /小标宋|xiaobiaosong|fzxbs/i,
32
+ matchInstalled: /小标宋|xiaobiaosong|fzxbs/i,
33
+ },
34
+ {
35
+ canonical: '楷体_GB2312',
36
+ matchDeclared: /楷体|kaiti/i,
37
+ matchInstalled: /楷体|kaiti/i,
38
+ },
39
+ ];
40
+ let cachedHostFonts = null;
41
+ async function fileExists(targetPath) {
42
+ try {
43
+ await access(targetPath);
44
+ return true;
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ }
50
+ async function detectHostInstalledFonts() {
51
+ if (cachedHostFonts)
52
+ return cachedHostFonts;
53
+ cachedHostFonts = (async () => {
54
+ const names = new Set();
55
+ const extraDirs = (process.env.DEEPPATH_FONT_DIRS ?? '')
56
+ .split(path.delimiter)
57
+ .map((s) => s.trim())
58
+ .filter(Boolean);
59
+ try {
60
+ const { stdout } = await execFileAsync('fc-list', [':', 'family,file'], {
61
+ timeout: 4_000,
62
+ maxBuffer: 4 * 1024 * 1024,
63
+ });
64
+ for (const line of stdout.split('\n')) {
65
+ const trimmed = line.trim();
66
+ if (trimmed)
67
+ names.add(trimmed);
68
+ }
69
+ }
70
+ catch {
71
+ // 宿主未安装 fontconfig(如精简容器或桌面系统)时退回扫描标准字体目录文件名。
72
+ }
73
+ const candidateDirs = [
74
+ ...extraDirs,
75
+ '/usr/share/fonts',
76
+ '/usr/local/share/fonts',
77
+ '/Library/Fonts',
78
+ '/System/Library/Fonts',
79
+ ];
80
+ const walkFontDir = async (dir, depth) => {
81
+ if (depth > 3)
82
+ return;
83
+ let entries;
84
+ try {
85
+ entries = await readdir(dir, { withFileTypes: true });
86
+ }
87
+ catch {
88
+ return;
89
+ }
90
+ for (const entry of entries) {
91
+ if (entry.isDirectory()) {
92
+ await walkFontDir(path.join(dir, entry.name), depth + 1);
93
+ }
94
+ else if (/\.(ttf|otf|ttc)$/i.test(entry.name)) {
95
+ names.add(entry.name);
96
+ }
97
+ }
98
+ };
99
+ for (const dir of candidateDirs) {
100
+ await walkFontDir(dir, 0);
101
+ }
102
+ return [...names];
103
+ })();
104
+ return cachedHostFonts;
105
+ }
106
+ /** 测试辅助:重置宿主字体探测缓存。 */
107
+ export function resetDocPreviewFontCacheForTests() {
108
+ cachedHostFonts = null;
109
+ }
110
+ async function locatePptProjectForFile(chatId, filePath) {
111
+ const resolvedFile = path.resolve(filePath);
112
+ // 1. 直接位于会话 PPT 工作区 `<pptWorkspace>/<projectId>/...` 下
113
+ try {
114
+ const pptWorkspace = path.resolve(getChatPptWorkspace(chatId));
115
+ if (resolvedFile.startsWith(pptWorkspace + path.sep)) {
116
+ const rel = path.relative(pptWorkspace, resolvedFile);
117
+ const projectId = rel.split(path.sep)[0];
118
+ if (projectId) {
119
+ return {
120
+ projectPath: path.join(pptWorkspace, projectId),
121
+ projectId,
122
+ };
123
+ }
124
+ }
125
+ }
126
+ catch {
127
+ // 非标准 chatId 时继续尝试邻近项目目录推断。
128
+ }
129
+ // 2. 导出文件位于 `<projectPath>/exports/*.pptx` 或 `<projectPath>/*.pptx`
130
+ const parentDir = path.dirname(resolvedFile);
131
+ const grandParentDir = path.dirname(parentDir);
132
+ for (const candidate of [parentDir, grandParentDir]) {
133
+ if ((await fileExists(path.join(candidate, 'validation', 'svg_quality_report.json'))) ||
134
+ (await fileExists(path.join(candidate, 'svg_output')))) {
135
+ return { projectPath: candidate, projectId: null };
136
+ }
137
+ }
138
+ return null;
139
+ }
140
+ async function readPptQualityWarningIssues(projectPath) {
141
+ try {
142
+ const raw = await readFile(path.join(projectPath, 'validation', 'svg_quality_report.json'), 'utf8');
143
+ const parsed = JSON.parse(raw);
144
+ const rawList = parsed.categories?.warning?.issues ?? parsed.categories?.warnings?.issues;
145
+ if (!Array.isArray(rawList))
146
+ return [];
147
+ const warnings = [];
148
+ for (const item of rawList.slice(0, 10)) {
149
+ if (!item || typeof item !== 'object')
150
+ continue;
151
+ const rec = item;
152
+ const msg = typeof rec.message === 'string' ? rec.message.trim() : '';
153
+ const file = typeof rec.file === 'string' ? rec.file.trim() : '';
154
+ if (!msg)
155
+ continue;
156
+ warnings.push({
157
+ severity: 'warning',
158
+ code: 'ppt_svg_quality_warning',
159
+ message: msg,
160
+ ...(file ? { location: file } : {}),
161
+ });
162
+ }
163
+ return warnings;
164
+ }
165
+ catch {
166
+ return [];
167
+ }
168
+ }
169
+ /**
170
+ * 创建 PPTX 交付质检器(`doc-preview-ppt`)。
171
+ */
172
+ export function createPptDeliverableVerifier() {
173
+ return {
174
+ id: 'doc-preview-ppt',
175
+ matchExtensions: ['.pptx'],
176
+ async verify(ctx) {
177
+ let entries;
178
+ try {
179
+ const bytes = await readFile(ctx.filePath);
180
+ entries = unzipSync(new Uint8Array(bytes));
181
+ }
182
+ catch {
183
+ return {
184
+ status: 'failed',
185
+ summary: 'PPTX 文件损坏:无法解析 ZIP/OOXML 容器',
186
+ issues: [
187
+ {
188
+ severity: 'blocking',
189
+ code: 'invalid_pptx_archive',
190
+ message: '生成的 .pptx 不是合法的 OOXML 压缩包,请重新执行导出脚本',
191
+ },
192
+ ],
193
+ };
194
+ }
195
+ if (!entries['[Content_Types].xml'] || !entries['ppt/presentation.xml']) {
196
+ return {
197
+ status: 'failed',
198
+ summary: 'PPTX 结构不完整:缺少 [Content_Types].xml 或 ppt/presentation.xml',
199
+ issues: [
200
+ {
201
+ severity: 'blocking',
202
+ code: 'missing_pptx_core_xml',
203
+ message: 'PPTX 缺少核心 OOXML 描述文件([Content_Types].xml / ppt/presentation.xml)',
204
+ },
205
+ ],
206
+ };
207
+ }
208
+ const slideNames = Object.keys(entries).filter((name) => /^ppt\/slides\/slide\d+\.xml$/i.test(name));
209
+ if (slideNames.length === 0) {
210
+ return {
211
+ status: 'failed',
212
+ summary: 'PPTX 不包含任何幻灯片页',
213
+ issues: [
214
+ {
215
+ severity: 'blocking',
216
+ code: 'empty_pptx_slides',
217
+ message: 'PPTX 内未找到任何 ppt/slides/slide*.xml 幻灯片,请先生成内容后再交付',
218
+ },
219
+ ],
220
+ };
221
+ }
222
+ const located = await locatePptProjectForFile(ctx.chatId, ctx.filePath);
223
+ if (located) {
224
+ if (located.projectId) {
225
+ try {
226
+ await refreshPptQualityReport(ctx.chatId, located.projectId);
227
+ }
228
+ catch {
229
+ // 测试或离线无 ppt-master 脚本时回退读取项目内既有 svg_quality_report.json。
230
+ }
231
+ }
232
+ const reportPath = path.join(located.projectPath, 'validation', 'svg_quality_report.json');
233
+ const blocking = await readPptQualityBlockingIssues(located.projectPath);
234
+ if (blocking.length > 0) {
235
+ const issues = blocking.map((item) => ({
236
+ severity: 'blocking',
237
+ code: 'ppt_layout_blocking',
238
+ message: item.message || 'SVG 版式质检未通过(越界或溢出)',
239
+ ...(item.file ? { location: item.file } : {}),
240
+ }));
241
+ return {
242
+ status: 'failed',
243
+ summary: `PPT 版式质检拦截:检出 ${blocking.length} 项阻断问题,请修复 SVG 越界/溢出后重新导出`,
244
+ issues,
245
+ ...(await fileExists(reportPath) ? { reportPath } : {}),
246
+ };
247
+ }
248
+ const warnings = await readPptQualityWarningIssues(located.projectPath);
249
+ if (warnings.length > 0) {
250
+ return {
251
+ status: 'warnings',
252
+ summary: `PPT 版式质检通过(共 ${slideNames.length} 页,0 阻断,${warnings.length} 项版式提示)`,
253
+ issues: warnings,
254
+ ...(await fileExists(reportPath) ? { reportPath } : {}),
255
+ };
256
+ }
257
+ }
258
+ return {
259
+ status: 'verified',
260
+ summary: `PPT 版式与结构质检已通过(共 ${slideNames.length} 页,0 阻断)`,
261
+ issues: [],
262
+ };
263
+ },
264
+ };
265
+ }
266
+ function extractDeclaredDocxFonts(entries) {
267
+ const candidates = [
268
+ 'word/fontTable.xml',
269
+ 'word/styles.xml',
270
+ 'word/document.xml',
271
+ ];
272
+ const found = new Set();
273
+ const attrPatterns = [
274
+ /\bw:name="([^"]+)"/g,
275
+ /\bw:eastAsia="([^"]+)"/g,
276
+ /\bw:ascii="([^"]+)"/g,
277
+ /\bw:hAnsi="([^"]+)"/g,
278
+ ];
279
+ for (const name of candidates) {
280
+ const raw = entries[name];
281
+ if (!raw)
282
+ continue;
283
+ const xml = Buffer.from(raw).toString('utf8');
284
+ for (const re of attrPatterns) {
285
+ for (const match of xml.matchAll(re)) {
286
+ const fontName = match[1]?.trim();
287
+ if (fontName)
288
+ found.add(fontName);
289
+ }
290
+ }
291
+ }
292
+ return [...found];
293
+ }
294
+ function decodeXmlEntities(input) {
295
+ return input
296
+ .replace(/&lt;/g, '<')
297
+ .replace(/&gt;/g, '>')
298
+ .replace(/&quot;/g, '"')
299
+ .replace(/&apos;/g, "'")
300
+ .replace(/&amp;/g, '&');
301
+ }
302
+ async function readWordFormatReportBlockers(docxPath) {
303
+ const reportCandidate = path.join(path.dirname(path.resolve(docxPath)), 'validation', 'word_format_report.json');
304
+ if (!(await fileExists(reportCandidate)))
305
+ return [];
306
+ try {
307
+ const raw = JSON.parse(await readFile(reportCandidate, 'utf8'));
308
+ if (raw.passed !== false && raw.valid !== false && raw.ok !== false) {
309
+ return [];
310
+ }
311
+ const rawErrors = Array.isArray(raw.errors)
312
+ ? raw.errors
313
+ : Array.isArray(raw.issues)
314
+ ? raw.issues
315
+ : [];
316
+ if (rawErrors.length === 0) {
317
+ return [
318
+ {
319
+ severity: 'blocking',
320
+ code: 'word_format_report_failed',
321
+ message: 'word_format_report.json 标记版式校验未通过,请修复后重跑 verify_format.py',
322
+ location: 'validation/word_format_report.json',
323
+ },
324
+ ];
325
+ }
326
+ return rawErrors.slice(0, 10).map((item) => ({
327
+ severity: 'blocking',
328
+ code: 'word_format_report_failed',
329
+ message: typeof item === 'string'
330
+ ? item
331
+ : typeof item?.message === 'string'
332
+ ? String(item.message)
333
+ : 'Word 公文版式校验项未通过',
334
+ location: 'validation/word_format_report.json',
335
+ }));
336
+ }
337
+ catch {
338
+ return [];
339
+ }
340
+ }
341
+ /**
342
+ * 创建 DOCX 公文交付质检器(`doc-preview-word`)。
343
+ */
344
+ export function createWordDeliverableVerifier(options = {}) {
345
+ const listFonts = options.listInstalledFonts ?? detectHostInstalledFonts;
346
+ return {
347
+ id: 'doc-preview-word',
348
+ matchExtensions: ['.docx'],
349
+ async verify(ctx) {
350
+ let entries;
351
+ try {
352
+ const bytes = await readFile(ctx.filePath);
353
+ entries = unzipSync(new Uint8Array(bytes));
354
+ }
355
+ catch {
356
+ return {
357
+ status: 'failed',
358
+ summary: 'DOCX 文件损坏:无法解析 ZIP/OOXML 容器',
359
+ issues: [
360
+ {
361
+ severity: 'blocking',
362
+ code: 'invalid_docx_archive',
363
+ message: '生成的 .docx 不是合法的 OOXML 压缩包,请重新生成文档',
364
+ },
365
+ ],
366
+ };
367
+ }
368
+ const contentTypes = entries['[Content_Types].xml'];
369
+ const documentXmlBytes = entries['word/document.xml'];
370
+ if (!contentTypes || !documentXmlBytes) {
371
+ return {
372
+ status: 'failed',
373
+ summary: 'DOCX 结构不完整:缺少 [Content_Types].xml 或 word/document.xml',
374
+ issues: [
375
+ {
376
+ severity: 'blocking',
377
+ code: 'missing_docx_core_xml',
378
+ message: 'DOCX 缺少核心 OOXML 组件([Content_Types].xml / word/document.xml)',
379
+ },
380
+ ],
381
+ };
382
+ }
383
+ const documentXml = Buffer.from(documentXmlBytes).toString('utf8');
384
+ const hasWellFormedRoot = /<w:document\b/.test(documentXml) &&
385
+ /<\/w:document>\s*$/.test(documentXml.trim()) &&
386
+ /<w:body\b/.test(documentXml) &&
387
+ /<\/w:body>/.test(documentXml);
388
+ if (!hasWellFormedRoot) {
389
+ return {
390
+ status: 'failed',
391
+ summary: 'DOCX 正文 XML 结构损坏(w:document / w:body 未闭合)',
392
+ issues: [
393
+ {
394
+ severity: 'blocking',
395
+ code: 'malformed_docx_xml',
396
+ message: 'word/document.xml 结构不完整或标签未闭合',
397
+ location: 'word/document.xml',
398
+ },
399
+ ],
400
+ };
401
+ }
402
+ const textRuns = [];
403
+ for (const match of documentXml.matchAll(/<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>/g)) {
404
+ if (match[1])
405
+ textRuns.push(decodeXmlEntities(match[1]));
406
+ }
407
+ const visibleText = textRuns.join('').trim();
408
+ if (!visibleText) {
409
+ return {
410
+ status: 'failed',
411
+ summary: 'DOCX 正文为空,已拦截空白公文交付',
412
+ issues: [
413
+ {
414
+ severity: 'blocking',
415
+ code: 'empty_docx_body',
416
+ message: 'word/document.xml 未提取到任何可见正文文字,请检查公文生成脚本输出',
417
+ location: 'word/document.xml',
418
+ },
419
+ ],
420
+ };
421
+ }
422
+ const formatBlockers = await readWordFormatReportBlockers(ctx.filePath);
423
+ if (formatBlockers.length > 0) {
424
+ return {
425
+ status: 'failed',
426
+ summary: `Word 公文版式校验未通过(${formatBlockers.length} 项阻断问题)`,
427
+ issues: formatBlockers,
428
+ };
429
+ }
430
+ const paragraphCount = (documentXml.match(/<w:p(?:\s|>)/g) ?? []).length;
431
+ const declaredFonts = extractDeclaredDocxFonts(entries);
432
+ const installedFonts = await listFonts();
433
+ const installedCorpus = installedFonts.join('\n');
434
+ const matchedOfficial = [];
435
+ const missingOfficial = [];
436
+ for (const spec of OFFICIAL_FONT_SPECS) {
437
+ const isDeclared = declaredFonts.some((font) => spec.matchDeclared.test(font));
438
+ if (!isDeclared)
439
+ continue;
440
+ if (spec.matchInstalled.test(installedCorpus)) {
441
+ matchedOfficial.push(spec.canonical);
442
+ }
443
+ else {
444
+ missingOfficial.push(spec.canonical);
445
+ }
446
+ }
447
+ const issues = [];
448
+ if (missingOfficial.length > 0) {
449
+ issues.push({
450
+ severity: 'warning',
451
+ code: 'official_font_fallback',
452
+ message: `检测到公文字体回退(当前环境未安装:${missingOfficial.join('、')})`,
453
+ location: 'word/fontTable.xml',
454
+ });
455
+ return {
456
+ status: 'warnings',
457
+ summary: `OOXML 文档结构校验通过(共 ${paragraphCount} 段,0 阻断);检测到公文字体回退(${missingOfficial.join('、')})`,
458
+ issues,
459
+ };
460
+ }
461
+ const fontNote = matchedOfficial.length > 0
462
+ ? `;公文标准字体核查:${matchedOfficial.join('、')} 全部命中`
463
+ : '';
464
+ return {
465
+ status: 'verified',
466
+ summary: `OOXML 文档结构与段落完整性校验通过(共 ${paragraphCount} 段,0 阻断)${fontNote}`,
467
+ issues: [],
468
+ };
469
+ },
470
+ };
471
+ }
472
+ /**
473
+ * 创建 `doc-preview` 标准交付质检器组合(PPTX + DOCX)。
474
+ */
475
+ export function createDocPreviewDeliverableVerifiers(options = {}) {
476
+ return [
477
+ createPptDeliverableVerifier(),
478
+ createWordDeliverableVerifier(options),
479
+ ];
480
+ }
@@ -3,3 +3,4 @@
3
3
  */
4
4
  export { assembleDocumentPreview, createDocumentPreviewPack, } from './assemble.js';
5
5
  export { DOCUMENT_PREVIEW_MIGRATIONS, ETOWN_MIGRATIONS } from './migrations.js';
6
+ export { createDocPreviewDeliverableVerifiers, createPptDeliverableVerifier, createWordDeliverableVerifier, resetDocPreviewFontCacheForTests, } from './deliverable-verifiers.js';
@@ -22,6 +22,7 @@
22
22
  "Copy file path": "复制文件路径",
23
23
  "Copied": "已复制",
24
24
  "Loading file preview…": "正在加载文件预览…",
25
+ "Could not render file preview.": "无法渲染文件预览",
25
26
  "This chat has no previewable files yet.": "本会话还没有可预览的文件",
26
27
  "PDF, spreadsheets, and images from this chat show up here.": "本会话写出的 PDF、表格和图片会在这里预览。",
27
28
  "Showing the first rows.": "只显示前面的行。",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/steer",
3
- "version": "0.3.13",
3
+ "version": "0.3.15",
4
4
  "description": "Steer Agent CLI & TUI — local-first AI assistant for your terminal and server.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://steeragent.app",
@@ -25,16 +25,16 @@
25
25
  "node": ">=22.19.0"
26
26
  },
27
27
  "dependencies": {
28
- "@steerable/agent-cli": "0.14.1",
29
- "@steerable/agent-shell": "0.14.1",
28
+ "@steerable/agent-cli": "0.14.2",
29
+ "@steerable/agent-shell": "0.14.2",
30
30
  "fflate": "^0.8.2",
31
31
  "playwright-core": "1.63.0"
32
32
  },
33
33
  "optionalDependencies": {
34
- "@steerable/runtime-darwin-arm64": "0.14.1",
35
- "@steerable/runtime-darwin-x64": "0.14.1",
36
- "@steerable/runtime-linux-arm64": "0.14.1",
37
- "@steerable/runtime-linux-x64": "0.14.1",
38
- "@steerable/runtime-win32-x64": "0.14.1"
34
+ "@steerable/runtime-darwin-arm64": "0.14.2",
35
+ "@steerable/runtime-darwin-x64": "0.14.2",
36
+ "@steerable/runtime-linux-arm64": "0.14.2",
37
+ "@steerable/runtime-linux-x64": "0.14.2",
38
+ "@steerable/runtime-win32-x64": "0.14.2"
39
39
  }
40
40
  }