From 9848fdf93e4cf35e905104152ad6a4eb377b3b7d Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Tue, 21 Jul 2026 00:25:51 +0800 Subject: [PATCH] refactor: remove unrelated helper extractions --- packages/sdk/scripts/src/args.ts | 5 ++-- packages/sdk/scripts/src/forwarding.ts | 21 ----------------- .../src/structured-protocol.ts | 10 -------- .../subagent-inprocess/src/structured.ts | 14 +++++++++-- .../support/agent-loop-testkit/src/index.ts | 18 ++++----------- packages/ui/app-boot/src/config-path.ts | 23 ------------------- packages/ui/app-boot/src/index.ts | 21 +++++++++++++++-- 7 files changed, 39 insertions(+), 73 deletions(-) delete mode 100644 packages/sdk/scripts/src/forwarding.ts delete mode 100644 packages/subagent/subagent-inprocess/src/structured-protocol.ts delete mode 100644 packages/ui/app-boot/src/config-path.ts diff --git a/packages/sdk/scripts/src/args.ts b/packages/sdk/scripts/src/args.ts index 448315a0ec..4d1ce867de 100644 --- a/packages/sdk/scripts/src/args.ts +++ b/packages/sdk/scripts/src/args.ts @@ -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') diff --git a/packages/sdk/scripts/src/forwarding.ts b/packages/sdk/scripts/src/forwarding.ts deleted file mode 100644 index 56fa85f564..0000000000 --- a/packages/sdk/scripts/src/forwarding.ts +++ /dev/null @@ -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) } -} diff --git a/packages/subagent/subagent-inprocess/src/structured-protocol.ts b/packages/subagent/subagent-inprocess/src/structured-protocol.ts deleted file mode 100644 index 8ae87e73b0..0000000000 --- a/packages/subagent/subagent-inprocess/src/structured-protocol.ts +++ /dev/null @@ -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.' diff --git a/packages/subagent/subagent-inprocess/src/structured.ts b/packages/subagent/subagent-inprocess/src/structured.ts index cecb7d173e..09aa2d24b7 100644 --- a/packages/subagent/subagent-inprocess/src/structured.ts +++ b/packages/subagent/subagent-inprocess/src/structured.ts @@ -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 { diff --git a/packages/support/agent-loop-testkit/src/index.ts b/packages/support/agent-loop-testkit/src/index.ts index ca7148ee23..c7b0cb7304 100644 --- a/packages/support/agent-loop-testkit/src/index.ts +++ b/packages/support/agent-loop-testkit/src/index.ts @@ -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 { - 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 ?? {}) diff --git a/packages/ui/app-boot/src/config-path.ts b/packages/ui/app-boot/src/config-path.ts deleted file mode 100644 index bdfb933feb..0000000000 --- a/packages/ui/app-boot/src/config-path.ts +++ /dev/null @@ -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) -} diff --git a/packages/ui/app-boot/src/index.ts b/packages/ui/app-boot/src/index.ts index 959a7120d7..e2413fa736 100644 --- a/packages/ui/app-boot/src/index.ts +++ b/packages/ui/app-boot/src/index.ts @@ -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