bots-garden/mini-mepublic Fork
⑂ e695ee0
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/mini-me.git
git clone ssh://git@rickub.com/bots-garden/mini-me.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

♻️ Quality: decision-dnd runs decision-chat-golang's ask-decider hook (10 duplicate findings → 0)

decision-dnd/hooks/ask-decider was a byte-for-byte copy of
decision-chat-golang's (its header said so). The copy is gone:
dungeon_master.yaml runs ../decision-chat-golang/hooks/ask-decider —
the hook reads its decider file and writes its dumps relative to
MM_CONFIG_DIR, so spell.yaml and .mm/decider stay decision-dnd's.
READMEs EN+FR, the hook's doc comment and the flow diagram (its
description in the drawio skill, regenerated) say so.

Checked: the old copy and the shared hook given the same three
situations with decision-dnd's spell.yaml (d1-3B on the host):
identical answers; then the whole demo end to end through mm -p with
dungeon_master.yaml (Qwen3.5-4B + d1-3B on the host): the hook runs from
the neighbouring folder, the dump lands in decision-dnd/.mm/decider.
The demo now needs decision-chat-golang beside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
agent committed 2026-11-28T13:06:12+01:00 Browse files
e695ee0 parent: fc3d5e4
modified demos/decision-chat-golang/hooks/ask-decider/main.go +3 -1
@@ -1,4 +1,6 @@
1-// Command ask-decider is the preGeneration hook of demos/decision-chat-golang.
1+// Command ask-decider is the preGeneration hook of demos/decision-chat-golang,
2+// and of demos/decision-dnd, which runs this copy (its own decider file:
3+// paths are relative to MM_CONFIG_DIR, the folder of the agent file).
24 //
35 // It reads the hook input on stdin, sends the user's question to the decider
46 // (run as `mm -config <decider> -p "<question>"`), and writes a reply whose
@@ -1,4 +1,6 @@
1-// Command ask-decider is the preGeneration hook of demos/decision-chat-golang.1+// Command ask-decider is the preGeneration hook of demos/decision-chat-golang,
2+// and of demos/decision-dnd, which runs this copy (its own decider file:
3+// paths are relative to MM_CONFIG_DIR, the folder of the agent file).
2 //4 //
3 // It reads the hook input on stdin, sends the user's question to the decider5 // It reads the hook input on stdin, sends the user's question to the decider
4 // (run as `mm -config <decider> -p "<question>"`), and writes a reply whose6 // (run as `mm -config <decider> -p "<question>"`), and writes a reply whose
modified demos/decision-dnd/README.en.md +3 -3
@@ -2,7 +2,7 @@
22
33 *[Version française](README.fr.md)*
44
5-A novice wizard describes a situation; a decider (LiquidAI d1-3B, `spell.yaml`, ACP name `sidekick`) picks one of the wizard's five spells, and a chat agent playing the Dungeon Master (Qwen3.5-4B, `dungeon_master.yaml`) explains the choice. A `preGeneration` hook written in Go, `hooks/ask-decider/` — the hook of [`decision-chat-golang`](../decision-chat-golang/README.en.md) — sends each message to the decider and adds its answer under the message.
5+A novice wizard describes a situation; a decider (LiquidAI d1-3B, `spell.yaml`, ACP name `sidekick`) picks one of the wizard's five spells, and a chat agent playing the Dungeon Master (Qwen3.5-4B, `dungeon_master.yaml`) explains the choice. A `preGeneration` hook written in Go, `../decision-chat-golang/hooks/ask-decider/` — the hook of [`decision-chat-golang`](../decision-chat-golang/README.en.md) — sends each message to the decider and adds its answer under the message.
66
77 ![The decision-dnd flow: the player's situation goes to a Go preGeneration hook, which asks the spell decider and passes its pick to the Dungeon Master; a debug dump keeps one JSON file per question](decision-dnd-flow.svg)
88
@@ -11,8 +11,8 @@ Editable source: `decision-dnd-flow.drawio` (draw.io); `decision-dnd-flow.svg` i
1111 | File | Role |
1212 |------|------|
1313 | `spell.yaml` | the decider: one `choice` question, `spell` — `fireball`, `arcane_bolt`, `shield`, `misty_step`, `sleep`, each described by **when** to cast it |
14-| `dungeon_master.yaml` | the chat agent, its system prompt (below), and its `preGeneration` hook: `cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |
15-| `hooks/ask-decider/` | the Go hook (its own module): runs the decider named by its argument, writes `spell: <name> (confidence <c>)` under the message |
14+| `dungeon_master.yaml` | the chat agent, its system prompt (below), and its `preGeneration` hook: `cd "$MM_CONFIG_DIR/../decision-chat-golang/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |
15+| `../decision-chat-golang/hooks/ask-decider/` | the Go hook, shared with decision-chat-golang (its own module; it reads `spell.yaml` and writes the dumps relative to this folder, `$MM_CONFIG_DIR`): runs the decider named by its argument, writes `spell: <name> (confidence <c>)` under the message |
1616
1717 ## Run it
1818
@@ -2,7 +2,7 @@
2 2
3 *[Version française](README.fr.md)*3 *[Version française](README.fr.md)*
4 4
5-A novice wizard describes a situation; a decider (LiquidAI d1-3B, `spell.yaml`, ACP name `sidekick`) picks one of the wizard's five spells, and a chat agent playing the Dungeon Master (Qwen3.5-4B, `dungeon_master.yaml`) explains the choice. A `preGeneration` hook written in Go, `hooks/ask-decider/` — the hook of [`decision-chat-golang`](../decision-chat-golang/README.en.md) — sends each message to the decider and adds its answer under the message.5+A novice wizard describes a situation; a decider (LiquidAI d1-3B, `spell.yaml`, ACP name `sidekick`) picks one of the wizard's five spells, and a chat agent playing the Dungeon Master (Qwen3.5-4B, `dungeon_master.yaml`) explains the choice. A `preGeneration` hook written in Go, `../decision-chat-golang/hooks/ask-decider/` — the hook of [`decision-chat-golang`](../decision-chat-golang/README.en.md) — sends each message to the decider and adds its answer under the message.
6 6
7 ![The decision-dnd flow: the player's situation goes to a Go preGeneration hook, which asks the spell decider and passes its pick to the Dungeon Master; a debug dump keeps one JSON file per question](decision-dnd-flow.svg)7 ![The decision-dnd flow: the player's situation goes to a Go preGeneration hook, which asks the spell decider and passes its pick to the Dungeon Master; a debug dump keeps one JSON file per question](decision-dnd-flow.svg)
8 8
@@ -11,8 +11,8 @@ Editable source: `decision-dnd-flow.drawio` (draw.io); `decision-dnd-flow.svg` i
11 | File | Role |11 | File | Role |
12 |------|------|12 |------|------|
13 | `spell.yaml` | the decider: one `choice` question, `spell` — `fireball`, `arcane_bolt`, `shield`, `misty_step`, `sleep`, each described by **when** to cast it |13 | `spell.yaml` | the decider: one `choice` question, `spell` — `fireball`, `arcane_bolt`, `shield`, `misty_step`, `sleep`, each described by **when** to cast it |
14-| `dungeon_master.yaml` | the chat agent, its system prompt (below), and its `preGeneration` hook: `cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |14+| `dungeon_master.yaml` | the chat agent, its system prompt (below), and its `preGeneration` hook: `cd "$MM_CONFIG_DIR/../decision-chat-golang/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |
15-| `hooks/ask-decider/` | the Go hook (its own module): runs the decider named by its argument, writes `spell: <name> (confidence <c>)` under the message |15+| `../decision-chat-golang/hooks/ask-decider/` | the Go hook, shared with decision-chat-golang (its own module; it reads `spell.yaml` and writes the dumps relative to this folder, `$MM_CONFIG_DIR`): runs the decider named by its argument, writes `spell: <name> (confidence <c>)` under the message |
16 16
17 ## Run it17 ## Run it
18 18
modified demos/decision-dnd/README.fr.md +3 -3
@@ -2,7 +2,7 @@
22
33 *[English version](README.en.md)*
44
5-Un magicien débutant décrit une situation ; un décideur (LiquidAI d1-3B, `spell.yaml`, nom ACP `sidekick`) choisit l'un des cinq sorts du magicien, et un agent de chat qui joue le maître du jeu (Qwen3.5-4B, `dungeon_master.yaml`) explique ce choix. Un hook `preGeneration` écrit en Go, `hooks/ask-decider/` — le hook de [`decision-chat-golang`](../decision-chat-golang/README.fr.md) — envoie chaque message au décideur et ajoute sa réponse sous le message.
5+Un magicien débutant décrit une situation ; un décideur (LiquidAI d1-3B, `spell.yaml`, nom ACP `sidekick`) choisit l'un des cinq sorts du magicien, et un agent de chat qui joue le maître du jeu (Qwen3.5-4B, `dungeon_master.yaml`) explique ce choix. Un hook `preGeneration` écrit en Go, `../decision-chat-golang/hooks/ask-decider/` — le hook de [`decision-chat-golang`](../decision-chat-golang/README.fr.md) — envoie chaque message au décideur et ajoute sa réponse sous le message.
66
77 ![Le flux de decision-dnd : la situation du joueur passe par un hook preGeneration en Go, qui interroge le décideur des sorts et transmet son choix au maître du jeu ; une sauvegarde de débogage garde un fichier JSON par question](decision-dnd-flow.svg)
88
@@ -11,8 +11,8 @@ Source modifiable : `decision-dnd-flow.drawio` (draw.io) ; `decision-dnd-flow.sv
1111 | Fichier | Rôle |
1212 |---------|------|
1313 | `spell.yaml` | le décideur : une question `choice`, `spell` — `fireball`, `arcane_bolt`, `shield`, `misty_step`, `sleep`, chacun décrit par **quand** le lancer |
14-| `dungeon_master.yaml` | l'agent de chat, son prompt système (plus bas), et son hook `preGeneration` : `cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |
15-| `hooks/ask-decider/` | le hook Go (un module à part) : lance le décideur nommé en argument, écrit `spell: <nom> (confidence <c>)` sous le message |
14+| `dungeon_master.yaml` | l'agent de chat, son prompt système (plus bas), et son hook `preGeneration` : `cd "$MM_CONFIG_DIR/../decision-chat-golang/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |
15+| `../decision-chat-golang/hooks/ask-decider/` | le hook Go, partagé avec decision-chat-golang (un module à part ; il lit `spell.yaml` et écrit les dumps par rapport à ce dossier, `$MM_CONFIG_DIR`) : lance le décideur nommé en argument, écrit `spell: <nom> (confidence <c>)` sous le message |
1616
1717 ## La lancer
1818
@@ -2,7 +2,7 @@
2 2
3 *[English version](README.en.md)*3 *[English version](README.en.md)*
4 4
5-Un magicien débutant décrit une situation ; un décideur (LiquidAI d1-3B, `spell.yaml`, nom ACP `sidekick`) choisit l'un des cinq sorts du magicien, et un agent de chat qui joue le maître du jeu (Qwen3.5-4B, `dungeon_master.yaml`) explique ce choix. Un hook `preGeneration` écrit en Go, `hooks/ask-decider/` — le hook de [`decision-chat-golang`](../decision-chat-golang/README.fr.md) — envoie chaque message au décideur et ajoute sa réponse sous le message.5+Un magicien débutant décrit une situation ; un décideur (LiquidAI d1-3B, `spell.yaml`, nom ACP `sidekick`) choisit l'un des cinq sorts du magicien, et un agent de chat qui joue le maître du jeu (Qwen3.5-4B, `dungeon_master.yaml`) explique ce choix. Un hook `preGeneration` écrit en Go, `../decision-chat-golang/hooks/ask-decider/` — le hook de [`decision-chat-golang`](../decision-chat-golang/README.fr.md) — envoie chaque message au décideur et ajoute sa réponse sous le message.
6 6
7 ![Le flux de decision-dnd : la situation du joueur passe par un hook preGeneration en Go, qui interroge le décideur des sorts et transmet son choix au maître du jeu ; une sauvegarde de débogage garde un fichier JSON par question](decision-dnd-flow.svg)7 ![Le flux de decision-dnd : la situation du joueur passe par un hook preGeneration en Go, qui interroge le décideur des sorts et transmet son choix au maître du jeu ; une sauvegarde de débogage garde un fichier JSON par question](decision-dnd-flow.svg)
8 8
@@ -11,8 +11,8 @@ Source modifiable : `decision-dnd-flow.drawio` (draw.io) ; `decision-dnd-flow.sv
11 | Fichier | Rôle |11 | Fichier | Rôle |
12 |---------|------|12 |---------|------|
13 | `spell.yaml` | le décideur : une question `choice`, `spell` — `fireball`, `arcane_bolt`, `shield`, `misty_step`, `sleep`, chacun décrit par **quand** le lancer |13 | `spell.yaml` | le décideur : une question `choice`, `spell` — `fireball`, `arcane_bolt`, `shield`, `misty_step`, `sleep`, chacun décrit par **quand** le lancer |
14-| `dungeon_master.yaml` | l'agent de chat, son prompt système (plus bas), et son hook `preGeneration` : `cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |14+| `dungeon_master.yaml` | l'agent de chat, son prompt système (plus bas), et son hook `preGeneration` : `cd "$MM_CONFIG_DIR/../decision-chat-golang/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml` |
15-| `hooks/ask-decider/` | le hook Go (un module à part) : lance le décideur nommé en argument, écrit `spell: <nom> (confidence <c>)` sous le message |15+| `../decision-chat-golang/hooks/ask-decider/` | le hook Go, partagé avec decision-chat-golang (un module à part ; il lit `spell.yaml` et écrit les dumps par rapport à ce dossier, `$MM_CONFIG_DIR`) : lance le décideur nommé en argument, écrit `spell: <nom> (confidence <c>)` sous le message |
16 16
17 ## La lancer17 ## La lancer
18 18
modified demos/decision-dnd/decision-dnd-flow.drawio +1 -1
@@ -12,7 +12,7 @@
1212 <mxCell id="c21" value="" style="edgeStyle=none;rounded=0;html=1;strokeColor=#37474F;strokeWidth=2;endArrow=block;endFill=1;startArrow=none;dashed=1;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="370" y="260" as="sourcePoint"/><mxPoint x="150" y="410" as="targetPoint"/><Array as="points"><mxPoint x="370" y="320"/><mxPoint x="150" y="320"/></Array></mxGeometry></mxCell>
1313 <mxCell id="c23" value="" style="edgeStyle=none;rounded=0;html=1;strokeColor=#37474F;strokeWidth=2;endArrow=block;endFill=1;startArrow=none;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1020" y="140" as="sourcePoint"/><mxPoint x="135" y="140" as="targetPoint"/><Array as="points"><mxPoint x="1020" y="100"/><mxPoint x="135" y="100"/></Array></mxGeometry></mxCell>
1414 <mxCell id="c1" value="🧑&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Player&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;describes the situation&lt;br&gt;terminal · -tui · editor&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#E3F2FD;gradientColor=#BBDEFB;strokeColor=#1565C0;strokeWidth=2;shadow=1;fontSize=20;fontColor=#0D47A1;" vertex="1" parent="1"><mxGeometry x="40" y="140" width="190" height="120" as="geometry"/></mxCell>
15- <mxCell id="c2" value="⚙️&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;preGeneration hook&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;hooks/ask-decider (Go)&lt;br&gt;go run . spell.yaml&lt;br&gt;DECIDER_DUMP=.mm/decider&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#FFFDE7;gradientColor=#FFF9C4;strokeColor=#F9A825;strokeWidth=2;shadow=1;fontSize=20;fontColor=#E65100;" vertex="1" parent="1"><mxGeometry x="330" y="140" width="270" height="120" as="geometry"/></mxCell>
15+ <mxCell id="c2" value="⚙️&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;preGeneration hook&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;decision-chat-golang's hook (Go)&lt;br&gt;go run . spell.yaml&lt;br&gt;DECIDER_DUMP=.mm/decider&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#FFFDE7;gradientColor=#FFF9C4;strokeColor=#F9A825;strokeWidth=2;shadow=1;fontSize=20;fontColor=#E65100;" vertex="1" parent="1"><mxGeometry x="330" y="140" width="270" height="120" as="geometry"/></mxCell>
1616 <mxCell id="c3" value="🤖&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Dungeon Master&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;Qwen3.5-4B · dungeon_master.yaml&lt;br&gt;shows the data and the confidence&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#E1F5FE;gradientColor=#B3E5FC;strokeColor=#0277BD;strokeWidth=2;shadow=1;fontSize=20;fontColor=#01579B;" vertex="1" parent="1"><mxGeometry x="880" y="140" width="280" height="120" as="geometry"/></mxCell>
1717 <mxCell id="c4" value="⚖️&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Decider · sidekick&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;LiquidAI d1-3B · spell.yaml&lt;br&gt;POST /v1/systemone&lt;br&gt;one choice, ~0.5 s&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#F3E5F5;gradientColor=#E1BEE7;strokeColor=#6A1B9A;strokeWidth=3;shadow=1;fontSize=20;fontColor=#4A148C;" vertex="1" parent="1"><mxGeometry x="335" y="400" width="260" height="140" as="geometry"/></mxCell>
1818 <mxCell id="c5" value="&lt;b&gt;★ decides&lt;/b&gt;" style="rounded=1;arcSize=50;html=1;fillColor=#6A1B9A;strokeColor=none;fontColor=#FFFFFF;fontSize=11;" vertex="1" parent="1"><mxGeometry x="526.2" y="388" width="78.8" height="24" as="geometry"/></mxCell>
@@ -12,7 +12,7 @@
12 <mxCell id="c21" value="" style="edgeStyle=none;rounded=0;html=1;strokeColor=#37474F;strokeWidth=2;endArrow=block;endFill=1;startArrow=none;dashed=1;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="370" y="260" as="sourcePoint"/><mxPoint x="150" y="410" as="targetPoint"/><Array as="points"><mxPoint x="370" y="320"/><mxPoint x="150" y="320"/></Array></mxGeometry></mxCell>12 <mxCell id="c21" value="" style="edgeStyle=none;rounded=0;html=1;strokeColor=#37474F;strokeWidth=2;endArrow=block;endFill=1;startArrow=none;dashed=1;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="370" y="260" as="sourcePoint"/><mxPoint x="150" y="410" as="targetPoint"/><Array as="points"><mxPoint x="370" y="320"/><mxPoint x="150" y="320"/></Array></mxGeometry></mxCell>
13 <mxCell id="c23" value="" style="edgeStyle=none;rounded=0;html=1;strokeColor=#37474F;strokeWidth=2;endArrow=block;endFill=1;startArrow=none;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1020" y="140" as="sourcePoint"/><mxPoint x="135" y="140" as="targetPoint"/><Array as="points"><mxPoint x="1020" y="100"/><mxPoint x="135" y="100"/></Array></mxGeometry></mxCell>13 <mxCell id="c23" value="" style="edgeStyle=none;rounded=0;html=1;strokeColor=#37474F;strokeWidth=2;endArrow=block;endFill=1;startArrow=none;" edge="1" parent="1"><mxGeometry relative="1" as="geometry"><mxPoint x="1020" y="140" as="sourcePoint"/><mxPoint x="135" y="140" as="targetPoint"/><Array as="points"><mxPoint x="1020" y="100"/><mxPoint x="135" y="100"/></Array></mxGeometry></mxCell>
14 <mxCell id="c1" value="🧑&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Player&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;describes the situation&lt;br&gt;terminal · -tui · editor&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#E3F2FD;gradientColor=#BBDEFB;strokeColor=#1565C0;strokeWidth=2;shadow=1;fontSize=20;fontColor=#0D47A1;" vertex="1" parent="1"><mxGeometry x="40" y="140" width="190" height="120" as="geometry"/></mxCell>14 <mxCell id="c1" value="🧑&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Player&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;describes the situation&lt;br&gt;terminal · -tui · editor&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#E3F2FD;gradientColor=#BBDEFB;strokeColor=#1565C0;strokeWidth=2;shadow=1;fontSize=20;fontColor=#0D47A1;" vertex="1" parent="1"><mxGeometry x="40" y="140" width="190" height="120" as="geometry"/></mxCell>
15- <mxCell id="c2" value="⚙️&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;preGeneration hook&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;hooks/ask-decider (Go)&lt;br&gt;go run . spell.yaml&lt;br&gt;DECIDER_DUMP=.mm/decider&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#FFFDE7;gradientColor=#FFF9C4;strokeColor=#F9A825;strokeWidth=2;shadow=1;fontSize=20;fontColor=#E65100;" vertex="1" parent="1"><mxGeometry x="330" y="140" width="270" height="120" as="geometry"/></mxCell>15+ <mxCell id="c2" value="⚙️&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;preGeneration hook&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;decision-chat-golang's hook (Go)&lt;br&gt;go run . spell.yaml&lt;br&gt;DECIDER_DUMP=.mm/decider&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#FFFDE7;gradientColor=#FFF9C4;strokeColor=#F9A825;strokeWidth=2;shadow=1;fontSize=20;fontColor=#E65100;" vertex="1" parent="1"><mxGeometry x="330" y="140" width="270" height="120" as="geometry"/></mxCell>
16 <mxCell id="c3" value="🤖&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Dungeon Master&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;Qwen3.5-4B · dungeon_master.yaml&lt;br&gt;shows the data and the confidence&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#E1F5FE;gradientColor=#B3E5FC;strokeColor=#0277BD;strokeWidth=2;shadow=1;fontSize=20;fontColor=#01579B;" vertex="1" parent="1"><mxGeometry x="880" y="140" width="280" height="120" as="geometry"/></mxCell>16 <mxCell id="c3" value="🤖&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Dungeon Master&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;Qwen3.5-4B · dungeon_master.yaml&lt;br&gt;shows the data and the confidence&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#E1F5FE;gradientColor=#B3E5FC;strokeColor=#0277BD;strokeWidth=2;shadow=1;fontSize=20;fontColor=#01579B;" vertex="1" parent="1"><mxGeometry x="880" y="140" width="280" height="120" as="geometry"/></mxCell>
17 <mxCell id="c4" value="⚖️&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Decider · sidekick&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;LiquidAI d1-3B · spell.yaml&lt;br&gt;POST /v1/systemone&lt;br&gt;one choice, ~0.5 s&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#F3E5F5;gradientColor=#E1BEE7;strokeColor=#6A1B9A;strokeWidth=3;shadow=1;fontSize=20;fontColor=#4A148C;" vertex="1" parent="1"><mxGeometry x="335" y="400" width="260" height="140" as="geometry"/></mxCell>17 <mxCell id="c4" value="⚖️&lt;br&gt;&lt;b style=&quot;font-size:16px&quot;&gt;Decider · sidekick&lt;/b&gt;&lt;br&gt;&lt;span style=&quot;font-size:11.5px;font-weight:normal&quot;&gt;LiquidAI d1-3B · spell.yaml&lt;br&gt;POST /v1/systemone&lt;br&gt;one choice, ~0.5 s&lt;/span&gt;" style="rounded=1;arcSize=14;whiteSpace=wrap;html=1;fillColor=#F3E5F5;gradientColor=#E1BEE7;strokeColor=#6A1B9A;strokeWidth=3;shadow=1;fontSize=20;fontColor=#4A148C;" vertex="1" parent="1"><mxGeometry x="335" y="400" width="260" height="140" as="geometry"/></mxCell>
18 <mxCell id="c5" value="&lt;b&gt;★ decides&lt;/b&gt;" style="rounded=1;arcSize=50;html=1;fillColor=#6A1B9A;strokeColor=none;fontColor=#FFFFFF;fontSize=11;" vertex="1" parent="1"><mxGeometry x="526.2" y="388" width="78.8" height="24" as="geometry"/></mxCell>18 <mxCell id="c5" value="&lt;b&gt;★ decides&lt;/b&gt;" style="rounded=1;arcSize=50;html=1;fillColor=#6A1B9A;strokeColor=none;fontColor=#FFFFFF;fontSize=11;" vertex="1" parent="1"><mxGeometry x="526.2" y="388" width="78.8" height="24" as="geometry"/></mxCell>
modified demos/decision-dnd/decision-dnd-flow.png +0 -0
Binary files a/demos/decision-dnd/decision-dnd-flow.png and b/demos/decision-dnd/decision-dnd-flow.png differ
Binary files a/demos/decision-dnd/decision-dnd-flow.png and b/demos/decision-dnd/decision-dnd-flow.png differBinary files a/demos/decision-dnd/decision-dnd-flow.png and b/demos/decision-dnd/decision-dnd-flow.png differ
modified demos/decision-dnd/decision-dnd-flow.svg +3 -1
@@ -8,6 +8,8 @@
88 <linearGradient id="gGrey" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="#ECEFF1"/><stop offset="100%" stop-color="#CFD8DC"/></linearGradient>
99 <filter id="shadow" x="-30%" y="-30%" width="160%" height="160%"><feDropShadow dx="2" dy="3" stdDeviation="4" flood-color="#000000" flood-opacity="0.25"/></filter>
1010 <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#37474F"/></marker>
11+ <marker id="arrowGrey" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#78909C"/></marker>
12+ <marker id="arrowOrange" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#EF6C00"/></marker>
1113 </defs>
1214 <rect x="0" y="0" width="1200" height="660" fill="url(#gBg)"/>
1315 <text x="600.0" y="38" text-anchor="middle" font-size="25" font-weight="700" fill="#1A237E">demos/decision-dnd — the decider picks the spell</text>
@@ -26,7 +28,7 @@
2628 <g filter="url(#shadow)"><rect x="330" y="140" width="270" height="120" rx="16" fill="url(#gYellow)" stroke="#F9A825" stroke-width="2"/></g>
2729 <text x="465.0" y="171.5" text-anchor="middle" font-size="22">⚙️</text>
2830 <text x="465.0" y="194.5" text-anchor="middle" font-size="16" font-weight="700" fill="#E65100">preGeneration hook</text>
29- <text x="465.0" y="212.5" text-anchor="middle" font-size="11.5" fill="#E65100">hooks/ask-decider (Go)</text>
31+ <text x="465.0" y="212.5" text-anchor="middle" font-size="11.5" fill="#E65100">decision-chat-golang's hook (Go)</text>
3032 <text x="465.0" y="229.5" text-anchor="middle" font-size="11.5" fill="#E65100">go run . spell.yaml</text>
3133 <text x="465.0" y="246.5" text-anchor="middle" font-size="11.5" fill="#E65100">DECIDER_DUMP=.mm/decider</text>
3234 <g filter="url(#shadow)"><rect x="880" y="140" width="280" height="120" rx="16" fill="url(#gBlue2)" stroke="#0277BD" stroke-width="2"/></g>
@@ -8,6 +8,8 @@
8 <linearGradient id="gGrey" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="#ECEFF1"/><stop offset="100%" stop-color="#CFD8DC"/></linearGradient>8 <linearGradient id="gGrey" x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stop-color="#ECEFF1"/><stop offset="100%" stop-color="#CFD8DC"/></linearGradient>
9 <filter id="shadow" x="-30%" y="-30%" width="160%" height="160%"><feDropShadow dx="2" dy="3" stdDeviation="4" flood-color="#000000" flood-opacity="0.25"/></filter>9 <filter id="shadow" x="-30%" y="-30%" width="160%" height="160%"><feDropShadow dx="2" dy="3" stdDeviation="4" flood-color="#000000" flood-opacity="0.25"/></filter>
10 <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#37474F"/></marker>10 <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#37474F"/></marker>
11+ <marker id="arrowGrey" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#78909C"/></marker>
12+ <marker id="arrowOrange" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="#EF6C00"/></marker>
11 </defs>13 </defs>
12 <rect x="0" y="0" width="1200" height="660" fill="url(#gBg)"/>14 <rect x="0" y="0" width="1200" height="660" fill="url(#gBg)"/>
13 <text x="600.0" y="38" text-anchor="middle" font-size="25" font-weight="700" fill="#1A237E">demos/decision-dnd — the decider picks the spell</text>15 <text x="600.0" y="38" text-anchor="middle" font-size="25" font-weight="700" fill="#1A237E">demos/decision-dnd — the decider picks the spell</text>
@@ -26,7 +28,7 @@
26 <g filter="url(#shadow)"><rect x="330" y="140" width="270" height="120" rx="16" fill="url(#gYellow)" stroke="#F9A825" stroke-width="2"/></g>28 <g filter="url(#shadow)"><rect x="330" y="140" width="270" height="120" rx="16" fill="url(#gYellow)" stroke="#F9A825" stroke-width="2"/></g>
27 <text x="465.0" y="171.5" text-anchor="middle" font-size="22">⚙️</text>29 <text x="465.0" y="171.5" text-anchor="middle" font-size="22">⚙️</text>
28 <text x="465.0" y="194.5" text-anchor="middle" font-size="16" font-weight="700" fill="#E65100">preGeneration hook</text>30 <text x="465.0" y="194.5" text-anchor="middle" font-size="16" font-weight="700" fill="#E65100">preGeneration hook</text>
29- <text x="465.0" y="212.5" text-anchor="middle" font-size="11.5" fill="#E65100">hooks/ask-decider (Go)</text>31+ <text x="465.0" y="212.5" text-anchor="middle" font-size="11.5" fill="#E65100">decision-chat-golang's hook (Go)</text>
30 <text x="465.0" y="229.5" text-anchor="middle" font-size="11.5" fill="#E65100">go run . spell.yaml</text>32 <text x="465.0" y="229.5" text-anchor="middle" font-size="11.5" fill="#E65100">go run . spell.yaml</text>
31 <text x="465.0" y="246.5" text-anchor="middle" font-size="11.5" fill="#E65100">DECIDER_DUMP=.mm/decider</text>33 <text x="465.0" y="246.5" text-anchor="middle" font-size="11.5" fill="#E65100">DECIDER_DUMP=.mm/decider</text>
32 <g filter="url(#shadow)"><rect x="880" y="140" width="280" height="120" rx="16" fill="url(#gBlue2)" stroke="#0277BD" stroke-width="2"/></g>34 <g filter="url(#shadow)"><rect x="880" y="140" width="280" height="120" rx="16" fill="url(#gBlue2)" stroke="#0277BD" stroke-width="2"/></g>
modified demos/decision-dnd/dungeon_master.yaml +3 -2
@@ -1,5 +1,6 @@
11 # A Dungeon Master helped by a decider. Before each message reaches the chat
2-# model, a preGeneration hook — a Go program, hooks/ask-decider — sends it to a
2+# model, a preGeneration hook — a Go program, the hook of decision-chat-golang
3+# (../decision-chat-golang/hooks/ask-decider, one copy for both demos) — sends it to a
34 # decision model (spell.yaml) and adds its pick under the message:
45 # "spell: <name> (confidence <c>)". The system prompt says what that line means.
56 #
@@ -59,5 +60,5 @@ displayHooks: true
5960
6061 hooks:
6162 preGeneration:
62- - command: cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml
63+ - command: cd "$MM_CONFIG_DIR/../decision-chat-golang/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml
6364 timeout: 60s # the first call loads the decision model (and go run compiles once)
@@ -1,5 +1,6 @@
1 # A Dungeon Master helped by a decider. Before each message reaches the chat1 # A Dungeon Master helped by a decider. Before each message reaches the chat
2-# model, a preGeneration hook — a Go program, hooks/ask-decider — sends it to a2+# model, a preGeneration hook — a Go program, the hook of decision-chat-golang
3+# (../decision-chat-golang/hooks/ask-decider, one copy for both demos) — sends it to a
3 # decision model (spell.yaml) and adds its pick under the message:4 # decision model (spell.yaml) and adds its pick under the message:
4 # "spell: <name> (confidence <c>)". The system prompt says what that line means.5 # "spell: <name> (confidence <c>)". The system prompt says what that line means.
5 #6 #
@@ -59,5 +60,5 @@ displayHooks: true
59 60
60 hooks:61 hooks:
61 preGeneration:62 preGeneration:
62- - command: cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml63+ - command: cd "$MM_CONFIG_DIR/../decision-chat-golang/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml
63 timeout: 60s # the first call loads the decision model (and go run compiles once)64 timeout: 60s # the first call loads the decision model (and go run compiles once)
deleted demos/decision-dnd/hooks/ask-decider/.gitignore +0 -2
deleted file mode 100644
@@ -1,2 +0,0 @@
1-# Built by `go build -o ask-decider .` (see the README); not committed.
2-/ask-decider
deleted file mode 100644
@@ -1,2 +0,0 @@
1-# Built by `go build -o ask-decider .` (see the README); not committed.
2-/ask-decider
deleted demos/decision-dnd/hooks/ask-decider/dump.go +0 -43
deleted file mode 100644
@@ -1,43 +0,0 @@
1-package main
2-
3-import (
4- "encoding/json"
5- "os"
6- "path/filepath"
7- "strings"
8- "time"
9-)
10-
11-// record is what one run of the hook keeps when DECIDER_DUMP is set: enough
12-// to see what the decider was asked, what it answered, and what the chat
13-// model was given.
14-type record struct {
15- Time time.Time `json:"time"`
16- Decider string `json:"decider"`
17- Prompt string `json:"prompt"`
18- Response json.RawMessage `json:"response,omitempty"` // the server's JSON, untouched
19- Context string `json:"context,omitempty"` // what the chat model reads under the question
20- Error string `json:"error,omitempty"` // why nothing was handed over
21-}
22-
23-// dump writes rec, indented, to a new file of folder named after its time and
24-// its decider — 20261024-081530.123-spell.json — creating folder if needed.
25-//
26-// dump(".mm/decider", record{Time: time.Now(), Decider: "spell.yaml", Prompt: "…"})
27-func dump(folder string, rec record) error {
28- if err := os.MkdirAll(folder, 0o755); err != nil {
29- return err
30- }
31- data, err := json.MarshalIndent(rec, "", " ")
32- if err != nil {
33- return err
34- }
35- return os.WriteFile(filepath.Join(folder, dumpName(rec)), append(data, '\n'), 0o644)
36-}
37-
38-// dumpName is the file name of a record: its time to the millisecond, then
39-// the decider file's name without its folder and extension.
40-func dumpName(rec record) string {
41- decider := strings.TrimSuffix(filepath.Base(rec.Decider), filepath.Ext(rec.Decider))
42- return rec.Time.Format("20060102-150405.000") + "-" + decider + ".json"
43-}
deleted file mode 100644
@@ -1,43 +0,0 @@
1-package main
2-
3-import (
4- "encoding/json"
5- "os"
6- "path/filepath"
7- "strings"
8- "time"
9-)
10-
11-// record is what one run of the hook keeps when DECIDER_DUMP is set: enough
12-// to see what the decider was asked, what it answered, and what the chat
13-// model was given.
14-type record struct {
15- Time time.Time `json:"time"`
16- Decider string `json:"decider"`
17- Prompt string `json:"prompt"`
18- Response json.RawMessage `json:"response,omitempty"` // the server's JSON, untouched
19- Context string `json:"context,omitempty"` // what the chat model reads under the question
20- Error string `json:"error,omitempty"` // why nothing was handed over
21-}
22-
23-// dump writes rec, indented, to a new file of folder named after its time and
24-// its decider — 20261024-081530.123-spell.json — creating folder if needed.
25-//
26-// dump(".mm/decider", record{Time: time.Now(), Decider: "spell.yaml", Prompt: "…"})
27-func dump(folder string, rec record) error {
28- if err := os.MkdirAll(folder, 0o755); err != nil {
29- return err
30- }
31- data, err := json.MarshalIndent(rec, "", " ")
32- if err != nil {
33- return err
34- }
35- return os.WriteFile(filepath.Join(folder, dumpName(rec)), append(data, '\n'), 0o644)
36-}
37-
38-// dumpName is the file name of a record: its time to the millisecond, then
39-// the decider file's name without its folder and extension.
40-func dumpName(rec record) string {
41- decider := strings.TrimSuffix(filepath.Base(rec.Decider), filepath.Ext(rec.Decider))
42- return rec.Time.Format("20060102-150405.000") + "-" + decider + ".json"
43-}
deleted demos/decision-dnd/hooks/ask-decider/dump_test.go +0 -68
deleted file mode 100644
@@ -1,68 +0,0 @@
1-package main
2-
3-import (
4- "encoding/json"
5- "os"
6- "path/filepath"
7- "testing"
8- "time"
9-)
10-
11-func TestDumpNameIsTheTimeThenTheDecider(t *testing.T) {
12- at := time.Date(2026, 10, 24, 8, 15, 30, 123_000_000, time.UTC)
13- got := dumpName(record{Time: at, Decider: "../deciders/spell.yaml"})
14- if got != "20261024-081530.123-spell.json" {
15- t.Fatalf("got %q", got)
16- }
17-}
18-
19-func TestDumpWritesTheResponseUntouchedInANewFolder(t *testing.T) {
20- folder := filepath.Join(t.TempDir(), "logs", "decider")
21- rec := record{
22- Time: time.Date(2026, 10, 24, 8, 15, 30, 0, time.UTC),
23- Decider: "spell.yaml",
24- Prompt: "An ogre is raising its club.",
25- Response: json.RawMessage(`{"answers":{"spell":{"type":"choice","choice":"shield","confidence":0.85}}}`),
26- Context: "spell: shield (confidence 0.85)",
27- }
28- if err := dump(folder, rec); err != nil {
29- t.Fatal(err)
30- }
31- data, err := os.ReadFile(filepath.Join(folder, "20261024-081530.000-spell.json"))
32- if err != nil {
33- t.Fatal(err)
34- }
35- var back struct {
36- Prompt string `json:"prompt"`
37- Response struct {
38- Answers map[string]answer `json:"answers"`
39- } `json:"response"`
40- Context string `json:"context"`
41- Error string `json:"error"`
42- }
43- if err := json.Unmarshal(data, &back); err != nil {
44- t.Fatalf("not JSON: %v\n%s", err, data)
45- }
46- if back.Prompt != rec.Prompt || back.Context != rec.Context || back.Error != "" {
47- t.Fatalf("fields lost: %+v", back)
48- }
49- if back.Response.Answers["spell"].Choice != "shield" {
50- t.Fatalf("response not kept: %s", data)
51- }
52-}
53-
54-func TestDumpKeepsTheErrorWhenTheDeciderFailed(t *testing.T) {
55- folder := t.TempDir()
56- rec := record{Time: time.Unix(0, 0), Decider: "missing.yaml", Prompt: "q", Error: "exit status 1: config error"}
57- if err := dump(folder, rec); err != nil {
58- t.Fatal(err)
59- }
60- data, _ := os.ReadFile(filepath.Join(folder, dumpName(rec)))
61- var back map[string]any
62- if err := json.Unmarshal(data, &back); err != nil {
63- t.Fatal(err)
64- }
65- if back["error"] != rec.Error || back["response"] != nil {
66- t.Fatalf("got %s", data)
67- }
68-}
deleted file mode 100644
@@ -1,68 +0,0 @@
1-package main
2-
3-import (
4- "encoding/json"
5- "os"
6- "path/filepath"
7- "testing"
8- "time"
9-)
10-
11-func TestDumpNameIsTheTimeThenTheDecider(t *testing.T) {
12- at := time.Date(2026, 10, 24, 8, 15, 30, 123_000_000, time.UTC)
13- got := dumpName(record{Time: at, Decider: "../deciders/spell.yaml"})
14- if got != "20261024-081530.123-spell.json" {
15- t.Fatalf("got %q", got)
16- }
17-}
18-
19-func TestDumpWritesTheResponseUntouchedInANewFolder(t *testing.T) {
20- folder := filepath.Join(t.TempDir(), "logs", "decider")
21- rec := record{
22- Time: time.Date(2026, 10, 24, 8, 15, 30, 0, time.UTC),
23- Decider: "spell.yaml",
24- Prompt: "An ogre is raising its club.",
25- Response: json.RawMessage(`{"answers":{"spell":{"type":"choice","choice":"shield","confidence":0.85}}}`),
26- Context: "spell: shield (confidence 0.85)",
27- }
28- if err := dump(folder, rec); err != nil {
29- t.Fatal(err)
30- }
31- data, err := os.ReadFile(filepath.Join(folder, "20261024-081530.000-spell.json"))
32- if err != nil {
33- t.Fatal(err)
34- }
35- var back struct {
36- Prompt string `json:"prompt"`
37- Response struct {
38- Answers map[string]answer `json:"answers"`
39- } `json:"response"`
40- Context string `json:"context"`
41- Error string `json:"error"`
42- }
43- if err := json.Unmarshal(data, &back); err != nil {
44- t.Fatalf("not JSON: %v\n%s", err, data)
45- }
46- if back.Prompt != rec.Prompt || back.Context != rec.Context || back.Error != "" {
47- t.Fatalf("fields lost: %+v", back)
48- }
49- if back.Response.Answers["spell"].Choice != "shield" {
50- t.Fatalf("response not kept: %s", data)
51- }
52-}
53-
54-func TestDumpKeepsTheErrorWhenTheDeciderFailed(t *testing.T) {
55- folder := t.TempDir()
56- rec := record{Time: time.Unix(0, 0), Decider: "missing.yaml", Prompt: "q", Error: "exit status 1: config error"}
57- if err := dump(folder, rec); err != nil {
58- t.Fatal(err)
59- }
60- data, _ := os.ReadFile(filepath.Join(folder, dumpName(rec)))
61- var back map[string]any
62- if err := json.Unmarshal(data, &back); err != nil {
63- t.Fatal(err)
64- }
65- if back["error"] != rec.Error || back["response"] != nil {
66- t.Fatalf("got %s", data)
67- }
68-}
deleted demos/decision-dnd/hooks/ask-decider/go.mod +0 -5
deleted file mode 100644
@@ -1,5 +0,0 @@
1-// The demo's preGeneration hook. Its own module, so that `go build ./...` in
2-// mini-me does not build it.
3-module askdecider
4-
5-go 1.27
deleted file mode 100644
@@ -1,5 +0,0 @@
1-// The demo's preGeneration hook. Its own module, so that `go build ./...` in
2-// mini-me does not build it.
3-module askdecider
4-
5-go 1.27
deleted demos/decision-dnd/hooks/ask-decider/main.go +0 -222
deleted file mode 100644
@@ -1,222 +0,0 @@
1-// Command ask-decider is the preGeneration hook of demos/decision-dnd (a copy of
2-// the one of demos/decision-chat-golang).
3-//
4-// It reads the hook input on stdin, sends the user's question to the decider
5-// (run as `mm -config <decider> -p "<question>"`), and writes a reply whose
6-// context holds one line per answer:
7-//
8-// level: beginner (confidence 0.91)
9-// topic: concurrency (confidence 0.88)
10-// wants_code: yes (0.97)
11-//
12-// The lines are built from whatever questions the decider declares, in their
13-// order, so changing the decider's questions needs no change here. Set
14-// DECIDER_RAW=1 to hand over the server's JSON answers instead of the lines.
15-//
16-// When the decider's file sets `decision.display: true`, `mm -p` marks its
17-// JSON with `"display": true`, and the reply also carries `display`: the
18-// answers, indented, which mm shows the user (in its own colour) before the
19-// chat model answers — never to the model.
20-//
21-// The decider file is the first argument, relative to the folder of the agent
22-// file that declares the hook (MM_CONFIG_DIR); without one, agent.decider.yaml:
23-//
24-// command: cd "$MM_CONFIG_DIR/hooks/ask-decider" && go run . spell.yaml
25-//
26-// Set DECIDER_DUMP to a folder (relative to MM_CONFIG_DIR) to keep, for each
27-// question, a timestamped JSON file with the question, the decider's whole
28-// response, the context handed over, or the error — see dump.go:
29-//
30-// command: cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml
31-//
32-// MM_BIN is the running mm (set by mm for its hooks); MM_CONFIG_DIR is the
33-// folder of agent.yaml. A decider that fails adds nothing: the program writes
34-// nothing and the chat model reads the question alone.
35-package main
36-
37-import (
38- "bytes"
39- "encoding/json"
40- "fmt"
41- "os"
42- "os/exec"
43- "path/filepath"
44- "strconv"
45- "strings"
46- "time"
47-)
48-
49-// hookInput is the part of the preGeneration input this hook reads.
50-type hookInput struct {
51- Prompt string `json:"prompt"`
52-}
53-
54-// answer is one answer of /v1/systemone; which fields are set depends on Type.
55-type answer struct {
56- Type string `json:"type"`
57- Choice string `json:"choice"`
58- Confidence float64 `json:"confidence"`
59- Noul float64 `json:"noul"`
60- Score float64 `json:"score"`
61- Legend map[string]string `json:"legend"`
62-}
63-
64-// named keeps an answer with its question's name, in the decider's order.
65-type named struct {
66- Name string
67- Answer answer
68-}
69-
70-func main() {
71- var input hookInput
72- if err := json.NewDecoder(os.Stdin).Decode(&input); err != nil {
73- return
74- }
75- rec := record{Time: time.Now(), Decider: deciderFile(os.Args[1:]), Prompt: input.Prompt}
76- if folder := os.Getenv("DECIDER_DUMP"); folder != "" {
77- defer func() {
78- if err := dump(inConfigDir(folder), rec); err != nil {
79- fmt.Fprintln(os.Stderr, "ask-decider: dump:", err)
80- }
81- }()
82- }
83- payload, err := askDecider(rec.Decider, input.Prompt)
84- if err != nil {
85- rec.Error = err.Error()
86- return // empty stdout = continue, the question unchanged
87- }
88- rec.Response = payload
89- context, err := contextFor(payload, os.Getenv("DECIDER_RAW") != "")
90- if err != nil {
91- rec.Error = err.Error()
92- return
93- }
94- rec.Context = context
95- fields := map[string]string{"context": context}
96- if display := displayFor(payload); display != "" {
97- fields["display"] = display
98- }
99- reply, _ := json.Marshal(fields)
100- fmt.Println(string(reply))
101-}
102-
103-// inConfigDir resolves a path relative to MM_CONFIG_DIR, the folder of the
104-// agent file that declares the hook (../.. from here when it is not set).
105-func inConfigDir(path string) string {
106- if filepath.IsAbs(path) {
107- return path
108- }
109- dir := os.Getenv("MM_CONFIG_DIR")
110- if dir == "" {
111- dir = "../.."
112- }
113- return filepath.Join(dir, path)
114-}
115-
116-// deciderFile returns the decider's agent file named by the arguments, or
117-// agent.decider.yaml when there is none.
118-func deciderFile(args []string) string {
119- if len(args) > 0 && args[0] != "" {
120- return args[0]
121- }
122- return "agent.decider.yaml"
123-}
124-
125-// askDecider runs the decider file (relative to MM_CONFIG_DIR unless it is
126-// absolute) on the question and returns its stdout, the server's JSON.
127-func askDecider(file, question string) ([]byte, error) {
128- mm := os.Getenv("MM_BIN")
129- if mm == "" {
130- mm = "mm"
131- }
132- var stderr bytes.Buffer
133- cmd := exec.Command(mm, "-config", inConfigDir(file), "-p", question)
134- cmd.Stderr = &stderr
135- out, err := cmd.Output()
136- if err != nil {
137- return nil, fmt.Errorf("%w: %s", err, strings.TrimSpace(stderr.String()))
138- }
139- return out, nil
140-}
141-
142-// contextFor turns the decider's JSON into the text the chat model reads:
143-// one line per answer, or the raw answers object when raw is true.
144-func contextFor(payload []byte, raw bool) (string, error) {
145- var envelope struct {
146- Answers json.RawMessage `json:"answers"`
147- }
148- if err := json.Unmarshal(payload, &envelope); err != nil {
149- return "", err
150- }
151- if raw {
152- return string(envelope.Answers), nil
153- }
154- answers, err := inOrder(envelope.Answers)
155- if err != nil {
156- return "", err
157- }
158- lines := make([]string, len(answers))
159- for i, a := range answers {
160- lines[i] = line(a.Name, a.Answer)
161- }
162- return strings.Join(lines, "\n"), nil
163-}
164-
165-// displayFor returns the decider's answers, indented, when its file asked
166-// for them to be shown (`"display": true` in the JSON of `mm -p`); ""
167-// otherwise, or when the payload cannot be read.
168-func displayFor(payload []byte) string {
169- var envelope struct {
170- Display bool `json:"display"`
171- Answers json.RawMessage `json:"answers"`
172- }
173- if json.Unmarshal(payload, &envelope) != nil || !envelope.Display || len(envelope.Answers) == 0 {
174- return ""
175- }
176- var indented bytes.Buffer
177- if json.Indent(&indented, envelope.Answers, "", " ") != nil {
178- return ""
179- }
180- return indented.String()
181-}
182-
183-// inOrder decodes the answers object keeping the order of its keys, which is
184-// the order of the decider's questions (a Go map would lose it).
185-func inOrder(object json.RawMessage) ([]named, error) {
186- decoder := json.NewDecoder(bytes.NewReader(object))
187- if _, err := decoder.Token(); err != nil { // {
188- return nil, err
189- }
190- var out []named
191- for decoder.More() {
192- key, err := decoder.Token()
193- if err != nil {
194- return nil, err
195- }
196- var a answer
197- if err := decoder.Decode(&a); err != nil {
198- return nil, err
199- }
200- out = append(out, named{Name: fmt.Sprint(key), Answer: a})
201- }
202- return out, nil
203-}
204-
205-// line writes one answer the way the chat model's system prompt reads it.
206-func line(name string, a answer) string {
207- switch a.Type {
208- case "choice":
209- return fmt.Sprintf("%s: %s (confidence %.2f)", name, a.Choice, a.Confidence)
210- case "noul":
211- verdict := "no"
212- if a.Noul >= 0.5 {
213- verdict = "yes"
214- }
215- return fmt.Sprintf("%s: %s (%.2f)", name, verdict, a.Noul)
216- case "score":
217- level := a.Legend[strconv.Itoa(int(a.Score+0.5))]
218- return fmt.Sprintf("%s: %s (score %.2f)", name, level, a.Score)
219- default:
220- return fmt.Sprintf("%s: (unknown answer type %q)", name, a.Type)
221- }
222-}
deleted file mode 100644
@@ -1,222 +0,0 @@
1-// Command ask-decider is the preGeneration hook of demos/decision-dnd (a copy of
2-// the one of demos/decision-chat-golang).
3-//
4-// It reads the hook input on stdin, sends the user's question to the decider
5-// (run as `mm -config <decider> -p "<question>"`), and writes a reply whose
6-// context holds one line per answer:
7-//
8-// level: beginner (confidence 0.91)
9-// topic: concurrency (confidence 0.88)
10-// wants_code: yes (0.97)
11-//
12-// The lines are built from whatever questions the decider declares, in their
13-// order, so changing the decider's questions needs no change here. Set
14-// DECIDER_RAW=1 to hand over the server's JSON answers instead of the lines.
15-//
16-// When the decider's file sets `decision.display: true`, `mm -p` marks its
17-// JSON with `"display": true`, and the reply also carries `display`: the
18-// answers, indented, which mm shows the user (in its own colour) before the
19-// chat model answers — never to the model.
20-//
21-// The decider file is the first argument, relative to the folder of the agent
22-// file that declares the hook (MM_CONFIG_DIR); without one, agent.decider.yaml:
23-//
24-// command: cd "$MM_CONFIG_DIR/hooks/ask-decider" && go run . spell.yaml
25-//
26-// Set DECIDER_DUMP to a folder (relative to MM_CONFIG_DIR) to keep, for each
27-// question, a timestamped JSON file with the question, the decider's whole
28-// response, the context handed over, or the error — see dump.go:
29-//
30-// command: cd "$MM_CONFIG_DIR/hooks/ask-decider" && DECIDER_DUMP=.mm/decider go run . spell.yaml
31-//
32-// MM_BIN is the running mm (set by mm for its hooks); MM_CONFIG_DIR is the
33-// folder of agent.yaml. A decider that fails adds nothing: the program writes
34-// nothing and the chat model reads the question alone.
35-package main
36-
37-import (
38- "bytes"
39- "encoding/json"
40- "fmt"
41- "os"
42- "os/exec"
43- "path/filepath"
44- "strconv"
45- "strings"
46- "time"
47-)
48-
49-// hookInput is the part of the preGeneration input this hook reads.
50-type hookInput struct {
51- Prompt string `json:"prompt"`
52-}
53-
54-// answer is one answer of /v1/systemone; which fields are set depends on Type.
55-type answer struct {
56- Type string `json:"type"`
57- Choice string `json:"choice"`
58- Confidence float64 `json:"confidence"`
59- Noul float64 `json:"noul"`
60- Score float64 `json:"score"`
61- Legend map[string]string `json:"legend"`
62-}
63-
64-// named keeps an answer with its question's name, in the decider's order.
65-type named struct {
66- Name string
67- Answer answer
68-}
69-
70-func main() {
71- var input hookInput
72- if err := json.NewDecoder(os.Stdin).Decode(&input); err != nil {
73- return
74- }
75- rec := record{Time: time.Now(), Decider: deciderFile(os.Args[1:]), Prompt: input.Prompt}
76- if folder := os.Getenv("DECIDER_DUMP"); folder != "" {
77- defer func() {
78- if err := dump(inConfigDir(folder), rec); err != nil {
79- fmt.Fprintln(os.Stderr, "ask-decider: dump:", err)
80- }
81- }()
82- }
83- payload, err := askDecider(rec.Decider, input.Prompt)
84- if err != nil {
85- rec.Error = err.Error()
86- return // empty stdout = continue, the question unchanged
87- }
88- rec.Response = payload
89- context, err := contextFor(payload, os.Getenv("DECIDER_RAW") != "")
90- if err != nil {
91- rec.Error = err.Error()
92- return
93- }
94- rec.Context = context
95- fields := map[string]string{"context": context}
96- if display := displayFor(payload); display != "" {
97- fields["display"] = display
98- }
99- reply, _ := json.Marshal(fields)
100- fmt.Println(string(reply))
101-}
102-
103-// inConfigDir resolves a path relative to MM_CONFIG_DIR, the folder of the
104-// agent file that declares the hook (../.. from here when it is not set).
105-func inConfigDir(path string) string {
106- if filepath.IsAbs(path) {
107- return path
108- }
109- dir := os.Getenv("MM_CONFIG_DIR")
110- if dir == "" {
111- dir = "../.."
112- }
113- return filepath.Join(dir, path)
114-}
115-
116-// deciderFile returns the decider's agent file named by the arguments, or
117-// agent.decider.yaml when there is none.
118-func deciderFile(args []string) string {
119- if len(args) > 0 && args[0] != "" {
120- return args[0]
121- }
122- return "agent.decider.yaml"
123-}
124-
125-// askDecider runs the decider file (relative to MM_CONFIG_DIR unless it is
126-// absolute) on the question and returns its stdout, the server's JSON.
127-func askDecider(file, question string) ([]byte, error) {
128- mm := os.Getenv("MM_BIN")
129- if mm == "" {
130- mm = "mm"
131- }
132- var stderr bytes.Buffer
133- cmd := exec.Command(mm, "-config", inConfigDir(file), "-p", question)
134- cmd.Stderr = &stderr
135- out, err := cmd.Output()
136- if err != nil {
137- return nil, fmt.Errorf("%w: %s", err, strings.TrimSpace(stderr.String()))
138- }
139- return out, nil
140-}
141-
142-// contextFor turns the decider's JSON into the text the chat model reads:
143-// one line per answer, or the raw answers object when raw is true.
144-func contextFor(payload []byte, raw bool) (string, error) {
145- var envelope struct {
146- Answers json.RawMessage `json:"answers"`
147- }
148- if err := json.Unmarshal(payload, &envelope); err != nil {
149- return "", err
150- }
151- if raw {
152- return string(envelope.Answers), nil
153- }
154- answers, err := inOrder(envelope.Answers)
155- if err != nil {
156- return "", err
157- }
158- lines := make([]string, len(answers))
159- for i, a := range answers {
160- lines[i] = line(a.Name, a.Answer)
161- }
162- return strings.Join(lines, "\n"), nil
163-}
164-
165-// displayFor returns the decider's answers, indented, when its file asked
166-// for them to be shown (`"display": true` in the JSON of `mm -p`); ""
167-// otherwise, or when the payload cannot be read.
168-func displayFor(payload []byte) string {
169- var envelope struct {
170- Display bool `json:"display"`
171- Answers json.RawMessage `json:"answers"`
172- }
173- if json.Unmarshal(payload, &envelope) != nil || !envelope.Display || len(envelope.Answers) == 0 {
174- return ""
175- }
176- var indented bytes.Buffer
177- if json.Indent(&indented, envelope.Answers, "", " ") != nil {
178- return ""
179- }
180- return indented.String()
181-}
182-
183-// inOrder decodes the answers object keeping the order of its keys, which is
184-// the order of the decider's questions (a Go map would lose it).
185-func inOrder(object json.RawMessage) ([]named, error) {
186- decoder := json.NewDecoder(bytes.NewReader(object))
187- if _, err := decoder.Token(); err != nil { // {
188- return nil, err
189- }
190- var out []named
191- for decoder.More() {
192- key, err := decoder.Token()
193- if err != nil {
194- return nil, err
195- }
196- var a answer
197- if err := decoder.Decode(&a); err != nil {
198- return nil, err
199- }
200- out = append(out, named{Name: fmt.Sprint(key), Answer: a})
201- }
202- return out, nil
203-}
204-
205-// line writes one answer the way the chat model's system prompt reads it.
206-func line(name string, a answer) string {
207- switch a.Type {
208- case "choice":
209- return fmt.Sprintf("%s: %s (confidence %.2f)", name, a.Choice, a.Confidence)
210- case "noul":
211- verdict := "no"
212- if a.Noul >= 0.5 {
213- verdict = "yes"
214- }
215- return fmt.Sprintf("%s: %s (%.2f)", name, verdict, a.Noul)
216- case "score":
217- level := a.Legend[strconv.Itoa(int(a.Score+0.5))]
218- return fmt.Sprintf("%s: %s (score %.2f)", name, level, a.Score)
219- default:
220- return fmt.Sprintf("%s: (unknown answer type %q)", name, a.Type)
221- }
222-}
deleted demos/decision-dnd/hooks/ask-decider/main_test.go +0 -78
deleted file mode 100644
@@ -1,78 +0,0 @@
1-package main
2-
3-import "testing"
4-
5-// A payload as /v1/systemone returns it, keys deliberately not in
6-// alphabetical order: the lines must follow the decider's order.
7-const payload = `{"model":"d1","answers":{
8- "topic":{"type":"choice","choice":"concurrency","probabilities":{"basics":0.05,"concurrency":0.95},"confidence":0.91},
9- "wants_code":{"type":"noul","noul":0.97},
10- "level":{"type":"score","score":1.6,"legend":{"0":"low","1":"medium","2":"high"},"probabilities":{"0":0.1,"1":0.2,"2":0.7},"confidence":0.6},
11- "calm":{"type":"noul","noul":0.12}},"usage":{"input_tokens":10,"output_tokens":0}}`
12-
13-func TestContextForWritesOneLinePerAnswerInTheDecidersOrder(t *testing.T) {
14- got, err := contextFor([]byte(payload), false)
15- if err != nil {
16- t.Fatal(err)
17- }
18- want := "topic: concurrency (confidence 0.91)\n" +
19- "wants_code: yes (0.97)\n" +
20- "level: high (score 1.60)\n" +
21- "calm: no (0.12)"
22- if got != want {
23- t.Fatalf("got\n%s\nwant\n%s", got, want)
24- }
25-}
26-
27-func TestContextForRawHandsOverTheAnswersObject(t *testing.T) {
28- got, err := contextFor([]byte(`{"answers":{"x":{"type":"noul","noul":0.5}}}`), true)
29- if err != nil {
30- t.Fatal(err)
31- }
32- if got != `{"x":{"type":"noul","noul":0.5}}` {
33- t.Fatalf("got %s", got)
34- }
35-}
36-
37-func TestContextForRejectsWhatIsNotJSON(t *testing.T) {
38- if _, err := contextFor([]byte("decision: server unreachable"), false); err == nil {
39- t.Fatal("want an error")
40- }
41-}
42-
43-func TestLineRoundsTheScoreToTheNearestLevel(t *testing.T) {
44- legend := map[string]string{"0": "low", "1": "medium", "2": "high"}
45- cases := map[float64]string{0.2: "low", 1.49: "medium", 1.5: "high"}
46- for score, level := range cases {
47- got := line("s", answer{Type: "score", Score: score, Legend: legend})
48- if want := "s: " + level; got[:len(want)] != want {
49- t.Errorf("score %.2f: got %q, want the level %q", score, got, level)
50- }
51- }
52-}
53-
54-func TestDeciderFileDefaultsToAgentDeciderYaml(t *testing.T) {
55- if got := deciderFile(nil); got != "agent.decider.yaml" {
56- t.Fatalf("no argument: got %q", got)
57- }
58- if got := deciderFile([]string{"spell.yaml"}); got != "spell.yaml" {
59- t.Fatalf("one argument: got %q", got)
60- }
61-}
62-
63-func TestDisplayForIndentsTheAnswersWhenTheDeciderAsks(t *testing.T) {
64- marked := `{"display":true,"model":"d1","answers":{"spell":{"type":"choice","choice":"sleep","confidence":0.8}}}`
65- want := "{\n \"spell\": {\n \"type\": \"choice\",\n \"choice\": \"sleep\",\n \"confidence\": 0.8\n }\n}"
66- if got := displayFor([]byte(marked)); got != want {
67- t.Fatalf("got\n%s\nwant\n%s", got, want)
68- }
69-}
70-
71-func TestDisplayForIsEmptyWithoutTheFlag(t *testing.T) {
72- if got := displayFor([]byte(payload)); got != "" {
73- t.Fatalf("got %q, want nothing to show", got)
74- }
75- if got := displayFor([]byte("not json")); got != "" {
76- t.Fatalf("got %q", got)
77- }
78-}
deleted file mode 100644
@@ -1,78 +0,0 @@
1-package main
2-
3-import "testing"
4-
5-// A payload as /v1/systemone returns it, keys deliberately not in
6-// alphabetical order: the lines must follow the decider's order.
7-const payload = `{"model":"d1","answers":{
8- "topic":{"type":"choice","choice":"concurrency","probabilities":{"basics":0.05,"concurrency":0.95},"confidence":0.91},
9- "wants_code":{"type":"noul","noul":0.97},
10- "level":{"type":"score","score":1.6,"legend":{"0":"low","1":"medium","2":"high"},"probabilities":{"0":0.1,"1":0.2,"2":0.7},"confidence":0.6},
11- "calm":{"type":"noul","noul":0.12}},"usage":{"input_tokens":10,"output_tokens":0}}`
12-
13-func TestContextForWritesOneLinePerAnswerInTheDecidersOrder(t *testing.T) {
14- got, err := contextFor([]byte(payload), false)
15- if err != nil {
16- t.Fatal(err)
17- }
18- want := "topic: concurrency (confidence 0.91)\n" +
19- "wants_code: yes (0.97)\n" +
20- "level: high (score 1.60)\n" +
21- "calm: no (0.12)"
22- if got != want {
23- t.Fatalf("got\n%s\nwant\n%s", got, want)
24- }
25-}
26-
27-func TestContextForRawHandsOverTheAnswersObject(t *testing.T) {
28- got, err := contextFor([]byte(`{"answers":{"x":{"type":"noul","noul":0.5}}}`), true)
29- if err != nil {
30- t.Fatal(err)
31- }
32- if got != `{"x":{"type":"noul","noul":0.5}}` {
33- t.Fatalf("got %s", got)
34- }
35-}
36-
37-func TestContextForRejectsWhatIsNotJSON(t *testing.T) {
38- if _, err := contextFor([]byte("decision: server unreachable"), false); err == nil {
39- t.Fatal("want an error")
40- }
41-}
42-
43-func TestLineRoundsTheScoreToTheNearestLevel(t *testing.T) {
44- legend := map[string]string{"0": "low", "1": "medium", "2": "high"}
45- cases := map[float64]string{0.2: "low", 1.49: "medium", 1.5: "high"}
46- for score, level := range cases {
47- got := line("s", answer{Type: "score", Score: score, Legend: legend})
48- if want := "s: " + level; got[:len(want)] != want {
49- t.Errorf("score %.2f: got %q, want the level %q", score, got, level)
50- }
51- }
52-}
53-
54-func TestDeciderFileDefaultsToAgentDeciderYaml(t *testing.T) {
55- if got := deciderFile(nil); got != "agent.decider.yaml" {
56- t.Fatalf("no argument: got %q", got)
57- }
58- if got := deciderFile([]string{"spell.yaml"}); got != "spell.yaml" {
59- t.Fatalf("one argument: got %q", got)
60- }
61-}
62-
63-func TestDisplayForIndentsTheAnswersWhenTheDeciderAsks(t *testing.T) {
64- marked := `{"display":true,"model":"d1","answers":{"spell":{"type":"choice","choice":"sleep","confidence":0.8}}}`
65- want := "{\n \"spell\": {\n \"type\": \"choice\",\n \"choice\": \"sleep\",\n \"confidence\": 0.8\n }\n}"
66- if got := displayFor([]byte(marked)); got != want {
67- t.Fatalf("got\n%s\nwant\n%s", got, want)
68- }
69-}
70-
71-func TestDisplayForIsEmptyWithoutTheFlag(t *testing.T) {
72- if got := displayFor([]byte(payload)); got != "" {
73- t.Fatalf("got %q, want nothing to show", got)
74- }
75- if got := displayFor([]byte("not json")); got != "" {
76- t.Fatalf("got %q", got)
77- }
78-}