乐于分享
好东西不私藏

OpenClaw Agent 运行时模块分析

OpenClaw Agent 运行时模块分析

文档版本:2026.4.9  最后更新:2026-04-09

源码验证: ✅ 本文档基于实际源码分析

1. 模块概述

cover

Agent 运行时模块是 OpenClaw 的核心执行引擎,负责运行 AI Agent、管理模型调用、处理工具执行和流式响应。基于源码验证,该模块采用嵌入式 Pi Agent 架构,支持多模型、故障转移、身份验证轮换和工具执行管道。

核心职责

  • • Agent 执行: 运行嵌入式 Pi Agent,处理用户提示
  • • 模型管理: 模型选择、身份验证、上下文窗口验证
  • • 故障转移: 自动切换认证配置文件、模型降级
  • • 工具执行: 管理编码工具(bash、文件操作等)
  • • 流式处理: 流式响应、分块回复、推理流
  • • 会话管理: SessionManager 集成、转录文件操作

关键文件位置

src/agents/├── pi-embedded-runner/│   ├── run.ts                            # 主入口(runEmbeddedPiAgent)│   ├── run/│   │   ├── attempt.ts                    # 单次运行尝试(runEmbeddedAttempt)│   │   ├── payloads.ts                   # 响应载荷构建│   │   └── params.ts                     # 参数类型定义(RunEmbeddedPiAgentParams)│   ├── runs.ts                           # 运行状态管理(队列、中止)│   ├── auth/│   │   └── controller.ts                 # Auth Controller(createEmbeddedRunAuthController)│   ├── context-engine/                   # 上下文引擎(替代直接压缩)│   │   ├── index.ts│   │   └── lifecycle.ts│   ├── compact.ts                        # 传统会话压缩│   ├── session-lock.ts                   # 会话写锁(acquireSessionWriteLock)│   ├── types.ts                          # 核心类型定义│   ├── session-manager-cache.ts          # SessionManager 缓存│   └── ...(其他辅助模块)├── pi-embedded-subscribe.ts              # 流式事件订阅├── pi-tools.ts                           # 工具创建(createOpenClawCodingTools)├── pi-embedded-helpers.ts                # 辅助函数(错误分类等)└── bundle-mcp/                           # Bundle MCP 工具运行时    └── runtime.ts

2. 核心组件

architecture

2.1 主运行入口(runEmbeddedPiAgent

文件src/agents/pi-embedded-runner/run.ts

函数签名

export async function runEmbeddedPiAgent(  params: RunEmbeddedPiAgentParams): Promise<EmbeddedPiRunResult>

核心流程

0. SessionKey 回填(早期规范化)   backfillSessionKey({ config, sessionId, sessionKey, agentId })   → 确保所有下游(Hook、LCM、压缩等)都接收到非空 sessionKey1. 队列管理   enqueueSession() → enqueueGlobal()   → 会话级队列:防止同一会话并发运行   → 全局级队列:控制全局并发2. 工作空间解析 & 插件加载   resolveRunWorkspaceDir({ workspaceDir, sessionKey, agentId, config })   → 支持 fallback 路径(workspaceResolution.usedFallback)   ensureRuntimePluginsLoaded({ config, workspaceDir, allowGatewaySubagentBinding })   → 延迟绑定运行时插件3. Hook 模型选择(新增)   resolveHookModelSelection({ prompt, provider, modelId, hookRunner, hookContext })   → 允许插件 hook 在运行前替换 provider/modelId   → 结果: { provider, modelId, legacyBeforeAgentStartResult }4. 模型解析(异步)   resolveModelAsync(provider, modelId, agentDir, config)   → 从模型注册表查找模型定义   resolveEffectiveRuntimeModel({ cfg, provider, modelId, runtimeModel })   → 处理运行时模型覆盖(如动态切换)5. Context Engine 初始化(新增)   ensureContextEnginesInitialized()   contextEngine = await resolveContextEngine(params.config)   → 新增的上下文引擎抽象层,替代直接调用 compactEmbeddedPiSessionDirect   → contextEngine.compact() / contextEngine.dispose()   → contextEngine.info.ownsCompaction 决定谁负责触发压缩6. Auth Controller(重构)   createEmbeddedRunAuthController({ ...状态引用... })   → 封装所有认证配置文件管理逻辑   → 提供: advanceAuthProfile / initializeAuthProfile /            maybeRefreshRuntimeAuthForAuthError / stopRuntimeAuthRefreshTimer7. 循环尝试(while(true),上限 MAX_RUN_LOOP_ITERATIONS)   runEmbeddedAttempt(...)   ── 成功路径 ──   → buildEmbeddedRunPayloads()   → markAuthProfileGood / markAuthProfileUsed   → 返回 EmbeddedPiRunResult   ── 新增错误路径 ──   a) 超时触发压缩(timeout + 高 token 占用率 > 65%)      contextEngine.compact({ trigger: "timeout_recovery", force: true })      → 压缩成功 → continue(重试)      → 失败 → 转普通超时错误处理   b) 上下文溢出(改用 contextEngine)      contextEngine.compact({ trigger: "overflow", force: true })      → 支持 MAX_OVERFLOW_COMPACTION_ATTEMPTS=3 次尝试      → 工具结果截断: truncateOversizedToolResultsInSession()      → 完全失败 → 返回 context_overflow 错误   c) 速率限制 → 配置文件轮换限制升级      maybeEscalateRateLimitProfileFallback()      → 超过 rateLimitProfileRotationLimit → 升级为 FailoverError(模型降级)   d) 规划仅执行(Planning-Only)检测(新增)      resolvePlanningOnlyRetryInstruction()      → 检测到 Agent 只规划但未执行      → 注入 "act-now" 指令重试(最多 1 次)      → emitAgentPlanEvent() 通知上层   e) 不完整轮次(Incomplete Turn)检测(新增)      resolveIncompleteTurnPayloadText()      → prompt() 提前解析但无 payload      → 返回用户可见错误提示   f) 实时模型切换(Live Model Switch)(新增)      shouldSwitchToLiveModel()      → 检测到待处理的模型切换请求      → 抛出 LiveSessionModelSwitchError 触发上层切换8. 结果构建   buildEmbeddedRunPayloads()   → 整合 assistantTexts、toolMetas、lastAssistant   → 返回 EmbeddedPiRunResult(含 successfulCronAdds、messagingToolSentMediaUrls)

