From bcf874db2bfc7e5e696ea45fa06fcbcf4f6f59b0 Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 21 Jul 2026 13:09:13 +0800 Subject: [PATCH] =?UTF-8?q?tier3(print/msg/org/schedule/app,=207=20files):?= =?UTF-8?q?=20=E8=B7=A8=E5=91=BD=E4=BB=A4=20auto-fix=20pipeline=20?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=20(S-X1/S-X2=20silent=20+=20G-X1=20suggest?= =?UTF-8?q?=20+=20L3=20CommandLog=20=E8=90=BD=E7=9B=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 参照 dict/typecreate.ts:14-66 boilerplate, 给写操作命令补齐三重提醒三重修复: L1 (--verbose/--json stdout 三模式): setupOutputFilter from _output_filter.ts L2 (silent/assertive/suggest 三级 fix): runCommandAutoFix + fetchExistingLists from _auto_fix.ts L3 (CommandLog 落盘, 失败也落): printCommandEnd from _output_filter.ts 修改文件: - print/create.ts (先于 dfeb935 自动 commit) - org/create.ts - msg/noticecreate.ts (MSERR114) - msg/templatecreate.ts (MSERR114 + 端点修复注释保留) - schedule/create.ts (SYS131 时间关系) - schedule/trigger.ts (W11-D4 手动触发, 仅 L1+L3) - app/login.ts (Phase E base_system 检测 + app 不存在回滚命令) - app/context.ts (新会话第一步入口, L3 落 dbLinkId/forms/menus 数量) 未触及 (留待后续 batch): - app/create.ts: 5-step 复杂创建 (system→DB→DataSource→授权→重登), 5 处 process.exit(1) 需重构为 throw + 集中 try/catch, 超出本轮估算 - app/clear.ts: 30KB destructive 操作, 三层接入风险 > 收益, 需先 --dry-run 保护再接入 - 已知 baseline pre-existing bugs: org/create 的 405 后端路由 fallback 问题, msg/notice 的 GET fallback 405 — 与本 commit 无关 L1 验证: npx tsc --noEmit 0 新错误 (7 文件相关 error 为空) L2/L3 e2e 抽样: - msg templateCreate S-X1/S-X2+L3 跑通 (e2e id=849237951593317317 已清理) - print create S-X1+S-X2+L3 跑通 (前置 commit dfeb935) - app context --json 单行 JSON + L3 落盘跑通 --- src/commands/app/context.ts | 45 ++++++++++++++++++++- src/commands/app/login.ts | 36 ++++++++++++++++- src/commands/msg/noticecreate.ts | 62 ++++++++++++++++++++++++++++- src/commands/msg/templatecreate.ts | 59 ++++++++++++++++++++++++++- src/commands/org/create.ts | 64 +++++++++++++++++++++++++++++- src/commands/schedule/create.ts | 61 ++++++++++++++++++++++++++-- src/commands/schedule/trigger.ts | 36 ++++++++++++++++- 7 files changed, 350 insertions(+), 13 deletions(-) diff --git a/src/commands/app/context.ts b/src/commands/app/context.ts index b97b017..2bc503e 100644 --- a/src/commands/app/context.ts +++ b/src/commands/app/context.ts @@ -18,6 +18,7 @@ import { installHelpHookWithPatterns } from '../../core/help.ts' import { log } from '../../core/log.ts' import { loadToken } from '../../core/config.ts' import type { AppContext, FormSummary } from '../../core/types.ts' +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘 import { checkSystemExists, formatSystemMissingHint, @@ -356,8 +357,13 @@ export function buildAppContextCommand(): Command { const cmd = new Command('context') .description('输出当前应用环境快照 (dbLinkId/enCode/表/菜单/token 状态). AI 新会话第一步先跑此命令.') .option('--json', '单行 JSON 输出 (AI 友好)', false) + .option('--verbose', '完整输出 (含 loadAppContext 内部 API 调用日志)', false) .option('--app ', '覆盖 token 中的 appCode (供快速切换测试)') - .action(async (opts: ContextOpts) => { + .action(async (opts: ContextOpts & { verbose?: boolean }) => { + // v2.1+ L1: stdout 三模式 (default=quiet, --verbose=完整, --json=单行 JSON; --json 优先) + setupOutputFilter(opts) + const startTime = Date.now() + // P1.2: 复用 loadAppContext 提取的核心采集逻辑 const ctx = await loadAppContext(opts.app ? { appCode: opts.app } : undefined) @@ -369,6 +375,16 @@ export function buildAppContextCommand(): Command { if (opts.json) { // 单行 JSON (AI 友好, 便于 grep/管道) console.log(JSON.stringify(ctx)) + // v2.1+ L3: 落 CommandLog (即使 --json, CommandLog 仍落, 供 dacli log last 查询) + printCommandEnd({ + command: 'app context', + appCode: ctx.appCode, + result: exitCode === 0 ? 'success' : 'partial', + summary: { appCode: ctx.appCode, systemExists: ctx.systemExists, dbLinkId: ctx.dbLinkId }, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: true, + }) if (exitCode !== 0) process.exit(exitCode) return } @@ -380,6 +396,17 @@ export function buildAppContextCommand(): Command { log.info(` 重建命令: dacli app create --appCode=${ctx.appCode} --appName="未知应用"`) log.info(` 自动恢复: dacli app init --appCode=${ctx.appCode} --auto-recover (v0.11e+, 自动重建+重登)`) log.dim(` ↑ 不要继续 form/menu CRUD, 会触发后端 NPE (Phase 4 复盘 2026-06-27)`) + // v2.1+ L3: 失败也落 CommandLog (rollback 命令已写入 stdout warnings) + printCommandEnd({ + command: 'app context', + appCode: ctx.appCode, + result: 'partial', + summary: { appCode: ctx.appCode, systemExists: false }, + error: `appCode=${ctx.appCode} 在 base_system 不存在`, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(exitCode) } @@ -395,6 +422,22 @@ export function buildAppContextCommand(): Command { log.warn(`采集警告 ${ctx.warnings.length} 条:`) for (const w of ctx.warnings) log.dim(` - ${w}`) } + + // v2.1+ L3: 成功落 CommandLog + printCommandEnd({ + command: 'app context', + appCode: ctx.appCode, + summary: { + appCode: ctx.appCode, + dbLinkId: ctx.dbLinkId, + releasedForms: ctx.releasedForms.length, + tables: ctx.existingTables.length, + menus: ctx.menus.length, + }, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) }) installHelpHookWithPatterns(cmd, 'app context', { diff --git a/src/commands/app/login.ts b/src/commands/app/login.ts index 6d12e9d..5c63140 100644 --- a/src/commands/app/login.ts +++ b/src/commands/app/login.ts @@ -1,9 +1,15 @@ /** - * commands/app/login.ts — `dacli app login` (原顶层 `dacli app login`, v0.9 重命名归入 app 命名空间) + * commands/app/login.ts — `dacli app login` (原顶层 `dacli app login`, v0.9 重命名归入 app 命名空间, v2.1+ 三层接入) * * v0.11e+ Phase E: 登录成功后立即验证 base_system 存在性 * 缺失时清除 token + 视为登录失败 + 退出码 1 + 提示重建命令 * 解决盲点: 旧版返 "✓ 登录成功" 但实际 app 不存在, 后续所有命令返间接错误 + * + * v2.1+ (2026-07-21) 三层接入: + * L1: --verbose (默认静默, --verbose 打印 base_system 检测结果) + * L2: 不走 runCommandAutoFix (login 是鉴权流, 无 schema); "app 不存在" 视为 assertive + + * rollback 命令 (`dacli app init` 主推荐, 已在 W11-D4/G 注释里写) + * L3: 登录历史落 CommandLog, 供 AI 查 "我什么时候登录到哪个 app" (`dacli log last` / `--detail`) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -17,6 +23,7 @@ import { import { installHelpHook } from '../../core/help.ts' import { log } from '../../core/log.ts' import { checkSystemExists } from './_check_system.ts' +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘 export function buildAppLoginCommand(): Command { const cmd = new Command('login') @@ -26,13 +33,20 @@ export function buildAppLoginCommand(): Command { .option('--appCode ', '应用代码 (testspace 推荐=测试场 | jxcj=业务 | developSystem/workSystem=只读 baseline)', DEFAULT_APP_CODE) .option('--baseUrl ', 'JNPF API 根地址 (含 /api)') .option('--no-check-system', '跳过 base_system 存在性检测 (默认 ON, v0.11e+ Phase E)') + .option('--verbose', '完整输出 (含 base_system 检测等过程日志)', false) .action(async (opts: { account: string password: string appCode: string baseUrl?: string checkSystem?: boolean + verbose?: boolean + json?: boolean }) => { + // v2.1+ L1: stdout 三模式 (默认静默, --verbose 完整, --json 仅返回 token 元数据) + setupOutputFilter(opts) + const startTime = Date.now() + const c = await JnpfClient.login({ account: opts.account, password: opts.password, @@ -49,9 +63,11 @@ export function buildAppLoginCommand(): Command { // - 关键词 "应用不存在" 而非 "base_system 不存在" // - 突出"如需要请重新 init"作为主推荐, create 作为备选 // - 用分隔线 + 大写 WARN 标记, 醒目 + let appExists = true const checkSystem = opts.checkSystem !== false // 默认 ON if (checkSystem) { const exists = await checkSystemExists(c, opts.appCode) + appExists = exists !== false if (exists === false) { // ⚠ 警告而非 fatal: 保留 token (允许继续调 app create/init 重建) log.warn(`┌─────────────────────────────────────────────────────────────────────┐`) @@ -80,6 +96,24 @@ export function buildAppLoginCommand(): Command { log.dim(`token : ${c.token.slice(0, 32)}... (${c.token.length} chars)`) if (c.dbLinkId) log.dim(`dbLinkId : ${c.dbLinkId}`) log.dim(`saved to : ${getTokenPath()}`) + + // v2.1+ L3: 登录历史落 CommandLog (供 AI 查 "何时登录到什么 app, app 是否存在") + // L2 assertive: app 不存在 → 打印 rollback 命令 (dacli app init --auto-recover), 已在 stdout log.warn 里 + printCommandEnd({ + command: 'app login', + appCode: c.appCode, + summary: { + account: c.account, + appCode: c.appCode, + baseUrl: c.baseUrl, + dbLinkId: c.dbLinkId, + appExists: appExists, + }, + result: appExists ? 'success' : 'partial', + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) }) installHelpHook(cmd, { diff --git a/src/commands/msg/noticecreate.ts b/src/commands/msg/noticecreate.ts index 8faff16..99a43bb 100644 --- a/src/commands/msg/noticecreate.ts +++ b/src/commands/msg/noticecreate.ts @@ -1,7 +1,16 @@ /** - * commands/msg/noticecreate.ts — 新建通知公告 + * commands/msg/noticecreate.ts — 新建通知公告 (v2.1+ 三层接入) * * API: POST /api/message/Notice + * + * v2.1+ (2026-07-21) 三层接入 (跨命令 auto-fix 模式, 参照 dict/typecreate.ts): + * L1: --verbose / --json 三模式 (commands/_output_filter.ts:setupOutputFilter) + * L2: 跨命令 auto-fix pipeline + * - enCode 含 `-`/`_` 自动 strip (S-X1 silent, BS-新38) + * - fullName 含 space/parens 自动 soften (S-X2 silent, BS-新52) + * - 已有 msg 重名 → suggest 加 `` 前缀 (G-X1 suggest) + * L3: 完成后落 CommandLog, 失败 (MSERR114) 也落 + * v0.11e+ Phase D1: step machine 校验 (MSERR114 系统编码规则) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -9,12 +18,15 @@ import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { validateMsgCreate } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘 interface CreateOpts { fullName: string enCode: string body?: string json?: boolean + verbose?: boolean } export function buildMsgNoticeCreateCommand(): Command { @@ -24,9 +36,20 @@ export function buildMsgNoticeCreateCommand(): Command { .requiredOption('--fullName ', '通知标题') .requiredOption('--enCode ', '通知编码') .option('--body ', '通知正文 (可选)') + .option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { + // v2.1+ L1: stdout 三模式 + setupOutputFilter(opts) const c = await JnpfClient.fromToken() + const startTime = Date.now() + + // v2.1+ L2 silent+suggest: 跨命令 auto-fix pipeline (S-X1/S-X2/G-X1) + const fixCtx = await fetchExistingLists(c, c.appCode) + const cmdFix = runCommandAutoFix(opts as unknown as Record, fixCtx) + if (cmdFix.silent.length > 0) { + Object.assign(opts, cmdFix.opts) + } // v0.11e+ Phase D1: step machine 校验 (MSERR114 系统编码规则) const validation = validateMsgCreate({ @@ -39,6 +62,18 @@ export function buildMsgNoticeCreateCommand(): Command { log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`) } } + // v2.1+ L3: 失败落 CommandLog (MSERR114 系统编码规则) + printCommandEnd({ + command: 'msg noticeCreate', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: validation.steps.flatMap(s => s.errors).map(e => e.message).join('; '), + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`) @@ -56,6 +91,18 @@ export function buildMsgNoticeCreateCommand(): Command { if (r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'msg', { entity: 'msg' }) log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) + // v2.1+ L3: API 失败落 CommandLog + printCommandEnd({ + command: 'msg noticeCreate', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: r.msg || `code=${r.code}`, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } let id = r.data?.id @@ -69,8 +116,19 @@ export function buildMsgNoticeCreateCommand(): Command { ) id = found?.id } - log.info(`✓ 通知公告创建成功 id=${id}`) + log.ok(`✓ 通知公告创建成功 id=${id}`) if (opts.json) printJson({ ...(r.data as object), id }) + + // v2.1+ L3: 落 CommandLog + 摘要 + "详情: dacli log last" + printCommandEnd({ + command: 'msg noticeCreate', + appCode: c.appCode, + summary: { id, enCode: opts.enCode, fullName: opts.fullName }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) }) installHelpHook(cmd, { purpose: '新建通知公告 (草稿, 用 notice-release 发布)', diff --git a/src/commands/msg/templatecreate.ts b/src/commands/msg/templatecreate.ts index fbbe887..954206c 100644 --- a/src/commands/msg/templatecreate.ts +++ b/src/commands/msg/templatecreate.ts @@ -1,11 +1,17 @@ /** - * commands/msg/templatecreate.ts — 新建消息模板 (v0.11e+ Phase D1 wire up) + * commands/msg/templatecreate.ts — 新建消息模板 (v0.11e+ Phase D1 wire up, v2.1+ 三层接入) * * 走 JNPF MessageTemplateConfig 端点 (web 真实端点, v0.11+ P0 修复) * * 修复历史: * - v0.10 错误端点: /api/system/MessageTemplate (web 端不存在) * - v0.11+ 正确端点: /api/message/MessageTemplateConfig (web api/msgCenter/msgTemplate.ts) + * + * v2.1+ (2026-07-21) 三层接入 (跨命令 auto-fix 模式, 参照 dict/typecreate.ts): + * L1: --verbose / --json 三模式 + * L2: 跨命令 auto-fix pipeline (S-X1/S-X2 silent + G-X1 suggest) + * L3: 完成后落 CommandLog, 失败 (MSERR114) 也落 + * v0.11e+ Phase D1: step machine 校验 (fullName/enCode 必填 + MSERR114 系统编码规则) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -13,6 +19,8 @@ import { installHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { validateMsgCreate } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘 interface CreateOpts { fullName: string @@ -20,6 +28,7 @@ interface CreateOpts { category?: string content?: string json?: boolean + verbose?: boolean } export function buildMsgTemplateCreateCommand(): Command { @@ -30,9 +39,20 @@ export function buildMsgTemplateCreateCommand(): Command { .requiredOption('--enCode ', '模板编码 (全平台唯一)') .option('--category ', '分类 (1=系统 2=业务)', '1') .option('--content ', '模板内容 (可选)') + .option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { + // v2.1+ L1: stdout 三模式 + setupOutputFilter(opts) const c = await JnpfClient.fromToken() + const startTime = Date.now() + + // v2.1+ L2 silent+suggest: 跨命令 auto-fix pipeline (S-X1/S-X2/G-X1) + const fixCtx = await fetchExistingLists(c, c.appCode) + const cmdFix = runCommandAutoFix(opts as unknown as Record, fixCtx) + if (cmdFix.silent.length > 0) { + Object.assign(opts, cmdFix.opts) + } // v0.11e+ Phase D1: step machine 校验 (fullName/enCode 必填 + MSERR114 系统编码规则) const validation = validateMsgCreate({ @@ -45,6 +65,18 @@ export function buildMsgTemplateCreateCommand(): Command { log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`) } } + // v2.1+ L3: 失败落 CommandLog + printCommandEnd({ + command: 'msg templateCreate', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: validation.steps.flatMap(s => s.errors).map(e => e.message).join('; '), + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`) @@ -62,6 +94,18 @@ export function buildMsgTemplateCreateCommand(): Command { if (r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'msgTemplate', { entity: 'msg' }) log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) + // v2.1+ L3: API 失败落 CommandLog + printCommandEnd({ + command: 'msg templateCreate', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: r.msg || `code=${r.code}`, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } let id = r.data?.id @@ -75,8 +119,19 @@ export function buildMsgTemplateCreateCommand(): Command { ) id = found?.id } - log.info(`✓ 消息模板创建成功 id=${id}`) + log.ok(`✓ 消息模板创建成功 id=${id}`) if (opts.json) printJson({ ...(r.data as object), id }) + + // v2.1+ L3: 落 CommandLog + printCommandEnd({ + command: 'msg templateCreate', + appCode: c.appCode, + summary: { id, enCode: opts.enCode, fullName: opts.fullName, category: opts.category }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) }) installHelpHook(cmd, { purpose: '新建消息模板 (修复 v0.10 错误端点)', diff --git a/src/commands/org/create.ts b/src/commands/org/create.ts index 79a471e..49c4d23 100644 --- a/src/commands/org/create.ts +++ b/src/commands/org/create.ts @@ -1,5 +1,5 @@ /** - * commands/org/create.ts — 新建组织 (Phase D1, v3.0+ 走 webapi/permission 镜像) + * commands/org/create.ts — 新建组织 (Phase D1, v3.0+ 走 webapi/permission 镜像, v2.1+ 三层接入) * * 镜像 web organize/Form.vue + 后端 OrganizeController * - PS036: 组织层级限制 @@ -7,6 +7,14 @@ * * v0.11e+ Phase D1: P3 命令 step machine 集成 * v3.0+ (2026-06-29 regression audit P0): 改用 webapi/permission.createOrg + * + * v2.1+ (2026-07-21) 三层接入 (跨命令 auto-fix 模式, 参照 dict/typecreate.ts): + * L1: --verbose / --json 三模式 (commands/_output_filter.ts:setupOutputFilter) + * L2: 跨命令 auto-fix pipeline + * - enCode 含 `-`/`_` 自动 strip (S-X1 silent, BS-新38) + * - fullName 含 space/parens 自动 soften (S-X2 silent, BS-新52) + * - 已有 org 重名 → suggest 加 `` 前缀 (G-X1 suggest) + * L3: 完成后落 CommandLog, 失败时也落 (含 PS013/PS036 错误) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -19,6 +27,8 @@ import { createOrg, getOrganizeList, } from '../../webapi/permission.ts' +import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix (S-X1/S-X2 silent + G-X1 suggest) +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘 interface CreateOpts { fullName: string @@ -28,6 +38,7 @@ interface CreateOpts { enabledMark?: string sortCode?: string json?: boolean + verbose?: boolean } export function buildOrgCreateCommand(): Command { @@ -39,9 +50,23 @@ export function buildOrgCreateCommand(): Command { .requiredOption('--category ', '组织类型: 0=公司 1=部门 2=小组') .option('--enabledMark ', '0/1 启用', '1') .option('--sortCode ', '排序', '0') + .option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { + // v2.1+ L1: stdout 三模式 — 默认 quiet, --verbose 全部输出, --json 原始 JSON + setupOutputFilter(opts) const c = await JnpfClient.fromToken() + const startTime = Date.now() + + // v2.1+ L2 silent+assertive+suggest: 跨命令 auto-fix pipeline (S-X1/S-X2/G-X1) + // - enCode 含 `-`/`_` 自动 strip (BS-新38 silent) + // - fullName 含 space/parens 自动 soften (BS-新52 silent) + // - 已有 org 重名 → suggest 加 `` 前缀 (启用需 fetchExistingLists) + const fixCtx = await fetchExistingLists(c, c.appCode) + const cmdFix = runCommandAutoFix(opts as unknown as Record, fixCtx) + if (cmdFix.silent.length > 0) { + Object.assign(opts, cmdFix.opts) + } // v0.11e+ Phase D1: step machine 校验 (PS036 层级 + PS013 parentId) const validation = validateOrgCreate({ @@ -58,6 +83,18 @@ export function buildOrgCreateCommand(): Command { log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`) } } + // v2.1+ L3: 失败也落 CommandLog (PS013/PS036 错误供 AI 查 dacli log last) + printCommandEnd({ + command: 'org create', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: validation.steps.flatMap(s => s.errors).map(e => e.message).join('; '), + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`) @@ -76,6 +113,18 @@ export function buildOrgCreateCommand(): Command { if (r.code !== 200 && r.code !== undefined) { const enhanced = enhanceFromBackend(r.msg || '', 'org', { entity: 'org' }) log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) + // v2.1+ L3: API 失败也落 CommandLog + printCommandEnd({ + command: 'org create', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName, parentId: opts.parentId }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: r.msg || `code=${r.code}`, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } let id = r.id @@ -89,8 +138,19 @@ export function buildOrgCreateCommand(): Command { ) id = found?.id } - log.info(`✓ 组织创建成功 id=${id}`) + log.ok(`✓ 组织创建成功 id=${id}`) if (opts.json) printJson({ ...(r as object), id }) + + // v2.1+ L3: 落 CommandLog + 打印摘要 + "详情: dacli log last" 提示 + printCommandEnd({ + command: 'org create', + appCode: c.appCode, + summary: { id, enCode: opts.enCode, fullName: opts.fullName, parentId: opts.parentId, category: opts.category }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) }) installHelpHook(cmd, { purpose: '新建组织 (v0.11e+ Phase D1 + step machine 校验, 镜像 web organize/Form.vue + 后端 OrganizeController + PS013/PS036)', diff --git a/src/commands/schedule/create.ts b/src/commands/schedule/create.ts index 66ec6ce..1559898 100644 --- a/src/commands/schedule/create.ts +++ b/src/commands/schedule/create.ts @@ -1,8 +1,14 @@ /** - * commands/schedule/create.ts — 新建定时任务 + * commands/schedule/create.ts — 新建定时任务 (v0.11+ Phase 2 webapi + v2.1+ 三层接入) * * v0.11+ Phase 2: webapi 化 (loadSchedule.create) * 替代 v0.10 直接 c.postJson + * + * v2.1+ (2026-07-21) 三层接入 (跨命令 auto-fix 模式, 参照 dict/typecreate.ts): + * L1: --verbose / --json 三模式 + * L2: 跨命令 auto-fix pipeline (S-X1/S-X2 silent + G-X1 suggest) + * L3: 完成后落 CommandLog, 失败 (cron 格式 / SYS131 时间关系) 也落 + * v0.11e+ Phase C1: step machine 校验 (cron 格式 + SYS131 时间关系) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' @@ -11,6 +17,8 @@ import { log, printJson } from '../../core/log.ts' import { initWebapi, loadSchedule } from '../../webapi/schedule.ts' import { validateScheduleCreate } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { runCommandAutoFix, fetchExistingLists } from '../_auto_fix.ts' // v2.1+ (2026-07-21): 跨命令 auto-fix +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘 interface CreateOpts { fullName: string @@ -22,11 +30,12 @@ interface CreateOpts { endTime?: string enabledMark?: string json?: boolean + verbose?: boolean } export function buildScheduleCreateCommand(): Command { const cmd = new Command('create') - .description('新建定时任务 (Quartz cron, v0.11+ webapi + v0.11e+ step machine)') + .description('新建定时任务 (Quartz cron, v0.11+ webapi + v0.11e+ step machine + v2.1+ 三层接入)') .requiredOption('--fullName ', '任务名称') .requiredOption('--enCode ', '任务编码') .requiredOption('--executeType ', '执行类型 (e.g. SQL/JavaScript/...)') @@ -35,11 +44,22 @@ export function buildScheduleCreateCommand(): Command { .option('--startTime ', 'v0.11e+ Phase C1: 开始时间 (ISO 格式, SYS131 校验)') .option('--endTime ', 'v0.11e+ Phase C1: 结束时间 (ISO 格式, SYS131 校验)') .option('--enabledMark ', 'v0.11e+ Phase C1: 0/1', '1') + .option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { + // v2.1+ L1: stdout 三模式 + setupOutputFilter(opts) const c = await JnpfClient.fromToken() + const startTime = Date.now() await initWebapi(c) + // v2.1+ L2 silent+suggest: 跨命令 auto-fix pipeline (S-X1/S-X2/G-X1) + const fixCtx = await fetchExistingLists(c, c.appCode) + const cmdFix = runCommandAutoFix(opts as unknown as Record, fixCtx) + if (cmdFix.silent.length > 0) { + Object.assign(opts, cmdFix.opts) + } + // v0.11e+ Phase C1: step machine 校验 (cron 格式 + SYS131 时间关系) const validation = validateScheduleCreate({ fullName: opts.fullName, @@ -55,6 +75,18 @@ export function buildScheduleCreateCommand(): Command { log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`) } } + // v2.1+ L3: 失败落 CommandLog (cron 格式 / SYS131 错误供 AI 查) + printCommandEnd({ + command: 'schedule create', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName, cron: opts.cron }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: validation.steps.flatMap(s => s.errors).map(e => e.message).join('; '), + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`) @@ -74,11 +106,34 @@ export function buildScheduleCreateCommand(): Command { if (r.code !== 200 && r.code !== undefined) { const enhanced = enhanceFromBackend(r.msg || '', 'schedule', { entity: 'schedule' }) log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) + // v2.1+ L3: API 失败落 CommandLog + printCommandEnd({ + command: 'schedule create', + appCode: c.appCode, + result: 'failure', + summary: { enCode: opts.enCode, fullName: opts.fullName, cron: opts.cron }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + error: r.msg || `code=${r.code}`, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } const id = r.id || r.data?.id - log.info(`✓ 定时任务创建成功 id=${id}`) + log.ok(`✓ 定时任务创建成功 id=${id}`) if (opts.json) printJson(r.data || r) + + // v2.1+ L3: 落 CommandLog + printCommandEnd({ + command: 'schedule create', + appCode: c.appCode, + summary: { id, enCode: opts.enCode, fullName: opts.fullName, cron: opts.cron }, + fixes: [...cmdFix.silent, ...cmdFix.assertive, ...cmdFix.suggestions], + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) }) installHelpHook(cmd, { purpose: '新建定时任务 (Quartz cron, 决策 9: 与工作流区别)', diff --git a/src/commands/schedule/trigger.ts b/src/commands/schedule/trigger.ts index 585f2a4..5678e5f 100644 --- a/src/commands/schedule/trigger.ts +++ b/src/commands/schedule/trigger.ts @@ -1,29 +1,61 @@ /** - * commands/schedule/trigger.ts — 手动触发定时任务 + * commands/schedule/trigger.ts — 手动触发定时任务 (v2.1+ 三层接入) * * API: POST /api/scheduletask/white/trigger + * + * v2.1+ (2026-07-21) 三层接入: + * L1: --verbose / --json (trigger result 仅 stdout, 无 id 生成, 不走 runCommandAutoFix 但走 stdout 三模式) + * L3: 触发结果落 CommandLog, 失败也落 (W11-D4 手动触发验证的可见性) */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { log } from '../../core/log.ts' +import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘 interface TriggerOpts { id: string + verbose?: boolean + json?: boolean } export function buildScheduleTriggerCommand(): Command { const cmd = new Command('trigger') .description('手动触发定时任务 (白名单, 不等 cron)') .requiredOption('--id ', '定时任务 id') + .option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false) + .option('--json', '原始 JSON 输出', false) .action(async (opts: TriggerOpts) => { + // v2.1+ L1: stdout 三模式 + setupOutputFilter(opts) const c = await JnpfClient.fromToken() + const startTime = Date.now() const r = await c.postJson('/scheduletask/white/trigger', { id: opts.id }) if (r.code !== 200) { log.error(`schedule trigger 失败: ${r.msg}`) + // v2.1+ L3: 失败落 CommandLog + printCommandEnd({ + command: 'schedule trigger', + appCode: c.appCode, + result: 'failure', + summary: { id: opts.id }, + error: r.msg || `code=${r.code}`, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) process.exit(1) } - log.info(`✓ 定时任务 id=${opts.id} 已触发`) + log.ok(`✓ 定时任务 id=${opts.id} 已触发`) + // v2.1+ L3: 成功落 CommandLog + printCommandEnd({ + command: 'schedule trigger', + appCode: c.appCode, + summary: { id: opts.id }, + duration_ms: Date.now() - startTime, + verbose: opts.verbose, + json: opts.json, + }) }) installHelpHook(cmd, { purpose: '手动触发定时任务 (不等 cron, 立即跑)',