fix(agent): use picoclaw home dir for history file instead of /tmp

Security fix for issue #2234:
- HistoryFile was hardcoded to os.TempDir() which is world-readable
- Now uses internal.GetPicoclawHome() which respects $PICOCLAW_HOME
- Creates the home directory if it doesn't exist with proper permissions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
merlinmiao 2026-04-07 10:08:00 +08:00
parent 380debb506
commit ab2c6207a2

View file

@ -82,9 +82,14 @@ func agentCmd(message, sessionKey, model string, debug bool) error {
func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) { func interactiveMode(agentLoop *agent.AgentLoop, sessionKey string) {
prompt := fmt.Sprintf("%s You: ", internal.Logo) prompt := fmt.Sprintf("%s You: ", internal.Logo)
historyFile := filepath.Join(internal.GetPicoclawHome(), ".picoclaw_history")
if err := os.MkdirAll(internal.GetPicoclawHome(), 0700); err != nil {
fmt.Printf("Error creating picoclaw home directory: %v\n", err)
}
rl, err := readline.NewEx(&readline.Config{ rl, err := readline.NewEx(&readline.Config{
Prompt: prompt, Prompt: prompt,
HistoryFile: filepath.Join(os.TempDir(), ".picoclaw_history"), HistoryFile: historyFile,
HistoryLimit: 100, HistoryLimit: 100,
InterruptPrompt: "^C", InterruptPrompt: "^C",
EOFPrompt: "exit", EOFPrompt: "exit",