refactor: remove unrelated helper extractions

This commit is contained in:
Tianyi Cui
2026-07-21 00:25:51 +08:00
parent 0c08e34a4a
commit 9848fdf93e
7 changed files with 39 additions and 73 deletions

View File

@@ -6,7 +6,6 @@
import { parseArgs as parseNodeArgs } from 'node:util'
import { Command } from 'commander'
import { splitForwardedArgs } from './forwarding.ts'
/** Commands implemented by the dsh-sdk launcher. */
type DshSdkCommand = 'start' | 'dev' | 'build' | 'config' | 'create'
@@ -35,7 +34,9 @@ export function parseDshSdkArgs(argv: readonly string[]): DshSdkArgs {
if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
return { forwarded: [], help: true }
}
const { launcher: launcherArgv, forwarded: passthrough } = splitForwardedArgs(argv)
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')

View File

@@ -1,21 +0,0 @@
/** Argument-delimiter handling shared by the SDK launcher and its invariant. */
/** Launcher-owned arguments and opaque arguments following `--`. */
export interface ForwardedArgumentSplit {
/** Arguments parsed by the SDK launcher. */
readonly launcher: readonly string[]
/** Arguments passed unchanged to the selected project command. */
readonly forwarded: readonly string[]
}
/**
* Split the first `--` delimiter without interpreting either side.
* @param argv - complete user argument vector.
* @returns launcher arguments and post-delimiter arguments.
*/
export function splitForwardedArgs(argv: readonly string[]): ForwardedArgumentSplit {
const separator = argv.indexOf('--')
return separator === -1
? { launcher: argv, forwarded: [] }
: { launcher: argv.slice(0, separator), forwarded: argv.slice(separator + 1) }
}

View File

@@ -1,10 +0,0 @@
/** Model-facing constants shared by structured child execution and its invariant. */
/** The model-facing tool name a structured child must call to finish. */
export const STRUCTURED_OUTPUT_TOOL = 'structured_output'
/** The terminal structured-result instruction appended to a child request. */
export const STRUCTURED_OUTPUT_INSTRUCTION
= 'When you have your final answer, you MUST report it by calling the '
+ `\`${STRUCTURED_OUTPUT_TOOL}\` tool with arguments matching its parameter schema exactly. `
+ 'Do not finish with a plain text answer: only the tool call counts as your result.'

View File

@@ -15,9 +15,19 @@ import type { ContinuationStop } from '@deepseek-ai/dsh-agent'
import type { ContentBlock, ToolSchema } from '@deepseek-ai/dsh-llm'
import type { ToolExecution } from '@deepseek-ai/dsh-tools'
import { ToolArgsError, validateStructuredValue, type StructuredOutputSchema } from '@deepseek-ai/dsh-tools'
import { STRUCTURED_OUTPUT_INSTRUCTION, STRUCTURED_OUTPUT_TOOL } from './structured-protocol.ts'
export { STRUCTURED_OUTPUT_INSTRUCTION, STRUCTURED_OUTPUT_TOOL } from './structured-protocol.ts'
/** The model-facing tool name a structured child must call to finish. */
export const STRUCTURED_OUTPUT_TOOL = 'structured_output'
/**
* The instruction registered as the child's trailing (order-190, the end of
* the tool-guidance band) scoped prompt section: the demand travels with the
* tool, as ordinary prompt state of exactly one agent.
*/
export const STRUCTURED_OUTPUT_INSTRUCTION
= 'When you have your final answer, you MUST report it by calling the '
+ `\`${STRUCTURED_OUTPUT_TOOL}\` tool with arguments matching its parameter schema exactly. `
+ 'Do not finish with a plain text answer: only the tool call counts as your result.'
/** One structured run's live handle: read the captured value once the child settles. */
export interface StructuredAttachment {

View File

@@ -6,7 +6,12 @@
*/
import type { Context } from 'cordis'
import AgentRegistry from '@deepseek-ai/dsh-agent'
import LlmService from '@deepseek-ai/dsh-llm'
import SessionStore from '@deepseek-ai/dsh-session'
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
import type { Config as SystemPromptConfig } from '@deepseek-ai/dsh-system-prompt'
import ToolRegistry from '@deepseek-ai/dsh-tools'
import type { Config as ToolRegistryConfig } from '@deepseek-ai/dsh-tools'
/** Configuration forwarded to the prerequisite service plugins. */
@@ -33,19 +38,6 @@ export async function mountAgentLoopTestDependencies(
ctx: Context,
options: AgentLoopTestDependenciesOptions = {},
): Promise<void> {
const [
{ default: LlmService },
{ default: SessionStore },
{ default: SystemPrompt },
{ default: ToolRegistry },
{ default: AgentRegistry },
] = await Promise.all([
import('@deepseek-ai/dsh-llm'),
import('@deepseek-ai/dsh-session'),
import('@deepseek-ai/dsh-system-prompt'),
import('@deepseek-ai/dsh-tools'),
import('@deepseek-ai/dsh-agent'),
])
await ctx.plugin(LlmService)
await ctx.plugin(SessionStore)
await ctx.plugin(SystemPrompt, options.systemPrompt ?? {})

View File

@@ -1,23 +0,0 @@
/** Snapshot-aware application configuration path selection. @module @deepseek-ai/dsh-app-boot/config-path */
import { basename, dirname, resolve } from 'node:path'
/**
* Resolve the config to boot. Replay swaps a `cordis.yml` basename for
* `cordis.snapshot.yml` in the same directory; every other mode keeps the path.
* @param configPath - requested config path, absolute or relative to `cwd`.
* @param snapshotMode - bin `$DSH_SNAPSHOT`; only `replay` swaps the basename.
* @param cwd - base for a relative `configPath`.
* @returns the absolute path of the config to boot.
*/
export function resolveConfigPath(
configPath: string,
snapshotMode: string | undefined,
cwd: string = process.cwd(),
): string {
const absolute = resolve(cwd, configPath)
if (snapshotMode !== 'replay') return absolute
const dir = dirname(absolute)
const replayName = basename(absolute).replace(/cordis\.ya?ml$/, 'cordis.snapshot.yml')
return resolve(dir, replayName)
}

View File

@@ -6,12 +6,29 @@
*/
import { pathToFileURL } from 'node:url'
import { dirname, resolve } from 'node:path'
import { basename, dirname, resolve } from 'node:path'
import { Context } from 'cordis'
import Loader from '@cordisjs/plugin-loader'
import Include from '@cordisjs/plugin-include'
export { resolveConfigPath } from './config-path.ts'
/**
* Resolve the config to boot. Replay swaps a `cordis.yml` basename for
* `cordis.snapshot.yml` in the same directory; every other mode keeps the path.
* @param configPath - the requested config path (absolute, or relative to `cwd`).
* @param snapshotMode - the bin's `$DSH_SNAPSHOT` value; only `'replay'` swaps the
* basename.
* @param cwd - the base a relative `configPath` resolves against.
* @returns the absolute path of the config to boot.
*/
export function resolveConfigPath(
configPath: string, snapshotMode: string | undefined, cwd: string = process.cwd(),
): string {
const absolute = resolve(cwd, configPath)
if (snapshotMode !== 'replay') return absolute
const dir = dirname(absolute)
const replayName = basename(absolute).replace(/cordis\.ya?ml$/, 'cordis.snapshot.yml')
return resolve(dir, replayName)
}
/**
* Load the optional gitignored `.env` from `dir`. Missing files fall back to the