mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-20 15:25:50 +00:00
chore(workflow): 工作流相关代码中文文案全部英文化
源码(src/workflow/ + packages/workflow-engine/src/)的中文注释、 用户可见错误消息、字符串字面量;测试文件的标题与注释;同步 6 条 硬编码断言到英文化后的错误消息。 Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
@@ -7,9 +7,9 @@ import type {
|
||||
} from './types.js'
|
||||
|
||||
/**
|
||||
* 不透明 host 句柄。核心侧每次工具调用构造一个,内含 toolUseContext/
|
||||
* canUseTool/parentMessage 等。包内绝不检视其内部,只透传给 AgentRunner。
|
||||
* 这是包与核心层之间唯一的耦合缝隙,且是不透明的。
|
||||
* Opaque host handle. The core side constructs one per tool call, containing toolUseContext/
|
||||
* canUseTool/parentMessage, etc. The package never inspects its internals; it only passes it through to the AgentRunner.
|
||||
* This is the only coupling seam between the package and the core layer, and it is opaque.
|
||||
*/
|
||||
const HOST_HANDLE = Symbol('workflow.hostHandle')
|
||||
|
||||
@@ -17,12 +17,12 @@ export type HostBundle = unknown
|
||||
|
||||
export type HostHandle = { readonly [HOST_HANDLE]: HostBundle }
|
||||
|
||||
/** 核心 side hostFactory 用:把任意 bundle 包成不透明句柄。 */
|
||||
/** Used by the core-side hostFactory: wraps any bundle into an opaque handle. */
|
||||
export function createHostHandle(bundle: HostBundle): HostHandle {
|
||||
return { [HOST_HANDLE]: bundle } as HostHandle
|
||||
}
|
||||
|
||||
/** 类型守卫。 */
|
||||
/** Type guard. */
|
||||
export function isHostHandle(value: unknown): value is HostHandle {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
@@ -31,12 +31,12 @@ export function isHostHandle(value: unknown): value is HostHandle {
|
||||
)
|
||||
}
|
||||
|
||||
/** 核心 side adapter 用:解包(仅 adapter 应调用)。 */
|
||||
/** Used by the core-side adapter: unwraps (only the adapter should call this). */
|
||||
export function unwrapHostHandle(handle: HostHandle): HostBundle {
|
||||
return (handle as { [k: symbol]: HostBundle })[HOST_HANDLE]
|
||||
}
|
||||
|
||||
/** agent() 钩子的后端。 */
|
||||
/** Backend for the agent() hook. */
|
||||
export type AgentRunner = {
|
||||
runAgentToResult(
|
||||
params: AgentRunParams,
|
||||
@@ -44,16 +44,16 @@ export type AgentRunner = {
|
||||
): Promise<AgentRunResult>
|
||||
}
|
||||
|
||||
/** 进度事件发射。 */
|
||||
/** Progress event emitter. */
|
||||
export type ProgressEmitter = {
|
||||
emit(event: ProgressEvent): void
|
||||
}
|
||||
|
||||
/** 后台任务生命周期。 */
|
||||
/** Background task lifecycle. */
|
||||
export type TaskRegistrar = {
|
||||
/**
|
||||
* 注册后台任务。adapter 创建 AbortController 并存入 task 状态,
|
||||
* 返回 runId 与 signal(供引擎 detached 执行 + kill 中止用)。
|
||||
* Register a background task. The adapter creates an AbortController and stores it in task state,
|
||||
* returning runId and signal (for the engine to execute detached + kill to abort).
|
||||
*/
|
||||
register(
|
||||
opts: {
|
||||
@@ -61,7 +61,7 @@ export type TaskRegistrar = {
|
||||
workflowFile?: string
|
||||
summary?: string
|
||||
toolUseId?: string
|
||||
/** resume 时复用既有 runId(读其 journal)。省略则生成新 id。 */
|
||||
/** On resume, reuse the existing runId (read its journal). Omit to generate a new id. */
|
||||
runId?: string
|
||||
},
|
||||
host: HostHandle,
|
||||
@@ -70,61 +70,61 @@ export type TaskRegistrar = {
|
||||
fail(runId: string, error: string): void
|
||||
kill(runId: string): void
|
||||
/**
|
||||
* 注册 agent 级 AbortController。backend 启动 agent 时调用,让 service
|
||||
* .kill(runId, agentId) 能精确中断单个 agent(不影响同 run 其他 agent)。
|
||||
* 幂等:同 agentId 重复注册覆盖。
|
||||
* Register an agent-level AbortController. Called by the backend when starting an agent, so that service
|
||||
* .kill(runId, agentId) can precisely abort a single agent (without affecting other agents in the same run).
|
||||
* Idempotent: re-registering with the same agentId overwrites.
|
||||
*/
|
||||
registerAgentAbort?(runId: string, agentId: number, ac: AbortController): void
|
||||
/**
|
||||
* 注销 agent 级 AbortController(agent 完成/失败时调;幂等)。
|
||||
* Unregister an agent-level AbortController (called when the agent completes/fails; idempotent).
|
||||
*/
|
||||
unregisterAgentAbort?(runId: string, agentId: number): void
|
||||
/**
|
||||
* 中断单个 agent。返回是否命中(false = agent 已完成/不存在)。
|
||||
* 不影响同 run 其他 agent,workflow 继续跑(被中断 agent 返回 dead → null)。
|
||||
* Abort a single agent. Returns whether it hit (false = agent already completed/does not exist).
|
||||
* Does not affect other agents in the same run; the workflow continues (the aborted agent returns dead → null).
|
||||
*/
|
||||
killAgent?(runId: string, agentId: number): boolean
|
||||
/** 返回当前待处理的 skip/retry 动作,或 null。 */
|
||||
/** Returns the current pending skip/retry action, or null. */
|
||||
pendingAction(runId: string): { kind: 'skip' | 'retry' } | null
|
||||
}
|
||||
|
||||
/** journal 持久化。 */
|
||||
/** Journal persistence. */
|
||||
export type JournalStore = {
|
||||
read(runId: string): Promise<JournalEntry[]>
|
||||
append(runId: string, entry: JournalEntry): Promise<void>
|
||||
truncate(runId: string): Promise<void>
|
||||
}
|
||||
|
||||
/** 取消/权限门。 */
|
||||
/** Cancellation / permission gate. */
|
||||
export type PermissionGate = {
|
||||
isAborted(host: HostHandle): boolean
|
||||
}
|
||||
|
||||
/** 日志 + 遥测。 */
|
||||
/** Logging + telemetry. */
|
||||
export type Logger = {
|
||||
debug(msg: string): void
|
||||
event(name: string, metadata?: Record<string, unknown>): void
|
||||
/**
|
||||
* 警告级日志(如 parallel/pipeline 单项失败被吞掉的错误)。
|
||||
* Optional:旧 ports 实现可省略;hooks 用 `?.()` 容错。
|
||||
* Warning-level log (e.g. errors swallowed when a single parallel/pipeline item fails).
|
||||
* Optional: old ports implementations may omit it; hooks tolerate it with `?.()`.
|
||||
*/
|
||||
warn?(msg: string): void
|
||||
}
|
||||
|
||||
/** 引擎从 host 提取的可直接使用上下文(句柄 + 基本字段)。 */
|
||||
/** Ready-to-use context the engine extracts from the host (handle + basic fields). */
|
||||
export type WorkflowHostContext = {
|
||||
/** 透传给 AgentRunner 的不透明句柄(内含 toolUseContext/canUseTool/parentMessage)。 */
|
||||
/** Opaque handle passed through to the AgentRunner (contains toolUseContext/canUseTool/parentMessage). */
|
||||
handle: HostHandle
|
||||
cwd: string
|
||||
/** token 预算上限,null 表示无限制。 */
|
||||
/** Token budget cap; null means unlimited. */
|
||||
budgetTotal: number | null
|
||||
/** 核心 side 的工具调用 ID(透传给 task 注册)。 */
|
||||
/** Core-side tool-use id (passed through to task registration). */
|
||||
toolUseId?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心 side 提供:从工具调用的核心上下文构造 WorkflowHostContext。
|
||||
* 参数对包是不透明的(unknown);核心侧 hostFactory 知道真实类型。
|
||||
* Provided by the core side: constructs a WorkflowHostContext from the tool call's core context.
|
||||
* The arguments are opaque to the package (unknown); the core-side hostFactory knows the real types.
|
||||
*/
|
||||
export type HostFactory = (args: {
|
||||
context: unknown
|
||||
@@ -132,12 +132,12 @@ export type HostFactory = (args: {
|
||||
parentMessage: unknown
|
||||
}) => WorkflowHostContext
|
||||
|
||||
/** 所有端口的聚合。createWorkflowTool(ports) 注入。 */
|
||||
/** Aggregate of all ports. Injected into createWorkflowTool(ports). */
|
||||
export type WorkflowPorts = {
|
||||
agentRunner: AgentRunner
|
||||
/**
|
||||
* 多后端 adapter registry。提供时优先于 agentRunner——hooks.agent 按 registry
|
||||
* 路由到 adapter.run;省略则回退 agentRunner(兼容旧用法)。
|
||||
* Multi-backend adapter registry. When provided, takes precedence over agentRunner — hooks.agent routes
|
||||
* to adapter.run via the registry; when omitted, falls back to agentRunner (backward compatibility).
|
||||
*/
|
||||
agentAdapterRegistry?: AgentAdapterRegistry
|
||||
progressEmitter: ProgressEmitter
|
||||
|
||||
Reference in New Issue
Block a user