Skip to content

@codesoul-co/hypha-core / contracts/command-execution

模块用法

用于声明并运行时校验契约。Command execution 模块公开 6 接口、1 类型。

从包入口导入

ts
import type {
  CommandExecutionRequest,
  CommandExecutionResult,
  CommandOutputChunk,
  ExecutionCancelRequest,
  ExecutionReceipt,
  ExecutionResourceUsage,
  CommandExecutionStatus,
} from '@codesoul-co/hypha-core';

使用要点

  • 7 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。

公共导出

Symbol种类签名说明
CommandExecutionRequest接口interface CommandExecutionRequestCommand Execution Request 接口,共包含 35 个公开字段或方法。
CommandExecutionResult接口interface CommandExecutionResultCommand Execution Result 接口,共包含 25 个公开字段或方法。
CommandOutputChunk接口interface CommandOutputChunkCommand Output Chunk 接口,共包含 9 个公开字段或方法。
ExecutionCancelRequest接口interface ExecutionCancelRequestExecution Cancel Request 接口,共包含 9 个公开字段或方法。
ExecutionReceipt接口interface ExecutionReceiptExecution Receipt 接口,共包含 8 个公开字段或方法。
ExecutionResourceUsage接口interface ExecutionResourceUsageExecution Resource Usage 接口,共包含 8 个公开字段或方法。
CommandExecutionStatus类型type CommandExecutionStatus = 'queued' | 'starting' | 'running' | 'cancelling' | 'cancelled' | 'completed' | 'failed' | 'timed_out' | 'oom_killed' | 'resource_exceeded' | 'quarantined'Command Execution Status 公共类型别名;完整类型表达式见声明。

CommandExecutionRequest

Command Execution Request 接口,共包含 35 个公开字段或方法。

声明

