From aa21fc57ef0f9ac124edb5f9aa2136c72642b3b6 Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 21 Jul 2026 18:48:56 +0800 Subject: [PATCH] =?UTF-8?q?docs(ADR=200015):=20P4=20v3=20=E5=85=A8?= =?UTF-8?q?=E9=87=8F=E6=94=B6=E5=8F=A3=E5=9B=BA=E5=8C=96=20+=20=C2=A74.1?= =?UTF-8?q?=20=E7=BB=8F=E9=AA=8C=E6=95=99=E8=AE=AD=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 §4.1 'P4 v3 全量收口 (2026-07-21)' 详细段: - 范围修正: scan 估算 ~330 处, 实际 25 文件 33+ 处真表格. 其余分 (a) 树/key:value dump (dict/typelist + storage/info + user/auth-groups + user/info + menu/info) (b) 调试日志 (form/_ai + kb/show + apis/info 等) - 8 批 commit 表格 (15b3361 → 07463cb, 本 session 19 文件 + 前 session 6 = 25/25) - 迁移模式固化 (代码模板) - 6 条经验教训 (估算偏差 / Edit vs Write / UUID 截断 / --include-actions / 进度条保留 / 不需新 primitive) §3 优先级表 P4 v3 行: '待' → '✅ DONE', 加 8 commit 引用 + ~310 散布分类 原 §4.1-4.4 顺延 → §4.2-4.5 (P0 ROI / P1 紧跟 / P3 不放 P1 前 / P5-P6 风险). 验证: - TS compile baseline 57 不变 - 73/73 vitest PASS - P4 v3 全量收口闭环: 25/25 REAL_TABLE 文件 --- docs/decisions/0015-source-leftovers.md | 99 +++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/docs/decisions/0015-source-leftovers.md b/docs/decisions/0015-source-leftovers.md index 45a1aa4..ede6a05 100644 --- a/docs/decisions/0015-source-leftovers.md +++ b/docs/decisions/0015-source-leftovers.md @@ -141,13 +141,102 @@ ADR 0015 早期记述有误, 现清空. | **P5 全量** | 0.2h | 中 | ✅ **DONE** | c6b7fe8 portal/create + bigscreen/construct 2 文件 throw → DacliError (剩 ~15 路径不存在, 都在 SDK/test helper) | | **P6 sample 续** | 0.7h | 中 | ✅ **DONE** | 11f94a3 wrapCommand 续迁 7 文件 (form/list + report/{list,info} + storage/list + integration/{email,smstest,webhook}test); tests/unit/report_wired.test.ts 老 pattern 静态契约更新到 wrapCommand 新约定 | | **P4 v2** | 0.5h | 中 | ✅ **DONE** | log.printRawTable(headers, rows, opts) 新 primitive + 3 文件迁移 (datasource/list, dm/list, dm/fields) + 5 单测; 剩 ~330 处 console.log 表格后续 session 推广 | +| **P4 v3** | ~2h (8 batches) | 中 | ✅ **DONE** | 19 文件完整 wrapCommand 迁移 + 25/25 REAL_TABLE 文件全部 printRawTable 化 (8 commits: 15b3361 → 07463cb). 详见 §P4 v3 全量收口段. 剩 ~310 处 console.log 散布分两类: (a) 树/key:value dump (dict/typelist + storage/info + user/auth-groups + user/info + menu/info 等), 需另写 printTree helper 或保留 console.log; (b) 调试日志 (form/_ai + kb/show + apis/info 等), 不属 P4 v3 范围. | | P2 | 2-3h | 高 | 待 | form/create + workflow/create + form/codegen 高严重度 25+ 文件批量审查 | -| P4 v3 | 1h | 中 | 待 | 剩 ~330 console.log 表格批量迁移到 printRawTable | | P6 大坑 | 8+h | 极高 | 待 (跨多 session) | 350+ 裸 process.exit 全面收口 | ## 4. 决策依据 -### 4.1 为什么 P0 ROI 极高 +### 4.1 P4 v3 全量收口 (2026-07-21) + +#### 范围修正 + +scan-2026-07-21.md 估算 "剩 ~330 处 console.log 表格待迁移", 实际**只有 25 文件 33+ 处 console.log 真表格**. +其余散布分两类: + +1. **树状 dump / 递归结构** (~10 文件): `dict/typelist.ts` (printTree 递归), `storage/info.ts` (Object.entries key:value), `user/auth-groups.ts` (flattenTree + indent depth), `user/info.ts` (菜单权限嵌套树), `menu/info.ts` (16 console.log 调用). **不属 printRawTable 适用范围**. +2. **调试日志 / 状态行** (~20 文件): `form/_ai.ts` (AI step 输出), `kb/show.ts` (KB entry 详情), `apis/info.ts` (单 API 详情), `apis/status.ts` (缓存状态) 等. **不属于表格**. + +#### 8 批 commit (本 session 2026-07-21) + +| Batch | Commit | 文件数 | 内容 | +|-------|--------|--------|------| +| 1 | `15b3361` | 3 | 简单 swap (已 wrapCommand): report/list + storage/list + workflow/list | +| 2 | `a772647` | 2 | apis/search (双表) + apis/tags 完整 wrapCommand | +| 3 | `f25a87e` | 3 | app/list + bigscreen/list (原 printCommandEnd → wrapCommand) + portal/list | +| 4 | `399f50f` | 4 | doc/list (本地 FS) + doc/toc + form/selector + kb/list (重写, 原 builder 链顺序错) | +| 5 | `12f445b` | 7 | msg×2 + monitor/online + org/list (UUID 28+.. 截断保留) + print/list + role×2 | +| 6 | `73784f6` | 3 | schedule/log + user/get-position + user/list (6 列最长) | +| 7 | `4c417cc` | 2 | workflow/selector + workflow/tasks | +| 8 | `07463cb` | 1 | menu/list.ts (复杂 2 表 + --include-actions 标志) | + +**合计**: 8 commits, 25 文件 (本 session 19 + 前 session 6), 100% REAL_TABLE 收口. + +#### 迁移模式固化 + +每文件统一采用: + +```ts +import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' + +interface Opts { + // ... 原 options + /** v2.1+ (2026-07-21): --verbose, addOutputOptions 注入 */ + verbose?: boolean +} + +// 在 cmd builder: +addOutputOptions(cmd) // 删本地 --verbose/--json + +.action(async (opts: Opts) => { + setupOutputFilter(opts) + const c = await JnpfClient.fromToken() // 或无 c (storage/doc/kb 类) + + await wrapCommand({ + command: ' ', + appCode: c?.appCode, + startTime: Date.now(), + verbose: opts.verbose, + json: opts.json, + fixes: [], + }, async (ctx) => { + try { + // ... 业务逻辑 ... + const summary = { ... } + if (opts.json) { + printJson(...) + return ctx.success(summary) + } + log.printRawTable( + ['COL1', 'COL2', ...], + list.map(d => [String(d.col1 || ''), String(d.col2 || ''), ...]), + { maxColWidth: 80 }, // 可选, 默认 36 + ) + ctx.success(summary) + } catch (e) { + ctx.fail(` 失败: ${(e as Error).message?.slice(0, 200)}`) + } + }) +}) +``` + +#### 经验教训 + +1. **估算偏差**: scan-2026-07-21.md 说 ~330 待迁移, 实际只有 33+ 处真表格. 后续 ADR 估算应明示 "console.log 调用数 ≠ 表格数", 表格需 header + separator + padEnd 三要素判定. +2. **Edit vs Write**: 90% 文件 Edit 工作良好, 但 kb/list.ts 原 builder pattern 链顺序错 (.option() 必须在 .action() 前), Write 更清晰. menu/list.ts 因 2 表 + 多 flag + 大量 import 重排, Write 整文件最稳. +3. **UUID 截断保留**: org/list.ts 原 `'..' + slice(0, 28)` 截断逻辑不能直接交给 printRawTable 的 `…` 截断 (视觉不一致), 用 pre-truncate 保留. +4. **--include-actions 默认 ON**: menu/list.ts 用 `--include-actions` / `--no-include-actions` 双写 (commander 默认 true), 不能简单 `addOutputOptions` 覆盖. +5. **进度条保留**: menu/list.ts 的 `process.stderr.write('\r 扫描 form: ...')` 直接写 stderr, 不走 quiet buffer, 真实进度可见. 不能用 log.* (会被缓冲). +6. **不需新 primitive**: tree dump (dict/typelist 等) 不属本 ADR 范围, 后续如需 printTree helper 再单独立 ADR. + +#### 验证 + +- TS compile baseline=57 (无新错误) — 每个 batch 后立即验证 +- vitest 73/73 PASS (含 printRawTable 5 单测) — 每个 batch 后立即验证 +- CI 关卡 G WARN (pre-existing, 2 个白名单: integration/storage 已知) +- 8 commits 全部 git push 成功, 累计本 session 19 文件 P4 v3 改造 + +### 4.2 为什么 P0 ROI 极高 - **一行 helper = 30+ 行样板**: 39 文件每处 5c + process.exit(1) 是 6 行, wrapCommand 提供的 ctx 让 handler 模板减到 1-3 行. @@ -158,17 +247,17 @@ ADR 0015 早期记述有误, 现清空. P0 的 wrapCommand 收口 (e.g. `dict/typecreate.ts` 多处 `process.exit(1)` 现 切到 `ctx.fail`), 后续 P6 改造时只需要看 wrapCommand 是否覆盖到对应路径. -### 4.2 为什么 P1 紧跟 P0 +### 4.3 为什么 P1 紧跟 P0 P1 是 2 个独立 1 文件修改, 跟 P0 同 PR 不合适 (应独立 commit), 但风险极低 (只 1 文件 + 1 import). -### 4.3 为什么 P3 不放在 P1 之前 +### 4.4 为什么 P3 不放在 P1 之前 P3 是 18 文件批量改 import, 改完不引入新功能 (只增一致性), 而 P1 解决已知不变量违反. **修已知坑优先于批量调整**. -### 4.4 P5/P6 风险评估 +### 4.5 P5/P6 风险评估 P5 涉及大量文件 (100+) 改 console.log → log.* + throw new Error → DacliError, 每次改动都需单测覆盖 (避免 console.log → log.* 后 silent 模式吞掉表格).