Repository navigation
agent.prompt: read AGENTS.md from project root; pasclaw init + /init - #298
Conversation
Adopts the opencode / Codex / Cursor / Zed AI / Claude Code
cross-tool convention: AGENTS.md at the project root carries
authoritative per-project agent rules. PasClaw now does both
ends -- it reads any AGENTS.md the session happens to be sitting
in, and it can generate a starter one for a fresh repo.
Reader side (PasClaw.Agent.Prompt):
* FindProjectAgentsMd(StartDir) walks from cwd up to the
first .git boundary (file or dir) and returns the AGENTS.md
path. Stops at the git root so a nested repo doesn't inherit
a parent monorepo's rules.
* BuildProjectRulesSection reads the file (cap 64 KB; tail-
truncates oversized bodies with an elision notice) and
emits a "## Project Rules (AGENTS.md)" section between
Memory and Skills. Empty / missing / malformed files are
silently skipped, MEMORY.md style.
Writer side (PasClaw.Cmd.Init, `pasclaw init`):
* Walks the file tree (depth 3, 400-entry cap, skipping
node_modules / target / .git / etc.) and reads first 4 KB
of well-known config files (README, package.json,
Cargo.toml, Makefile, ...).
* Packages it as a digest (capped at 48 KB) and asks the
configured provider with ONE Chat() call -- no tool loop,
no execute_code, no fs_write tool. Only thing that touches
disk is the final AGENTS.md write.
* Refuses to clobber an existing AGENTS.md unless --force.
* Strips a leading ```markdown ... ``` fence if the model
wraps its output in one (UnfenceMarkdown).
* Distinct from `pasclaw runbook` (already shipped) which is
the model-driven, tool-using deeper variant. Docs cross-
reference both shapes.
TUI:
* New `/init [flags]` slash command in the FPC line-based
REPL delegates straight to Cmd_Init_Run so the slash is
byte-for-byte equivalent to `pasclaw init` on the CLI.
Tests (src/tests/agents_md_tests.pas, new test-agents-md
target wired into `make test`):
* FindProjectAgentsMd absent / in-cwd / walks-to-git-root /
stops-at-git-root (regression for the bug surfaced during
development where the walk crossed the .git boundary).
* BuildProjectRulesSection absent / present / oversize (tail
truncated with notice, total bounded).
* UnfenceMarkdown bare / wrapped.
* Cmd.Init digest shape (lists tree, quotes README, includes
subdir).
Docs:
* docs/commands.md gets an init section + cross-link to
runbook (and vice versa).
* docs/getting-started.md gets a "Project rules: AGENTS.md"
block in the workflow before "Next steps".
Trivial Makefile conflict in the .PHONY list and the aggregate `test:` target -- main added test-tool-choice + test-responses-tool-choice from PR #297 (jaen's tool_choice work); this branch added test-agents-md. Both sets kept. No code conflicts; binary + test-agents-md still build clean.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2fb4a93ab8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SetLength(Result, N); | ||
| Move(Buf[0], Result[1], N); |
There was a problem hiding this comment.
Decode key-file snippets as UTF-8
When pasclaw init is built with Delphi, string is UTF-16, so copying raw bytes from README/package files directly into Result[1] produces garbled/NUL-padded text in the digest sent to the model. In that environment the model loses the key-file contents it needs to infer build/test commands; use the existing ReadFileText/TEncoding.UTF8.GetString path before applying the snippet cap.
Useful? React with 👍 / 👎.
| FS := TFileStream.Create(Target, fmCreate); | ||
| try | ||
| if Body <> '' then | ||
| FS.WriteBuffer(Body[1], Length(Body)); |
There was a problem hiding this comment.
Write AGENTS.md as encoded bytes
In Delphi builds Body[1] is a WideChar and Length(Body) is a character count, but WriteBuffer expects a byte count. This means every generated AGENTS.md from pasclaw init in that build is written as truncated UTF-16 memory with embedded NULs instead of UTF-8 markdown; route this through WriteFileText or TEncoding.UTF8.GetBytes like the rest of the codebase.
Useful? React with 👍 / 👎.
| if (Cmd = '/init') or (Copy(Cmd, 1, 6) = '/init ') then | ||
| begin | ||
| HandleInitCommand(Copy(Cmd, 7, MaxInt)); | ||
| Exit; |
There was a problem hiding this comment.
Wire /init in the full-screen TUI
This only adds /init to the FPC legacy REPL handler; the Delphi/full-screen TUI handles slash commands separately in SubmitInput, where /init still falls through to unknown. As a result pasclaw tui users in the primary TUI cannot run the command that the docs now advertise, so add the same Cmd_Init_Run path to SubmitInput or limit the claim to the FPC REPL.
Useful? React with 👍 / 👎.
Three Delphi-correctness fixes flagged by Codex. * P2 #1 (UTF-8 decode in ReadHead): Move(Buf[0], Result[1], N) on a UnicodeString reinterprets UTF-8 bytes as UTF-16 code units and leaves the second half of the allocation as garbage. Now goes through TEncoding.UTF8.GetString -- same path ReadFileText uses in PasClaw.Utils. * P2 #2 (UTF-8 write of AGENTS.md): TFileStream.WriteBuffer(Body[1], Length(Body)) under Delphi writes Length-in-chars (UTF-16 units) bytes of UTF-16 memory, producing a half-size NUL-laced file. Replaced with WriteFileText, which encodes properly under both compilers. * P2 #3 (/init unwired in positioned TUI): SubmitInput's slash dispatcher now recognises /init. To keep the framebuffer clean (Provider.Chat status output would corrupt the rendered display), the action goes through a new stdio-free RunInit worker that returns a TInitOutcome record; the positioned TUI reports the result via Flash, the CLI's Cmd_Init_Run wraps the same worker with PrintLn/PrintErr. Public surface change: PasClaw.Cmd.Init now exports RunInit + TInitOutcome so the TUI (and any future programmatic caller, e.g. a /v1/init gateway endpoint) can drive the bootstrap without screen-scraping CLI output. New tests: * TestDigestUtf8 -- writes a README with a multibyte UTF-8 codepoint (`é` as C3 A9) and asserts it survives the ReadHead/digest path. Pins the regression. * TestRunInitArgFailures -- exercises the no-network arg-validation paths of RunInit (missing dir, existing AGENTS.md without --force) and asserts Status / ErrorMsg shape.
The README + docs/changelog.md last entry was 2026-06-13 (FMXExpress#244). Five substantial PRs (FMXExpress#314 FMXExpress#315 FMXExpress#316 FMXExpress#317 FMXExpress#318) and ten more feature PRs between them and that entry shipped without changelog entries. This brings both files current through today. Twenty new entries (newest first, matching the existing style): 2026-06-21 FMXExpress#318 Relay pull-worker provider (queue + provider + /v1/relay/* HTTP) 2026-06-20 FMXExpress#317 pasclaw plan + build PLAN.md pickup + build --goal + cog mode FMXExpress#316 Cloudflare AI Gateway provider catalog rows FMXExpress#315 MCP progressive disclosure + tool_search FMXExpress#314 Stock defaults adopt lean-edit shape; fs_grep split-gate 2026-06-18 FMXExpress#312 Web UI workspace.zip export + import FMXExpress#310 Model-callable cron tool FMXExpress#309 FTS5 snippet window widened 24 -> 60 FMXExpress#307 Windows cmd.exe quoting fix 2026-06-17 FMXExpress#306 cog-build honours profile=security sandbox FMXExpress#304 cog-build default profile = max-build FMXExpress#303 cog-build list[Path] outputs + Secret inputs + -q 2026-06-16 FMXExpress#302 cog-build optional workspace_in FMXExpress#300 pasclaw build cmd + cog-build/ predictor (parent feature) FMXExpress#299 Checkpoints zpaq backend + /redo FMXExpress#298 AGENTS.md + pasclaw init + /init FMXExpress#297 tool_choice force-a-specific-tool form FMXExpress#296 Delphi ExtraEnv injection fix FMXExpress#295 KB native PDF ingest 2026-06-15 FMXExpress#292 pasclaw profile diff + bench Skipped per the changelog's stated convention ("Bug fixes and review follow-ups are in the full git log"): FMXExpress#293 cmd/profile dcc64 fix FMXExpress#294 skills_manage gemini empty-enum fix FMXExpress#301 cmd.build dcc64 fix FMXExpress#311 cron dcc64 fix Files updated identically (the docs/changelog.md note at the top says "This file mirrors the changelog section at the top of the root README.md"): M README.md 20 entries + 20 link refs added M docs/changelog.md same The link-ref block at the bottom of each file gained 20 [#NNN] entries keeping the existing one-per-line / sorted-numerically format.
Summary
Adopts the cross-tool AGENTS.md convention shared by opencode, Codex CLI, Cursor, Zed AI, and Claude Code — PasClaw now both reads
AGENTS.mdat session start and can generate a starter one for a fresh repo.Reader side (
PasClaw.Agent.Prompt)FindProjectAgentsMd(StartDir)walks fromcwdup to the first.gitboundary (dir or worktree file). Stops at the git root so a nested repo doesn't inherit a parent monorepo's rules.BuildProjectRulesSectionreads the file (64 KB cap, tail-truncates with an elision notice) and emits## Project Rules (AGENTS.md)between Memory and Skills. Missing / malformed / empty files are silently skipped (MEMORY.mdphilosophy).Writer side (
pasclaw init, newPasClaw.Cmd.Init)node_modules/target/.git/ etc.) and reads first 4 KB of well-known config files (README.md,package.json,Cargo.toml,Makefile,go.mod, …).Chat()call — no tool loop, no shell exec; the only disk touch is the finalAGENTS.mdwrite. Fast and trust-minimal.AGENTS.mdunless--force. Strips a leading```markdown ```fence if the model wraps its output.pasclaw runbook(already shipped) as the deeper model-driven variant.TUI
/init [flags]slash command in the FPC line REPL delegates straight toCmd_Init_Run— byte-for-byte equivalent topasclaw init.Tests (
src/tests/agents_md_tests.pas, newmake test-agents-mdtarget wired intomake test)FindProjectAgentsMd: absent / in-cwd / walks-to-git-root / stops-at-git-root (regression for the walk-past-boundary bug surfaced during development).BuildProjectRulesSection: absent / present / oversize (tail truncated, total bounded).UnfenceMarkdown: bare / wrapped.BuildProjectDigest: tree-listing + README-quoting shape.Docs —
docs/commands.mdanddocs/getting-started.mdget matching sections.Test plan
make test-agents-md— 10 tests, all passmake— full binary compiles under FPC 3.2.2pasclaw init --helpandpasclawtop-level help list the new commandpasclaw init, eyeball the generatedAGENTS.md, thenpasclaw agent "what are my project rules?"and verify the system prompt picked them up.delphi_build_testslane).Generated by Claude Code