diff --git a/bantam.pl b/bantam.pl index 64a8bce..b53de0b 100755 --- a/bantam.pl +++ b/bantam.pl @@ -58,7 +58,7 @@ sub get_cfg { return \%d; } -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- run_subagent: delegate a sub-task to a child agent; returns its reply.\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. Delegate large or independent sub-tasks to run_subagent. 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 braces 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, GEMINI.md, CLAUDE.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- run_subagent: delegate a sub-task to a child agent; returns its reply.\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. Delegate large or independent sub-tasks to run_subagent. 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 braces 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, GEMINI.md, CLAUDE.md contents in the project."; sub prompt { my ($p) = @_; diff --git a/bantam.py b/bantam.py index 06aa44f..c220bb6 100755 --- a/bantam.py +++ b/bantam.py @@ -43,7 +43,7 @@ DEFAULT_SYSTEM_PROMPT = """You are Bantam, a tiny, powerful AI agent. Solve the - shell_exec: run a shell command; returns its output and exit code. - run_subagent: delegate a sub-task to a child agent; returns its reply. -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. Delegate large or independent sub-tasks to run_subagent. Stop as soon as the goal is met and report concisely: results, not process. +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. Delegate large or independent sub-tasks to run_subagent. Stop as soon as the goal is met and report concisely: results, not process. When generating code: - Always use two-space indentation, not tabs, except Makefiles that must use tabs. diff --git a/main.go b/main.go index af07875..99bb9ae 100644 --- a/main.go +++ b/main.go @@ -82,7 +82,7 @@ const defaultSystemPrompt = `You are Bantam, a tiny, powerful AI agent. Solve th - shell_exec: run a shell command; returns its output and exit code. - run_subagent: delegate a sub-task to a child agent; returns its reply. -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. Delegate large or independent sub-tasks to run_subagent. Stop as soon as the goal is met and report concisely: results, not process. +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. Delegate large or independent sub-tasks to run_subagent. Stop as soon as the goal is met and report concisely: results, not process. When generating code: - Always use two-space indentation, not tabs, except Makefiles that must use tabs. diff --git a/mb b/mb index 680ab08..7619b68 100755 --- a/mb +++ b/mb @@ -14,6 +14,7 @@ $SIG{__WARN__} = sub { # results) prints cleanly instead of triggering "Wide character in print" binmode(STDOUT, ':encoding(UTF-8)'); binmode(STDERR, ':encoding(UTF-8)'); +binmode(STDIN, ':encoding(UTF-8)'); $| = 1; # unbuffered output: live spinner, responsive prompt @@ -21,12 +22,12 @@ my $DEF_SP = "You are Bantam, a tiny, powerful AI agent. Solve the user's task u my $SDIR = ($ENV{HOME} || $ENV{USERPROFILE} || '.') . '/.bantam/sessions'; sub cfg { my %d = (endpoint=>'https://opencode.ai/zen/v1', model=>'big-pickle', temperature=>0.7, api_key=>'-', timeout=>300, shell_timeout=>120, max_al_iterations=>1000); - if (open my $f, '<', 'model.cfg') { while (<$f>) { /^(\w+)\s*=\s*(.+)$/ and $d{$1} = $2; } } + if (open my $f, '<:encoding(UTF-8)', 'model.cfg') { while (<$f>) { /^(\w+)\s*=\s*(.+)$/ and $d{$1} = $2; } } $d{api_key} = $ENV{OPENAI_API_KEY} if $d{api_key} eq q{-} && $ENV{OPENAI_API_KEY}; \%d; } sub sp { my $p = ''; - if (open my $f, '<', 'system.txt') { local $/; $p = <$f>; } + if (open my $f, '<:encoding(UTF-8)', 'system.txt') { local $/; $p = <$f>; } $p =~ s/^\s+|\s+$//g; length($p) ? $p : $DEF_SP; } @@ -51,6 +52,7 @@ sub shell_exec { my ($cmd, $t) = @_; # run a command under a hard timeout my $out = ''; eval { local $SIG{ALRM} = sub { alarm 0; die "timeout\n" }; alarm $t; $out = `$cmd 2>&1`; alarm 0; }; $out =~ s/\s+$//; + utf8::decode($out); $@ ? "$out\n[timeout after ${t}s]\nexit: -1" : "$out\nexit: " . ($? >> 8); } sub last_assistant { for my $m (reverse @{$_[0]}) { return $m->{content} if $m->{role} eq 'assistant' && defined $m->{content} && length $m->{content}; } '' } @@ -96,7 +98,7 @@ sub list_sessions { map { [$_->{id}, scalar @{$_->{messages} // []}] } sessions( sub main { my ($c, $sp) = (cfg(), sp()); my $msgs = [{role=>'system', content=>$sp}]; - if (@ARGV) { open my $f, '<', $ARGV[0] or die "cannot open $ARGV[0]: $!"; # file mode + if (@ARGV) { open my $f, '<:encoding(UTF-8)', $ARGV[0] or die "cannot open $ARGV[0]: $!"; # file mode local $/; push @$msgs, {role=>'user', content=><$f>}; AL($c, $msgs, $sp); autosave($msgs); return; } print "MicroBantam ready ($c->{model}). Commands: /quit /clear /save /list /load /help\n"; diff --git a/system.txt b/system.txt index efd07d5..9b74190 100644 --- a/system.txt +++ b/system.txt @@ -2,7 +2,7 @@ You are Bantam, a tiny, powerful AI agent. Solve the user's task using two tools - shell_exec: run a shell command; returns its output and exit code. - run_subagent: delegate a sub-task to a child agent; returns its reply. -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. Delegate large or independent sub-tasks to run_subagent. Stop as soon as the goal is met and report concisely: results, not process. +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. Delegate large or independent sub-tasks to run_subagent. Stop as soon as the goal is met and report concisely: results, not process. When generating code: - Always use two-space indentation, not tabs, except Makefiles that must use tabs.