modified
.tickets/issues/0253-variables-in-the-system-prompt-date-cwd-env-name.yaml +49 -3 | @@ -1,12 +1,12 @@ | ||
| 1 | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | 2 | id: 253 |
| 3 | 3 | title: "Variables in the system prompt: {{date}}, {{cwd}}, {{env.NAME}}" |
| 4 | -state: open | |
| 4 | +state: closed | |
| 5 | 5 | author: |
| 6 | 6 | name: k33g |
| 7 | 7 | email: ph.charriere@gmail.com |
| 8 | 8 | createdAt: 2026-11-24T05:59:01.000Z |
| 9 | -updatedAt: 2026-11-24T20:40:18.000Z | |
| 9 | +updatedAt: 2026-11-25T04:31:32.000Z | |
| 10 | 10 | labels: |
| 11 | 11 | - enhancement |
| 12 | 12 | - kind::feature |
| @@ -47,4 +47,50 @@ body: | | ||
| 47 | 47 | - `mm init` writes the comment line listing the variables. |
| 48 | 48 | - Tests, and EN+FR reference docs. |
| 49 | 49 | tasks: [] |
| 50 | -comments: [] | |
| 50 | +comments: | |
| 51 | + - id: 1 | |
| 52 | + author: | |
| 53 | + name: k33g | |
| 54 | + email: ph.charriere@gmail.com | |
| 55 | + createdAt: 2026-11-25T04:15:05.000Z | |
| 56 | + body: | | |
| 57 | + Implemented on branch `feature/prompt-variables` (not committed). | |
| 58 | + Decisions taken (the ticket's points): | |
| 59 | + - unset `env.NAME`: replaced by nothing + a banner warning | |
| 60 | + (`Config.PromptWarnings`); a name that looks like a secret | |
| 61 | + (`_KEY`, `_TOKEN`, `_SECRET`, `PASSWORD`, `CREDENTIALS`…) is a | |
| 62 | + configuration error (see #244/#259); | |
| 63 | + - only the three forms are replaced, any other `{…}` left as written | |
| 64 | + (Go templates, Mustache examples in prompts); `\{date}` escapes; | |
| 65 | + - `system:` only, not AGENTS.md (the project's text); | |
| 66 | + - replaced when a conversation's prompt is built (new session, /new, | |
| 67 | + resume), not per question — the cached prompt prefix holds; | |
| 68 | + - `{cwd}`: the session's directory over ACP (agentsmd.System gets it); | |
| 69 | + - own pattern (`config.promptVarPattern`): `placeholderPattern` has no | |
| 70 | + `.` for `env.NAME`. | |
| 71 | + Where: `config.ExpandPrompt` called by `agentsmd.System` (every front | |
| 72 | + end) and `agent.RunStructuredPrompt` (which skips AGENTS.md); mm init | |
| 73 | + writes the `# Variables:` line (golden previews updated). | |
| 74 | + Tests: config (expand, escape, secret names, warnings), agentsmd. | |
| 75 | + Live (sandbox, gemma-3-1b): banner warning for an unset variable, the | |
| 76 | + model repeats the date and the directory, a secret name refused. | |
| 77 | + - id: 2 | |
| 78 | + author: | |
| 79 | + name: k33g | |
| 80 | + email: ph.charriere@gmail.com | |
| 81 | + createdAt: 2026-11-25T04:25:19.000Z | |
| 82 | + body: | | |
| 83 | + Added at the user's request (2026-11-25): a `variables:` section of the | |
| 84 | + file's own values, used as `{{config.NAME}}`. A value may hold | |
| 85 | + `{{date}}`, `{{cwd}}`, `{{env.NAME}}` (same secret check), not another | |
| 86 | + `{{config.…}}` (no chains, no loops); an unknown `{{config.NAME}}` and a | |
| 87 | + bad key are configuration errors; an unset env variable used through a | |
| 88 | + value is warned. Demo `demos/prompt-variables` (Qwen3.5 2B, llamacpp) | |
| 89 | + created and measured; mm init's comment line names `{{config.NAME}}`. | |
| 90 | + - id: 3 | |
| 91 | + author: | |
| 92 | + name: k33g | |
| 93 | + email: ph.charriere@gmail.com | |
| 94 | + createdAt: 2026-11-25T04:31:32.000Z | |
| 95 | + body: | | |
| 96 | + Validated by the user; merged into `main`. The demos now use Qwen3.5 4B. | |
| @@ -1,12 +1,12 @@ | |||
| 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | id: 253 | 2 | id: 253 |
| 3 | title: "Variables in the system prompt: {{date}}, {{cwd}}, {{env.NAME}}" | 3 | title: "Variables in the system prompt: {{date}}, {{cwd}}, {{env.NAME}}" |
| 4 | -state: open | 4 | +state: closed |
| 5 | author: | 5 | author: |
| 6 | name: k33g | 6 | name: k33g |
| 7 | email: ph.charriere@gmail.com | 7 | email: ph.charriere@gmail.com |
| 8 | createdAt: 2026-11-24T05:59:01.000Z | 8 | createdAt: 2026-11-24T05:59:01.000Z |
| 9 | -updatedAt: 2026-11-24T20:40:18.000Z | 9 | +updatedAt: 2026-11-25T04:31:32.000Z |
| 10 | labels: | 10 | labels: |
| 11 | - enhancement | 11 | - enhancement |
| 12 | - kind::feature | 12 | - kind::feature |
| @@ -47,4 +47,50 @@ body: | | |||
| 47 | - `mm init` writes the comment line listing the variables. | 47 | - `mm init` writes the comment line listing the variables. |
| 48 | - Tests, and EN+FR reference docs. | 48 | - Tests, and EN+FR reference docs. |
| 49 | tasks: [] | 49 | tasks: [] |
| 50 | -comments: [] | 50 | +comments: |
| 51 | + - id: 1 | ||
| 52 | + author: | ||
| 53 | + name: k33g | ||
| 54 | + email: ph.charriere@gmail.com | ||
| 55 | + createdAt: 2026-11-25T04:15:05.000Z | ||
| 56 | + body: | | ||
| 57 | + Implemented on branch `feature/prompt-variables` (not committed). | ||
| 58 | + Decisions taken (the ticket's points): | ||
| 59 | + - unset `env.NAME`: replaced by nothing + a banner warning | ||
| 60 | + (`Config.PromptWarnings`); a name that looks like a secret | ||
| 61 | + (`_KEY`, `_TOKEN`, `_SECRET`, `PASSWORD`, `CREDENTIALS`…) is a | ||
| 62 | + configuration error (see #244/#259); | ||
| 63 | + - only the three forms are replaced, any other `{…}` left as written | ||
| 64 | + (Go templates, Mustache examples in prompts); `\{date}` escapes; | ||
| 65 | + - `system:` only, not AGENTS.md (the project's text); | ||
| 66 | + - replaced when a conversation's prompt is built (new session, /new, | ||
| 67 | + resume), not per question — the cached prompt prefix holds; | ||
| 68 | + - `{cwd}`: the session's directory over ACP (agentsmd.System gets it); | ||
| 69 | + - own pattern (`config.promptVarPattern`): `placeholderPattern` has no | ||
| 70 | + `.` for `env.NAME`. | ||
| 71 | + Where: `config.ExpandPrompt` called by `agentsmd.System` (every front | ||
| 72 | + end) and `agent.RunStructuredPrompt` (which skips AGENTS.md); mm init | ||
| 73 | + writes the `# Variables:` line (golden previews updated). | ||
| 74 | + Tests: config (expand, escape, secret names, warnings), agentsmd. | ||
| 75 | + Live (sandbox, gemma-3-1b): banner warning for an unset variable, the | ||
| 76 | + model repeats the date and the directory, a secret name refused. | ||
| 77 | + - id: 2 | ||
| 78 | + author: | ||
| 79 | + name: k33g | ||
| 80 | + email: ph.charriere@gmail.com | ||
| 81 | + createdAt: 2026-11-25T04:25:19.000Z | ||
| 82 | + body: | | ||
| 83 | + Added at the user's request (2026-11-25): a `variables:` section of the | ||
| 84 | + file's own values, used as `{{config.NAME}}`. A value may hold | ||
| 85 | + `{{date}}`, `{{cwd}}`, `{{env.NAME}}` (same secret check), not another | ||
| 86 | + `{{config.…}}` (no chains, no loops); an unknown `{{config.NAME}}` and a | ||
| 87 | + bad key are configuration errors; an unset env variable used through a | ||
| 88 | + value is warned. Demo `demos/prompt-variables` (Qwen3.5 2B, llamacpp) | ||
| 89 | + created and measured; mm init's comment line names `{{config.NAME}}`. | ||
| 90 | + - id: 3 | ||
| 91 | + author: | ||
| 92 | + name: k33g | ||
| 93 | + email: ph.charriere@gmail.com | ||
| 94 | + createdAt: 2026-11-25T04:31:32.000Z | ||
| 95 | + body: | | ||
| 96 | + Validated by the user; merged into `main`. The demos now use Qwen3.5 4B. | ||
modified
README.md +1 -0 | @@ -176,6 +176,7 @@ The `demos/` directory holds ready-made set-ups (most with a README explaining h | ||
| 176 | 176 | | `demos/codex-style/` | the same idea with Codex CLI's default instructions (preambles, plans, ambition vs. precision, final-answer format), adapted to mm and to gpt-oss 20B (harmony format, `reasoning_effort`, `model_identity`) on llmman; measured results | |
| 177 | 177 | | `demos/news-roundup/` | a press-review agent: DuckDuckGo News through a small MCP server (Python standard library), Qwen3.5 9B on llmman, ready-made citations so no article is invented, measured results | |
| 178 | 178 | | `demos/qwen-search/` | the same kind of agent with **skills** instead of an MCP server: web search and a press review through DuckDuckGo Lite and `fetch_content`, plus a skill with a catalogue of trusted pages (WebAssembly); Qwen3.5 2B and 4B measured | |
| 179 | +| `demos/prompt-variables/` | the variables of the system prompt — `{{date}}`, `{{cwd}}`, `{{env.USER}}` and a `variables:` section used as `{{config.NAME}}` — with Qwen3.5 4B (and 2B) on llamacpp: what a small model repeats correctly, and what it cannot compute from them (measured) | | |
| 179 | 180 | | `demos/project-wizard/` | the interactive prompts (`ask_user`) in a small agent: a four-question form (text, two choices, several choices), then a yes/no confirmation carrying the plan before any file is written; Qwen3.5 9B on llmman, measured results | |
| 180 | 181 | | `demos/hooks/` | hooks in Node.js around a small shell assistant (Gemma 4 E4B on llmman): a question holding a secret never reaches the model, today's date and the file list are added to every question, `rm -r` / `sudo` / `curl \| sh` are denied, every tool call and turn is logged to `.mm/hooks-audit.jsonl` | |
| 181 | 182 | | `demos/hooks-ask/` | `preAsk` and `postAsk` hooks in Node.js around a help desk that hands technical questions to an expert agent (both Gemma 4 E4B on llmman): secrets masked before they leave, at most 2 `ask_agent` calls per question, standing rules added for the expert, a failed hand-off turned into an instruction, every hand-off logged to `.mm/ask-audit.jsonl` | |
| @@ -176,6 +176,7 @@ The `demos/` directory holds ready-made set-ups (most with a README explaining h | |||
| 176 | | `demos/codex-style/` | the same idea with Codex CLI's default instructions (preambles, plans, ambition vs. precision, final-answer format), adapted to mm and to gpt-oss 20B (harmony format, `reasoning_effort`, `model_identity`) on llmman; measured results | | 176 | | `demos/codex-style/` | the same idea with Codex CLI's default instructions (preambles, plans, ambition vs. precision, final-answer format), adapted to mm and to gpt-oss 20B (harmony format, `reasoning_effort`, `model_identity`) on llmman; measured results | |
| 177 | | `demos/news-roundup/` | a press-review agent: DuckDuckGo News through a small MCP server (Python standard library), Qwen3.5 9B on llmman, ready-made citations so no article is invented, measured results | | 177 | | `demos/news-roundup/` | a press-review agent: DuckDuckGo News through a small MCP server (Python standard library), Qwen3.5 9B on llmman, ready-made citations so no article is invented, measured results | |
| 178 | | `demos/qwen-search/` | the same kind of agent with **skills** instead of an MCP server: web search and a press review through DuckDuckGo Lite and `fetch_content`, plus a skill with a catalogue of trusted pages (WebAssembly); Qwen3.5 2B and 4B measured | | 178 | | `demos/qwen-search/` | the same kind of agent with **skills** instead of an MCP server: web search and a press review through DuckDuckGo Lite and `fetch_content`, plus a skill with a catalogue of trusted pages (WebAssembly); Qwen3.5 2B and 4B measured | |
| 179 | +| `demos/prompt-variables/` | the variables of the system prompt — `{{date}}`, `{{cwd}}`, `{{env.USER}}` and a `variables:` section used as `{{config.NAME}}` — with Qwen3.5 4B (and 2B) on llamacpp: what a small model repeats correctly, and what it cannot compute from them (measured) | | ||
| 179 | | `demos/project-wizard/` | the interactive prompts (`ask_user`) in a small agent: a four-question form (text, two choices, several choices), then a yes/no confirmation carrying the plan before any file is written; Qwen3.5 9B on llmman, measured results | | 180 | | `demos/project-wizard/` | the interactive prompts (`ask_user`) in a small agent: a four-question form (text, two choices, several choices), then a yes/no confirmation carrying the plan before any file is written; Qwen3.5 9B on llmman, measured results | |
| 180 | | `demos/hooks/` | hooks in Node.js around a small shell assistant (Gemma 4 E4B on llmman): a question holding a secret never reaches the model, today's date and the file list are added to every question, `rm -r` / `sudo` / `curl \| sh` are denied, every tool call and turn is logged to `.mm/hooks-audit.jsonl` | | 181 | | `demos/hooks/` | hooks in Node.js around a small shell assistant (Gemma 4 E4B on llmman): a question holding a secret never reaches the model, today's date and the file list are added to every question, `rm -r` / `sudo` / `curl \| sh` are denied, every tool call and turn is logged to `.mm/hooks-audit.jsonl` | |
| 181 | | `demos/hooks-ask/` | `preAsk` and `postAsk` hooks in Node.js around a help desk that hands technical questions to an expert agent (both Gemma 4 E4B on llmman): secrets masked before they leave, at most 2 `ask_agent` calls per question, standing rules added for the expert, a failed hand-off turned into an instruction, every hand-off logged to `.mm/ask-audit.jsonl` | | 182 | | `demos/hooks-ask/` | `preAsk` and `postAsk` hooks in Node.js around a help desk that hands technical questions to an expert agent (both Gemma 4 E4B on llmman): secrets masked before they leave, at most 2 `ask_agent` calls per question, standing rules added for the expert, a failed hand-off turned into an instruction, every hand-off logged to `.mm/ask-audit.jsonl` | |
added
demos/prompt-variables/.gitignore +3 -0 | new file mode 100644 | ||
| @@ -0,0 +1,3 @@ | ||
| 1 | +!.mm | |
| 2 | +sessions | |
| 3 | +traces | |
| \ No newline at end of file | ||
| new file mode 100644 | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | +!.mm | ||
| 2 | +sessions | ||
| 3 | +traces | ||
| \ No newline at end of file | \ No newline at end of file | ||
added
demos/prompt-variables/.mm/agent.yaml +114 -0 | new file mode 100644 | ||
| @@ -0,0 +1,114 @@ | ||
| 1 | +# Ada — answers questions, no tools. | |
| 2 | +# | |
| 3 | +# Written by `mm init`. Every value says why it has that value; change | |
| 4 | +# them as you watch the agent work: | |
| 5 | +# https://rickub.com/bots-garden/mini-me/blob/main/guides/agent-settings-for-small-models.md | |
| 6 | +# | |
| 7 | +# model family: qwen | |
| 8 | +# usage: assistant | |
| 9 | +# machine: small — a laptop, models up to about 8B | |
| 10 | +# model facts: none — llamacpp said nothing about this model beyond its name | |
| 11 | +# | |
| 12 | +# Where the numbers come from (the tag before their comment): | |
| 13 | +# [card] from the model card or the GGUF, not measured — re-read the new card | |
| 14 | +# [guide] the settings guide's row for this machine | |
| 15 | +# [rule] a rule of thumb, not specific to this model | |
| 16 | +# | |
| 17 | +# mm or mm tui started from the project root (it finds .mm/agent.yaml) | |
| 18 | + | |
| 19 | +provider: llamacpp | |
| 20 | +# The model. Chosen for it (family qwen): sampling (temperature, top_p, top_k, | |
| 21 | +# max_tokens) and sampling.chat_template_kwargs (enable_thinking). Change the | |
| 22 | +# model and redo them together — running mm init again is the quick way. | |
| 23 | +model: "unsloth/Qwen3.5-4B-GGUF:Q4_K_M" | |
| 24 | +# No baseUrl: llamacpp's defaults apply. For the record: | |
| 25 | +# baseUrl: "http://127.0.0.1:9931/v1" | |
| 26 | +# (llamacpp also tries http://127.0.0.1:8080/v1 on this machine when baseUrl does not answer) | |
| 27 | +# fallback: "http://host.docker.internal:9931/v1" # tried when baseUrl does not answer | |
| 28 | +# Nothing answers at this address: mm starts llama-server (router mode, this | |
| 29 | +# model, downloaded on first use) and stops it with the last mm session using | |
| 30 | +# it. A server you started yourself is never stopped. false: start it yourself. | |
| 31 | +llamacpp: | |
| 32 | + autoStart: true | |
| 33 | + | |
| 34 | +# 0 = mm asks the server for the window it serves | |
| 35 | +contextWindow: 0 | |
| 36 | +# usage assistant's default: tools run without asking | |
| 37 | +yolo: true | |
| 38 | +# usage assistant | |
| 39 | +bashTool: false | |
| 40 | +editTools: false | |
| 41 | +planTool: false | |
| 42 | +# off: an agent with nothing to look up has no question to ask; Qwen3.5 2B | |
| 43 | +# used ask_user to avoid answering (demos/qwen-search) | |
| 44 | +askUserTool: false | |
| 45 | +# unload the model from the server's memory when mm exits; false keeps it | |
| 46 | +# loaded (faster next start, or another tool uses it) | |
| 47 | +unloadOnExit: true | |
| 48 | +# no skills: add a .mm/skills/ folder and set skillsDir: .mm/skills to use | |
| 49 | +# some (see | |
| 50 | +# https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/add-a-skill.md) | |
| 51 | +skillsDir: no-skills | |
| 52 | +# usage assistant | |
| 53 | +maxTurns: 5 | |
| 54 | +# [guide] settings guide, row "Small model (≤ 8B), short tasks" | |
| 55 | +maxOutput: 8000 | |
| 56 | +firstTokenTimeout: 3m | |
| 57 | +watchdogTimeout: 20s | |
| 58 | + | |
| 59 | +sampling: | |
| 60 | + # [card] family qwen: Qwen model cards (thinking 0.6 / 0.95 / 20, | |
| 61 | + # non-thinking 0.7 / 0.8 / 20); precise 0.0 measured with Qwen3.5 4B, | |
| 62 | + # thinking off (demos/docs-search, memory-search, plans) | |
| 63 | + temperature: 0.7 | |
| 64 | + top_p: 0.8 | |
| 65 | + top_k: 20 | |
| 66 | + # [rule] room for an answer or a whole file in one tool call | |
| 67 | + max_tokens: 4096 | |
| 68 | + # one tool call per reply: small models run a check before the change it | |
| 69 | + # checks has landed otherwise | |
| 70 | + parallel_tool_calls: false | |
| 71 | + chat_template_kwargs: | |
| 72 | + # reasoning off: short, direct answers (family qwen) | |
| 73 | + enable_thinking: false | |
| 74 | + | |
| 75 | +context: | |
| 76 | + # compress the history before the window is full (settings guide, every row) | |
| 77 | + enabled: true | |
| 78 | + # mm's default: 75 % of the window the server serves, a quarter left for the | |
| 79 | + # next question and its tool outputs | |
| 80 | + threshold: 75 | |
| 81 | + | |
| 82 | +agentsMd: | |
| 83 | + # An AGENTS.md in the project directory is added to the system prompt. | |
| 84 | + enabled: true | |
| 85 | + | |
| 86 | +acp: | |
| 87 | + name: ada | |
| 88 | + title: "Ada (assistant)" | |
| 89 | + | |
| 90 | +# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts. | |
| 91 | +# This demo uses all of them (ticket 253): the model cannot know today's date, | |
| 92 | +# the folder it runs in or who runs it; the prompt tells it. The variables: | |
| 93 | +# section holds the file's own values, written once and used as {{config.NAME}}. | |
| 94 | +variables: | |
| 95 | + project: mini-me, a coding agent written in Go | |
| 96 | + since: "{{date}}" | |
| 97 | +system: | | |
| 98 | + Your name is Ada. | |
| 99 | + Today is {{date}} (year-month-day). You run in the folder {{cwd}}. | |
| 100 | + The user you are talking to is called {{env.USER}}. | |
| 101 | + You help with the project {{config.project}}; this conversation started on {{config.since}}. | |
| 102 | + | |
| 103 | + You are a helpful assistant. Answer clearly and briefly, in the user's | |
| 104 | + language. Say when you do not know; never invent facts, names or | |
| 105 | + figures. For today's date, the year, the folder or the user's name, use | |
| 106 | + the lines above — never your memory, which is months or years old. | |
| 107 | + | |
| 108 | +# The server said nothing about this model beyond its name: the settings | |
| 109 | +# come from the family table. | |
| 110 | + | |
| 111 | +# Next: skills https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/add-a-skill.md | |
| 112 | +# MCP servers https://rickub.com/bots-garden/mini-me/blob/main/docs/en/tutorials/mcp-getting-started.md | |
| 113 | +# hooks https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/guard-the-agent-with-hooks.md | |
| 114 | +# sessions https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/keep-sessions.md | |
| new file mode 100644 | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | +# Ada — answers questions, no tools. | ||
| 2 | +# | ||
| 3 | +# Written by `mm init`. Every value says why it has that value; change | ||
| 4 | +# them as you watch the agent work: | ||
| 5 | +# https://rickub.com/bots-garden/mini-me/blob/main/guides/agent-settings-for-small-models.md | ||
| 6 | +# | ||
| 7 | +# model family: qwen | ||
| 8 | +# usage: assistant | ||
| 9 | +# machine: small — a laptop, models up to about 8B | ||
| 10 | +# model facts: none — llamacpp said nothing about this model beyond its name | ||
| 11 | +# | ||
| 12 | +# Where the numbers come from (the tag before their comment): | ||
| 13 | +# [card] from the model card or the GGUF, not measured — re-read the new card | ||
| 14 | +# [guide] the settings guide's row for this machine | ||
| 15 | +# [rule] a rule of thumb, not specific to this model | ||
| 16 | +# | ||
| 17 | +# mm or mm tui started from the project root (it finds .mm/agent.yaml) | ||
| 18 | + | ||
| 19 | +provider: llamacpp | ||
| 20 | +# The model. Chosen for it (family qwen): sampling (temperature, top_p, top_k, | ||
| 21 | +# max_tokens) and sampling.chat_template_kwargs (enable_thinking). Change the | ||
| 22 | +# model and redo them together — running mm init again is the quick way. | ||
| 23 | +model: "unsloth/Qwen3.5-4B-GGUF:Q4_K_M" | ||
| 24 | +# No baseUrl: llamacpp's defaults apply. For the record: | ||
| 25 | +# baseUrl: "http://127.0.0.1:9931/v1" | ||
| 26 | +# (llamacpp also tries http://127.0.0.1:8080/v1 on this machine when baseUrl does not answer) | ||
| 27 | +# fallback: "http://host.docker.internal:9931/v1" # tried when baseUrl does not answer | ||
| 28 | +# Nothing answers at this address: mm starts llama-server (router mode, this | ||
| 29 | +# model, downloaded on first use) and stops it with the last mm session using | ||
| 30 | +# it. A server you started yourself is never stopped. false: start it yourself. | ||
| 31 | +llamacpp: | ||
| 32 | + autoStart: true | ||
| 33 | + | ||
| 34 | +# 0 = mm asks the server for the window it serves | ||
| 35 | +contextWindow: 0 | ||
| 36 | +# usage assistant's default: tools run without asking | ||
| 37 | +yolo: true | ||
| 38 | +# usage assistant | ||
| 39 | +bashTool: false | ||
| 40 | +editTools: false | ||
| 41 | +planTool: false | ||
| 42 | +# off: an agent with nothing to look up has no question to ask; Qwen3.5 2B | ||
| 43 | +# used ask_user to avoid answering (demos/qwen-search) | ||
| 44 | +askUserTool: false | ||
| 45 | +# unload the model from the server's memory when mm exits; false keeps it | ||
| 46 | +# loaded (faster next start, or another tool uses it) | ||
| 47 | +unloadOnExit: true | ||
| 48 | +# no skills: add a .mm/skills/ folder and set skillsDir: .mm/skills to use | ||
| 49 | +# some (see | ||
| 50 | +# https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/add-a-skill.md) | ||
| 51 | +skillsDir: no-skills | ||
| 52 | +# usage assistant | ||
| 53 | +maxTurns: 5 | ||
| 54 | +# [guide] settings guide, row "Small model (≤ 8B), short tasks" | ||
| 55 | +maxOutput: 8000 | ||
| 56 | +firstTokenTimeout: 3m | ||
| 57 | +watchdogTimeout: 20s | ||
| 58 | + | ||
| 59 | +sampling: | ||
| 60 | + # [card] family qwen: Qwen model cards (thinking 0.6 / 0.95 / 20, | ||
| 61 | + # non-thinking 0.7 / 0.8 / 20); precise 0.0 measured with Qwen3.5 4B, | ||
| 62 | + # thinking off (demos/docs-search, memory-search, plans) | ||
| 63 | + temperature: 0.7 | ||
| 64 | + top_p: 0.8 | ||
| 65 | + top_k: 20 | ||
| 66 | + # [rule] room for an answer or a whole file in one tool call | ||
| 67 | + max_tokens: 4096 | ||
| 68 | + # one tool call per reply: small models run a check before the change it | ||
| 69 | + # checks has landed otherwise | ||
| 70 | + parallel_tool_calls: false | ||
| 71 | + chat_template_kwargs: | ||
| 72 | + # reasoning off: short, direct answers (family qwen) | ||
| 73 | + enable_thinking: false | ||
| 74 | + | ||
| 75 | +context: | ||
| 76 | + # compress the history before the window is full (settings guide, every row) | ||
| 77 | + enabled: true | ||
| 78 | + # mm's default: 75 % of the window the server serves, a quarter left for the | ||
| 79 | + # next question and its tool outputs | ||
| 80 | + threshold: 75 | ||
| 81 | + | ||
| 82 | +agentsMd: | ||
| 83 | + # An AGENTS.md in the project directory is added to the system prompt. | ||
| 84 | + enabled: true | ||
| 85 | + | ||
| 86 | +acp: | ||
| 87 | + name: ada | ||
| 88 | + title: "Ada (assistant)" | ||
| 89 | + | ||
| 90 | +# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts. | ||
| 91 | +# This demo uses all of them (ticket 253): the model cannot know today's date, | ||
| 92 | +# the folder it runs in or who runs it; the prompt tells it. The variables: | ||
| 93 | +# section holds the file's own values, written once and used as {{config.NAME}}. | ||
| 94 | +variables: | ||
| 95 | + project: mini-me, a coding agent written in Go | ||
| 96 | + since: "{{date}}" | ||
| 97 | +system: | | ||
| 98 | + Your name is Ada. | ||
| 99 | + Today is {{date}} (year-month-day). You run in the folder {{cwd}}. | ||
| 100 | + The user you are talking to is called {{env.USER}}. | ||
| 101 | + You help with the project {{config.project}}; this conversation started on {{config.since}}. | ||
| 102 | + | ||
| 103 | + You are a helpful assistant. Answer clearly and briefly, in the user's | ||
| 104 | + language. Say when you do not know; never invent facts, names or | ||
| 105 | + figures. For today's date, the year, the folder or the user's name, use | ||
| 106 | + the lines above — never your memory, which is months or years old. | ||
| 107 | + | ||
| 108 | +# The server said nothing about this model beyond its name: the settings | ||
| 109 | +# come from the family table. | ||
| 110 | + | ||
| 111 | +# Next: skills https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/add-a-skill.md | ||
| 112 | +# MCP servers https://rickub.com/bots-garden/mini-me/blob/main/docs/en/tutorials/mcp-getting-started.md | ||
| 113 | +# hooks https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/guard-the-agent-with-hooks.md | ||
| 114 | +# sessions https://rickub.com/bots-garden/mini-me/blob/main/docs/en/how-to/keep-sessions.md | ||
added
demos/prompt-variables/README.en.md +69 -0 | new file mode 100644 | ||
| @@ -0,0 +1,69 @@ | ||
| 1 | +# prompt-variables — the date, the folder and the user in the system prompt | |
| 2 | + | |
| 3 | +*[French version](README.fr.md)* | |
| 4 | + | |
| 5 | +A small assistant, Ada, whose system prompt uses the variables of ticket 253: the three built-in ones, and a `variables:` section of the file's own values. A model cannot know today's date, the folder it runs in or who runs it: the prompt tells it. | |
| 6 | + | |
| 7 | +```yaml | |
| 8 | +system: | | |
| 9 | + Your name is Ada. | |
| 10 | + Today is {{date}} (year-month-day). You run in the folder {{cwd}}. | |
| 11 | + The user you are talking to is called {{env.USER}}. | |
| 12 | + You help with the project {{config.project}}; this conversation started on {{config.since}}. | |
| 13 | + | |
| 14 | +variables: | |
| 15 | + project: mini-me, a coding agent written in Go | |
| 16 | + since: "{{date}}" | |
| 17 | +``` | |
| 18 | + | |
| 19 | +| | | | |
| 20 | +|---|---| | |
| 21 | +| Agent | `.mm/agent.yaml`, written by `mm init` (usage assistant, `--project yes`), then the prompt above | | |
| 22 | +| Model | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, reasoning off (Qwen3.5 2B measured too, below) | | |
| 23 | +| Server | llamacpp, started by mm when nothing answers (`llamacpp.autoStart: true`) | | |
| 24 | +| Tools | none (`ask_user` off: with nothing to look up, Qwen3.5 2B used it to avoid answering in `demos/qwen-search`) | | |
| 25 | + | |
| 26 | +## Run | |
| 27 | + | |
| 28 | +```bash | |
| 29 | +cd demos/prompt-variables | |
| 30 | +../../mm -p "What is today's date?" | |
| 31 | +../../mm -p "Who am I?" | |
| 32 | +../../mm # conversation | |
| 33 | +``` | |
| 34 | + | |
| 35 | +`{{env.USER}}` is your login on macOS and Linux. On Windows the variable is `USERNAME`: change the prompt to `{{env.USERNAME}}`. An unset variable is replaced by nothing, and the banner says so: | |
| 36 | + | |
| 37 | +```text | |
| 38 | +[warning: system: {{env.USER}} — USER is not set, replaced by nothing] | |
| 39 | +``` | |
| 40 | + | |
| 41 | +## What the variables become | |
| 42 | + | |
| 43 | +- `{{date}}`: `2026-11-25` — replaced when the conversation starts (a new session, `/new`, a resumed one), not before every question, so the server's prompt cache holds. | |
| 44 | +- `{{cwd}}`: the folder mm runs in; in an editor (ACP), the folder of the session. | |
| 45 | +- `{{config.project}}`: the value `project` of the `variables:` section — written once in the file. A value may itself use `{{date}}`, `{{cwd}}` and `{{env.NAME}}` (`since: "{{date}}"`), not another `{{config.…}}`; a `{{config.NAME}}` the section does not have stops mm at start-up. | |
| 46 | +- `{{env.USER}}`: the value of `USER`. A name that looks like a secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`) is refused when the file is loaded: the prompt goes to the model, the sessions and the traces. | |
| 47 | + | |
| 48 | +## Measured results | |
| 49 | + | |
| 50 | +Measured on 2026-11-25 with `mm -p`, in a Docker sandbox (Linux arm64, CPU), llama.cpp build 12359, `USER=k33g`; each question asked twice. | |
| 51 | + | |
| 52 | +| Question | Qwen3.5 4B | Qwen3.5 2B | | |
| 53 | +|---|---|---| | |
| 54 | +| Which project do you help with? (`{{config.project}}`) | ✅ "mini-me, a coding agent written in Go", twice | ✅ twice | | |
| 55 | +| What is today's date? | ✅ "2026-11-25", twice | ✅ twice | | |
| 56 | +| En quelle année sommes-nous ? | ✅ "2026", twice | ✅ twice | | |
| 57 | +| In which folder are you running? | ✅ the folder, exact, twice | ✅ twice | | |
| 58 | +| Who am I? | ✅ "You are k33g.", twice | ✅ once asked | | |
| 59 | +| What is my name? / Comment je m'appelle ? | ✅ "Your name is k33g." / "Tu t'appelles k33g.", 4 of 4 | ❌ "My name is Ada.", 4 of 4 | | |
| 60 | +| Do you know who I am? | ✅ "I know your name is k33g.", twice | ❌ "No, I don't know who you are…" | | |
| 61 | +| How many days until Christmas? | ½ 30 (right), then 13 | ½ 50, then 30 (right) | | |
| 62 | +| Quel jour de la semaine sommes-nous ? | ❌ Friday, then Thursday (it is a Wednesday) | ❌ Tuesday, then Thursday | | |
| 63 | + | |
| 64 | +What the variables give — the date, the year, the folder, the user's name, the file's own values — both models repeat correctly; the 4B also understands "my name" as the user's, which the 2B reads as its own. What must be computed from them is beyond both: the day of the week (the prompt gives no weekday), a number of days. | |
| 65 | + | |
| 66 | +## Limits | |
| 67 | + | |
| 68 | +- No weekday variable, and neither model computes it from the date: write it in the prompt as a fact if the agent needs it. | |
| 69 | +- A session that crosses midnight keeps its date until `/new`. | |
| new file mode 100644 | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | +# prompt-variables — the date, the folder and the user in the system prompt | ||
| 2 | + | ||
| 3 | +*[French version](README.fr.md)* | ||
| 4 | + | ||
| 5 | +A small assistant, Ada, whose system prompt uses the variables of ticket 253: the three built-in ones, and a `variables:` section of the file's own values. A model cannot know today's date, the folder it runs in or who runs it: the prompt tells it. | ||
| 6 | + | ||
| 7 | +```yaml | ||
| 8 | +system: | | ||
| 9 | + Your name is Ada. | ||
| 10 | + Today is {{date}} (year-month-day). You run in the folder {{cwd}}. | ||
| 11 | + The user you are talking to is called {{env.USER}}. | ||
| 12 | + You help with the project {{config.project}}; this conversation started on {{config.since}}. | ||
| 13 | + | ||
| 14 | +variables: | ||
| 15 | + project: mini-me, a coding agent written in Go | ||
| 16 | + since: "{{date}}" | ||
| 17 | +``` | ||
| 18 | + | ||
| 19 | +| | | | ||
| 20 | +|---|---| | ||
| 21 | +| Agent | `.mm/agent.yaml`, written by `mm init` (usage assistant, `--project yes`), then the prompt above | | ||
| 22 | +| Model | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, reasoning off (Qwen3.5 2B measured too, below) | | ||
| 23 | +| Server | llamacpp, started by mm when nothing answers (`llamacpp.autoStart: true`) | | ||
| 24 | +| Tools | none (`ask_user` off: with nothing to look up, Qwen3.5 2B used it to avoid answering in `demos/qwen-search`) | | ||
| 25 | + | ||
| 26 | +## Run | ||
| 27 | + | ||
| 28 | +```bash | ||
| 29 | +cd demos/prompt-variables | ||
| 30 | +../../mm -p "What is today's date?" | ||
| 31 | +../../mm -p "Who am I?" | ||
| 32 | +../../mm # conversation | ||
| 33 | +``` | ||
| 34 | + | ||
| 35 | +`{{env.USER}}` is your login on macOS and Linux. On Windows the variable is `USERNAME`: change the prompt to `{{env.USERNAME}}`. An unset variable is replaced by nothing, and the banner says so: | ||
| 36 | + | ||
| 37 | +```text | ||
| 38 | +[warning: system: {{env.USER}} — USER is not set, replaced by nothing] | ||
| 39 | +``` | ||
| 40 | + | ||
| 41 | +## What the variables become | ||
| 42 | + | ||
| 43 | +- `{{date}}`: `2026-11-25` — replaced when the conversation starts (a new session, `/new`, a resumed one), not before every question, so the server's prompt cache holds. | ||
| 44 | +- `{{cwd}}`: the folder mm runs in; in an editor (ACP), the folder of the session. | ||
| 45 | +- `{{config.project}}`: the value `project` of the `variables:` section — written once in the file. A value may itself use `{{date}}`, `{{cwd}}` and `{{env.NAME}}` (`since: "{{date}}"`), not another `{{config.…}}`; a `{{config.NAME}}` the section does not have stops mm at start-up. | ||
| 46 | +- `{{env.USER}}`: the value of `USER`. A name that looks like a secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`) is refused when the file is loaded: the prompt goes to the model, the sessions and the traces. | ||
| 47 | + | ||
| 48 | +## Measured results | ||
| 49 | + | ||
| 50 | +Measured on 2026-11-25 with `mm -p`, in a Docker sandbox (Linux arm64, CPU), llama.cpp build 12359, `USER=k33g`; each question asked twice. | ||
| 51 | + | ||
| 52 | +| Question | Qwen3.5 4B | Qwen3.5 2B | | ||
| 53 | +|---|---|---| | ||
| 54 | +| Which project do you help with? (`{{config.project}}`) | ✅ "mini-me, a coding agent written in Go", twice | ✅ twice | | ||
| 55 | +| What is today's date? | ✅ "2026-11-25", twice | ✅ twice | | ||
| 56 | +| En quelle année sommes-nous ? | ✅ "2026", twice | ✅ twice | | ||
| 57 | +| In which folder are you running? | ✅ the folder, exact, twice | ✅ twice | | ||
| 58 | +| Who am I? | ✅ "You are k33g.", twice | ✅ once asked | | ||
| 59 | +| What is my name? / Comment je m'appelle ? | ✅ "Your name is k33g." / "Tu t'appelles k33g.", 4 of 4 | ❌ "My name is Ada.", 4 of 4 | | ||
| 60 | +| Do you know who I am? | ✅ "I know your name is k33g.", twice | ❌ "No, I don't know who you are…" | | ||
| 61 | +| How many days until Christmas? | ½ 30 (right), then 13 | ½ 50, then 30 (right) | | ||
| 62 | +| Quel jour de la semaine sommes-nous ? | ❌ Friday, then Thursday (it is a Wednesday) | ❌ Tuesday, then Thursday | | ||
| 63 | + | ||
| 64 | +What the variables give — the date, the year, the folder, the user's name, the file's own values — both models repeat correctly; the 4B also understands "my name" as the user's, which the 2B reads as its own. What must be computed from them is beyond both: the day of the week (the prompt gives no weekday), a number of days. | ||
| 65 | + | ||
| 66 | +## Limits | ||
| 67 | + | ||
| 68 | +- No weekday variable, and neither model computes it from the date: write it in the prompt as a fact if the agent needs it. | ||
| 69 | +- A session that crosses midnight keeps its date until `/new`. | ||
added
demos/prompt-variables/README.fr.md +69 -0 | new file mode 100644 | ||
| @@ -0,0 +1,69 @@ | ||
| 1 | +# prompt-variables — la date, le dossier et l'utilisateur dans le prompt système | |
| 2 | + | |
| 3 | +*[English version](README.en.md)* | |
| 4 | + | |
| 5 | +Un petit assistant, Ada, dont le prompt système utilise les variables du ticket 253 : les trois intégrées, et une section `variables:` de valeurs propres au fichier. Un modèle ne peut pas connaître la date du jour, le dossier où il tourne ni qui l'utilise : le prompt le lui dit. | |
| 6 | + | |
| 7 | +```yaml | |
| 8 | +system: | | |
| 9 | + Your name is Ada. | |
| 10 | + Today is {{date}} (year-month-day). You run in the folder {{cwd}}. | |
| 11 | + The user you are talking to is called {{env.USER}}. | |
| 12 | + You help with the project {{config.project}}; this conversation started on {{config.since}}. | |
| 13 | + | |
| 14 | +variables: | |
| 15 | + project: mini-me, a coding agent written in Go | |
| 16 | + since: "{{date}}" | |
| 17 | +``` | |
| 18 | + | |
| 19 | +| | | | |
| 20 | +|---|---| | |
| 21 | +| Agent | `.mm/agent.yaml`, écrit par `mm init` (usage assistant, `--project yes`), puis le prompt ci-dessus | | |
| 22 | +| Modèle | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, raisonnement désactivé (Qwen3.5 2B mesuré aussi, plus bas) | | |
| 23 | +| Serveur | llamacpp, démarré par mm quand rien ne répond (`llamacpp.autoStart: true`) | | |
| 24 | +| Outils | aucun (`ask_user` désactivé : sans rien à chercher, Qwen3.5 2B s'en servait pour éviter de répondre dans `demos/qwen-search`) | | |
| 25 | + | |
| 26 | +## Lancer | |
| 27 | + | |
| 28 | +```bash | |
| 29 | +cd demos/prompt-variables | |
| 30 | +../../mm -p "What is today's date?" | |
| 31 | +../../mm -p "Who am I?" | |
| 32 | +../../mm # conversation | |
| 33 | +``` | |
| 34 | + | |
| 35 | +`{{env.USER}}` est votre identifiant sous macOS et Linux. Sous Windows, la variable s'appelle `USERNAME` : mettez `{{env.USERNAME}}` dans le prompt. Une variable non définie est remplacée par rien, et la bannière le signale : | |
| 36 | + | |
| 37 | +```text | |
| 38 | +[warning: system: {{env.USER}} — USER is not set, replaced by nothing] | |
| 39 | +``` | |
| 40 | + | |
| 41 | +## Ce que deviennent les variables | |
| 42 | + | |
| 43 | +- `{{date}}` : `2026-11-25` — remplacée au début de la conversation (une nouvelle session, `/new`, une session reprise), pas avant chaque question, pour que le cache de prompt du serveur tienne. | |
| 44 | +- `{{cwd}}` : le dossier où tourne mm ; dans un éditeur (ACP), le dossier de la session. | |
| 45 | +- `{{config.project}}` : la valeur `project` de la section `variables:` — écrite une fois dans le fichier. Une valeur peut elle-même utiliser `{{date}}`, `{{cwd}}` et `{{env.NAME}}` (`since: "{{date}}"`), pas une autre `{{config.…}}` ; un `{{config.NAME}}` absent de la section arrête mm au démarrage. | |
| 46 | +- `{{env.USER}}` : la valeur de `USER`. Un nom qui ressemble à un secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`) est refusé au chargement du fichier : le prompt va au modèle, dans les sessions et les traces. | |
| 47 | + | |
| 48 | +## Résultats mesurés | |
| 49 | + | |
| 50 | +Mesurés le 25/11/2026 avec `mm -p`, dans un Docker Sandbox (Linux arm64, CPU), llama.cpp build 12359, `USER=k33g` ; chaque question posée deux fois. | |
| 51 | + | |
| 52 | +| Question | Qwen3.5 4B | Qwen3.5 2B | | |
| 53 | +|---|---|---| | |
| 54 | +| Which project do you help with? (`{{config.project}}`) | ✅ « mini-me, a coding agent written in Go », deux fois | ✅ deux fois | | |
| 55 | +| What is today's date? | ✅ « 2026-11-25 », deux fois | ✅ deux fois | | |
| 56 | +| En quelle année sommes-nous ? | ✅ « 2026 », deux fois | ✅ deux fois | | |
| 57 | +| In which folder are you running? | ✅ le dossier, exact, deux fois | ✅ deux fois | | |
| 58 | +| Who am I? | ✅ « You are k33g. », deux fois | ✅ posée une fois | | |
| 59 | +| What is my name? / Comment je m'appelle ? | ✅ « Your name is k33g. » / « Tu t'appelles k33g. », 4 sur 4 | ❌ « My name is Ada. », 4 sur 4 | | |
| 60 | +| Do you know who I am? | ✅ « I know your name is k33g. », deux fois | ❌ « No, I don't know who you are… » | | |
| 61 | +| How many days until Christmas? | ½ 30 (juste), puis 13 | ½ 50, puis 30 (juste) | | |
| 62 | +| Quel jour de la semaine sommes-nous ? | ❌ vendredi, puis jeudi (c'est un mercredi) | ❌ mardi, puis jeudi | | |
| 63 | + | |
| 64 | +Ce que les variables apportent — la date, l'année, le dossier, le nom de l'utilisateur, les valeurs propres au fichier — les deux modèles le restituent correctement ; le 4B comprend aussi « my name » comme le nom de l'utilisateur, que le 2B prend pour le sien. Ce qu'il faut en calculer les dépasse tous les deux : le jour de la semaine (le prompt ne le donne pas), un nombre de jours. | |
| 65 | + | |
| 66 | +## Limites | |
| 67 | + | |
| 68 | +- Pas de variable pour le jour de la semaine, et aucun des deux modèles ne le calcule à partir de la date : écrivez-le dans le prompt si l'agent en a besoin. | |
| 69 | +- Une session qui passe minuit garde sa date jusqu'à `/new`. | |
| new file mode 100644 | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | +# prompt-variables — la date, le dossier et l'utilisateur dans le prompt système | ||
| 2 | + | ||
| 3 | +*[English version](README.en.md)* | ||
| 4 | + | ||
| 5 | +Un petit assistant, Ada, dont le prompt système utilise les variables du ticket 253 : les trois intégrées, et une section `variables:` de valeurs propres au fichier. Un modèle ne peut pas connaître la date du jour, le dossier où il tourne ni qui l'utilise : le prompt le lui dit. | ||
| 6 | + | ||
| 7 | +```yaml | ||
| 8 | +system: | | ||
| 9 | + Your name is Ada. | ||
| 10 | + Today is {{date}} (year-month-day). You run in the folder {{cwd}}. | ||
| 11 | + The user you are talking to is called {{env.USER}}. | ||
| 12 | + You help with the project {{config.project}}; this conversation started on {{config.since}}. | ||
| 13 | + | ||
| 14 | +variables: | ||
| 15 | + project: mini-me, a coding agent written in Go | ||
| 16 | + since: "{{date}}" | ||
| 17 | +``` | ||
| 18 | + | ||
| 19 | +| | | | ||
| 20 | +|---|---| | ||
| 21 | +| Agent | `.mm/agent.yaml`, écrit par `mm init` (usage assistant, `--project yes`), puis le prompt ci-dessus | | ||
| 22 | +| Modèle | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M`, raisonnement désactivé (Qwen3.5 2B mesuré aussi, plus bas) | | ||
| 23 | +| Serveur | llamacpp, démarré par mm quand rien ne répond (`llamacpp.autoStart: true`) | | ||
| 24 | +| Outils | aucun (`ask_user` désactivé : sans rien à chercher, Qwen3.5 2B s'en servait pour éviter de répondre dans `demos/qwen-search`) | | ||
| 25 | + | ||
| 26 | +## Lancer | ||
| 27 | + | ||
| 28 | +```bash | ||
| 29 | +cd demos/prompt-variables | ||
| 30 | +../../mm -p "What is today's date?" | ||
| 31 | +../../mm -p "Who am I?" | ||
| 32 | +../../mm # conversation | ||
| 33 | +``` | ||
| 34 | + | ||
| 35 | +`{{env.USER}}` est votre identifiant sous macOS et Linux. Sous Windows, la variable s'appelle `USERNAME` : mettez `{{env.USERNAME}}` dans le prompt. Une variable non définie est remplacée par rien, et la bannière le signale : | ||
| 36 | + | ||
| 37 | +```text | ||
| 38 | +[warning: system: {{env.USER}} — USER is not set, replaced by nothing] | ||
| 39 | +``` | ||
| 40 | + | ||
| 41 | +## Ce que deviennent les variables | ||
| 42 | + | ||
| 43 | +- `{{date}}` : `2026-11-25` — remplacée au début de la conversation (une nouvelle session, `/new`, une session reprise), pas avant chaque question, pour que le cache de prompt du serveur tienne. | ||
| 44 | +- `{{cwd}}` : le dossier où tourne mm ; dans un éditeur (ACP), le dossier de la session. | ||
| 45 | +- `{{config.project}}` : la valeur `project` de la section `variables:` — écrite une fois dans le fichier. Une valeur peut elle-même utiliser `{{date}}`, `{{cwd}}` et `{{env.NAME}}` (`since: "{{date}}"`), pas une autre `{{config.…}}` ; un `{{config.NAME}}` absent de la section arrête mm au démarrage. | ||
| 46 | +- `{{env.USER}}` : la valeur de `USER`. Un nom qui ressemble à un secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`) est refusé au chargement du fichier : le prompt va au modèle, dans les sessions et les traces. | ||
| 47 | + | ||
| 48 | +## Résultats mesurés | ||
| 49 | + | ||
| 50 | +Mesurés le 25/11/2026 avec `mm -p`, dans un Docker Sandbox (Linux arm64, CPU), llama.cpp build 12359, `USER=k33g` ; chaque question posée deux fois. | ||
| 51 | + | ||
| 52 | +| Question | Qwen3.5 4B | Qwen3.5 2B | | ||
| 53 | +|---|---|---| | ||
| 54 | +| Which project do you help with? (`{{config.project}}`) | ✅ « mini-me, a coding agent written in Go », deux fois | ✅ deux fois | | ||
| 55 | +| What is today's date? | ✅ « 2026-11-25 », deux fois | ✅ deux fois | | ||
| 56 | +| En quelle année sommes-nous ? | ✅ « 2026 », deux fois | ✅ deux fois | | ||
| 57 | +| In which folder are you running? | ✅ le dossier, exact, deux fois | ✅ deux fois | | ||
| 58 | +| Who am I? | ✅ « You are k33g. », deux fois | ✅ posée une fois | | ||
| 59 | +| What is my name? / Comment je m'appelle ? | ✅ « Your name is k33g. » / « Tu t'appelles k33g. », 4 sur 4 | ❌ « My name is Ada. », 4 sur 4 | | ||
| 60 | +| Do you know who I am? | ✅ « I know your name is k33g. », deux fois | ❌ « No, I don't know who you are… » | | ||
| 61 | +| How many days until Christmas? | ½ 30 (juste), puis 13 | ½ 50, puis 30 (juste) | | ||
| 62 | +| Quel jour de la semaine sommes-nous ? | ❌ vendredi, puis jeudi (c'est un mercredi) | ❌ mardi, puis jeudi | | ||
| 63 | + | ||
| 64 | +Ce que les variables apportent — la date, l'année, le dossier, le nom de l'utilisateur, les valeurs propres au fichier — les deux modèles le restituent correctement ; le 4B comprend aussi « my name » comme le nom de l'utilisateur, que le 2B prend pour le sien. Ce qu'il faut en calculer les dépasse tous les deux : le jour de la semaine (le prompt ne le donne pas), un nombre de jours. | ||
| 65 | + | ||
| 66 | +## Limites | ||
| 67 | + | ||
| 68 | +- Pas de variable pour le jour de la semaine, et aucun des deux modèles ne le calcule à partir de la date : écrivez-le dans le prompt si l'agent en a besoin. | ||
| 69 | +- Une session qui passe minuit garde sa date jusqu'à `/new`. | ||
modified
demos/qwen-search/README.en.md +3 -3 | @@ -7,7 +7,7 @@ A research agent that searches the internet with **skills** and the built-in `fe | ||
| 7 | 7 | | | | |
| 8 | 8 | |---|---| |
| 9 | 9 | | Agent | `.mm/agent.yaml`, written by `mm init` (usage researcher), then tuned (see below) | |
| 10 | -| Model | `unsloth/Qwen3.5-2B-GGUF:Q4_K_M` in the file; **`unsloth/Qwen3.5-4B-GGUF:Q4_K_M` recommended** (measured below) | | |
| 10 | +| Model | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (Qwen3.5 2B measured too, below: reliable for the press review only) | | |
| 11 | 11 | | Server | llamacpp, started by mm when nothing answers (`llamacpp.autoStart: true`) | |
| 12 | 12 | | Tools | `fetch_content`, `read_skill`, `save_answer` — no bash, no file editing, no `ask_user` | |
| 13 | 13 | |
| @@ -31,7 +31,7 @@ cd demos/qwen-search | ||
| 31 | 31 | ../../mm # conversation (mm finds .mm/agent.yaml) |
| 32 | 32 | ``` |
| 33 | 33 | |
| 34 | -To use the recommended model, change `model:` in `.mm/agent.yaml` to `"unsloth/Qwen3.5-4B-GGUF:Q4_K_M"`; mm downloads it on the first start. | |
| 34 | +mm downloads the model on the first start. | |
| 35 | 35 | |
| 36 | 36 | ## What changed after `mm init` |
| 37 | 37 | |
| @@ -72,5 +72,5 @@ Before "do NOT open the result pages" was added to `news-roundup`, the 4B opened | ||
| 72 | 72 | |
| 73 | 73 | - **DuckDuckGo Lite returns pages, not dated articles.** A roundup lists news sites and section pages more than today's stories. The MCP server of `demos/news-roundup` uses DuckDuckGo News (`news.js`), which needs a per-query token that a skill cannot get with `fetch_content`. |
| 74 | 74 | - **`fetch_content` reads robots.txt**, and a site may refuse it; the skill then has the excerpts only. |
| 75 | -- **The 2B is not reliable** for anything but the press review: use the 4B. | |
| 75 | +- **Qwen3.5 2B is not reliable** for anything but the press review. | |
| 76 | 76 | - The 4B is slow on a CPU (1 to 4 minutes a question here); on a Mac with Metal it is much faster. |
| @@ -7,7 +7,7 @@ A research agent that searches the internet with **skills** and the built-in `fe | |||
| 7 | | | | | 7 | | | | |
| 8 | |---|---| | 8 | |---|---| |
| 9 | | Agent | `.mm/agent.yaml`, written by `mm init` (usage researcher), then tuned (see below) | | 9 | | Agent | `.mm/agent.yaml`, written by `mm init` (usage researcher), then tuned (see below) | |
| 10 | -| Model | `unsloth/Qwen3.5-2B-GGUF:Q4_K_M` in the file; **`unsloth/Qwen3.5-4B-GGUF:Q4_K_M` recommended** (measured below) | | 10 | +| Model | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (Qwen3.5 2B measured too, below: reliable for the press review only) | |
| 11 | | Server | llamacpp, started by mm when nothing answers (`llamacpp.autoStart: true`) | | 11 | | Server | llamacpp, started by mm when nothing answers (`llamacpp.autoStart: true`) | |
| 12 | | Tools | `fetch_content`, `read_skill`, `save_answer` — no bash, no file editing, no `ask_user` | | 12 | | Tools | `fetch_content`, `read_skill`, `save_answer` — no bash, no file editing, no `ask_user` | |
| 13 | 13 | ||
| @@ -31,7 +31,7 @@ cd demos/qwen-search | |||
| 31 | ../../mm # conversation (mm finds .mm/agent.yaml) | 31 | ../../mm # conversation (mm finds .mm/agent.yaml) |
| 32 | ``` | 32 | ``` |
| 33 | 33 | ||
| 34 | -To use the recommended model, change `model:` in `.mm/agent.yaml` to `"unsloth/Qwen3.5-4B-GGUF:Q4_K_M"`; mm downloads it on the first start. | 34 | +mm downloads the model on the first start. |
| 35 | 35 | ||
| 36 | ## What changed after `mm init` | 36 | ## What changed after `mm init` |
| 37 | 37 | ||
| @@ -72,5 +72,5 @@ Before "do NOT open the result pages" was added to `news-roundup`, the 4B opened | |||
| 72 | 72 | ||
| 73 | - **DuckDuckGo Lite returns pages, not dated articles.** A roundup lists news sites and section pages more than today's stories. The MCP server of `demos/news-roundup` uses DuckDuckGo News (`news.js`), which needs a per-query token that a skill cannot get with `fetch_content`. | 73 | - **DuckDuckGo Lite returns pages, not dated articles.** A roundup lists news sites and section pages more than today's stories. The MCP server of `demos/news-roundup` uses DuckDuckGo News (`news.js`), which needs a per-query token that a skill cannot get with `fetch_content`. |
| 74 | - **`fetch_content` reads robots.txt**, and a site may refuse it; the skill then has the excerpts only. | 74 | - **`fetch_content` reads robots.txt**, and a site may refuse it; the skill then has the excerpts only. |
| 75 | -- **The 2B is not reliable** for anything but the press review: use the 4B. | 75 | +- **Qwen3.5 2B is not reliable** for anything but the press review. |
| 76 | - The 4B is slow on a CPU (1 to 4 minutes a question here); on a Mac with Metal it is much faster. | 76 | - The 4B is slow on a CPU (1 to 4 minutes a question here); on a Mac with Metal it is much faster. |
modified
demos/qwen-search/README.fr.md +3 -3 | @@ -7,7 +7,7 @@ Un agent de recherche qui interroge internet avec des **skills** et le seul outi | ||
| 7 | 7 | | | | |
| 8 | 8 | |---|---| |
| 9 | 9 | | Agent | `.mm/agent.yaml`, écrit par `mm init` (usage researcher), puis ajusté (voir plus bas) | |
| 10 | -| Modèle | `unsloth/Qwen3.5-2B-GGUF:Q4_K_M` dans le fichier ; **`unsloth/Qwen3.5-4B-GGUF:Q4_K_M` recommandé** (mesures plus bas) | | |
| 10 | +| Modèle | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (Qwen3.5 2B mesuré aussi, plus bas : fiable pour la seule revue de presse) | | |
| 11 | 11 | | Serveur | llamacpp, démarré par mm quand rien ne répond (`llamacpp.autoStart: true`) | |
| 12 | 12 | | Outils | `fetch_content`, `read_skill`, `save_answer` — ni bash, ni édition de fichiers, ni `ask_user` | |
| 13 | 13 | |
| @@ -31,7 +31,7 @@ cd demos/qwen-search | ||
| 31 | 31 | ../../mm # conversation (mm trouve .mm/agent.yaml) |
| 32 | 32 | ``` |
| 33 | 33 | |
| 34 | -Pour le modèle recommandé, mettez `model:` à `"unsloth/Qwen3.5-4B-GGUF:Q4_K_M"` dans `.mm/agent.yaml` ; mm le télécharge au premier démarrage. | |
| 34 | +mm télécharge le modèle au premier démarrage. | |
| 35 | 35 | |
| 36 | 36 | ## Ce qui a changé après `mm init` |
| 37 | 37 | |
| @@ -72,5 +72,5 @@ Avant l'ajout de « do NOT open the result pages » dans `news-roundup`, le 4B o | ||
| 72 | 72 | |
| 73 | 73 | - **DuckDuckGo Lite renvoie des pages, pas des articles datés.** Une revue de presse liste des sites d'actualité et des rubriques plus que les articles du jour. Le serveur MCP de `demos/news-roundup` utilise DuckDuckGo News (`news.js`), qui demande un jeton par requête qu'une skill ne peut pas obtenir avec `fetch_content`. |
| 74 | 74 | - **`fetch_content` lit robots.txt**, et un site peut le refuser ; la skill n'a alors que les extraits. |
| 75 | -- **Le 2B n'est fiable que pour la revue de presse** : utilisez le 4B. | |
| 75 | +- **Qwen3.5 2B n'est fiable que pour la revue de presse.** | |
| 76 | 76 | - Le 4B est lent sur CPU (1 à 4 minutes par question ici) ; sur un Mac avec Metal il est bien plus rapide. |
| @@ -7,7 +7,7 @@ Un agent de recherche qui interroge internet avec des **skills** et le seul outi | |||
| 7 | | | | | 7 | | | | |
| 8 | |---|---| | 8 | |---|---| |
| 9 | | Agent | `.mm/agent.yaml`, écrit par `mm init` (usage researcher), puis ajusté (voir plus bas) | | 9 | | Agent | `.mm/agent.yaml`, écrit par `mm init` (usage researcher), puis ajusté (voir plus bas) | |
| 10 | -| Modèle | `unsloth/Qwen3.5-2B-GGUF:Q4_K_M` dans le fichier ; **`unsloth/Qwen3.5-4B-GGUF:Q4_K_M` recommandé** (mesures plus bas) | | 10 | +| Modèle | `unsloth/Qwen3.5-4B-GGUF:Q4_K_M` (Qwen3.5 2B mesuré aussi, plus bas : fiable pour la seule revue de presse) | |
| 11 | | Serveur | llamacpp, démarré par mm quand rien ne répond (`llamacpp.autoStart: true`) | | 11 | | Serveur | llamacpp, démarré par mm quand rien ne répond (`llamacpp.autoStart: true`) | |
| 12 | | Outils | `fetch_content`, `read_skill`, `save_answer` — ni bash, ni édition de fichiers, ni `ask_user` | | 12 | | Outils | `fetch_content`, `read_skill`, `save_answer` — ni bash, ni édition de fichiers, ni `ask_user` | |
| 13 | 13 | ||
| @@ -31,7 +31,7 @@ cd demos/qwen-search | |||
| 31 | ../../mm # conversation (mm trouve .mm/agent.yaml) | 31 | ../../mm # conversation (mm trouve .mm/agent.yaml) |
| 32 | ``` | 32 | ``` |
| 33 | 33 | ||
| 34 | -Pour le modèle recommandé, mettez `model:` à `"unsloth/Qwen3.5-4B-GGUF:Q4_K_M"` dans `.mm/agent.yaml` ; mm le télécharge au premier démarrage. | 34 | +mm télécharge le modèle au premier démarrage. |
| 35 | 35 | ||
| 36 | ## Ce qui a changé après `mm init` | 36 | ## Ce qui a changé après `mm init` |
| 37 | 37 | ||
| @@ -72,5 +72,5 @@ Avant l'ajout de « do NOT open the result pages » dans `news-roundup`, le 4B o | |||
| 72 | 72 | ||
| 73 | - **DuckDuckGo Lite renvoie des pages, pas des articles datés.** Une revue de presse liste des sites d'actualité et des rubriques plus que les articles du jour. Le serveur MCP de `demos/news-roundup` utilise DuckDuckGo News (`news.js`), qui demande un jeton par requête qu'une skill ne peut pas obtenir avec `fetch_content`. | 73 | - **DuckDuckGo Lite renvoie des pages, pas des articles datés.** Une revue de presse liste des sites d'actualité et des rubriques plus que les articles du jour. Le serveur MCP de `demos/news-roundup` utilise DuckDuckGo News (`news.js`), qui demande un jeton par requête qu'une skill ne peut pas obtenir avec `fetch_content`. |
| 74 | - **`fetch_content` lit robots.txt**, et un site peut le refuser ; la skill n'a alors que les extraits. | 74 | - **`fetch_content` lit robots.txt**, et un site peut le refuser ; la skill n'a alors que les extraits. |
| 75 | -- **Le 2B n'est fiable que pour la revue de presse** : utilisez le 4B. | 75 | +- **Qwen3.5 2B n'est fiable que pour la revue de presse.** |
| 76 | - Le 4B est lent sur CPU (1 à 4 minutes par question ici) ; sur un Mac avec Metal il est bien plus rapide. | 76 | - Le 4B est lent sur CPU (1 à 4 minutes par question ici) ; sur un Mac avec Metal il est bien plus rapide. |
modified
docs/en/reference/configuration.md +2 -1 | @@ -23,7 +23,8 @@ Where `mm` looks for this file: [Configuration file resolution](cli.md#configura | ||
| 23 | 23 | | `showThinking` | bool | `true` | Show what a thinking model reasons about before it answers. Only the display is optional: the reasoning is always read off the wire, because it is what keeps the watchdog alive while the model thinks. See [Thinking models](../explanation/thinking-models.md). | |
| 24 | 24 | | `showCompletionTime` | bool | `true` | Window mode: show `⏱ <duration>` in the status bar, ticking while a turn or an `/ask` runs, then the final duration until the next question. `false` keeps the status bar to its counters. See [the window mode](cli.md). | |
| 25 | 25 | | `showSpeed` | bool | `true` | The model's generation speed in tokens per second. Window mode: `⚡ ~58 tok/s` in the status bar while a model call streams (an estimate, refreshed every half second), then `⚡ 59.9 tok/s`, the turn's average, until the next answer starts. The turn's average is its tokens over the time the model spent generating them: the tools' run time and the prompt reading are left out. Source: the server's own `timings` when it sends them (llama-server, MLX-Serve), otherwise measured by mm from the first streamed token to the last. Editor (ACP): each finished call and turn goes in a `usage_update`'s `_meta.mm` (`tokensPerSecond`, `scope` `call` or `turn`, `source` `server` or `measured`), which a client that does not know the key ignores. The line mode shows nothing. `false` turns it off. | |
| 26 | -| `system` | string | built-in prompt | The system prompt, first message of every history. | | |
| 26 | +| `system` | string | built-in prompt | The system prompt, first message of every history. Three variables are replaced each time a conversation starts (a new session, `/new`, a resumed one — not before every question, so the server's prompt cache holds): `{{date}}` today's date, `YYYY-MM-DD`, local time; `{{cwd}}` the directory the conversation works in (over ACP, the session's own); `{{env.NAME}}` the variable NAME — unset, replaced by nothing, with a banner warning; `{{config.NAME}}` the value NAME of the `variables` section. A NAME that looks like a secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`, `…CREDENTIALS…`) is a configuration error: the prompt goes to the model, the sessions and the traces. Spaces inside the braces are allowed (`{{ date }}`). Any other `{{…}}` is left as written; `\{{date}}` writes `{{date}}`. Not replaced in AGENTS.md. A session that crosses midnight keeps its date until `/new`. | | |
| 27 | +| `variables` | map name → string | none | The file's own values for the system prompt, used there as `{{config.NAME}}`. A value may hold `{{date}}`, `{{cwd}}` and `{{env.NAME}}` (expanded, the same secret check), not another `{{config.…}}`. Names: letters, digits, `_` and `-`, not starting with a digit. A `{{config.NAME}}` the section does not have is a configuration error. Example: `variables: {project: "mini-me, a coding agent written in Go"}`, then `You help with {{config.project}}.` in `system`. | | |
| 27 | 28 | | `turnReminder` | string | `""` | A text appended to every question the model reads, under a `[reminder]` line, after the `preGeneration` hooks, in every front end (line mode, window, `-p`, editor). Kept in the history, like a hook's context; a question recalled with ↑ comes back without it. For a small model, a rule placed next to the question is followed more often than the same rule in the system prompt: measured in `demos/lfm-coder`, a rule asking it to call `ask_user` when a decision is missing was followed 0 times out of 5 from the system prompt, and 3 out of 3 next to the question with the exact call shape. Empty = none. | |
| 28 | 29 | | `structuredOutput` | string (Go declarations) | `""` | The shape every answer must follow, as JSON: Go `type` declarations and one `var` naming the root of the answer. See [`structuredOutput`](#structuredoutput) below. Empty = free-text answers. Incompatible with any declared tool. | |
| 29 | 30 | | `decision` | mapping or absent | absent | Makes the agent a **decider**: its model is a decision model served by `POST /v1/systemone`, and every message it receives is answered with these questions. See [`decision`](#decision) below. Providers `llamacpp`, `llmman`, `ollama`, `openai` only. | |
| @@ -23,7 +23,8 @@ Where `mm` looks for this file: [Configuration file resolution](cli.md#configura | |||
| 23 | | `showThinking` | bool | `true` | Show what a thinking model reasons about before it answers. Only the display is optional: the reasoning is always read off the wire, because it is what keeps the watchdog alive while the model thinks. See [Thinking models](../explanation/thinking-models.md). | | 23 | | `showThinking` | bool | `true` | Show what a thinking model reasons about before it answers. Only the display is optional: the reasoning is always read off the wire, because it is what keeps the watchdog alive while the model thinks. See [Thinking models](../explanation/thinking-models.md). | |
| 24 | | `showCompletionTime` | bool | `true` | Window mode: show `⏱ <duration>` in the status bar, ticking while a turn or an `/ask` runs, then the final duration until the next question. `false` keeps the status bar to its counters. See [the window mode](cli.md). | | 24 | | `showCompletionTime` | bool | `true` | Window mode: show `⏱ <duration>` in the status bar, ticking while a turn or an `/ask` runs, then the final duration until the next question. `false` keeps the status bar to its counters. See [the window mode](cli.md). | |
| 25 | | `showSpeed` | bool | `true` | The model's generation speed in tokens per second. Window mode: `⚡ ~58 tok/s` in the status bar while a model call streams (an estimate, refreshed every half second), then `⚡ 59.9 tok/s`, the turn's average, until the next answer starts. The turn's average is its tokens over the time the model spent generating them: the tools' run time and the prompt reading are left out. Source: the server's own `timings` when it sends them (llama-server, MLX-Serve), otherwise measured by mm from the first streamed token to the last. Editor (ACP): each finished call and turn goes in a `usage_update`'s `_meta.mm` (`tokensPerSecond`, `scope` `call` or `turn`, `source` `server` or `measured`), which a client that does not know the key ignores. The line mode shows nothing. `false` turns it off. | | 25 | | `showSpeed` | bool | `true` | The model's generation speed in tokens per second. Window mode: `⚡ ~58 tok/s` in the status bar while a model call streams (an estimate, refreshed every half second), then `⚡ 59.9 tok/s`, the turn's average, until the next answer starts. The turn's average is its tokens over the time the model spent generating them: the tools' run time and the prompt reading are left out. Source: the server's own `timings` when it sends them (llama-server, MLX-Serve), otherwise measured by mm from the first streamed token to the last. Editor (ACP): each finished call and turn goes in a `usage_update`'s `_meta.mm` (`tokensPerSecond`, `scope` `call` or `turn`, `source` `server` or `measured`), which a client that does not know the key ignores. The line mode shows nothing. `false` turns it off. | |
| 26 | -| `system` | string | built-in prompt | The system prompt, first message of every history. | | 26 | +| `system` | string | built-in prompt | The system prompt, first message of every history. Three variables are replaced each time a conversation starts (a new session, `/new`, a resumed one — not before every question, so the server's prompt cache holds): `{{date}}` today's date, `YYYY-MM-DD`, local time; `{{cwd}}` the directory the conversation works in (over ACP, the session's own); `{{env.NAME}}` the variable NAME — unset, replaced by nothing, with a banner warning; `{{config.NAME}}` the value NAME of the `variables` section. A NAME that looks like a secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`, `…CREDENTIALS…`) is a configuration error: the prompt goes to the model, the sessions and the traces. Spaces inside the braces are allowed (`{{ date }}`). Any other `{{…}}` is left as written; `\{{date}}` writes `{{date}}`. Not replaced in AGENTS.md. A session that crosses midnight keeps its date until `/new`. | |
| 27 | +| `variables` | map name → string | none | The file's own values for the system prompt, used there as `{{config.NAME}}`. A value may hold `{{date}}`, `{{cwd}}` and `{{env.NAME}}` (expanded, the same secret check), not another `{{config.…}}`. Names: letters, digits, `_` and `-`, not starting with a digit. A `{{config.NAME}}` the section does not have is a configuration error. Example: `variables: {project: "mini-me, a coding agent written in Go"}`, then `You help with {{config.project}}.` in `system`. | | ||
| 27 | | `turnReminder` | string | `""` | A text appended to every question the model reads, under a `[reminder]` line, after the `preGeneration` hooks, in every front end (line mode, window, `-p`, editor). Kept in the history, like a hook's context; a question recalled with ↑ comes back without it. For a small model, a rule placed next to the question is followed more often than the same rule in the system prompt: measured in `demos/lfm-coder`, a rule asking it to call `ask_user` when a decision is missing was followed 0 times out of 5 from the system prompt, and 3 out of 3 next to the question with the exact call shape. Empty = none. | | 28 | | `turnReminder` | string | `""` | A text appended to every question the model reads, under a `[reminder]` line, after the `preGeneration` hooks, in every front end (line mode, window, `-p`, editor). Kept in the history, like a hook's context; a question recalled with ↑ comes back without it. For a small model, a rule placed next to the question is followed more often than the same rule in the system prompt: measured in `demos/lfm-coder`, a rule asking it to call `ask_user` when a decision is missing was followed 0 times out of 5 from the system prompt, and 3 out of 3 next to the question with the exact call shape. Empty = none. | |
| 28 | | `structuredOutput` | string (Go declarations) | `""` | The shape every answer must follow, as JSON: Go `type` declarations and one `var` naming the root of the answer. See [`structuredOutput`](#structuredoutput) below. Empty = free-text answers. Incompatible with any declared tool. | | 29 | | `structuredOutput` | string (Go declarations) | `""` | The shape every answer must follow, as JSON: Go `type` declarations and one `var` naming the root of the answer. See [`structuredOutput`](#structuredoutput) below. Empty = free-text answers. Incompatible with any declared tool. | |
| 29 | | `decision` | mapping or absent | absent | Makes the agent a **decider**: its model is a decision model served by `POST /v1/systemone`, and every message it receives is answered with these questions. See [`decision`](#decision) below. Providers `llamacpp`, `llmman`, `ollama`, `openai` only. | | 30 | | `decision` | mapping or absent | absent | Makes the agent a **decider**: its model is a decision model served by `POST /v1/systemone`, and every message it receives is answered with these questions. See [`decision`](#decision) below. Providers `llamacpp`, `llmman`, `ollama`, `openai` only. | |
modified
docs/fr/reference/configuration.md +2 -1 | @@ -23,7 +23,8 @@ Où `mm` cherche ce fichier : [Résolution du fichier de configuration](cli.md#r | ||
| 23 | 23 | | `showThinking` | booléen | `true` | Affiche ce qu'un modèle à raisonnement réfléchit avant de répondre. Seul l'affichage est optionnel : le raisonnement est toujours lu sur le fil, car c'est lui qui maintient le chien de garde en vie pendant que le modèle réfléchit. Voir [Modèles à raisonnement](../explanation/thinking-models.md). | |
| 24 | 24 | | `showCompletionTime` | booléen | `true` | Mode fenêtre : afficher `⏱ <durée>` dans la barre d'état, qui défile pendant un tour ou un `/ask`, puis la durée finale jusqu'à la question suivante. `false` limite la barre d'état à ses compteurs. Voir [le mode fenêtre](cli.md). | |
| 25 | 25 | | `showSpeed` | booléen | `true` | La vitesse de génération du modèle, en tokens par seconde. Mode fenêtre : `⚡ ~58 tok/s` dans la barre d'état pendant qu'un appel au modèle est en cours (une estimation, mise à jour toutes les demi-secondes), puis `⚡ 59.9 tok/s`, la moyenne du tour, jusqu'au début de la réponse suivante. La moyenne du tour est le nombre de tokens divisé par le temps passé par le modèle à les générer : le temps des outils et celui de la lecture du prompt sont exclus. Source : les `timings` du serveur quand il en envoie (llama-server, MLX-Serve), sinon une mesure de mm entre le premier et le dernier token reçus. Éditeur (ACP) : chaque appel et chaque tour terminés vont dans le `_meta.mm` d'un `usage_update` (`tokensPerSecond`, `scope` `call` ou `turn`, `source` `server` ou `measured`), qu'un client qui ne connaît pas la clé ignore. Le mode ligne n'affiche rien. `false` le désactive. | |
| 26 | -| `system` | chaîne | prompt intégré | Le prompt système, premier message de chaque historique. | | |
| 26 | +| `system` | chaîne | prompt intégré | Le prompt système, premier message de chaque historique. Trois variables sont remplacées à chaque début de conversation (une nouvelle session, `/new`, une session reprise — pas avant chaque question, pour que le cache de prompt du serveur tienne) : `{{date}}` la date du jour, `AAAA-MM-JJ`, heure locale ; `{{cwd}}` le dossier où la conversation travaille (en ACP, celui de la session) ; `{{env.NAME}}` la variable NAME — non définie, remplacée par rien, avec un avertissement dans la bannière ; `{{config.NAME}}` la valeur NAME de la section `variables`. Un NAME qui ressemble à un secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`, `…CREDENTIALS…`) est une erreur de configuration : le prompt va au modèle, dans les sessions et les traces. Les espaces dans les accolades sont acceptés (`{{ date }}`). Tout autre `{{…}}` est laissé tel quel ; `\{{date}}` écrit `{{date}}`. Non remplacées dans AGENTS.md. Une session qui passe minuit garde sa date jusqu'à `/new`. | | |
| 27 | +| `variables` | dictionnaire nom → chaîne | aucune | Les valeurs propres au fichier pour le prompt système, utilisées comme `{{config.NAME}}`. Une valeur peut contenir `{{date}}`, `{{cwd}}` et `{{env.NAME}}` (remplacées, avec le même contrôle des secrets), pas une autre `{{config.…}}`. Noms : lettres, chiffres, `_` et `-`, sans commencer par un chiffre. Un `{{config.NAME}}` absent de la section est une erreur de configuration. Exemple : `variables: {project: "mini-me, a coding agent written in Go"}`, puis `You help with {{config.project}}.` dans `system`. | | |
| 27 | 28 | | `turnReminder` | chaîne | `""` | Un texte ajouté à chaque question que lit le modèle, sous une ligne `[reminder]`, après les hooks `preGeneration`, dans toutes les interfaces (mode ligne, fenêtre, `-p`, éditeur). Gardé dans l'historique, comme le contexte d'un hook ; une question rappelée avec ↑ revient sans lui. Pour un petit modèle, une règle placée à côté de la question est mieux suivie que la même règle dans le prompt système : mesuré dans `demos/lfm-coder`, une règle lui demandant d'appeler `ask_user` quand une décision manque a été suivie 0 fois sur 5 depuis le prompt système, et 3 fois sur 3 à côté de la question avec la forme exacte de l'appel. Vide = aucun. | |
| 28 | 29 | | `structuredOutput` | chaîne (déclarations Go) | `""` | La forme que doit suivre chaque réponse, en JSON : des déclarations `type` Go et une `var` qui nomme la racine de la réponse. Voir [`structuredOutput`](#structuredoutput) ci-dessous. Vide = réponses en texte libre. Incompatible avec tout outil déclaré. | |
| 29 | 30 | | `decision` | mapping ou absent | absent | Fait de l'agent un **décideur** : son modèle est un modèle de décision servi par `POST /v1/systemone`, et chaque message reçu obtient pour réponse ces questions. Voir [`decision`](#decision) ci-dessous. Fournisseurs `llamacpp`, `llmman`, `ollama`, `openai` seulement. | |
| @@ -23,7 +23,8 @@ Où `mm` cherche ce fichier : [Résolution du fichier de configuration](cli.md#r | |||
| 23 | | `showThinking` | booléen | `true` | Affiche ce qu'un modèle à raisonnement réfléchit avant de répondre. Seul l'affichage est optionnel : le raisonnement est toujours lu sur le fil, car c'est lui qui maintient le chien de garde en vie pendant que le modèle réfléchit. Voir [Modèles à raisonnement](../explanation/thinking-models.md). | | 23 | | `showThinking` | booléen | `true` | Affiche ce qu'un modèle à raisonnement réfléchit avant de répondre. Seul l'affichage est optionnel : le raisonnement est toujours lu sur le fil, car c'est lui qui maintient le chien de garde en vie pendant que le modèle réfléchit. Voir [Modèles à raisonnement](../explanation/thinking-models.md). | |
| 24 | | `showCompletionTime` | booléen | `true` | Mode fenêtre : afficher `⏱ <durée>` dans la barre d'état, qui défile pendant un tour ou un `/ask`, puis la durée finale jusqu'à la question suivante. `false` limite la barre d'état à ses compteurs. Voir [le mode fenêtre](cli.md). | | 24 | | `showCompletionTime` | booléen | `true` | Mode fenêtre : afficher `⏱ <durée>` dans la barre d'état, qui défile pendant un tour ou un `/ask`, puis la durée finale jusqu'à la question suivante. `false` limite la barre d'état à ses compteurs. Voir [le mode fenêtre](cli.md). | |
| 25 | | `showSpeed` | booléen | `true` | La vitesse de génération du modèle, en tokens par seconde. Mode fenêtre : `⚡ ~58 tok/s` dans la barre d'état pendant qu'un appel au modèle est en cours (une estimation, mise à jour toutes les demi-secondes), puis `⚡ 59.9 tok/s`, la moyenne du tour, jusqu'au début de la réponse suivante. La moyenne du tour est le nombre de tokens divisé par le temps passé par le modèle à les générer : le temps des outils et celui de la lecture du prompt sont exclus. Source : les `timings` du serveur quand il en envoie (llama-server, MLX-Serve), sinon une mesure de mm entre le premier et le dernier token reçus. Éditeur (ACP) : chaque appel et chaque tour terminés vont dans le `_meta.mm` d'un `usage_update` (`tokensPerSecond`, `scope` `call` ou `turn`, `source` `server` ou `measured`), qu'un client qui ne connaît pas la clé ignore. Le mode ligne n'affiche rien. `false` le désactive. | | 25 | | `showSpeed` | booléen | `true` | La vitesse de génération du modèle, en tokens par seconde. Mode fenêtre : `⚡ ~58 tok/s` dans la barre d'état pendant qu'un appel au modèle est en cours (une estimation, mise à jour toutes les demi-secondes), puis `⚡ 59.9 tok/s`, la moyenne du tour, jusqu'au début de la réponse suivante. La moyenne du tour est le nombre de tokens divisé par le temps passé par le modèle à les générer : le temps des outils et celui de la lecture du prompt sont exclus. Source : les `timings` du serveur quand il en envoie (llama-server, MLX-Serve), sinon une mesure de mm entre le premier et le dernier token reçus. Éditeur (ACP) : chaque appel et chaque tour terminés vont dans le `_meta.mm` d'un `usage_update` (`tokensPerSecond`, `scope` `call` ou `turn`, `source` `server` ou `measured`), qu'un client qui ne connaît pas la clé ignore. Le mode ligne n'affiche rien. `false` le désactive. | |
| 26 | -| `system` | chaîne | prompt intégré | Le prompt système, premier message de chaque historique. | | 26 | +| `system` | chaîne | prompt intégré | Le prompt système, premier message de chaque historique. Trois variables sont remplacées à chaque début de conversation (une nouvelle session, `/new`, une session reprise — pas avant chaque question, pour que le cache de prompt du serveur tienne) : `{{date}}` la date du jour, `AAAA-MM-JJ`, heure locale ; `{{cwd}}` le dossier où la conversation travaille (en ACP, celui de la session) ; `{{env.NAME}}` la variable NAME — non définie, remplacée par rien, avec un avertissement dans la bannière ; `{{config.NAME}}` la valeur NAME de la section `variables`. Un NAME qui ressemble à un secret (`…_KEY`, `…_TOKEN`, `…_SECRET`, `…PASSWORD…`, `…CREDENTIALS…`) est une erreur de configuration : le prompt va au modèle, dans les sessions et les traces. Les espaces dans les accolades sont acceptés (`{{ date }}`). Tout autre `{{…}}` est laissé tel quel ; `\{{date}}` écrit `{{date}}`. Non remplacées dans AGENTS.md. Une session qui passe minuit garde sa date jusqu'à `/new`. | |
| 27 | +| `variables` | dictionnaire nom → chaîne | aucune | Les valeurs propres au fichier pour le prompt système, utilisées comme `{{config.NAME}}`. Une valeur peut contenir `{{date}}`, `{{cwd}}` et `{{env.NAME}}` (remplacées, avec le même contrôle des secrets), pas une autre `{{config.…}}`. Noms : lettres, chiffres, `_` et `-`, sans commencer par un chiffre. Un `{{config.NAME}}` absent de la section est une erreur de configuration. Exemple : `variables: {project: "mini-me, a coding agent written in Go"}`, puis `You help with {{config.project}}.` dans `system`. | | ||
| 27 | | `turnReminder` | chaîne | `""` | Un texte ajouté à chaque question que lit le modèle, sous une ligne `[reminder]`, après les hooks `preGeneration`, dans toutes les interfaces (mode ligne, fenêtre, `-p`, éditeur). Gardé dans l'historique, comme le contexte d'un hook ; une question rappelée avec ↑ revient sans lui. Pour un petit modèle, une règle placée à côté de la question est mieux suivie que la même règle dans le prompt système : mesuré dans `demos/lfm-coder`, une règle lui demandant d'appeler `ask_user` quand une décision manque a été suivie 0 fois sur 5 depuis le prompt système, et 3 fois sur 3 à côté de la question avec la forme exacte de l'appel. Vide = aucun. | | 28 | | `turnReminder` | chaîne | `""` | Un texte ajouté à chaque question que lit le modèle, sous une ligne `[reminder]`, après les hooks `preGeneration`, dans toutes les interfaces (mode ligne, fenêtre, `-p`, éditeur). Gardé dans l'historique, comme le contexte d'un hook ; une question rappelée avec ↑ revient sans lui. Pour un petit modèle, une règle placée à côté de la question est mieux suivie que la même règle dans le prompt système : mesuré dans `demos/lfm-coder`, une règle lui demandant d'appeler `ask_user` quand une décision manque a été suivie 0 fois sur 5 depuis le prompt système, et 3 fois sur 3 à côté de la question avec la forme exacte de l'appel. Vide = aucun. | |
| 28 | | `structuredOutput` | chaîne (déclarations Go) | `""` | La forme que doit suivre chaque réponse, en JSON : des déclarations `type` Go et une `var` qui nomme la racine de la réponse. Voir [`structuredOutput`](#structuredoutput) ci-dessous. Vide = réponses en texte libre. Incompatible avec tout outil déclaré. | | 29 | | `structuredOutput` | chaîne (déclarations Go) | `""` | La forme que doit suivre chaque réponse, en JSON : des déclarations `type` Go et une `var` qui nomme la racine de la réponse. Voir [`structuredOutput`](#structuredoutput) ci-dessous. Vide = réponses en texte libre. Incompatible avec tout outil déclaré. | |
| 29 | | `decision` | mapping ou absent | absent | Fait de l'agent un **décideur** : son modèle est un modèle de décision servi par `POST /v1/systemone`, et chaque message reçu obtient pour réponse ces questions. Voir [`decision`](#decision) ci-dessous. Fournisseurs `llamacpp`, `llmman`, `ollama`, `openai` seulement. | | 30 | | `decision` | mapping ou absent | absent | Fait de l'agent un **décideur** : son modèle est un modèle de décision servi par `POST /v1/systemone`, et chaque message reçu obtient pour réponse ces questions. Voir [`decision`](#decision) ci-dessous. Fournisseurs `llamacpp`, `llmman`, `ollama`, `openai` seulement. | |
modified
internal/agent/structured.go +5 -1 | @@ -4,9 +4,11 @@ import ( | ||
| 4 | 4 | "context" |
| 5 | 5 | "fmt" |
| 6 | 6 | "io" |
| 7 | + "time" | |
| 7 | 8 | |
| 8 | 9 | "github.com/firebase/genkit/go/ai" |
| 9 | 10 | |
| 11 | + "mm/internal/config" | |
| 10 | 12 | "mm/internal/engine" |
| 11 | 13 | "mm/internal/session" |
| 12 | 14 | "mm/internal/ui" |
| @@ -28,7 +30,9 @@ func RunStructuredPrompt(ctx context.Context, e *engine.Engine, system, prompt s | ||
| 28 | 30 | ui.SetActive(quietSink{}) |
| 29 | 31 | defer ui.SetActive(nil) |
| 30 | 32 | |
| 31 | - messages := append(session.Fresh(system), ai.NewUserTextMessage(prompt)) | |
| 33 | + // The prompt's variables, as everywhere else (ticket 253); no AGENTS.md | |
| 34 | + // here, as before. | |
| 35 | + messages := append(session.Fresh(config.ExpandPrompt(system, "", time.Now())), ai.NewUserTextMessage(prompt)) | |
| 32 | 36 | resp, _, err := e.Generate(ctx, messages, nil) |
| 33 | 37 | if err != nil { |
| 34 | 38 | return err |
| @@ -4,9 +4,11 @@ import ( | |||
| 4 | "context" | 4 | "context" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | "io" | 6 | "io" |
| 7 | + "time" | ||
| 7 | 8 | ||
| 8 | "github.com/firebase/genkit/go/ai" | 9 | "github.com/firebase/genkit/go/ai" |
| 9 | 10 | ||
| 11 | + "mm/internal/config" | ||
| 10 | "mm/internal/engine" | 12 | "mm/internal/engine" |
| 11 | "mm/internal/session" | 13 | "mm/internal/session" |
| 12 | "mm/internal/ui" | 14 | "mm/internal/ui" |
| @@ -28,7 +30,9 @@ func RunStructuredPrompt(ctx context.Context, e *engine.Engine, system, prompt s | |||
| 28 | ui.SetActive(quietSink{}) | 30 | ui.SetActive(quietSink{}) |
| 29 | defer ui.SetActive(nil) | 31 | defer ui.SetActive(nil) |
| 30 | 32 | ||
| 31 | - messages := append(session.Fresh(system), ai.NewUserTextMessage(prompt)) | 33 | + // The prompt's variables, as everywhere else (ticket 253); no AGENTS.md |
| 34 | + // here, as before. | ||
| 35 | + messages := append(session.Fresh(config.ExpandPrompt(system, "", time.Now())), ai.NewUserTextMessage(prompt)) | ||
| 32 | resp, _, err := e.Generate(ctx, messages, nil) | 36 | resp, _, err := e.Generate(ctx, messages, nil) |
| 33 | if err != nil { | 37 | if err != nil { |
| 34 | return err | 38 | return err |
modified
internal/agentinit/render.go +1 -0 | @@ -99,6 +99,7 @@ func Render(s Settings) string { | ||
| 99 | 99 | b.WriteString("\n") |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | + b.WriteString("# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts.\n") | |
| 102 | 103 | b.WriteString("system: |\n") |
| 103 | 104 | if c.Name != "" { |
| 104 | 105 | fmt.Fprintf(&b, " Your name is %s.\n", c.Name) |
| @@ -99,6 +99,7 @@ func Render(s Settings) string { | |||
| 99 | b.WriteString("\n") | 99 | b.WriteString("\n") |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | + b.WriteString("# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts.\n") | ||
| 102 | b.WriteString("system: |\n") | 103 | b.WriteString("system: |\n") |
| 103 | if c.Name != "" { | 104 | if c.Name != "" { |
| 104 | fmt.Fprintf(&b, " Your name is %s.\n", c.Name) | 105 | fmt.Fprintf(&b, " Your name is %s.\n", c.Name) |
modified
internal/agentinit/testdata/preview-developer.yaml +1 -0 | @@ -83,6 +83,7 @@ acp: | ||
| 83 | 83 | name: developer |
| 84 | 84 | title: "Developer (developer)" |
| 85 | 85 | |
| 86 | +# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts. | |
| 86 | 87 | system: | |
| 87 | 88 | Your name is developer. |
| 88 | 89 | You are a coding agent working in a terminal, in the user's project. |
| @@ -83,6 +83,7 @@ acp: | |||
| 83 | name: developer | 83 | name: developer |
| 84 | title: "Developer (developer)" | 84 | title: "Developer (developer)" |
| 85 | 85 | ||
| 86 | +# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts. | ||
| 86 | system: | | 87 | system: | |
| 87 | Your name is developer. | 88 | Your name is developer. |
| 88 | You are a coding agent working in a terminal, in the user's project. | 89 | You are a coding agent working in a terminal, in the user's project. |
modified
internal/agentinit/testdata/preview-researcher.yaml +1 -0 | @@ -81,6 +81,7 @@ acp: | ||
| 81 | 81 | name: researcher |
| 82 | 82 | title: "Researcher (researcher)" |
| 83 | 83 | |
| 84 | +# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts. | |
| 84 | 85 | system: | |
| 85 | 86 | Your name is researcher. |
| 86 | 87 | You are a research assistant. To answer, read the web pages the user |
| @@ -81,6 +81,7 @@ acp: | |||
| 81 | name: researcher | 81 | name: researcher |
| 82 | title: "Researcher (researcher)" | 82 | title: "Researcher (researcher)" |
| 83 | 83 | ||
| 84 | +# Variables: {{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}} (a variables: section) — replaced when a conversation starts. | ||
| 84 | system: | | 85 | system: | |
| 85 | Your name is researcher. | 86 | Your name is researcher. |
| 86 | You are a research assistant. To answer, read the web pages the user | 87 | You are a research assistant. To answer, read the web pages the user |
modified
internal/agentsmd/agentsmd.go +4 -0 | @@ -23,6 +23,7 @@ import ( | ||
| 23 | 23 | "os" |
| 24 | 24 | "path/filepath" |
| 25 | 25 | "strings" |
| 26 | + "time" | |
| 26 | 27 | "unicode/utf8" |
| 27 | 28 | |
| 28 | 29 | "mm/internal/config" |
| @@ -96,6 +97,9 @@ func Load(workDir string) File { | ||
| 96 | 97 | // |
| 97 | 98 | // messages := session.Fresh(agentsmd.System(config.Cfg.System, cwd)) |
| 98 | 99 | func System(base, workDir string) string { |
| 100 | + // The prompt's variables first ({{date}}, {{cwd}}, {{env.NAME}}, ticket | |
| 101 | + // 253): an AGENTS.md is the project's text and is left as written. | |
| 102 | + base = config.ExpandPrompt(base, workDir, time.Now()) | |
| 99 | 103 | f := Load(workDir) |
| 100 | 104 | if f.Status != Loaded { |
| 101 | 105 | return base |
| @@ -23,6 +23,7 @@ import ( | |||
| 23 | "os" | 23 | "os" |
| 24 | "path/filepath" | 24 | "path/filepath" |
| 25 | "strings" | 25 | "strings" |
| 26 | + "time" | ||
| 26 | "unicode/utf8" | 27 | "unicode/utf8" |
| 27 | 28 | ||
| 28 | "mm/internal/config" | 29 | "mm/internal/config" |
| @@ -96,6 +97,9 @@ func Load(workDir string) File { | |||
| 96 | // | 97 | // |
| 97 | // messages := session.Fresh(agentsmd.System(config.Cfg.System, cwd)) | 98 | // messages := session.Fresh(agentsmd.System(config.Cfg.System, cwd)) |
| 98 | func System(base, workDir string) string { | 99 | func System(base, workDir string) string { |
| 100 | + // The prompt's variables first ({{date}}, {{cwd}}, {{env.NAME}}, ticket | ||
| 101 | + // 253): an AGENTS.md is the project's text and is left as written. | ||
| 102 | + base = config.ExpandPrompt(base, workDir, time.Now()) | ||
| 99 | f := Load(workDir) | 103 | f := Load(workDir) |
| 100 | if f.Status != Loaded { | 104 | if f.Status != Loaded { |
| 101 | return base | 105 | return base |
modified
internal/agentsmd/agentsmd_test.go +14 -0 | @@ -180,3 +180,17 @@ func TestTokensEstimate(t *testing.T) { | ||
| 180 | 180 | t.Errorf("Tokens = %d, want 200 (700 characters / 3.5)", f.Tokens()) |
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | + | |
| 184 | +// Ticket 253: the prompt's variables are replaced, {{cwd}} with the | |
| 185 | +// session's directory; the AGENTS.md text is left as written. | |
| 186 | +func TestSystemReplacesThePromptVariablesNotTheProjectFile(t *testing.T) { | |
| 187 | + withSettings(t, defaults) | |
| 188 | + dir := project(t, "Keep {{cwd}} as is.\n") | |
| 189 | + got := System("You work in {{cwd}}. Today is {{date}}.\n", dir) | |
| 190 | + if !strings.HasPrefix(got, "You work in "+dir+". Today is 2") { | |
| 191 | + t.Errorf("variables not replaced:\n%s", got) | |
| 192 | + } | |
| 193 | + if !strings.HasSuffix(got, "Keep {{cwd}} as is.\n") { | |
| 194 | + t.Errorf("the AGENTS.md text was changed:\n%s", got) | |
| 195 | + } | |
| 196 | +} | |
| @@ -180,3 +180,17 @@ func TestTokensEstimate(t *testing.T) { | |||
| 180 | t.Errorf("Tokens = %d, want 200 (700 characters / 3.5)", f.Tokens()) | 180 | t.Errorf("Tokens = %d, want 200 (700 characters / 3.5)", f.Tokens()) |
| 181 | } | 181 | } |
| 182 | } | 182 | } |
| 183 | + | ||
| 184 | +// Ticket 253: the prompt's variables are replaced, {{cwd}} with the | ||
| 185 | +// session's directory; the AGENTS.md text is left as written. | ||
| 186 | +func TestSystemReplacesThePromptVariablesNotTheProjectFile(t *testing.T) { | ||
| 187 | + withSettings(t, defaults) | ||
| 188 | + dir := project(t, "Keep {{cwd}} as is.\n") | ||
| 189 | + got := System("You work in {{cwd}}. Today is {{date}}.\n", dir) | ||
| 190 | + if !strings.HasPrefix(got, "You work in "+dir+". Today is 2") { | ||
| 191 | + t.Errorf("variables not replaced:\n%s", got) | ||
| 192 | + } | ||
| 193 | + if !strings.HasSuffix(got, "Keep {{cwd}} as is.\n") { | ||
| 194 | + t.Errorf("the AGENTS.md text was changed:\n%s", got) | ||
| 195 | + } | ||
| 196 | +} | ||
modified
internal/config/config.go +10 -0 | @@ -105,8 +105,15 @@ type Config struct { | ||
| 105 | 105 | AutoPull bool `yaml:"autoPull"` |
| 106 | 106 | |
| 107 | 107 | // System: the system prompt — what the agent is, and what it may do. |
| 108 | + // Its variables ({{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}}) are | |
| 109 | + // replaced when a conversation starts (promptvars.go). | |
| 108 | 110 | System string `yaml:"system"` |
| 109 | 111 | |
| 112 | + // Variables: the file's own values for the prompt, used as | |
| 113 | + // {{config.NAME}} (ticket 253). A value may hold {{date}}, {{cwd}} and | |
| 114 | + // {{env.NAME}}, not another {{config.…}}. | |
| 115 | + Variables map[string]string `yaml:"variables"` | |
| 116 | + | |
| 110 | 117 | // TurnReminder: a text appended to every question the model reads, after |
| 111 | 118 | // the preGeneration hooks, under the line "[reminder]" (ticket 230). For a |
| 112 | 119 | // small model WHERE a rule sits matters more than how it is worded: in |
| @@ -1143,6 +1150,9 @@ func (c Config) validate() error { | ||
| 1143 | 1150 | if err := c.LlamaCpp.validate(); err != nil { |
| 1144 | 1151 | return err |
| 1145 | 1152 | } |
| 1153 | + if err := validatePrompt(c.System, c.Variables); err != nil { | |
| 1154 | + return err | |
| 1155 | + } | |
| 1146 | 1156 | switch { |
| 1147 | 1157 | case c.Provider == "": |
| 1148 | 1158 | return errors.New("provider must not be empty") |
| @@ -105,8 +105,15 @@ type Config struct { | |||
| 105 | AutoPull bool `yaml:"autoPull"` | 105 | AutoPull bool `yaml:"autoPull"` |
| 106 | 106 | ||
| 107 | // System: the system prompt — what the agent is, and what it may do. | 107 | // System: the system prompt — what the agent is, and what it may do. |
| 108 | + // Its variables ({{date}}, {{cwd}}, {{env.NAME}}, {{config.NAME}}) are | ||
| 109 | + // replaced when a conversation starts (promptvars.go). | ||
| 108 | System string `yaml:"system"` | 110 | System string `yaml:"system"` |
| 109 | 111 | ||
| 112 | + // Variables: the file's own values for the prompt, used as | ||
| 113 | + // {{config.NAME}} (ticket 253). A value may hold {{date}}, {{cwd}} and | ||
| 114 | + // {{env.NAME}}, not another {{config.…}}. | ||
| 115 | + Variables map[string]string `yaml:"variables"` | ||
| 116 | + | ||
| 110 | // TurnReminder: a text appended to every question the model reads, after | 117 | // TurnReminder: a text appended to every question the model reads, after |
| 111 | // the preGeneration hooks, under the line "[reminder]" (ticket 230). For a | 118 | // the preGeneration hooks, under the line "[reminder]" (ticket 230). For a |
| 112 | // small model WHERE a rule sits matters more than how it is worded: in | 119 | // small model WHERE a rule sits matters more than how it is worded: in |
| @@ -1143,6 +1150,9 @@ func (c Config) validate() error { | |||
| 1143 | if err := c.LlamaCpp.validate(); err != nil { | 1150 | if err := c.LlamaCpp.validate(); err != nil { |
| 1144 | return err | 1151 | return err |
| 1145 | } | 1152 | } |
| 1153 | + if err := validatePrompt(c.System, c.Variables); err != nil { | ||
| 1154 | + return err | ||
| 1155 | + } | ||
| 1146 | switch { | 1156 | switch { |
| 1147 | case c.Provider == "": | 1157 | case c.Provider == "": |
| 1148 | return errors.New("provider must not be empty") | 1158 | return errors.New("provider must not be empty") |
added
internal/config/promptvars.go +175 -0 | new file mode 100644 | ||
| @@ -0,0 +1,175 @@ | ||
| 1 | +package config | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "fmt" | |
| 5 | + "os" | |
| 6 | + "regexp" | |
| 7 | + "slices" | |
| 8 | + "sort" | |
| 9 | + "strings" | |
| 10 | + "time" | |
| 11 | +) | |
| 12 | + | |
| 13 | +// Variables in the system prompt (ticket 253): | |
| 14 | +// | |
| 15 | +// system: | | |
| 16 | +// You are a helpful assistant. Today is {{date}}. | |
| 17 | +// You work in {{cwd}}, for {{env.USER}}. | |
| 18 | +// | |
| 19 | +// - {{date}}: today's date, YYYY-MM-DD, local time; | |
| 20 | +// - {{cwd}}: the directory the conversation works in — the session's own | |
| 21 | +// directory over ACP, where every session has one; | |
| 22 | +// - {{env.NAME}}: the value of the environment variable NAME; unset, it is | |
| 23 | +// replaced by nothing and the banner says so. A NAME that looks like a | |
| 24 | +// secret (…_KEY, …_TOKEN, …_SECRET, …PASSWORD…) is a configuration | |
| 25 | +// error: the prompt goes to the model, the sessions and the traces; | |
| 26 | +// - {{config.NAME}}: the value of NAME in the file's `variables:` section, | |
| 27 | +// itself expanded (its {{date}}, {{cwd}}, {{env.NAME}}). A name the | |
| 28 | +// section does not have is a configuration error — the `config.` | |
| 29 | +// namespace is the file's, so an unknown name is a typo — and so is a | |
| 30 | +// {{config.…}} inside a value: no chains, no loops. | |
| 31 | +// | |
| 32 | +// variables: | |
| 33 | +// team: bots-garden | |
| 34 | +// system: | | |
| 35 | +// You help the {{config.team}} team. Today is {{date}}. | |
| 36 | +// | |
| 37 | +// They are replaced each time a conversation's system prompt is built — a | |
| 38 | +// new session, /new, a resumed one — not before every question: the prompt | |
| 39 | +// is the start of what the server caches. A session that crosses midnight | |
| 40 | +// keeps its date until /new. | |
| 41 | +// | |
| 42 | +// Only these three forms are replaced; any other {{…}} (a Go template, a | |
| 43 | +// Mustache example) is left as written. `\{{date}}` writes `{{date}}` itself. | |
| 44 | + | |
| 45 | +// promptVarPattern matches a variable, with the backslash that escapes it. | |
| 46 | +var promptVarPattern = regexp.MustCompile(`(\\?)\{\{\s*(date|cwd|env\.([A-Za-z_][A-Za-z0-9_]*)|config\.([A-Za-z_][A-Za-z0-9_-]*))\s*\}\}`) | |
| 47 | + | |
| 48 | +// variableName is a valid key of the `variables:` section. | |
| 49 | +var variableName = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_-]*$`) | |
| 50 | + | |
| 51 | +// secretName is a variable name that looks like it holds a secret. | |
| 52 | +var secretName = regexp.MustCompile(`(?i)(^|_)(KEY|APIKEY|TOKEN|SECRET|PASSWORD|PASSWD|PASS|CREDENTIALS?|PRIVATE)(_|$)`) | |
| 53 | + | |
| 54 | +// ExpandPrompt replaces the variables of text. cwd "" is the process's | |
| 55 | +// working directory. | |
| 56 | +// | |
| 57 | +// ExpandPrompt("Today is {{date}}.", "", now) // "Today is 2026-11-25." | |
| 58 | +func ExpandPrompt(text, cwd string, now time.Time) string { | |
| 59 | + return expand(text, cwd, now, Cfg.Variables) | |
| 60 | +} | |
| 61 | + | |
| 62 | +// expand replaces the variables of text; vars nil leaves the | |
| 63 | +// {{config.NAME}} as written (a value of the section is expanded that way). | |
| 64 | +func expand(text, cwd string, now time.Time, vars map[string]string) string { | |
| 65 | + if !strings.Contains(text, "{{") { | |
| 66 | + return text | |
| 67 | + } | |
| 68 | + if cwd == "" { | |
| 69 | + cwd, _ = os.Getwd() | |
| 70 | + } | |
| 71 | + return promptVarPattern.ReplaceAllStringFunc(text, func(m string) string { | |
| 72 | + sub := promptVarPattern.FindStringSubmatch(m) | |
| 73 | + if sub[1] != "" { // escaped: the variable itself, without the backslash | |
| 74 | + return m[1:] | |
| 75 | + } | |
| 76 | + switch { | |
| 77 | + case sub[2] == "date": | |
| 78 | + return now.Format("2006-01-02") | |
| 79 | + case sub[2] == "cwd": | |
| 80 | + return cwd | |
| 81 | + case sub[4] != "": | |
| 82 | + v, ok := vars[sub[4]] | |
| 83 | + if !ok { | |
| 84 | + return m | |
| 85 | + } | |
| 86 | + return expand(v, cwd, now, nil) | |
| 87 | + default: | |
| 88 | + return os.Getenv(sub[3]) | |
| 89 | + } | |
| 90 | + }) | |
| 91 | +} | |
| 92 | + | |
| 93 | +// promptEnvNames lists the {{env.NAME}} of text that are not escaped. | |
| 94 | +func promptEnvNames(text string) []string { | |
| 95 | + var names []string | |
| 96 | + for _, sub := range promptVarPattern.FindAllStringSubmatch(text, -1) { | |
| 97 | + if sub[1] == "" && sub[3] != "" { | |
| 98 | + names = append(names, sub[3]) | |
| 99 | + } | |
| 100 | + } | |
| 101 | + return names | |
| 102 | +} | |
| 103 | + | |
| 104 | +// validatePrompt refuses a {{env.NAME}} whose name looks like a secret — | |
| 105 | +// in the prompt or in a value of the `variables:` section —, a | |
| 106 | +// {{config.NAME}} the section does not have, a {{config.…}} inside a value, | |
| 107 | +// and a key that is not a name. | |
| 108 | +func validatePrompt(system string, vars map[string]string) error { | |
| 109 | + check := func(where, text string) error { | |
| 110 | + for _, name := range promptEnvNames(text) { | |
| 111 | + if secretName.MatchString(name) { | |
| 112 | + return fmt.Errorf("%s: {{env.%s}} looks like a secret — the prompt is sent to the model and kept in the sessions and traces; refused", where, name) | |
| 113 | + } | |
| 114 | + } | |
| 115 | + return nil | |
| 116 | + } | |
| 117 | + for _, key := range sortedKeys(vars) { | |
| 118 | + if !variableName.MatchString(key) { | |
| 119 | + return fmt.Errorf("variables: %q is not a valid name (letters, digits, _ and -, not starting with a digit)", key) | |
| 120 | + } | |
| 121 | + if names := promptConfigNames(vars[key]); len(names) > 0 { | |
| 122 | + return fmt.Errorf("variables.%s: {{config.%s}} — a value cannot use another variable of the section", key, names[0]) | |
| 123 | + } | |
| 124 | + if err := check("variables."+key, vars[key]); err != nil { | |
| 125 | + return err | |
| 126 | + } | |
| 127 | + } | |
| 128 | + for _, name := range promptConfigNames(system) { | |
| 129 | + if _, ok := vars[name]; !ok { | |
| 130 | + return fmt.Errorf("system: {{config.%s}} — the variables: section has no %q", name, name) | |
| 131 | + } | |
| 132 | + } | |
| 133 | + return check("system", system) | |
| 134 | +} | |
| 135 | + | |
| 136 | +// promptConfigNames lists the {{config.NAME}} of text that are not escaped. | |
| 137 | +func promptConfigNames(text string) []string { | |
| 138 | + var names []string | |
| 139 | + for _, sub := range promptVarPattern.FindAllStringSubmatch(text, -1) { | |
| 140 | + if sub[1] == "" && sub[4] != "" { | |
| 141 | + names = append(names, sub[4]) | |
| 142 | + } | |
| 143 | + } | |
| 144 | + return names | |
| 145 | +} | |
| 146 | + | |
| 147 | +// sortedKeys is m's keys in order: the first error found is always the same. | |
| 148 | +func sortedKeys(m map[string]string) []string { | |
| 149 | + keys := make([]string, 0, len(m)) | |
| 150 | + for k := range m { | |
| 151 | + keys = append(keys, k) | |
| 152 | + } | |
| 153 | + sort.Strings(keys) | |
| 154 | + return keys | |
| 155 | +} | |
| 156 | + | |
| 157 | +// PromptWarnings is one banner line per {{env.NAME}} of the system prompt | |
| 158 | +// whose variable is not set: it is replaced by nothing. | |
| 159 | +func (c Config) PromptWarnings() []string { | |
| 160 | + var out []string | |
| 161 | + seen := map[string]bool{} | |
| 162 | + names := promptEnvNames(c.System) | |
| 163 | + for _, key := range sortedKeys(c.Variables) { | |
| 164 | + if slices.Contains(promptConfigNames(c.System), key) { | |
| 165 | + names = append(names, promptEnvNames(c.Variables[key])...) | |
| 166 | + } | |
| 167 | + } | |
| 168 | + for _, name := range names { | |
| 169 | + if _, set := os.LookupEnv(name); !set && !seen[name] { | |
| 170 | + seen[name] = true | |
| 171 | + out = append(out, fmt.Sprintf("system: {{env.%s}} — %s is not set, replaced by nothing", name, name)) | |
| 172 | + } | |
| 173 | + } | |
| 174 | + return out | |
| 175 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,175 @@ | |||
| 1 | +package config | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "os" | ||
| 6 | + "regexp" | ||
| 7 | + "slices" | ||
| 8 | + "sort" | ||
| 9 | + "strings" | ||
| 10 | + "time" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +// Variables in the system prompt (ticket 253): | ||
| 14 | +// | ||
| 15 | +// system: | | ||
| 16 | +// You are a helpful assistant. Today is {{date}}. | ||
| 17 | +// You work in {{cwd}}, for {{env.USER}}. | ||
| 18 | +// | ||
| 19 | +// - {{date}}: today's date, YYYY-MM-DD, local time; | ||
| 20 | +// - {{cwd}}: the directory the conversation works in — the session's own | ||
| 21 | +// directory over ACP, where every session has one; | ||
| 22 | +// - {{env.NAME}}: the value of the environment variable NAME; unset, it is | ||
| 23 | +// replaced by nothing and the banner says so. A NAME that looks like a | ||
| 24 | +// secret (…_KEY, …_TOKEN, …_SECRET, …PASSWORD…) is a configuration | ||
| 25 | +// error: the prompt goes to the model, the sessions and the traces; | ||
| 26 | +// - {{config.NAME}}: the value of NAME in the file's `variables:` section, | ||
| 27 | +// itself expanded (its {{date}}, {{cwd}}, {{env.NAME}}). A name the | ||
| 28 | +// section does not have is a configuration error — the `config.` | ||
| 29 | +// namespace is the file's, so an unknown name is a typo — and so is a | ||
| 30 | +// {{config.…}} inside a value: no chains, no loops. | ||
| 31 | +// | ||
| 32 | +// variables: | ||
| 33 | +// team: bots-garden | ||
| 34 | +// system: | | ||
| 35 | +// You help the {{config.team}} team. Today is {{date}}. | ||
| 36 | +// | ||
| 37 | +// They are replaced each time a conversation's system prompt is built — a | ||
| 38 | +// new session, /new, a resumed one — not before every question: the prompt | ||
| 39 | +// is the start of what the server caches. A session that crosses midnight | ||
| 40 | +// keeps its date until /new. | ||
| 41 | +// | ||
| 42 | +// Only these three forms are replaced; any other {{…}} (a Go template, a | ||
| 43 | +// Mustache example) is left as written. `\{{date}}` writes `{{date}}` itself. | ||
| 44 | + | ||
| 45 | +// promptVarPattern matches a variable, with the backslash that escapes it. | ||
| 46 | +var promptVarPattern = regexp.MustCompile(`(\\?)\{\{\s*(date|cwd|env\.([A-Za-z_][A-Za-z0-9_]*)|config\.([A-Za-z_][A-Za-z0-9_-]*))\s*\}\}`) | ||
| 47 | + | ||
| 48 | +// variableName is a valid key of the `variables:` section. | ||
| 49 | +var variableName = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_-]*$`) | ||
| 50 | + | ||
| 51 | +// secretName is a variable name that looks like it holds a secret. | ||
| 52 | +var secretName = regexp.MustCompile(`(?i)(^|_)(KEY|APIKEY|TOKEN|SECRET|PASSWORD|PASSWD|PASS|CREDENTIALS?|PRIVATE)(_|$)`) | ||
| 53 | + | ||
| 54 | +// ExpandPrompt replaces the variables of text. cwd "" is the process's | ||
| 55 | +// working directory. | ||
| 56 | +// | ||
| 57 | +// ExpandPrompt("Today is {{date}}.", "", now) // "Today is 2026-11-25." | ||
| 58 | +func ExpandPrompt(text, cwd string, now time.Time) string { | ||
| 59 | + return expand(text, cwd, now, Cfg.Variables) | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +// expand replaces the variables of text; vars nil leaves the | ||
| 63 | +// {{config.NAME}} as written (a value of the section is expanded that way). | ||
| 64 | +func expand(text, cwd string, now time.Time, vars map[string]string) string { | ||
| 65 | + if !strings.Contains(text, "{{") { | ||
| 66 | + return text | ||
| 67 | + } | ||
| 68 | + if cwd == "" { | ||
| 69 | + cwd, _ = os.Getwd() | ||
| 70 | + } | ||
| 71 | + return promptVarPattern.ReplaceAllStringFunc(text, func(m string) string { | ||
| 72 | + sub := promptVarPattern.FindStringSubmatch(m) | ||
| 73 | + if sub[1] != "" { // escaped: the variable itself, without the backslash | ||
| 74 | + return m[1:] | ||
| 75 | + } | ||
| 76 | + switch { | ||
| 77 | + case sub[2] == "date": | ||
| 78 | + return now.Format("2006-01-02") | ||
| 79 | + case sub[2] == "cwd": | ||
| 80 | + return cwd | ||
| 81 | + case sub[4] != "": | ||
| 82 | + v, ok := vars[sub[4]] | ||
| 83 | + if !ok { | ||
| 84 | + return m | ||
| 85 | + } | ||
| 86 | + return expand(v, cwd, now, nil) | ||
| 87 | + default: | ||
| 88 | + return os.Getenv(sub[3]) | ||
| 89 | + } | ||
| 90 | + }) | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +// promptEnvNames lists the {{env.NAME}} of text that are not escaped. | ||
| 94 | +func promptEnvNames(text string) []string { | ||
| 95 | + var names []string | ||
| 96 | + for _, sub := range promptVarPattern.FindAllStringSubmatch(text, -1) { | ||
| 97 | + if sub[1] == "" && sub[3] != "" { | ||
| 98 | + names = append(names, sub[3]) | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + return names | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +// validatePrompt refuses a {{env.NAME}} whose name looks like a secret — | ||
| 105 | +// in the prompt or in a value of the `variables:` section —, a | ||
| 106 | +// {{config.NAME}} the section does not have, a {{config.…}} inside a value, | ||
| 107 | +// and a key that is not a name. | ||
| 108 | +func validatePrompt(system string, vars map[string]string) error { | ||
| 109 | + check := func(where, text string) error { | ||
| 110 | + for _, name := range promptEnvNames(text) { | ||
| 111 | + if secretName.MatchString(name) { | ||
| 112 | + return fmt.Errorf("%s: {{env.%s}} looks like a secret — the prompt is sent to the model and kept in the sessions and traces; refused", where, name) | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + return nil | ||
| 116 | + } | ||
| 117 | + for _, key := range sortedKeys(vars) { | ||
| 118 | + if !variableName.MatchString(key) { | ||
| 119 | + return fmt.Errorf("variables: %q is not a valid name (letters, digits, _ and -, not starting with a digit)", key) | ||
| 120 | + } | ||
| 121 | + if names := promptConfigNames(vars[key]); len(names) > 0 { | ||
| 122 | + return fmt.Errorf("variables.%s: {{config.%s}} — a value cannot use another variable of the section", key, names[0]) | ||
| 123 | + } | ||
| 124 | + if err := check("variables."+key, vars[key]); err != nil { | ||
| 125 | + return err | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + for _, name := range promptConfigNames(system) { | ||
| 129 | + if _, ok := vars[name]; !ok { | ||
| 130 | + return fmt.Errorf("system: {{config.%s}} — the variables: section has no %q", name, name) | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + return check("system", system) | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +// promptConfigNames lists the {{config.NAME}} of text that are not escaped. | ||
| 137 | +func promptConfigNames(text string) []string { | ||
| 138 | + var names []string | ||
| 139 | + for _, sub := range promptVarPattern.FindAllStringSubmatch(text, -1) { | ||
| 140 | + if sub[1] == "" && sub[4] != "" { | ||
| 141 | + names = append(names, sub[4]) | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + return names | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +// sortedKeys is m's keys in order: the first error found is always the same. | ||
| 148 | +func sortedKeys(m map[string]string) []string { | ||
| 149 | + keys := make([]string, 0, len(m)) | ||
| 150 | + for k := range m { | ||
| 151 | + keys = append(keys, k) | ||
| 152 | + } | ||
| 153 | + sort.Strings(keys) | ||
| 154 | + return keys | ||
| 155 | +} | ||
| 156 | + | ||
| 157 | +// PromptWarnings is one banner line per {{env.NAME}} of the system prompt | ||
| 158 | +// whose variable is not set: it is replaced by nothing. | ||
| 159 | +func (c Config) PromptWarnings() []string { | ||
| 160 | + var out []string | ||
| 161 | + seen := map[string]bool{} | ||
| 162 | + names := promptEnvNames(c.System) | ||
| 163 | + for _, key := range sortedKeys(c.Variables) { | ||
| 164 | + if slices.Contains(promptConfigNames(c.System), key) { | ||
| 165 | + names = append(names, promptEnvNames(c.Variables[key])...) | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + for _, name := range names { | ||
| 169 | + if _, set := os.LookupEnv(name); !set && !seen[name] { | ||
| 170 | + seen[name] = true | ||
| 171 | + out = append(out, fmt.Sprintf("system: {{env.%s}} — %s is not set, replaced by nothing", name, name)) | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + return out | ||
| 175 | +} | ||
added
internal/config/promptvars_test.go +92 -0 | new file mode 100644 | ||
| @@ -0,0 +1,92 @@ | ||
| 1 | +package config | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "strings" | |
| 5 | + "testing" | |
| 6 | + "time" | |
| 7 | +) | |
| 8 | + | |
| 9 | +// Ticket 253: the three variables are replaced, spaces inside the braces | |
| 10 | +// allowed; any other {{…}} and an escaped variable are left as written. | |
| 11 | +func TestExpandPrompt(t *testing.T) { | |
| 12 | + t.Setenv("MM_TEST_TEAM", "rickub") | |
| 13 | + t.Setenv("MM_TEST_EMPTY", "") | |
| 14 | + now := time.Date(2026, 11, 25, 23, 59, 0, 0, time.Local) | |
| 15 | + got := ExpandPrompt("Today is {{date}} in {{ cwd }} for {{env.MM_TEST_TEAM}}{{env.MM_TEST_EMPTY}}{{env.MM_TEST_UNSET}}.", "/work/game", now) | |
| 16 | + if got != "Today is 2026-11-25 in /work/game for rickub." { | |
| 17 | + t.Errorf("got %q", got) | |
| 18 | + } | |
| 19 | + kept := "Write {{.Name}} and {{name}}; the literal \\{{date}} stays; {{dates}} too." | |
| 20 | + if got := ExpandPrompt(kept, "/w", now); got != "Write {{.Name}} and {{name}}; the literal {{date}} stays; {{dates}} too." { | |
| 21 | + t.Errorf("got %q", got) | |
| 22 | + } | |
| 23 | + if got := ExpandPrompt("no variable", "", now); got != "no variable" { | |
| 24 | + t.Errorf("got %q", got) | |
| 25 | + } | |
| 26 | + if got := ExpandPrompt("{{cwd}}", "", now); got == "{{cwd}}" || got == "" { | |
| 27 | + t.Errorf("empty cwd must be the process's directory, got %q", got) | |
| 28 | + } | |
| 29 | +} | |
| 30 | + | |
| 31 | +// A {{env.NAME}} that looks like a secret is refused at load; an unset one | |
| 32 | +// is a banner warning, once. | |
| 33 | +func TestPromptValidationAndWarnings(t *testing.T) { | |
| 34 | + for _, name := range []string{"GITHUB_TOKEN", "CONTEXT7_API_KEY", "OPENAI_APIKEY", "DB_PASSWORD", "AWS_SECRET_ACCESS_KEY", "token"} { | |
| 35 | + if err := validatePrompt("x {{env."+name+"}}", nil); err == nil || !strings.Contains(err.Error(), name) { | |
| 36 | + t.Errorf("%s: %v, want refused", name, err) | |
| 37 | + } | |
| 38 | + } | |
| 39 | + for _, name := range []string{"USER", "HOME", "KEYBOARD_LAYOUT", "MONKEY"} { | |
| 40 | + if err := validatePrompt("x {{env."+name+"}}", nil); err != nil { | |
| 41 | + t.Errorf("%s: %v, want accepted", name, err) | |
| 42 | + } | |
| 43 | + } | |
| 44 | + if err := validatePrompt(`the literal \{{env.GITHUB_TOKEN}}`, nil); err != nil { | |
| 45 | + t.Errorf("an escaped variable is text: %v", err) | |
| 46 | + } | |
| 47 | + t.Setenv("MM_TEST_SET", "x") | |
| 48 | + w := Config{System: "{{env.MM_TEST_UNSET}} {{env.MM_TEST_SET}} {{env.MM_TEST_UNSET}}"}.PromptWarnings() | |
| 49 | + if len(w) != 1 || !strings.Contains(w[0], "MM_TEST_UNSET is not set") { | |
| 50 | + t.Errorf("warnings %v, want one for MM_TEST_UNSET", w) | |
| 51 | + } | |
| 52 | +} | |
| 53 | + | |
| 54 | +// The variables: section, used as {{config.NAME}}: a value is itself | |
| 55 | +// expanded (date, cwd, env), never another {{config.…}}. | |
| 56 | +func TestPromptConfigVariables(t *testing.T) { | |
| 57 | + saved := Cfg.Variables | |
| 58 | + t.Cleanup(func() { Cfg.Variables = saved }) | |
| 59 | + t.Setenv("MM_TEST_TEAM", "rickub") | |
| 60 | + Cfg.Variables = map[string]string{"team": "{{env.MM_TEST_TEAM}}", "style": "short answers", "since": "since {{date}}"} | |
| 61 | + now := time.Date(2026, 11, 25, 9, 0, 0, 0, time.Local) | |
| 62 | + got := ExpandPrompt("Team {{config.team}}, {{ config.style }}, {{config.since}}; \\{{config.team}} stays.", "/w", now) | |
| 63 | + if got != "Team rickub, short answers, since 2026-11-25; {{config.team}} stays." { | |
| 64 | + t.Errorf("got %q", got) | |
| 65 | + } | |
| 66 | +} | |
| 67 | + | |
| 68 | +func TestPromptConfigVariablesValidation(t *testing.T) { | |
| 69 | + ok := map[string]string{"team": "bots-garden", "my-var_2": "x"} | |
| 70 | + if err := validatePrompt("{{config.team}} {{config.my-var_2}}", ok); err != nil { | |
| 71 | + t.Errorf("valid: %v", err) | |
| 72 | + } | |
| 73 | + for name, c := range map[string]struct { | |
| 74 | + system string | |
| 75 | + vars map[string]string | |
| 76 | + want string | |
| 77 | + }{ | |
| 78 | + "unknown name": {"{{config.teem}}", ok, `has no "teem"`}, | |
| 79 | + "chain": {"{{config.a}}", map[string]string{"a": "{{config.b}}", "b": "x"}, "cannot use another variable"}, | |
| 80 | + "secret in value": {"{{config.k}}", map[string]string{"k": "{{env.GITHUB_TOKEN}}"}, "variables.k: {{env.GITHUB_TOKEN}} looks like a secret"}, | |
| 81 | + "bad key": {"x", map[string]string{"2team": "x"}, "not a valid name"}, | |
| 82 | + } { | |
| 83 | + if err := validatePrompt(c.system, c.vars); err == nil || !strings.Contains(err.Error(), c.want) { | |
| 84 | + t.Errorf("%s: %v, want %q", name, err, c.want) | |
| 85 | + } | |
| 86 | + } | |
| 87 | + // An unset variable used through a value of the section is warned too. | |
| 88 | + w := Config{System: "{{config.team}}", Variables: map[string]string{"team": "{{env.MM_TEST_UNSET2}}"}}.PromptWarnings() | |
| 89 | + if len(w) != 1 || !strings.Contains(w[0], "MM_TEST_UNSET2") { | |
| 90 | + t.Errorf("warnings %v", w) | |
| 91 | + } | |
| 92 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | +package config | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "strings" | ||
| 5 | + "testing" | ||
| 6 | + "time" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +// Ticket 253: the three variables are replaced, spaces inside the braces | ||
| 10 | +// allowed; any other {{…}} and an escaped variable are left as written. | ||
| 11 | +func TestExpandPrompt(t *testing.T) { | ||
| 12 | + t.Setenv("MM_TEST_TEAM", "rickub") | ||
| 13 | + t.Setenv("MM_TEST_EMPTY", "") | ||
| 14 | + now := time.Date(2026, 11, 25, 23, 59, 0, 0, time.Local) | ||
| 15 | + got := ExpandPrompt("Today is {{date}} in {{ cwd }} for {{env.MM_TEST_TEAM}}{{env.MM_TEST_EMPTY}}{{env.MM_TEST_UNSET}}.", "/work/game", now) | ||
| 16 | + if got != "Today is 2026-11-25 in /work/game for rickub." { | ||
| 17 | + t.Errorf("got %q", got) | ||
| 18 | + } | ||
| 19 | + kept := "Write {{.Name}} and {{name}}; the literal \\{{date}} stays; {{dates}} too." | ||
| 20 | + if got := ExpandPrompt(kept, "/w", now); got != "Write {{.Name}} and {{name}}; the literal {{date}} stays; {{dates}} too." { | ||
| 21 | + t.Errorf("got %q", got) | ||
| 22 | + } | ||
| 23 | + if got := ExpandPrompt("no variable", "", now); got != "no variable" { | ||
| 24 | + t.Errorf("got %q", got) | ||
| 25 | + } | ||
| 26 | + if got := ExpandPrompt("{{cwd}}", "", now); got == "{{cwd}}" || got == "" { | ||
| 27 | + t.Errorf("empty cwd must be the process's directory, got %q", got) | ||
| 28 | + } | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +// A {{env.NAME}} that looks like a secret is refused at load; an unset one | ||
| 32 | +// is a banner warning, once. | ||
| 33 | +func TestPromptValidationAndWarnings(t *testing.T) { | ||
| 34 | + for _, name := range []string{"GITHUB_TOKEN", "CONTEXT7_API_KEY", "OPENAI_APIKEY", "DB_PASSWORD", "AWS_SECRET_ACCESS_KEY", "token"} { | ||
| 35 | + if err := validatePrompt("x {{env."+name+"}}", nil); err == nil || !strings.Contains(err.Error(), name) { | ||
| 36 | + t.Errorf("%s: %v, want refused", name, err) | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + for _, name := range []string{"USER", "HOME", "KEYBOARD_LAYOUT", "MONKEY"} { | ||
| 40 | + if err := validatePrompt("x {{env."+name+"}}", nil); err != nil { | ||
| 41 | + t.Errorf("%s: %v, want accepted", name, err) | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + if err := validatePrompt(`the literal \{{env.GITHUB_TOKEN}}`, nil); err != nil { | ||
| 45 | + t.Errorf("an escaped variable is text: %v", err) | ||
| 46 | + } | ||
| 47 | + t.Setenv("MM_TEST_SET", "x") | ||
| 48 | + w := Config{System: "{{env.MM_TEST_UNSET}} {{env.MM_TEST_SET}} {{env.MM_TEST_UNSET}}"}.PromptWarnings() | ||
| 49 | + if len(w) != 1 || !strings.Contains(w[0], "MM_TEST_UNSET is not set") { | ||
| 50 | + t.Errorf("warnings %v, want one for MM_TEST_UNSET", w) | ||
| 51 | + } | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +// The variables: section, used as {{config.NAME}}: a value is itself | ||
| 55 | +// expanded (date, cwd, env), never another {{config.…}}. | ||
| 56 | +func TestPromptConfigVariables(t *testing.T) { | ||
| 57 | + saved := Cfg.Variables | ||
| 58 | + t.Cleanup(func() { Cfg.Variables = saved }) | ||
| 59 | + t.Setenv("MM_TEST_TEAM", "rickub") | ||
| 60 | + Cfg.Variables = map[string]string{"team": "{{env.MM_TEST_TEAM}}", "style": "short answers", "since": "since {{date}}"} | ||
| 61 | + now := time.Date(2026, 11, 25, 9, 0, 0, 0, time.Local) | ||
| 62 | + got := ExpandPrompt("Team {{config.team}}, {{ config.style }}, {{config.since}}; \\{{config.team}} stays.", "/w", now) | ||
| 63 | + if got != "Team rickub, short answers, since 2026-11-25; {{config.team}} stays." { | ||
| 64 | + t.Errorf("got %q", got) | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +func TestPromptConfigVariablesValidation(t *testing.T) { | ||
| 69 | + ok := map[string]string{"team": "bots-garden", "my-var_2": "x"} | ||
| 70 | + if err := validatePrompt("{{config.team}} {{config.my-var_2}}", ok); err != nil { | ||
| 71 | + t.Errorf("valid: %v", err) | ||
| 72 | + } | ||
| 73 | + for name, c := range map[string]struct { | ||
| 74 | + system string | ||
| 75 | + vars map[string]string | ||
| 76 | + want string | ||
| 77 | + }{ | ||
| 78 | + "unknown name": {"{{config.teem}}", ok, `has no "teem"`}, | ||
| 79 | + "chain": {"{{config.a}}", map[string]string{"a": "{{config.b}}", "b": "x"}, "cannot use another variable"}, | ||
| 80 | + "secret in value": {"{{config.k}}", map[string]string{"k": "{{env.GITHUB_TOKEN}}"}, "variables.k: {{env.GITHUB_TOKEN}} looks like a secret"}, | ||
| 81 | + "bad key": {"x", map[string]string{"2team": "x"}, "not a valid name"}, | ||
| 82 | + } { | ||
| 83 | + if err := validatePrompt(c.system, c.vars); err == nil || !strings.Contains(err.Error(), c.want) { | ||
| 84 | + t.Errorf("%s: %v, want %q", name, err, c.want) | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + // An unset variable used through a value of the section is warned too. | ||
| 88 | + w := Config{System: "{{config.team}}", Variables: map[string]string{"team": "{{env.MM_TEST_UNSET2}}"}}.PromptWarnings() | ||
| 89 | + if len(w) != 1 || !strings.Contains(w[0], "MM_TEST_UNSET2") { | ||
| 90 | + t.Errorf("warnings %v", w) | ||
| 91 | + } | ||
| 92 | +} | ||
modified
main.go +1 -0 | @@ -334,6 +334,7 @@ func main() { | ||
| 334 | 334 | } |
| 335 | 335 | agentTools := set.tools |
| 336 | 336 | set.warnings = append(set.warnings, ask.Missing()...) |
| 337 | + set.warnings = append(set.warnings, config.Cfg.PromptWarnings()...) | |
| 337 | 338 | |
| 338 | 339 | // Handle prompt mode: run a single prompt and exit |
| 339 | 340 | if *promptMode != "" && e.IsDecider() { |
| @@ -334,6 +334,7 @@ func main() { | |||
| 334 | } | 334 | } |
| 335 | agentTools := set.tools | 335 | agentTools := set.tools |
| 336 | set.warnings = append(set.warnings, ask.Missing()...) | 336 | set.warnings = append(set.warnings, ask.Missing()...) |
| 337 | + set.warnings = append(set.warnings, config.Cfg.PromptWarnings()...) | ||
| 337 | 338 | ||
| 338 | // Handle prompt mode: run a single prompt and exit | 339 | // Handle prompt mode: run a single prompt and exit |
| 339 | if *promptMode != "" && e.IsDecider() { | 340 | if *promptMode != "" && e.IsDecider() { |