From 958c23fb0120d4e24e803e60839f2063d1ddf93e Mon Sep 17 00:00:00 2001 From: VITOHJL Date: Thu, 5 Mar 2026 23:45:20 +0800 Subject: [PATCH 1/2] chore: refine platform policy and memory SKILL docs --- nanobot/agent/context.py | 28 ++++++++++++++++++++++++++++ nanobot/skills/memory/SKILL.md | 15 ++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/nanobot/agent/context.py b/nanobot/agent/context.py index df4825f..9254a7f 100644 --- a/nanobot/agent/context.py +++ b/nanobot/agent/context.py @@ -58,6 +58,32 @@ Skills with available="false" need dependencies installed first - you can try in system = platform.system() runtime = f"{'macOS' if system == 'Darwin' else system} {platform.machine()}, Python {platform.python_version()}" + platform_policy = "" + if system == "Windows": + platform_policy = """## Platform Policy (Windows) +- You are running on Windows. Shell commands executed via the `exec` tool run under the default Windows shell (PowerShell or cmd.exe) unless you explicitly invoke another shell. +- Prefer UTF-8 for file I/O and command output. If terminal output is garbled/mojibake, retry with: + - PowerShell: `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ` + - cmd.exe: `chcp 65001 >NUL & ` +- Do NOT assume GNU tools like `grep`, `sed`, `awk` exist. Prefer Windows built-ins: + - Search text: `findstr /i "keyword" path\\to\\file` + - List files: `dir` + - Show file: `type path\\to\\file` +- When in doubt, prefer the file tools (`read_file`, `list_dir`) over shell for portability and reliability. +""" + elif system == "Darwin": + platform_policy = """## Platform Policy (macOS) +- You are running on macOS. Prefer POSIX tools and UTF-8. +- Use forward-slash paths. Prefer `ls`, `cat`, `grep`, `find` for filesystem and text operations. +- When in doubt, prefer the file tools (`read_file`, `list_dir`) over shell for portability and reproducibility. +""" + else: + platform_policy = """## Platform Policy (Linux) +- You are running on Linux. Prefer POSIX tools and UTF-8. +- Use forward-slash paths. Prefer `ls`, `cat`, `grep`, `find` for filesystem and text operations. +- When in doubt, prefer the file tools (`read_file`, `list_dir`) over shell for portability and reproducibility. +""" + return f"""# nanobot 🐈 You are nanobot, a helpful AI assistant. @@ -71,6 +97,8 @@ Your workspace is at: {workspace_path} - History log: {workspace_path}/memory/HISTORY.md (grep-searchable). Each entry starts with [YYYY-MM-DD HH:MM]. - Custom skills: {workspace_path}/skills/{{skill-name}}/SKILL.md +{platform_policy} + ## nanobot Guidelines - State intent before tool calls, but NEVER predict or claim results before receiving them. - Before modifying a file, read it first. Do not assume files or directories exist. diff --git a/nanobot/skills/memory/SKILL.md b/nanobot/skills/memory/SKILL.md index 529a02d..865f11f 100644 --- a/nanobot/skills/memory/SKILL.md +++ b/nanobot/skills/memory/SKILL.md @@ -9,15 +9,20 @@ always: true ## Structure - `memory/MEMORY.md` — Long-term facts (preferences, project context, relationships). Always loaded into your context. -- `memory/HISTORY.md` — Append-only event log. NOT loaded into context. Search it with grep. Each entry starts with [YYYY-MM-DD HH:MM]. +- `memory/HISTORY.md` — Append-only event log. NOT loaded into context. Search it with grep-style tools or in-memory filters. Each entry starts with [YYYY-MM-DD HH:MM]. ## Search Past Events -```bash -grep -i "keyword" memory/HISTORY.md -``` +**Recommended approach (cross-platform):** +- Use `read_file` to read `memory/HISTORY.md`, then search in-memory +- This is the most reliable and portable method on all platforms -Use the `exec` tool to run grep. Combine patterns: `grep -iE "meeting|deadline" memory/HISTORY.md` +**Alternative (if you need command-line search):** +- **Linux/macOS:** `grep -i "keyword" memory/HISTORY.md` +- **Windows:** `findstr /i "keyword" memory\HISTORY.md` +- **Python (cross-platform):** `python -c "import re; content=open('memory/HISTORY.md', encoding='utf-8').read(); print('\n'.join([l for l in content.split('\n') if 'keyword' in l.lower()][-20:]))"` + +Use the `exec` tool to run these commands. For complex searches, prefer `read_file` + in-memory filtering. ## When to Update MEMORY.md From 4715321319f7282ffe9df99be59898a9782a2440 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Sun, 8 Mar 2026 16:39:37 +0000 Subject: [PATCH 2/2] Merge branch 'main' into pr-1579 and tighten platform guidance --- nanobot/agent/context.py | 25 ++++++------------------- nanobot/skills/memory/SKILL.md | 13 +++++++------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/nanobot/agent/context.py b/nanobot/agent/context.py index 3dced80..2c648eb 100644 --- a/nanobot/agent/context.py +++ b/nanobot/agent/context.py @@ -62,27 +62,14 @@ Skills with available="false" need dependencies installed first - you can try in platform_policy = "" if system == "Windows": platform_policy = """## Platform Policy (Windows) -- You are running on Windows. Shell commands executed via the `exec` tool run under the default Windows shell (PowerShell or cmd.exe) unless you explicitly invoke another shell. -- Prefer UTF-8 for file I/O and command output. If terminal output is garbled/mojibake, retry with: - - PowerShell: `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; ` - - cmd.exe: `chcp 65001 >NUL & ` -- Do NOT assume GNU tools like `grep`, `sed`, `awk` exist. Prefer Windows built-ins: - - Search text: `findstr /i "keyword" path\\to\\file` - - List files: `dir` - - Show file: `type path\\to\\file` -- When in doubt, prefer the file tools (`read_file`, `list_dir`) over shell for portability and reliability. -""" - elif system == "Darwin": - platform_policy = """## Platform Policy (macOS) -- You are running on macOS. Prefer POSIX tools and UTF-8. -- Use forward-slash paths. Prefer `ls`, `cat`, `grep`, `find` for filesystem and text operations. -- When in doubt, prefer the file tools (`read_file`, `list_dir`) over shell for portability and reproducibility. +- You are running on Windows. Do not assume GNU tools like `grep`, `sed`, or `awk` exist. +- Prefer Windows-native commands or file tools when they are more reliable. +- If terminal output is garbled, retry with UTF-8 output enabled. """ else: - platform_policy = """## Platform Policy (Linux) -- You are running on Linux. Prefer POSIX tools and UTF-8. -- Use forward-slash paths. Prefer `ls`, `cat`, `grep`, `find` for filesystem and text operations. -- When in doubt, prefer the file tools (`read_file`, `list_dir`) over shell for portability and reproducibility. + platform_policy = """## Platform Policy (POSIX) +- You are running on a POSIX system. Prefer UTF-8 and standard shell tools. +- Use file tools when they are simpler or more reliable than shell commands. """ return f"""# nanobot 🐈 diff --git a/nanobot/skills/memory/SKILL.md b/nanobot/skills/memory/SKILL.md index 865f11f..3f0a8fc 100644 --- a/nanobot/skills/memory/SKILL.md +++ b/nanobot/skills/memory/SKILL.md @@ -13,16 +13,17 @@ always: true ## Search Past Events -**Recommended approach (cross-platform):** -- Use `read_file` to read `memory/HISTORY.md`, then search in-memory -- This is the most reliable and portable method on all platforms +Choose the search method based on file size: -**Alternative (if you need command-line search):** +- Small `memory/HISTORY.md`: use `read_file`, then search in-memory +- Large or long-lived `memory/HISTORY.md`: use the `exec` tool for targeted search + +Examples: - **Linux/macOS:** `grep -i "keyword" memory/HISTORY.md` - **Windows:** `findstr /i "keyword" memory\HISTORY.md` -- **Python (cross-platform):** `python -c "import re; content=open('memory/HISTORY.md', encoding='utf-8').read(); print('\n'.join([l for l in content.split('\n') if 'keyword' in l.lower()][-20:]))"` +- **Cross-platform Python:** `python -c "from pathlib import Path; text = Path('memory/HISTORY.md').read_text(encoding='utf-8'); print('\n'.join([l for l in text.splitlines() if 'keyword' in l.lower()][-20:]))"` -Use the `exec` tool to run these commands. For complex searches, prefer `read_file` + in-memory filtering. +Prefer targeted command-line search for large history files. ## When to Update MEMORY.md