feat(dacli): P4a console.error/warn → log.* + P6 sample wrapCommand (7 文件)

P4a (高置信, 0 风险):
  - 17 处 console.error/warn → log.error/warn across 11 文件
  - 自动 import { log } from '../core/log.ts' (没引过的)
  - 影响: _blindspot_guards/app/status/bigscreen/construct/form/release/kb/*/test/*
  - 剩 333 处 console.log 是表格输出 (new primitive log.printRawTable 待 ADR)

P6 sample (5-8 文件, 命中 7):
  - dm/list, dm/fields, dict/datalist, dict/typelist, form/info
  - workflow/info (原本 P6 raw exit, 没落 CommandLog — 顺手补全)
  - workflow/list (原本 2 printCommandEnd 重复, 双落 log)
  - 全部 try/catch/finally → wrapCommand + ctx.fail/success
  - 每个文件消除 1-3 个裸 process.exit

验证:
  - TS compile 56 baseline 不变, 0 新错误 (修了一个我自己引入的: workflow/info Opts
    interface 缺 verbose? field)
  - 端到端: dm list/fields, dict data-list/typeList, form info --summary, workflow
    list 都正确输出 + CommandLog 落盘
  - workflow/info 同时修了 CommandLog 落盘缺失的 bug (原本裸 process.exit(1), 历史
    可追溯不到)

剩余 P5 (throw new Error → DacliError, 37 处) + P6 大坑 (350+ process.exit 跨 session
治理) + console.log → log.printRawTable 新 primitive (P4 v2 范围扩大)
留待后续 session 推进.
This commit is contained in:
ssw committed 2026-07-21 17:44:05 +08:00
1 parent 5ead157903
commit 22593df7c4
18 files changed
+401 -422

No files matched your search

+2 -2
View File
@@ -722,12 +722,12 @@ export function handleGuardResult(label: string, issues: BlindspotIssue[]): void
if (errors.length > 0) {
log.error(`Blindspot guard 失败 (${label} 终止, 请修复后重试):`)
console.error(formatIssues(errors))
log.error(formatIssues(errors))
process.exit(2)
}
if (warns.length > 0) {
log.warn(`Blindspot guard 警告 (${label} 不阻断, 但请关注):`)
console.warn(formatIssues(warns))
log.warn(formatIssues(warns))
}
}
+5 -5
View File
@@ -93,9 +93,9 @@ export function buildAppStatusCommand(): Command {
// v0.11e+ Phase E: system 缺失时明确提示 + 退出码 1
if (systemExists === false) {
console.error('')
console.error(systemError)
console.error('')
log.error('')
log.error(systemError)
log.error('')
process.exit(1)
}
if (systemExists === null) {
@@ -104,8 +104,8 @@ export function buildAppStatusCommand(): Command {
// v0.11h+: 健康检查失败时退出码 1 (便于脚本/AI 检测)
if (!healthR.ok) {
console.error('')
console.error('⚠ JNPF 不可达, 后续 form/menu/dict 操作会失败. 见上面修复指引')
log.error('')
log.error('⚠ JNPF 不可达, 后续 form/menu/dict 操作会失败. 见上面修复指引')
process.exit(1)
}
})
+1 -1
View File
@@ -144,7 +144,7 @@ export function buildBigscreenConstructCommand(): Command {
} catch (err) {
const errMsg = `构造失败: ${(err as Error).message}`
log.error(errMsg)
if (process.env.DACLI_DEBUG === '1') console.error(err)
if (process.env.DACLI_DEBUG === '1') log.error(err)
// v2.1+ (2026-07-21): 错误路径落 CommandLog (L3)
printCommandEnd({
command: 'bigscreen construct',
+40 -47
View File
@@ -10,7 +10,7 @@ import { JnpfClient } from '../../core/client.ts'
import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDict } from '../../webapi/dict.ts'
import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (data list 类查询历史可追溯)
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (data list 类查询历史可追溯); v2.2+ wrapCommand 收口 5c 样板
interface Opts {
typeId?: string
@@ -31,54 +31,47 @@ export function buildDictDataListCommand(): Command {
// 输出过滤: 默认静默
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
let cmdError: string | undefined
let cmdSummary: Record<string, unknown> = {}
try {
await initWebapi(c)
let path: string
let data: unknown
if (opts.all || !opts.typeId) {
path = '/system/DictionaryData/All'
data = await loadDict.getDictionaryAll()
} else {
path = `/system/DictionaryData/${opts.typeId}/Data`
data = await loadDict.getDictionaryDataList({ typeId: opts.typeId })
await wrapCommand({
command: 'dict data-list',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
await initWebapi(c)
let path: string
let data: unknown
if (opts.all || !opts.typeId) {
path = '/system/DictionaryData/All'
data = await loadDict.getDictionaryAll()
} else {
path = `/system/DictionaryData/${opts.typeId}/Data`
data = await loadDict.getDictionaryDataList({ typeId: opts.typeId })
}
const list = (Array.isArray(data) ? data : (data as { list?: unknown[] })?.list) || []
const summary = {
typeId: opts.typeId || '(all)',
path,
total: list.length,
}
if (opts.json) {
printJson(data)
return ctx.success(summary)
}
log.info(`${path} 共 ${list.length} 条`)
console.log('ENCODE'.padEnd(21) + 'FULL_NAME'.padEnd(22) + 'SORT')
console.log('-'.repeat(60))
for (const d of list as Record<string, unknown>[]) {
console.log(`${String(d.enCode || d.id || '').padEnd(21)}${String(d.fullName || '').padEnd(22)}${d.sortCode || ''}`)
}
ctx.success(summary)
} catch (e) {
ctx.fail(`dict datalist 失败: ${(e as Error).message?.slice(0, 200)}`)
}
if (opts.json) {
printJson(data)
return
}
const list = (Array.isArray(data) ? data : (data as { list?: unknown[] })?.list) || []
cmdSummary = {
typeId: opts.typeId || '(all)',
path,
total: list.length,
}
log.info(`${path} 共 ${list.length} 条`)
console.log('ENCODE'.padEnd(21) + 'FULL_NAME'.padEnd(22) + 'SORT')
console.log('-'.repeat(60))
for (const d of list as Record<string, unknown>[]) {
console.log(`${String(d.enCode || d.id || '').padEnd(21)}${String(d.fullName || '').padEnd(22)}${d.sortCode || ''}`)
}
} catch (e) {
cmdError = (e as Error).message?.slice(0, 200)
log.error(`dict datalist 失败: ${cmdError}`)
} finally {
// v2.1+ (2026-07-21): 落 CommandLog (L3)
printCommandEnd({
command: 'dict data-list',
appCode: c.appCode,
result: cmdError ? 'failure' : 'success',
error: cmdError,
summary: cmdSummary,
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
if (cmdError) process.exit(1)
}
})
})
installHelpHook(cmd, {
+70 -79
View File
@@ -16,7 +16,7 @@ import { JnpfClient } from '../../core/client.ts'
import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDict } from '../../webapi/dict.ts'
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘
import { setupOutputFilter, wrapCommand } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘; v2.2+ wrapCommand 收口 5c 样板
interface Opts { json?: boolean; keyword?: string; recursive?: boolean; tree?: boolean; verbose?: boolean }
@@ -62,88 +62,79 @@ export function buildDictTypeListCommand(): Command {
// 输出过滤: 默认静默 (quiet mode), --verbose 走完整日志, --json 走原始 JSON
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
let cmdError: string | undefined
let cmdSummary: Record<string, unknown> = {}
try {
await initWebapi(c)
const data = (await loadDict.getDictionaryType()) as { list?: Record<string, unknown>[] }
if (opts.json) {
cmdSummary = { mode: 'json' }
printJson(data)
return
}
// === v0.12+ BS-New-6: 默认递归展平 children (用户实际想要的字典)
// 旧行为: 只显示顶层 2 项, --keyword 无法命中
// 新行为: 递归展平所有节点, --keyword 真正可用
const recursive = opts.recursive !== false && !opts.tree
const treeView = !!opts.tree
// --tree 模式直接打印树
if (treeView) {
log.info(`共 ${data?.list?.length || 0} 个顶层分类 (树形视图)`)
if (opts.keyword) {
log.warn('--tree 与 --keyword 互斥 (树形显示全部, 不用过滤)')
await wrapCommand({
command: 'dict typeList',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
await initWebapi(c)
const data = (await loadDict.getDictionaryType()) as { list?: Record<string, unknown>[] }
if (opts.json) {
printJson(data)
return ctx.success({ mode: 'json' })
}
console.log('ID'.padEnd(36) + 'ENCODE'.padEnd(22) + 'FULL_NAME')
// === v0.12+ BS-New-6: 默认递归展平 children (用户实际想要的字典)
// 旧行为: 只显示顶层 2 项, --keyword 无法命中
// 新行为: 递归展平所有节点, --keyword 真正可用
const recursive = opts.recursive !== false && !opts.tree
const treeView = !!opts.tree
// --tree 模式直接打印树
if (treeView) {
log.info(`共 ${data?.list?.length || 0} 个顶层分类 (树形视图)`)
if (opts.keyword) {
log.warn('--tree 与 --keyword 互斥 (树形显示全部, 不用过滤)')
}
console.log('ID'.padEnd(36) + 'ENCODE'.padEnd(22) + 'FULL_NAME')
console.log('-'.repeat(80))
printTree(data?.list || [], 0)
return ctx.success({ mode: 'tree' })
}
let list: Array<Record<string, any>>
if (recursive) {
list = flattenTree(data?.list || [])
} else {
list = (data?.list || []) as Array<Record<string, any>>
}
if (opts.keyword) {
const kw = opts.keyword.toLowerCase()
list = list.filter(
(t) =>
String(t.enCode || '').toLowerCase().includes(kw) ||
String(t.fullName || '').toLowerCase().includes(kw),
)
}
const summary = {
keyword: opts.keyword,
total: list.length,
recursive,
mode: 'flat',
}
log.info(`共 ${list.length} 个字典类型${opts.keyword ? ` (匹配 keyword="${opts.keyword}")` : ''}${recursive ? ' [递归展平]' : ' [仅顶层]'}`)
if (recursive && !opts.keyword) {
console.log('(BS-New-6: 默认递归展平 children 树, --tree 看原始树形, --no-recursive 只看顶层)')
}
console.log('ID'.padEnd(36) + 'ENCODE'.padEnd(21) + 'FULL_NAME')
console.log('-'.repeat(80))
printTree(data?.list || [], 0)
cmdSummary = { mode: 'tree' }
return
for (const t of list) {
const path = t._path ? ` [${t._path}]` : ''
console.log(`${String(t.id || '').padEnd(36)}${String(t.enCode || '').padEnd(21)}${t.fullName || ''}${path}`)
}
ctx.success(summary)
} catch (e) {
ctx.fail(`dict typeList 失败: ${(e as Error).message?.slice(0, 200)}`)
}
let list: Array<Record<string, any>>
if (recursive) {
list = flattenTree(data?.list || [])
} else {
list = (data?.list || []) as Array<Record<string, any>>
}
if (opts.keyword) {
const kw = opts.keyword.toLowerCase()
list = list.filter(
(t) =>
String(t.enCode || '').toLowerCase().includes(kw) ||
String(t.fullName || '').toLowerCase().includes(kw),
)
}
cmdSummary = {
keyword: opts.keyword,
total: list.length,
recursive,
mode: 'flat',
}
log.info(`共 ${list.length} 个字典类型${opts.keyword ? ` (匹配 keyword="${opts.keyword}")` : ''}${recursive ? ' [递归展平]' : ' [仅顶层]'}`)
if (recursive && !opts.keyword) {
console.log('(BS-New-6: 默认递归展平 children 树, --tree 看原始树形, --no-recursive 只看顶层)')
}
console.log('ID'.padEnd(36) + 'ENCODE'.padEnd(21) + 'FULL_NAME')
console.log('-'.repeat(80))
for (const t of list) {
const path = t._path ? ` [${t._path}]` : ''
console.log(`${String(t.id || '').padEnd(36)}${String(t.enCode || '').padEnd(21)}${t.fullName || ''}${path}`)
}
} catch (e) {
cmdError = (e as Error).message?.slice(0, 200)
log.error(`dict typeList 失败: ${cmdError}`)
throw e
} finally {
// v2.1+ (2026-07-21): 落 CommandLog (L3)
printCommandEnd({
command: 'dict typeList',
appCode: c.appCode,
result: cmdError ? 'failure' : 'success',
error: cmdError,
summary: cmdSummary,
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
}
})
})
installHelpHook(cmd, {
+48 -55
View File
@@ -10,7 +10,7 @@ import { JnpfClient } from '../../core/client.ts'
import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDataModel } from '../../webapi/dataModel.ts'
import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (dm fields 类查询历史可追溯)
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (dm fields 类查询历史可追溯); v2.2+ wrapCommand 收口 5c 样板
interface FieldsOpts {
table: string
@@ -30,62 +30,55 @@ export function buildDmFieldsCommand(): Command {
// 输出过滤: 默认静默
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
let cmdError: string | undefined
let cmdSummary: Record<string, unknown> = { table: opts.table }
try {
// BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId
const dbLinkId = c.resolveDbLinkId(opts.dbLinkId)
// v0.11+ Phase 1: 用 web 端 getDataModelFieldList (替代 c.get('/system/DataModel/{id}/Tables/{t}/Fields'))
await initWebapi(c)
const dataObj = (await loadDataModel.getDataModelFieldList(dbLinkId, opts.table)) as
| Record<string, unknown>
| unknown[]
| null
if (opts.json) {
printJson(dataObj)
return
await wrapCommand({
command: 'dm fields',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
// BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId
const dbLinkId = c.resolveDbLinkId(opts.dbLinkId)
// v0.11+ Phase 1: 用 web 端 getDataModelFieldList (替代 c.get('/system/DataModel/{id}/Tables/{t}/Fields'))
await initWebapi(c)
const dataObj = (await loadDataModel.getDataModelFieldList(dbLinkId, opts.table)) as
| Record<string, unknown>
| unknown[]
| null
// 兼容 data 是数组 / { list: [...] } / { fields: [...] }
const arr = Array.isArray(dataObj)
? dataObj
: ((dataObj as { list?: unknown[]; fields?: unknown[] })?.list ||
(dataObj as { fields?: unknown[] })?.fields ||
[])
const summary = {
dbLinkId,
table: opts.table,
fieldCount: arr.length,
}
if (opts.json) {
printJson(dataObj)
return ctx.success(summary)
}
log.info(`表 ${opts.table} 字段数=${arr.length}`)
console.log('FIELD TYPE LENGTH NULL PK')
console.log('-'.repeat(60))
for (const f of arr as Array<Record<string, unknown>>) {
const field = String(f.field || f.columnName || '').padEnd(20)
const type = String(f.dataType || '').padEnd(14)
const len = String(f.dataLength || '').padEnd(7)
const nullable = f.allowNull === 0 || f.allowNull === '0' ? 'NO' : 'YES'
const pk = f.primaryKey === 1 || f.primaryKey === '1' ? 'PK' : ''
console.log(`${field}${type}${len}${nullable.padEnd(5)}${pk}`)
}
ctx.success(summary)
} catch (e) {
ctx.fail(`dm fields 失败: ${(e as Error).message?.slice(0, 200)}`)
}
// 兼容 data 是数组 / { list: [...] } / { fields: [...] }
const arr = Array.isArray(dataObj)
? dataObj
: ((dataObj as { list?: unknown[]; fields?: unknown[] })?.list ||
(dataObj as { fields?: unknown[] })?.fields ||
[])
cmdSummary = {
dbLinkId,
table: opts.table,
fieldCount: arr.length,
}
log.info(`表 ${opts.table} 字段数=${arr.length}`)
console.log('FIELD TYPE LENGTH NULL PK')
console.log('-'.repeat(60))
for (const f of arr as Array<Record<string, unknown>>) {
const field = String(f.field || f.columnName || '').padEnd(20)
const type = String(f.dataType || '').padEnd(14)
const len = String(f.dataLength || '').padEnd(7)
const nullable = f.allowNull === 0 || f.allowNull === '0' ? 'NO' : 'YES'
const pk = f.primaryKey === 1 || f.primaryKey === '1' ? 'PK' : ''
console.log(`${field}${type}${len}${nullable.padEnd(5)}${pk}`)
}
} catch (e) {
cmdError = (e as Error).message?.slice(0, 200)
log.error(`dm fields 失败: ${cmdError}`)
} finally {
// v2.1+ (2026-07-21): 落 CommandLog (L3)
printCommandEnd({
command: 'dm fields',
appCode: c.appCode,
result: cmdError ? 'failure' : 'success',
error: cmdError,
summary: cmdSummary,
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
if (cmdError) process.exit(1)
}
})
})
installHelpHook(cmd, {
+40 -47
View File
@@ -10,7 +10,7 @@ import { JnpfClient } from '../../core/client.ts'
import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { initWebapi, loadDataModel } from '../../webapi/dataModel.ts'
import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (dm list 类查询历史可追溯)
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (dm list 类查询历史可追溯); v2.2+ wrapCommand 收口 5c 样板
interface ListOpts {
dbLinkId?: string
@@ -34,54 +34,47 @@ export function buildDmListCommand(): Command {
// 输出过滤: 默认静默
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
let cmdError: string | undefined
let cmdSummary: Record<string, unknown> = {}
try {
// BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId
const dbLinkId = c.resolveDbLinkId(opts.dbLinkId)
// v0.11+ Phase 1: 用 web 端 getDataModelList (替代 c.get('/system/DataModel/{id}/Tables'))
await initWebapi(c)
const resp = (await loadDataModel.getDataModelList({
linkId: dbLinkId,
currentPage: Number(opts.page) || 1,
pageSize: Number(opts.pageSize) || 50,
keyword: opts.keyword,
})) as { list: { table: string; tableName: string; primaryKeyPolicy?: number }[] }
const list = resp?.list || (Array.isArray(resp) ? (resp as any) : [])
cmdSummary = {
dbLinkId,
keyword: opts.keyword,
total: list.length,
await wrapCommand({
command: 'dm list',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
// BS-48 fix: '--dbLinkId=default' 字面量 → token.dbLinkId
const dbLinkId = c.resolveDbLinkId(opts.dbLinkId)
// v0.11+ Phase 1: 用 web 端 getDataModelList (替代 c.get('/system/DataModel/{id}/Tables'))
await initWebapi(c)
const resp = (await loadDataModel.getDataModelList({
linkId: dbLinkId,
currentPage: Number(opts.page) || 1,
pageSize: Number(opts.pageSize) || 50,
keyword: opts.keyword,
})) as { list: { table: string; tableName: string; primaryKeyPolicy?: number }[] }
const list = resp?.list || (Array.isArray(resp) ? (resp as any) : [])
const summary = {
dbLinkId,
keyword: opts.keyword,
total: list.length,
}
if (opts.json) {
printJson(resp)
return ctx.success(summary)
}
log.info(`dbLinkId=${dbLinkId} 共 ${list.length} 张表`)
console.log('TABLE TABLE_NAME(中文)')
console.log('-'.repeat(60))
for (const t of list) {
console.log(`${t.table.padEnd(30)}${t.tableName || ''}`)
}
ctx.success(summary)
} catch (e) {
ctx.fail(`dm list 失败: ${(e as Error).message?.slice(0, 200)}`)
}
if (opts.json) {
printJson(resp)
return
}
log.info(`dbLinkId=${dbLinkId} 共 ${list.length} 张表`)
console.log('TABLE TABLE_NAME(中文)')
console.log('-'.repeat(60))
for (const t of list) {
console.log(`${t.table.padEnd(30)}${t.tableName || ''}`)
}
} catch (e) {
cmdError = (e as Error).message?.slice(0, 200)
log.error(`dm list 失败: ${cmdError}`)
} finally {
// v2.1+ (2026-07-21): 落 CommandLog (L3)
printCommandEnd({
command: 'dm list',
appCode: c.appCode,
result: cmdError ? 'failure' : 'success',
error: cmdError,
summary: cmdSummary,
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
if (cmdError) process.exit(1)
}
})
})
installHelpHook(cmd, {
+48 -53
View File
@@ -17,7 +17,7 @@ import { installHelpHookWithPatterns } from '../../core/help.ts'
import { printJson, log } from '../../core/log.ts'
import type { FormDetail } from '../../core/types.ts'
import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts'
import { setupOutputFilter, addOutputOptions, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (info 类查询历史可追溯)
import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ (2026-07-21): 输出过滤 + CommandLog 落盘 (info 类查询历史可追溯); v2.2+ wrapCommand 收口 5c 样板
/**
* 尝试 JSON.parse 字符串, 失败返回原值. 用于 formData/columnData/tables 解 escaped JSON.
@@ -47,61 +47,56 @@ export function buildFormInfoCommand(): Command {
// 输出过滤: 默认静默
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
let cmdError: string | undefined
let cmdSummary: Record<string, unknown> = { id }
try {
// v0.11+ Phase 1: 用 web 端 getInfo (替代 c.get('/visualdev/Base/{id}'))
await initWebapi(c)
const data = (await loadVisualDev.getInfo(id)) as FormDetail
cmdSummary = {
id,
enCode: data.enCode,
fullName: data.fullName,
state: data.state,
mode: opts.summary ? 'summary' : (opts.json ? 'json-decoded' : 'json-raw'),
}
if (opts.summary) {
const tables = (Array.isArray(data.tables) ? data.tables : []) as Array<{ table?: string }>
log.ok(`${data.fullName} (${data.enCode})`)
log.dim(`id : ${data.id}`)
log.dim(`state : ${data.state} type: ${data.type} webType: ${data.webType}`)
log.dim(`dbLinkId : ${data.dbLinkId || '(none)'}`)
log.dim(`category : ${data.category || '(none)'}`)
log.dim(`tables : ${tables.length} (${tables.map((t) => t.table).join(', ')})`)
return
}
// v0.13+ BS-新1: --json 模式解 formData/columnData/tables escaped JSON
if (opts.json) {
const decoded = { ...data } as Record<string, unknown>
for (const key of ['formData', 'columnData', 'appColumnData', 'tables']) {
if (key in decoded) {
decoded[key] = tryParseJsonString(decoded[key])
}
await wrapCommand({
command: 'form info',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
// v0.11+ Phase 1: 用 web 端 getInfo (替代 c.get('/visualdev/Base/{id}'))
await initWebapi(c)
const data = (await loadVisualDev.getInfo(id)) as FormDetail
const summary = {
id,
enCode: data.enCode,
fullName: data.fullName,
state: data.state,
mode: opts.summary ? 'summary' : (opts.json ? 'json-decoded' : 'json-raw'),
}
printJson(decoded)
return
if (opts.summary) {
const tables = (Array.isArray(data.tables) ? data.tables : []) as Array<{ table?: string }>
log.ok(`${data.fullName} (${data.enCode})`)
log.dim(`id : ${data.id}`)
log.dim(`state : ${data.state} type: ${data.type} webType: ${data.webType}`)
log.dim(`dbLinkId : ${data.dbLinkId || '(none)'}`)
log.dim(`category : ${data.category || '(none)'}`)
log.dim(`tables : ${tables.length} (${tables.map((t) => t.table).join(', ')})`)
return ctx.success(summary)
}
// v0.13+ BS-新1: --json 模式解 formData/columnData/tables escaped JSON
if (opts.json) {
const decoded = { ...data } as Record<string, unknown>
for (const key of ['formData', 'columnData', 'appColumnData', 'tables']) {
if (key in decoded) {
decoded[key] = tryParseJsonString(decoded[key])
}
}
printJson(decoded)
return ctx.success(summary)
}
printJson(data)
ctx.success(summary)
} catch (e) {
const errMsg = (e as Error).message?.slice(0, 200)
log.error(`form info 失败: ${errMsg}`)
if (opts.json) printJson({ error: errMsg, id })
ctx.fail(`form info 失败: ${errMsg}`, { id })
}
printJson(data)
} catch (e) {
cmdError = (e as Error).message?.slice(0, 200)
log.error(`form info 失败: ${cmdError}`)
if (opts.json) printJson({ error: cmdError, id })
} finally {
// v2.1+ (2026-07-21): 落 CommandLog (L3) — info 类查询历史可追溯
printCommandEnd({
command: 'form info',
appCode: c.appCode,
result: cmdError ? 'failure' : 'success',
error: cmdError,
summary: cmdSummary,
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
if (cmdError) process.exit(1)
}
})
})
installHelpHookWithPatterns(cmd, 'form info', {
+1 -1
View File
@@ -69,7 +69,7 @@ export function buildFormReleaseCommand(): Command {
const bs37 = postIssues.filter(i => i.id === 'BS-37' && i.level === 'WARN')
if (bs37.length) {
log.warn('Blindspot guard 提示:')
console.warn(formatIssues(bs37))
log.warn(formatIssues(bs37))
}
}
}
+2 -1
View File
@@ -8,6 +8,7 @@ import { Command } from 'commander';
import { query, SCHEMA } from './_client';
import { SCHEMA_DDL } from './_schema';
import { log } from '../../core/log.ts'
export function registerInit(program: Command) {
program
.command('init')
@@ -37,7 +38,7 @@ export function registerInit(program: Command) {
console.log(` - Triggers (${triggers.length}): ${triggers.map(t => t.trigger_name).join(', ')}`);
console.log(` - Views (${views.length}): ${views.map(v => v.table_name).join(', ')}`);
} catch (e: any) {
console.error(`✗ Init failed: ${e.message}`);
log.error(`✗ Init failed: ${e.message}`);
process.exit(1);
}
});
+2 -1
View File
@@ -1,13 +1,14 @@
import { Command } from 'commander';
import { query, SCHEMA } from './_client.ts';
import { log } from '../../core/log.ts'
export function buildKbAuditCommand(): Command {
return new Command('audit')
.argument('[type]', 'Audit type', 'stale')
.description('Audit KB health (type: stale, default)')
.action(async (type: string = 'stale') => {
if (type !== 'stale') {
console.error(`✗ Unknown audit type '${type}'. Supported: stale`);
log.error(`✗ Unknown audit type '${type}'. Supported: stale`);
process.exit(1);
}
+2 -1
View File
@@ -1,6 +1,7 @@
import { Command } from 'commander';
import { execute, SCHEMA } from './_client.ts';
import { log } from '../../core/log.ts'
export function buildKbDeprecateCommand(): Command {
return new Command('deprecate')
.argument('<id>', 'Entry id (the one being deprecated)')
@@ -16,7 +17,7 @@ export function buildKbDeprecateCommand(): Command {
[oldId]
);
if (n === 0) {
console.error(`✗ Entry #${id} not found`);
log.error(`✗ Entry #${id} not found`);
process.exit(1);
}
// 2. INSERT replacements
+2 -1
View File
@@ -2,6 +2,7 @@ import { Command } from 'commander';
import * as readline from 'readline';
import { query, SCHEMA } from './_client.ts';
import { log } from '../../core/log.ts'
function ask(rl: readline.Interface, q: string): Promise<string> {
return new Promise(resolve => rl.question(q, resolve));
}
@@ -31,7 +32,7 @@ export function buildKbEntryCommand(): Command {
[domain]
);
if (domainRow.length === 0) {
console.error(`✗ Domain '${domain}' not found`);
log.error(`✗ Domain '${domain}' not found`);
process.exit(1);
}
const domainId = domainRow[0].id;
+2 -1
View File
@@ -1,6 +1,7 @@
import { Command } from 'commander';
import { query, SCHEMA } from './_client.ts';
import { log } from '../../core/log.ts'
export function buildKbShowCommand(): Command {
return new Command('show')
.argument('<domain>', 'Domain name (e.g. dacli)')
@@ -12,7 +13,7 @@ export function buildKbShowCommand(): Command {
[domain]
);
if (meta.length === 0) {
console.error(`✗ Domain '${domain}' not found`);
log.error(`✗ Domain '${domain}' not found`);
process.exit(1);
}
const m = meta[0];
+1 -1
View File
@@ -164,7 +164,7 @@ function renderBashScript(p: {
}
const date = formItem.locator('.ant-picker input').first();
if (await date.count() > 0) { await date.fill('${f.sample}'); return; }
console.warn('未找到字段: ${f.label} (vmodel=${f.vmodel})');
log.warn('未找到字段: ${f.label} (vmodel=${f.vmodel})');
}"`
})
.join('\n\n')
+1 -1
View File
@@ -186,7 +186,7 @@ export function buildTestRenderCommand(): Command {
}
} catch (e) {
log.error(`运行异常: ${(e as Error).message}`)
if (process.env.DACLI_DEBUG === '1') console.error(e)
if (process.env.DACLI_DEBUG === '1') log.error(e)
process.exit(1)
}
+90 -70
View File
@@ -11,11 +11,11 @@ import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { setupOutputFilter } from '../_output_filter.ts'
import { setupOutputFilter, wrapCommand } from '../_output_filter.ts' // v2.2+ wrapCommand 收口 5c 样板, 顺便补 CommandLog (旧版 raw exit 没落 L3)
import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
interface Opts { id: string; json?: boolean; includeInternals?: boolean }
interface Opts { id: string; json?: boolean; verbose?: boolean; includeInternals?: boolean }
export function buildWorkflowInfoCommand(): Command {
const cmd = new Command('info')
@@ -27,76 +27,96 @@ export function buildWorkflowInfoCommand(): Command {
.action(async (opts: Opts) => {
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
await initWebapi(c)
// v0.12+ Bug 4 修复: 优先 getInfo (basic, 必成功), 然后 chain getFlowInfo (full, fallback)
const basic = (await loadWorkflow.getInfo(opts.id)) as Record<string, unknown>
if (!basic) {
const enhanced = enhanceFromBackend('id 不存在或已被删除', 'id', { entity: 'workflow' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })}`)
process.exit(1)
}
let full: Record<string, unknown> | null = null
let enabledMark: number | undefined
let flowId: string | undefined
try {
// 从 Version 列表取一个 flowJson id, 然后拉完整信息
const versions = (await loadWorkflow.getVersionList(opts.id)) as Array<{ id: string; state: number }>
if (Array.isArray(versions) && versions.length > 0) {
flowId = versions[0].id
full = (await loadWorkflow.getFlowInfo(flowId)) as Record<string, unknown>
}
} catch {
// 拉取失败用 basic 信息 (兜底)
}
// enabledMark: 从 list 接口拿 (TemplatePageLisVO 才有 enabledMark 字段, 其他 VO 都没有)
try {
const listResp = (await loadWorkflow.getList({ currentPage: 1, pageSize: 200 })) as {
list?: Array<{ id: string; enabledMark?: number; status?: number; flowId?: string }>
}
const item = listResp.list?.find((t) => t.id === opts.id)
if (item) {
enabledMark = item.enabledMark
// basic 缺的 status 用 list 补
if (basic.status === undefined && item.status !== undefined) {
basic.status = item.status
await wrapCommand({
command: 'workflow info',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
await initWebapi(c)
// v0.12+ Bug 4 修复: 优先 getInfo (basic, 必成功), 然后 chain getFlowInfo (full, fallback)
const basic = (await loadWorkflow.getInfo(opts.id)) as Record<string, unknown>
if (!basic) {
const enhanced = enhanceFromBackend('id 不存在或已被删除', 'id', { entity: 'workflow' })
log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })}`)
return ctx.fail('id 不存在或已被删除', { id: opts.id })
}
let full: Record<string, unknown> | null = null
let enabledMark: number | undefined
let flowId: string | undefined
try {
// 从 Version 列表取一个 flowJson id, 然后拉完整信息
const versions = (await loadWorkflow.getVersionList(opts.id)) as Array<{ id: string; state: number }>
if (Array.isArray(versions) && versions.length > 0) {
flowId = versions[0].id
full = (await loadWorkflow.getFlowInfo(flowId)) as Record<string, unknown>
}
} catch {
// 拉取失败用 basic 信息 (兜底)
}
// enabledMark: 从 list 接口拿 (TemplatePageLisVO 才有 enabledMark 字段, 其他 VO 都没有)
try {
const listResp = (await loadWorkflow.getList({ currentPage: 1, pageSize: 200 })) as {
list?: Array<{ id: string; enabledMark?: number; status?: number; flowId?: string }>
}
const item = listResp.list?.find((t) => t.id === opts.id)
if (item) {
enabledMark = item.enabledMark
// basic 缺的 status 用 list 补
if (basic.status === undefined && item.status !== undefined) {
basic.status = item.status
}
}
} catch {
// 拉取失败忽略
}
// 合并: basic + full + list-兜底字段
// v0.21+ BS-drift-W-2 fix: 把 list-兜底的 enabledMark 合并进 d (业务侧 enabledMark=1 过滤不漏掉)
const d: Record<string, unknown> = {
...basic,
...(full || {}),
// status=1 (上架) 且 list 有 enabledMark → 优先用 list 值 (1=启用)
// 否则 fallback: status=1 → enabledMark=1 (兜底)
enabledMark: enabledMark !== undefined ? enabledMark : (basic.status === 1 ? 1 : 0),
}
const summary = {
id: opts.id,
flowId: (d.flowId as string) || flowId,
fullInfoLoaded: !!full,
}
if (opts.json) {
// BS-E11 (Round 8 P2): 默认隐藏内部调试字段
// 这些是 webapi 内部状态, 不属于 workflow schema, AI 拿到会困惑
// 加 --include-internals 才输出
const payload = opts.includeInternals
? { ...d, _fullInfoLoaded: !!full, _flowIdUsed: flowId, _enabledMarkFromList: enabledMark }
: d
printJson(payload)
return ctx.success(summary)
}
log.info(`流程模板详情 (id=${opts.id}${full ? ' [完整信息已加载]' : ' [仅基础信息]'})`)
console.log(` fullName : ${d.fullName}`)
console.log(` enCode : ${d.enCode}`)
console.log(` category : ${d.category}`)
console.log(
` enabledMark : ${enabledMark === 1 ? '启用' : enabledMark === 0 ? '禁用' : '未知'}`,
)
console.log(` status : ${d.status === 1 ? '上架' : d.status === 0 ? '未上架' : d.status}`)
console.log(` version : ${d.version || (d as { flowVersion?: string }).flowVersion || '1'}`)
console.log(` flowId : ${(d.flowId as string) || flowId || '-'}`)
console.log(` flowableId : ${d.flowableId || '-'}`)
console.log(` flowXml 长度 : ${d.flowXml ? String(d.flowXml).length : 0}`)
console.log(` flowNodes 节点数: ${d.flowNodes ? Object.keys(d.flowNodes as object).length : 0}`)
console.log(` description : ${d.description || '-'}`)
ctx.success(summary)
} catch (e) {
ctx.fail(`workflow info 失败: ${(e as Error).message?.slice(0, 200)}`, { id: opts.id })
}
} catch {
// 拉取失败忽略
}
// 合并: basic + full + list-兜底字段
// v0.21+ BS-drift-W-2 fix: 把 list-兜底的 enabledMark 合并进 d (业务侧 enabledMark=1 过滤不漏掉)
const d: Record<string, unknown> = {
...basic,
...(full || {}),
// status=1 (上架) 且 list 有 enabledMark → 优先用 list 值 (1=启用)
// 否则 fallback: status=1 → enabledMark=1 (兜底)
enabledMark: enabledMark !== undefined ? enabledMark : (basic.status === 1 ? 1 : 0),
}
if (opts.json) {
// BS-E11 (Round 8 P2): 默认隐藏内部调试字段
// 这些是 webapi 内部状态, 不属于 workflow schema, AI 拿到会困惑
// 加 --include-internals 才输出
const payload = opts.includeInternals
? { ...d, _fullInfoLoaded: !!full, _flowIdUsed: flowId, _enabledMarkFromList: enabledMark }
: d
printJson(payload)
return
}
log.info(`流程模板详情 (id=${opts.id}${full ? ' [完整信息已加载]' : ' [仅基础信息]'})`)
console.log(` fullName : ${d.fullName}`)
console.log(` enCode : ${d.enCode}`)
console.log(` category : ${d.category}`)
console.log(
` enabledMark : ${enabledMark === 1 ? '启用' : enabledMark === 0 ? '禁用' : '未知'}`,
)
console.log(` status : ${d.status === 1 ? '上架' : d.status === 0 ? '未上架' : d.status}`)
console.log(` version : ${d.version || (d as { flowVersion?: string }).flowVersion || '1'}`)
console.log(` flowId : ${(d.flowId as string) || flowId || '-'}`)
console.log(` flowableId : ${d.flowableId || '-'}`)
console.log(` flowXml 长度 : ${d.flowXml ? String(d.flowXml).length : 0}`)
console.log(` flowNodes 节点数: ${d.flowNodes ? Object.keys(d.flowNodes as object).length : 0}`)
console.log(` description : ${d.description || '-'}`)
})
})
installHelpHook(cmd, {
purpose: '流程模板详情. AI 引用 workflow id 验证 (P0 闭环). v0.12+ 优先 getFlowInfo 返回完整信息 (含 flowXml/flowNodes/enabledMark/flowId).',
+44 -55
View File
@@ -9,7 +9,7 @@ import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts'
import { setupOutputFilter, wrapCommand } from '../_output_filter.ts' // v2.2+ wrapCommand 收口 5c 样板
interface ListOpts {
category?: string
@@ -30,63 +30,52 @@ export function buildWorkflowListCommand(): Command {
.action(async (opts: ListOpts) => {
setupOutputFilter(opts)
const c = await JnpfClient.fromToken()
const startTime = Date.now()
let cmdError: string | undefined
let cmdSummary: Record<string, unknown> = {}
try {
const todo = Number(opts.todo || '0')
const path = todo > 0
? `/workflow/operator/List/${todo}`
: `/workflow/template${opts.category ? `?category=${opts.category}` : ''}`
const r = await c.get<{ list?: { id: string; fullName: string; enCode?: string; category?: string; flowId?: string; enabledMark?: number; status?: number }[]; msg?: string }>(path, {
currentPage: 1,
pageSize: opts.pageSize,
})
if (r.code !== 200) {
cmdError = r.msg || `code=${r.code}`
log.error(`workflow list 失败: ${cmdError}`)
// v2.1+ (2026-07-21): 错误路径落 CommandLog
printCommandEnd({
command: 'workflow list',
appCode: c.appCode,
result: 'failure',
error: cmdError,
summary: { path, category: opts.category, todo },
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
await wrapCommand({
command: 'workflow list',
appCode: c.appCode,
startTime: Date.now(),
verbose: opts.verbose,
json: opts.json,
fixes: [],
}, async (ctx) => {
try {
const todo = Number(opts.todo || '0')
const path = todo > 0
? `/workflow/operator/List/${todo}`
: `/workflow/template${opts.category ? `?category=${opts.category}` : ''}`
const r = await c.get<{ list?: { id: string; fullName: string; enCode?: string; category?: string; flowId?: string; enabledMark?: number; status?: number }[]; msg?: string }>(path, {
currentPage: 1,
pageSize: opts.pageSize,
})
process.exit(1)
if (r.code !== 200) {
const errMsg = r.msg || `code=${r.code}`
log.error(`workflow list 失败: ${errMsg}`)
return ctx.fail(`workflow list 失败: ${errMsg}`, { path, category: opts.category, todo })
}
const list = r.data?.list || []
const summary = { path, total: list.length, category: opts.category, todo }
if (opts.json) {
printJson(r.data)
return ctx.success(summary)
}
log.info(`${path} 共 ${list.length} 条`)
// v0.12+ jxcj-2026-06-29 fix: 多输出一列 FLOW_ID (TemplateJsonEntity.id = 最新 version id)
// 作用: launchFlow / actionLaunchFlow 用 template=FLOW_ID, 不要用 ID (TemplateEntity.id)
console.log('ID FLOW_ID FULL_NAME ENCODE CATEGORY')
console.log('-'.repeat(120))
for (const t of list) {
console.log(`${String(t.id || '').padEnd(36)}${String(t.flowId || '').padEnd(36)}${String(t.fullName || '').padEnd(22)}${String(t.enCode || '').padEnd(22)}${t.category || ''}`)
}
if (list.some((t) => t.id !== t.flowId)) {
log.info(` 💡 launchFlow / actionLaunchFlow 需用 FLOW_ID (≠ ID):`)
log.info(` dacli workflow launch --id=<FLOW_ID> ...`)
}
ctx.success(summary)
} catch (e) {
ctx.fail(`workflow list 失败: ${(e as Error).message?.slice(0, 200)}`, { path: '/workflow/template' })
}
const list = r.data?.list || []
cmdSummary = { path, total: list.length, category: opts.category, todo }
if (opts.json) { printJson(r.data); return }
log.info(`${path} 共 ${list.length} 条`)
// v0.12+ jxcj-2026-06-29 fix: 多输出一列 FLOW_ID (TemplateJsonEntity.id = 最新 version id)
// 作用: launchFlow / actionLaunchFlow 用 template=FLOW_ID, 不要用 ID (TemplateEntity.id)
console.log('ID FLOW_ID FULL_NAME ENCODE CATEGORY')
console.log('-'.repeat(120))
for (const t of list) {
console.log(`${String(t.id || '').padEnd(36)}${String(t.flowId || '').padEnd(36)}${String(t.fullName || '').padEnd(22)}${String(t.enCode || '').padEnd(22)}${t.category || ''}`)
}
if (list.some((t) => t.id !== t.flowId)) {
log.info(` 💡 launchFlow / actionLaunchFlow 需用 FLOW_ID (≠ ID):`)
log.info(` dacli workflow launch --id=<FLOW_ID> ...`)
}
} finally {
// v2.1+ (2026-07-21): 落 CommandLog (L3) — list 类查询历史可追溯
printCommandEnd({
command: 'workflow list',
appCode: c.appCode,
result: cmdError ? 'failure' : 'success',
error: cmdError,
summary: cmdSummary,
duration_ms: Date.now() - startTime,
verbose: opts.verbose,
json: opts.json,
})
}
})
})
installHelpHook(cmd, {