Files
deepseek-harness/packages/scaffold/scripts/src/args.ts
Tianyi Cui 3fc35c91ff refactor(packages): dissolve ui/ and rename sdk/ to scaffold/
git mv per the regrouping RFC: the five human-collaboration seams and
tui join packages/interaction/, app-boot becomes packages/boot/, and
jsonrpc joins the renamed scaffold/ (formerly sdk/) as its server half
beside client/protocol/create-sdk/helper/scripts/telemetry, whose
folders drop the legacy sdk- prefix. Three new group README triplets
replace the ui/ and sdk/ ones; tsconfig references/paths/globs,
knip keys, vitest globs, gate scripts, catalogs, docs, and the
lockfile follow. Adds the four settled FIXME rename markers
(dsh-sdk-server, dsh-sdk-telemetry, dsh-sdk-helper, dsh-sdk-scripts).

The scaffold folders diverge from their npm names until those renames
land, so tsconfig.base.json maps the three affected names explicitly
beside the group wildcard. Also repairs two pre-existing stale-path
classes the strengthened sweep surfaced: docs/web-styling.md's retired
web-ui host package and type-model spec fixture-literal joins.

app-boot's three Loader-composition specs time out at the default 5s
under full-suite parallel load on this filesystem (pre-existing;
pass isolated with --testTimeout=30000); interaction/scaffold/boot
suites otherwise green (687 passed).
2026-08-09 01:21:12 +08:00

75 lines
2.9 KiB
TypeScript

/**
* Commander adapter for the dsh-sdk subcommand surface.
*
* @module @deepseek-ai/dsh-scripts/args
*/
import { parseArgs as parseNodeArgs } from 'node:util'
import { Command } from 'commander'
/** Commands implemented by the dsh-sdk launcher. */
type DshSdkCommand = 'start' | 'dev' | 'build' | 'config' | 'create'
/** Parsed dsh-sdk invocation. */
export interface DshSdkArgs {
command?: DshSdkCommand
target?: string
source?: string
forwarded: readonly string[]
help: boolean
}
/** Parse arbitrary project flags through Node's zero-schema argument parser. */
export function parseSdkBootArgs(argv: readonly string[]): Record<string, string | boolean | undefined> {
return parseNodeArgs({
args: [...argv],
strict: false,
allowPositionals: true,
allowNegative: true,
}).values
}
/** Parse one launcher invocation through real Commander subcommands. */
export function parseDshSdkArgs(argv: readonly string[]): DshSdkArgs {
if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
return { forwarded: [], help: true }
}
const separator = argv.indexOf('--')
const launcherArgv = separator === -1 ? argv : argv.slice(0, separator)
const passthrough = separator === -1 ? [] : argv.slice(separator + 1)
let parsed: DshSdkArgs | undefined
const program = new Command()
.name('dsh-sdk')
.helpOption(false)
.showHelpAfterError(false)
.exitOverride()
.configureOutput({
/* v8 ignore next -- the command wrapper renders the package-owned usage template */
writeOut: () => {},
/* v8 ignore next -- Commander errors are returned to the command wrapper */
writeErr: () => {},
})
program.command('start [target]').helpOption(false).action((target?: string) => {
parsed = { command: 'start', ...target ? { target } : {}, forwarded: [], help: false }
})
program.command('dev [target]').helpOption(false).action((target?: string) => {
parsed = { command: 'dev', ...target ? { target } : {}, forwarded: [], help: false }
})
program.command('build [args...]').helpOption(false).allowUnknownOption(true).action((args: string[] = []) => {
parsed = { command: 'build', forwarded: args, help: false }
})
program.command('config').helpOption(false).action(() => {
parsed = { command: 'config', forwarded: [], help: false }
})
program.command('create <source>').helpOption(false).action((source: string) => {
parsed = { command: 'create', source, forwarded: [], help: false }
})
program.parse([...launcherArgv], { from: 'user' })
/* v8 ignore next -- every registered Commander action above assigns parsed or Commander throws */
if (!parsed) throw new Error('dsh-sdk command did not resolve')
if (parsed.command === 'config' && passthrough.length > 0) {
throw new Error('dsh-sdk config does not accept forwarded arguments')
}
return { ...parsed, forwarded: [...parsed.forwarded, ...passthrough] }
}