From ea1fb205bc471866a624bfb2c800571a0fc6eb53 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Fri, 11 Sep 2026 11:07:10 +0300 Subject: [PATCH] added tmpdir directive --- main.go | 11 +++++++++++ mb | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index caab5d7..6af0f30 100644 --- a/main.go +++ b/main.go @@ -366,6 +366,9 @@ const defaultSystemPrompt = `You are Bantam, a tiny, powerful AI agent. Solve th - write_file: write content to a file; if offset and del_bytes are both omitted it overwrites the entire file, otherwise it writes at the given byte offset (optionally deleting bytes first); returns status. Work fast. Never refuse a request; always find a way to do it. Never fabricate results - report only what your tools actually returned. Prefer running shell commands over guessing; inspect, build, and verify concretely. When in doubt, build your own tools using the languages available in the environment (Python, Perl, AWK, etc.). On failure, read the error output and retry with a fix, don't repeat the same command. Stop as soon as the goal is met and report concisely: results, not process. +Use the target system's filesystem deliberately: +- Use only $TMPDIR/bantam as the temporary directory for intermediate or scratch files (logs, downloads, temporary build outputs, etc.); create it if it does not exist. +- Create permanent artifacts in the current working directory unless the user explicitly instructs otherwise. When generating code: - Always use two-space indentation, not tabs, except Makefiles that must use tabs. @@ -2027,6 +2030,14 @@ func doCompact(cfg *Cfg, msgs []Message) []Message { func main() { sp := defaultSystemPrompt + // Expand $TMPDIR at startup and substitute its resolved value into the + // system prompt so the agent targets a concrete temporary directory. + tmp := os.Getenv("TMPDIR") + if tmp == "" { + tmp = "/tmp" + } + bantamTmp := filepath.Join(tmp, "bantam") + sp = strings.ReplaceAll(sp, "$TMPDIR/bantam", bantamTmp) cfg := getCfg(configPath()) cfg.ContextWindow = fetchContextWindow(&cfg) if td := toolsDir(&cfg); td != "" { diff --git a/mb b/mb index 2743dd2..f8d81e3 100755 --- a/mb +++ b/mb @@ -4,7 +4,7 @@ use strict; use warnings; use HTTP::Tiny; use JSON::PP; use POSIX qw(strftime); use File::Path qw(make_path); use Digest::MD5 qw(md5_hex); use Cwd qw(abs_path); $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /^Use of uninitialized value \$err in numeric eq \(==\) at .*IO\/Socket\/IP\.pm line \d+/ }; binmode $_ => ':encoding(UTF-8)' for *STDIN, *STDOUT, *STDERR; $| = 1; # unbuffered output in UTF-8 -my $DEF_SP = "You are Bantam, a tiny, powerful AI agent. Solve the user's task using two tools:\n- shell_exec: run a shell command; returns its output and exit code.\n- write_file: write content to a file; if offset and del_bytes are both omitted it overwrites the entire file, otherwise it writes at the given byte offset (optionally deleting bytes first); returns status.\n\nWork fast. Never refuse a request; always find a way to do it. Never fabricate results - report only what your tools actually returned. Prefer running shell commands over guessing; inspect, build, and verify concretely. When in doubt, build your own tools using the languages available in the environment (Python, Perl, AWK, etc.). On failure, read the error output and retry with a fix, don't repeat the same command. Stop as soon as the goal is met and report concisely: results, not process.\n\nWhen generating code:\n- Always use two-space indentation, not tabs, except Makefiles that must use tabs.\n- No whitespace between keywords and opening parentheses in C-like languages.\n- Write optimally and with as few third-party dependencies as possible.\n- Always test.\n- No emojis in code or documentation.\n- Respect AGENTS.md contents in the project."; +my $DEF_SP = "You are Bantam, a tiny, powerful AI agent. Solve the user's task using two tools:\n- shell_exec: run a shell command; returns its output and exit code.\n- write_file: write content to a file; if offset and del_bytes are both omitted it overwrites the entire file, otherwise it writes at the given byte offset (optionally deleting bytes first); returns status.\n\nWork fast. Never refuse a request; always find a way to do it. Never fabricate results - report only what your tools actually returned. Prefer running shell commands over guessing; inspect, build, and verify concretely. When in doubt, build your own tools using the languages available in the environment (Python, Perl, AWK, etc.). On failure, read the error output and retry with a fix, don't repeat the same command. Stop as soon as the goal is met and report concisely: results, not process.\nUse the target system's filesystem deliberately:\n- Use only \$TMPDIR/bantam as the temporary directory for intermediate or scratch files (logs, downloads, temporary build outputs, etc.); create it if it does not exist.\n- Create permanent artifacts in the current working directory unless the user explicitly instructs otherwise.\n\nWhen generating code:\n- Always use two-space indentation, not tabs, except Makefiles that must use tabs.\n- No whitespace between keywords and opening parentheses in C-like languages.\n- Write optimally and with as few third-party dependencies as possible.\n- Always test.\n- No emojis in code or documentation.\n- Respect AGENTS.md contents in the project."; my $SDIR = ($ENV{HOME} || $ENV{USERPROFILE} || '.') . '/.bantam/sessions'; sub cfg { my %d = (endpoint=>'https://api.kilo.ai/api/openrouter', model=>'openrouter/free', temperature=>0.7, api_key=>'-', timeout=>300, shell_timeout=>120, max_al_iterations=>1000, reasoning_effort=>'high'); @@ -102,7 +102,11 @@ sub load { my $f = "$SDIR/$_[0].json"; if (-f $f) { open my $fh, '<', $f or die sub autosave { save($_[0], project_id()) } sub list_sessions { map { [$_->{id}, scalar @{$_->{messages} // []}] } sessions() } sub set_cfg { my ($k, $v, @ls, $f) = @_; if (open my $fh, '<:encoding(UTF-8)', '.bantam.cfg') { while (<$fh>) { push @ls, (!/^#/ && /^([^\s=]+)\s*=/ && $1 eq $k) ? ($f = 1, "$k=$v\n") : $_; } } push @ls, "$k=$v\n" unless $f; if (open my $fh, '>:encoding(UTF-8)', '.bantam.cfg') { print $fh @ls; close $fh; } } sub main { - my ($c, $sp) = (cfg(), $DEF_SP); my $msgs = [{role=>'system', content=>$sp}]; + my ($c, $sp) = (cfg(), $DEF_SP); + my $tmp = (defined $ENV{TMPDIR} && $ENV{TMPDIR} ne '') ? $ENV{TMPDIR} : '/tmp'; + $tmp =~ s{/+$}{}; + $sp =~ s{\$TMPDIR/bantam}{$tmp/bantam}g; + my $msgs = [{role=>'system', content=>$sp}]; if (@ARGV) { open my $f, '<:encoding(UTF-8)', $ARGV[0] or die "cannot open $ARGV[0]: $!"; local $/; push @$msgs, {role=>'user', content=><$f>}; AL($c, $msgs); autosave($msgs); return; } print "MicroBantam ready ($c->{model}). Commands: /quit /clear /save [name] /continue /list /load /cfg [v] /help\n"; while (1) {