Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-6362: redact secrets from provider command logs (#7206)

Multica Eve3c3e77b00c14
diff --git a/apps/docs/content/docs/agents-create.ja.mdx b/apps/docs/content/docs/agents-create.ja.mdx
index ed92e6b7e4..daaca781b0 100644
--- a/apps/docs/content/docs/agents-create.ja.mdx
+++ b/apps/docs/content/docs/agents-create.ja.mdx
@@ -119,6 +119,10 @@ Access を変更できるのはエージェントの owner だけで、ワーク
カスタム引数は配列として 1 つずつ AI コーディングツールに渡され、シェル展開は行われません。引数名が有効かどうかは対応するツールが判断します。専用フィールドがあるモデル設定を、ここで重ねて指定する必要はありません。
+<Callout type="warning">
+認証情報などのシークレットをカスタム引数に入れないでください。値は子プロセスの argv に残り、同じマシン上の別プロセスから `ps` や `/proc` を通じて見える可能性があります。代わりに環境変数(`custom_env`)を使用してください。デーモンログでは引数値をマスクしますが、OS のプロセス一覧までは保護できません。
+</Callout>
+
MCP 構成にはトークンが含まれることがあり、保存と表示のルールは環境変数と同じです。この項目が表示されるのは、マネージド MCP 構成をサポートするランタイムだけです。サポートしないツールが、構成を保存しただけで MCP 機能を獲得することはありません。
## エージェントの複製
diff --git a/apps/docs/content/docs/agents-create.ko.mdx b/apps/docs/content/docs/agents-create.ko.mdx
index b776cb95eb..f9a9c7f9e5 100644
--- a/apps/docs/content/docs/agents-create.ko.mdx
+++ b/apps/docs/content/docs/agents-create.ko.mdx
@@ -119,6 +119,10 @@ Access는 어떤 멤버가 이 에이전트를 실행할 수 있는지 결정합
사용자 지정 인수는 배열의 각 항목으로 AI 코딩 도구에 전달되며 shell 확장을 거치지 않습니다. 인수 이름의 유효성은 해당 도구가 결정합니다. 별도 필드가 있는 모델 설정을 여기서 다시 입력할 필요는 없습니다.
+<Callout type="warning">
+자격 증명이나 다른 secret을 사용자 지정 인수에 넣지 마세요. 값은 자식 프로세스의 argv에 남아 같은 머신의 다른 프로세스에서 `ps` 또는 `/proc`를 통해 보일 수 있습니다. 대신 환경 변수(`custom_env`)를 사용하세요. 데몬 로그는 인수 값을 가리지만 운영 체제의 프로세스 목록까지 보호하지는 못합니다.
+</Callout>
+
MCP 설정에는 token이 포함될 수 있으며 저장 및 표시 규칙은 환경 변수와 같습니다. 관리형 MCP 설정을 지원하는 런타임에서만 이 항목이 표시됩니다. 지원하지 않는 도구는 설정을 저장해도 MCP 기능을 자동으로 얻지 않습니다.
## 에이전트 복사
diff --git a/apps/docs/content/docs/agents-create.mdx b/apps/docs/content/docs/agents-create.mdx
index 351ae8d926..a18fd08a25 100644
--- a/apps/docs/content/docs/agents-create.mdx
+++ b/apps/docs/content/docs/agents-create.mdx
@@ -119,6 +119,10 @@ Critical runtime variables such as `PATH`, `HOME`, and `MULTICA_*` cannot be ove
Custom arguments are passed to the AI coding tool as an array, item by item, without shell expansion. Whether an argument is valid is up to the tool; model configuration that already has a dedicated field doesn't need to be repeated here.
+<Callout type="warning">
+Do not put credentials or other secrets in custom arguments. They remain in the child process's argv and may be visible to other local processes through `ps` or `/proc`; use environment variables (`custom_env`) instead. Daemon logs redact argument values, but that does not protect the operating system's process list.
+</Callout>
+
MCP configuration may contain tokens; its storage and display rules match environment variables. Only runtimes that support managed MCP configuration show this section; tools without MCP support don't gain it just because a configuration is saved.
## Duplicating an agent
diff --git a/apps/docs/content/docs/agents-create.zh.mdx b/apps/docs/content/docs/agents-create.zh.mdx
index 874c7c1c64..a80770af1f 100644
--- a/apps/docs/content/docs/agents-create.zh.mdx
+++ b/apps/docs/content/docs/agents-create.zh.mdx
@@ -119,6 +119,10 @@ Access 决定哪些成员可以运行这名智能体(分配、@提及或对话
自定义参数按数组逐项传给 AI 编程工具,不经过 shell 展开。参数名称是否有效由对应工具决定;已有独立字段的模型配置不需要在这里重复设置。
+<Callout type="warning">
+不要把凭据或其他 secret 放进自定义参数。它们会留在子进程的 argv 中,同机其他进程可能通过 `ps` 或 `/proc` 看到;请改用环境变量(`custom_env`)。守护进程日志会遮蔽参数值,但无法保护操作系统的进程列表。
+</Callout>
+
MCP 配置可能包含 token,保存与展示规则和环境变量相同。只有支持托管 MCP 配置的运行时会显示这一项;不支持的工具不会因为保存了配置就自动获得 MCP 能力。
## 复制智能体
diff --git a/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md b/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md
index 40688701f2..ee4e6299c8 100644
--- a/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md
+++ b/server/internal/service/builtin_skills/multica-creating-agents/SKILL.md
@@ -180,6 +180,12 @@ handler inspects `custom_args` for a model flag. Pi is stricter at invocation
time: `--thinking` in `custom_args` is filtered because the first-class
`thinking_level` field owns that flag and must be the only source of its value.
+Never put credentials or other secrets in `custom_args`. Daemon command logs
+redact argument values, but the values still live in the provider process's
+argv and may be visible to other local processes through `ps` or `/proc`. Put
+provider credentials in `custom_env` instead, using its stdin or 0600 file
+input where possible.
+
## Env & secrets
`custom_env` is secret material. The CLI offers three input channels; two keep
diff --git a/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md b/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md
index 78a6ad74b4..ef89c8bf02 100644
--- a/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md
+++ b/server/internal/service/builtin_skills/multica-creating-agents/references/creating-agents-source-map.md
@@ -120,6 +120,7 @@ go test ./internal/service -run TestBuiltinSkillsConformToTemplate
| Workspace skills FIRST | 1115 | `skills := h.TaskService.LoadAgentSkills(...)` |
| Built-ins appended | 1116 | `skills = append(skills, h.TaskService.BuiltinSkills()...)` |
| Runtime payload | `daemon.go` `TaskAgentData` | Carries `Instructions`, `Skills`, `CustomEnv`, `CustomArgs`, `Model`, `ThinkingLevel`, `ServiceTier`, and `McpConfig`; metadata-only fields remain absent |
+| `custom_args` argv and safe launch log | `internal/daemon/daemon.go` `ExecOptions.CustomArgs`; `pkg/agent/launch.go` `Config.logAgentCommand` | Custom args reach the provider process argv. Launch logs preserve flag names but redact inline values and positional/value tokens; OS process-list exposure remains, so credentials belong in `custom_env`. |
## Skill loading — `server/internal/service/task.go`
diff --git a/server/internal/service/builtin_skills_test.go b/server/internal/service/builtin_skills_test.go
index bfd8a3c963..6e10a7c095 100644
--- a/server/internal/service/builtin_skills_test.go
+++ b/server/internal/service/builtin_skills_test.go
@@ -377,6 +377,7 @@ func TestCreatingAgentsSkillCoversAgentCreationContracts(t *testing.T) {
"multica agent create --name <name> --runtime-id <runtime-id>",
"`model` is a first-class persisted column",
"custom_env",
+ "Never put credentials or other secrets in `custom_args`",
"--custom-env-stdin",
"--custom-env-file",
"multica agent skills add <agent-id> --skill-ids <skill-id> --output json",
diff --git a/server/pkg/agent/agent.go b/server/pkg/agent/agent.go
index 04145c23fc..fcf41f4ee1 100644
--- a/server/pkg/agent/agent.go
+++ b/server/pkg/agent/agent.go
@@ -261,6 +261,10 @@ type Config struct {
// vendor's binary; it defaults to false so an unset caller fails
// closed onto standard behavior.
BuiltinRuntime bool
+ // provider is the runtime/provider identity used in safe launch logs. New
+ // fills it from the protocol family; NewRuntime preserves the concrete
+ // built-in runtime identity instead (for example omp rather than pi).
+ provider string
// LaunchPrefix is the argv prefix that belongs to ExecutablePath itself —
// a custom runtime profile's fixed_args. It is spliced in directly after
// the executable, ahead of every argument a backend builds, because a
@@ -361,6 +365,9 @@ func New(agentType string, cfg Config) (Backend, error) {
if cfg.Logger == nil {
cfg.Logger = slog.Default()
}
+ if cfg.provider == "" {
+ cfg.provider = agentType
+ }
// Filter the launch prefix here, at the one point that knows both the
// prefix and the protocol family. Doing it per-backend would be the same
// opt-in arrangement that let ExtraArgs rot: a family that forgot the call
diff --git a/server/pkg/agent/antigravity.go b/server/pkg/agent/antigravity.go
index e769f0811f..73978ff0cc 100644
--- a/server/pkg/agent/antigravity.go
+++ b/server/pkg/agent/antigravity.go
@@ -81,7 +81,7 @@ func (b *antigravityBackend) Execute(ctx context.Context, prompt string, opts Ex
cmd := b.cfg.commandAt(execPath).exec(runCtx, args...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", args)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/builtin_runtimes.go b/server/pkg/agent/builtin_runtimes.go
index 4e07a7d103..43fed8437d 100644
--- a/server/pkg/agent/builtin_runtimes.go
+++ b/server/pkg/agent/builtin_runtimes.go
@@ -173,6 +173,7 @@ func NewRuntime(runtimeID string, cfg Config) (Backend, error) {
if !ok {
return nil, fmt.Errorf("unknown runtime identity: %q", runtimeID)
}
+ cfg.provider = runtimeID
backend, err := New(desc.ProtocolFamily, cfg)
if err != nil {
return nil, fmt.Errorf("runtime %q (family %q): %w", runtimeID, desc.ProtocolFamily, err)
diff --git a/server/pkg/agent/claude.go b/server/pkg/agent/claude.go
index f296192b26..c23aba0c13 100644
--- a/server/pkg/agent/claude.go
+++ b/server/pkg/agent/claude.go
@@ -89,7 +89,7 @@ func (b *claudeBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
// only after the tree has been signalled. Returning nil keeps os/exec from
// racing us with its own kill; WaitDelay remains the hard backstop.
cmd.Cancel = func() error { return nil }
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", args)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/codebuddy.go b/server/pkg/agent/codebuddy.go
index e1839d0dad..7cd79a5fbf 100644
--- a/server/pkg/agent/codebuddy.go
+++ b/server/pkg/agent/codebuddy.go
@@ -137,7 +137,7 @@ func (b *codebuddyBackend) Execute(ctx context.Context, prompt string, opts Exec
cmd := b.cfg.commandAt(execPath).exec(runCtx, args...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", args)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/codex.go b/server/pkg/agent/codex.go
index 6f91ac7860..1fe1c16292 100644
--- a/server/pkg/agent/codex.go
+++ b/server/pkg/agent/codex.go
@@ -958,10 +958,10 @@ func (b *codexBackend) executeOnce(ctx context.Context, prompt string, opts Exec
// `mcp_servers.<id>.env` is allowed to carry secrets (Codex docs:
// https://developers.openai.com/codex/mcp#configure-with-configtoml)
// and our UI already treats mcp_config as a redacted-for-non-admins
- // field. Process argv ends up in OS-level `ps` listings and is also
- // echoed into the daemon's `agent command` log line below, so any
- // inline env-bearing TOML would defeat the redaction. Writing through
- // config.toml at 0o600 keeps the secret values out of argv and logs.
+ // field. Process argv ends up in OS-level `ps` listings; daemon command
+ // logs redact values, but log redaction cannot protect the process list.
+ // Writing through config.toml at 0o600 keeps the secret values out of argv
+ // entirely.
codexHome := strings.TrimSpace(b.cfg.Env["CODEX_HOME"])
if codexHome != "" {
if err := ensureCodexMcpConfig(filepath.Join(codexHome, "config.toml"), opts.McpConfig, b.cfg.Logger); err != nil {
@@ -1041,7 +1041,7 @@ func (b *codexBackend) executeOnce(ctx context.Context, prompt string, opts Exec
// open pipe held by a grandchild) can't hang cmd.Wait() forever. Matches
// the other long-lived backends (claude, copilot, cursor, …).
cmd.WaitDelay = codexProcessWaitDelay()
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", codexArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(codexArgs, trustAgentCommandPositional(0, "app-server")))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/copilot.go b/server/pkg/agent/copilot.go
index f9ee4036e1..e3ed3c1752 100644
--- a/server/pkg/agent/copilot.go
+++ b/server/pkg/agent/copilot.go
@@ -348,9 +348,9 @@ func (b *copilotBackend) Execute(ctx context.Context, prompt string, opts ExecOp
runCtx, cancel := runContext(ctx, timeout)
args := buildCopilotArgs(prompt, opts, b.cfg.Logger)
- cmd, argv0, cmdArgs := b.cfg.commandAt(execName).execVia(runCtx, chooseCopilotInvocation, lookedUp, args, b.cfg.Logger)
+ cmd, _, _ := b.cfg.commandAt(execName).execVia(runCtx, chooseCopilotInvocation, lookedUp, args, b.cfg.Logger)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", argv0, "args", cmdArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/cursor.go b/server/pkg/agent/cursor.go
index e424e465dd..783268116e 100644
--- a/server/pkg/agent/cursor.go
+++ b/server/pkg/agent/cursor.go
@@ -36,9 +36,9 @@ func (b *cursorBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
runCtx, cancel := runContext(ctx, timeout)
args := buildCursorArgs(opts, b.cfg.Logger)
- cmd, argv0, cmdArgs := b.cfg.commandAt(execName).execVia(runCtx, chooseCursorInvocation, lookedUp, args, b.cfg.Logger)
+ cmd, _, _ := b.cfg.commandAt(execName).execVia(runCtx, chooseCursorInvocation, lookedUp, args, b.cfg.Logger)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", argv0, "args", cmdArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))
cmd.WaitDelay = 500 * time.Millisecond
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/deveco.go b/server/pkg/agent/deveco.go
index 79137f6bf3..7cc6ba578f 100644
--- a/server/pkg/agent/deveco.go
+++ b/server/pkg/agent/deveco.go
@@ -131,7 +131,7 @@ func (b *devecoBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
// here keeps os/exec from racing us with its own kill; WaitDelay is the
// hard backstop.
cmd.Cancel = func() error { return nil }
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", args)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args, trustAgentCommandPositional(0, "run")))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/grok.go b/server/pkg/agent/grok.go
index 61eeea64de..f2e7ffd3d8 100644
--- a/server/pkg/agent/grok.go
+++ b/server/pkg/agent/grok.go
@@ -145,7 +145,10 @@ func (b *grokBackend) Execute(ctx context.Context, prompt string, opts ExecOptio
cmd := b.cfg.commandAt(execPath).exec(runCtx, grokArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", grokArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(grokArgs,
+ trustAgentCommandPositional(1, "agent"),
+ trustAgentCommandPositional(len(grokArgs)-1, "stdio"),
+ ))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/hermes.go b/server/pkg/agent/hermes.go
index 8c57ec4481..c366bf1912 100644
--- a/server/pkg/agent/hermes.go
+++ b/server/pkg/agent/hermes.go
@@ -288,7 +288,7 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOpt
hermesArgs := hermesCLIArgs(opts.CustomArgs, b.cfg.Logger)
cmd := b.cfg.commandAt(execPath).exec(runCtx, hermesArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", hermesArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(hermesArgs, trustAgentCommandPositional(0, hermesACPSubcommand)))
agentsMDPresent := false
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/kimi.go b/server/pkg/agent/kimi.go
index 4a4d1f8e39..331ebb90dd 100644
--- a/server/pkg/agent/kimi.go
+++ b/server/pkg/agent/kimi.go
@@ -67,7 +67,7 @@ func (b *kimiBackend) Execute(ctx context.Context, prompt string, opts ExecOptio
kimiArgs := append([]string{"acp"}, filterCustomArgs(opts.CustomArgs, kimiBlockedArgs, b.cfg.Logger)...)
cmd := b.cfg.commandAt(execPath).exec(runCtx, kimiArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", kimiArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(kimiArgs, trustAgentCommandPositional(0, "acp")))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/kiro.go b/server/pkg/agent/kiro.go
index cbcff40364..fb75413594 100644
--- a/server/pkg/agent/kiro.go
+++ b/server/pkg/agent/kiro.go
@@ -64,7 +64,7 @@ func (b *kiroBackend) Execute(ctx context.Context, prompt string, opts ExecOptio
kiroArgs := append([]string{"acp", "--trust-all-tools"}, filterCustomArgs(opts.CustomArgs, kiroBlockedArgs, b.cfg.Logger)...)
cmd := b.cfg.commandAt(execPath).exec(runCtx, kiroArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", kiroArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(kiroArgs, trustAgentCommandPositional(0, "acp")))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/launch.go b/server/pkg/agent/launch.go
index fd8c39765d..223b04bcb8 100644
--- a/server/pkg/agent/launch.go
+++ b/server/pkg/agent/launch.go
@@ -7,6 +7,37 @@ import (
"strings"
)
+const redactedAgentCommandArg = "<redacted>"
+
+const maxLoggedAgentCommandFlagLen = 64
+
+// agentCommandLogArgs describes the adapter-assembled argv handed to the
+// launch boundary. trustedPositionals contains indexes into invocationArgs for
+// literal subcommands owned by the adapter; every other positional remains
+// redacted. Keeping index-and-literal assertions instead of a global string
+// allowlist makes trust follow the argument's source, so an identical token
+// supplied through custom_args is still treated as sensitive.
+type agentCommandLogArgs struct {
+ invocationArgs []string
+ trustedPositionals []trustedAgentCommandPositional
+}
+
+type trustedAgentCommandPositional struct {
+ index int
+ value string
+}
+
+func trustAgentCommandPositional(index int, value string) trustedAgentCommandPositional {
+ return trustedAgentCommandPositional{index: index, value: value}
+}
+
+func newAgentCommandLogArgs(invocationArgs []string, trustedPositionals ...trustedAgentCommandPositional) agentCommandLogArgs {
+ return agentCommandLogArgs{
+ invocationArgs: invocationArgs,
+ trustedPositionals: append([]trustedAgentCommandPositional(nil), trustedPositionals...),
+ }
+}
+
// Command is the identity of a runtime CLI: the executable Multica spawns plus
// the argv prefix that belongs to the command itself rather than to any single
// invocation.
@@ -142,6 +173,127 @@ func (c Config) commandAt(path string) Command {
return Command{Path: path, Prefix: c.LaunchPrefix, logger: c.Logger}
}
+// logAgentCommand is the only boundary allowed to record runtime process
+// arguments. It works from the final exec.Cmd so launch prefixes and
+// platform-specific rewrites are represented, but never records argument
+// values: flag names and adapter-owned literal subcommands remain useful for
+// diagnostics, inline values are removed, and every other positional/value
+// token is replaced with a marker.
+func (c Config) logAgentCommand(cmd *exec.Cmd, source agentCommandLogArgs) {
+ c.logAgentCommandFields(cmd, source, 0, false)
+}
+
+// logAgentCommandWithPrompt adds only a typed prompt byte count to the safe
+// command log. Keeping it separate from logAgentCommand avoids an open-ended
+// optional field channel that could accidentally carry prompt content.
+func (c Config) logAgentCommandWithPrompt(cmd *exec.Cmd, source agentCommandLogArgs, promptBytes int) {
+ c.logAgentCommandFields(cmd, source, promptBytes, true)
+}
+
+func (c Config) logAgentCommandFields(cmd *exec.Cmd, source agentCommandLogArgs, promptBytes int, includePromptBytes bool) {
+ if cmd == nil {
+ return
+ }
+ logger := c.Logger
+ if logger == nil {
+ logger = slog.Default()
+ }
+
+ args := []string{}
+ if len(cmd.Args) > 1 {
+ args = cmd.Args[1:]
+ }
+ trustedPositionals := c.trustedAgentCommandPositionals(args, source)
+ fields := []any{
+ "provider", c.provider,
+ "exec", cmd.Path,
+ "args", redactAgentCommandArgs(args, trustedPositionals),
+ "arg_count", len(args),
+ }
+ if includePromptBytes {
+ fields = append(fields, "prompt_bytes", promptBytes)
+ }
+ logger.Info("agent command", fields...)
+}
+
+// trustedAgentCommandPositionals maps source indexes onto the final exec.Cmd
+// argv. Platform launch rewrites may prepend a PowerShell host and wrapper
+// arguments, so the original launch prefix plus adapter argv must match the
+// final suffix before any positional is trusted. A mismatch fails closed.
+func (c Config) trustedAgentCommandPositionals(finalArgs []string, source agentCommandLogArgs) map[int]struct{} {
+ originalLen := len(c.LaunchPrefix) + len(source.invocationArgs)
+ start := len(finalArgs) - originalLen
+ if start < 0 {
+ return nil
+ }
+ for i, arg := range c.LaunchPrefix {
+ if finalArgs[start+i] != arg {
+ return nil
+ }
+ }
+ invocationStart := start + len(c.LaunchPrefix)
+ for i, arg := range source.invocationArgs {
+ if finalArgs[invocationStart+i] != arg {
+ return nil
+ }
+ }
+
+ trusted := make(map[int]struct{}, len(source.trustedPositionals))
+ for _, positional := range source.trustedPositionals {
+ if positional.index < 0 || positional.index >= len(source.invocationArgs) ||
+ source.invocationArgs[positional.index] != positional.value {
+ continue
+ }
+ trusted[invocationStart+positional.index] = struct{}{}
+ }
+ return trusted
+}
+
+// redactAgentCommandArgs preserves only syntactically plausible flag names and
+// source-proven adapter subcommands while removing every value. Single-dash
+// flags must be one ASCII letter; this keeps a token such as
+// "-sTk9xQZ-secretvalue" from being mistaken for a flag. Long flags are
+// length-bounded and lose inline values. All other tokens become <redacted>.
+func redactAgentCommandArgs(args []string, trustedPositionals map[int]struct{}) []string {
+ redacted := make([]string, len(args))
+ for i, arg := range args {
+ if _, ok := trustedPositionals[i]; ok {
+ redacted[i] = arg
+ continue
+ }
+ if flag, ok := safeAgentCommandFlagName(arg); ok {
+ redacted[i] = flag
+ continue
+ }
+ redacted[i] = redactedAgentCommandArg
+ }
+ return redacted
+}
+
+func safeAgentCommandFlagName(arg string) (string, bool) {
+ flag := arg
+ if equals := strings.IndexByte(flag, '='); equals > 0 {
+ flag = flag[:equals]
+ }
+ if len(flag) == 2 && flag[0] == '-' && isASCIIAlpha(flag[1]) {
+ return flag, true
+ }
+ if len(flag) < 3 || len(flag) > maxLoggedAgentCommandFlagLen || !strings.HasPrefix(flag, "--") || !isASCIIAlpha(flag[2]) {
+ return "", false
+ }
+ for i := 3; i < len(flag); i++ {
+ ch := flag[i]
+ if !isASCIIAlpha(ch) && (ch < '0' || ch > '9') && ch != '.' && ch != '_' && ch != '-' {
+ return "", false
+ }
+ }
+ return flag, true
+}
+
+func isASCIIAlpha(ch byte) bool {
+ return ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z'
+}
+
// launchPrefixBlockedArgs maps a protocol family to the flags a launch prefix
// may not set. It exists so New can filter the prefix once, at the single
// point that knows the family, instead of asking each backend to remember.
diff --git a/server/pkg/agent/launch_test.go b/server/pkg/agent/launch_test.go
index a6362484bc..ede0bc767f 100644
--- a/server/pkg/agent/launch_test.go
+++ b/server/pkg/agent/launch_test.go
@@ -8,6 +8,7 @@ import (
"go/token"
"log/slog"
"os"
+ "os/exec"
"path/filepath"
"strings"
"testing"
@@ -180,6 +181,141 @@ func TestCommandArgvNeverAliasesItsInputs(t *testing.T) {
}
}
+func TestRedactAgentCommandArgsPreservesOnlySafeFlagNames(t *testing.T) {
+ t.Parallel()
+
+ overlongFlag := "--" + strings.Repeat("a", maxLoggedAgentCommandFlagLen)
+ args := []string{
+ "--api-key", "api-key-secret",
+ "--dash-prefixed-secret", "-sTk9xQZ-secretvalue",
+ "--token=token-secret",
+ "--header", "Authorization: Bearer header-secret",
+ "-c", `model_providers.example.api_key="config-secret"`,
+ "--future-secret", "future-value-secret",
+ "prompt-secret",
+ "--verbose",
+ "-not-a-short-flag",
+ overlongFlag,
+ }
+ want := []string{
+ "--api-key", redactedAgentCommandArg,
+ "--dash-prefixed-secret", redactedAgentCommandArg,
+ "--token",
+ "--header", redactedAgentCommandArg,
+ "-c", redactedAgentCommandArg,
+ "--future-secret", redactedAgentCommandArg,
+ redactedAgentCommandArg,
+ "--verbose",
+ redactedAgentCommandArg,
+ redactedAgentCommandArg,
+ }
+
+ got := redactAgentCommandArgs(args, nil)
+ if strings.Join(got, "\x00") != strings.Join(want, "\x00") {
+ t.Fatalf("redactAgentCommandArgs = %v, want %v", got, want)
+ }
+}
+
+func TestTrustedAgentCommandPositionalsFollowSourceIndexes(t *testing.T) {
+ t.Parallel()
+
+ invocationArgs := []string{"acp", "--api-key", "-sTk9xQZ-secretvalue", "acp"}
+ finalArgs := []string{
+ "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "wrapper.ps1",
+ "start", "q36",
+ "acp", "--api-key", "-sTk9xQZ-secretvalue", "acp",
+ }
+ cfg := Config{LaunchPrefix: []string{"start", "q36"}}
+ trusted := cfg.trustedAgentCommandPositionals(finalArgs,
+ newAgentCommandLogArgs(invocationArgs, trustAgentCommandPositional(0, "acp")))
+
+ got := redactAgentCommandArgs(finalArgs, trusted)
+ want := []string{
+ redactedAgentCommandArg, redactedAgentCommandArg, redactedAgentCommandArg, redactedAgentCommandArg, redactedAgentCommandArg,
+ redactedAgentCommandArg, redactedAgentCommandArg,
+ "acp", "--api-key", redactedAgentCommandArg, redactedAgentCommandArg,
+ }
+ if strings.Join(got, "\x00") != strings.Join(want, "\x00") {
+ t.Fatalf("source-aware redaction = %v, want %v", got, want)
+ }
+}
+
+func TestLogAgentCommandRedactsTextAndJSON(t *testing.T) {
+ t.Parallel()
+
+ args := []string{
+ "--api-key", "api-key-secret",
+ "--dash-prefixed-secret", "-sTk9xQZ-secretvalue",
+ "--token=token-secret",
+ "--header", "Authorization: Bearer header-secret",
+ "-c", `model_providers.example.api_key="config-secret"`,
+ "--future-secret", "future-value-secret",
+ "prompt-secret",
+ }
+ secrets := []string{
+ "api-key-secret",
+ "-sTk9xQZ-secretvalue",
+ "token-secret",
+ "Authorization: Bearer header-secret",
+ "config-secret",
+ "future-value-secret",
+ "prompt-secret",
+ }
+
+ for _, tc := range []struct {
+ name string
+ handler func(*bytes.Buffer) slog.Handler
+ }{
+ {"text", func(buf *bytes.Buffer) slog.Handler { return slog.NewTextHandler(buf, nil) }},
+ {"json", func(buf *bytes.Buffer) slog.Handler { return slog.NewJSONHandler(buf, nil) }},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ var buf bytes.Buffer
+ cfg := Config{Logger: slog.New(tc.handler(&buf)), provider: "codex"}
+ cmd := &exec.Cmd{Path: "/opt/multica/bin/codex", Args: append([]string{"codex"}, args...)}
+ cfg.logAgentCommandWithPrompt(cmd, newAgentCommandLogArgs(args), 123)
+
+ output := buf.String()
+ for _, secret := range secrets {
+ if strings.Contains(output, secret) {
+ t.Errorf("%s log exposed %q: %s", tc.name, secret, output)
+ }
+ }
+ for _, diagnostic := range []string{
+ "agent command", "provider", "codex", "/opt/multica/bin/codex",
+ "--api-key", "--token", "--header", "-c", "--future-secret",
+ redactedAgentCommandArg, "arg_count", "prompt_bytes",
+ } {
+ if !strings.Contains(output, diagnostic) {
+ t.Errorf("%s log omitted diagnostic %q: %s", tc.name, diagnostic, output)
+ }
+ }
+ })
+ }
+}
+
+func TestBackendFactoriesSetCommandLogProvider(t *testing.T) {
+ t.Parallel()
+
+ claude, err := New("claude", Config{Logger: slog.Default()})
+ if err != nil {
+ t.Fatalf("New(claude): %v", err)
+ }
+ if got := claude.(*claudeBackend).cfg.provider; got != "claude" {
+ t.Fatalf("claude log provider = %q, want claude", got)
+ }
+
+ omp, err := NewRuntime("omp", Config{Logger: slog.Default()})
+ if err != nil {
+ t.Fatalf("NewRuntime(omp): %v", err)
+ }
+ if got := omp.(*piBackend).cfg.provider; got != "omp" {
+ t.Fatalf("omp log provider = %q, want omp", got)
+ }
+}
+
// TestOnlyLaunchGoSpawnsRuntimeProcesses is the structural half of this fix.
//
// Distributed opt-in is what let ExtraArgs rot: it was honoured by six of
@@ -248,6 +384,92 @@ func TestOnlyLaunchGoSpawnsRuntimeProcesses(t *testing.T) {
}
}
+func containsRuntimeArgReference(expr ast.Expr) bool {
+ found := false
+ ast.Inspect(expr, func(n ast.Node) bool {
+ switch node := n.(type) {
+ case *ast.SelectorExpr:
+ if node.Sel.Name == "Args" {
+ found = true
+ return false
+ }
+ case *ast.Ident:
+ switch strings.ToLower(node.Name) {
+ case "args", "cmdargs", "argv":
+ found = true
+ return false
+ }
+ }
+ return !found
+ })
+ return found
+}
+
+// TestOnlyLaunchGoLogsAgentCommandArgs keeps raw argv out of adapter-local log
+// calls. Every runtime process log must flow through Config.logAgentCommand in
+// launch.go, where values are redacted consistently for text and JSON handlers.
+// The guard checks both common field labels and the expressions themselves, so
+// renaming an "args" field to "argv" cannot bypass it while still passing
+// cmd.Args, args, cmdArgs, or argv to a logger.
+func TestOnlyLaunchGoLogsAgentCommandArgs(t *testing.T) {
+ t.Parallel()
+
+ entries, err := os.ReadDir(".")
+ if err != nil {
+ t.Fatalf("read package dir: %v", err)
+ }
+
+ fset := token.NewFileSet()
+ var offenders []string
+ for _, entry := range entries {
+ name := entry.Name()
+ if entry.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") || name == "launch.go" {
+ continue
+ }
+ src, err := os.ReadFile(name)
+ if err != nil {
+ t.Fatalf("read %s: %v", name, err)
+ }
+ file, err := parser.ParseFile(fset, name, src, 0)
+ if err != nil {
+ t.Fatalf("parse %s: %v", name, err)
+ }
+ ast.Inspect(file, func(n ast.Node) bool {
+ call, ok := n.(*ast.CallExpr)
+ if !ok {
+ return true
+ }
+ sel, ok := call.Fun.(*ast.SelectorExpr)
+ if !ok {
+ return true
+ }
+ switch sel.Sel.Name {
+ case "Debug", "Info", "Warn", "Error", "Log", "LogAttrs":
+ default:
+ return true
+ }
+ for _, arg := range call.Args {
+ literal, ok := arg.(*ast.BasicLit)
+ if ok && literal.Kind == token.STRING &&
+ (literal.Value == `"args"` || literal.Value == `"argv"` || literal.Value == `"agent command"`) {
+ offenders = append(offenders, fset.Position(call.Pos()).String())
+ break
+ }
+ if containsRuntimeArgReference(arg) {
+ offenders = append(offenders, fset.Position(call.Pos()).String())
+ break
+ }
+ }
+ return true
+ })
+ }
+
+ if len(offenders) > 0 {
+ t.Fatalf("runtime argv logs must use Config.logAgentCommand in launch.go so values are redacted. Offending sites:\n%s",
+ strings.Join(offenders, "\n"))
+ }
+}
+
// TestClaudeBackendLaunchesWrapperSubcommandFirst is the end-to-end proof:
// a real subprocess, spawned through the real backend, records the argv it was
// handed. The fake wrapper stands in for `ccms` and never touches a
diff --git a/server/pkg/agent/mcode.go b/server/pkg/agent/mcode.go
index 8f1eee7fd7..a9de902bb8 100644
--- a/server/pkg/agent/mcode.go
+++ b/server/pkg/agent/mcode.go
@@ -99,7 +99,7 @@ func (b *mcodeBackend) Execute(ctx context.Context, prompt string, opts ExecOpti
return nil
}
cmd.WaitDelay = mcodeReaderDrainGrace
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", args)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args, trustAgentCommandPositional(0, "acp")))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/openclaw.go b/server/pkg/agent/openclaw.go
index a7688a3640..c6a2e31dd5 100644
--- a/server/pkg/agent/openclaw.go
+++ b/server/pkg/agent/openclaw.go
@@ -76,7 +76,7 @@ func (b *openclawBackend) Execute(ctx context.Context, prompt string, opts ExecO
cmd := b.cfg.commandAt(execPath).exec(runCtx, args...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", args)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args, trustAgentCommandPositional(0, "agent")))
// 500ms, matching cursor-agent — the other backend whose CLI can deliver a
// terminal result while keeping a process alive.
//
diff --git a/server/pkg/agent/opencode.go b/server/pkg/agent/opencode.go
index ec2cf2a12a..947785f319 100644
--- a/server/pkg/agent/opencode.go
+++ b/server/pkg/agent/opencode.go
@@ -106,8 +106,9 @@ func (b *opencodeBackend) Execute(ctx context.Context, prompt string, opts ExecO
// (8,191 when a .cmd shim routes the call through cmd.exe), and a prompt
// carrying the workspace's models and skills clears that on its own — the
// process then never starts and Go surfaces the misleading "The filename or
- // extension is too long" (#6538). Keeping the prompt off argv also stops it
- // from being echoed into the "agent command" log line below.
+ // extension is too long" (#6538). Keeping the prompt off argv also keeps it
+ // out of OS process listings; the shared command logger separately redacts
+ // argv values.
cmd := b.cfg.commandAt(execPath).exec(runCtx, args...)
hideAgentWindow(cmd)
@@ -123,7 +124,7 @@ func (b *opencodeBackend) Execute(ctx context.Context, prompt string, opts ExecO
// signalled. Returning nil here keeps os/exec from racing us with its own
// kill; WaitDelay remains the hard backstop.
cmd.Cancel = func() error { return nil }
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", args, "prompt_bytes", len(prompt))
+ b.cfg.logAgentCommandWithPrompt(cmd, newAgentCommandLogArgs(args, trustAgentCommandPositional(0, "run")), len(prompt))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/pi.go b/server/pkg/agent/pi.go
index 59cc7c827b..cda446bea6 100644
--- a/server/pkg/agent/pi.go
+++ b/server/pkg/agent/pi.go
@@ -230,9 +230,9 @@ func (b *piBackend) Execute(ctx context.Context, prompt string, opts ExecOptions
runCtx, cancel := runContext(ctx, timeout)
args := buildPiArgs(sessionPath, opts, b.cfg.Logger)
- cmd, argv0, cmdArgs := b.cfg.commandAt(execName).execVia(runCtx, choosePiInvocation, lookedUp, args, b.cfg.Logger)
+ cmd, _, _ := b.cfg.commandAt(execName).execVia(runCtx, choosePiInvocation, lookedUp, args, b.cfg.Logger)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", argv0, "args", cmdArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/qoder.go b/server/pkg/agent/qoder.go
index c9ddbede53..aab6f49380 100644
--- a/server/pkg/agent/qoder.go
+++ b/server/pkg/agent/qoder.go
@@ -103,7 +103,7 @@ func (b *qoderBackend) Execute(ctx context.Context, prompt string, opts ExecOpti
)
cmd := b.cfg.commandAt(execPath).exec(runCtx, qoderArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", qoderArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(qoderArgs))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/qwen.go b/server/pkg/agent/qwen.go
index ba6b6c9860..f8036dcb7f 100644
--- a/server/pkg/agent/qwen.go
+++ b/server/pkg/agent/qwen.go
@@ -98,8 +98,8 @@ func (b *qwenBackend) Execute(ctx context.Context, prompt string, opts ExecOptio
}()
cmd := b.cfg.commandAt(execPath).exec(runCtx, args...)
hideAgentWindow(cmd)
- // args contain the task prompt; never expose it in daemon logs.
- b.cfg.Logger.Info("agent command", "exec", execPath, "provider", "qwen")
+ // args contain the task prompt; the shared logger preserves only flag names.
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))
cmd.WaitDelay = 10 * time.Second
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
diff --git a/server/pkg/agent/qwenpaw.go b/server/pkg/agent/qwenpaw.go
index 447202dcb0..2a8896e668 100644
--- a/server/pkg/agent/qwenpaw.go
+++ b/server/pkg/agent/qwenpaw.go
@@ -88,7 +88,7 @@ func (b *qwenpawBackend) Execute(ctx context.Context, prompt string, opts ExecOp
cmd := b.cfg.commandAt(execPath).exec(runCtx, qwenpawArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", qwenpawArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(qwenpawArgs, trustAgentCommandPositional(0, "acp")))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/reasonix.go b/server/pkg/agent/reasonix.go
index d5512fffcf..129915ad8a 100644
--- a/server/pkg/agent/reasonix.go
+++ b/server/pkg/agent/reasonix.go
@@ -87,7 +87,7 @@ func (b *reasonixBackend) Execute(ctx context.Context, prompt string, opts ExecO
reasonixArgs := append(reasonixACPLaunchArgs(), filterCustomArgs(opts.CustomArgs, reasonixBlockedArgs, b.cfg.Logger)...)
cmd := b.cfg.commandAt(execPath).exec(runCtx, reasonixArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", reasonixArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(reasonixArgs, trustAgentCommandPositional(0, "acp")))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}
diff --git a/server/pkg/agent/traecli.go b/server/pkg/agent/traecli.go
index 9c7f9459e7..1e33062adf 100644
--- a/server/pkg/agent/traecli.go
+++ b/server/pkg/agent/traecli.go
@@ -113,7 +113,10 @@ func (b *traecliBackend) Execute(ctx context.Context, prompt string, opts ExecOp
)
cmd := b.cfg.commandAt(execPath).exec(runCtx, traecliArgs...)
hideAgentWindow(cmd)
- b.cfg.Logger.Info("agent command", "exec", execPath, "args", traecliArgs)
+ b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(traecliArgs,
+ trustAgentCommandPositional(0, "acp"),
+ trustAgentCommandPositional(1, "serve"),
+ ))
if opts.Cwd != "" {
cmd.Dir = opts.Cwd
}