2026-08-27 03:12:55 +00:00
|
|
|
package tools
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// assignmentPattern finds NAME=value in a model-built shell command.
|
|
|
|
|
// It is not used on user chat text. The name must be UPPER_SNAKE_CASE so
|
|
|
|
|
// flags like --model and URLs are not treated as environment variables.
|
|
|
|
|
var assignmentPattern = regexp.MustCompile(
|
|
|
|
|
`(?:^|[;|&\s])(?:export\s+)?([A-Z_][A-Z0-9_]{0,127})=(?:"([^"]*)"|'([^']*)'|([^\s;|&]+))`,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func extractExportedEnv(command string) map[string]string {
|
|
|
|
|
out := map[string]string{}
|
|
|
|
|
for _, match := range assignmentPattern.FindAllStringSubmatch(command, -1) {
|
|
|
|
|
name := match[1]
|
|
|
|
|
value := match[2] + match[3] + match[4]
|
|
|
|
|
if name == "" || value == "" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
out[name] = value
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func collectUsedSkillEnv(command string, toolEnv map[string]string) map[string]string {
|
|
|
|
|
out := extractExportedEnv(command)
|
|
|
|
|
for name, value := range toolEnv {
|
|
|
|
|
if strings.TrimSpace(value) == "" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
out[name] = value
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
fix(sandbox): make skill env capture fill blanks only
Capture existed so a credential a user typed in chat survives the turn.
It also overwrote values already stored, inferred the skill from a path in
the command, and logged the command that carried the secret — so one
hallucinated `export KEY=test` could permanently replace a working key,
and the key ended up in the application log either way.
Capture now only fills a blank: a name the workspace or the caller has
already filled in is dropped before the write path sees it, the skill must
be named explicitly, and assignment values are masked in logs.
The path the error message advertised did not exist: a required variable
was refused before the call's own env was considered, so an IM user, who
has no settings page, could never get the skill to run. Values supplied by
the call now satisfy the requirement, and the message names the tool that
accepts them.
Also take envs out of the generic UpdateSkill. Every install-progress
write is a read-modify-write of the whole row, and the heartbeat reloads
it every 30 seconds, so carrying envs along could put a stale declaration
back over one just recorded. Encryption failures abort the write instead
of storing plaintext in a queryable JSONB column, matching TenantAPIKey.
Reverts an unrelated deletion of the no-volume-support warning.
2026-08-27 04:25:19 +00:00
|
|
|
// maskCommandAssignments replaces the value of every NAME=value assignment with
|
|
|
|
|
// a placeholder. A command is logged at Info, and passing a credential inline is
|
|
|
|
|
// a documented way to hand a skill its key, so the raw string must never reach
|
|
|
|
|
// the log.
|
|
|
|
|
func maskCommandAssignments(command string) string {
|
|
|
|
|
return assignmentPattern.ReplaceAllStringFunc(command, func(match string) string {
|
|
|
|
|
eq := strings.Index(match, "=")
|
|
|
|
|
if eq < 0 {
|
|
|
|
|
return match
|
2026-08-27 03:12:55 +00:00
|
|
|
}
|
fix(sandbox): make skill env capture fill blanks only
Capture existed so a credential a user typed in chat survives the turn.
It also overwrote values already stored, inferred the skill from a path in
the command, and logged the command that carried the secret — so one
hallucinated `export KEY=test` could permanently replace a working key,
and the key ended up in the application log either way.
Capture now only fills a blank: a name the workspace or the caller has
already filled in is dropped before the write path sees it, the skill must
be named explicitly, and assignment values are masked in logs.
The path the error message advertised did not exist: a required variable
was refused before the call's own env was considered, so an IM user, who
has no settings page, could never get the skill to run. Values supplied by
the call now satisfy the requirement, and the message names the tool that
accepts them.
Also take envs out of the generic UpdateSkill. Every install-progress
write is a read-modify-write of the whole row, and the heartbeat reloads
it every 30 seconds, so carrying envs along could put a stale declaration
back over one just recorded. Encryption failures abort the write instead
of storing plaintext in a queryable JSONB column, matching TenantAPIKey.
Reverts an unrelated deletion of the no-volume-support warning.
2026-08-27 04:25:19 +00:00
|
|
|
return match[:eq+1] + "***"
|
|
|
|
|
})
|
2026-08-27 03:12:55 +00:00
|
|
|
}
|