P1 (0.5h):
- dm/drop.ts 加 TTY 拦截 — 镜像 form/delete.ts:25 + print/delete.ts:46 +
report/delete.ts:39 已稳定的 pattern: `if (!opts.yes && process.stdin.isTTY)` 时
warn + exit 1; 非 TTY 模式 (CI/脚本) 静默 --yes 走即可. 同步 DOC 注释 + 移除 TODO.
- storage/info.ts:38 DacliError 分叉 — 验证**实际不存在** (`class DacliError`
仅 src/core/types.ts:57 一处定义, 已被 storage/_helpers.ts:21 正确 import).
ADR 0015 §2.2 早期记述有误, 修订清空.
shim 清理 (0.5h):
- 11 个 workflow 子命令 (approve/create/decision/delete/info/launch/list/
selector/syncForm/tasks/update) 把 `import { ... } from './_output.ts'`
改成 `from '../_output_filter.ts'` (1 行 sed × 11 文件).
- 删除 src/commands/workflow/_output.ts shim 文件 (D 掉), 减少 1 个间接层.
- 不影响 L1 输出过滤 / L3 CommandLog 落盘, 因接口签名不变.
验证:
- TS compile: 56 errors baseline 不变, 0 新错误
- 68/68 单元测试 PASS (含 tests/unit/workflow/create_stale_retry)
- 端到端: dacli dm drop --help + dacli workflow info --help 完整
118 lines
6.0 KiB
TypeScript
118 lines
6.0 KiB
TypeScript
/**
|
|
* commands/workflow/info.ts — 流程模板详情
|
|
*
|
|
* v0.11+ Phase 2: webapi 化 (loadWorkflow.getInfo)
|
|
* v0.12+ Bug 4 修复: 优先 getFlowInfo (Info/{flowJsonId}) 拿完整信息
|
|
* getInfo (/template/{id}) 返回 TemplateInfoVO, 缺 enabledMark/flowXml/formId
|
|
* getFlowInfo (/template/Info/{flowJsonId}) 返回 TemplateJsonInfoVO, 含全部字段
|
|
* 链: getInfo (basic) → getVersionList → getFlowInfo (full, fallback)
|
|
*/
|
|
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 { initWebapi, loadWorkflow } from '../../webapi/workflow.ts'
|
|
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
|
|
|
interface Opts { id: string; json?: boolean; includeInternals?: boolean }
|
|
|
|
export function buildWorkflowInfoCommand(): Command {
|
|
const cmd = new Command('info')
|
|
.description('流程模板详情 (含 category/enabledMark/version/关联 form, v0.12+ 优先 getFlowInfo 返回完整信息)')
|
|
.requiredOption('--id <id>', '流程模板 id')
|
|
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
|
|
.option('--json', '原始 JSON 输出', false)
|
|
.option('--include-internals', '输出 webapi 内部调试字段 (_fullInfoLoaded/_flowIdUsed/_enabledMarkFromList)', false)
|
|
.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
|
|
}
|
|
}
|
|
} 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).',
|
|
required: { '--id': '流程模板 id' },
|
|
optional: { '--json': '原始 JSON 输出' },
|
|
example: 'dacli workflow info --id=1234567890',
|
|
source: {
|
|
api: 'GET /api/workflow/template/{id} (basic) + /template/Info/{flowJsonId} (full)',
|
|
ref: 'web/.../api/workFlow/template.ts getInfo() + getFlowInfo() + getVersionList()',
|
|
},
|
|
notes: [
|
|
'v0.11+ 改用 webapi 镜像 (loadWorkflow.getInfo)',
|
|
'v0.12+ Bug 4 修复: 链 getInfo → getVersionList → getFlowInfo, 返回完整信息',
|
|
'fallback: getFlowInfo 失败时回退 basic 信息 (标记 [仅基础信息])',
|
|
],
|
|
})
|
|
return cmd
|
|
}
|