text
export interface CommandExecutionRequest {
    executionId?: string;
    operationId: string;
    principal: ExecutionPrincipal;
    tenantId?: string;
    userId: string;
    workspaceId: string;
    sessionId?: string;
    runId: string;
    stepId?: string;
    agentId?: string;
    fsmState?: string;
    sandboxId?: string;
    environmentRef: SpecRef;
    executable: string;
    args?: string[];
    cwd?: string;
    env?: Record<string, string>;
    secretRefs?: string[];
    shell?: boolean;
    stdin?: string | Uint8Array;
    timeoutMs?: number;
    idleTimeoutMs?: number;
    maxStdoutBytes?: number;
    maxStderrBytes?: number;
    captureArtifacts?: boolean;
    captureFileMutations?: boolean;
    snapshotBefore?: boolean;
    snapshotAfter?: boolean;
    snapshotOnFailure?: boolean;
    networkAuthorizationRef?: string;
    idempotencyKey?: string;
    expectedWorkspaceSnapshotHash?: string;
    correlationId?: string;
    causationId?: string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
agentId属性agentId?: string公开属性;类型、只读和可选状态以签名列为准。
args属性args?: string[]公开属性;类型、只读和可选状态以签名列为准。
captureArtifacts属性captureArtifacts?: boolean公开属性;类型、只读和可选状态以签名列为准。
captureFileMutations属性captureFileMutations?: boolean公开属性;类型、只读和可选状态以签名列为准。
causationId属性causationId?: string公开属性;类型、只读和可选状态以签名列为准。
correlationId属性correlationId?: string公开属性;类型、只读和可选状态以签名列为准。
cwd属性cwd?: string公开属性;类型、只读和可选状态以签名列为准。
env属性env?: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
environmentRef属性environmentRef: SpecRef公开属性;类型、只读和可选状态以签名列为准。
executable属性executable: string公开属性;类型、只读和可选状态以签名列为准。
executionId属性executionId?: string公开属性;类型、只读和可选状态以签名列为准。
expectedWorkspaceSnapshotHash属性expectedWorkspaceSnapshotHash?: string公开属性;类型、只读和可选状态以签名列为准。
fsmState属性fsmState?: string公开属性;类型、只读和可选状态以签名列为准。
idempotencyKey属性idempotencyKey?: string公开属性;类型、只读和可选状态以签名列为准。
idleTimeoutMs属性idleTimeoutMs?: number公开属性;类型、只读和可选状态以签名列为准。
maxStderrBytes属性maxStderrBytes?: number公开属性;类型、只读和可选状态以签名列为准。
maxStdoutBytes属性maxStdoutBytes?: number公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
networkAuthorizationRef属性networkAuthorizationRef?: string公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
principal属性principal: ExecutionPrincipal公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
sandboxId属性sandboxId?: string公开属性;类型、只读和可选状态以签名列为准。
secretRefs属性secretRefs?: string[]公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
shell属性shell?: boolean公开属性;类型、只读和可选状态以签名列为准。
snapshotAfter属性snapshotAfter?: boolean公开属性;类型、只读和可选状态以签名列为准。
snapshotBefore属性snapshotBefore?: boolean公开属性;类型、只读和可选状态以签名列为准。
snapshotOnFailure属性snapshotOnFailure?: boolean公开属性;类型、只读和可选状态以签名列为准。
stdin属性stdin?: string | Uint8Array<ArrayBufferLike>公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
timeoutMs属性timeoutMs?: number公开属性;类型、只读和可选状态以签名列为准。
userId属性userId: string公开属性;类型、只读和可选状态以签名列为准。
workspaceId属性workspaceId: string公开属性;类型、只读和可选状态以签名列为准。

CommandExecutionResult

Command Execution Result 接口,共包含 25 个公开字段或方法。

声明

text
export interface CommandExecutionResult {
    executionId: string;
    revision: number;
    sandboxId: string;
    status: CommandExecutionStatus;
    exitCode: number | null;
    signal?: string;
    stdout?: string;
    stderr?: string;
    /** SHA-256 content hash of the bounded inline stdout value. */
    stdoutContentHash?: string;
    /** SHA-256 content hash of the bounded inline stderr value. */
    stderrContentHash?: string;
    stdoutTruncated?: boolean;
    stderrTruncated?: boolean;
    stdoutArtifactRef?: string;
    stderrArtifactRef?: string;
    changedFiles: FileMutation[];
    generatedArtifactRefs: string[];
    snapshotBeforeRef?: string;
    snapshotAfterRef?: string;
    resourceUsage?: ExecutionResourceUsage;
    externalReceipt?: ExecutionReceipt;
    startedAt: string;
    completedAt?: string;
    latencyMs?: number;
    error?: NormalizedExecutionError;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
changedFiles属性changedFiles: FileMutation[]公开属性;类型、只读和可选状态以签名列为准。
completedAt属性completedAt?: string公开属性;类型、只读和可选状态以签名列为准。
error属性error?: NormalizedExecutionError公开属性;类型、只读和可选状态以签名列为准。
executionId属性executionId: string公开属性;类型、只读和可选状态以签名列为准。
exitCode属性exitCode: number公开属性;类型、只读和可选状态以签名列为准。
externalReceipt属性externalReceipt?: ExecutionReceipt公开属性;类型、只读和可选状态以签名列为准。
generatedArtifactRefs属性generatedArtifactRefs: string[]公开属性;类型、只读和可选状态以签名列为准。
latencyMs属性latencyMs?: number公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
resourceUsage属性resourceUsage?: ExecutionResourceUsage公开属性;类型、只读和可选状态以签名列为准。
revision属性revision: number公开属性;类型、只读和可选状态以签名列为准。
sandboxId属性sandboxId: string公开属性;类型、只读和可选状态以签名列为准。
signal属性signal?: string公开属性;类型、只读和可选状态以签名列为准。
snapshotAfterRef属性snapshotAfterRef?: string公开属性;类型、只读和可选状态以签名列为准。
snapshotBeforeRef属性snapshotBeforeRef?: string公开属性;类型、只读和可选状态以签名列为准。
startedAt属性startedAt: string公开属性;类型、只读和可选状态以签名列为准。
status属性status: CommandExecutionStatus公开属性;类型、只读和可选状态以签名列为准。
stderr属性stderr?: string公开属性;类型、只读和可选状态以签名列为准。
stderrArtifactRef属性stderrArtifactRef?: string公开属性;类型、只读和可选状态以签名列为准。
stderrContentHash属性stderrContentHash?: stringSHA-256 content hash of the bounded inline stderr value.
stderrTruncated属性stderrTruncated?: boolean公开属性;类型、只读和可选状态以签名列为准。
stdout属性stdout?: string公开属性;类型、只读和可选状态以签名列为准。
stdoutArtifactRef属性stdoutArtifactRef?: string公开属性;类型、只读和可选状态以签名列为准。
stdoutContentHash属性stdoutContentHash?: stringSHA-256 content hash of the bounded inline stdout value.
stdoutTruncated属性stdoutTruncated?: boolean公开属性;类型、只读和可选状态以签名列为准。

CommandOutputChunk

Command Output Chunk 接口,共包含 9 个公开字段或方法。

声明

text
export interface CommandOutputChunk {
    executionId: string;
    sequence: number;
    stream: 'stdout' | 'stderr';
    encoding: 'utf8' | 'base64';
    content: string;
    byteLength: number;
    contentHash: string;
    emittedAt: string;
    truncated?: boolean;
}

契约成员

成员种类签名说明
byteLength属性byteLength: number公开属性;类型、只读和可选状态以签名列为准。
content属性content: string公开属性;类型、只读和可选状态以签名列为准。
contentHash属性contentHash: string公开属性;类型、只读和可选状态以签名列为准。
emittedAt属性emittedAt: string公开属性;类型、只读和可选状态以签名列为准。
encoding属性encoding: "utf8" | "base64"公开属性;类型、只读和可选状态以签名列为准。
executionId属性executionId: string公开属性;类型、只读和可选状态以签名列为准。
sequence属性sequence: number公开属性;类型、只读和可选状态以签名列为准。
stream属性stream: "stdout" | "stderr"公开属性;类型、只读和可选状态以签名列为准。
truncated属性truncated?: boolean公开属性;类型、只读和可选状态以签名列为准。

ExecutionCancelRequest

Execution Cancel Request 接口,共包含 9 个公开字段或方法。

声明

text
export interface ExecutionCancelRequest {
    operationId: string;
    executionId: string;
    principal: ExecutionPrincipal;
    expectedRevision: number;
    reason?: string;
    gracePeriodMs?: number;
    idempotencyKey?: string;
    correlationId?: string;
    causationId?: string;
}

契约成员

成员种类签名说明
causationId属性causationId?: string公开属性;类型、只读和可选状态以签名列为准。
correlationId属性correlationId?: string公开属性;类型、只读和可选状态以签名列为准。
executionId属性executionId: string公开属性;类型、只读和可选状态以签名列为准。
expectedRevision属性expectedRevision: number公开属性;类型、只读和可选状态以签名列为准。
gracePeriodMs属性gracePeriodMs?: number公开属性;类型、只读和可选状态以签名列为准。
idempotencyKey属性idempotencyKey?: string公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
principal属性principal: ExecutionPrincipal公开属性;类型、只读和可选状态以签名列为准。
reason属性reason?: string公开属性;类型、只读和可选状态以签名列为准。

ExecutionReceipt

Execution Receipt 接口,共包含 8 个公开字段或方法。

声明

text
export interface ExecutionReceipt {
    id: string;
    providerId: string;
    executionId: string;
    providerExecutionRef?: string;
    status: 'accepted' | 'completed' | 'rejected' | 'unknown';
    issuedAt: string;
    receiptHash: string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
executionId属性executionId: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
issuedAt属性issuedAt: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
providerExecutionRef属性providerExecutionRef?: string公开属性;类型、只读和可选状态以签名列为准。
providerId属性providerId: string公开属性;类型、只读和可选状态以签名列为准。
receiptHash属性receiptHash: string公开属性;类型、只读和可选状态以签名列为准。
status属性status: "unknown" | "accepted" | "completed" | "rejected"公开属性;类型、只读和可选状态以签名列为准。

ExecutionResourceUsage

Execution Resource Usage 接口,共包含 8 个公开字段或方法。

声明

text
export interface ExecutionResourceUsage {
    cpuTimeMs?: number;
    peakMemoryBytes?: number;
    readBytes?: number;
    writtenBytes?: number;
    networkBytesSent?: number;
    networkBytesReceived?: number;
    processCountPeak?: number;
    outputBytes?: number;
}

契约成员

成员种类签名说明
cpuTimeMs属性cpuTimeMs?: number公开属性;类型、只读和可选状态以签名列为准。
networkBytesReceived属性networkBytesReceived?: number公开属性;类型、只读和可选状态以签名列为准。
networkBytesSent属性networkBytesSent?: number公开属性;类型、只读和可选状态以签名列为准。
outputBytes属性outputBytes?: number公开属性;类型、只读和可选状态以签名列为准。
peakMemoryBytes属性peakMemoryBytes?: number公开属性;类型、只读和可选状态以签名列为准。
processCountPeak属性processCountPeak?: number公开属性;类型、只读和可选状态以签名列为准。
readBytes属性readBytes?: number公开属性;类型、只读和可选状态以签名列为准。
writtenBytes属性writtenBytes?: number公开属性;类型、只读和可选状态以签名列为准。

CommandExecutionStatus

Command Execution Status 公共类型别名;完整类型表达式见声明。

声明

text
export type CommandExecutionStatus = 'queued' | 'starting' | 'running' | 'cancelling' | 'cancelled' | 'completed' | 'failed' | 'timed_out' | 'oom_killed' | 'resource_exceeded' | 'quarantined';