Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
fix: bundle DeepSeek Harness, install agent CLIs in SOP sandboxes, redact their keys (#379)
Robert0622223bd4165dbe
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d3664e71..2e7094f3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,11 @@ Platform releases use `vX.Y.Z` tags and publish `ghcr.io/tencent/loopforge`. Loo## Unreleased+- The platform image bundles DeepSeek Harness `@deepseek-ai/[email protected]` next to Codex and CodeBuddy, so a DeepSeek key works in conversations and SOP roles without an install step. 0.3.8 had no `dsh` and answered a DeepSeek Harness chat with “AI 助手生成失败,请稍后重试”. The image download grows by about 180 MB. An installation without the image installs the same pinned version from the conversation: every dsh release is a prerelease requiring Node 24.9, and npm on Node 22 found no version for the bare package name.+- A DeepSeek Harness reply longer than 8 KB (about 2,700 Chinese characters) is shown in full. `dsh --json` cuts every event string at 8 KiB and only its `final` event carries the whole answer, so the chat stopped mid-sentence while the saved reply was complete.+- SOP sandboxes of the published image install OpenCode, Kimi Code and Pi on first use, as they already did for Claude Code. An SOP role on one of these CLIs used to fail with `exec: <cli>: not found` (exit 127) even after a conversation installed it.+- Run logs and telemetry redact every environment variable ending in `_API_KEY`, `_TOKEN`, `_SECRET` or `_PASSWORD`. Agent CLI keys such as `DEEPSEEK_API_KEY`, and `AGENTFLOW_CLI_API_KEY` used with a custom Base URL, used to appear in clear text in the `docker exec` line of an SOP run log, readable by project members. Rotate a key that ran an SOP role before this release.+- Repository clone URLs no longer carry credentials. Saving a `cloneUrl` with a user name or password, such as `https://user:[email protected]/acme/app.git`, is rejected with a pointer to the Git token in personal settings; the repositories API, bootstrap payload, run, task and requirement views, and the runner task management list strip credentials from `cloneUrl` and `webUrl` of rows saved earlier; a `webUrl` with credentials is rejected on save; runner clone errors and redacted Git output mask them. `ssh://git@host/...` and `git@host:path` remotes are still accepted.Repositories saved earlier with a token in `cloneUrl` keep cloning until they are saved again. Saving one from the studio stores the URL without the token, so first put the Git token in 个人配置, then save the repository. Until then the token also lands in each workspace's `.git/config`, where the agent can read it, so re-save such repositories soon after upgrading.diff --git a/Dockerfile b/Dockerfileindex ae4002b8..b8641017 100644--- a/Dockerfile+++ b/Dockerfile@@ -30,7 +30,7 @@ RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cacheFROM node:22-bookwormRUN --mount=type=cache,target=/root/.npm apt-get update && apt-get install -y --no-install-recommends ca-certificates git openssh-client bash curl python3 ripgrep \&& rm -rf /var/lib/apt/lists/* \- && npm install -g @openai/[email protected] @tencent-ai/[email protected]+ && npm install -g @openai/[email protected] @tencent-ai/[email protected] @deepseek-ai/[email protected]COPY --from=docker:27-cli /usr/local/bin/docker /usr/local/bin/dockerCOPY --from=docker:27-cli /usr/local/libexec/docker/cli-plugins/docker-buildx /usr/local/libexec/docker/cli-plugins/docker-buildxWORKDIR /appdiff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.mdindex 99b659da..aedb4b85 100644--- a/THIRD_PARTY_NOTICES.md+++ b/THIRD_PARTY_NOTICES.md@@ -48,6 +48,6 @@ SOFTWARE.## Executor CLI packages-The Docker build downloads pinned Codex and CodeBuddy CLI packages from their provider registries. Claude Code is proprietary and is not included in published images. When a conversation asks to install a missing CLI, the platform downloads the pinned `@anthropic-ai/claude-code` package, or the public npm package for OpenCode, Kimi Code, Pi or DeepSeek Harness, into the installation's data directory. Cursor CLI and Antigravity are installed with their providers' installers. An SOP sandbox that selects Claude Code installs the same pinned release on first use. These packages and their bundled dependencies retain the licenses/notices shipped by their providers and are subject to those providers' terms; they are not relicensed under LoopForge's MIT license. Provider accounts, credentials and service terms apply separately. The installed packages retain their original license/readme files.+The Docker build downloads pinned Codex, CodeBuddy and DeepSeek Harness (`@deepseek-ai/dsh`, MIT) CLI packages from their provider registries. DeepSeek Harness depends on `@img/sharp-libvips-linux-x64` / `@img/sharp-libvips-linux-arm64`, unmodified prebuilt libvips shared libraries under LGPL-3.0-or-later; the library versions are listed in the package's `versions.json`, and their sources are available from https://github.com/libvips/libvips and https://github.com/lovell/sharp-libvips. Claude Code is proprietary and is not included in published images. When a conversation asks to install a missing CLI, the platform downloads the pinned `@anthropic-ai/claude-code` or `@deepseek-ai/dsh` package, or the public npm package for OpenCode, Kimi Code or Pi, into the installation's data directory. Cursor CLI and Antigravity are installed with their providers' installers. An SOP sandbox that selects Claude Code, OpenCode, Kimi Code or Pi installs the same package on first use. These packages and their bundled dependencies retain the licenses/notices shipped by their providers and are subject to those providers' terms; they are not relicensed under LoopForge's MIT license. Provider accounts, credentials and service terms apply separately. The installed packages retain their original license/readme files.The platform source was contributed by the repository owner from the recorded upstream master and is distributed under the root MIT license.diff --git a/docs/deployment.md b/docs/deployment.mdindex b6c1ed5f..a133f19c 100644--- a/docs/deployment.md+++ b/docs/deployment.md@@ -13,7 +13,7 @@ codebuddy --versionnpm install --global @openai/[email protected] @anthropic-ai/[email protected]```-Ensure the service can find `codebuddy` and Node.js on its PATH, or set `AGENTFLOW_CODEBUDDY_BIN` to the installed executable. Configure the model key and its network environment in personal settings. The no-key script demo does not need the CLI. The production Docker image includes CodeBuddy and Codex. Claude Code and the other agent CLIs are not bundled. When a conversation fails because one is missing, the error says it is not installed and offers an install button. That downloads the pinned `@anthropic-ai/claude-code` release, or the public package for OpenCode, Kimi Code, Pi and DeepSeek Harness, into `$LOOPFORGE_DATA_DIR/cli`. Cursor CLI and Antigravity use their providers' installers and land in the service user's `~/.local/bin`. Closing or reloading the browser does not stop an install that has already started, and the button stays on “自动安装” until it finishes. A finished install replaces the earlier generation failure with a prompt to send the message again. The next message reuses the installation. An SOP sandbox that selects Claude Code still installs that pinned release on first use. Connected runners keep their own CLI requirements.+Ensure the service can find `codebuddy` and Node.js on its PATH, or set `AGENTFLOW_CODEBUDDY_BIN` to the installed executable. Configure the model key and its network environment in personal settings. The no-key script demo does not need the CLI. The production Docker image includes CodeBuddy, Codex and DeepSeek Harness (`dsh`). Claude Code and the other agent CLIs are not bundled. When a conversation fails because one is missing, the error says it is not installed and offers an install button. That downloads the pinned `@anthropic-ai/claude-code` release, or the public package for OpenCode, Kimi Code and Pi, into `$LOOPFORGE_DATA_DIR/cli`; an installation outside the image gets the pinned `@deepseek-ai/dsh` release the same way. Cursor CLI and Antigravity use their providers' installers and land in the service user's `~/.local/bin`. Closing or reloading the browser does not stop an install that has already started, and the button stays on “自动安装” until it finishes. A finished install replaces the earlier generation failure with a prompt to send the message again. The next message reuses the installation. An SOP sandbox of the published image that selects Claude Code, OpenCode, Kimi Code or Pi installs the same package on first use and shares it with conversations. Cursor CLI and Antigravity are not installed into SOP sandboxes. Connected runners keep their own CLI requirements.Stop the foreground service with Ctrl-C. Start it again with the same command. MySQL data stays in its Compose volume. `docker compose stop mysql` stops the database without deleting it.diff --git a/internal/runtime/agent_cli_deepseek_stream_test.go b/internal/runtime/agent_cli_deepseek_stream_test.gonew file mode 100644index 00000000..f529cbca--- /dev/null+++ b/internal/runtime/agent_cli_deepseek_stream_test.go@@ -0,0 +1,115 @@+package runtime++import (+ "encoding/json"+ "slices"+ "strconv"+ "testing"+)++func TestAgentCLITranslatorDeepSeekFlushesHeldTruncatedText(t *testing.T) {+ // kinds 把翻译出的事件压成 "块类型:文本" 序列,便于断言顺序。+ kinds := func(lines []string) []string {+ var out []string+ for _, line := range lines {+ var event struct {+ Type string+ IsError bool `json:"is_error"`+ Result string+ Message struct {+ Content []struct{ Type, Text, Thinking string }+ }+ }+ if err := json.Unmarshal([]byte(line), &event); err != nil {+ t.Fatalf("invalid event %q: %v", line, err)+ }+ switch event.Type {+ case "assistant", "user":+ for _, block := range event.Message.Content {+ out = append(out, block.Type+":"+block.Text+block.Thinking)+ }+ case "result":+ out = append(out, "result:"+strconv.FormatBool(event.IsError)+":"+event.Result)+ }+ }+ return out+ }+ run := func(raws ...string) []string {+ translate := NewAgentCLITranslator(AgentCLIDeepSeek)+ var lines []string+ for _, raw := range raws {+ lines = append(lines, translate(raw)...)+ }+ return kinds(lines)+ }++ for _, tc := range []struct {+ name string+ raws []string+ want []string+ }{+ {+ name: "thinking flushes the held text first",+ raws: []string{+ `{"type":"text","truncated":true,"text":"截断A"}`,+ `{"type":"thinking","text":"想一想"}`,+ },+ want: []string{"text:截断A", "thinking:想一想"},+ },+ {+ name: "tool result flushes the held text first",+ raws: []string{+ `{"type":"text","truncated":true,"text":"截断A"}`,+ `{"type":"tool_result","callId":"c1","status":"completed","result":"ok"}`,+ },+ want: []string{"text:截断A", "tool_result:"},+ },+ {+ name: "a second truncated text flushes the first and is held itself",+ raws: []string{+ `{"type":"text","truncated":true,"text":"截断A"}`,+ `{"type":"text","truncated":true,"text":"截断B"}`,+ },+ want: []string{"text:截断A"},+ },+ {+ name: "final that does not extend the held text keeps the held text",+ raws: []string{+ `{"type":"text","truncated":true,"text":"截断A"}`,+ `{"type":"final","reason":{"kind":"completed"},"text":"另一段总结"}`,+ },+ want: []string{"text:截断A", "result:false:另一段总结"},+ },+ {+ name: "status and session events do not flush the held text",+ raws: []string{+ `{"type":"text","truncated":true,"text":"截断A"}`,+ `{"type":"status","phase":"step_end","usage":{"inputTokens":1}}`,+ `{"type":"session","sessionId":"s-2"}`,+ },+ want: nil,+ },+ {+ name: "failed final without text reports the held text and the error",+ raws: []string{+ `{"type":"text","truncated":true,"text":"截断A"}`,+ `{"type":"error","message":"quota exceeded"}`,+ `{"type":"final","reason":{"kind":"error"}}`,+ },+ want: []string{"text:截断A", "result:true:quota exceeded"},+ },+ {+ name: "failed final without text or error names the reason",+ raws: []string{+ `{"type":"final","reason":{"kind":"aborted"}}`,+ },+ want: []string{"result:true:DeepSeek Harness 运行结束:aborted"},+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ if got := run(tc.raws...); !slices.Equal(got, tc.want) {+ t.Fatalf("events = %q, want %q", got, tc.want)+ }+ })+ }+}diff --git a/internal/runtime/agent_cli_stream.go b/internal/runtime/agent_cli_stream.goindex 2099ddb0..d3a94805 100644--- a/internal/runtime/agent_cli_stream.go+++ b/internal/runtime/agent_cli_stream.go@@ -593,20 +593,33 @@ func (p *piStream) translate(s *ClaudeStream, raw map[string]any) []string {}// dshStream: `dsh --profile headless --json` run events.-type dshStream struct{ failure string }+// dshStream: `dsh --json` caps every event string at 8 KiB and flags the event+// `truncated`; only the terminal `final` carries the whole answer. A truncated+// text is held back so `final` can replace it instead of being appended to it.+type dshStream struct{ failure, truncatedText string }func (d *dshStream) translate(s *ClaudeStream, raw map[string]any) []string {- switch stringValue(raw["type"]) {+ kind := stringValue(raw["type"])+ var out []string+ if d.truncatedText != "" && (kind == "thinking" || kind == "text" || kind == "tool_call" || kind == "tool_result") {+ out = s.Text(d.truncatedText)+ d.truncatedText = ""+ }+ switch kind {case "session":- return s.Init(stringValue(raw["sessionId"]), "")+ return append(out, s.Init(stringValue(raw["sessionId"]), "")...)case "thinking":- return s.Thinking(stringValue(raw["text"]))+ return append(out, s.Thinking(stringValue(raw["text"]))...)case "text":- return s.Text(stringValue(raw["text"]))+ if raw["truncated"] == true {+ d.truncatedText = stringValue(raw["text"])+ return out+ }+ return append(out, s.Text(stringValue(raw["text"]))...)case "tool_call":- return s.ToolUse(stringValue(raw["callId"]), stringValue(raw["tool"]), raw["input"])+ return append(out, s.ToolUse(stringValue(raw["callId"]), stringValue(raw["tool"]), raw["input"])...)case "tool_result":- return s.ToolResult(stringValue(raw["callId"]), stringValue(raw["status"]) != "completed", jsonText(raw["result"]))+ return append(out, s.ToolResult(stringValue(raw["callId"]), stringValue(raw["status"]) != "completed", jsonText(raw["result"]))...)case "status":if stringValue(raw["phase"]) == "step_end" {usage, _ := raw["usage"].(map[string]any)@@ -621,12 +634,19 @@ func (d *dshStream) translate(s *ClaudeStream, raw map[string]any) []string {reason, _ := raw["reason"].(map[string]any)failed := stringValue(reason["kind"]) != "completed"text := stringValue(raw["text"])+ if held := d.truncatedText; held != "" {+ d.truncatedText = ""+ if strings.HasPrefix(text, held) {+ held = text+ }+ out = append(out, s.Text(held)...)+ }if failed && text == "" {if text = d.failure; text == "" {text = "DeepSeek Harness 运行结束:" + stringValue(reason["kind"])}}- return s.Result(text, failed)+ return append(out, s.Result(text, failed)...)}- return nil+ return out}diff --git a/internal/runtime/agent_cli_test.go b/internal/runtime/agent_cli_test.goindex f83b186b..9cd69276 100644--- a/internal/runtime/agent_cli_test.go+++ b/internal/runtime/agent_cli_test.go@@ -5,6 +5,7 @@ import ("os""path/filepath""slices"+ "strconv""strings""testing"@@ -219,6 +220,58 @@ func TestAgentCLITranslatorPiNestedTools(t *testing.T) {}}+func TestAgentCLITranslatorDeepSeekReplacesTruncatedTextWithFinal(t *testing.T) {+ texts := func(lines []string) []string {+ var out []string+ for _, line := range lines {+ var event struct {+ Type string+ Message struct{ Content []struct{ Type, Text string } }+ }+ if json.Unmarshal([]byte(line), &event) == nil && event.Type == "assistant" {+ for _, block := range event.Message.Content {+ if block.Type == "text" {+ out = append(out, block.Text)+ }+ }+ }+ }+ return out+ }+ full := strings.Repeat("长篇正文", 1000) + "(全文完)"+ preview := full[:8190]+ translate := NewAgentCLITranslator(AgentCLIDeepSeek)+ var lines []string+ for _, raw := range []string{+ `{"type":"session","sessionId":"s-1"}`,+ `{"type":"text","truncated":true,"text":` + strconv.Quote(preview) + `}`,+ `{"type":"status","phase":"step_end","usage":{"inputTokens":1,"outputTokens":2}}`,+ `{"type":"status","phase":"turn_end","reason":{"kind":"completed"}}`,+ `{"type":"final","sessionId":"s-1","reason":{"kind":"completed"},"text":` + strconv.Quote(full) + `}`,+ } {+ lines = append(lines, translate(raw)...)+ }+ if got := texts(lines); len(got) != 1 || got[0] != full {+ t.Fatalf("answer blocks %d, first %d bytes; want the whole final text once", len(got), len(got[0]))+ }+ if last := lines[len(lines)-1]; !strings.Contains(last, `"type":"result"`) || !strings.Contains(last, "(全文完)") {+ t.Fatalf("result: %.200s", last)+ }++ translate = NewAgentCLITranslator(AgentCLIDeepSeek)+ lines = nil+ for _, raw := range []string{+ `{"type":"text","text":"短回复"}`,+ `{"type":"text","truncated":true,"text":"被截断的说明"}`,+ `{"type":"tool_call","callId":"c1","tool":"read","input":{}}`,+ } {+ lines = append(lines, translate(raw)...)+ }+ if got := texts(lines); !slices.Equal(got, []string{"短回复", "被截断的说明"}) || !strings.Contains(lines[len(lines)-1], `"tool_use"`) {+ t.Fatalf("texts before a tool call: %q\n%s", got, strings.Join(lines, "\n"))+ }+}+func TestAgentCLIUserCredentials(t *testing.T) {creds := AgentCLIUserCredentials(domain.User{AgentCLICredentials: map[string]domain.AgentCLICredential{"kimi": {APIKey: "k", BaseURL: "u", Protocol: "messages"}}})if creds["kimi"] != (ProviderCredential{APIKey: "k", BaseURL: "u", Protocol: "messages"}) {diff --git a/internal/runtime/claude_install_test.go b/internal/runtime/claude_install_test.goindex 0c134724..13c6cfbb 100644--- a/internal/runtime/claude_install_test.go+++ b/internal/runtime/claude_install_test.go@@ -135,3 +135,43 @@ esact.Fatal("on-demand CLIs must be appended after the image PATH")}}++func TestDockerSandboxInstallsNPMAgentCLIBeforeExec(t *testing.T) {+ root := t.TempDir()+ log := filepath.Join(t.TempDir(), "npm.log")+ t.Setenv("AGENTFLOW_ISOLATED_IMAGE", "loopforge-platform:tested")+ t.Setenv("AGENTFLOW_RUNTIME_CLI_DIR", root)+ t.Setenv("NPM_TEST_LOG", log)+ t.Setenv("NPM_TEST_BIN", "pi")+ useFakeCommands(t, map[string]string{"npm": genericFakeNPM})+ sandbox := &dockerSandbox{dockerfile: domain.DockerfileDefinition{Content: IsolatedDockerfile}}+ got, err := sandbox.onDemandCLIPath(context.Background(), CommandSpec{Provider: "pi", Argv: []string{"pi", "-p"}})+ if want := filepath.Join(root, "pi", "current", "node_modules", ".bin"); err != nil || got != want {+ t.Fatalf("pi bin dir %q %v, want %q", got, err, want)+ }+ for _, command := range []CommandSpec{+ {Provider: "codex", Argv: []string{"codex", "exec"}},+ {Provider: "codebuddy", Argv: []string{"codebuddy", "-p"}},+ {Provider: "dsh", Argv: []string{"dsh", "--profile", "headless"}},+ {Provider: "cursor", Argv: []string{"cursor-agent", "-p"}},+ {Provider: "pi", Argv: []string{"/custom/pi"}},+ } {+ if got, err := sandbox.onDemandCLIPath(context.Background(), command); err != nil || got != "" {+ t.Fatalf("%v: %q %v", command.Argv, got, err)+ }+ }+ calls, _ := os.ReadFile(log)+ if strings.Count(string(calls), "\n") != 1 || !strings.Contains(string(calls), "@earendil-works/pi-coding-agent") {+ t.Fatalf("npm calls: %s", calls)+ }+}++func TestDockerfileBundlesTheOnDemandDeepSeekHarnessRelease(t *testing.T) {+ raw, err := os.ReadFile(filepath.Join("..", "..", "Dockerfile"))+ if err != nil {+ t.Fatal(err)+ }+ if !strings.Contains(string(raw), "@deepseek-ai/dsh@"+DeepSeekHarnessVersion+" ") && !strings.Contains(string(raw), "@deepseek-ai/dsh@"+DeepSeekHarnessVersion+"\n") {+ t.Fatalf("Dockerfile must install @deepseek-ai/dsh@%s", DeepSeekHarnessVersion)+ }+}diff --git a/internal/runtime/cli_ondemand.go b/internal/runtime/cli_ondemand.goindex e9bce6b3..185ba7dd 100644--- a/internal/runtime/cli_ondemand.go+++ b/internal/runtime/cli_ondemand.go@@ -11,36 +11,45 @@ import ("sync")-// CLIs the published platform image does not guarantee. Codex and CodeBuddy-// are baked into that image; the rest are installed only after a person asks-// from a failed conversation. Package names and installer URLs are fixed:+// CLIs the published platform image does not guarantee. Codex, CodeBuddy and+// DeepSeek Harness are baked into that image; the rest are installed only after+// a person asks from a failed conversation. Package names and installer URLs are fixed:// the request may choose an engine, never a URL or a package.const (cursorInstallScript = "curl -fsSL --proto '=https' --tlsv1.2 https://cursor.com/install | bash"agyInstallScript = "curl -fsSL --proto '=https' --tlsv1.2 https://antigravity.google/cli/install.sh | bash")+// DeepSeekHarnessVersion is the dsh release the Dockerfile bundles and an+// installation without it downloads. It must be named explicitly: every dsh+// release is a prerelease requiring a newer Node than the image ships, so a+// bare package name resolves to no version at all.+const DeepSeekHarnessVersion = "0.2.2-rc.1"+type onDemandCLI struct {Engine stringBinary stringPackage stringScript stringRelaxEngines bool+ // Bundled CLIs ship in the published image, so its sandboxes never+ // install them.+ Bundled bool}var onDemandInstallMu sync.Mutexfunc onDemandCLICatalog() map[string]onDemandCLI {return map[string]onDemandCLI{- "codex": {Engine: "codex", Binary: "codex", Package: "@openai/codex"},- "codebuddy": {Engine: "codebuddy", Binary: "codebuddy", Package: "@tencent-ai/codebuddy-code"},+ "codex": {Engine: "codex", Binary: "codex", Package: "@openai/codex", Bundled: true},+ "codebuddy": {Engine: "codebuddy", Binary: "codebuddy", Package: "@tencent-ai/codebuddy-code", Bundled: true},"claude-code": {Engine: "claude-code", Binary: "claude"},"opencode": {Engine: "opencode", Binary: "opencode", Package: "opencode-ai"},"cursor": {Engine: "cursor", Binary: "cursor-agent", Script: cursorInstallScript},"agy": {Engine: "agy", Binary: "agy", Script: agyInstallScript},"kimi": {Engine: "kimi", Binary: "kimi", Package: "@moonshot-ai/kimi-code"},"pi": {Engine: "pi", Binary: "pi", Package: "@earendil-works/pi-coding-agent"},- "dsh": {Engine: "dsh", Binary: "dsh", Package: "@deepseek-ai/dsh", RelaxEngines: true},+ "dsh": {Engine: "dsh", Binary: "dsh", Package: "@deepseek-ai/dsh@" + DeepSeekHarnessVersion, RelaxEngines: true, Bundled: true},}}diff --git a/internal/runtime/cli_ondemand_sandbox_test.go b/internal/runtime/cli_ondemand_sandbox_test.gonew file mode 100644index 00000000..90cd42b5--- /dev/null+++ b/internal/runtime/cli_ondemand_sandbox_test.go@@ -0,0 +1,103 @@+package runtime++import (+ "context"+ "os"+ "path/filepath"+ "testing"++ "agentflow/internal/domain"+)++// A failed on-demand install must stop the sandbox exec instead of silently+// running without the CLI on PATH.+func TestDockerSandboxOnDemandCLIPathReturnsInstallErrors(t *testing.T) {+ t.Setenv("AGENTFLOW_ISOLATED_IMAGE", "loopforge-platform:tested")+ t.Setenv("AGENTFLOW_RUNTIME_CLI_DIR", t.TempDir())+ t.Setenv("NPM_TEST_LOG", filepath.Join(t.TempDir(), "npm.log"))+ t.Setenv("NPM_TEST_BIN", "kimi")+ t.Setenv("NPM_TEST_FAIL", "1")+ sandbox := &dockerSandbox{dockerfile: domain.DockerfileDefinition{Content: IsolatedDockerfile}}++ useFakeCommands(t, map[string]string{"npm": genericFakeNPM})+ if got, err := sandbox.onDemandCLIPath(context.Background(), CommandSpec{Provider: "kimi", Argv: []string{"kimi"}}); err == nil || got != "" {+ t.Fatalf("npm agent CLI install failure: %q %v", got, err)+ }++ useFakeCommands(t, map[string]string{"npm": fakeNPM})+ if got, err := sandbox.onDemandCLIPath(context.Background(), CommandSpec{Provider: "claude-code", Argv: []string{"claude", "-p"}}); err == nil || got != "" {+ t.Fatalf("Claude Code install failure: %q %v", got, err)+ }+}++// Commands that never need an on-demand install must not touch npm at all.+func TestDockerSandboxOnDemandCLIPathSkipsWithoutInstalling(t *testing.T) {+ log := filepath.Join(t.TempDir(), "npm.log")+ t.Setenv("AGENTFLOW_ISOLATED_IMAGE", "loopforge-platform:tested")+ t.Setenv("AGENTFLOW_RUNTIME_CLI_DIR", t.TempDir())+ t.Setenv("NPM_TEST_LOG", log)+ t.Setenv("NPM_TEST_BIN", "opencode")+ useFakeCommands(t, map[string]string{"npm": genericFakeNPM})+ sandbox := &dockerSandbox{dockerfile: domain.DockerfileDefinition{Content: IsolatedDockerfile}}+ for _, command := range []CommandSpec{+ {Provider: "opencode"},+ {Provider: "opencode", Argv: []string{}},+ {Provider: "unknown-engine", Argv: []string{"unknown-engine"}},+ {Provider: "", Argv: []string{"opencode"}},+ {Provider: "agy", Argv: []string{"agy"}},+ {Provider: "opencode", Argv: []string{"kimi"}},+ } {+ if got, err := sandbox.onDemandCLIPath(context.Background(), command); err != nil || got != "" {+ t.Fatalf("%q %v: %q %v", command.Provider, command.Argv, got, err)+ }+ }+ custom := &dockerSandbox{dockerfile: domain.DockerfileDefinition{Content: "FROM custom\n"}}+ if got, err := custom.onDemandCLIPath(context.Background(), CommandSpec{Provider: "opencode", Argv: []string{"opencode"}}); err != nil || got != "" {+ t.Fatalf("custom images keep their own agent CLIs: %q %v", got, err)+ }+ t.Setenv("AGENTFLOW_RUNTIME_CLI_DIR", "")+ if got, err := sandbox.onDemandCLIPath(context.Background(), CommandSpec{Provider: "opencode", Argv: []string{"opencode"}}); err != nil || got != "" {+ t.Fatalf("no runtime CLI directory: %q %v", got, err)+ }+ if calls, _ := os.ReadFile(log); len(calls) != 0 {+ t.Fatalf("npm must not run: %s", calls)+ }+}++func TestOnDemandCLICatalogMarksBundledCLIs(t *testing.T) {+ catalog := onDemandCLICatalog()+ for engine, want := range map[string]bool{+ "codex": true, "codebuddy": true, "dsh": true,+ "claude-code": false, "opencode": false, "cursor": false, "agy": false, "kimi": false, "pi": false,+ } {+ if got := catalog[engine].Bundled; got != want {+ t.Fatalf("%s bundled = %v, want %v", engine, got, want)+ }+ }+ if pkg := catalog["dsh"].Package; pkg != "@deepseek-ai/dsh@"+DeepSeekHarnessVersion || !catalog["dsh"].RelaxEngines {+ t.Fatalf("dsh must pin its release and relax engines: %+v", catalog["dsh"])+ }+}++func TestSensitiveProcessEnvironmentKeyMatchesCredentialSuffixes(t *testing.T) {+ for _, key := range []string{+ // keys listed explicitly before the suffix rule+ "CODEBUDDY_API_KEY", "OPENAI_API_KEY", "CODEX_API_KEY", "ANTHROPIC_API_KEY",+ "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN", "AGENTFLOW_GIT_TOKEN", "GIT_CONFIG_KEY_0",+ // covered by the suffix rule+ "DEEPSEEK_API_KEY", "CURSOR_AUTH_TOKEN", "WEBHOOK_SECRET", "DB_PASSWORD",+ "deepseek_api_key", "Db_Password", "git_config_key_1",+ } {+ if !sensitiveProcessEnvironmentKey(key) {+ t.Errorf("%s must be redacted", key)+ }+ }+ for _, key := range []string{+ "", "PATH", "HOME", "DSH_HOME", "API_KEY_FILE", "MAX_TOKENS", "TOKEN", "SECRET",+ "GIT_CONFIG_VALUE_0", "GIT_CONFIG_COUNT", "NODE_OPTIONS",+ } {+ if sensitiveProcessEnvironmentKey(key) {+ t.Errorf("%s must not be redacted", key)+ }+ }+}diff --git a/internal/runtime/cli_ondemand_test.go b/internal/runtime/cli_ondemand_test.goindex e7d14473..23069da3 100644--- a/internal/runtime/cli_ondemand_test.go+++ b/internal/runtime/cli_ondemand_test.go@@ -66,7 +66,7 @@ func TestInstallOnDemandCLIKeepsDeepSeekEngineRelaxation(t *testing.T) {t.Fatal(err)}calls, _ := os.ReadFile(log)- if !strings.Contains(string(calls), "@deepseek-ai/dsh") || !strings.Contains(string(calls), "--engine-strict=false") {+ if !strings.Contains(string(calls), "@deepseek-ai/dsh@"+DeepSeekHarnessVersion) || !strings.Contains(string(calls), "--engine-strict=false") {t.Fatalf("npm calls: %s", calls)}}diff --git a/internal/runtime/process.go b/internal/runtime/process.goindex 789eca73..be8b69d2 100644--- a/internal/runtime/process.go+++ b/internal/runtime/process.go@@ -117,12 +117,16 @@ func compactCommand(args []string) string {return string(runes[:maxRunes]) + fmt.Sprintf(" … [arguments truncated, %d chars]", len(runes))}+// sensitiveProcessEnvironmentKey matches by suffix so the key variable of a+// newly added agent CLI is redacted without being listed here.func sensitiveProcessEnvironmentKey(key string) bool {- return key == "CODEBUDDY_API_KEY" ||- key == "OPENAI_API_KEY" || key == "CODEX_API_KEY" ||- key == "ANTHROPIC_API_KEY" || key == "ANTHROPIC_AUTH_TOKEN" || key == "CLAUDE_CODE_OAUTH_TOKEN" ||- key == "AGENTFLOW_GIT_TOKEN" ||- strings.HasPrefix(key, "GIT_CONFIG_KEY_")+ key = strings.ToUpper(key)+ for _, suffix := range []string{"_API_KEY", "_TOKEN", "_SECRET", "_PASSWORD"} {+ if strings.HasSuffix(key, suffix) {+ return true+ }+ }+ return strings.HasPrefix(key, "GIT_CONFIG_KEY_")}func commandResult(err error) string {diff --git a/internal/runtime/runtime_test.go b/internal/runtime/runtime_test.goindex 203866bb..b3b828be 100644--- a/internal/runtime/runtime_test.go+++ b/internal/runtime/runtime_test.go@@ -1704,6 +1704,15 @@ func TestCompactCommandKeepsShortCommandsAndBoundsPrompts(t *testing.T) {if strings.Contains(secret, "ck_secret") || strings.Contains(secret, "private:token") {t.Fatalf("credential leaked into compact command: %s", secret)}+ agentCLI := compactCommand([]string{"docker", "exec", "-e", "DEEPSEEK_API_KEY=sk-deepseek", "-e", "AGENTFLOW_CLI_API_KEY=sk-gateway", "-e", "KIMI_API_KEY=sk-kimi", "-e", "CURSOR_AUTH_TOKEN=cursor-token", "-e", "DSH_HOME=/home/.dsh", "sandbox", "dsh"})+ for _, leaked := range []string{"sk-deepseek", "sk-gateway", "sk-kimi", "cursor-token"} {+ if strings.Contains(agentCLI, leaked) {+ t.Fatalf("agent CLI credential leaked into compact command: %s", agentCLI)+ }+ }+ if !strings.Contains(agentCLI, "DSH_HOME=/home/.dsh") {+ t.Fatalf("non-secret environment was redacted: %s", agentCLI)+ }}func TestAdaptersEmitVersionedPortableObservations(t *testing.T) {diff --git a/internal/runtime/sandbox_docker.go b/internal/runtime/sandbox_docker.goindex 69067d12..f1f33fe6 100644--- a/internal/runtime/sandbox_docker.go+++ b/internal/runtime/sandbox_docker.go@@ -193,17 +193,29 @@ if [ -n "${AGENTFLOW_RUNTIME_CLI_PATH:-}" ] && [ -d "$AGENTFLOW_RUNTIME_CLI_PATHfi`-// onDemandCLIPath installs Claude Code for sandboxes of the published runtime-// image, which does not bundle it, and returns the mounted bin directory. It is-// appended to PATH so a CLI shipped by an older image still takes precedence.+// onDemandCLIPath installs a CLI the published runtime image does not bundle+// (Claude Code and the npm agent CLIs) for sandboxes of that image, and returns+// the mounted bin directory. It is appended to PATH so a CLI shipped by an+// older image still takes precedence.func (s *dockerSandbox) onDemandCLIPath(ctx context.Context, command CommandSpec) (string, error) {- if command.Provider != "claude-code" || len(command.Argv) == 0 || command.Argv[0] != "claude" || RuntimeCLIDir() == "" || isolatedRuntimeImage(s.dockerfile) == "" {+ if len(command.Argv) == 0 || RuntimeCLIDir() == "" || isolatedRuntimeImage(s.dockerfile) == "" {return "", nil}- if _, err := EnsureClaudeCode(ctx); err != nil {+ spec, ok := onDemandCLICatalog()[command.Provider]+ if !ok || spec.Bundled || spec.Script != "" || command.Argv[0] != spec.Binary {+ return "", nil+ }+ if spec.Engine == "claude-code" {+ if _, err := EnsureClaudeCode(ctx); err != nil {+ return "", err+ }+ return ClaudeCodeBinDir(), nil+ }+ path, err := InstallOnDemandCLI(ctx, spec.Engine)+ if err != nil {return "", err}- return ClaudeCodeBinDir(), nil+ return filepath.Dir(path), nil}func dropShellLoginFlag(argv []string) []string {diff --git a/scripts/test-runtime-image.sh b/scripts/test-runtime-image.shindex 69f3f165..efff5a87 100755--- a/scripts/test-runtime-image.sh+++ b/scripts/test-runtime-image.sh@@ -24,5 +24,6 @@ unzip -v >/dev/nullcodex --versionif command -v claude >/dev/null; then printf 'Claude Code must not be bundled; it installs on first use.\n' >&2; exit 1; ficodebuddy --version+dsh --versionprintf 'Runtime image compatibility checks passed.\n'CHECK