2026-07-22 10:55:17 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
/**
|
2026-07-25 15:50:10 +08:00
|
|
|
* dsh — command-line entry. Dynamic imports per mode keep unrelated modes out
|
|
|
|
|
* of each dispatch path; the adapter prints and exits for
|
2026-07-25 14:15:25 +08:00
|
|
|
* `--help`/`--version`/a parse error, so only a valid mode reaches the switch.
|
2026-07-22 10:55:17 +08:00
|
|
|
* @module @deepseek-ai/dsh/bin
|
|
|
|
|
*/
|
|
|
|
|
|
2026-08-04 10:07:17 +08:00
|
|
|
/* v8 ignore file -- built-bin acceptance exercises this self-executing dispatch. */
|
2026-07-22 10:55:17 +08:00
|
|
|
|
2026-07-24 19:43:59 +08:00
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import { fileURLToPath } from 'node:url'
|
feat(credentials): move the store to .credentials.yaml and layer $DSH_HOME/.env
$DSH_HOME/.env carried two incompatible jobs. As credentials-local's writable
secret store it could not be hoisted into process.env — hoisting makes every
stored key read as a read-only launch override and blocks rotation from the
TUI and the web page. But its name and dotenv format promise an environment
file, so a DEEPSEEK_BASE_URL sitting beside a working DEEPSEEK_API_KEY in the
same file was silently ignored: only the credential provider read the
document, and it addresses credential references alone.
Split the two jobs into two files.
.credentials.yaml is the provider-managed store: a strict YAML mapping of
CredentialRef to non-empty string, no version field, no wrapper level. Because
it holds credentials and nothing else, a non-mapping root, a non-identifier
key, a non-string value, an empty string, a duplicate key, and malformed YAML
are all rejections rather than skipped entries — loud at boot and at a write,
warn-and-keep-last-good on a live reload. The dotenv physical-line editor
gives way to a patch of the parsed document, so comments and untouched entries
keep their formatting and any string value round-trips, multi-line included.
Writer lock, read-modify-write, atomic 0600 write under a 0700 directory,
watcher, self-write suppression, and quiescent disposal are unchanged.
$DSH_HOME/.env becomes the user's ordinary environment layer. app-boot's new
loadLayeredEnv loads the invoking directory's .env then the Harness home's,
giving user < project < inherited; the home resolves from the inherited
environment first, so a project .env cannot redirect it.
Credential precedence is unchanged: the live environment still wins read-only
over the file, and shadowed writes still reject. Whether a provider-managed
store should instead win over the environment is a separate decision.
No migration: a key already in $DSH_HOME/.env keeps resolving through the new
environment layer, as a read-only env source that shadows the stored one.
2026-08-04 14:50:38 +08:00
|
|
|
import { loadLayeredEnv } from '@deepseek-ai/dsh-app-boot'
|
2026-07-24 19:43:59 +08:00
|
|
|
import { parseDshArgs } from './args.ts'
|
|
|
|
|
|
|
|
|
|
// Both the source tree (apps/cli/src) and the bundled bin (apps/cli/lib) sit
|
|
|
|
|
// one directory under apps/cli, so the checked-in manifest resolves with the
|
|
|
|
|
// same relative hop from either artifact.
|
|
|
|
|
/** This app's version, read from its checked-in package.json. */
|
|
|
|
|
function readVersion(): string {
|
|
|
|
|
const manifest = JSON.parse(
|
|
|
|
|
readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'),
|
|
|
|
|
) as { version?: unknown }
|
|
|
|
|
return typeof manifest.version === 'string' ? manifest.version : '0.0.0'
|
|
|
|
|
}
|
2026-07-22 10:55:17 +08:00
|
|
|
|
2026-08-04 10:07:17 +08:00
|
|
|
const invocation = parseDshArgs(process.argv.slice(2), readVersion())
|
2026-07-22 10:55:17 +08:00
|
|
|
|
2026-07-24 19:43:59 +08:00
|
|
|
switch (invocation.mode) {
|
2026-08-06 04:40:32 +08:00
|
|
|
case 'profile': {
|
|
|
|
|
const { runProfile } = await import('./profile-boot.ts')
|
|
|
|
|
await runProfile({
|
2026-08-07 23:28:17 +08:00
|
|
|
environment: loadLayeredEnv('dsh'),
|
2026-08-06 04:40:32 +08:00
|
|
|
profile: invocation.profile,
|
|
|
|
|
patchFiles: invocation.patches,
|
2026-08-08 02:07:11 +08:00
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
case 'run': {
|
|
|
|
|
const { runProfile } = await import('./profile-boot.ts')
|
|
|
|
|
await runProfile({
|
|
|
|
|
environment: loadLayeredEnv('dsh'),
|
|
|
|
|
profile: invocation.profile,
|
|
|
|
|
patchFiles: invocation.patches,
|
|
|
|
|
task: invocation.task,
|
2026-08-06 04:40:32 +08:00
|
|
|
})
|
2026-08-04 10:07:17 +08:00
|
|
|
break
|
|
|
|
|
}
|
2026-07-24 19:43:59 +08:00
|
|
|
case 'web': {
|
|
|
|
|
const { runWeb } = await import('./web.ts')
|
2026-08-07 23:28:17 +08:00
|
|
|
await runWeb(invocation, loadLayeredEnv('dsh'))
|
2026-07-24 19:43:59 +08:00
|
|
|
break
|
|
|
|
|
}
|
2026-08-06 04:40:32 +08:00
|
|
|
case 'plugin': {
|
|
|
|
|
const { runPlugin } = await import('./plugin.ts')
|
|
|
|
|
process.exit(runPlugin(invocation.profile, invocation.args))
|
2026-07-29 15:28:38 +08:00
|
|
|
break
|
|
|
|
|
}
|
2026-07-31 02:00:01 +08:00
|
|
|
case 'dump-config': {
|
|
|
|
|
const { runDumpConfig } = await import('./dump-config.ts')
|
2026-08-06 04:40:32 +08:00
|
|
|
runDumpConfig(invocation.profile, invocation.defaultOnly, invocation.patches)
|
2026-07-31 02:00:01 +08:00
|
|
|
break
|
|
|
|
|
}
|
2026-07-24 19:43:59 +08:00
|
|
|
default:
|
|
|
|
|
invocation satisfies never
|
|
|
|
|
throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`)
|
2026-07-22 10:55:17 +08:00
|
|
|
}
|