feat(dacli): extend DacliHelp with 4 fields + add tests/core to vitest include

This commit is contained in:
ssw committed 2026-07-16 16:26:29 +08:00
1 parent f95fe29e85
commit c16bd298a7
2 files changed
+45 -6

No files matched your search

+27 -6
View File
@@ -7,24 +7,45 @@
*/
import type { Command } from 'commander'
export interface AiHelp {
export interface DacliHelp {
purpose: string
required?: Record<string, string>
optional?: Record<string, string>
example?: string | string[]
source?: { web?: string; api?: string; ref?: string }
/** 反模式: ❌ 错 / ✅ 对 配对 */
pitfalls?: Array<{
wrong: string
right: string
severity?: 'P0' | 'P1' | 'P2'
}>
/** 推荐做法 */
bestPractices?: string[]
/** 何时用 vs 何时不用 */
decisionTree?: string
/** 跨文件链接 */
relatedRefs?: string[]
/** legacy: 杂项 */
notes?: string[]
}
/** Backward-compat alias during migration */
export type AiHelp = DacliHelp
const AI_FLAGS = new Set(['--ai-help', '--example', '--source'])
/** 把元数据挂到 command 上, cli.ts 顶层会读 */
export function installAiHelpHook(cmd: Command, meta: AiHelp): void {
;(cmd as unknown as { _aiMeta?: AiHelp })._aiMeta = meta
export function installAiHelpHook(cmd: Command, meta: DacliHelp): void {
;(cmd as unknown as { _aiMeta?: DacliHelp })._aiMeta = meta
}
function getMeta(cmd: Command): AiHelp | undefined {
return (cmd as unknown as { _aiMeta?: AiHelp })._aiMeta
function getMeta(cmd: Command): DacliHelp | undefined {
return (cmd as unknown as { _aiMeta?: DacliHelp })._aiMeta
}
/**
@@ -65,7 +86,7 @@ export function maybeInterceptAiHelp(program: Command): boolean {
process.exit(0)
}
function renderAiHelp(cmd: Command, meta: AiHelp): string {
function renderAiHelp(cmd: Command, meta: DacliHelp): string {
const lines: string[] = []
// 拼出完整路径
const path: string[] = [cmd.name()]
+18
View File
@@ -0,0 +1,18 @@
import { describe, it, expect } from 'vitest'
import type { DacliHelp } from '../../src/core/help'
describe('DacliHelp interface', () => {
it('should accept the 4 new fields', () => {
const help: DacliHelp = {
purpose: 'test',
pitfalls: [{ wrong: 'wrong way', right: 'right way', severity: 'P0' }],
bestPractices: ['use --autoRelease'],
decisionTree: 'when A do B',
relatedRefs: ['docs/decisions/0001.md'],
}
expect(help.pitfalls).toHaveLength(1)
expect(help.bestPractices).toContain('use --autoRelease')
expect(help.decisionTree).toBe('when A do B')
expect(help.relatedRefs).toContain('docs/decisions/0001.md')
})
})