Files
pikasTech-HWLAB/docs/reference/agentrun-code-agent-dispatch.md
T
2026-06-02 18:48:56 +08:00

3.7 KiB
Raw Blame History

AgentRun Code Agent Dispatch

本文定义 HWLAB Code Agent 通过 AgentRun v0.1 手动调度 API 执行时的装配边界。它只描述稳定的 payload、SecretRef 和 credential 归属,不替代当前 G14 DEV /v1/agent/chat 的真实 completed 判定。

装配入口

  • 源码入口是 internal/agent/agentrun-dispatch.mjs
  • createHwlabAgentRunDispatchAssembly() 生成 AgentRun POST /api/v1/runsPOST /api/v1/runs/:runId/commandsPOST /api/v1/runs/:runId/runner-jobs 三段 payload。
  • dispatchHwlabAgentRun() 使用同一 assembly 顺序调用 AgentRun manager;调用方可以注入 fetchImpl 做合同测试或接入真实 manager。
  • 默认 manager URL 是 http://agentrun-mgr.agentrun-v01.svc.cluster.local:8080,默认 namespace 是 agentrun-v01,默认 providerId 是 G14,默认 workspace branch 是 v0.2

Credential 边界

  • Provider credential 只通过 executionPolicy.secretScope.providerCredentials[] 的 AgentRun provider SecretRef 引用,默认随 backendProfile 选择 agentrun-v01-provider-deepseekagentrun-v01-provider-codexagentrun-v01-provider-minimax-m3
  • GitHub PR/issue 能力通过 toolCredentials[].tool=github 注入,默认 SecretRef 是 agentrun-v01-tool-github-pr key GH_TOKEN
  • UniDesk SSH passthrough 通过 toolCredentials[].tool=unidesk-ssh 注入,默认 SecretRef 是 agentrun-v01-tool-unidesk-ssh key UNIDESK_SSH_CLIENT_TOKEN
  • UNIDESK_SSH_CLIENT_TOKEN 只授予 UniDesk frontend /ws/ssh scoped client 能力;route allowlist 由 UniDesk frontend 配置控制。HWLAB 不持有 provider token、主 server SSH key 或完整 frontend 登录态。
  • runnerJob.transientEnv 只能承接本次 runner job 需要的短期执行上下文,例如 HWLAB_DEVICE_POD_API_KEYUNIDESK_MAIN_SERVER_IPHWLAB_DEVICE_POD_API_KEY 必须标记 sensitive,不得承载 GitHub token、UniDesk SSH client token、provider key、长期 SSH key 或 registry token。
  • HWLAB v0.2 device-pod 能力在 runner 内只通过 hwpod -> HWLAB_RUNTIME_API_URL -> hwlab-cloud-api 进入。HWLAB_RUNTIME_API_URL 指向当前 namespace 的 hwlab-cloud-api ServiceHWLAB_RUNTIME_WEB_URL 仅供需要浏览器同源语义的工具查看 Cloud Web。AgentRun 不把 HWLAB_DEVICE_POD_API_KEY 发往 Cloud Web,也不以 Cloud Web 代理替代设备 API。

ResourceBundle

  • AgentRun run 必须使用 Git-only resourceBundleRef,默认 repo 是 http://git-mirror-http.devops-infra.svc.cluster.local/pikasTech/HWLAB.git
  • commitId 必须是完整 40 字符小写 SHA,不接受 branch、tag、HEAD 或短 SHA。
  • workspaceRef 只描述目标 repo/branch,默认 branch 是 v0.2;实际 checkout 身份以 resourceBundleRef.repoUrl + commitId 为准。
  • 默认 toolAliases 会把 tools/unidesk-ssh.mjs 暴露为 runner shell 内的 unidesk-ssh 命令;它只实现 AgentRun Code Agent 所需的短连接 UniDesk SSH passthrough,例如 unidesk-ssh G14:/root/hwlab-v02 script -- 'pwd',完整文件传输和 patch 仍走 UniDesk CLI 原入口。
  • AgentRun runtime image 已预装 gh,结合 tool=github 注入的 GH_TOKEN 即可访问 HWLAB/UniDesk PR 与 issue;不得把 GitHub token 放入 prompt 或 transientEnv

验收

  • 源码合同测试:node --test internal/agent/agentrun-dispatch.test.mjs
  • 语法检查:node --check internal/agent/agentrun-dispatch.mjs && node --check internal/agent/agentrun-dispatch.test.mjs
  • 合同必须证明 UNIDESK_SSH_CLIENT_TOKEN 不出现在 transientEnvGitHub/UniDesk SSH 能力都通过 AgentRun toolCredentials SecretRef 装配,且 runner resource bundle 默认暴露 unidesk-ssh 可执行别名。