xonecas.io
64875
Mc

mini-coder / commit ed699fb

feat: initial benchmarks driven changes

xonecas2026-04-25 ed699fb93e4ac89acbcdaa4a499b480d008a97dc parent 262db76

7 files changed

benchmarks/local-harbor-agent.py+173−20
@@ -8,6 +8,9 @@ from pathlib import Path
88 from tempfile import TemporaryDirectory
99 from typing import Any
1010
11+
12+_FINAL_STOP_REASONS = frozenset({"stop", "error", "aborted"})
13+
1114 from harbor.agents.installed.base import BaseInstalledAgent, with_prompt_template
1215 from harbor.environments.base import BaseEnvironment
1316 from harbor.models.agent.context import AgentContext
@@ -20,12 +23,21 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
2023 _JSON_LOG_FILENAME = "mini-coder.json"
2124 _STDERR_LOG_FILENAME = "mini-coder.stderr.txt"
2225 _PACKAGE_PATHS = ("bin/mc.ts", "src")
23- _PACKAGE_MANIFEST_KEYS = ("name", "version", "type", "bin", "dependencies")
26+ _PACKAGE_MANIFEST_KEYS = (
27+ "name",
28+ "version",
29+ "type",
30+ "bin",
31+ "dependencies",
32+ "packageManager",
33+ )
2434
2535 def __init__(self, *args, version: str = "local", **kwargs):
2636 super().__init__(*args, version=version, **kwargs)
2737 self._host_repo_root = Path(__file__).resolve().parents[1]
28- self._host_auth_path = Path.home() / ".config" / "mini-coder" / "auth.json"
38+ host_config_dir = Path.home() / ".config" / "mini-coder"
39+ self._host_auth_path = host_config_dir / "auth.json"
40+ self._host_settings_path = host_config_dir / "settings.json"
2941
3042 @staticmethod
3143 def name() -> str:
@@ -74,12 +86,14 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
7486 self._merge_context_metadata(context, metadata)
7587 return
7688
77- if not isinstance(result, dict):
78- metadata["parse_error"] = "mini-coder JSON log was not an object"
89+ parsed_result = self._extract_result_from_json_log(result)
90+ metadata.update(parsed_result["metadata"])
91+ result_message = parsed_result.get("message")
92+ if not isinstance(result_message, dict):
7993 self._merge_context_metadata(context, metadata)
8094 return
8195
82- usage = result.get("usage")
96+ usage = result_message.get("usage")
8397 usage_data = usage if isinstance(usage, dict) else {}
8498
8599 context.n_input_tokens = self._optional_int(usage_data.get("input"))
@@ -102,7 +116,7 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
102116 ("stopReason", "stop_reason"),
103117 ("errorMessage", "error_message"),
104118 ):
105- value = result.get(source_key)
119+ value = result_message.get(source_key)
106120 if isinstance(value, str) and value:
107121 metadata[metadata_key] = value
108122
@@ -111,6 +125,55 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
111125
112126 self._merge_context_metadata(context, metadata)
113127
128+ @classmethod
129+ def _extract_result_from_json_log(
130+ cls, result: Any
131+ ) -> dict[str, dict[str, Any] | dict[str, Any] | None]:
132+ if isinstance(result, dict):
133+ return {"message": result, "metadata": {"json_log_shape": "object"}}
134+
135+ if not isinstance(result, list):
136+ return {
137+ "message": None,
138+ "metadata": {
139+ "json_log_shape": type(result).__name__,
140+ "parse_error": "mini-coder JSON log was neither an object nor an array",
141+ },
142+ }
143+
144+ assistant_messages = [
145+ item
146+ for item in result
147+ if isinstance(item, dict) and item.get("role") == "assistant"
148+ ]
149+ if not assistant_messages:
150+ return {
151+ "message": None,
152+ "metadata": {
153+ "json_log_shape": "array",
154+ "event_count": len(result),
155+ "assistant_message_count": 0,
156+ "parse_error": "mini-coder JSON log array had no assistant messages",
157+ },
158+ }
159+
160+ final_message = next(
161+ (
162+ item
163+ for item in reversed(assistant_messages)
164+ if item.get("stopReason") in _FINAL_STOP_REASONS
165+ ),
166+ assistant_messages[-1],
167+ )
168+ return {
169+ "message": final_message,
170+ "metadata": {
171+ "json_log_shape": "array",
172+ "event_count": len(result),
173+ "assistant_message_count": len(assistant_messages),
174+ },
175+ }
176+
114177 @staticmethod
115178 def _optional_int(value: Any) -> int | None:
116179 if isinstance(value, bool):
@@ -246,6 +309,24 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
246309
247310 return package_manifest
248311
312+ @staticmethod
313+ def _pinned_bun_version(package_manager: Any) -> str | None:
314+ if not isinstance(package_manager, str):
315+ return None
316+ tool_name, _, version = package_manager.partition("@")
317+ if tool_name != "bun" or not version:
318+ return None
319+ if any(not part.isdigit() for part in version.split(".")):
320+ return None
321+ return version
322+
323+ def _expected_bun_version(self) -> str | None:
324+ manifest_path = self._host_repo_root / "package.json"
325+ source_manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
326+ if not isinstance(source_manifest, dict):
327+ return None
328+ return self._pinned_bun_version(source_manifest.get("packageManager"))
329+
249330 async def _install_system_dependencies(self, environment: BaseEnvironment) -> None:
250331 await self.exec_as_root(
251332 environment,
@@ -262,11 +343,35 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
262343 )
263344
264345 async def _install_bun(self, environment: BaseEnvironment) -> None:
346+ expected_version = self._expected_bun_version()
347+ install_command = "curl -fsSL https://bun.sh/install | bash"
348+ if expected_version is not None:
349+ install_command = (
350+ f"curl -fsSL https://bun.sh/install | bash -s -- bun-v{expected_version}"
351+ )
352+ await self.exec_as_agent(
353+ environment,
354+ command=(
355+ f"expected_version={shlex.quote(expected_version)}; "
356+ "current_version=''; "
357+ "if command -v bun >/dev/null 2>&1; then "
358+ "current_version=$(bun --version 2>/dev/null || true); "
359+ "fi; "
360+ "if [ -z \"$current_version\" ] || [ \"$current_version\" != \"$expected_version\" ]; then "
361+ f"{install_command}; "
362+ "fi; "
363+ "export PATH=\"$HOME/.bun/bin:$PATH\"; "
364+ "test -x \"$(command -v bun)\" && "
365+ "[ \"$(bun --version)\" = \"$expected_version\" ]"
366+ ),
367+ )
368+ return
369+
265370 await self.exec_as_agent(
266371 environment,
267372 command=(
268373 "if ! command -v bun >/dev/null 2>&1; then "
269- "curl -fsSL https://bun.sh/install | bash; fi; "
374+ f"{install_command}; fi; "
270375 "export PATH=\"$HOME/.bun/bin:$PATH\"; "
271376 "test -x \"$(command -v bun)\""
272377 ),
@@ -284,32 +389,76 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
284389 ),
285390 )
286391
287- async def _container_config_dir(self, environment: BaseEnvironment) -> str:
392+ async def _container_home(self, environment: BaseEnvironment) -> str:
288393 result = await self.exec_as_agent(environment, command='printf %s "$HOME"')
289394 home_dir = (result.stdout or "").strip()
290395 if not home_dir:
291396 raise RuntimeError("Failed to determine the agent home directory")
397+ return home_dir
292398
399+ async def _container_config_dir(self, environment: BaseEnvironment, home_dir: str) -> str:
293400 config_dir = f"{home_dir}/.config/mini-coder"
294401 await self.exec_as_agent(
295- environment, command=f"mkdir -p {shlex.quote(config_dir)}"
402+ environment,
403+ command=(
404+ f"export HOME={shlex.quote(home_dir)}; "
405+ f"mkdir -p {shlex.quote(config_dir)}"
406+ ),
296407 )
297408 return config_dir
298409
299- async def _upload_host_auth(
300- self, environment: BaseEnvironment, config_dir: str
410+ async def _upload_host_config_file(
411+ self,
412+ environment: BaseEnvironment,
413+ host_path: Path,
414+ container_tmp_path: str,
415+ target_path: str,
416+ *,
417+ required: bool,
301418 ) -> None:
302- tmp_auth_path = "/tmp/mini-coder-auth.json"
303- auth_target = f"{config_dir}/auth.json"
304- await environment.upload_file(self._host_auth_path, tmp_auth_path)
305- await self.exec_as_root(environment, command=f"chmod 644 {tmp_auth_path}")
419+ if not host_path.is_file():
420+ if required:
421+ raise FileNotFoundError(
422+ f"Missing mini-coder config file required for Harbor: {host_path}"
423+ )
424+ return
425+
426+ await environment.upload_file(host_path, container_tmp_path)
427+ await self.exec_as_root(
428+ environment, command=f"chmod 644 {shlex.quote(container_tmp_path)}"
429+ )
306430 await self.exec_as_agent(
307431 environment,
308432 command=(
309- f"cp {shlex.quote(tmp_auth_path)} {shlex.quote(auth_target)} && "
310- f"chmod 600 {shlex.quote(auth_target)}"
433+ f"cp {shlex.quote(container_tmp_path)} {shlex.quote(target_path)} && "
434+ f"chmod 600 {shlex.quote(target_path)}"
311435 ),
312436 )
437+ await self.exec_as_root(
438+ environment, command=f"rm -f {shlex.quote(container_tmp_path)}"
439+ )
440+
441+ async def _upload_host_auth(
442+ self, environment: BaseEnvironment, config_dir: str
443+ ) -> None:
444+ await self._upload_host_config_file(
445+ environment,
446+ self._host_auth_path,
447+ "/tmp/mini-coder-auth.json",
448+ f"{config_dir}/auth.json",
449+ required=True,
450+ )
451+
452+ async def _upload_host_settings(
453+ self, environment: BaseEnvironment, config_dir: str
454+ ) -> None:
455+ await self._upload_host_config_file(
456+ environment,
457+ self._host_settings_path,
458+ "/tmp/mini-coder-settings.json",
459+ f"{config_dir}/settings.json",
460+ required=False,
461+ )
313462
314463 @with_prompt_template
315464 async def run(
@@ -320,8 +469,10 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
320469 ) -> None:
321470 del context
322471 self._require_host_auth()
323- config_dir = await self._container_config_dir(environment)
472+ home_dir = await self._container_home(environment)
473+ config_dir = await self._container_config_dir(environment, home_dir)
324474 await self._upload_host_auth(environment, config_dir)
475+ await self._upload_host_settings(environment, config_dir)
325476
326477 stdout_path = (
327478 EnvironmentPaths.agent_dir / self._JSON_LOG_FILENAME
@@ -329,11 +480,13 @@ class LocalMiniCoderAgent(BaseInstalledAgent):
329480 stderr_path = (
330481 EnvironmentPaths.agent_dir / self._STDERR_LOG_FILENAME
331482 ).as_posix()
483+ mc_path = f"{home_dir}/.bun/bin/mc"
332484 await self.exec_as_agent(
333485 environment,
334486 command=(
335- "export PATH=\"$HOME/.bun/bin:$PATH\"; "
336- f"mc --json -p {shlex.quote(instruction)} </dev/null "
487+ f"export HOME={shlex.quote(home_dir)}; "
488+ f"export PATH={shlex.quote(f'{home_dir}/.bun/bin')}:$PATH; "
489+ f"{shlex.quote(mc_path)} --json -p {shlex.quote(instruction)} </dev/null "
337490 f">{shlex.quote(stdout_path)} "
338491 f"2>{shlex.quote(stderr_path)}"
339492 ),
bun.lock+10−10
@@ -96,23 +96,23 @@
9696
9797 "@babel/runtime": ["@babel/runtime@7.29.2", "", {}, "sha512-JiDShH45zKHWyGe4ZNVRrCjBz8Nh9TMmZG1kh4QTK8hCBTWBi8Da+i7s1fJw7/lYpM4ccepSNfqzZ/QvABBi5g=="],
9898
99- "@biomejs/biome": ["@biomejs/biome@2.4.12", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.4.12", "@biomejs/cli-darwin-x64": "2.4.12", "@biomejs/cli-linux-arm64": "2.4.12", "@biomejs/cli-linux-arm64-musl": "2.4.12", "@biomejs/cli-linux-x64": "2.4.12", "@biomejs/cli-linux-x64-musl": "2.4.12", "@biomejs/cli-win32-arm64": "2.4.12", "@biomejs/cli-win32-x64": "2.4.12" }, "bin": { "biome": "bin/biome" } }, "sha512-Rro7adQl3NLq/zJCIL98eElXKI8eEiBtoeu5TbXF/U3qbjuSc7Jb5rjUbeHHcquDWeS …
99+ "@biomejs/biome": ["@biomejs/biome@2.4.13", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.4.13", "@biomejs/cli-darwin-x64": "2.4.13", "@biomejs/cli-linux-arm64": "2.4.13", "@biomejs/cli-linux-arm64-musl": "2.4.13", "@biomejs/cli-linux-x64": "2.4.13", "@biomejs/cli-linux-x64-musl": "2.4.13", "@biomejs/cli-win32-arm64": "2.4.13", "@biomejs/cli-win32-x64": "2.4.13" }, "bin": { "biome": "bin/biome" } }, "sha512-gLXOwkOBBg0tr7bDsqlkIh4uFeKuMjxvqsrb1Tukww1iDmHcfr4Uu8MoQxp0Rcte+69 …
100100
101- "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.4.12", "", { "os": "darwin", "cpu": "arm64" }, "sha512-BnMU4Pc3ciEVteVpZ0BK33MLr7X57F5w1dwDLDn+/iy/yTrA4Q/N2yftidFtsA4vrDh0FMXDpacNV/Tl3fbmng=="],
101+ "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.4.13", "", { "os": "darwin", "cpu": "arm64" }, "sha512-2KImO1jhNFBa2oWConyr0x6flxbQpGKv6902uGXpYM62Xyem8U80j441SyUJ8KyngsmKbQjeIv1q2CQfDkNnYg=="],
102102
103- "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.4.12", "", { "os": "darwin", "cpu": "x64" }, "sha512-x9uJ0bI1rJsWICp3VH8w/5PnAVD3A7SqzDpbrfoUQX1QyWrK5jSU4fRLo/wSgGeplCivbxBRKmt5Xq4/nWvq8A=="],
103+ "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.4.13", "", { "os": "darwin", "cpu": "x64" }, "sha512-BKrJklbaFN4p1Ts4kPBczo+PkbsHQg57kmJ+vON9u2t6uN5okYHaSr7h/MutPCWQgg2lglaWoSmm+zhYW+oOkg=="],
104104
105- "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.4.12", "", { "os": "linux", "cpu": "arm64" }, "sha512-tOwuCuZZtKi1jVzbk/5nXmIsziOB6yqN8c9r9QM0EJYPU6DpQWf11uBOSCfFKKM4H3d9ZoarvlgMfbcuD051Pw=="],
105+ "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.4.13", "", { "os": "linux", "cpu": "arm64" }, "sha512-NzkUDSqfvMBrPplKgVr3aXLHZ2NEELvvF4vZxXulEylKWIGqlvNEcwUcj9OLrn75TD3lJ/GIqCVlBwd1MZCuYQ=="],
106106
107- "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.4.12", "", { "os": "linux", "cpu": "arm64" }, "sha512-FhfpkAAlKL6kwvcVap0Hgp4AhZmtd3YImg0kK1jd7C/aSoh4SfsB2f++yG1rU0lr8Y5MCFJrcSkmssiL9Xnnig=="],
107+ "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.4.13", "", { "os": "linux", "cpu": "arm64" }, "sha512-U5MsuBQW25dXaYtqWWSPM3P96H6Y+fHuja3TQpMNnylocHW0tEbtFTDlUj6oM+YJLntvEkQy4grBvQNUD4+RCg=="],
108108
109- "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.4.12", "", { "os": "linux", "cpu": "x64" }, "sha512-8pFeAnLU9QdW9jCIslB/v82bI0lhBmz2ZAKc8pVMFPO0t0wAHsoEkrUQUbMkIorTRIjbqyNZHA3lEXavsPWYSw=="],
109+ "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.4.13", "", { "os": "linux", "cpu": "x64" }, "sha512-Az3ZZedYRBo9EQzNnD9SxFcR1G5QsGo6VEc2hIyVPZ1rdKwee/7E9oeBBZFpE8Z44ekxsDQBqbiWGW5ShOhUSQ=="],
110110
111- "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.4.12", "", { "os": "linux", "cpu": "x64" }, "sha512-dwTIgZrGutzhkQCuvHynCkyW6hJxUuyZqKKO0YNfaS2GUoRO+tOvxXZqZB6SkWAOdfZTzwaw8IEdUnIkHKHoew=="],
111+ "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.4.13", "", { "os": "linux", "cpu": "x64" }, "sha512-Z601MienRgTBDza/+u2CH3RSrWoXo9rtr8NK6A4KJzqGgfxx+H3VlyLgTJ4sRo40T3pIsqpTmiOQEvYzQvBRvQ=="],
112112
113- "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.4.12", "", { "os": "win32", "cpu": "arm64" }, "sha512-B0DLnx0vA9ya/3v7XyCaP+/lCpnbWbMOfUFFve+xb5OxyYvdHaS55YsSddr228Y+JAFk58agCuZTsqNiw2a6ig=="],
113+ "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.4.13", "", { "os": "win32", "cpu": "arm64" }, "sha512-Px9PS2B5/Q183bUwy/5VHqp3J2lzdOCeVGzMpphYfl8oSa7VDCqenBdqWpy6DCy/en4Rbf/Y1RieZF6dJPcc9A=="],
114114
115- "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.4.12", "", { "os": "win32", "cpu": "x64" }, "sha512-yMckRzTyZ83hkk8iDFWswqSdU8tvZxspJKnYNh7JZr/zhZNOlzH13k4ecboU6MurKExCe2HUkH75pGI/O2JwGA=="],
115+ "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.4.13", "", { "os": "win32", "cpu": "x64" }, "sha512-tTcMkXyBrmHi9BfrD2VNHs/5rYIUKETqsBlYOvSAABwBkJhSDVb5e7wPukftsQbO3WzQkXe6kaztC6WtUOXSoQ=="],
116116
117117 "@cel-tui/clew": ["@cel-tui/clew@0.8.1", "", { "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-4X021mpOQYSPR2HzmSMoxSX3wn6zoGpCgUPePdJPTy/IQe0N0vRLooDVZr74uVaUt8UxHLYUrH4WN7DuJq/YqA=="],
118118
@@ -124,7 +124,7 @@
124124
125125 "@google/genai": ["@google/genai@1.50.1", "", { "dependencies": { "google-auth-library": "^10.3.0", "p-retry": "^4.6.2", "protobufjs": "^7.5.4", "ws": "^8.18.0" }, "peerDependencies": { "@modelcontextprotocol/sdk": "^1.25.2" }, "optionalPeers": ["@modelcontextprotocol/sdk"] }, "sha512-YbkX7H9+1Pt8wOt7DDREy8XSoiL6fRDzZQRyaVBarFf8MR3zHGqVdvM4cLbDXqPhxqvegZShgfxb8kw9C7YhAQ=="],
126126
127- "@mariozechner/pi-ai": ["@mariozechner/pi-ai@0.70.0", "", { "dependencies": { "@anthropic-ai/sdk": "^0.90.0", "@aws-sdk/client-bedrock-runtime": "^3.1030.0", "@google/genai": "^1.40.0", "@mistralai/mistralai": "^2.2.0", "chalk": "^5.6.2", "openai": "6.26.0", "partial-json": "^0.1.7", "proxy-agent": "^6.5.0", "typebox": "^1.1.24", "undici": "^7.19.1", "zod-to-json-schema": "^3.24.6" }, "bin": { "pi-ai": "dist/cli.js" } }, "sha512-lVT9bb0eFkNr5YXvZ5r00TNA5r110fOO8uJV9VLCQ5GdtunWIjcptWitzIjjl2M …
127+ "@mariozechner/pi-ai": ["@mariozechner/pi-ai@0.70.2", "", { "dependencies": { "@anthropic-ai/sdk": "^0.90.0", "@aws-sdk/client-bedrock-runtime": "^3.1030.0", "@google/genai": "^1.40.0", "@mistralai/mistralai": "^2.2.0", "chalk": "^5.6.2", "openai": "6.26.0", "partial-json": "^0.1.7", "proxy-agent": "^6.5.0", "typebox": "^1.1.24", "undici": "^7.19.1", "zod-to-json-schema": "^3.24.6" }, "bin": { "pi-ai": "dist/cli.js" } }, "sha512-+30LRPjXsXF+oI96DvGWMbdPGeqoLJvadh6UPev7wx2DzhC9FEqXkQcoMZ0usbC …
128128
129129 "@mistralai/mistralai": ["@mistralai/mistralai@2.2.0", "", { "dependencies": { "ws": "^8.18.0", "zod": "^3.25.0 || ^4.0.0", "zod-to-json-schema": "^3.25.0" } }, "sha512-JQUGIXjFWnw/J9LpTSf/ZXwVW3Sh8FBAcfTo5QvAHqkl4CfSiIwnjRJhMoAFcP6ncCe84YPU1ncDGX+p3OXnfg=="],
130130
package.json+2−2
@@ -14,7 +14,7 @@
1414 "format": "bun run prettier --write *.md && bun run biome format --write . && bun run biome check --write ."
1515 },
1616 "devDependencies": {
17- "@biomejs/biome": "^2.4.12",
17+ "@biomejs/biome": "^2.4.13",
1818 "@types/bun": "^1.3.13",
1919 "prettier": "^3.8.3",
2020 "typescript": "^6.0.3"
@@ -22,7 +22,7 @@
2222 "dependencies": {
2323 "@cel-tui/components": "^0.8.1",
2424 "@cel-tui/core": "^0.8.1",
25- "@mariozechner/pi-ai": "^0.70.0",
25+ "@mariozechner/pi-ai": "^0.70.2",
2626 "diff": "^9.0.0",
2727 "yaml": "^2.8.3"
2828 }
src/agent.ts+10−6
@@ -13,28 +13,31 @@ import {
1313 import { parseSkillFrontmatter } from "./shared";
1414 import type { CliOptions, ToolAndRunner } from "./types";
1515
16+// TODO: Add environment information section (including git status)
1617 const IDENTITY_PROMPT = `# You are "mini-coder", an elite coding agent.
1718
1819 Behaviour guidelines:
1920
21+- Summaries must match the diff.
22+- Do not overstate what changed or what was verified.
23+- Do not over-scope your work, focus on the requirements to answer only.
24+- Once you've gathered enough information to complete the request, stop exploring and complete it.
25+- Be defensive with existing changes and destructive commands, they could harm your user's changes.
2026 - Tone: use a jovial but motivated colleague persona. Be less verbose and more concise. You are working with software engineers, act appropriately, no fluff, only direct talk.`;
2127
2228 export const MAIN_PROMPT = `${IDENTITY_PROMPT}
2329 - Answer all user questions without guessing, or assuming.
2430 - Use recent online information, the current environment, and your training data combined for a complete answer.
25-- Once you've gathered enough information to complete the request, stop exploring and complete it.
26-- Use the \`task()\` tool to complete your work. Define a plan with the user, break it down into tasks, and use the tool.
27-- Be careful with overlapping work when using \`task()\` in parallel.
28-- Be careful with existing changes and destructive commands, they could harm your user's changes.
31+- **Use the \`task()\` tool to do most your work**. Define a plan with the user, break it down into tasks, and use the tool.
32+- If a task requires more than 1 or 2 other tool calls, or follow up calls, **always** use the \`task()\` tool instead.
2933 `;
3034
3135 export const TASK_PROMPT = `${IDENTITY_PROMPT}
3236 - Use recent online information, the current environment, and your training data combined for a complete answer.
33-- Once you've gathered enough information to complete the request, stop exploring and complete the task.
3437 - When completing a task, ensure that you fulfill the contract **exactly**.
3538 - Always verify your changes using compilation, testing, and manual verification when possible.
3639 - Use temp directory for temp files, scripts or anything that doesn't match the requested output.
37-- Be careful with existing changes and destructive commands, they could harm your user's changes.
40+- Your final message should include a summary of your actions and any diffs from your edits.
3841 `;
3942
4043 // `AGENTS.md` support: find it in current folder (./AGENTS.md) and a global one. (`.agents/AGENTS.md`)
@@ -195,6 +198,7 @@ export async function streamAgent(
195198 // TODO: Investigate why we get an error: `No output for tool call id XXXX...` when
196199 // we add { apiKey } in this call. And how does it work without it?
197200 const cont = await completeSimple(options.model, context, {
201+ apiKey,
198202 reasoning: options.effort,
199203 signal: controller.signal,
200204 });
src/headless.ts+5−2
@@ -1,8 +1,9 @@
11 import type { Message } from "@mariozechner/pi-ai";
2-import { streamAgent, TASK_PROMPT } from "./agent";
2+import { MAIN_PROMPT, streamAgent } from "./agent";
33 import { getApiKey } from "./oauth";
44 import { bash, runBashTool } from "./tool-bash";
55 import { edit, runEditTool } from "./tool-edit";
6+import { runTaskTool, task } from "./tool-task";
67 import type { CliOptions, ToolAndRunner } from "./types";
78
89 export async function streamHeadless(
@@ -14,6 +15,7 @@ export async function streamHeadless(
1415 const tools: ToolAndRunner[] = [
1516 { tool: bash, runner: runBashTool },
1617 { tool: edit, runner: runEditTool },
18+ { tool: task, runner: (args) => runTaskTool(options, args) },
1719 ];
1820 const messages: Message[] = [
1921 { role: "user", content: options.prompt || "", timestamp: Date.now() },
@@ -30,7 +32,7 @@ export async function streamHeadless(
3032 await streamAgent(
3133 apiKey,
3234 tools,
33- TASK_PROMPT,
35+ MAIN_PROMPT,
3436 messages,
3537 options,
3638 undefined,
@@ -43,6 +45,7 @@ export async function streamHeadless(
4345 log("> Thinking...");
4446 break;
4547 case "toolcall_end":
48+ // TODO: other tools output
4649 log(`> ${ev.toolCall.name}: ${ev.toolCall.arguments.command}`);
4750 break;
4851 case "error":
src/tool-task.ts+9−3
@@ -16,12 +16,16 @@ const description = `## Task tool
1616 Best practices using this tool:
1717
1818 - Use detailed prompts, be specific about the expected output and guardrails.
19-- Task tool doesn't know your context, make sure include all relevant details.
19+- Task tool doesn't know your context, make sure you include all relevant details.
2020 - Break your work down into small tasks, one small job for each task call.
21-- Always prefer using this tool before any other specific tool.
2221 - Use this tool to explore directories, codebases and the web.
2322 - Use this tool to perform edits, run verifications, and review changes.
24-- When describing edits, include detailed descriptions and validation requirements.`;
23+- When describing edits, include detailed descriptions and validation requirements.
24+- Always use it whenever more than one follow-up step is likely.
25+- Always include all context, scope, constraints, and expected output.
26+- Be careful with overlapping work when using \`task()\` in parallel.
27+- Trust but verify the the task's output.
28+`;
2529
2630 export const task: Tool = {
2731 name: "task",
@@ -79,5 +83,7 @@ export async function runTaskTool(
7983 onComplete,
8084 );
8185
86+ // TODO: Structured footer for output and edit diffs.
87+
8288 return output.trim();
8389 }
src/tui.ts+8−5
@@ -4,6 +4,8 @@ import type { Message } from "@mariozechner/pi-ai";
44 import { MAIN_PROMPT, streamAgent } from "./agent";
55 import { getApiKey } from "./oauth";
66 import { estimateTokens, secureRandomString } from "./shared";
7+import { bash, runBashTool } from "./tool-bash";
8+import { edit, runEditTool } from "./tool-edit";
79 import { runTaskTool, task } from "./tool-task";
810 import { ActivityPill, Spinner, TextPill, theme } from "./tui-components";
911 import { Conversation } from "./tui-conversation";
@@ -120,13 +122,14 @@ export async function streamTUI(state: TUIState) {
120122 const abortController = new AbortController();
121123 state.abortController = abortController;
122124
123- const lastTs = Date.now();
124125 const apiKey = await getApiKey(state.options);
125126 const tools: ToolAndRunner[] = [
127+ { tool: bash, runner: runBashTool },
128+ { tool: edit, runner: runEditTool },
126129 {
127130 tool: task,
128131 runner: async (args: Record<string, any>) => {
129- return runTaskTool({...state.options, abortController}, args);
132+ return runTaskTool({ ...state.options, abortController }, args);
130133 },
131134 },
132135 ];
@@ -244,14 +247,14 @@ export async function streamTUI(state: TUIState) {
244247 },
245248
246249 (msg, context) => {
247- const dur = Date.now() - lastTs;
250+ const dur = Date.now() - msg.timestamp;
248251
249252 if (msg.errorMessage) {
250253 state.messages.push({
251254 id: secureRandomString(8),
252255 role: "agent",
253256 content: `Error (${msg.stopReason}): ${msg.errorMessage}`,
254- timestamp: Date.now(),
257+ timestamp: msg.timestamp,
255258 durationMs: dur,
256259 });
257260 } else {
@@ -263,7 +266,7 @@ export async function streamTUI(state: TUIState) {
263266 id: secureRandomString(8),
264267 role: "agent",
265268 content: text,
266- timestamp: Date.now(),
269+ timestamp: msg.timestamp,
267270 durationMs: dur,
268271 });
269272 }