关键特性

  • • 双层队列: 会话级 + 全局级,防止并发冲突
  • • Auth Controller: 封装认证管理,支持运行时刷新
  • • Context Engine: 新的上下文引擎抽象,统一管理压缩/维护
  • • 超时触发压缩: LLM 超时时若 prompt token 占用率 > 65% 自动压缩
  • • 规划重试: 检测 planning-only 轮次并注入执行指令
  • • 速率限制升级: N 次轮换后自动升级为模型降级
  • • 思考级别降级: 不支持时自动降级(high → low → off)
  • • GitHub Copilot 特殊处理: 动态 token 交换

2.2 运行尝试(runEmbeddedAttempt

文件src/agents/pi-embedded-runner/run/attempt.ts

函数签名

export async function runEmbeddedAttempt(  params: EmbeddedRunAttemptParams): Promise<EmbeddedRunAttemptResult>

核心流程

1. 工作空间初始化   fs.mkdir(resolvedWorkspace)   → 支持沙盒隔离(sandbox.enabled)   → effectiveWorkspace 根据沙盒访问级别选择路径   acquireSessionWriteLock({ sessionFile, maxHoldMs })  ← 新增会话写锁2. 技能加载   resolveEmbeddedRunSkillEntries(workspaceDir, config, agentId, skillsSnapshot)   applySkillEnvOverridesFromSnapshot() | applySkillEnvOverrides()   → 从 skillsSnapshot 或 .skills/ 目录加载   → 应用环境变量覆盖3. Bootstrap 文件处理   resolveAttemptBootstrapContext({ contextInjectionMode, bootstrapContextMode, ... })   → 加载工作空间引导文件(如 AGENTS.md/CLAUDE.md)   → analyzeBootstrapBudget() 分析 token 预算   → 支持 lightweight/full 模式(bootstrapContextMode)   → buildBootstrapPromptWarning() 生成截断警告4. 工具创建(含 Bundle MCP/LSP)   createOpenClawCodingTools()                         ← 内置编码工具   normalizeProviderToolSchemas()                      ← provider 规范化   getOrCreateSessionMcpRuntime() + materializeBundleMcpToolsForRun()  ← Bundle MCP(新增)   createBundleLspToolRuntime()                        ← Bundle LSP(新增)   effectiveTools = [ ...tools, ...bundleMcpTools, ...bundleLspTools ]   → toolsAllow 过滤(最小化模式)5. 系统提示构建   buildEmbeddedSystemPrompt()                         ← 主体系统提示   resolveSystemPromptOverride()                       ← 允许配置完全替换   resolveProviderSystemPromptContribution()           ← provider 特有贡献(新增)   → 含 heartbeatPrompt、ttsHint、memoryCitationsMode   → effectivePromptMode: "full" | "minimal"(toolsAllow 时用 minimal)6. SessionManager 初始化   prewarmSessionFile(sessionFile)   SessionManager.open(sessionFile) + guardSessionManager()   runAttemptContextEngineBootstrap()                  ← Context Engine 引导(新增)   buildEmbeddedExtensionFactories()                   ← 扩展工厂(新增)   DefaultResourceLoader({ extensionFactories })       ← 资源加载器(新增)   applyPiAutoCompactionGuard()                        ← auto-compaction 守卫7. 历史消息处理   sanitizeSessionHistory() → validateReplayTurns()   ← 新增 validateReplayTurns   filterHeartbeatPairs()                              ← 心跳消息过滤(新增)   limitHistoryTurns() → sanitizeToolUseResultPairing()   pruneProcessedHistoryImages()                       ← 历史图像裁剪(新增)8. Context Engine 消息组装(新增)   assembleAttemptContextEngine({ contextEngine, messages, tokenBudget, ... })   → 可注入 systemPromptAddition   → 替换 messages(memory、增强等)9. Stream 传输策略(重构)   resolveEmbeddedAgentBaseStreamFn()                  ← 基础流函数   registerProviderStreamForModel()                    ← provider 特有流(新增)   shouldUseOpenAIWebSocketTransport()                 ← WebSocket 传输(新增)   → streamFn 链式包装:     - dropThinkingBlocks / sanitizeToolCallIds(transcriptPolicy)     - wrapStreamFnSanitizeMalformedToolCalls     - wrapStreamFnTrimToolCallNames     - wrapStreamFnRepairMalformedToolCallArguments(Anthropic)     - wrapStreamFnDecodeXaiToolCallArguments(xAI)     - wrapStreamFnHandleSensitiveStopReason     - streamWithIdleTimeout(LLM 空闲超时,新增)     - GooglePromptCacheStreamFn(Google 提示缓存,新增)     - sessions_yield 中止检测10. 预检溢出检测(新增)    shouldPreemptivelyCompactBeforePrompt()    → route: "truncate_tool_results_only" → 提前截断工具结果    → route: "compact_only" / "compact_then_truncate" → 触发 preflightRecovery11. 图像注入(增强)    detectAndLoadPromptImages({ sandbox, workspaceOnly, ... })    → 支持沙盒路径限制    → imageOrder 控制注入顺序12. Agent 运行    createAgentSession({ builtInTools, customTools: [...customTools, ...clientToolDefs], ... })    → Client Tools(OpenResponses 托管工具,新增)    → sessions_yield 工具(新增)    await activeSession.prompt(effectivePrompt, { images? })    → 超时管理:scheduleAbortTimer 含 compactionGrace 扩展13. 订阅流式事件    subscribeEmbeddedPiSession()    → 详见序列图 0314. Context Engine 轮次收尾(新增)    finalizeAttemptContextEngineTurn({ contextEngine, ... })    → 触发 after_compaction hooks15. 返回结果    {      assistantTexts, toolMetas, lastAssistant,      sessionIdUsed, aborted, timedOut, idleTimedOut,      timedOutDuringCompaction,                        ← 新增      preflightRecovery,                               ← 新增      yieldDetected,                                   ← 新增      clientToolCall,                                  ← 新增      successfulCronAdds,                              ← 新增      messagingToolSentMediaUrls,                      ← 新增      compactionCount, attemptUsage, promptCache       ← 新增    }

关键特性

  • • 会话写锁: 防止同一会话文件并发写入
  • • Bundle MCP/LSP: 动态加载插件提供的额外工具
  • • 预检溢出: 在提交前估算 token,主动触发截断/压缩
  • • Context Engine 生命周期: bootstrap → assemble → finalize 三段式
  • • LLM 空闲超时: 独立于全局超时的 LLM 无响应检测
  • • sessions_yield 工具: Agent 主动让出控制权
  • • Client Tools: 支持 OpenResponses 托管工具(外部调用回调)
  • • Stream 变换链: 多层 transcriptPolicy 流包装,处理各 provider 差异

2.3 流式订阅(subscribeEmbeddedPiSession

文件src/agents/pi-embedded-subscribe.ts

函数签名

export function subscribeEmbeddedPiSession(  params: SubscribeEmbeddedPiSessionParams)

核心状态

const state: EmbeddedPiSubscribeState = {  assistantTexts: [],              // 助手文本累积  toolMetas: [],                   // 工具元数据  toolMetaById: Map<string, ToolMeta>,  lastToolError: undefined,  blockReplyBreak: &#x27;text_end&#x27;,     // 分块回复触发点  reasoningMode: &#x27;off&#x27; | &#x27;on&#x27; | &#x27;stream&#x27;,  includeReasoning: boolean,  shouldEmitPartialReplies: boolean,  streamReasoning: boolean,  deltaBuffer: "",                 // 增量文本缓冲  blockBuffer: "",                 // 块缓冲  blockState: {                    // 状态跟踪    thinking: boolean,             // 是否在 <think> 块内    final: boolean,                // 是否在 <final> 块内    inlineCode: InlineCodeState    // 内联代码状态  },  messagingToolSentTexts: [],      // 消息工具已发送文本  compactionInFlight: boolean,     // 压缩进行中  pendingCompactionRetry: number   // 待处理压缩重试}

事件处理

// 文本增量(流式)on text_delta:  deltaBuffer += delta  → 检测 <think>/<final> 标签  → 更新 blockState(thinking, final)  → 推送到 blockChunker(分块器)  → 触发 onBlockReply(如果配置)// 消息开始on message_start:  resetAssistantMessageState()  → 清空缓冲区、重置状态  → assistantMessageIndex += 1// 消息结束on message_end:  finalizeAssistantTexts()  → 合并最终文本  → 推送到 assistantTexts// 工具调用on tool_calls:  → 存储工具元数据到 toolMetaById  → 等待工具结果// 工具结果on tool_result:  → 更新 toolMetas  → 检测消息工具(telegram, whatsapp)  → 去重已发送文本// 压缩请求on compaction_start:  compactionInFlight = true  → 暂停正常流处理on compaction_complete:  compactionInFlight = false  → 恢复流处理

分块回复(BlockReplyChunking)

blockReplyBreak: &#x27;text_end&#x27; | &#x27;tool_execution_start&#x27;blockReplyChunking: {  paragraphPreference?: boolean,  // 段落优先  softChunkSize?: number,         // 软分块大小  hardChunkMaxSize?: number       // 硬分块最大值}// 分块器逻辑EmbeddedBlockChunker:  → 检测段落边界(\n\n)  → 重新打开围栏代码块(```)  → 软分块 vs 硬分块  → 触发 onBlockReply(chunk)

2.4 工具系统(createOpenClawCodingTools

文件src/agents/pi-tools.ts

核心工具类型

// 编码工具(来自 pi-coding-agent)- read_file          // 读取文件- write_file         // 写入文件- edit_file          // 编辑文件(查找替换)- apply_patch        // 应用补丁(OpenClaw 扩展)- exec               // 执行命令- process_send_keys  // 向后台进程发送按键// 消息工具(OpenClaw 特有)- telegram_send      // 发送 Telegram 消息- whatsapp_send      // 发送 WhatsApp 消息- discord_send       // 发送 Discord 消息- slack_send         // 发送 Slack 消息- sessions_send      // 向其他会话发送消息// OpenClaw 管理工具- sessions_list      // 列出会话- sessions_spawn     // 生成子代理- camera_capture     // 捕获摄像头- ...(其他工具)

工具策略过滤

resolveEffectiveToolPolicy(config, sessionKey)  → 基础策略: config.tools?.policy  → 群组策略: resolveGroupToolPolicy()  → 子代理策略: resolveSubagentToolPolicy()  → 插件策略: expandPolicyWithPluginGroups()filterToolsByPolicy(tools, policy)  → 应用允许列表/阻止列表  → 移除仅限插件工具(如果未安装)

沙盒工具包装

// 沙盒启用时:- read_file  → createSandboxedReadTool()- write_file → createSandboxedWriteTool()- edit_file  → createSandboxedEditTool()// 限制:- 无法访问沙盒外的文件- 路径自动重新映射到沙盒目录

2.5 运行状态管理(runs.ts

文件src/agents/pi-embedded-runner/runs.ts

活动运行跟踪

const activeEmbeddedRuns = new Map<string, EmbeddedPiQueueHandle>();setActiveEmbeddedRun(runId, handle)  → 存储运行句柄  → 支持中止操作clearActiveEmbeddedRun(runId)  → 移除运行句柄isEmbeddedPiRunActive(runId)  → 检查运行是否活动abortEmbeddedPiRun(runId)  → 中止运行(通过 AbortController

运行队列句柄

type EmbeddedPiQueueHandle = {  promise: Promise<T>;  abort: () => void;  isStreaming: boolean;}

3. 数据结构(实际定义)

3.1 RunEmbeddedPiAgentParams

文件src/agents/pi-embedded-runner/run/params.ts

type RunEmbeddedPiAgentParams = {  // 会话标识  sessionId: string;  sessionKey?: string;  agentId?: string;                        // ← 新增  // 触发类型(新增)  /** "user" | "heartbeat" | "cron" | "memory" | "overflow" | "manual" */  trigger?: EmbeddedRunTrigger;  // 提示和输入  prompt: string;  images?: ImageContent[];                 // ← 类型变更(原 string[])  imageOrder?: PromptImageOrderEntry[];    // ← 新增  /** OpenResponses 托管工具(新增)*/  clientTools?: ClientToolDefinition[];  // 模型配置  provider?: string;  model?: string;  thinkLevel?: ThinkLevel;  fastMode?: boolean;                      // ← 新增  reasoningLevel?: ReasoningLevel;  // 认证  authProfileId?: string;  authProfileIdSource?: &#x27;auto&#x27; | &#x27;user&#x27;;  allowTransientCooldownProbe?: boolean;   // ← 新增  // 工作空间  sessionFile: string;  workspaceDir: string;  agentDir?: string;  // 消息上下文  messageChannel?: string;  messageProvider?: string;  agentAccountId?: string;  messageTo?: string;  messageThreadId?: string | number;  memoryFlushWritePath?: string;           // ← 新增  // 群组上下文(与先前相同)  groupId?: string | null;  groupChannel?: string | null;  groupSpace?: string | null;  spawnedBy?: string | null;  // 发送者信息  senderId?: string | null;  senderName?: string | null;  senderUsername?: string | null;  senderE164?: string | null;  senderIsOwner?: boolean;                 // ← 新增  // 频道/线程细节(新增)  currentChannelId?: string;  currentThreadTs?: string;  currentMessageId?: string | number;  replyToMode?: &#x27;off&#x27; | &#x27;first&#x27; | &#x27;all&#x27; | &#x27;batched&#x27;;  hasRepliedRef?: { value: boolean };  requireExplicitMessageTarget?: boolean;  // ← 新增  disableMessageTool?: boolean;           // ← 新增  allowGatewaySubagentBinding?: boolean;  // ← 新增  // 工具配置  disableTools?: boolean;  toolsAllow?: string[];                  // ← 新增(最小化模式)  toolResultFormat?: &#x27;markdown&#x27; | &#x27;plain&#x27;;  suppressToolErrorWarnings?: boolean;    // ← 新增  execOverrides?: ExecToolDefaults;  bashElevated?: ExecElevatedDefaults;  // Bootstrap 模式(新增)  bootstrapContextMode?: &#x27;full&#x27; | &#x27;lightweight&#x27;;  bootstrapContextRunKind?: &#x27;default&#x27; | &#x27;heartbeat&#x27; | &#x27;cron&#x27;;  bootstrapPromptWarningSignaturesSeen?: string[];  bootstrapPromptWarningSignature?: string;  // 流式回调(签名有变化)  onPartialReply?: (payload: { text?: string; mediaUrls?: string[] }) => void | Promise<void>;  onAssistantMessageStart?: () => void | Promise<void>;   // ← 新增  onBlockReply?: (payload: BlockReplyPayload) => void | Promise<void>;  onBlockReplyFlush?: () => void | Promise<void>;  blockReplyBreak?: &#x27;text_end&#x27; | &#x27;message_end&#x27;;           // ← 枚举值变更  blockReplyChunking?: BlockReplyChunking;  onReasoningStream?: (payload: { text?: string; mediaUrls?: string[] }) => void | Promise<void>;  onReasoningEnd?: () => void | Promise<void>;            // ← 新增  onToolResult?: (payload: ReplyPayload) => void | Promise<void>;  onAgentEvent?: (evt: { stream: string; data: Record<string, unknown> }) => void;  // 运行控制  runId: string;  timeoutMs: number;  abortSignal?: AbortSignal;  lane?: string;  enqueue?: typeof enqueueCommand;  replyOperation?: ReplyOperation;        // ← 新增  shouldEmitToolResult?: () => boolean;   // ← 新增  shouldEmitToolOutput?: () => boolean;   // ← 新增  // 其他  config?: OpenClawConfig;  skillsSnapshot?: SkillSnapshot;  verboseLevel?: VerboseLevel;  extraSystemPrompt?: string;  ownerNumbers?: string[];  enforceFinalTag?: boolean;  silentExpected?: boolean;              // ← 新增  inputProvenance?: InputProvenance;     // ← 新增  streamParams?: AgentStreamParams;      // ← 新增  internalEvents?: AgentInternalEvent[]; // ← 新增  cleanupBundleMcpOnRunEnd?: boolean;    // ← 新增}

3.2 EmbeddedPiRunResult

文件src/agents/pi-embedded-runner/types.ts

type EmbeddedPiRunResult = {  // 响应载荷  payloads?: Array<{    text?: string;    mediaUrl?: string;    mediaUrls?: string[];    replyToId?: string;    isError?: boolean;  }>;  // 元数据  meta: {    durationMs: number;    agentMeta?: {      sessionId: string;      provider: string;      model: string;      usage?: { input?; output?; cacheRead?; cacheWrite?; total? };      lastCallUsage?: { ... };   // ← 新增:最近一次调用 usage      promptTokens?: number;     // ← 新增      compactionCount?: number;  // ← 新增:本轮自动压缩次数    };    aborted?: boolean;    systemPromptReport?: SessionSystemPromptReport;    error?: {      kind: &#x27;context_overflow&#x27; | &#x27;compaction_failure&#x27; | &#x27;role_ordering&#x27; | &#x27;image_size&#x27;;      message: string;    };    // 停止原因(新增语义)    stopReason?: string;         // &#x27;tool_calls&#x27;(clientToolCall)| &#x27;end_turn&#x27;(yield)| ...    // 待处理 Client Tool 调用(新增)    pendingToolCalls?: Array<{      id: string;      name: string;      arguments: string;    }>;  };  // 消息工具标志  didSendViaMessagingTool?: boolean;  didSendDeterministicApprovalPrompt?: boolean;  // ← 新增  messagingToolSentTexts?: string[];  messagingToolSentMediaUrls?: string[];          // ← 新增  messagingToolSentTargets?: MessagingToolSend[];  successfulCronAdds?: SuccessfulCronAdd[];       // ← 新增}

3.3 EmbeddedSandboxInfo

文件src/agents/pi-embedded-runner/types.ts

type EmbeddedSandboxInfo = {  enabled: boolean;  workspaceDir?: string;          // 沙盒工作空间目录  workspaceAccess?: &#x27;none&#x27; | &#x27;ro&#x27; | &#x27;rw&#x27;;  agentWorkspaceMount?: string;   // Agent 内的挂载路径  browserBridgeUrl?: string;      // 浏览器桥接 URL  browserNoVncUrl?: string;       // noVNC URL  hostBrowserAllowed?: boolean;   // 允许主机浏览器  elevated?: {    allowed: boolean;    defaultLevel: &#x27;on&#x27; | &#x27;off&#x27; | &#x27;ask&#x27; | &#x27;full&#x27;;  };}

4. 核心流程(实际实现)

run-orchestration

4.1 完整运行流程

用户消息  ↓Gateway WebSocket Server  ↓runEmbeddedPiAgent(params)  ↓┌─────────────────────────────────────┐│ 0. SessionKey 回填                  ││   backfillSessionKey()              │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 1. 队列管理                          ││   - enqueueSession (会话级)         ││   - enqueueGlobal (全局级)          │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 2. 工作空间解析 & 插件加载          ││   - resolveRunWorkspaceDir()        ││   - ensureRuntimePluginsLoaded()    │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 3. Hook 模型选择(新增)            ││   - resolveHookModelSelection()     ││   - 插件可替换 provider/modelId     │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 4. 模型解析 & 验证                  ││   - resolveModelAsync()             ││   - resolveEffectiveRuntimeModel()  │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 5. Context Engine 初始化(新增)    ││   - resolveContextEngine()          ││   - 统一管理压缩/维护生命周期       │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 6. Auth Controller 准备             ││   - createEmbeddedRunAuthController ││   - initializeAuthProfile()         │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 7. 循环尝试(新增多个退出路径)     ││   while(true) 上限 MAX_LOOP_ITERS   │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 8. 单次运行尝试                     ││   runEmbeddedAttempt(params)        ││     ├─ 会话写锁                     ││     ├─ Bundle MCP/LSP 加载          ││     ├─ 预检溢出检测                 ││     ├─ 流式变换链                   ││     ├─ sessions_yield 支持          ││     └─ Context Engine 轮次生命周期  │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 9. 错误处理 & 故障转移              ││   - timeout + 高 token → 超时压缩  ││   - context_overflow → CE 压缩     ││   - rate_limit → 轮换/升级降级     ││   - planning_only → act-now 重试   ││   - incomplete_turn → 错误提示     ││   - live_switch → 模型切换信号     ││   - auth_error → 刷新/轮换         ││   - unsupported_thinking → 降级    │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 10. 结果构建                        ││   buildEmbeddedRunPayloads()        │└─────────────────────────────────────┘  ↓返回 EmbeddedPiRunResult  ↓Gateway 响应用户
运行编排流程

4.2 流式事件处理流程

createAgentSession()  ↓subscribeEmbeddedPiSession(params)  ↓┌─────────────────────────────────────┐│ 事件监听器注册                      ││   - text_delta                      ││   - message_start                   ││   - message_end                     ││   - tool_calls                      ││   - tool_result                     ││   - compaction_start/complete       │└─────────────────────────────────────┘  ↓Agent 开始流式输出  ↓┌─────────────────────────────────────┐│ text_delta 事件                     ││   deltaBuffer += delta              ││   ↓                                 ││   检测 <think>/<final> 标签         ││   ↓                                 ││   更新 blockState                   ││   ↓                                 ││   推送到 blockChunker               ││   ↓                                 ││   触发 onBlockReply(chunk)          │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ tool_calls 事件                     ││   存储 toolMetas                    ││   ↓                                 ││   执行工具(如 exec、read_file)    ││   ↓                                 ││   返回工具结果                      │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ tool_result 事件                    ││   更新 toolMetas                    ││   ↓                                 ││   检测消息工具                      ││   (telegram_send, whatsapp_send)    ││   ↓                                 ││   去重已发送文本                    │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ message_end 事件                    ││   finalizeAssistantTexts()          ││   ↓                                 ││   合并最终文本                      ││   ↓                                 ││   推送到 assistantTexts             │└─────────────────────────────────────┘  ↓返回完整结果
流式事件处理流程

4.3 认证配置文件故障转移

初始配置文件列表  profileCandidates = [profile1, profile2, profile3]  ↓┌─────────────────────────────────────┐│ 尝试 profile1                       ││   applyApiKeyInfo(profile1)         ││   ↓                                 ││   runEmbeddedAttempt(...)           │└─────────────────────────────────────┘  ↓ (失败:速率限制)┌─────────────────────────────────────┐│ 标记失败                            ││   markAuthProfileFailure(profile1)  ││   → 设置冷却期(30分钟)            │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 前进到下一个                        ││   advanceAuthProfile()              ││   → 跳过冷却中的配置文件            ││   → profileIndex++                  │└─────────────────────────────────────┘  ↓┌─────────────────────────────────────┐│ 尝试 profile2                       ││   applyApiKeyInfo(profile2)         ││   ↓                                 ││   runEmbeddedAttempt(...)           │└─────────────────────────────────────┘  ↓ (成功)┌─────────────────────────────────────┐│ 标记成功                            ││   markAuthProfileGood(profile2)     ││   markAuthProfileUsed(profile2)     ││   → 清除失败计数器                  ││   → 更新最后使用时间                │└─────────────────────────────────────┘  ↓返回成功结果

4.4 自动压缩流程(Context Engine 版)

runEmbeddedAttempt(...)  ↓ (失败:context_overflow 或 timeout + 高 token 占用率)┌─────────────────────────────────────┐│ 超时触发压缩(新路径)              ││   tokenUsedRatio > 0.65?            ││   → contextEngine.compact({         ││       trigger: "timeout_recovery",  ││       force: true                   ││     })                              ││   → 成功 → continue(重试)         ││   → 失败 → 转普通超时处理           │└─────────────────────────────────────┘  ↓(上下文溢出)┌─────────────────────────────────────┐│ 溢出压缩(最多 3 次)               ││   hadAttemptLevelCompaction?        ││   → 是:不再压缩,continue          ││   → 否:                           ││     contextEngine.compact({         ││       trigger: "overflow"           ││     })                              │└─────────────────────────────────────┘  ↓ (失败)┌─────────────────────────────────────┐│ 工具结果截断                        ││   truncateOversizedToolResultsIn    ││   Session()                         ││   → 成功 → continue                 ││   → 失败 → 返回 context_overflow    │└─────────────────────────────────────┘
执行尝试流程

5. 依赖关系(实际引用)

5.1 外部依赖

核心依赖

  • • 
  • @mariozechner/pi-coding-agent
  •  (v0.49.3+)
    • • createAgentSession() - 创建 Agent 会话
    • • SessionManager - 会话管理
    • • SettingsManager - 设置管理
    • • DefaultResourceLoader - 含扩展工厂的资源加载器(新增)
    • • codingTools - 基础编码工具
  • • 
  • @mariozechner/pi-ai
    • • streamSimple() - 流式 API 调用
  • • 
  • @mariozechner/pi-agent-core
    • • AgentMessage - 消息类型
    • • AssistantMessage - 助手消息类型

内部依赖

pi-embedded-runner/run.ts  ↓ depends onrun/attempt.ts               # 单次尝试  ↓ depends onpi-embedded-subscribe.ts     # 流式订阅pi-tools.ts                  # 工具创建pi-embedded-helpers.ts       # 辅助函数auth/controller.ts           # Auth Controller(新增)context-engine/              # 上下文引擎(新增)session-lock.ts              # 会话写锁(新增)bundle-mcp/runtime.ts        # Bundle MCP 运行时(新增)model-auth.ts                # 模型认证model-selection.ts           # 模型选择sandbox.ts                   # 沙盒管理skills.ts                    # 技能管理bootstrap-files.ts           # Bootstrap 文件

5.2 被依赖模块(调用方)

Gateway 层

  • • src/gateway/server-methods/agent.ts - Agent 方法处理
  • • src/gateway/server-chat.ts - 聊天消息处理

CLI 层

  • • src/commands/agent/message.ts - CLI 消息命令

自动回复层

  • • src/auto-reply/reply/agent-run.ts - 自动回复执行

6. 性能优化(实际策略)

6.1 队列管理

双层队列

// 会话级队列(防止同一会话并发)const sessionLane = resolveSessionLane(sessionKey);enqueueSession(() => ...)// 全局级队列(控制全局并发)const globalLane = resolveGlobalLane(lane);enqueueGlobal(() => ...)

优点:

  • • 会话隔离:同一会话串行执行,避免状态冲突
  • • 全局限流:控制整体负载,防止资源耗尽

6.2 SessionManager 缓存

文件src/agents/pi-embedded-runner/session-manager-cache.ts

// 预热会话文件prewarmSessionFile(sessionFile)  → 提前加载 SessionManager 到内存// 跟踪访问trackSessionManagerAccess(sessionFile)  → 记录最后访问时间  → 用于缓存淘汰

优点:

  • • 减少重复文件 I/O
  • • 加快会话加载速度

6.3 认证配置文件冷却

// 失败后设置冷却期markAuthProfileFailure(profileId)  → 记录失败时间 + 失败计数  → 冷却期:30 分钟(可配置)// 检查冷却期isProfileInCooldown(authStore, profileId)  → 如果在冷却期内,跳过该配置文件

优点:

  • • 避免重复失败
  • • 快速故障转移到可用配置文件

6.4 流式分块优化

段落优先分块

blockReplyChunking: {  paragraphPreference: true,  softChunkSize: 500,  hardChunkMaxSize: 2000}// 分块器逻辑EmbeddedBlockChunker:  → 优先在段落边界分块(\n\n)  → 软分块:500 字符(推荐点)  → 硬分块:2000 字符(强制点)

优点:

  • • 保持段落完整性
  • • 平衡响应速度与可读性

6.5 图像处理优化

懒加载 + 尺寸限制

detectAndLoadPromptImages(prompt, workspaceDir)  → 仅加载提示中引用的图像  → 检查文件大小限制(MAX_IMAGE_BYTES  → Base64 编码injectHistoryImagesIntoMessages(messages, historyImages)  → 去重:避免重复注入  → 仅注入用户消息

优点:

  • • 减少不必要的磁盘 I/O
  • • 控制内存使用

7. 关键实现细节(源码验证)

7.1 Anthropic 拒绝测试 Token 清理

// src/agents/pi-embedded-runner/run.tsconst ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL =  "ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL";const ANTHROPIC_MAGIC_STRING_REPLACEMENT =  "ANTHROPIC MAGIC STRING TRIGGER REFUSAL (redacted)";function scrubAnthropicRefusalMagic(prompt: string): string {  if (!prompt.includes(ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL))    return prompt;  return prompt.replaceAll(    ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL,    ANTHROPIC_MAGIC_STRING_REPLACEMENT  );}// 使用const prompt = provider === "anthropic"  ? scrubAnthropicRefusalMagic(params.prompt  : params.prompt;

目的: 防止 Anthropic 测试 Token 污染会话转录

7.2 思考级别降级

// pi-embedded-helpers.tsfunction pickFallbackThinkingLevel(params: {  message?: string;  attempted: Set<ThinkLevel>;}): ThinkLevel | null {  const msg = params.message?.toLowerCase() ?? "";  const isThinkingError =     msg.includes("thinking") ||     msg.includes("extended_thinking");  if (!isThinkingError) return null;  // 降级顺序: high → low → off  if (!params.attempted.has("low")) return "low";  if (!params.attempted.has("off")) return "off";  return null;}// 使用const fallbackThinking = pickFallbackThinkingLevel({  message: errorText,  attempted: attemptedThinking});if (fallbackThinking) {  thinkLevel = fallbackThinking;  continue; // 重试}

支持的思考级别:

  • • high: 深度推理(如 o1-preview)
  • • low: 轻量推理
  • • off: 无推理

7.3 GitHub Copilot Token 交换

// run.tsif (model.provider === "github-copilot") {  const { resolveCopilotApiToken } =    await import("../../providers/github-copilot-token.js");  const copilotToken = await resolveCopilotApiToken({    githubToken: apiKeyInfo.apiKey  });  authStorage.setRuntimeApiKey(    model.provider    copilotToken.token  );}

特殊处理:

  • • GitHub Token → Copilot API Token
  • • 动态交换,不持久化

7.4 消息工具去重

// pi-embedded-subscribe.tsconst isMessagingToolDuplicateNormalized(  normalized: string,  existing: string[]): boolean {  return existing.some(prev => prev === normalized);}// 工具结果处理on tool_result:  if (isMessagingTool(toolName)) {    const normalized = normalizeTextForComparison(text);    if (!isMessagingToolDuplicateNormalized(      normalized,       messagingToolSentTextsNormalized    )) {      messagingToolSentTexts.push(text);      messagingToolSentTextsNormalized.push(normalized);    }  }

目的: 防止消息工具重复发送相同文本

7.5 SessionManager 守卫

// session-tool-result-guard-wrapper.tsfunction guardSessionManager(  sessionManager: SessionManager,  params: {     agentId: string    sessionKey: string;    allowSyntheticToolResults: boolean;  }): SessionManager {  // 包装 appendMessage,拦截合成工具结果  const originalAppendMessage =     sessionManager.appendMessage.bind(sessionManager);  sessionManager.appendMessage = (message) => {    if (message.role === "tool_result" &&        isSyntheticToolResult(message)) {      if (!params.allowSyntheticToolResults) {        // 跳过合成工具结果        return;      }    }    originalAppendMessage(message);  };  return sessionManager;}

目的: 防止合成工具结果污染转录文件

7.6 上下文窗口守卫

// context-window-guard.tsconst CONTEXT_WINDOW_WARN_BELOW_TOKENS = 8_000;const CONTEXT_WINDOW_HARD_MIN_TOKENS = 4_000;const ctxGuard = evaluateContextWindowGuard({  info: ctxInfo,  warnBelowTokens: CONTEXT_WINDOW_WARN_BELOW_TOKENS,  hardMinTokens: CONTEXT_WINDOW_HARD_MIN_TOKENS});if (ctxGuard.shouldBlock) {  throw new FailoverError(    `Model context window too small (${ctxGuard.tokens} tokens). ` +    `Minimum is ${CONTEXT_WINDOW_HARD_MIN_TOKENS}.`,    { reason: "unknown", provider, model: modelId }  );}

验证层级:

  • • 警告阈值:8000 tokens(记录日志)
  • • 硬性最小值:4000 tokens(阻止运行)

8. 错误处理与故障转移

error-recovery

8.1 错误分类

// pi-embedded-helpers.tsfunction classifyFailoverReason(  message: string): FailoverReason | null {  const lower = message.toLowerCase();  // 认证错误  if (lower.includes("unauthorized") ||       lower.includes("invalid api key")) {    return "auth";  }  // 速率限制  if (lower.includes("rate limit") ||       lower.includes("429")) {    return "rate_limit";  }  // 超时  if (lower.includes("timeout") ||       lower.includes("timed out")) {    return "timeout";  }  // 上下文溢出  if (lower.includes("context") &&       lower.includes("overflow")) {    return "context_overflow";  }  // 其他  return null;}

8.2 故障转移决策树

错误发生  ↓classifyFailoverReason(errorMessage)  ↓┌───────────────────────────────────┐│ auth / rate_limit / timeout       ││   → markAuthProfileFailure()      ││   → advanceAuthProfile()          ││   → 重试                          │└───────────────────────────────────┘  ↓ (所有配置文件耗尽)┌───────────────────────────────────┐│ fallbackConfigured?               ││   Yes → throw FailoverError       ││         (触发模型降级)            ││   No  → throw Error               ││         (失败)                    │└───────────────────────────────────┘  ↓┌───────────────────────────────────┐│ context_overflow                  ││   → compactEmbeddedPiSession()    ││   → 重试                          │└───────────────────────────────────┘  ↓┌───────────────────────────────────┐│ unsupported_thinking              ││   → pickFallbackThinkingLevel()   ││   → 降级 thinkLevel               ││   → 重试                          │└───────────────────────────────────┘  ↓┌───────────────────────────────────┐│ image_size / image_dimension      ││   → 返回用户友好错误              ││   → 不重试                        │└───────────────────────────────────┘

8.3 FailoverError 特殊处理

// failover-error.tsclass FailoverError extends Error {  reason: FailoverReason;  provider: string;  model: string;  profileId?: string;  status?: number;}// 使用if (fallbackConfigured && isFailoverErrorMessage(errorText)) {  throw new FailoverError(errorText, {    reason: assistantFailoverReason ?? "unknown",    provider,    model: modelId,    profileId: lastProfileId,    status: resolveFailoverStatus(reason)  });}

特性:

  • • 携带详细故障信息
  • • 触发上层模型降级逻辑
  • • 保留原始错误上下文

7.7 Sessions Yield 工具(新增)

// attempt.tslet yieldDetected = false;let yieldMessage: string | null = null;// tools: sessions_yield 工具被 invoke 时触发onYield: (message) => {  yieldDetected = true;  yieldMessage = message;  queueSessionsYieldInterruptMessage(activeSession);  runAbortController.abort("sessions_yield");  abortSessionForYield?.();}// 检测 yield 中止(非错误)yieldAborted =  yieldDetected &&  isRunnerAbortError(err) &&  err.cause === "sessions_yield";if (yieldAborted) {  aborted = false;          // 不视为错误中止  stripSessionsYieldArtifacts(activeSession);  await persistSessionsYieldContextMessage(activeSession, yieldMessage);}

目的: 允许 Agent 主动让出控制权,保留上下文继续后续轮次

7.8 Planning-Only 检测与重试(新增)

// run.tsconst nextPlanningOnlyRetryInstruction = resolvePlanningOnlyRetryInstruction({  provider, modelId, aborted, timedOut, attempt,});if (!incompleteTurnText && nextPlanningOnlyRetryInstruction && planningOnlyRetryAttempts < 1) {  // 发出 Plan 事件通知上层  const planDetails = extractPlanningOnlyPlanDetails(planningOnlyText);  if (planDetails) {    emitAgentPlanEvent({ runId, data: { phase: "update", ... } });    params.onAgentEvent?.({ stream: "plan", data: { ... } });  }  planningOnlyRetryAttempts += 1;  planningOnlyRetryInstruction = nextPlanningOnlyRetryInstruction;  continue; // 重试,注入 "act-now" 指令}

目的: 当 Agent 仅输出规划内容但未执行时,自动注入"立即执行"指令

7.9 预检溢出检测(新增)

// attempt.ts - 在提交 prompt 前检测const preemptiveCompaction = shouldPreemptivelyCompactBeforePrompt({  messages: activeSession.messages,  systemPrompt: systemPromptText,  prompt: effectivePrompt,  contextTokenBudget,  reserveTokens,});// route: "truncate_tool_results_only"// → 先截断工具结果,不走压缩if (preemptiveCompaction.route === "truncate_tool_results_only") {  truncateOversizedToolResultsInSessionManager(...)  preflightRecovery = { route: "truncate_tool_results_only", handled: true }  skipPromptSubmission = true;  // 跳过提交,触发 preflightRecovery 重试}// route: "compact_only" | "compact_then_truncate"// → 标记 promptError,触发外层压缩逻辑if (preemptiveCompaction.shouldCompact) {  preflightRecovery = { route: "compact_only" | "compact_then_truncate" }  promptError = new Error(PREEMPTIVE_OVERFLOW_ERROR_TEXT)  skipPromptSubmission = true;}

目的: 在 prompt 提交前估算 token,主动防止溢出(避免模型报错后再压缩)


文档版本: v2.0 (基于源码验证)\ 验证日期: 2026-04-09

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-04-10 09:21:40 HTTP/1.1 GET : https://www.yeyulingfeng.com/a/508726.html
  2. 运行时间 : 0.124997s [ 吞吐率:8.00req/s ] 内存消耗:4,895.35kb 文件加载:145
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=9a6b4f0313d0818dea7611d5d6290cfa
  1. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_static.php ( 6.05 KB )
  7. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/ralouphie/getallheaders/src/getallheaders.php ( 1.60 KB )
  10. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  11. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  12. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  13. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  14. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  15. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  16. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  17. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  18. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  19. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions_include.php ( 0.16 KB )
  21. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions.php ( 5.54 KB )
  22. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  23. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  24. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  25. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/provider.php ( 0.19 KB )
  26. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  27. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  28. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  29. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/common.php ( 0.03 KB )
  30. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  32. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/alipay.php ( 3.59 KB )
  33. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  34. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/app.php ( 0.95 KB )
  35. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cache.php ( 0.78 KB )
  36. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/console.php ( 0.23 KB )
  37. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cookie.php ( 0.56 KB )
  38. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/database.php ( 2.48 KB )
  39. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/filesystem.php ( 0.61 KB )
  40. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/lang.php ( 0.91 KB )
  41. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/log.php ( 1.35 KB )
  42. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/middleware.php ( 0.19 KB )
  43. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/route.php ( 1.89 KB )
  44. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/session.php ( 0.57 KB )
  45. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/trace.php ( 0.34 KB )
  46. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/view.php ( 0.82 KB )
  47. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/event.php ( 0.25 KB )
  48. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  49. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/service.php ( 0.13 KB )
  50. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/AppService.php ( 0.26 KB )
  51. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  52. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  53. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  54. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  55. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  56. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/services.php ( 0.14 KB )
  57. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  58. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  59. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  60. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  61. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  62. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  63. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  64. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  65. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  66. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  67. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  68. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  69. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  70. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  71. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  72. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  73. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  74. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  75. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  76. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  77. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  78. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  79. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  80. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  81. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  82. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  83. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  84. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  85. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  86. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  87. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/Request.php ( 0.09 KB )
  88. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  89. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/middleware.php ( 0.25 KB )
  90. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  91. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  92. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  93. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  94. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  95. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  96. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  97. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  98. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  99. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  100. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  101. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  102. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  103. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/route/app.php ( 3.94 KB )
  104. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  105. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  106. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Index.php ( 9.87 KB )
  108. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/BaseController.php ( 2.05 KB )
  109. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  110. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  111. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  112. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  113. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  114. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  115. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  116. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  117. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  118. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  119. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  120. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  121. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  122. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  123. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  124. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  125. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  126. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  127. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  128. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  129. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  130. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  131. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  132. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  133. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  134. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  135. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Es.php ( 3.30 KB )
  136. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  137. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  138. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  139. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  140. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  141. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  142. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  143. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  144. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/runtime/temp/c935550e3e8a3a4c27dd94e439343fdf.php ( 31.80 KB )
  145. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000616s ] mysql:host=127.0.0.1;port=3306;dbname=wenku;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000721s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.011199s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000312s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000582s ]
  6. SELECT * FROM `set` [ RunTime:0.000271s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000622s ]
  8. SELECT * FROM `article` WHERE `id` = 508726 LIMIT 1 [ RunTime:0.000593s ]
  9. UPDATE `article` SET `lasttime` = 1775784100 WHERE `id` = 508726 [ RunTime:0.015994s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 64 LIMIT 1 [ RunTime:0.000309s ]
  11. SELECT * FROM `article` WHERE `id` < 508726 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000505s ]
  12. SELECT * FROM `article` WHERE `id` > 508726 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.004492s ]
  13. SELECT * FROM `article` WHERE `id` < 508726 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.001017s ]
  14. SELECT * FROM `article` WHERE `id` < 508726 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.005298s ]
  15. SELECT * FROM `article` WHERE `id` < 508726 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.000783s ]
0.126697s