feat(v0.11+): log exception/request + di info/test/update/delete (6 个 P0 NEW-CMD)

Phase 1 审计 (cmd-review/log.md + di.md) 标记 P0 必补:

log 子命令 (P0 AI 调试核心):
- log exception (category=4) - Java 异常堆栈查询, AI 调试后端错误核心入口
- log request (category=5) - API 调用审计
- 累计 log 4 子命令 (login/operate/exception/request)

di 子命令 (P0 闭环):
- di info (查 schema + 参数, AI 引用 DI 必需)
- di test (测试调用, 校验链路)
- di update (改 schema/path)
- di delete (CRUD 闭环)
- 累计 di 5 子命令 (list/info/test/update/delete), 从 1 → 5

Web 端参考:
- log: web/api/system/log.ts getLogList(category=4/5)
- di: web/api/systemData/dataInterface.ts 完整 11 函数

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
sswandClaude committed 2026-06-25 15:18:30 +08:00
1 parent 90e938f384
commit 59a6b4aba4
8 files changed
+386 -5

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
/**
* commands/di/delete.ts — 数据接口删除
*
* v0.11+ Phase 2 新增: 闭环 DI CRUD
*
* API: DELETE /api/system/DataInterface/{id}
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log } from '../../core/log.ts'
interface Opts { id: string; yes?: boolean }
export function buildDiDeleteCommand(): Command {
const cmd = new Command('delete')
.description('数据接口删除 (硬删, 无回收)')
.requiredOption('--id <id>', '数据接口 id')
.option('--yes', '跳过确认', false)
.action(async (opts: Opts) => {
if (!opts.yes) {
log.warn(`即将删除 DI id=${opts.id}, 加 --yes 跳过确认`)
process.exit(2)
}
const c = await JnpfClient.fromToken()
const r = await c.del(`/system/DataInterface/${opts.id}`)
if (r.code !== 200) {
log.error(`di delete 失败: ${r.msg}`)
process.exit(1)
}
log.ok(`✓ DI id=${opts.id} 已删除`)
})
installAiHelpHook(cmd, {
purpose: '数据接口删除. 引用该 DI 的 form 会失效.',
required: { '--id': 'DI id', '--yes': '跳过确认' },
example: 'dacli di delete --id=1234567890 --yes',
source: { api: 'DELETE /api/system/DataInterface/{id}' },
notes: ['v0.11+ P0 新增, 引用 DI 的 form 会失效', '谨慎操作'],
})
return cmd
}
+11 -1
View File
@@ -1,11 +1,21 @@
/**
* commands/di/index.ts — di 父命令 (数据接口)
*
* v0.11+ Phase 2: 5 子命令 (list/info/test/update/delete) — 闭环 CRUD
*/
import { Command } from 'commander'
import { buildDiListCommand } from './list.ts'
import { buildDiInfoCommand } from './info.ts'
import { buildDiTestCommand } from './test.ts'
import { buildDiUpdateCommand } from './update.ts'
import { buildDiDeleteCommand } from './delete.ts'
export function buildDiCommand(): Command {
const cmd = new Command('di').description('数据接口 (弹窗选择/下拉补全/关联表单)')
const cmd = new Command('di').description('数据接口 (form 引用 DI 闭环 CRUD)')
cmd.addCommand(buildDiListCommand())
cmd.addCommand(buildDiInfoCommand())
cmd.addCommand(buildDiTestCommand())
cmd.addCommand(buildDiUpdateCommand())
cmd.addCommand(buildDiDeleteCommand())
return cmd
}
+52
View File
@@ -0,0 +1,52 @@
/**
* commands/di/info.ts — 数据接口详情
*
* v0.11+ Phase 2 新增: AI 拿到 di id 后查 schema + 参数 (form 引用 DI 闭环必需)
*
* API: GET /api/system/DataInterface/{id}
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface Opts { id: string; json?: boolean }
export function buildDiInfoCommand(): Command {
const cmd = new Command('info')
.description('数据接口详情 (含 request/response schema + 参数)')
.requiredOption('--id <id>', '数据接口 id')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<Record<string, unknown>>(`/system/DataInterface/${opts.id}`)
if (r.code !== 200 || !r.data) {
log.error(`di info 失败: ${r.msg || 'id 不存在'}`)
process.exit(1)
}
if (opts.json) {
printJson(r.data)
return
}
const d = r.data
log.info(`数据接口详情 (id=${opts.id})`)
console.log(` fullName : ${d.fullName}`)
console.log(` enCode : ${d.enCode}`)
console.log(` categoryId : ${d.categoryId}`)
console.log(` requestMethod : ${d.requestMethod || '-'} (GET/POST/PUT/DELETE)`)
console.log(` url : ${d.url || d.interfaceUrl || '-'}`)
console.log(` enabledMark : ${d.enabledMark === 1 ? '启用' : '禁用'}`)
console.log(` description : ${d.description || '-'}`)
if (d.requestParams) console.log(` requestParams : ${JSON.stringify(d.requestParams).slice(0, 200)}`)
if (d.responseParams) console.log(` responseParams : ${JSON.stringify(d.responseParams).slice(0, 200)}`)
})
installAiHelpHook(cmd, {
purpose: '数据接口详情 (含 request/response schema + 参数). AI 引用 DI 时查 schema 必需.',
required: { '--id': '数据接口 id' },
optional: { '--json': '原始 JSON 输出' },
example: 'dacli di info --id=1234567890',
source: { api: 'GET /api/system/DataInterface/{id}' },
notes: ['v0.11+ P0 新增, 之前 di 只有 list, AI 完全无法闭环'],
})
return cmd
}
+57
View File
@@ -0,0 +1,57 @@
/**
* commands/di/test.ts — 数据接口测试调用
*
* v0.11+ Phase 2 新增: AI 测试 DI 是否能正常调用 (校验链路)
*
* API: POST /api/system/DataInterface/{id}/Actions/Preview
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface Opts {
id: string
data?: string
json?: boolean
}
export function buildDiTestCommand(): Command {
const cmd = new Command('test')
.description('数据接口测试调用 (Preview)')
.requiredOption('--id <id>', '数据接口 id')
.option('--data <json>', '请求参数 JSON (默认空 {})', '{}')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => {
const c = await JnpfClient.fromToken()
let body: Record<string, unknown> = {}
try {
body = JSON.parse(opts.data || '{}')
} catch (e) {
log.error(`--data JSON 解析失败: ${(e as Error).message}`)
process.exit(2)
}
log.info(`POST /system/DataInterface/${opts.id}/Actions/Preview`)
const r = await c.postJson<unknown>(`/system/DataInterface/${opts.id}/Actions/Preview`, body)
if (r.code !== 200) {
log.error(`di test 失败 (code=${r.code}): ${r.msg}`)
if (opts.json) printJson(r)
process.exit(1)
}
log.ok(`✓ DI 测试调用 OK`)
if (opts.json) printJson(r.data)
else console.log(JSON.stringify(r.data, null, 2).slice(0, 500))
})
installAiHelpHook(cmd, {
purpose: '数据接口测试调用. AI 验证 DI 配置正确性 (链路, 鉴权, 返回值).',
required: { '--id': '数据接口 id' },
optional: { '--data': '请求参数 JSON (默认 {})', '--json': '原始 JSON 输出' },
example: [
'dacli di test --id=1234567890',
'dacli di test --id=1234567890 --data=\'{"userId":"u1"}\'',
],
source: { api: 'POST /api/system/DataInterface/{id}/Actions/Preview' },
notes: ['v0.11+ P0 新增, 之前 DI 测试需走 web 端, AI 无法独立验证'],
})
return cmd
}
+72
View File
@@ -0,0 +1,72 @@
/**
* commands/di/update.ts — 数据接口修改
*
* v0.11+ Phase 2 新增: AI 改 DI 配置 (webType/path 等)
*
* API: PUT /api/system/DataInterface/{id}
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface Opts {
id: string
fullName?: string
enCode?: string
categoryId?: string
requestMethod?: string
url?: string
json?: boolean
}
export function buildDiUpdateCommand(): Command {
const cmd = new Command('update')
.description('数据接口修改 (改 schema/path/参数)')
.requiredOption('--id <id>', '数据接口 id')
.option('--fullName <n>', '中文名')
.option('--enCode <e>', '英文编码')
.option('--categoryId <c>', '分类 id')
.option('--requestMethod <m>', '请求方法 (GET/POST/PUT/DELETE)')
.option('--url <u>', '接口路径/URL')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: Opts) => {
const c = await JnpfClient.fromToken()
// 先 GET 拉原 form, 然后合并更新
const origR = await c.get<Record<string, unknown>>(`/system/DataInterface/${opts.id}`)
if (origR.code !== 200 || !origR.data) {
log.error(`di update 失败 (拉原 DI): ${origR.msg || 'id 不存在'}`)
process.exit(1)
}
const body: Record<string, unknown> = { ...origR.data, id: opts.id }
if (opts.fullName) body.fullName = opts.fullName
if (opts.enCode) body.enCode = opts.enCode
if (opts.categoryId) body.categoryId = opts.categoryId
if (opts.requestMethod) body.requestMethod = opts.requestMethod
if (opts.url) body.url = opts.url
log.info(`PUT /system/DataInterface/${opts.id}`)
const r = await c.putJson<unknown>(`/system/DataInterface/${opts.id}`, body)
if (r.code !== 200) {
log.error(`di update 失败 (code=${r.code}): ${r.msg}`)
if (opts.json) printJson(r)
process.exit(1)
}
log.ok(`✓ DI 更新成功 (id=${opts.id})`)
if (opts.json) printJson(r.data)
})
installAiHelpHook(cmd, {
purpose: '数据接口修改 (改 schema/path/参数). PUT 语义, 未传字段保留原值.',
required: { '--id': '数据接口 id' },
optional: {
'--fullName': '中文名',
'--enCode': '英文编码',
'--categoryId': '分类 id',
'--requestMethod': '请求方法',
'--url': '接口路径/URL',
},
example: 'dacli di update --id=123 --url=/api/new/path',
source: { api: 'PUT /api/system/DataInterface/{id}' },
notes: ['v0.11+ P0 新增, 未传字段保留原值 (PUT 语义)'],
})
return cmd
}
+80
View File
@@ -0,0 +1,80 @@
/**
* commands/log/exception.ts — 异常日志 (P0 AI 调试核心入口)
*
* v0.11+ Phase 2 (2026-06-25) 新增: 异常日志 (category='4') 查后端 Java 异常堆栈
* 解决: form create 失败 → 想查异常原因 → log exception 命令不存在 盲点
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface ListOpts {
keyword?: string
json?: boolean
limit?: string
}
export function buildLogExceptionCommand(): Command {
const cmd = new Command('exception')
.description('异常日志 (Java 异常堆栈, AI 调试核心入口)')
.option('--keyword <k>', '按账号/异常名/URL 模糊搜索')
.option('--limit <n>', '最多取 N 条 (默认 20)', '20')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: ListOpts) => {
const c = await JnpfClient.fromToken()
// JNPF 异常日志 = Log + category='4' (web/src/views/sysLog/errorLog/index.vue)
const r = await c.get<{ list: Record<string, unknown>[] }>('/system/Log', {
category: '4',
keyword: opts.keyword,
currentPage: 1,
pageSize: opts.limit || '20',
})
if (r.code !== 200) {
log.error(`log exception 失败: ${r.msg}`)
process.exit(1)
}
const list = r.data?.list || []
if (opts.json) {
printJson(r.data)
return
}
log.info(`异常日志 ${list.length} 条 (category=4, 找后端 Java 异常堆栈)`)
for (const d of list) {
// 异常日志核心字段: userName / ipAddress / moduleName / requestMethod / requestUrl / json / createTime
const time = String(d.createTime || d.F_CreatorTime || '').slice(0, 19)
const user = String(d.userName || d.F_UserId || '-')
const url = String(d.requestUrl || d.F_RequestUrl || '-')
const module = String(d.moduleName || d.F_ModuleName || '-')
const method = String(d.requestMethod || d.F_RequestMethod || '-')
console.log(`[${time}] ${user} ${method} ${url} (${module})`)
// 输出 json 字段 (含异常堆栈, 不截断)
const json = String(d.json || d.F_Json || '')
if (json) {
console.log(' ↳ 异常详情:')
for (const line of json.split('\n').slice(0, 30)) console.log(` ${line}`)
if (json.split('\n').length > 30) console.log(` ... (共 ${json.split('\n').length} 行, --json 拿全)`)
}
}
})
installAiHelpHook(cmd, {
purpose: '异常日志 (Java 异常堆栈, AI 调试后端错误核心入口). 解决 form create 失败 / 业务异常无路径排查盲点.',
optional: { '--keyword': '按账号/异常名/URL 模糊搜索', '--limit': '最多取 N 条', '--json': '原始 JSON 输出' },
example: [
'dacli log exception',
'dacli log exception --keyword="NullPointer"',
'dacli log exception --keyword=form_create --limit=5',
],
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/sysLog/errorLog/index.vue',
api: 'GET /api/system/Log?category=4',
ref: 'dacli/docs/cmd-review/log.md §NEW-CMD P0',
},
notes: [
'v0.11+ P0 新增, 之前 AI 排查后端异常无路可走',
'category=4 是 JNPF 固定枚举 (1 登录 / 3 操作 / 4 异常 / 5 请求)',
'json 字段含完整 Java 堆栈, --json 拿全',
],
})
return cmd
}
+10 -4
View File
@@ -1,19 +1,25 @@
/**
* commands/log/index.ts — log 父命令
*
* JNPF 日志 (P2 收尾)
* JNPF 日志 (v0.7+ v2/v0.11+)
*
* 子命令:
* login 登录日志
* operate 操作日志
* login 登录日志 (category=1)
* operate 操作日志 (category=3)
* exception 异常日志 (category=4) — v0.11+ P0 AI 调试核心
* request 请求日志 (category=5) — v0.11+ P0 审计 API
*/
import { Command } from 'commander'
import { buildLogLoginCommand } from './login.ts'
import { buildLogOperateCommand } from './operate.ts'
import { buildLogExceptionCommand } from './exception.ts'
import { buildLogRequestCommand } from './request.ts'
export function buildLogCommand(): Command {
const cmd = new Command('log').description('日志 (P2: 登录日志 + 操作日志)')
const cmd = new Command('log').description('日志 (登录 / 操作 / 异常 / 请求, category 1/3/4/5)')
cmd.addCommand(buildLogLoginCommand())
cmd.addCommand(buildLogOperateCommand())
cmd.addCommand(buildLogExceptionCommand())
cmd.addCommand(buildLogRequestCommand())
return cmd
}
+63
View File
@@ -0,0 +1,63 @@
/**
* commands/log/request.ts — 请求日志 (P0 审计 API 调用)
*
* v0.11+ Phase 2 (2026-06-25) 新增: 请求日志 (category='5') 审计 API 调用
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface ListOpts {
keyword?: string
json?: boolean
limit?: string
}
export function buildLogRequestCommand(): Command {
const cmd = new Command('request')
.description('请求日志 (API 调用审计, category=5)')
.option('--keyword <k>', '按账号/URL 模糊搜索')
.option('--limit <n>', '最多取 N 条 (默认 20)', '20')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: ListOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<{ list: Record<string, unknown>[] }>('/system/Log', {
category: '5',
keyword: opts.keyword,
currentPage: 1,
pageSize: opts.limit || '20',
})
if (r.code !== 200) {
log.error(`log request 失败: ${r.msg}`)
process.exit(1)
}
const list = r.data?.list || []
if (opts.json) {
printJson(r.data)
return
}
log.info(`请求日志 ${list.length} 条 (category=5, 审计 API 调用)`)
for (const d of list) {
const time = String(d.createTime || '').slice(0, 19)
const user = String(d.userName || '-')
const method = String(d.requestMethod || '-')
const url = String(d.requestUrl || '-')
const ip = String(d.ipAddress || '-')
const status = String(d.status || d.F_Status || '-')
console.log(`[${time}] ${user} ${method} ${url} ip=${ip} status=${status}`)
}
})
installAiHelpHook(cmd, {
purpose: '请求日志 (API 调用审计). 排查 API 调用失败 / IP 异常.',
optional: { '--keyword': '按账号/URL 模糊搜索', '--limit': '最多取 N 条', '--json': '原始 JSON 输出' },
example: [
'dacli log request',
'dacli log request --keyword=/api/visualdev',
'dacli log request --keyword=500 --limit=10',
],
source: { web: 'web/apps/jnpf-web-apps-main/src/views/sysLog/requestLog/index.vue', api: 'GET /api/system/Log?category=5' },
notes: ['v0.11+ P0 新增, web 端已实现, 之前 dacli 缺'],
})
return cmd
}